IP-Shield
 

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-Shield

Started by Dessamator, 06 May, 2005, 19:40:55

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dessamator

-------------------------------------------------------------------------------------------
-- Added : Tag Check(request by Alexinno), removed GetCom , fixed RC / 2006-06-17
-- Lua 5 version by Dessamator
-- added user commands (right clicks)
-- File handling fixed by jiten
-- IP-Shield / Version: 1.0 / By: NightLitch / 2004-03-09
-------------------------------------------------------------------------------------------
-- Example to add a range:
-- !addrange 192.168.0.1-192.168.0.255 Local
-------------------------------------------------------------------------------------------
BotName = "-IP-Shield-"
Prefix = "!"
-------------------------------------------------------------------------------------------
AllowRange = {}
AllowFile = "Ranges/Ranges.dat"
Redirect = true -- To redirect a user true/false
RedirAddy ="typeaddresshere" --redirect address
-------------------------------------------------------------------------------------------
function Main()
	frmHub:RegBot(BotName)
	if loadfile(AllowFile) then dofile(AllowFile)? 
? ? ? ? else
? ? ? ? 	os.execute("mkdir Ranges") -- creates a folder if it doesnt exist
? ? ? ? 	io.output(AllowFile) 
? ? ? ? end
end
-------------------------------------------------------------------------------------------
function ComputeIP(curIP)
	local _,_,a,b,c,d = string.find(curIP, "(%d+).(%d+).(%d+).(%d+)")
	return a*16777216 + b*65536 + c*256 + d
end
-------------------------------------------------------------------------------------------
function GetRange(ip,tTable)
	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 pairs(tTable) 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,string.lower(tTable[r]["NETWORK"])
				end
			end
		end
	end
end
-------------------------------------------------------------------------------------------
function NewUserConnected(curUser)
	curUser:SendData(BotName,"Running IP-Shield 1.0 By: NightLitch")
	local Allow,Range,Network = GetRange(curUser.sIP,AllowRange)
	if Allow then
		if not( string.find(string.lower(curUser.sName),"(%b["..Network.."])"))? then
			curUser:SendData(BotName,"You are from "..Network.." network your nick must be ["..Network.."]"..curUser.sName)
				curUser:Disconnect()
		else
			curUser:SendData(BotName,"Your IP is Allowed here...")
		end
	else
		if Redirect then
			curUser:SendData(BotName,"Your IP is not Allowed here...")
			curUser:SendData("$ForceMove "..RedirAddy)
		else
			curUser:Disconnect()
		return 1
		end
	end	
end
-------------------------------------------------------------------------------------------
function OpConnected(curUser)
	if curUser.iProfile==0 then
		curUser:SendData("$UserCommand 255 1")
		curUser:SendData("$UserCommand 1 3 IP Shield\\Addrange$$To: "..BotName.." From: %[mynick] $<%[mynick]> !addrange %[line:range] %[line:network]&#124;")
		curUser:SendData("$UserCommand 1 3 IP Shield\\Delrange$$To: "..BotName.." From: %[mynick] $<%[mynick]> !delrange %[line:range]&#124;")
		curUser:SendData("$UserCommand 1 3 IP Shield\\Findip$$To: "..BotName.." From: %[mynick] $<%[mynick]> !findip %[line:ip]&#124;")
		curUser:SendData("$UserCommand 1 3 IP Shield\\Show Ranges$$To: "..BotName.." From: %[mynick] $<%[mynick]> !show&#124;")
		curUser:SendData("$UserCommand 1 3 IP Shield\\Display Help$$To: "..BotName.." From: %[mynick] $<%[mynick]> !help&#124;")
	end
end
-------------------------------------------------------------------------------------------
function ToArrival(curUser, data)
	local s,e,to,from,text = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s$(.*)|$")
	if to == BotName then
		local _,_,cmd = string.find(text,"^%b<>%s+%"..Prefix.."(%S+)")
		if cmd and IPCommand[cmd] and curUser.iProfile==0 then
			local Com = IPCommand[cmd](curUser,text)
			return 1
		end
	end
