IP Ranger from Thor 2.0
 

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

IP Ranger from Thor 2.0

Started by TTB, 15 May, 2005, 03:57:01

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TTB

IP-Ranger, standalone now, in LUA5.

You need to make a folder/file:
/scripts/ranges/AllowR.dat
/scripts/ranges/DenyR.dat

Put in AllowR.dat this table:
AllowR = {

}

and in DenyR.dat this table:
DenyR = {

}

Here is the script... Report bugs, maybe I can fix them :)

-----------------------------------------------------------
--// IP-Ranger: Thor Add-on ? NightLitch 2004
--// Converted to LUA5 by TTB
--// Date: 15-05-2005
--// Update by TTB, 19-10-05
----------------------------------------------------------- 

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

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

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

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

function ToArrival(curUser,data)
	local _,_,whoTo,mes = string.find(data,"$To:%s+(%S+)%s+From:%s+%S+%s+$(.*)")
	if (whoTo == Ranger_Name and string.find(mes,"%b<>%s+(.*)")) then
		data = string.sub(mes,1,string.len(mes)-1)
		ParseRanger(curUser,data)
		return 1
	end
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 ByPassVIP==1 and sUser.iProfile == 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
					SendErrorTag(sUser,ARange)
			elseif ISPTagOK == 2 and ISP_Check==1 then
				SendErrorLevel(sUser,ARange)
			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

--// 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")
		SaveIPFile(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")
		SaveIPFile(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.")
			SaveIPFile(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.")
			SaveIPFile(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).." ")
		SaveIPFile(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).." ")
			SaveIPFile(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   ___________________________________________________________________________
__________________________"
	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 LoadIPFile(file)
local handle = io.open(file,"r")
        if (handle ~= nil) then
                dofile(file)
		handle:flush()
		handle:close()
        end
end


function SaveIPFile(table,tablename,filename)
	local hFile = io.open (filename,"w");
	Serialize(table, tablename, hFile);
	hFile:close()
end
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

GrinSlaW

Hi

how can i change so that all op's can use the help menu in ip ranger ?

ihave robocop v10 profiles

cheers
.:: AcExtreme ::. | .:: AcPro ::.

jiten

Quotehow can i change so that all op's can use the help menu in ip ranger ?
Change your ParseRanger function to this:
--// Parse Ranger Commands
function ParseRanger(sUser,sData)
	local _,_,cmd = string.find(sData,"%b<>%s+%!(%S+)")
	if cmd then
		if Ranger_Commands[cmd] and sUser.bOperator then
			return Ranger_Commands[cmd](sUser,sData)
		else
			return 0
		end
	end
end
Best regards

GrinSlaW

tnx m8 :-) it works
.:: AcExtreme ::. | .:: AcPro ::.

jiten

You're welcome...  :]

6Marilyn6Manson6


TTB

nice to know some ppl are trying this script. I have tested it, but it is disabled @ my hub atm (need to do some other things first).
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

Leun

Hi TTB

I get this little bug;

Syntax \scripts\IP Ranger from Thor 2.0.lua:7: function arguments expected near `='

I'm a newbie here, and I can't get my bug fixed.
Mabie it's my fault......

Hope you can fix it....

Scanning

#8
QuoteOriginally posted by Leun
Hi TTB

I get this little bug;

Syntax \scripts\IP Ranger from Thor 2.0.lua:7: function arguments expected near `='

I'm a newbie here, and I can't get my bug fixed.
Mabie it's my fault......

Hope you can fix it....

Copy the script from

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

Not from the top of the page :P

bluebear

TTB, i was wondering what purpose thease 2 lines has in the GetRange() function? (Other than not really being used :p)

local c = ""  

c = "1"
Sincerely,
bluebear
--
http://www.thewildplace.dk/ is is closed - Use the following mirrors instead
http://bluebear.psycho-chihuahua.net
http://pxextension.piratez.dk/
[Lua extensions - Chat stats - YnHub PMSpy - DC Source code - and more]

Leun

thnx Scanning

That was a stupid fault.....
But it's running now  :D

Thnx for your help

witch

hola guys nice script, but got this error:

[21:11] Syntax D:\PtokaX\![pz]0.3.3.21.nt.dbg\scripts\BanIpRange.lua:511: unfinished string near `"

   ???????????????????????????????????????????????????????????????????????????'
thx  :))



mateci

QuoteOriginally posted by witch

[21:11] Syntax D:\PtokaX\![pz]0.3.3.21.nt.dbg\scripts\BanIpRange.lua:511: unfinished string near `"

   ???????????????????????????????????????????????????????????????????????????'

i think it is because of c/p of script..


msg=msg.."\r\n   ___________________________________________________________________________
__________________________"
lines must be a line not two.

TTB

QuoteOriginally posted by bluebear
TTB, i was wondering what purpose thease 2 lines has in the GetRange() function? (Other than not really being used :p)

local c = ""  

c = "1"

Hi,

g00d question. I converted the script, I accually don't know why this is... NL made the script, I just converted it ;-)
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

witch

QuoteOriginally posted by mateci
QuoteOriginally posted by witch

[21:11] Syntax D:\PtokaX\![pz]0.3.3.21.nt.dbg\scripts\BanIpRange.lua:511: unfinished string near `"

   ???????????????????????????????????????????????????????????????????????????'

i think it is because of c/p of script..


msg=msg.."\r\n   ___________________________________________________________________________
__________________________"
lines must be a line not two.
yop u right mate, i removed the double lines and script started to work, till i added some ip ranges to DenyR.dat, than i got this error:

[21:35] Syntax ...]0.3.3.21.nt.dbg\scripts\IP Ranger from Thor 2.0.lua:44: bad argument #1 to `find' (string expected, got nil)



mateci

i will help u if u send DenyR table and when this error is coming(after a command or after a new user connected or after starting script)

thx

witch

QuoteOriginally posted by mateci
i will help u if u send DenyR table and when this error is coming(after a command or after a new user connected or after starting script)

thx
Thx a lot mateci for your replay.

here is DenyR.dat
DenyR = {

["80.xxx.xxx.xxx"] = "80.xxx.xxx.xxx",

}

this error comes when user conected:

[16:05] Syntax ...]0.3.3.21.nt.dbg\scripts\IP Ranger from Thor 2.0.lua:44: bad argument #1 to `find' (string expected, got nil)

