PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: catwo on 26 May, 2005, 22:02:52

Title: IP informer to OPs
Post by: catwo on 26 May, 2005, 22:02:52
Hi is it possible to have a script that on a command i.e. !IPWatch a message box pops up for you to enter a users IP then on enter another box pops up with reason.  Then when the IP comes into the hub the script sends a message to OPs saying i.e. 192.168.1.1 Message = Disconnecting downloads without reason.  Any help would be most appreciated as always, many thanks in advance.
Title:
Post by: jiten on 26 May, 2005, 22:13:02
QuoteOriginally posted by catwo
Hi is it possible to have a script that on a command i.e. !IPWatch a message box pops up for you to enter a users IP then on enter another box pops up with reason.  Then when the IP comes into the hub the script sends a message to OPs saying i.e. 192.168.1.1 Message = Disconnecting downloads without reason.  Any help would be most appreciated as always, many thanks in advance.
Do you mean a script that notifies all OPs when a certain IP logs in, and, at the same time, disconnects all its downloads?
Title:
Post by: catwo on 26 May, 2005, 22:18:39
Yes reference the IP logging in but with added message of why IP was being watched.  i.e.  User IP was watched because he/she disconnected other users downloads without reason. Sorry for my previous explanation and many thanks for quick reply.
Title:
Post by: jiten on 27 May, 2005, 11:26:09
Give this a try:
--/------------------------------------------------------------
-- IP Monitoring v1.0 by jiten (5/27/2005)
--/------------------------------------------------------------

sBot = frmHub:GetHubBotName()
wIP = {} IPFile = "IP.tbl"

Main = function()
if loadfile(IPFile) then dofile(IPFile) end
end

