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)
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
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..
just though of it... why not creating a ip-table of it and the
file is like a DenyIP Ranges... that will work...
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
good start NightLitch.
plop
Nice...
But I need to see a template of "banned.txt".
/shipis (servaks)
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.
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...
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
k, gonna try that... np..
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.
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.