PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: ConejoDelMal on 28 April, 2005, 13:52:18

Title: Traffic blocking if special reasons
Post by: ConejoDelMal on 28 April, 2005, 13:52:18
hi, i need some help...
i have this script:

sBot = "-=Brainu=-"

sOpChatName = "-=OpChat=-"


--## Configuration ##--

-- Put in this table the Prefixes you want the users to have
 
sPrefix = { "[CV]" , "(CV)" ,}

-- Put in this table the IP-Range or IP you want to be checked for

arrIP = {
   ["10.6.0.0"] = "10.6.0.30",
   ["84.90.0.0"] = "84.91.255.255",      --  Cabovisao,SA
   ["213.228.128.0"] = "213.228.191.255",   --  Cabovisao,SA
   ["217.129.0.0"] = "217.129.255.255",      --  Cabovisao,SA
}

--## END ##--

function Main()
   frmHub:RegBot(sBot)
end

function NewUserConnected(user)
   if (CheckUserPrefix(user) == nil) and not (isGoodIP(user.sIP) == nil) then
      user:SendPM(sBot, "Inclui o prefixo [CV] ou (CV) no teu nick, isto porque o Sapo Adsl conta como internacional o trafego de ti")
      user:SendPM(sBot, "Se precisares de ajuda, ou tiveres d?vidas contacta um Operador")
      SendPmToOps(sOpChatName, "O utilizador "..user.sName.." foi requisitado para usar o prefixo [CV]")
   end
end

OpConnected = NewUserConnected

function CheckUserPrefix(user)
for key,pre in sPrefix do
if string.find(string.lower(user.sName), string.lower(pre),1,1) then
return 1
end
end


function isGoodIP(sIP)
   sIP = ipToNumber(sIP)
   local iFirst,iLast
   for iFirst, iLast in arrIP do
      if (sIP >= ipToNumber(iFirst) and sIP <= ipToNumber(iLast)) then
         return 1
      end
   end
   return nil
end

function ipToNumber(sIP)
   iAux = ""
   string.gsub(sIP,"(%d+)", function(w)
      w = tonumber(w)
      if (w < 10) then
         iAux = iAux.."00"..w
      elseif (w < 100) then
         iAux = iAux.."0"..w
      else
         iAux = iAux..w
      end
   end)
   return tonumber(iAux)
end
end

and i want that the users with an ip belonging to that range, and if they dont use the tag [CV] or (CV) get blocked uploads and downloads.... I've been trying, but without success
thx
Title:
Post by: jiten on 28 April, 2005, 20:05:10
Here you go (not tested):
-- modded by jiten

sBot = "-=Brainu=-"

sOpChatName = "-=OpChat=-"


--## Configuration ##--

-- Put in this table the Prefixes you want the users to have
 
sPrefix = { "[CV]" , "(CV)" ,}

-- Put in this table the IP-Range or IP you want to be checked for

arrIP = {
   ["10.6.0.0"] = "10.6.0.30",
   ["84.90.0.0"] = "84.91.255.255",      --  Cabovisao,SA
   ["213.228.128.0"] = "213.228.191.255",   --  Cabovisao,SA
   ["217.129.0.0"] = "217.129.255.255",      --  Cabovisao,SA
}
--## END ##--

function Main()
frmHub:RegBot(sBot)
end

function NewUserConnected(user)
if (CheckUserPrefix(user) == nil) and not (isGoodIP(user.sIP) == nil) then
user:SendPM(sBot, "Inclui o prefixo [CV] ou (CV) no teu nick, isto porque o Sapo Adsl conta como internacional o trafego de ti")
user:SendPM(sBot, "Se precisares de ajuda, ou tiveres d?vidas contacta um Operador")
SendPmToOps(sOpChatName, "O utilizador "..user.sName.." foi requisitado para usar o prefixo [CV]")
end
end

OpConnected = NewUserConnected

function ConnectToMeArrival(user,data)
if (CheckUserPrefix(user) == nil) and not (isGoodIP(user.sIP) == nil) then
user:SendData(sBot, "N?o podes fazer downloads/uploads at? mudares o teu prefixo para [CV] ou (CV)")
return 1
end
end

RevConnectToMeArrival = ConnectToMeArrival

function CheckUserPrefix(user)
for key,pre in sPrefix do
if string.find(string.lower(user.sName), string.lower(pre),1,1) then
return 1
end
end
end