ChatArrival = function(sUser,sData)
local sData = string.sub(sData, 1, -2)
local s,e,cmd = string.find(sData,"%b<>%s+[%!%?%+%#](%S+)")
if cmd then
local tCmds = {
["online"] = function(sUser,sData)
local s,e,IP,reason = string.find(sData,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if (IP == nil or reason == nil) then
sUser:SendData(sBot, "*** Syntax Error: Type !online ")
else
local _,_,a,b,c,d = string.find(IP,"(%d*).(%d*).(%d*).(%d*)")
if not (a == "" or b == "" or c == "" or d == "") then
if wIP[IP] == nil then
wIP[IP] = {} wIP[IP] = reason
sUser:SendData(sBot,IP.." is being sucessfuly monitored.") SaveToFile(IPFile,wIP,"wIP")
elseif wIP[IP] ~= nil then
sUser:SendData(sBot, "*** Error: "..IP.." is already being monitored.")
end
else
sUser:SendData(sBot, "*** Syntax Error: Type !online ")
end
end
end,
["ronline"] = function(sUser,sData)
local s,e,IP = string.find(sData,"%b<>%s+%S+%s+(%S+)")
local _,_,a,b,c,d = string.find(IP,"(%d*).(%d*).(%d*).(%d*)")
if (IP == nil) or (a == "" or b == "" or c == "" or d == "") then
sUser:SendData(sBot, "*** Syntax Error: Type !ronline ")
elseif wIP[IP] ~= nil then
wIP[IP] = nil
sUser:SendData(sBot,IP.." is no longer being monitored.") SaveToFile(IPFile,wIP,"wIP")
elseif wIP[IP] == nil then
sUser:SendData(sBot,"*** Error: "..IP.." isn't being monitored.")
end
end,
["sonline"] = function(sUser,sData)
if next(wIP) then
local msg = "\r\n\r\n".."\t??????????????????????????????????????????".."\r\n"
msg = msg.."\t\tMonitored IPs:\tReason:\r\n"
msg = msg.."\t??????????????????????????????????????????".."\r\n"
local i,v for i, v in wIP do msg = msg.."\t\t* "..i.."\t"..v.."\r\n" end
sUser:SendData(sBot,msg)
else
sUser:SendData(sBot,"*** Error: The IP monitoring list is empty.")
end
end,
}
if tCmds[cmd] and sUser.bOperator then return tCmds[cmd](sUser,sData),1 end
end
end

NewUserConnected = function(sUser,sData)
for i,v in wIP do
if i == sUser.sIP then SendPmToOps(frmHub:GetOpChatName(),os.date().." - "..sUser.sName.." is being monitored because: "..v)end
end
if sUser.bOperator then
sUser:SendData("$UserCommand 1 3 Online\\Monitor IP$<%[mynick]> !online %[line:IP] %[line:Reason]||")
sUser:SendData("$UserCommand 1 3 Online\\Remove IP$<%[mynick]> !ronline %[line:IP]||")
sUser:SendData("$UserCommand 1 3 Online\\Show IPs$<%[mynick]> !sonline||")
end
end

OpConnected = NewUserConnected

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in tTable do
if (type(value) ~= "function") then
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
end
hFile:write(sTab.."}");
end

SaveToFile = function(file,table,tablename)
local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()
end

Best regards,

jiten
Title:
Post by: catwo on 27 May, 2005, 16:18:04
Thank you very much jiten, i will test it now. :D
Title:
Post by: catwo on 27 May, 2005, 16:52:15
Hmmmm loads ok no errors in script however, how do i use it?  Thanks in advance. ?(
Sorry i just found it, many thanks.
Title:
Post by: catwo on 27 May, 2005, 17:14:59
It works fine many thanks.  Any chance of:
1.   As well as the IP, it wil also display the users nick?
2.   It could be added on the right click menu so that if a user in the userlist is selected on right mouse button menu, the users Nick and IP are automatically selected and then an input box pops up requesting the reason why the user is being watched?

Once again many thanks for the script and hope you can add the other 2 parts.  :D
Title:
Post by: jiten on 27 May, 2005, 17:59:20
QuoteOriginally posted by catwo
It works fine many thanks.  Any chance of:
1.   As well as the IP, it wil also display the users nick?
2.   It could be added on the right click menu so that if a user in the userlist is selected on right mouse button menu, the users Nick and IP are automatically selected and then an input box pops up requesting the reason why the user is being watched?

Once again many thanks for the script and hope you can add the other 2 parts.  :D
First post updated with those requests ;)

Best regards
Title:
Post by: catwo on 27 May, 2005, 19:20:12
Hi jiten a lot better thanks for the prompt response again but it asks for IP input, it doesn't automatically get the users IP and Nick. Also when the user rejoins it displays IP and Nick but the reason doesn't display fully it only displays the word testing as follows:
05/27/05 18:14:34 - [XXX]nick (192.1.1.100) is being monitored because: testing
but i actually typed "testing new script nick".  Once again thanks for your help.
Title:
Post by: jiten on 27 May, 2005, 19:33:54
QuoteOriginally posted by catwo
... it asks for IP input, it doesn't automatically get the users IP and Nick.
Well, the way the script is now, that's the only way.
For that to work, it would have to be based on user's nick and so, the script would need a "complete" rewrite. Something like: !online nick reason (and not IP). Is it really needed?
Also when the user rejoins it displays IP and Nick but the reason doesn't display fully First post updated with that fix.

Best regards.
Title:
Post by: catwo on 27 May, 2005, 20:16:26
I try it now many thanks again jiten its much appreciated. :D
Title:
Post by: catwo on 27 May, 2005, 21:18:57
Works perfect, thanks for your time and efforts jiten much appreciated. :D
Title:
Post by: jiten on 27 May, 2005, 21:39:10
You're welcome :]
Title:
Post by: catwo on 28 May, 2005, 07:31:20
jiten, how about in between the IP input box and the Reason input box you could add a users nick input box?  That would also be usefull.  Many thanks. :D
Title:
Post by: jiten on 28 May, 2005, 11:44:29
QuoteOriginally posted by catwo
jiten, how about in between the IP input box and the Reason input box you could add a users nick input box?  That would also be usefull.  Many thanks. :D
Can you explain it better?
Something like "!online nick reason" also?
Title:
Post by: catwo on 28 May, 2005, 11:59:21
Sorry jiten, currently the script on selection of !online/MonitorIP pops up an input box for me to enter a users IP then when i enter the ip and select OK the Reason input box pops up so i can input the reason why the user is being watched.  What i would like if possible is the following:
IP input box, Nick Input box, Reason Input box.  I hope i have explained it ok.  As always many thanks.
Title:
Post by: jiten on 28 May, 2005, 12:45:18
QuoteOriginally posted by catwo
Sorry jiten, currently the script on selection of !online/MonitorIP pops up an input box for me to enter a users IP then when i enter the ip and select OK the Reason input box pops up so i can input the reason why the user is being watched.  What i would like if possible is the following:
IP input box, Nick Input box, Reason Input box.  I hope i have explained it ok.  As always many thanks.
So, you mean that it had to pop up IP, Nick and Reason at the same time? That's not possible with the current script. As I explained you some posts above this one, I'd have to rewrite it for that to work.
Just to mention, it had to be like:
and not both at the same time.
Hope you got it.

Best regards
Title:
Post by: catwo on 28 May, 2005, 13:01:34
Ok no problem many thanks for the script. :D

How about adding this:

Currently on Ionline/ShowIPs produces this:

   ??????????????????????????????????????????
         Monitored IPs:
   ??????????????????????????????????????????
    * 192.168.1.1
    * 193.168.1.1

is it possible to also show reason like this?

   ??????????????????????????????????????????
         Monitored IPs:
   ??????????????????????????????????????????
    * 192.168.1.1               Slot locking
    * 193.168.1.1               Incorrect hub/slot ratio

Thanks once again.  ;)
Title:
Post by: jiten on 28 May, 2005, 22:20:55
First post updated with your request.