end
-------------------------------------------------------------------------------------------
IPCommand = {
["addrange"] =	function(curUser,data) 
			local _,_,range,network = string.find(data,"%b<>%s+%S+%s+(%S+-%S+)%s+(%S+)")
			if range==nil or network==nil then
				curUser:SendPM(BotName,"Syntax: "..Prefix.."addrange ")
				return 1
			end
			if AllowRange[range] then
				curUser:SendPM(BotName,range.." is already in Allow File...")
				return 1
			end
			AllowRange[range] = {["NETWORK"] = network,["TAG"] = {"["..network.."]"}}
			SaveToFile(AllowFile , AllowRange , "AllowRange")
			curUser:SendPM(BotName,"Range: ( "..range.." ) - Network: "..network.." is added to Allow File")
			return 1
		end,
["delrange"] =	function(curUser,data)
			local _,_,range = string.find(data,"%b<>%s+%S+%s+(%S+-%S+)")
			if range==nil then
				curUser:SendPM(BotName,"Syntax: "..Prefix.."delrange ")
				return 1
			end
			if AllowRange[range] then
				AllowRange[range] = nil
				SaveToFile(AllowFile , AllowRange , "AllowRange")
				curUser:SendPM(BotName,"Range: ( "..range.." ) is deleted from Allow File.")
				return 1
			else
				curUser:SendPM(BotName,"Range: ( "..range.." ) is not found in Allow File.")
				return 1
			end
		end,
["show"] =	function(curUser,data)
			local Network,border = "",string.rep("-",15)..string.rep("=",100)..string.rep("-",15)
			local Msg = "\r\n\r\n"
			.. "\r\n	Allow Range's "
			.. "\r\n "..border..""
			.. "\r\n	? ? Network			Range	"
			.. "\r\n"
			local Nr = 0
			for Range,Index in pairs(AllowRange) do
				local Network = ""
				local ISP = ""
				local tmp = AllowRange[Range]
				if tmp then
					Network = tmp["NETWORK"]
					Nr = Nr +1
					Msg = Msg .. "\r\n	 "..Network.." "..string.rep("\t", 45/(8+string.len(Network))).." "..Range.." "
				end
			end
			Msg = Msg .. "\r\n "
			.. "\r\n	Total "..Nr.." Range(s)"
			.. "\r\n "..border..""
			curUser:SendPM(BotName,Msg)
			return 1
		end,
["findip"] =	function(curUser,data)
			local _,_,GetIP = string.find(data,"%b<>%s+%S+%s+(%S+)")
			if GetIP==nil then
				curUser:SendPM(BotName,"Syntax: "..Prefix.."findip ")
				return 1
			end
			if loadfile(AllowFile) then dofile(AllowFile) end
			local Msg = "\r\n\r\n"
			.. "\r\n	Result on IP ( "..GetIP.." ) :\r\n"
			local Allow,Range = GetRange(GetIP,AllowRange)
			local Network = ""
			if Allow==1 then
				local tmp = AllowRange[Range]
				if tmp then
					Network = tmp["NETWORK"]
				end
				Msg = Msg .. "\r\n	Range: "..Range..""
				.. "\r\n	Network: "..Network.." \r\n\r\n"
				curUser:SendPM(BotName,Msg)
			else
				curUser:SendPM(BotName,"Syntax: IP not found...")
				return 1
			end
		end,
["help"] =	function(curUser,data)
		
			local Msg,border = "\r\n\r\n",string.rep("-",15)..string.rep("=",100)..string.rep("-",15)
			Msg=Msg.. "\r\n				 IP-Shield Command Help "
			.. "\r\n "..border..""
			.. "\r\n "
			.. "\r\n	"..Prefix.."help			-	Show this Help"
			.. "\r\n	"..Prefix.."addrange 		-	Add Range"
			.. "\r\n	"..Prefix.."delrange 			-	Del Range"
			.. "\r\n	"..Prefix.."show			-	Show Ranges "
			.. "\r\n	"..Prefix.."findip 			-	Find IP in Range File"
			.. "\r\n "
			.. "\r\n "..border..""
			.. "\r\n\r\n "
			curUser:SendPM(BotName,Msg)
			return 1
		end,
}
-------------------------------------------------------------------------------------------
function Serialize(tTable, sTableName, hFile, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(hFile, "hFile equals nil");

	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");

	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n" );

	for key, value in pairs(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 SaveToFile(file , table , tablename)
	local hFile = io.open(file, "w+");
	Serialize(table, tablename, hFile);
	hFile:close();
end
-------------------------------------------------------------------------------------------
-- By: NightLitch 2004-03-09


Post Edited
Ignorance is Bliss.

Therion

hello

it looks like the script working
but i cant get it to respond in the ptokax hub soft
does i need to do anything else to get it to work ?

for example when i type !whois ip nothing happends ?? :)



very pleased for help

Thanks in Advance ///Therion

jiten

--
#2
QuoteOriginally posted by Therion
hello

it looks like the script working
but i cant get it to respond in the ptokax hub soft
does i need to do anything else to get it to work ?

for example when i type !whois ip nothing happends ?? :)



