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 2, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class mod_status { function mod_status() { global $conf; $this->modtype="url"; $this->modname="Server status report"; $this->urls=array("/server-status"); } function url(&$rq_err, &$out_contenttype, &$out_add_headers) { global $stats_start, $stats_cnx, $stats_hits, $stats_modlist, $stats_resperr, $stats_vhosts, $stats_xfer, $stats_rej, $remote_ip, $remote_host, $modules, $conf, $logger_pids, $scoreboard, $mypid, $query_string, $htreq_headers, $banned_ips; if ($allow=$conf["global"]["statusallowhost"]) for ($a=0;$a$st_arr) { $s.=str_pad($pid, 5, " ", STR_PAD_LEFT)." - ".str_pad($this->ts2str($t - $st_arr[NW_SB_FORKTIME]), 7, " ", STR_PAD_LEFT)." - ".$st_arr[NW_SB_PEERHOST]."\n -> ".$st_arr[NW_SB_STATUS]."\n"; $pst["pid"]=$pid; $pst["peer_host"]=$st_arr[NW_SB_PEERHOST]; $pst["status"]=$st_arr[NW_SB_STATUS]; $pst["uptime"]=$t - $st_arr[NW_SB_FORKTIME]; $st["who"][]=$pst; } } } else { if (is_callable("memory_get_usage")) { $im = memory_get_usage(); $um = (int)($im/1024)." KB"; } else { $um = false; } $out_contenttype="text/html"; $startd=gmdate("D, d M Y H:i:s T", $stats_start); $uptime=time()-$stats_start; $upstr=$this->ts2str($uptime); $nst=nw_server_string(); $s="
Nanoweb server status module

"; $s.="
"; $s.="Server : ".$nst."
"; $s.="Started : ".$startd."
"; $s.="Uptime : ".$upstr."
"; if ($um) $s.="Memory : ".$um."
"; $s.="
"; $st["status"]["server_string"]=$nst; $st["status"]["started_str"]=$startd; $st["status"]["uptime_str"]=$upstr; $st["status"]["started"]=$stats_start; $st["status"]["uptime"]=$uptime; if ($im) $st["status"]["memory_usage"] = $im; $acs=(count($scoreboard)+1); if (!$conf["global"]["singleprocessmode"][0]) { $s.="Active servers : ".$acs."/".((int)$conf["global"]["maxservers"][0]?(int)$conf["global"]["maxservers"][0]:"-")." ("; $st["status"]["active_servers"]=$acs; $st["status"]["max_active_servers"]=(int)$conf["global"]["maxservers"][0]; unset($tmp); foreach ($scoreboard as $pid=>$dummy) $tmp[]=$pid; $tmp[]=$mypid; $s.=implode(" ", $tmp); $st["status"]["servers_pid"]=$tmp; $s.=")
"; } if ($conf["global"]["loggerprocess"][0]) { $acl=count($logger_pids); $s.="Active loggers : ".$acl. "/".(int)$conf["global"]["loggerprocess"][0]." ("; $st["status"]["active_loggers"]=$acl; $st["status"]["configured_loggers"]=(int)$conf["global"]["loggerprocess"][0]; if ($c=count($logger_pids)) { unset($tmp); while (list($pid, $lgid)=each($logger_pids)) $tmp[]="#".$lgid."=".$pid; $s.=implode(" ", $tmp); $st["status"]["loggers_pid"]=array_keys($logger_pids); } $s.=")
"; } $s.="
"; $s.="Total hits/connections : ".($stats_hits+1)."/".($stats_cnx)." (avg ".sprintf("%.2f", (($stats_hits/$uptime)*60))."/m ".sprintf("%.2f", ($stats_hits/$uptime))."/s)
"; $st["stats"]["total_hits"]=($stats_hits+1); $st["stats"]["total_connections"]=$stats_cnx; $s.="Total sent size : ".number_format(sprintf("%.1f", $stats_xfer/1024))." KB (avg ".sprintf("%.2f", ((($stats_xfer/1024)/$uptime)*60))." KB/m ".sprintf("%.2f", (($stats_xfer/1024)/$uptime)*8)." Kbit/s)
"; $st["stats"]["total_sent_bytes"]=$stats_xfer; $s.="
"; if (strpos($query_string, "detailed")!==false) { $s.="Loaded modules

"; for ($a=0;$a"; $mst["module_name"]=$stats_modlist[$a][0]; $mst["module_desc"]=$stats_modlist[$a][1]; $st["modules"][]=$mst; } $s.="
"; $tresp=$stats_resperr; ksort($tresp); $s.="HTTP responses statistics

"; foreach ($tresp as $key=>$val) { $s.=str_pad($GLOBALS["HTTP_HEADERS"][$key], 26)." : ".$val."
"; $tst["response_code"]=$key; $tst["hits"]=$val; $st["responses"][]=$tst; } $s.="
"; $bln_str=", ".(int)$stats_rej." total rejected connections"; if (($nbip=count($banned_ips))==0) { $s.="No blocked IP address".($nbip>1?"es":"").$bln_str."

"; } else { $s.=$nbip." blocked IP addresses".$bln_str."

"; $s.="Source Address Type (expires) Rej
-------------------- ---------------- ------------------------------ -------
"; foreach ($banned_ips as $addr=>$bip) { $bip["address"]=$addr; $s.=str_pad($bip["source"], 20)." ".str_pad($addr, 16)." ".str_pad($bip["type"].($bip["type"]=="TEMP"?(" (".date("Y-m-d H:i:s", $bip["expires"]).")"):""), 30)." ".(int)$bip["rejects"]."
"; $st["blocked_ips"][]=$bip; } $s.="
"; } } if (strpos($query_string, "vstats")!==false) { $s.="Virtual hosts statistics

"; $sv=$stats_vhosts; arsort($sv); foreach ($sv as $vh=>$hits) { if (!$hmax) $hmax=$hits or $hmax=1; $s.=str_pad(substr($vh, 0, 20), 20, " ", STR_PAD_LEFT)." ".str_pad("", (int)($hits/$hmax*50), "#")." ".$hits."
"; $vst["name"]=$vh; $vst["hits"]=$hits; $st["vhosts"][]=$vst; } $s.="
"; } $s.="
The server is working properly
"; if (strpos($htreq_headers["USER-AGENT"], "Lynx")===0) { $out_contenttype="text/plain"; $s=strip_tags(str_replace("
", "\n", $s)); } } } else { // Return 403 Forbidden if hit is not coming from allowed host $rq_err=403; $s="no access"; } if (strpos($query_string, "php-serialize")!==false) { $out_contenttype="text/plain"; $s=serialize($st); } else if (strpos($query_string, "wddx")!==false) { if (is_callable("wddx_packet_start")) { $wd=wddx_packet_start("nanoweb mod_status"); wddx_add_vars($wd, "st"); $s=wddx_packet_end($wd); } else { $s="wddx support not built in PHP"; } } else if (strpos($query_string, "xml")!==false) { $out_contenttype="text/xml"; $s=$this->arr_to_xml($st, "nanoweb_mod_status"); } return($s); } function ts2str($timestamp) { $up_d=(int)($timestamp/86400); $up_h=((int)($timestamp/3600))%24; $up_m=((int)($timestamp/60))%60; $up_s=$timestamp%60; $tstr=($up_d?($up_d."d, "):"").(($up_h||$up_d)?($up_h."h, "):"").(($up_m||$up_h||$up_d)?($up_m."m, "):"").$up_s."s"; return ($tstr); } function arr_to_xml($arr, $rootname="php_array", $lvl=0) { $fill=($lvl+1)*4; for ($a=0;$a<$fill;$a++) $filler.=" "; if ($lvl==0) { $s="<"."?xml version=\"1.0\"?".">\n\n<$rootname>\n\n"; } foreach ($arr as $key=>$val) { if (is_int($key)) { $skey_o="element id=\"".$key."\""; $skey_c="element"; } else { $skey_o=$skey_c=$key; } if (is_array($val)) { $s.=$filler."<$skey_o>\n\n".$this->arr_to_xml($val, false, $lvl+1).$filler."\n\n"; } else { $s.=$filler."<$skey_o>$val\n\n"; } } if ($lvl==0) { $s.="\n"; } return($s); } } ?>