Ban IP writen in txt file.
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Ban IP writen in txt file.

Started by shipiz, 14 January, 2004, 21:00:54

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

shipiz

Hy!

Im looking for a small script wich bans users listed in txt file. I need this script so I can ban users in my hub from web page...

I have php vich adds to txt file a tex.
TXT looks like this:

127.0.0.1
81.81.81.81

And i need a script wich bans IP writen in txt file. After ban IP have to be deleted from txt file.

Please make this script for me.

/shipis (servaks)

plop

QuoteOriginally posted by shipiz
Hy!

Im looking for a small script wich bans users listed in txt file. I need this script so I can ban users in my hub from web page...

I have php vich adds to txt file a tex.
TXT looks like this:

127.0.0.1
81.81.81.81

And i need a script wich bans IP writen in txt file. After ban IP have to be deleted from txt file.

Please make this script for me.

/shipis (servaks)

IP's can't be banned by the scripts, only users.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

NightLitch

Well there is a way but really bad idea I think...

Create a table from the file with the stored ips...

Log every user to a table when logging in and then a check
to see if the ip number is in the list, IF then banned...

but user need to connect...

It's working like a ip-bot, in my eyes..
//NL

NightLitch

just though of it... why not creating a ip-table of it and the
file is like a DenyIP Ranges... that will work...
//NL

NightLitch

try this one, gonna fix it a little more tomorrow...

-- Ip-Ban-Bot-Tester --
-- By: NightLitch

BotName = "BanIP-Bot"

BanFile = "banned.txt"
BanIP = {}

sec = 1000 
min = 60 * sec

function Main()
	LoadIPs(BanIP,BanFile)
	SetTimer( 5 * min) 
	StartTimer()
end 

function OnTimer()
	LoadIPs(BanIP,BanFile)
end

function NewUserConnected(curUser)
	uIP = curUser.sIP
	local _,_,a,b,c,d = strfind(uIP, "(%d*).(%d*).(%d*).(%d*)")
	if a ~= nil then
		if BanIP[uIP] then
			curUser:SendData(BotName, " Your IP is Banned on this Hub !!") 
			curUser:Ban()
			return 1
		end
	end
end

function LoadIPs(table,file)
	local handle = openfile(file, "r")
	if (handle) then
    		local line = read(handle)
    		while line do
			s,e,ips = strfind( line, "(.*)")
			table[ips] = 1
			line = read(handle)
    		end
  		closefile(handle)
	end
end
//NL

plop

good start NightLitch.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

shipiz

#6
Nice...

But I need to see a template of "banned.txt".

/shipis (servaks)

NightLitch

banned.txt are supposed to be replaced with your file where you have your users... I asume you are viewing
from there to Template ?? or...

Anyway gonna try finish it now... But one thing...

The Timer... it is updating the table every 5min now...

Depending how big hub you have now... it can perhaps
get laggy... but I have plop or anyone else answer that..

But my instinct tells me it will do that if many users...

you now may not have the "template" file where you store
those ips in the same folder as PtokaX so here is what you should do:

BanFile = "c:/wwwserver/template/file.ext"

You will hear from me soon...

And ThX for the credit Plop.
//NL

NightLitch

#8
ok here it is. This Should do exact what you want.
Only Put the right location in BanFile and that it...
Simple like it should be... :-)

----------------------------------------
-- BanIP-Bot
-- By: NightLitch 2004
-- Remember the BanFile so the location is right...
----------------------------------------

-- Set Botname
BotName = "Hub-Security"
-- Set Filename ex. if it's another driver and folder like this:
-- Ex: ( c:/Server/www/templates/banned.tmp )
BanFile = "banned.txt"
-- Minutes between File/Table loads
Min = 5

----------------------------------------
BanIP = {}

sec = 1000 
min = 60 * sec
---------------[ Main ]-------------------------------------
function Main()
	LOADiP(BanIP,BanFile)
	SetTimer( Min * min) 
	StartTimer()
end 
---------------[ On Timer ]------------------------------
function OnTimer()
	LOADiP(BanIP,BanFile)
