Change request "IpLog" .. few things. please help
 

Change request "IpLog" .. few things. please help

Started by davnis, 02 June, 2005, 23:14:19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

davnis

I find this script usefull but need some part to be changed that i think will make it god enough for many people.


1.
The log script record the people when connect and disconect. I think is ok only the connected people.
In this way the txt file will be increased on large hubs.

Example :

  "[ June 02 23:49:17 ] - Log In > [RO]chit30, profile Unregistered, from: 81.196.155.160, using: oDC5.31, in: Passive mode, shares: 40.18 Gb., on: 1 slots, is in: 1 hubs as a user, regged in: 0, Ops in 0, total: 1",

 "[ June 02 23:49:23 ] - Log Out > [RO][GL][ASTRAL]Soviet, profile Unregistered, from: 83.103.199.31, using: DC++0.4032, in: Passive mode, shares: 20.62 Gb., on: 6 slots, is in: 8 hubs as a user, regged in: 0, Ops in 0, total: 8",


2.
The command +log can be modifyed to not return 200 records but an Nick or an Ip ??

Something like :

+log
+log

And the script to return all the records from that nick or ip

Any help will be apreciated !

thank you,
davnis






--Connection Log 1.0 LUA 5
--
--by Mutor The Ugly
--
-- Log connections to hub in an external file
-- Hublist pingers are excluded by nick, add IP's if needed
--User Settings------------------------------------------------
LogFile = "Log.txt"             --Log file
LogCmd = "+log"                 --View log Command
Maxlog = 200                    --Number of entries to cache
Bot = frmHub:GetHubBotName()   -- Bot name pulled from hub
--End User Settings--------------------------------------------
function Main()
local f,e = io.open( LogFile, "r" )
   if f then
        dofile(LogFile)
    else
        Log = {}
        SaveLog()
    end
end

function OnExit()
SaveLog()
end

function ChatArrival(user, data)
   if string.sub(data, 1, 1) ~= "<" then end
   data = string.sub(data,1,string.len(data)-1)
   local s,e,cmd = string.find(data, "^%b<>%s+(%S+)")
   local s,e,lines = string.find(data, "^%b<>%s+%S+%s+(%d+)")
   if cmd and cmd == LogCmd then
        if lines ~= nil then
            GetLog(user, lines)
            return 1
        else
            user:SendData("Please specify how may log entries to show, you can display available entries up to "..Maxlog.." lines.")
            return 1
        end
    return 1
   end
end

function GetLog(user, linecount)
    local n1 = table.getn(Log)
   local n2 = linecount
    local n3 = n1 - n2
    local n4
    local str
        if tonumber(n2) > n1 then
            n3 = 1
            n4 = n1 - n3
            str = "<"..string.rep("-",45).."-[ There are only ( "..n4.." ) Connection Log Entries ]----------->\r\n"
        else
            n4 = n2
            str = "<"..string.rep("-",50).."-[ Last ( "..n4.." ) Connection Log Entries ]----------->\r\n"
        end
   for i=n3+1,n1 do str = str.."\r\n"..Log end
   user:SendPM(Bot,str.."\r\n")
   user:SendPM(Bot,"<"..string.rep("-",60).."-[ End of Connection Log ]--------------->")
end

function NewUserConnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
    if GetProfileName(user.iProfile) == nil then
        prof = "Unregistered"
    else
        prof = GetProfileName(user.iProfile)
    end
    local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log In > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
    if table.getn(Log) > Maxlog then
        table.remove(Log, 1)
    end
SaveLog()
end

OpConnected = NewUserConnected

function UserDisconnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
    if GetProfileName(user.iProfile) == nil then
        prof = "Unregistered"
    else
        prof = GetProfileName(user.iProfile)
    end
    local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log Out > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
    if table.getn(Log) > Maxlog then
        table.remove(Log, 1)
    end
SaveLog()
end

OpDisconnected = UserDisconnected

function SaveLog()
   local f,e = io.open( LogFile, "w+" )
   if f then
      f:write( "Log={\n" )
        for i = 1, table.getn(Log) do
            f:write( "  "..string.format("%q", Log)..",\r\n" )
        end
      f:write( "}" )
      f:close()
      return 1
   else
      return nil, user:SendData("Save Log failed: "..e)
   end
end

function GetMode(mode)
   if mode == "A" then
      mode = "Active"
   elseif mode == "P" then
      mode = "Passive"
   else
        mode = Socks5
   end
   return mode
end

function GetStatus(status)
   if not status or status == nil or status == "" then
      status = 0
   end
   return status
end

6Marilyn6Manson6

You cann use this:


--Connection Log 1.0 LUA 5
--
--by Mutor The Ugly
--
-- Log connections to hub in an external file
-- Hublist pingers are excluded by nick, add IP's if needed

