PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: GrinSlaW on 12 May, 2005, 00:56:20

Title: Convert LUA4 To LUA5
Post by: GrinSlaW on 12 May, 2005, 00:56:20
Hello
Can someone help me?I want use NightLitch's IP-Ranger script. But it is not in lua5 :-(. And it will not work in newest ptokax sadly :-(
Can somebody help me with this, please?

The script looks like this:


-----------------------------------------------------------
--// IP-Ranger: Thor Add-on ? NightLitch 2004
-----------------------------------------------------------

IPVER = "1.3c"

--// Do INI-file
assert(dofile("Add-On/IP-Ranger/IP_Ranger.ini", "IP-Ranger.ini is not found in Add-On folder"))

--// Script Info Tag
nIPTag   = ""
nIPShare = 0.0
nIPMail  = ""
nIPSpeed = "BOT"
nIPDesc  = "By: NightLitch ? Swenorth 2004 "
nIPInfo = "$MyINFO $ALL "..Ranger_Name.." "..nIPDesc..""..nIPTag.."$ $"..nIPSpeed..strchar( 1 ).."$"..nIPMail.."$"..nIPShare.."$"

--// Tables
AllowR = {}
DenyR = {}

--// Files
FILE = {
AllowF = "Add-On/IP-Ranger/Ranges/AllowR.dat",
DenyF = "Add-On/IP-Ranger/Ranges/DenyR.dat",
}

--// Main Function
function Load_Ranger()
LoadFile(FILE.AllowF)
LoadFile(FILE.DenyF)
frmHub:RegBot(Ranger_Name)
ISPTagCheck = 0
end

--// Send Info
function SendInfo(sUser)
sUser:SendData(nIPInfo)
sUser:SendData(" Add-On: IP-Ranger "..IPVER)
end

--// IP-Check Function
function rIPCheck(sUser,sNick)
local AllowOK, ARange = GetRange(sUser.sIP, AllowR)
local DenyOK, DRange = GetRange(sUser.sIP, DenyR)
if CheckLevel(sNick)==1 then return 1 end
-- if ByPassVIP==1 and RegTable[sNick][2]==2 then return 1 end
if DenyOK==1 then
sUser:SendData(Ranger_Name, "Your IP ( "..sUser.sIP.." ) is Denyed here...")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
return 1
else
if AllowOK==1 then
local ISPTagOK = GetISP(sNick,AllowR[ARange][2])
if ISPTagOK==0 and ISP_Check==1 then
if ThorByPass==1 then
local ThorTagOK = GetISP(sNick,ISPTAG)
if ThorTagOK~=1 then
SendErrorTag(sUser,ARange)
end
else
SendErrorTag(sUser,ARange)
end
end
else
sUser:SendData(Ranger_Name, "Your IP ( "..sUser.sIP.." ) is not Allowed here...")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
return 1
end
end
end

--// Check User Level
function CheckLevel(sNick)
OK = -1
for nick,table in RegTable do
if strlower(nick)==strlower(sNick) then
OK = tonumber(table[2])
end
end
if ByPassVIP==1 and OK==2 then return 1 end
if tCheck[OK][1] >= 4 then
return 1
else
return 0
end
end

--// Send Error Message
function SendErrorTag(sUser,ARange)
sUser:SendData(Ranger_Name, "Your ISP Tag is not Allowed here...")
sUser:SendData(Ranger_Name, "Allowed ISP Tag's for you:\r\n\t"..GetTags(AllowR[ARange][2],0).."\r\n")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
end

--// Check Range
function GetRange(ip,table)
local _,_,a,b,c,d = strfind(ip, "(%d*).(%d*).(%d*).(%d*)")
if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
local uip = ComputeIP(ip)
if uip then
local c = ""
for r,i in table do
local _,_,range1,range2 = strfind(r, "(.*)-(.*)")
range1 = ComputeIP(range1)
range2 = ComputeIP(range2)
if uip>=range1 and uip<=range2 then
c = "1"
return 1,r
end
end
end
end
end

