PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: NemeziS on 14 June, 2005, 00:59:33

Title: block download if user IP is not in IP range.
Post by: NemeziS on 14 June, 2005, 00:59:33
Hi, i need a script that will allow download for users whose IPs are in IP range (and block download for users whose IP are not in IP range

This is the content of my ranges.txt file:
127.0.0.1|127.0.0.1
10.0.0.0|10.255.255.255
81.211.62.0|81.211.62.255
172.16.0.0|172.31.255.255
192.168.0.0|192.168.255.255
194.154.83.0|194.154.83.255
213.33.170.0|213.33.170.255
213.85.12.0|213.85.12.255
213.85.47.0|213.85.47.255


Respectfully,
NemeziS
Title:
Post by: NemeziS on 15 June, 2005, 00:08:55
Please!  :)
Title:
Post by: jiten on 15 June, 2005, 09:37:49
Check this (http://board.univ-angers.fr/thread.php?threadid=4334&boardid=29&sid=ca04aa4575737aec38b90880476dcfbe) one.

Cheers
Title:
Post by: NemeziS on 16 June, 2005, 10:21:10
Thanx, I'll try it!  :)

[*edit]  
I tested this script. (I need a variant in lua4). And it not works correctly.

So, thats my idea. I need a script in lua4 that will block downloads/uploads from users, whose ips are NOT in ip range or who hasn't got the prefix [Anlim], BUT every user (including [Anlim] users) which ip is IN ip range  could download and upload normally.

SO:
1)  If user has the prefix [Anlim] AND his ip is in IP range then he can both download and upload
2)  If user has the prefix [Anlim] AND his ip is NOT in IP range then he can't download and upload.
3)  If user has no prefix or it's not [Anlim] AND his IP is in IP range he can both upload and download, but the users without IP in IP range can't download from him (user with ip in IP range can't upload to him).

I have already tryed to write a script and here are the results:

--//Some code grabbed from RangeBlaster by Phatty

Ranges = {}

BlockTriggs = {
["$Rev"] = 1,
["$Con"] = 2,
}

function Main()
frmHub:EnableFullData(1)
LoadIps()
end

function LoadIps()
local tmp = 0
local handle = openfile("txt/Ranges.txt","r")
line = read(handle)
while line do
tmp = tmp + 1
local s,e,ipr1,ipr2 = strfind(line,"(%S+)|(%S+)")
if ipr2 == nil then
end
Ranges[ipr1] = ipr2
line = read(handle)
end
end

function Allowed(userip)
local s,e,range1,range2,range3,range4 = strfind(userip,"(%d+).(%d+).(%d+).(%d+)")
for i,p in Ranges do
local s,e,ipa1,ipb1,ipc1,ipd1 = strfind(i, "(%d*).(%d*).(%d*).(%d*)")
local s,e,ipa2,ipb2,ipc2,ipd2 = strfind(p, "(%d*).(%d*).(%d*).(%d*)")
if range1 == ipa1 then
if range1 < ipa1 or range1 > ipa2 then
else
if range2 < ipb1 or range2 > ipb2 then
else
if range3 < ipc1 or range3 > ipc2 then
else
if range4 < ipd1 or range4 > ipd2 then
else
collectgarbage()
flush()
return 1
end
end
end
end
end
end
end

function DataArrival(user,data)
if strsub(data,1,1) == "$" then
local str1 = strsub(data,1,4)
if BlockTriggs[str1] then
if BlockTriggs[str1] == 1 then
local _,_,conNick = strfind(data,"(%S+)|$")
local usr = GetItemByName(conNick)
if (Allowed(usr.sIP) == nil) then
return 1
end
elseif BlockTriggs[str1] == 2 then
local _,_,conNick = strfind(strsub(data,14,strlen(data)),"^(%S+)")
local usr = GetItemByName(conNick)
if (Allowed(usr.sIP) == nil) then
return 1
end
end
end
end
end

Please help me. It's very important  because users who upload information to users whose ips in not ip range have to pay  for every Megabyte they have uploaded.

Sorry about my English. It sucks. :(

Respectfully,
NemeziS