Cheers
Title:
Post by: catwo on 28 May, 2005, 22:50:56
PERFECT!, Thanks again jiten you are a star its much appreciated. :D
Title:
Post by: jiten on 29 May, 2005, 11:11:04
You're welcome :]
Title:
Post by: yoonohoo on 29 May, 2005, 21:44:25
Can you make the rightclick invisible to certain users?
As it is the reg can see the command although it cannot use it.
Thanks
Title:
Post by: jiten on 30 May, 2005, 09:08:53
First post updated with that fix.

Cheers
Title:
Post by: yoonohoo on 30 May, 2005, 11:48:06
Thanks once again jiten
Title:
Post by: chettedeboeuf on 31 May, 2005, 21:00:08
The reason doesn't appear :
?????????????????????????????????????????
   IPs surveill?es :
?????????????????????????????????????????
    * 127.0.0.1
    * 82.141.122.196
    * 85.217.1.75

Anybody have this problem ??
Title:
Post by: jiten on 31 May, 2005, 21:03:54
QuoteOriginally posted by chettedeboeuf
The reason doesn't appear :
?????????????????????????????????????????
   IPs surveill?es :
?????????????????????????????????????????
    * 127.0.0.1
    * 82.141.122.196
    * 85.217.1.75

Anybody have this problem ??
Try copying the script all over again and see if that happens.

Cheers
Title:
Post by: chettedeboeuf on 31 May, 2005, 21:23:39
I have tried this jiten, but nothing :
??????????????????????????????????????????
         Monitored IPs:
??????????????????????????????????????????
    * 82.141.122.196
    * 127.0.0.1
    * 85.217.1.75
    * 80.181.189.211

It's the wonder of catwo of having reason
But nothing in my hub

Sorry for my poor english and thank you for your help
Title:
Post by: jiten on 31 May, 2005, 21:39:47
QuoteOriginally posted by chettedeboeuf
I have tried this jiten, but nothing :
Sorry, my bad. I had copied the first script and it didn't include those changes. Guess it's ok now. :D
You may try it now.

Cheers
Title:
Post by: chettedeboeuf on 31 May, 2005, 21:43:24
Than you (Again !!!) jiten
Title:
Post by: catwo on 01 June, 2005, 20:00:46
--/------------------------------------------------------------

-- IP Monitoring v1.0 by jiten (5/27/2005)

