<? // IMC2 Server Stats PHP Class // Ver 1.5 // By: Xorith // // Ver 1.6 additions by Samson /* * Setup: * Modify imc.h so that the STATDUMP_FILE is in a desired location. * Using that location and the 'touch' command, create the file. * chmod 777 the file you just touched. This will make only that file world-r/w/x * Modify $statdump_file below to point to the FULL PATH of your stats file. * Example: "/home/imcserver/imcstats" * When done, place this script and the script that will display the information * in your web directory. You'll have to set both of these to the proper permissions for use. * This file is not intended to be accessed directly. Please use the 'intermud-serverstats.php' file, or * create your own using the class below. */ function addS( $var = "" ) { if( empty($var) ) return "s"; if( $var == 1 ) return ""; else return "s"; } class HubStats{ var $rxpkts; var $rxbytes; var $rxbps; var $txpkts; var $txbytes; var $txbps; var $maxpktsz; var $events; var $seqdrops; var $imcboot; var $imcboot_t; var $lastdump; var $lastdump_t; var $imcupfor; var $name; var $vers; var $addr; var $network; var $wholist; var $whototal = 0; var $script_ver = "1.6"; var $last_script_update = "12/26/2004"; function setup( $statdump_file = "PATH TO FILE HERE" ) { if( !($fp = fopen( $statdump_file, "r" ) ) ) { echo "Error, unable to open '".$statdump_file."'!\n"; return; } while( !feof( $fp ) ) { $data = fscanf( $fp, "%s\t%[^[]]\n" ); if( !$data[0] || !$data[1] || empty($data[0]) || empty($data[1]) ) continue; $data[1] = trim( $data[1] ); if( $data[0] == "RXPKTS" ) { $this->rxpkts = $data[1]; continue; } if( $data[0] == "RXBYTES" ) { $this->rxbytes = $data[1]; continue; } if( $data[0] == "RXBPS" ) { $this->rxbps = $data[1]; continue; } if( $data[0] == "TXPKTS" ) { $this->txpkts = $data[1]; continue; } if( $data[0] == "TXBYTES" ) { $this->txbytes = $data[1]; continue; } if( $data[0] == "TXBPS" ) { $this->txbps = $data[1]; continue; } if( $data[0] == "MAXPKTSZ" ) { $this->maxpktsz = $data[1]; continue; } if( $data[0] == "EVENTS" ) { $this->events = $data[1]; continue; } if( $data[0] == "SEQDROPS" ) { $this->seqdrops = $data[1]; continue; } if( $data[0] == "IMCBOOT" ) { $this->imcboot_t = $data[1]; $this->imcboot = strftime( "%a %b %e, %Y at %I:%M:%S%p %Z", $this->imcboot_t ); continue; } if( $data[0] == "IMCUPFOR" ) { $this->imcupfor = $data[1]; continue; } if( $data[0] == "NAME" ) { $this->name = $data[1]; continue; } if( $data[0] == "VERS" ) { $this->vers = $data[1]; continue; } if( $data[0] == "ADDR" ) { $this->addr = $data[1]; continue; } if( $data[0] == "NETWK" ) { $this->network = $data[1]; continue; } if( $data[0] == "CONN" ) { $var = explode( " ", $data[1] ); $this->wholist[$this->whototal][0] = $var[0]; $this->wholist[$this->whototal][1] = $var[1]; $this->wholist[$this->whototal][2] = $var[2]; if( !isset( $var[3] ) || empty( $var[3] ) || $var[3] == "" ) $this->wholist[$this->whototal][3] = "none"; else $this->wholist[$this->whototal][3] = $var[3]; $this->whototal++; continue; } if( $data[0] == "LASTDUMP" ) { $this->lastdump_t = $data[1]; $this->lastdump = strftime( "%a %b %e, %Y at %I:%M:%S%p %Z", $this->lastdump_t ); continue; } $this->error( "No match: ".$data[0]." containing ".$data[1] ); } } function error( $msg = "undefined error" ) { $fp = fopen( "imcstat.err", "a" ); fwrite( $fp, "[".date("F j, Y, g:i a")."] ".$msg."\n" ); fclose( $fp ); } function imc_up_for( $time = "" ) { if( empty( $time ) ) $time = $this->imcupfor; if( $time < 1 ) return "0 seconds"; if( $time < 60 ) return $time." seconds"; $sec = $time % 60; $min = floor($time / 60); if( $min < 60 ) return $min." minute".addS($min)." and ".$sec." second".addS($sec); $hours = floor($min / 60); $min = $min % 60; if( $hours < 24 ) return $hours." hour".addS($hours).", ".$min." minute".addS($min)." and ".$sec." second".addS($sec); $days = floor($hours / 24); $hours = $hours % 24; if( $days < 7 ) return $days." day".addS($days).", ".$hours." hour".addS($hours).", ".$min." minute".addS($min)." and ".$sec." second".addS($sec); $weeks = floor($days / 7); $days = $days % 7; return number_format($weeks, 0, ' ', ',')." week".addS($weeks).", ".$days." day".addS($days).", ".$hours." hour".addS($hours).", ".$min." minute".addS($min)." and ".$sec." second".addS($sec); } function print_name( $name = "unnamed", $who_url = "none" ) { if( !eregi("^http://+[A-Za-z0-9\_-]+.[A-Za-z0-9\_-]+/*", $who_url ) ) return "<span class=\"connlistname\">".$name."</span> "; else return "<span class=\"connlistname\"><a href=\"".$who_url."\" onclick=\"window.open(this.href,'_blank');return false;\">".$name."</a></span> "; } function print_status( $status = 0 ) { if( $status == 0 ) return "<span class=\"connlistoffline\">Offline</span>"; else return "<span class=\"connlistonline\">Online</span>"; } function print_type( $type = 0 ) { if( $type == 0 ) return "<span class=\"connlistclient\">Client</span>"; else return "<span class=\"connlistserver\">Server</span>"; } function print_wholist() { $x = 0; for( $x = 0; $x < $this->whototal; $x++ ) { list( $name, $status, $type, $who_url ) = $this->wholist[$x]; echo "<tr><td>".$this->print_name($name, $who_url)."</td><td>" .$this->print_status($status)."</td><td>".$this->print_type($type)."</td></tr>\n"; } } }