Iplog/ipsearch
 

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

Iplog/ipsearch

Started by ExtreeM, 07 February, 2008, 12:19:52

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExtreeM

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

speedX

#1
-- 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....
Thanking You,

speedX

ExtreeM

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

speedX

#3
Quote from: ExtreeM on 07 February, 2008, 20:05:24
RC commands
will be added in next version

Quote from: ExtreeM on 07 February, 2008, 20:05:24
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..
Thanking You,

speedX

Azurious

http://www.desideshat.com - The World Of Desi Stuff!!!

SMF spam blocked by CleanTalk