--// Check ISP Tag
function GetISP(nick,table)
local _,_,isp,name = strfind(strlower(nick), "^(%[%S+%])(%S+)")
check = 0
if isp~=nil then
for key,tags in table do
if tonumber(key) then
tags = strlower(tags)
if isp==tags then
check = 1
end
end
end
if check==1 then
return 1
elseif check==0 then
return 0
else
return 0
end
else
return 0
end
end

--// Get Tags
function GetTags(table,num)
local line = ""
local t = ""
for id, isp in table do
if not tonumber(isp) then
line = line..t..isp
if num==1 then
if t == "" then t = "," end
else
if t == "" then t = "   " end
end
end
end
return line
end

--// Parse Ranger Commands
function ParseRanger(sUser,sData)
local _,_,cmd = strfind(sData,"%b<>%s+%!(%S+)")
if cmd then
if Ranger_Commands[cmd] and sUser.iProfile==0 then
return Ranger_Commands[cmd](sUser,sData)
else
return 0
end
end
end

--// WhoIs Function
function checkwhois(ip)
local line, range, descr = ""
local socket, err = connect("whois.ripe.net", 43)
if not err then
socket:timeout(2)
err = socket:send(ip..strchar(13, 10))
while not err do
local s,e,key, value = strfind(line, "^(%l+)%:%s*(.*)$")
if key then
if key=="inetnum" then range = value
elseif key=="netname" then descr = value
break end
end
line, err = socket:receive("*l")
end
socket:close()
end
return range, descr
end

--// Ranger Commands
Ranger_Commands = {
["addrange"] = function(sUser,sData) return DoAddRange(sUser,sData) end,
["delrange"] = function(sUser,sData) return DoDelRange(sUser,sData) end,
["show"] = function(sUser,sData) return DoShowRange(sUser,sData) end,
["addisp"] = function(sUser,sData) return DoAddISP(sUser,sData) end,
["delisp"] = function(sUser,sData) return DoDelISP(sUser,sData) end,
["ipinfo"] = function(sUser,sData) return DoIPInfo(sUser,sData) end,
["help"] = function(sUser,sData) return DoIPHelp(sUser,sData) end,
}

--// AddRange Function
function DoAddRange(sUser,sData)
local _,_,range,network,value = strfind(sData,"%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)%s+(%S+)")
if range==nil or network==nil or value==nil then
sUser:SendPM(Ranger_Name,"Syntax: !addrange ")
return 1
end
if strlower(value)=="allow" then
if AllowR[range] then
sUser:SendPM(Ranger_Name,range.." is already in Allow File...")
return 1
end
AllowR[range] = {network, {"["..network.."]"}}
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) - Network: "..network.." is added to Allow File")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
elseif strlower(value)=="deny" then
if DenyRange[range] then
sUser:SendPM(Ranger_Name,range.." is already in Deny File...")
return 1
end
DenyR[range] = {network,{"["..network.."]"}}
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) - Network: "..network.." is added to Deny File")
SaveFile(DenyR , "DenyR", FILE.DenyF)
return 1
else
sUser:SendPM(Ranger_Name,"Wrong arg input! ( allow ) or ( deny ) not ( "..value.." )")
return 1
end
end

--// DelRange Function
function DoDelRange(sUser,sData)
local _,_,range,value = strfind(sData,"%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)")
if range==nil or value==nil then
sUser:SendPM(Ranger_Name,"Syntax: !delrange ")
return 1
end
if strlower(value)=="allow" then
if AllowR[range] then
AllowR[range] = nil
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is deleted from Allow File.")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is not found in Allow File.")
return 1
end
elseif strlower(value)=="deny" then
if DenyR[range] then
DenyR[range] = nil
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is deleted from Deny File.")
SaveFile(DenyR , "DenyR", FILE.DenyF)
return 1
else
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is not found in Deny File.")
return 1
end
else
sUser:SendPM(Ranger_Name,"Wrong arg input! ( allow ) or ( deny ) not ( "..value.." )")
return 1
end
end

