- Home»
- Cod sursa: rsh-stats.tcl
rsh-stats.tcl
rsh-stats.tcl
TCL script that generates a html page with the bots stats and information. (ban list, accesses, etc)
| Postat de | Copyright | Categorie | Review user | Vizualizari | Data |
|---|---|---|---|---|---|
| btc | rehash | stats | Cod netestat | 480 | 2023-12-25 11:41:37 |
# rsh-stats.tcl - by rehash
# Copyright (C) 2004, 2005 rehash.
# All rights reserverd.
#
# _ _
# _ _ ___| |_ __ _ __| |_
# | '_/ -_) ' \/ _` (_-< ' \
# |_| \___|_||_\__,_/__/_||_|
# rehash@relevant-undernet.org
#
# Contact: E-mail: rehash@relevant-undernet.org
# Web: www.relevant-undernet.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
######################################################################
#set file "C:\\Program Files\\VertrigoServ\\Apache\\htdocs\\eggdrop\\stats.php"
set file "stats.php"
#set logfile "$chan.$date.log"
putlog "Loading Channel Statistics - by rehash."
bind time - "* % % % %" do_page
bind join - * onjoin
bind part - * onpart
bind sign - * onsign
bind nick - * onnick
bind kick - * onkick
bind mode - * onmode
bind topc - * ontopc
bind pubm - * onpubm
bind notc - * onnotc
bind act - * onact
proc do_page { nick host hand chan text } {
global uptime version server serveraddress botnick botname file template
putlog "\[STATS\] Creating \[$file\]..."
append output "<? function template() { ?>\n"
append output "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
append output "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
append output "<head>\n"
append output "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n"
append output "<title>Channel & Bot stats for $botnick</title>\n"
append output "<style type=\"text/css\">\n"
append output "body { padding: 0; margin: 0; font: 11px Verdana; background: #D3D7D2; }\n"
append output "td.main { border: 1px solid #949D91; padding: 5px; }\n"
append output "td.stat { background: #e9e9e9; border-top: 1px solid #FFFFFF; border-bottom: 1px solid #859288; padding: 1px 0 1px 5px;}\n"
append output "td.nav { background: #ADB4AB; border-top: 1px solid #FFFFFF; border-bottom: 1px solid #859288; padding: 1px 0 1px 5px; color: #FFFFFF; font-weight: bold;}\n"
append output "td.bla { background: #D5D9D8; border-top: 1px solid #FFFFFF; border-bottom: 1px solid #859288; padding: 1px 0 1px 5px; color: #7D897A; font-weight: bold;}\n"
append output "td.link { background: #e9e9e9; border-top: 1px solid #FFFFFF; border-bottom: 1px solid #859288; padding: 1px 0 1px 5px;}\n"
append output "td.link:hover { background: #D5D9D8; border-top: 1px solid #FFFFFF; border-bottom: 1px solid #859288; padding: 1px 0 1px 5px; }\n"
append output "a.link { color: #7D897A; text-decoration: none; font-weight: bold;}\n"
append output "a.link:hover { color: #7D897A; text-decoration: underline;}\n"
append output "h3 { margin: 10px; font: 16px Arial; font-weight: bold}\n"
append output "p { margin: 0; font: 12px Verdana; padding: 2px;}\n"
append output "</style>\n"
append output "</head>\n"
append output "<body>\n"
append output "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"
append output " <tr>\n"
append output " <td height=\"50\"> </td>\n"
append output " </tr>\n"
append output "</table>\n"
append output "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"
append output " <tr>\n"
append output " <td width=\"10%\"> </td>\n"
append output " <td width=\"80%\">\n"
append output " <table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"
append output " <tr>\n"
append output " <td width=\"20%\" valign=\"top\">\n"
append output " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"
append output " <tr>\n"
append output " <td class=\"nav\" width=\"120\"><h3>» Navigation</h3></td>\n"
append output " </tr>\n"
append output "<tr><td class=\"link\"><a href=\"stats.php\" class=\"link\" style=\"display: block;\">Home</a></td></tr>\n"
append output "<tr><td class=\"link\"><a href=\"stats.php?schan=logs\" class=\"link\" style=\"display: block;\">Logs</a></td></tr>\n"
set i 0
foreach ch [channels] {
incr i
append output "<tr><td class=\"link\"><a href=\"?schan=$i\" class=\"link\" style=\"display: block;\">$ch</a></td></tr>\n"
}
append output " </table>\n"
append output " </td>\n"
append output " <td width=\"80%\" height=\"400\" valign=\"top\" class=\"main\">\n"
append output " <? content(); ?>\n"
append output " </td>\n"
append output " </tr>\n"
append output " <tr>\n"
append output " <td width=\"20%\"> </td>\n"
append output " <td width=\"80%\">Copyright 2005, rehash. ALL rights reserved. (This page updates every minute.)</td>\n"
append output " </tr>\n"
append output " </table>\n"
append output " </td>\n"
append output " <td width=\"10%\"> </td>\n"
append output " </tr>\n"
append output "</table>\n"
append output "</body>\n"
append output "</html>\n"
append output "<? } ?>\n"
append output "<?\n"
append output "\$p = \$_GET\['schan'\];\nswitch (\$p) \{\n"
set j 0
foreach c [channels] {
incr j
append output "\tcase '$j':\n\t\tschan_$j\();\n\t\tbreak;\n"
}
append output "\tcase 'logs':\n\t\tschan_logs\();\n\t\tbreak;\n"
append output "\tdefault:\n\t\thome();\n"
append output "\}\n"
append output "function home\() \{\n"
append output "\tfunction content\() \{\n"
global uptime version server serveraddress botnick botname
set tim [ctime $uptime]
set chans [channels]
set tm [strftime %H:%M]
set usrs [countusers]
set i 0
foreach ch $chans { incr i }
append output "\t\techo '($tm) === $botnick: $i channel(s), $usrs user(s).<br />';\n"
append output "\t\techo '($tm) Online Since: $tim<br />';\n"
append output "\t\techo '($tm) Bot Nick: $botnick<br />';\n"
append output "\t\techo '($tm) Bot Name: $botname<br />';\n"
append output "\t\techo '($tm) Version: $version<br />';\n"
append output "\t\techo '($tm) Connected to server: $server<br />';\n"
append output "\t\techo '($tm) Server DNS: $serveraddress<br />';\n"
append output "\t\}\n\ttemplate\();\n"
append output "\}\n\n"
set k 0
foreach h [channels] {
incr k
append output "function schan_$k\() \{\n"
append output "\tfunction content\() \{\n"
append output "\t\tif (!isset\(\$_GET\['logs'\])) \{\n"
set users [chanlist $h]
set modes [getchanmode $h]
set bans [chanbans $h]
set user "0"
set n "0"
set ops "0"
set voice "0"
set none "0"
set ban_nr "0"
set stick "no"
foreach name $users {
if {[isop $name $h] == 1} { incr ops }
if {[isvoice $name $h] == 1} { incr voice }
if {[isop $name $h] != 1 && [isvoice $name $h] != 1} { incr none }
incr n
}
append output "\t\t\techo '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">';\n"
append output "\t\t\techo '<tr><td class=\"nav\"><h2>Chan stats for $h.</h2></td></tr>';\n"
append output "\t\t\techo '<tr><td class=\"stat\">I\`m currently in this channel.</td></tr>';\n"
append output "\t\t\techo '<tr><td class=\"stat\"><b>Channel $h</b> has $n</b> users ($ops operator(s))</td></tr>';\n"
append output "\t\t\techo '<tr><td class=\"stat\"><b>Channel Modes</b>: $modes</td></tr>';\n"
append output "\t\t\techo '<tr><td class=\"stat\"><b>Channel Ban List</b>:</td></tr><tr><td class=\"bla\">';\n"
if {$bans == ""} { append output "\t\t\techo '<p>No bans in <b>$h</b> ban list!</p>';\n" }
foreach ban $bans {
incr ban_nr
if {[isbansticky $ban $h] == 1} { set stick "yes" }
append output "\t\t\techo '<p> $ban : \[Sticky: $stick\]</p>';\n"
}
append output "\t\t\techo '</td></tr></table>';\n"
append output "\t\t\techo '<table border=\"0\"><tr><td height=\"10\"> </td></tr></table>';\n"
append output "\t\t\techo '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">';\n"
append output "\t\t\techo '<tr><td colspan=\"4\" class=\"nav\"><h2>User stats</h2></td>';\n"
append output "\t\t\techo '<tr><td width=\"25%\" class=\"stat\"><b>Total Ops</b>: $ops.</td>';\n"
append output "\t\t\techo '<td width=\"25%\" class=\"bla\"><b>Total Voice</b>: $voice.</td>';\n"
append output "\t\t\techo '<td width=\"25%\" class=\"stat\"><b>Total Normal</b>: $none.</td>';\n"
append output "\t\t\techo '<td width=\"25%\" class=\"bla\"><b>Total Users</b>: $n.</td>';\n"
append output "\t\t\techo '</tr></table>';\n"
append output "\t\t\techo '<table border=\"0\"><tr><td height=\"10\"> </td></tr></table>';\n"
append output "\t\t\techo '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">';\n"
append output "\t\t\techo '<tr><td class=\"nav\"><h2>Users.</h2></td></tr>';\n"
foreach name $users {
set idle [getchanidle $name $h]
if {[isop $name $h] == 1} {
append output "\t\t\techo '<tr><td class=\"stat\">$name\t\t(@)\t\[i/$idle\]</td></tr>';\n"
continue
}
if {[isvoice $name $h] == 1} {
append output "\t\t\techo '<tr><td class=\"stat\">$name\t\t(+)\t\[i/$idle\]</td></tr>';\n"
continue
}
if {([isop $name $h] != 1 || [isvoice $name $h] != 1)} {
append output "\t\t\techo '<tr><td class=\"stat\">$name\t\t(-)\t\[i/$idle\]</td></tr>';\n"
continue
}
}
append output "\t\t\techo '</table>';\n\n"
append output "\t\t\}\n"
append output "\t\}\n\t template\();\n"
append output "\}\n\n"
}
append output "function schan_logs\() \{\n"
append output "\tfunction content\() \{\n"
append output "\t\techo '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">';\n"
append output "\t\techo '<tr><td colspan=\"4\" class=\"nav\"><h2>» Logs</h2></td></tr><tr><td class=\"bla\">';\n"
append output "\t\t\$dir = \"logs\";\n"
append output "\t\tif (is_dir\(\$dir)) \{\n"
append output "\t\t\tif (\$dh = opendir\(\$dir)) \{\n"
append output "\t\t\t\techo '<form action=\"?schan=logs\" method=\"post\"><select name=\"log\">';\n"
append output "\t\t\t\twhile ((\$file = readdir\(\$dh)) !== false) \{\n"
append output "\t\t\t\t\tif (\$file == \".\" || \$file == \"..\") \{ continue; \}\n"
append output "\t\t\t\t\t\$date = date\(\"d-m-Y\");\n"
append output "\t\t\t\t\tif (eregi\(\"\$date\", \$file)) \{\n"
append output "\t\t\t\t\t\techo '<option value=\"'.\$file.'\">'.\$file.'</option>';\n"
append outout "\t\t\t\t\t\}\n"
append output "\t\t\t\t\t\}\n"
append output "\t\t\t\t\}\n"
append output "\t\t\t\techo '</select> <input type=\"submit\" value=\"Print\"></form>';\n"
append output "\t\t\t\}\n"
append output "\t\t\tclosedir\(\$dh);\n"
append output "\t\t\} else \{\n"
append output "\t\t\techo '<p>Could not chdir to \$dir!</p>';\n"
append output "\t\t\}\n"
append output "\t\techo '</td></tr></table>';\n"
append output "\t\tif (isset(\$_POST\['log'\])) \{\n"
append output "\t\t\t\$file = \"logs/\".\$_POST\['log'\].\"\";\n"
append output "\t\t\t\$fd = fopen\(\$file, 'r');\n"
append output "\t\t\tif (!\$fd) \{\n"
append output "\t\t\t\techo 'Error: while reading file <b>'.\$file.'</b>...!<br>\';\n"
append output "\t\t\t\}\n"
append output "\t\t\techo '<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">';\n"
append output "\t\t\techo '<tr><td colspan=\"4\" class=\"nav\"><h2>» Printing: '.\$_POST\['log'\].'</h2></td></tr><tr><td class=\"stat\">';\n"
append output "\t\t\twhile (!feof\(\$fd)) \{\n"
append output "\t\t\t\t\$sp = fread\(\$fd, 1024*1024);\n"
append output "\t\t\t\t\$text = nl2br\(\$sp);\n"
append output "\t\t\t\techo ''.\$text.'';\n"
append output "\t\t\t\}\n"
append output "\t\t\techo '</td></tr></table>';\n"
append output "\t\t\}\n"
append output ""
append output "\t\}\n\ttemplate\();\n"
append output "\}\n"
append output "?>"
# Writing the web page!!
# CODE!
set page [open $file w]
puts $page $output
close $page
putlog "\[STATS\] \[$file\] was succesfully created!"
set serv "rehash.xhost.ro"
set ftp_usr "rehash.xhost.ro"
set ftp_pass "muiesteaua"
set all_chans [channels]
set date [strftime "%d-%m-%Y"]
foreach achan $all_chans {
set file_to_upload "logs/$achan.$date.log"
if {[file exist $file_to_upload]} {
putlog "\[STATS\] Uploading ($file_to_upload) to ($serv:21)..."
sendftp $file_to_upload $serv $ftp_usr $ftp_pass "/stats/logs/$file_to_upload"
} else {
putlog "\[STATS\] File $file_to_upload does not exists!"
}
}
putlog "\[STATS\] Uploading stats to ($serv:21)..."
sendftp $file $serv $ftp_usr $ftp_pass /stats/stats.php
}
proc onjoin {nick host hand chan} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
puts $lfile "($time) * $nick ($host) has joined $chan"
close $lfile
}
proc onpart {nick host hand chan msg} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
if {$msg == ""} { puts $lfile "($time) * $nick ($host) has left $chan" } else {
puts $lfile "($time) * $nick ($host) has left $chan ($msg)" }
close $lfile
}
proc onnick {nick host hand chan newnick} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
puts $lfile "($time) * $nick is known as $newnick"
close $lfile
}
proc onkick {nick host hand chan target reason} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
puts $lfile "($time) * $target was kicked by $nick ($reason)"
close $lfile
}
proc onsign {nick host hand chan reason} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
puts $lfile "($time) * $nick ($host) Quit ($reason)"
close $lfile
}
proc onmode {nick host hand chan mode victim} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set lfile [open $logfile a+]
if {$victim == ""} { puts $lfile "($time) * $nick sets mode: $mode" } else {
puts $lfile "($time) * $nick sets mode: $mode $victim" }
close $lfile
}
proc ontopc {nick host hand chan topic} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
if {$nick == ""} { return 1; }
set chtopic ""
set lfile [open $logfile a+]
puts $lfile "($time) * $nick changes topic to '$topic'"
close $lfile
}
proc onpubm {nick host hand chan text} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
set status ""
if {$nick == ""} { return 1; }
if {[isop $nick $chan] == 1} { set status "@" }
if {[isvoice $nick $chan] == 1} { set status "+" }
set lfile [open $logfile a+]
puts $lfile "($time) <$status$nick> $text"
close $lfile
}
proc onact {nick chan action} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$chan.$date.log"
set status ""
if {$nick == ""} { return 1; }
if {[isop $nick $chan] == 1} { set status "@" }
if {[isvoice $nick $chan] == 1} { set status "+" }
set lfile [open $logfile a+]
puts $lfile "($time) * $status$nick $action"
close $lfile
}
proc onnotc {nick host hand text dest} {
set date [strftime "%d-%m-%Y"]
set time [strftime "%H:%M"]
set logfile "logs/$dest.$date.log"
set status ""
if {$nick == ""} { return 1; }
if {[isop $nick $dest] == 1} { set status "@" }
if {[isvoice $nick $dest] == 1} { set status "+" }
set lfile [open $logfile a+]
puts $lfile "($time) -$status$nick- $text"
close $lfile
}
proc sendftp { localfile server user pass remotefile } {
if {![file exist $localfile]} {
putlog "sendftp: File $localfile does not exist."
}
set noftp [catch {set ftpprog [exec which ftd]}]
if {$noftp} {
if {[file exist /usr/bin/ftp]} {
set ftpprog /usr/bin/ftp
set noftp 0
}
if {[file exist /bin/ftp]} {
set ftpprog /bin/ftp
set noftp 0
}
}
if {$noftp} { putlog "sendftp: You don't seem to have the 'ftp' tool" }
set pipe [open "|$ftpprog -n $server" w]
puts $pipe "user $user $pass"
puts $pipe "bin"
puts $pipe "put $localfile $remotefile"
puts $pipe "quit"
close $pipe
return 1
}
IRC Snippets