####################################### # Stats.tcl by KuNgFo0 (www.eggfaq.com) #VERSION 0.5 #DESCRIPTION Adds several public !commands such as !uptime, !uname, !vhosts, etc. Useful for shell admins. Ineficient. # Set the next line as the command you want to display the uptime set stats_uptime_command "!uptime" # Set the next line as the command you want to display the uname set stats_uname_command "!uname" # Set the next line as the command you want to display the vhosts # (this command may not exist on all machines) set stats_vhosts_command "!vhosts" # Set the next line as the command you want to display the ps stats set stats_ps_command "!ps" # Set the next line as the list of processes to display stats on set stats_processlist "bnc eggdrop ircd" # Set the next line as the command you want to display the service stats set stats_services_command "!services" # Set the next line as the list of services to display stats on set stats_servicelist "cron sendmail sshd named inetd httpd" # Set then next line as the command you want to display the box stats set stats_stats_command "!stats" # Set then next line as the command you want to display the help set stats_help_command "!help" # Set the next line as the command on your shell to display the vhosts # (may be vhosts vhost etc) set stats_vhosts "vhosts" # Set the next line as the box's processor speed and type set stats_processor "Intel Pentium III xxx mhz" # Set the next line as the box's memory capacity set stats_memory "xx megs" # Set the next line as the box's connection speed set stats_linespeed "Txx xxxmbit" # Set the next line as the channels you want to run in set stats_chans "#testchannel1 #testchannel2" proc validnum {num} { return [expr [scan $num "%f%s" a b] == 1] } proc uptime_check {nick hand chan} { global stats_chans return [expr {(([lsearch -exact [string tolower $stats_chans] [string tolower $chan]] != -1) || ([strcmp $stats_chans "*"] == 0)) && (![matchattr $hand b]) && (![isbotnick $nick])}] } proc pub_uptime {nick uhost hand chan arg} { if {[uptime_check $nick $hand $chan]} { if {[catch {exec uptime} output]} { putserv "PRIVMSG $chan :Error: Could not execute uptime" } \ else { putserv "NOTICE $nick :Uptime: $output" } } } proc pub_uname {nick uhost hand chan arg} { if {[uptime_check $nick $hand $chan]} { if {[catch {exec uname -a} output]} { putserv "PRIVMSG $chan :Error: Could not execute uname" } \ else { putserv "NOTICE $nick :System Info: $output" } } } proc pub_vhosts {nick uhost hand chan arg} { global stats_vhosts if {[uptime_check $nick $hand $chan]} { if {[catch {exec $stats_vhosts} output]} { putserv "PRIVMSG $chan :Error: Could not execute vhosts" } \ else { putserv "NOTICE $nick :Vhosts:" foreach line [split $output \n] { putserv "NOTICE $nick :$line" } } } } proc pub_ps {nick uhost hand chan arg} { global stats_processlist if {[uptime_check $nick $hand $chan]} { if {[catch {exec ps axo user,tt,command} output]} { putserv "PRIVMSG $chan :Error: Could not execute ps" } \ else { set processes 0 foreach line [split $output \n] { if {([lsearch "root bin nobody qmail daemon mysql" [lindex $line 0]] == -1) && (([set tmp [lindex $line 1]] == "?") || ([string range $tmp end end] == "-"))} { foreach process $stats_processlist { if {[string match *[string tolower $process]* [string tolower $line]]} { if {![info exists processdata($process)]} { set processdata($process) 0 } incr processdata($process) } incr processes } } } set output "" if {[array names processdata] != ""} { foreach process $stats_processlist { if {[info exists processdata($process)]} { lappend output "$processdata($process) ${process}(s)" } } set output ", including: [join $output ", "]" } putserv "NOTICE $nick :Approx. $processes background process(es) currently running$output" } } } proc pub_services {nick uhost hand chan arg} { global stats_servicelist if {[uptime_check $nick $hand $chan]} { if {[catch {exec ps axo user,tt,command} output]} { putserv "PRIVMSG $chan :Error: Could not execute ps" } \ else { foreach line [split $output \n] { if {[lsearch "root bin nobody qmail daemon mysql" [lindex $line 0]] != -1} { foreach service $stats_servicelist { if {[string match *[string tolower $service]* [string tolower $line]]} { set servicedata($service) 1 } } } } if {[array names servicedata] != ""} { set output "" foreach service $stats_servicelist { if {[info exists servicedata($service)]} { lappend output "$service is online" } \ else { lappend output "$service is offline" } } } else { set output "none" } putserv "NOTICE $nick :Services running: [join $output ", "]" } } } proc pub_stats {nick uhost hand chan arg} { global stats_processor stats_memory stats_linespeed if {[uptime_check $nick $hand $chan]} { putserv "NOTICE $nick :Processor: $stats_processor" putserv "NOTICE $nick :Memory: $stats_memory" catch {exec top -b -n 1} output foreach line [split $output \n] { if {([lindex $line 0] == "Mem:") || ([lindex $line 0] == "Swap:")} { putserv "NOTICE $nick :* $line" } } if {[catch {exec df -k} output]} { putserv "PRIVMSG $chan :Error: Could not execute df" } \ else { set total 0 set used 0 set free 0 foreach line [split $output \n] { if {[validnum [lindex $line 1]]} { incr total [lindex $line 1] incr used [lindex $line 2] incr free [lindex $line 3] } } set output2 "" if {$total} { lappend output2 [format "%.2f GB total" [expr ($total / 1024.0) / 1024.0]] } if {$used} { lappend output2 [format "%.2f GB used" [expr ($used / 1024.0) / 1024.0]] } if {$free} { lappend output2 [format "%.2f GB free" [expr ($free / 1024.0) / 1024.0]] } } if {$output2 != ""} { putserv "NOTICE $nick :Hard Disk: [join $output2 ", "]" } putserv "NOTICE $nick :Line Speed: $stats_linespeed" } } proc pub_help {nick uhost hand chan arg} { global stats_uptime_command stats_uname_command stats_vhosts_command stats_ps_command stats_services_command stats_stats_command if {[uptime_check $nick $hand $chan]} { putserv "NOTICE $nick :Usage:" putserv "NOTICE $nick :[format "%-10s %s" $stats_uptime_command "Displays the server uptime"]" putserv "NOTICE $nick :[format "%-10s %s" $stats_uname_command "Displays the server version info"]" putserv "NOTICE $nick :[format "%-10s %s" $stats_vhosts_command "Displays the available vhosts"]" putserv "NOTICE $nick :[format "%-10s %s" $stats_ps_command "Displays the current bg process stats"]" putserv "NOTICE $nick :[format "%-10s %s" $stats_services_command "Displays the current services process stats"]" putserv "NOTICE $nick :[format "%-10s %s" $stats_stats_command "Displays the server stats"]" } } bind pub - $stats_uptime_command pub_uptime bind pub - $stats_uname_command pub_uname bind pub - $stats_vhosts_command pub_vhosts bind pub - $stats_ps_command pub_ps bind pub - $stats_services_command pub_services bind pub - $stats_stats_command pub_stats bind pub - $stats_help_command pub_help putlog "*** Stats.tcl 0.4 by KuNgFo0 loaded"