--// Show Ranges Function
function DoShowRange(sUser,sData)
local _,_,v = strfind(sData, "%b<>%s+%S+%s+(%S+)")
local msg,c = "\r\n", 0
if v==nil then
sUser:SendPM(Ranger_Name, "Syntax: !show ")
return 1
end
local t,n = "",""
if strlower(v)=="allow" then
t = AllowR
n = "Allow Range List"
elseif strlower(v)=="deny" then
t = DenyR
n = "Deny Range List"
else
sUser:SendPM(Ranger_Name, "Parameter error: not "..v.." !!")
return 1
end
msg=msg.."\r\n\t ? ? ? "..n.." ? ? ?"
msg=msg.."\r\n ?????????????????????????????????????????????????????????????????????????????????????????????????????"
msg=msg.."\r\n\t Network's Range's Isp's"
msg=msg.."\r\n\t ???????? ??????? ???? "
for range,index in t do
sort(t)
c = c +1
msg=msg.."\r\n\t"..index[1]..""..strrep("\t", 60/(20+strlen(index[1])))..""..range..""..strrep("\t", 70/(8+strlen(range)))..""..GetTags(index[2],0)
end
msg=msg.."\r\n _____________________________________________________________________________________________________"
sUser:SendPM(Ranger_Name,msg)
return 1
end

--// Add ISP Function
function DoAddISP(sUser,sData)
local _,_,range,i1,i2,i3,i4,i5,i6,i7,i8 = strfind(sData, "%b<>%s+%S+%s+(%S+-%S+)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)")
if range==nil then
sUser:SendPM(Ranger_Name, "Syntax: !addisp ")
return 1
end
if i1=="" then i1 = nil end
if i2=="" then i2 = nil end
if i3=="" then i3 = nil end
if i4=="" then i4 = nil end
if i5=="" then i5 = nil end
if i6=="" then i6 = nil end
if i7=="" then i7 = nil end
if i8=="" then i8 = nil end
if AllowR[range] then
AllowR[range] = {AllowR[range][1], {GetTags(AllowR[range][2],1), i1,i2,i3,i4,i5,i6,i7,i8},}
sUser:SendPM(Ranger_Name, "\r\n\r\n?ISP: ( "..i1.." ) have been added to: \r\n\r\n?Range: "..range.." \r\n?Network: "..AllowR[range][1].." \r\n?ISP's: "..GetTags(AllowR[range][2],0).." ")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name, "?Range: ( "..range.." ) is not found in database !! ")
return 1
end
end

--// Del ISP Function
function DoDelISP(sUser,sData)
local _,_,range,isp = strfind(sData, "%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)")
if range==nil or isp==nil then
sUser:SendPM(Ranger_Name, "Syntax: !delisp ")
return 1
end
if AllowR[range] then
local check = 0
for i = 1,getn(AllowR[range][2]) do
if isp==AllowR[range][2][i] then
AllowR[range][2][i] = nil
check = 1
end
end
if check==1 then
sUser:SendPM(Ranger_Name, "\r\n\r\n?ISP: ( "..isp.." ) have been removed from: \r\n\r\n?Range: "..range.." \r\n?Network: "..AllowR[range][1].." \r\n?ISP's: "..GetTags(AllowR[range][2],0).." ")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name, "?ISP: ( "..isp.." ) is not found in Range: ( "..range.." ) ")
return 1
end
else
sUser:SendPM(Ranger_Name, "?Range: ( "..range.." ) is not found in database !! ")
return 1
end
end

--// IP Info Function
function DoIPInfo(sUser,sData)
local _,_,ip = strfind(sData,"%b<>%s+%S+%s+(%d+.%d+.%d+.%d+)")
if ip==nil then sUser:SendPM(Range_Name,"Syntax: !ipinfo ") return 1 end
local netnum, netname = checkwhois(ip)
local c, Range = GetRange(ip,AllowR)
local msg = "\r\n"
msg=msg.."\r\n\t ? ? ? Info on "..ip.." ? ? ?"
msg=msg.."\r\n ?????????????????????????????????????????????????????????????????????????????????????????????????????"
msg=msg.."\r\n\t RIPE.Net Information "
msg=msg.."\r\n\t ???????????????????"
msg=msg.."\r\n\t Net Range: "..netnum
msg=msg.."\r\n\t Net Name: "..netname
msg=msg.."\r\n "
msg=msg.."\r\n\t Database Information "
msg=msg.."\r\n\t ???????????????????"
msg=msg.."\r\n\t Range: "..Range
msg=msg.."\r\n\t Network: "..AllowR[Range][1]
msg=msg.."\r\n\t ISP's: "..GetTags(AllowR[Range][2],0)
msg=msg.."\r\n _____________________________________________________________________________________________________"
sUser:SendPM(Ranger_Name,msg)
return 1
end