--User Settings------------------------------------------------
LogFile = "Log.txt"             --Log file
LogCmd = "+log"                 --View log Command
Maxlog = 200                    --Number of entries to cache
Bot = frmHub:GetHubBotName()	-- Bot name pulled from hub
--End User Settings--------------------------------------------

function Main()
local f,e = io.open( LogFile, "r" )
	if f then
        dofile(LogFile)
    else
        Log = {}
        SaveLog()
    end
end

function OnExit()
SaveLog()
end

function ChatArrival(user, data)
	if string.sub(data, 1, 1) ~= "<" then end
	data = string.sub(data,1,string.len(data)-1)
	local s,e,cmd = string.find(data, "^%b<>%s+(%S+)")
	local s,e,lines = string.find(data, "^%b<>%s+%S+%s+(%d+)")
	if cmd and cmd == LogCmd then
        if lines ~= nil then
            GetLog(user, lines)
            return 1
        else
            user:SendData("Please specify how may log entries to show, you can display available entries up to "..Maxlog.." lines.")
            return 1
        end
    return 1
	end
end

function GetLog(user, linecount)
    local n1 = table.getn(Log)
	local n2 = linecount
    local n3 = n1 - n2
    local n4
    local str
        if tonumber(n2) > n1 then
            n3 = 1
            n4 = n1 - n3
            str = "<"..string.rep("-",45).."-[ There are only ( "..n4.." ) Connection Log Entries ]----------->\r\n"
        else
            n4 = n2
            str = "<"..string.rep("-",50).."-[ Last ( "..n4.." ) Connection Log Entries ]----------->\r\n"
        end
	for i=n3+1,n1 do str = str.."\r\n"..Log[i] end
	user:SendPM(Bot,str.."\r\n")
	user:SendPM(Bot,"<"..string.rep("-",60).."-[ End of Connection Log ]--------------->")
end

function NewUserConnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
    if GetProfileName(user.iProfile) == nil then
        prof = "Unregistered"
    else
        prof = GetProfileName(user.iProfile)
    end
    local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log In > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
    if table.getn(Log) > Maxlog then
        table.remove(Log, 1)
    end
SaveLog()
end

OpConnected = NewUserConnected

function UserDisconnected(user,data)
if string.find(string.lower(user.sName), "ping") then return end
local prof = ""
    if GetProfileName(user.iProfile) == nil then
        prof = "Unregistered"
    else
        prof = GetProfileName(user.iProfile)
    end
    local when = os.date("[ %B %d %X ] ")
local userinfo = "- Log Out > "..user.sName..", profile "..prof..", from: "..user.sIP..
", using: "..user.sClient..user.sClientVersion..", in: "..GetMode(user.sMode).." mode, shares: "..string.format("%.2f Gb.",user.iShareSize/(1024 * 1024 * 1024))..
", on: "..user.iSlots.." slots, is in: "..GetStatus(user.iNormalHubs).." hubs as a user, regged in: "..GetStatus(user.iRegHubs)..
", Ops in "..GetStatus(user.iOpHubs)..", total: "..GetStatus(user.iHubs)
table.insert(Log, when..userinfo)
    if table.getn(Log) > Maxlog then
        table.remove(Log, 1)
    end
SaveLog()
end

OpDisconnected = UserDisconnected

function SaveLog()
	local f,e = io.open( LogFile, "w+" )
	if f then
		f:write( "Log={\n" )
		  for i = 1, table.getn(Log) do
		      f:write( "  "..string.format("%q", Log[i])..",\r\n" )
		  end
		f:write( "}" )
		f:close()
		return 1
	else
		return nil, user:SendData("Save Log failed: "..e)
	end
end

function GetMode(mode)
	if mode == "A" then
		mode = "Active"
	elseif mode == "P" then
		mode = "Passive"
	else
        mode = Socks5
	end
	return mode
end

function GetStatus(status)
	if not status or status == nil or status == "" then
		status = 0
	end
	return status
end

c ya

davnis

You paste me the original posted script !!!

I ask for an +log or +log

Did you read my post ?

davnis

davnis