end
---------------[ New User Connected ]-----------
function NewUserConnected(curUser)
	uIP = curUser.sIP
	local _,_,a,b,c,d = strfind(uIP, "(%d*).(%d*).(%d*).(%d*)")
	if a ~= nil then
		if BanIP[uIP] then
			curUser:SendData(BotName, " Your ASS is banned!")
			DELiP(BanIP,BanFile,uIP)
			curUser:Ban()
			return 1
		end
	end
end
-----------------[ Load IP from file ]-----------------
function LOADiP(table,file)
	local handle = openfile(file, "r")
	if (handle) then
    		local line = read(handle)
    		while line do
			s,e,ips = strfind( line, "(.*)")
			table[ips] = 1
			line = read(handle)
    		end
  		closefile(handle)
	end
end
---------------[ Delete IP from File ]----------------
function DELiP(table,file,ip)
	if table[ip] then
		table[ip]=nil
		local handle = openfile(file, "w")
		for i,v in table do
			write(handle,i.."\r\n")
		end
		closefile(handle)
	else
	end
end
-- By: NightLitch

You shouldn't have any problem with this...
User is banned thru txt-file and when trying to connect user
get's ban message and ip removed from txt file and then Banned in HubSoft instead...
//NL

plop

yw boy.

i suggest you start using 2 files.
1 from the webserver with the new ip's, just check on the timer if it excists.
if yes you push them all into the 2de file, when done you delete the 1st file.
results that the timer won't do anything if the 1st file is not there.
the 2de file is only loaded on bot startup and saved if a user enters with a 2 be banned ip.
this should lower the resources 2 the bare minumum.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

NightLitch

k, gonna try that... np..
//NL

NightLitch

But the file do exist there... otherwise it will not load or script will create file but be emty...

cause tried you hint but get to advanced for me for the moment... Am newly awake dude... :-D

but can try later...

did a fix until then...
----------------------------------------
-- BanIP-Bot
-- By: NightLitch 2004
-- Remember the BanFile so the location is right...
-- Fixed if file not exist file created
----------------------------------------

-- Set Botname
BotName = "Hub-Security"
-- Set Filename ex. if it's another driver and folder like this:
-- Ex: ( c:/Server/www/templates/banned.tmp )
BanFile = "banned.txt"
-- Minutes between File/Table loads
Min = 5

----------------------------------------
BanIP = {}
Temp = {}

sec = 1000 
min = 60 * sec
---------------[ Main ]-------------------------------------
function Main()
	LOADiP(BanIP,BanFile)
	SetTimer( Min * min) 
	StartTimer()
end 
---------------[ On Timer ]------------------------------
function OnTimer()
	LOADiP(BanIP,BanFile)
end
---------------[ New User Connected ]-----------
function NewUserConnected(curUser)
	uIP = curUser.sIP
	local _,_,a,b,c,d = strfind(uIP, "(%d*).(%d*).(%d*).(%d*)")
	if a ~= nil then
		if BanIP[uIP] then
			curUser:SendData(BotName, " Your ASS is banned!")
			DELiP(BanIP,BanFile,uIP)
			curUser:Ban()
			return 1
		end
	end
end
-----------------[ Load IP from file ]-----------------
function LOADiP(table,file)
	local handle = openfile(file, "r")
	if (handle) then
    		local line = read(handle)
    		while line do
			s,e,ips = strfind( line, "(.*)")
			table[ips] = 1
			line = read(handle)
    		end
  		closefile(handle)
	elseif (handle) == nil then
		local f = openfile(file, "w")
		write(f, "")
		closefile(f)
	end
end
---------------[ Delete IP from File ]----------------
function DELiP(table,file,ip)
	if table[ip] then
		table[ip]=nil
		local handle = openfile(file, "w")
		for i,v in table do
			write(handle,i.."\r\n")
		end
		closefile(handle)
	else
	end
end
-- By: NightLitch

this is simpler I think... but your idea is maybe less rescource taking Plop.
//NL

NightLitch

well shipiz.. have you tried it... wanna know if I need to rewrite something...

From my point of view it looks 100% ok and finish...
exept for maybe a small mods that I got from plop.
//NL

SMF spam blocked by CleanTalk