function DoIPHelp(sUser,sData)
local msg = "\r\n"
msg=msg.."\r\n\t ? ? ? IP-Ranger Help ? ? ?"
msg=msg.."\r\n ?????????????????????????????????????????????????????????????????????????????????????????????????????"
msg=msg.."\r\n\t !addrange - Add range to specific type"
msg=msg.."\r\n\t !delrange - Del range to specific type"
msg=msg.."\r\n\t !addisp - Add isp to range"
msg=msg.."\r\n\t !delisp - Del isp to range"
msg=msg.."\r\n\t !show - Show specific list"
msg=msg.."\r\n\t !ipinfo - Get info about IP"
msg=msg.."\r\n _____________________________________________________________________________________________________"
sUser:SendPM(Ranger_Name,msg)
return 1
end
Title:
Post by: ??????Hawk?????? on 12 May, 2005, 01:15:48
QuoteCan somebody help me with this, please?

Sure m8  ..  you start and when you get stuck  well  help you..   :))

take a look at the how to forum for hints on converting..


??????Hawk??????
Title:
Post by: GrinSlaW on 12 May, 2005, 02:11:59
I have tried NL's converter that one with a GUI and well it worked i think but when i started the script i get this error:

Syntax ...s\Ptokax\0.3.3.0.b17.05.nt.rls\scripts\IP_Ranger.lua:8: bad argument #1 to `assert' (value expected)

