Author Topic: Iplog/ipsearch  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

Offline ExtreeM

  • Forum Ace
  • *****
  • Posts: 83
  • Karma: +33/-6
Iplog/ipsearch
« on: 07 February, 2008, 12:19:52 »
i would like to request a little script that logs all ip who entered the hub, and you can search for an ip among the logged ip?s and get the users nick too

PtokaX forum

Iplog/ipsearch
« on: 07 February, 2008, 12:19:52 »

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: Iplog/ipsearch
« Reply #1 on: 07 February, 2008, 18:03:54 »
Code: [Select]
-- IPLog/IPsearch Script [API 2]
-- Made by speedX   (Requested by ExtreeM)
-- includes jiten's serialize function and some code bits from Mutor's scripts
-- Added Rightclick menu  (Requested by ExtreeM)

-- File Name
fIPFile = "IPLog.tbl"

-- Bot Name
sBot = SetMan.GetString(21)

-- Search Command
IPsearch = "ip"

OnStartup = function()
  if loadfile(fIPFile) ~= nil then dofile(fIPFile)
  else
    UserIP = {}
    SaveToFile(fIPFile, UserIP, "UserIP")
  end
  if sBot ~= SetMan.GetString(21) then Core.RegBot(sBot,"","",true) end
end

UserConnected = function(user)
  Core.SendToNick(user.sNick,"<"..sBot.."> Welcome "..user.sNick..", speedX's IPLog 1.0 is enabled. RightClick for menu.")
  UserIP[string.lower(user.sNick)] = {user.sIP}
  SaveToFile(fIPFile, UserIP, "UserIP")
  if tCommands[IPsearch].tLevels[user.iProfile] then
    Core.SendToNick(user.sNick,"$UserCommand 1 3 IPLog\\Search IP$<%[mynick]> +"..IPsearch.." %[line:Nick/IP]&#124;|")
  end
end
OpConnected = UserConnected
RegConnected = UserConnected

ChatArrival = function(user,data)
local _,_,to = string.find(data,"^$To:%s(%S+)%s+From:")
local _,_,cmd = string.find(data,"%b<> %p(%w+)")
if cmd and tCommands[cmd:lower()] then
cmd = cmd:lower()
if tCommands[cmd].tLevels[user.iProfile] then
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot,tCommands[cmd].sFunction(user,data)), true
else
 return Core.SendToNick(user.sNick,"<"..sBot.."> "..tCommands[cmd].sFunction(user,data)), true
end
else
if to and to == sBot then
return Core.SendPmToNick(user.sNick,sBot, "*** Error: You are not allowed to use this command!"), true
else
return Core.SendToNick(user.sNick,"<"..sBot.."> Error: You are not allowed to use this command!"), true
end
end
end
end
ToArrival = ChatArrival

tCommands = {
  [IPsearch] = {
    sFunction = function(user,data)
      local msg = ""
      local _,_,arg = string.find(data,"%b<> %p%w+ (%S+)|")
      if arg then
        if CheckUser(arg) then
          msg = "Nick: "..arg.."\tIP: "..CheckUser(arg)[1]
          return msg
        else
          for i,v in pairs(UserIP) do
            if v[1] == arg then
              msg = msg.."\r\n\tNick: "..i.."\tIP: "..v[1]
            end
          end
          if msg == "" then
            return "Invalid string. Not found in Database"
          else
            return msg
          end
        end
      else
        return "Use +ip <nick/ip>"
      end
    end,
  tLevels = {[-1] = false,[0] = true,[1] = true,[2] = true,[3] = false},
  }
}

CheckUser = function(arg)
  for i,v in pairs(UserIP) do
  if i:lower() == arg:lower() then
    return UserIP[i]
  end
  end
end

Serialize = function(tTable,sTableName,hFile,sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key,value in pairs(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

Tell me if it suits your request....
« Last Edit: 07 January, 2010, 09:31:23 by speedX »
Thanking You,

speedX

Offline ExtreeM

  • Forum Ace
  • *****
  • Posts: 83
  • Karma: +33/-6
Re: Iplog/ipsearch
« Reply #2 on: 07 February, 2008, 20:05:24 »
looks fine and thx for the very quick script speedx :)

i have some small changes

RC commands

and just to be sure, the script doesnt delete all ip after reboot??

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: Iplog/ipsearch
« Reply #3 on: 07 February, 2008, 20:08:54 »
RC commands
will be added in next version

and just to be sure, the script doesnt delete all ip after reboot??
Do you want it to delete all ip's after reboot?? Currently it doesn't..
« Last Edit: 07 February, 2008, 20:25:05 by speedX »
Thanking You,

speedX

Offline Azurious

  • Double Ace
  • *
  • Posts: 102
  • Karma: +5/-17
    • DesiDeshat - The World Of Desi Stuff!!!
Re: Iplog/ipsearch
« Reply #4 on: 21 November, 2008, 19:06:45 »
Thanks alot good work
http://www.desideshat.com - The World Of Desi Stuff!!!

PtokaX forum

Re: Iplog/ipsearch
« Reply #4 on: 21 November, 2008, 19:06:45 »