function isGoodIP(sIP)
sIP = ipToNumber(sIP)
local iFirst,iLast
for iFirst, iLast in arrIP do
if (sIP >= ipToNumber(iFirst) and sIP <= ipToNumber(iLast)) then
return 1
end
end
return nil
end

function ipToNumber(sIP)
iAux = ""
string.gsub(sIP,"(%d+)", function(w)
w = tonumber(w)
if (w < 10) then
iAux = iAux.."00"..w
elseif (w < 100) then
iAux = iAux.."0"..w
else
iAux = iAux..w
end
end)
return tonumber(iAux)
end

Best regards,

jiten
Title:
Post by: ConejoDelMal on 28 April, 2005, 20:53:11
lol....thx a lot jiten, i was already making it complicated, trying to add users to tables..  :D

*edited*
working great, once again, thx a lot!! u rule : :P
Title:
Post by: jiten on 29 April, 2005, 13:57:50
anytime m8 ;)
Title:
Post by: ConejoDelMal on 29 April, 2005, 15:43:28
can somebody now help me to make it work in lua 4?
i modded another script, mixtured with this one, but its not blocking the uploads, just the downloads
sBot = "-=Brainu=-"

sOpChatName = "-=OpChat=-"




--## Configuration ##--

-- Put in this table the Prefixes you want the users to have
 
sPrefix = { "[CV]" , "(CV)" ,}

-- Put in this table the IP-Range or IP you want to be checked for

IPS = {
"CV-84.90.0.0-84.91.255.255",      --  Cabovisao,SA
"CV-213.228.128.0-213.228.191.255",   --  Cabovisao,SA
"CV-217.129.0.0-217.129.255.255",      --  Cabovisao,SA
}

--## END ##--

function Main()
   frmHub:RegBot(sBot)
   frmHub:EnableFullData(1)
end

function CheckIP(sIP)
local s,e
ip = ComputeIP(sIP)
for i=1, getn(IPS) do
_,_,s,e = strfind(IPS[i], "%S+-(%S+)-(%S+)")
s = ComputeIP(s)
e = ComputeIP(e)
if ip>=s and ip<=e then
return i
end
end
return nil
end

function ComputeIP(sIP)
local a,b,c,d
_,_,a,b,c,d = strfind(sIP, "(%d+).(%d+).(%d+).(%d+)")
return a*16777216 + b*65536 + c*256 + d
end


function NewUserConnected(user)
   local i = CheckIP(user.sIP)
   if not i == nil then
     if (CheckUserPrefix(user) == nil) then
      user:SendPM(sBot, " ")
      user:SendPM(sBot, "Inclui o prefixo [CV] ou (CV) no teu nick, ex: [PT][CV]nick, isto porque o Sapo Adsl conta como internacional o tr?fego de ti")
      user:SendPM(sBot, "Por motivos de seguran?a o teu tr?fego est? bloqueado at? fazeres a altera??o. Se precisares de ajuda, ou tiveres d?vidas contacta um Operador")
     end
   end
end

OpConnected = NewUserConnected

function DataArrival(user, data)
local i = CheckIP(user.sIP)
if (CheckUserPrefix(user) == nil) and not i == nil then

if (strsub(data,1,15) == "$RevConnectToMe") then
local s,e,to,from = strfind(data, "$RevConnectToMe%s+(%S+)%s+(%S+)")
if (CheckUserPrefix(user) == nil) and not i == nil then
user:SendData(sBot, "N?o podes fazer downloads/uploads at? incluires o prefixo [CV] ou (CV) no teu nick")
return 1
end
end
if (strsub(data,1,12) == "$ConnectToMe") then
local s,e,from,toip = strfind(data, "$ConnectToMe%s+(%S+)%s+(%d+%.%d+%.%d+%.%d+):")
if (CheckUserPrefix(user) == nil) and not i == nil then
user:SendData(sBot, "N?o podes fazer downloads/uploads at? incluires o prefixo [CV] ou (CV) no teu nick")
return 1
end
end
end
end


function CheckUserPrefix(user)
for key,pre in sPrefix do
if strfind(strlower(user.sName), strlower(pre),1,1) then
return 1
end
end
end

*edited*
well...nevermind, not being able to download makes them to change the prefix instantly....though they need to be blocked, lazy people...  :D