i dont know where in the script this is ?(
Title:
Post by: bastya_elvtars on 12 May, 2005, 02:14:41
QuoteOriginally posted by GrinSlaW
I have tried NL's converter that one with a GUI and well it worked i think but when i started the script i get this error:

Syntax ...s\Ptokax\0.3.3.0.b17.05.nt.rls\scripts\IP_Ranger.lua:8: bad argument #1 to `assert' (value expected)

i dont know where in the script this is ?(

Then i is time to post what you got after conversion. ;) Otherwise no one can help you.
Title:
Post by: TTB on 12 May, 2005, 02:22:16
Save this text:

-----------------------------------------
--// Enable Add-On: 1=ON, 0=OFF
-----------------------------------------
IP_RANGER = 0
-----------------------------------------
--// Settings
-----------------------------------------
--// Ranger's Name
Ranger_Name = "-IP-Ranger-"
--// ISP Tag Check
ISP_Check = 1
--// Use Thor's ISPTag Check as bypass Tags
ThorByPass = 1
--// Allow VIP's to ByPass the IP-Check
ByPassVIP = 1
-----------------------------------------

in the file: "IP_Ranger.ini" and put it in the same map where you got your "IP_Ranger.lua".

Little hint: To run the script you wanna convert, you should have a DataArrival (LUA4), ChatArrival (LUA5) / ToArrival (LUA5). And check also the path in the line that gives you the error!
Title:
Post by: bastya_elvtars on 12 May, 2005, 02:24:55
Just rewrite assert(dofile("Add-On/IP-Ranger/IP_Ranger.ini", "IP-Ranger.ini is not found in Add-On folder"))
to

dofile("Add-On/IP-Ranger/IP_Ranger.ini", "IP-Ranger.ini is not found in Add-On folder")
and this error is solved, next please! :D
Title:
Post by: GrinSlaW on 12 May, 2005, 02:29:16
Tnx  :D so fast replay's  8)  tnx for the help m8's  :P i hope it will work now
Title:
Post by: TTB on 14 May, 2005, 22:59:04
Hm... got it almost working. I know NL will bring out a new bot soon, was just trying to convert thisone on my own. Got a problem though... Saving in file works, but when users are logging in, the loadfile function seems to be not correct. So adding a range, isp is ok, but when restarting the scripts, it gives problems... The ranges are not loaded from the txt file (*.dat).

Here is the changed script:

-----------------------------------------------------------
--// IP-Ranger: Thor Add-on ? NightLitch 2004
--// Converted to LUA5 by TTB... almost done..
-----------------------------------------------------------

Ranger_Name = "-IP-Ranger-"
ISP_Check = 1
ThorByPass = 1
ByPassVIP = 1

--// Tables
AllowR = {}
DenyR = {}
RegTable = {}

tCheck = {
[0] = {7,"Master"},
[5] = {6,"Hidden-Master"},
[1] = {5,"Operator"},
[4] = {4,"Hidden-Operator"},
[2] = {3,"VIP"},
[3] = {2,"Reg"},
[-1] = {1,"User"},}


--// Files
FILE = {
AllowF = "vliegen/ranges/AllowR.dat",
DenyF = "vliegen/ranges/DenyR.dat",
}

--// Main Function
function Main()
LoadFile(FILE.AllowF)
LoadFile(FILE.DenyF)
frmHub:RegBot(Ranger_Name)
end

function ChatArrival(curUser,data)
data = string.sub(data,1,string.len(data)-1)
ParseRanger(curUser,data)
return 1
end

function NewUserConnected(curUser,data)
rIPCheck(curUser)
end

--// Compute IP
function ComputeIP(curIP)
local _,_,a,b,c,d = string.find(curIP, "(%d+).(%d+).(%d+).(%d+)")
return a*16777216 + b*65536 + c*256 + d
end

--// IP-Check Function
function rIPCheck(sUser)
local AllowOK, ARange = GetRange(sUser.sIP, AllowR)
local DenyOK, DRange = GetRange(sUser.sIP, DenyR)
if CheckLevel(sUser)==1 then return 1 end
-- if ByPassVIP==1 and RegTable[sNick][2]==2 then return 1 end
if DenyOK==1 then
sUser:SendData(Ranger_Name, "Your IP ( "..sUser.sIP.." ) is Denyed here...")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
return 1
else
if AllowOK==1 then
local ISPTagOK = GetISP(sUser,AllowR[ARange][2])
if ISPTagOK==0 and ISP_Check==1 then
if ThorByPass==1 then
local ThorTagOK = GetISP(sUser,ISPTAG)
if ThorTagOK~=1 then
SendErrorTag(sUser,ARange)
end
else
SendErrorTag(sUser,ARange)
end
end
else
sUser:SendData(Ranger_Name, "Your IP ( "..sUser.sIP.." ) is not Allowed here...")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
return 1
end
end
end

--// Check User Level
function CheckLevel(sNick)
OK = -1
for nick,table in RegTable do
if string.lower(nick)==string.lower(sNick) then
OK = tonumber(table[2])
end
end
if ByPassVIP==1 and OK==2 then return 1 end
if tCheck[OK][1] >= 4 then
return 1
else
return 0
end
end

--// Send Error Message
function SendErrorTag(sUser,ARange)
sUser:SendData(Ranger_Name, "Your ISP Tag is not Allowed here...")
sUser:SendData(Ranger_Name, "Allowed ISP Tag's for you:\r\n\t"..GetTags(AllowR[ARange][2],0).."\r\n")
sUser:SendData(Ranger_Name, "*** Disconnected...")
sUser:Disconnect()
end

--// Check Range
function GetRange(ip,table)
local _,_,a,b,c,d = string.find(ip, "(%d*).(%d*).(%d*).(%d*)")
if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
local uip = ComputeIP(ip)
if uip then
local c = ""
for r,i in table do
local _,_,range1,range2 = string.find(r, "(.*)-(.*)")
range1 = ComputeIP(range1)
range2 = ComputeIP(range2)
if uip>=range1 and uip<=range2 then
c = "1"
return 1,r
end
end
end
end
end

--// Check ISP Tag
function GetISP(nick,table)
local _,_,isp,name = string.find(string.lower(nick.sName), "^(%[%S+%])(%S+)")
check = 0
if isp~=nil then
for key,tags in table do
if tonumber(key) then
tags = string.lower(tags)
if isp==tags then
check = 1
end
end
end
if check==1 then
return 1
elseif check==0 then
return 0
else
return 0
end
else
return 0
end
end

--// Get Tags
function GetTags(table,num)
local line = ""
local t = ""
for id, isp in table do
if not tonumber(isp) then
line = line..t..isp
if num==1 then
if t == "" then t = "," end
else
if t == "" then t = "   " end
end
end
end
return line
end

--// Parse Ranger Commands
function ParseRanger(sUser,sData)
local _,_,cmd = string.find(sData,"%b<>%s+%@(%S+)")
if cmd then
if Ranger_Commands[cmd] and sUser.iProfile==0 then
return Ranger_Commands[cmd](sUser,sData)
else
return 0
end
end
end

--// Ranger Commands
Ranger_Commands = {
["addrange"] = function(sUser,sData) return DoAddRange(sUser,sData) end,
["delrange"] = function(sUser,sData) return DoDelRange(sUser,sData) end,
["show"] = function(sUser,sData) return DoShowRange(sUser,sData) end,
["addisp"] = function(sUser,sData) return DoAddISP(sUser,sData) end,
["delisp"] = function(sUser,sData) return DoDelISP(sUser,sData) end,
["help"] = function(sUser,sData) return DoIPHelp(sUser,sData) end,
}

--// AddRange Function
function DoAddRange(sUser,sData)
local _,_,range,network,value = string.find(sData,"%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)%s+(%S+)")
if range==nil or network==nil or value==nil then
sUser:SendPM(Ranger_Name,"Syntax: !addrange ")
return 1
end
if string.lower(value)=="allow" then
if AllowR[range] then
sUser:SendPM(Ranger_Name,range.." is already in Allow File...")
return 1
end
AllowR[range] = {network, {"["..network.."]"}}
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) - Network: "..network.." is added to Allow File")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
elseif string.lower(value)=="deny" then
if DenyR[range] then
sUser:SendPM(Ranger_Name,range.." is already in Deny File...")
return 1
end
DenyR[range] = {network,{"["..network.."]"}}
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) - Network: "..network.." is added to Deny File")
SaveFile(DenyR , "DenyR", FILE.DenyF)
return 1
else
sUser:SendPM(Ranger_Name,"Wrong arg input! ( allow ) or ( deny ) not ( "..value.." )")
return 1
end
end