thx in advince :)



mateci

U must add ipranges like this

DenyR = {

	["160.xxx.xxx.xxx-192.xxx.xxx.xxx"] = {
		[1] = "Network Name",
		[2] = {
			[1] = "[Network Name]",
		},
	},
}

Change "network name" with your identifier for The iprange( like A University)

or use simply the command

!addrange ip1-ip2 network allow(or deny if you want to add deny)

ip1-ip2                 --//like 160.xxx.xxx.xxx-192.xxx.xxx.xxx
network            --//identifier of range
allow or deny    --//to add where

example
!addrange 160.xxx.xxx.xxx-192.xxx.xxx.xxx Mateci allow

The other commands u can use

help
addrange
delrange
show
addisp
delisp

I hope it will be usefull

witch

yahooo now it's works fine !

but i locked my self and dunno how to unblock it.....lol, so i added DenyR.dat how u says, but i added my own ip range for a test. it blocked me to enter the hub, fine. but than i added defferent ip range insted mine, but damn i still can't log in on hub hehe :) than i added my ip range to AllowR.dat and now it's says that my ISP tag is wrong, but how it's posseble? cose ISP tag that says i'm have to use is seted up on AllowR.dat also. i thout that it's read from AllowR.dat what ISP tag is Allowed for my ip range....but it's not. or what i did wrong mate?


thx a lot mateci for your help and pations  :))



mateci

local ThorTagOK = GetISP(sUser,ISPTAG)

I think this is the problem. I can not find anything about ISPTAG table in script.. (Also dont find how can i fix.. )

witch

ok dude thx a lot for your help anyways, i gona look for another script or maybe u could recomend me some IP Range blocker?

thx  :P



mateci

I dont know any iprange blocker,sorry:(   Im newbie here(and also newbie for lua scripting), so dont see any script about that.

uffetjur

zitat:
-----------------------------------------------------------------------
yahooo now it's works fine !

but i locked my self and dunno how to unblock it.....lol, so i added DenyR.dat how u says, but i added my own ip range for a test. it blocked me to enter the hub, fine. but than i added defferent ip range insted mine, but damn i still can't log in on hub hehe  than i added my ip range to AllowR.dat and now it's says that my ISP tag is wrong, but how it's posseble? cose ISP tag that says i'm have to use is seted up on AllowR.dat also. i thout that it's read from AllowR.dat what ISP tag is Allowed for my ip range....but it's not. or what i did wrong mate?

-----------------------------------------------------------------------

as far as  I rememer Nightlitch used syntax

[ISP]nick for users, and [ISP] must be the one set in ipranger, and theres option to use more then 1 [ISP] for each range:


 !addisp    -   Add isp to range"
Somewhere in Cyberspace

ohm

[15:07] Syntax ...nd Settings\login\Desktop\test1\scripts\ipranger.lua:108: attempt to call a nil value

Also how do i make it so this script doesnt have to have isp's in the nick

TTB

QuoteOriginally posted by ohm
[15:07] Syntax ...nd Settings\login\Desktop\test1\scripts\ipranger.lua:108: attempt to call a nil value

Also how do i make it so this script doesnt have to have isp's in the nick

Line 108 is a clear line.... weird! And no isp >>

ISP_Check = 1

shoud be

ISP_Check = 0

grtz
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

SMF spam blocked by CleanTalk