Come one man .. someone can easly do this :(

please help

jiten

#4
Give this a try:
-- Heavily optimized by jiten (6/4/2005)
-- Added: Nick/IP Search
-- Removed: Logout logging

-- Connection Log 1.0 LUA 5 by Mutor The Ugly
--
-- Log connections to hub in an external file
-- Hublist pingers are excluded by nick, add IP's if needed

--User Settings------------------------------------------------
LogFile = "Log.tbl"		-- Log file
LogCmd = "+log"			-- View log Command
Maxlog = 200			-- Number of entries to cache
MaxShow = 30			-- Number of entries to show
sBot = frmHub:GetHubBotName()	-- Bot name pulled from hub
--End User Settings--------------------------------------------

Main = function()
	if loadfile(LogFile) then dofile(LogFile) else Log = {} OnExit() end
end

OnExit = function()
	local f,e = io.open( LogFile, "w+" )
	if f then
		f:write("Log = {\n") 
		for i = 1, table.getn(Log) do f:write( "  "..string.format("%q", Log[i])..",\n" )  end
		f:write("}") f:close()
	end
end

ChatArrival = function(user, data)
	local data = string.sub(data,1,-2)
	local s,e,cmd = string.find(data, "^%b<>%s+(%S+)")
	if cmd and string.lower(cmd) == LogCmd then
		local s,e,IP = string.find(data,"%b<>%s+%S+%s+(%S+)")
		if IP then
			local _,_,a,b,c,d = string.find(IP,"(%d*).(%d*).(%d*).(%d*)")
			local Message = function(user,data)
				local msg, Exists = "", nil
				for i, value in Log do if string.find(value,IP) then msg = msg..value.."\r\n" Exists = 1 end end
				if Exists == 1 then
					local Structure = "\r\n<"..string.rep("-",45).."-[ Search Results of: ( "..IP.." ) ] ----------->\r\n\r\n"
					Structure = Structure..msg
					Structure = Structure.."\r\n<"..string.rep("-",60).."-[ End of Connection Log ]--------------->"
					user:SendPM(sBot,Structure)
				else
					user:SendData(sBot,"*** Error: There's no User/IP: "..IP.." in the Connection Logs.")
				end
			end
			if not (a == "" or b == "" or c == "" or d == "") or not tonumber(a) and b == "" and c == "" and d == "" then
				Message(user,data)
			else
				user:SendData(sBot, "*** Syntax Error: Type "..LogCmd.." ")
			end
		else
			local Structure = "\r\n<"..string.rep("-",45).."-[ Last ( "..table.getn(Log).." ) Connection Log Entries ] ----------->\r\n\r\n"
			for i = 1, table.getn(Log) do Structure = Structure..Log[i].."\r\n" end
			Structure = Structure.."\r\n<"..string.rep("-",60).."-[ End of Connection Log ]--------------->"
			user:SendPM(sBot,Structure)
		end
		return 1
	end
end

NewUserConnected = function(user,data)
	local GetMode = function(mode) if mode == "A" then mode = "Active" elseif mode == "P" then mode = "Passive" else mode = Socks5 end return mode end
	if string.find(string.lower(user.sName), "ping") then return end
	local userinfo = "- Log In > "..user.sName..", Profile: "..(GetProfileName(user.iProfile) or "Not Registered")..", IP: "..user.sIP..
	", Client/Version: "..user.sClient.."/"..user.sClientVersion..", Mode: "..GetMode(user.sMode).." , Share: "..string.format("%.2f GB.",user.iShareSize/(1024 * 1024 * 1024))..
	", Slots: "..user.iSlots..", User: "..(user.iNormalHubs or 0)..", Registered: "..(user.iRegHubs or 0)..
	", Operator: "..(user.iOpHubs or 0)..", Total Hubs: "..(user.iHubs or 0)
	table.insert(Log, os.date("[ %B %d %X ] ")..userinfo)
	if table.getn(Log) > Maxlog then table.remove(Log, 1) end OnExit()
end

OpConnected = NewUserConnected

Cheers

davnis

thank you a lot jiten !
i test it and work fine

im lookin forward for nick search also.

can be taken out the logout section ? i mean, is enough to see when is login, because you get the Ip already to the log.

thank you again,
davnis

jiten

QuoteOriginally posted by davnis
thank you a lot jiten !
i test it and work fine

im lookin forward for nick search also.

can be taken out the logout section ? i mean, is enough to see when is login, because you get the Ip already to the log.

thank you again,
davnis
Yes, it's possible to add nick search and remove the logout logging. I'll post it later today.

Best regards

davnis

is an error I think on line 85 !
please check

85: attempt to concatenate a nil value

thank you

jiten

QuoteOriginally posted by davnis
is an error I think on line 85 !
please check

85: attempt to concatenate a nil value

thank you
First post updated with those requests/debugs ;)

Cheers

davnis

#9
Can this script turn into Ops ONLY command ????

I enter like a normal user and I can use this script !!!!

---------------------------------------

I realy apreciate your help, is work 100% !!!
Hope all the ADMINS / OPs to use it. Was needed this one after will be denided from any normal users

thank you !





Anna

yes, if you change this line:

if cmd and string.lower(cmd) == LogCmd then

to:

if cmd and string.lower(cmd) == LogCmd and user.bOperator then

Only ops will be allowed to use the command then

Didnt feel it necessary to repost the entire script :D

davnis


jiten

Came a little late :D
Thanks Anna.

Best regards

Anna

:) np, I happened to see it, and that is one of the things among the little I know about lua :)
I'm on a slow learning process, mainly by looking in scripts and see how others made them

SMF spam blocked by CleanTalk