very pleased for help

Thanks in Advance ///Therion
Try using the commands in PM. It should work.
Btw, the commands are the ones in the IPCommand table.

Best regards,

jiten

Dessamator

#3
hmm, maybe i should add chatarrival, many users wont know how to use it,in  the way it currently is
Ignorance is Bliss.

BeeR

--
#4
QuoteOriginally posted by Dessamator
hmm, maybe i should add chatarrival, many users wont know how to use it,in  the way it currently is

Hi ,, can u plz make an option to disconnect/redirect
users with not allowed ip
A cold BeeR is stunning !!

TTB

Add this line...
curUser:SendData("$ForceMove "..frmHub:GetRedirectAddress() )

OK, here is the function you need to replace... Remove the old one, and put this function in the script:

function NewUserConnected(curUser,data)
	curUser:SendData(BotName,"Running IP-Shield 1.0 By: NightLitch")
	local Allow,Range,Network = GetRange(curUser.sIP,AllowRange),""
	if Allow==1 then 
		curUser:SendData(BotName,"Your IP is Allowed here...")
		return 1
	else
		curUser:SendData(BotName,"Your IP is not Allowed here...")
		curUser:SendData("$ForceMove "..frmHub:GetRedirectAddress() )
		curUser:Disconnect()
		return 1
	end
end

It will take the redirect from PtokaX.
TTB

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

Dessamator

--
#6
QuoteOriginally posted by BeeR
QuoteOriginally posted by Dessamator
hmm, maybe i should add chatarrival, many users wont know how to use it,in  the way it currently is

Hi ,, can u plz make an option to disconnect/redirect
users with not allowed ip

Done ! -->post edited above
Ignorance is Bliss.

Therion

even if i use the command in PM it dosent respond

does it nedd anything more then the lua file to work ? such as a .ini or something

please help me agin =)


///Therion

Dessamator

--
#8
QuoteOriginally posted by Therion
even if i use the command in PM it dosent respond

does it nedd anything more then the lua file to work ? such as a .ini or something

please help me again =)


///Therion

PM to the bot, it doesnt need any exra file, but it does need that u have a profile of number of 0, normally that profile refers to a master !
Ignorance is Bliss.

Therion

thanks a lot i didnt think of the profiles in set to netfounder so

thanks again but i didnt get the !whois commando to work ?

bastya_elvtars

--
#10
QuoteOriginally posted by Therion
thanks a lot i didnt think of the profiles in set to netfounder so

thanks again but i didnt get the !whois commando to work ?

!whois needs luasockets, thus won't work, because that is not in new ptokax.
Everything could have been anything else and it would have just as much meaning.

Dessamator

--
#11
QuoteOriginally posted by bastya_elvtars
QuoteOriginally posted by Therion
thanks a lot i didnt think of the profiles in set to netfounder so

thanks again but i didnt get the !whois commando to work ?

!whois needs luasockets, thus won't work, because that is not in new ptokax.

yep, ur right ill remove it from the script !
Ignorance is Bliss.

Therion

oki sad that !whois not work in new ptokax. why they remowed that ?

Dessamator

#13
they didnt remove that in ptokax, the new lua 5 doesnt have it, :)
btw, post edited added user commands, easier access,:)
Ignorance is Bliss.

Alexinno

the right click doesn't work :)
can you fix it pls