--// DelRange Function
function DoDelRange(sUser,sData)
local _,_,range,value = string.find(sData,"%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)")
if range==nil or value==nil then
sUser:SendPM(Ranger_Name,"Syntax: !delrange ")
return 1
end
if string.lower(value)=="allow" then
if AllowR[range] then
AllowR[range] = nil
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is deleted from Allow File.")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is not found in Allow File.")
return 1
end
elseif string.lower(value)=="deny" then
if DenyR[range] then
DenyR[range] = nil
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is deleted from Deny File.")
SaveFile(DenyR , "DenyR", FILE.DenyF)
return 1
else
sUser:SendPM(Ranger_Name,"Range: ( "..range.." ) is not found in Deny File.")
return 1
end
else
sUser:SendPM(Ranger_Name,"Wrong arg input! ( allow ) or ( deny ) not ( "..value.." )")
return 1
end
end

--// Show Ranges Function
function DoShowRange(sUser,sData)
local _,_,v = string.find(sData, "%b<>%s+%S+%s+(%S+)")
local msg,c = "\r\n", 0
if v==nil then
sUser:SendPM(Ranger_Name, "Syntax: !show ")
return 1
end
local t,n = "",""
if string.lower(v)=="allow" then
t = AllowR
n = "Allow Range List"
elseif string.lower(v)=="deny" then
t = DenyR
n = "Deny Range List"
else
sUser:SendPM(Ranger_Name, "Parameter error: not "..v.." !!")
return 1
end
msg=msg.."\r\n\t ? ? ? "..n.." ? ? ?"
msg=msg.."\r\n  ?????????????????????????????????????????????????????????????????????????????????????????????????????"
msg=msg.."\r\n\t Network's Range's Isp's"
msg=msg.."\r\n\t ???????? ??????? ???? "
for range,index in t do
table.sort(t)
c = c +1
msg=msg.."\r\n\t"..index[1]..""..string.rep("\t", 60/(20+string.len(index[1])))..""..range..""..string.rep("\t", 70/(8+string.len(range)))..""..GetTags(index[2],0)
end
msg=msg.."\r\n  _____________________________________________________________________________________________________"
sUser:SendPM(Ranger_Name,msg)
return 1
end