-- Small personal edits by catwo (6/01/2005
--/------------------------------------------------------------



sBot = frmHub:GetHubBotName()

wIP = {} IPFile = "IP.tbl"



Main = function()

   if loadfile(IPFile) then dofile(IPFile) end

end



ChatArrival = function(sUser,sData)

   local sData = string.sub(sData, 1, -2)

   local s,e,cmd = string.find(sData,"%b<>%s+[%!%?%+%#](%S+)")

   if cmd then

      local tCmds = {

      ["online"] =   function(sUser,sData)

               local s,e,IP,reason = string.find(sData,"%b<>%s+%S+%s+(%S+)%s+(.*)")

               if (IP == nil or reason == nil) then

                  sUser:SendData(sBot, "*** Syntax Error: Type !online ")

               else

                  local _,_,a,b,c,d = string.find(IP,"(%d*).(%d*).(%d*).(%d*)")

                  if not (a == "" or b == "" or c == "" or d == "") then

                     if wIP[IP] == nil then

                        wIP[IP] = {} wIP[IP] = reason

                        sUser:SendData(sBot,IP.." is being sucessfuly monitored.") SaveToFile(IPFile,wIP,"wIP")

                     elseif wIP[IP] ~= nil then

                        sUser:SendData(sBot, "*** Error: "..IP.." is already being monitored.")

                     end

                  else

                     sUser:SendData(sBot, "*** Syntax Error: Type !online ")

                  end

               end

            end,

      ["ronline"] =   function(sUser,sData)

               local s,e,IP = string.find(sData,"%b<>%s+%S+%s+(%S+)")

               local _,_,a,b,c,d = string.find(IP,"(%d*).(%d*).(%d*).(%d*)")

               if (IP == nil) or (a == "" or b == "" or c == "" or d == "") then

                  sUser:SendData(sBot, "*** Syntax Error: Type !ronline ")

               elseif wIP[IP] ~= nil then

                  wIP[IP] = nil

                  sUser:SendData(sBot,IP.." is no longer being monitored.") SaveToFile(IPFile,wIP,"wIP")

               elseif wIP[IP] == nil then

                  sUser:SendData(sBot,"*** Error: "..IP.." isn't being monitored.")

               end

            end,

      ["sonline"] =   function(sUser,sData)

               if next(wIP) then

                  local msg = "\r\n\r\n".."\????????????????????????????????????????????????????????????????????????????????????".."\r\n"
                  msg = msg.."\Monitored IP:\t\tReason:\r\n"
                  msg = msg.."\????????????????????????????????????????????????????????????????????????????????????".."\r\n"
                  local i,v for i, v in wIP do msg = msg.."*   "..i.."\t\t"..v.."\r\n" end
                  
                  sUser:SendData(sBot,msg)

               else

                  sUser:SendData(sBot,"*** Error: The IP monitoring list is empty.")

               end

            end,

      }

      if tCmds[cmd] and sUser.bOperator then return tCmds[cmd](sUser,sData),1 end

   end

end



NewUserConnected = function(sUser,sData)

   for i,v in wIP do

      if i == sUser.sIP then SendPmToOps(frmHub:GetOpChatName(),os.date().." - "..sUser.sName.." ("..i..") is being monitored because: "..v)end

   end

   if sUser.bOperator then

      sUser:SendData("$UserCommand 1 3 Online\\Monitor IP$<%[mynick]> !online %[line:UsersIP] %[line:UsersNick/Reason/Date/OPsName]||")

      sUser:SendData("$UserCommand 1 3 Online\\Remove IP$<%[mynick]> !ronline %[line:IP]||")

      sUser:SendData("$UserCommand 1 3 Online\\Show IPs$<%[mynick]> !sonline||")
   end
end



OpConnected = NewUserConnected



Serialize = function(tTable,sTableName,hFile,sTab)

   sTab = sTab or "";

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

   for key,value in tTable do

      if (type(value) ~= "function") then

         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

   end

   hFile:write(sTab.."}");

end



SaveToFile = function(file,table,tablename)

   local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close()

end

This is what i have and it works perfect ALL CREDIT to jiten.  My edit is just names on input boxes for OPs to all input the reason the same and left screen alignment.
Title:
Post by: chettedeboeuf on 02 June, 2005, 08:45:14
With catwo's modif :
[08:45] Syntax D:\Program Files\Hub PtokaX\HUB 0.3.3.0 17.08\scripts\IP Monitoring.lua:98: unexpected symbol near `&'
Title:
Post by: jiten on 02 June, 2005, 09:54:25
QuoteOriginally posted by chettedeboeuf
With catwo's modif :
[08:45] Syntax D:\Program Files\Hub PtokaX\HUB 0.3.3.0 17.08\scripts\IP Monitoring.lua:98: unexpected symbol near `&'
Replace & quot;\ with " in lines 98 and 100 and the error should be gone.

Cheers
Title:
Post by: catwo on 03 June, 2005, 17:32:33
Hmmm how come i don't get that error then? Strange things these PCs! :D