10q

Alexinno

Dessamator could you add another function to the script ?
I need something like this
let's pretend I added a range 81.180.171.1-81.180.171.255 to network It4web
so when the users from that network will connect to the hub they'll  receive a msg like this

You are from It4web network your nick mut be [It4web]nick


if not , disconnected

10q again in advance

Dessamator

Quote from: Alexinno on 17 June, 2006, 23:09:09
Dessamator could you add another function to the script ?
I need something like this
let's pretend I added a range 81.180.171.1-81.180.171.255 to network It4web
so when the users from that network will connect to the hub they'll? receive a msg like this

You are from It4web network your nick mut be [It4web]nick


if not , disconnected

10q again in advance

Done.
Ignorance is Bliss.

Alexinno

14:37] <-IP-Shield-> You are from it4web network your nick must be [it4web][I.G.]alex

it's working nice work m8
you forgot the
curUser:Disconnect()
to make them fix the nick

function NewUserConnected(curUser)
	curUser:SendData(BotName,"Running IP-Shield 1.0 By: NightLitch")
	local Allow,Range,Network = GetRange(curUser.sIP,AllowRange)
	if Allow then
		if not( string.find(string.lower(curUser.sName),"(%b["..Network.."])"))  then
			curUser:SendData(BotName,"You are from "..Network.." network your nick must be ["..Network.."]"..curUser.sName)
		        curUser:Disconnect()


[14:52] <-IP-Shield-> Running IP-Shield 1.0 By: NightLitch
[14:52] <-IP-Shield-> You are from it4web network your nick must be [it4web][I.G.]alex
[14:52] *** Disconnected

Dessamator

Ignorance is Bliss.

Alexinno

i have a problem with this script because it checks the prefix for the nick
You are from It4web network your nick must be [It4web]nick


but if i change my nick with [RO][CJ][It4web]nick the script will let me in , and i don't want that, i want that the users can connect to the hub only with the prefix in front of the nick
[It4web]nick


Anybody knows how can i make this to work ???

jiten

Quote from: Alexinno on 10 July, 2006, 08:41:12
i have a problem with this script because it checks the prefix for the nick

This is just a quick mod, but it should solve your problem.

Replace your existing NewUserConnected function with this one:

function NewUserConnected(curUser)
	curUser:SendData(BotName,"Running IP-Shield 1.0 By: NightLitch")
	local Allow,Range,Network = GetRange(curUser.sIP,AllowRange)
	if Allow then
		local _,_, sPrefix = string.find(string.lower(curUser.sName), "^(%b["..Network.."])")
		if not sPrefix then
			curUser:SendData(BotName,"You are from "..Network.." network your nick must be ["..Network.."]"..curUser.sName)
			curUser:Disconnect()
		else
			curUser:SendData(BotName,"Your IP is Allowed here...")
		end
	else
		if Redirect then
			curUser:SendData(BotName,"Your IP is not Allowed here...")
			curUser:SendData("$ForceMove "..RedirAddy)
		else
			curUser:Disconnect()
			return 1
		end
	end	
end

Alexinno

#21
10q jiten , it's worikng fine , but it's checking the VIP's too  ::)

jiten

Use this quickly modded function instead then:

function NewUserConnected(curUser)
	if curUser.iProfile ~= GetProfileIdx("VIP") then
		curUser:SendData(BotName,"Running IP-Shield 1.0 By: NightLitch")
		local Allow,Range,Network = GetRange(curUser.sIP,AllowRange)
		if Allow then
			local _,_, sPrefix = string.find(string.lower(curUser.sName), "^(%b["..Network.."])")
			if not sPrefix then
				curUser:SendData(BotName,"You are from "..Network.." network your nick must be ["..Network.."]"..curUser.sName)
				curUser:Disconnect()
			else
				curUser:SendData(BotName,"Your IP is Allowed here...")
			end
		else
			if Redirect then
				curUser:SendData(BotName,"Your IP is not Allowed here...")
				curUser:SendData("$ForceMove "..RedirAddy)
			else
				curUser:Disconnect()
				return 1
			end
		end	
	end
end

Alexinno


SMF spam blocked by CleanTalk