--// Add ISP Function
function DoAddISP(sUser,sData)
local _,_,range,i1,i2,i3,i4,i5,i6,i7,i8 = string.find(sData, "%b<>%s+%S+%s+(%S+-%S+)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)%s*(%S*)")
if range==nil then
sUser:SendPM(Ranger_Name, "Syntax: !addisp ")
return 1
end
if i1=="" then i1 = nil end
if i2=="" then i2 = nil end
if i3=="" then i3 = nil end
if i4=="" then i4 = nil end
if i5=="" then i5 = nil end
if i6=="" then i6 = nil end
if i7=="" then i7 = nil end
if i8=="" then i8 = nil end
if AllowR[range] then
AllowR[range] = {AllowR[range][1], {GetTags(AllowR[range][2],1), i1,i2,i3,i4,i5,i6,i7,i8},}
sUser:SendPM(Ranger_Name, "\r\n\r\n?ISP: ( "..i1.." ) have been added to: \r\n\r\n?Range: "..range.." \r\n?Network: "..AllowR[range][1].." \r\n?ISP's: "..GetTags(AllowR[range][2],0).." ")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name, "?Range: ( "..range.." ) is not found in database !! ")
return 1
end
end

--// Del ISP Function
function DoDelISP(sUser,sData)
local _,_,range,isp = string.find(sData, "%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)")
if range==nil or isp==nil then
sUser:SendPM(Ranger_Name, "Syntax: !delisp ")
return 1
end
if AllowR[range] then
local check = 0
for i = 1,table.getn(AllowR[range][2]) do
if isp==AllowR[range][2][i] then
AllowR[range][2][i] = nil
check = 1
end
end
if check==1 then
sUser:SendPM(Ranger_Name, "\r\n\r\n?ISP: ( "..isp.." ) have been removed from: \r\n\r\n?Range: "..range.." \r\n?Network: "..AllowR[range][1].." \r\n?ISP's: "..GetTags(AllowR[range][2],0).." ")
SaveFile(AllowR , "AllowR", FILE.AllowF)
return 1
else
sUser:SendPM(Ranger_Name, "?ISP: ( "..isp.." ) is not found in Range: ( "..range.." ) ")
return 1
end
else
sUser:SendPM(Ranger_Name, "?Range: ( "..range.." ) is not found in database !! ")
return 1
end
end

function DoIPHelp(sUser,sData)
local msg = "\r\n"
msg=msg.."\r\n\t ? ? ? IP-Ranger Help ? ? ?"
msg=msg.."\r\n  ?????????????????????????????????????????????????????????????????????????????????????????????????????"
msg=msg.."\r\n\t !addrange - Add range to specific type"
msg=msg.."\r\n\t !delrange - Del range to specific type"
msg=msg.."\r\n\t !addisp - Add isp to range"
msg=msg.."\r\n\t !delisp - Del isp to range"
msg=msg.."\r\n\t !show - Show specific list"
msg=msg.."\r\n\t !ipinfo - Get info about IP"
msg=msg.."\r\n  _____________________________________________________________________________________________________"
sUser:SendPM(Ranger_Name,msg)
return 1
end

function Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n" );
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
hFile:write(sTab.."}");
end

function LoadFile(filename)
local handle = io.open(filename,"r")
if handle then
local sdata = ""
local line = ""
for line in handle:lines() do
sdata = sdata..line.."\r\n"
end
return sdata
else
sdata = ""
return sdata
end
handle:close()
end

function SaveFile(table,tablename,filename)
local hFile = io.open (filename,"w");
Serialize(table, tablename, hFile);
hFile:close()
end
Title:
Post by: Dessamator on 14 May, 2005, 23:11:35
well its obvious the prob is in ur loadfile:

function LoadFile(filename)
local handle = io.open(filename,"r")
         if handle then
                local sdata = ""
              local line = ""
                for line in handle:lines() do
               data = sdata..line.."\r\n"
                end
              return sdata
        else
              sdata = ""
             return sdata
        end
        handle:close()
end


make sure that its really readin what u want it to read :)
hint.: use SendToAll or senddata to debug, :)
why are u using "return sdata"?? that value is never used in the script, unless im wrong !
Title:
Post by: TTB on 14 May, 2005, 23:18:27
To read them line by line (or am I wrong?). This was the lua4 code for this part:
function LoadFile(file)
assert(readfrom(file),file.." is not found.")
dostring(read("*all"))
readfrom()
end

The whole function is wrong anyway, I don't know what to do with the sdata. I just don't know how to handle this part.
Title:
Post by: Dessamator on 14 May, 2005, 23:28:18
you were almost there, btw check this threads for reference :  --->here (http://board.univ-angers.fr/thread.php?threadid=3672&boardid=30&styleid=1&sid=82a6388b58a2064c2c99a7e8ebf388db)  and here (http://board.univ-angers.fr/thread.php?threadid=3800&boardid=30&styleid=1&sid=82a6388b58a2064c2c99a7e8ebf388db)

good luck, :)
Title:
Post by: TTB on 14 May, 2005, 23:42:07
ok, this is making me crzay!

Now I got this:

function LoadFile(filename)
local handle = io.open(filename,"r")
        if (handle ~= nil) then
                loadstring(handle:read("*all"))
handle:flush()
handle:close()
        end
end

That should do the same like in LUA4 (2 posts before)... Hm... doesn't also work. I don't get it...  :(
Title:
Post by: Dessamator on 15 May, 2005, 00:13:42
okkkk,  try it like this ::

function LoadFile(file)
local handle = io.open(file,"r")
        if (handle ~= nil) then
                dofile(file)
handle:flush()
handle:close()
        end

end
Title:
Post by: TTB on 15 May, 2005, 00:18:05
Hi,

Maybe it is working... I don't know... I got this:
Syntax ...er ===---\DVD HUB ADSL\TESTHUB6\scripts\IPranger.lua:121: attempt to call a nil value
Line 121 is in the function GetRange:
--// Check Range
function GetRange(ip,table)
local _,_,a,b,c,d = string.find(ip, "(%d*).(%d*).(%d*).(%d*)")
if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then
local uip = ComputeIP(ip)
if uip then
local c = ""
for r,i in table do
local _,_,range1,range2 = string.find(r, "(.*)-(.*)")
range1 = ComputeIP(range1)
range2 = ComputeIP(range2)
if uip>=range1 and uip<=range2 then
c = "1"
return 1,r
end
end
end
end
end

This is line 121:for r,i in table do
Thanx for helping me Dessamator! Do you (or someone else) got any suggestions?
Title:
Post by: TTB on 15 May, 2005, 00:19:58
ow sh*t...

Made a mistake here, didn't fix a line what I chaged before. It seems to work now. I will test it further, thanx for helping me out!! 8)
Title: Network-Securityc
Post by: Pegboy on 15 May, 2005, 02:45:01
while ur trying to get stuff from lua 4 to work with lua 5,

see if ya can fix hawks standalone lua security script for me. :)
Title:
Post by: TTB on 15 May, 2005, 03:41:50
QuoteOriginally posted by Pegboy
while ur trying to get stuff from lua 4 to work with lua 5,

see if ya can fix hawks standalone lua security script for me. :)

You need to post scripts if you like to have them converted. Hawk has XN. Maybe you can try thatone.
Title:
Post by: TTB on 15 May, 2005, 04:00:31
QuoteOriginally posted by GrinSlaW
Tnx  :D so fast replay's  8)  tnx for the help m8's  :P i hope it will work now

Visit this threat >> *CLICK* (http://board.univ-angers.fr/thread.php?threadid=4480&boardid=26&page=1#1)
Title:
Post by: Dessamator on 15 May, 2005, 11:09:53
QuoteOriginally posted by TTB
ow sh*t...

Made a mistake here, didn't fix a line what I chaged before. It seems to work now. I will test it further, thanx for helping me out!! 8)
your welcome,im glad to know the hints  help sometimes, :)