1 --- lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 17:59:04.134098093 +0300
2 +++ lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 18:07:11.707053483 +0300
7 // +----------------------------------------------------------------------+
9 // ss_lighttpd_stats.php <hostname>
11 // As a script server object:
12 -// ss_lighttpd_stats.php ss_apache_stats <hostname>
13 +// ss_lighttpd_stats.php ss_lighttpd_stats <hostname>
21 -/* display no errors */
24 if (!isset($called_by_script_server)) {
25 include_once(dirname(__FILE__) . "/../include/config.php");
26 array_shift($_SERVER["argv"]);
28 $status = lighttpdStatus::getStatus($host);
31 - foreach($variables as $status_var => $cacti_var){
32 - if(isset($status[$status_var])){
33 + foreach ($variables as $status_var => $cacti_var){
34 + if (isset($status[$status_var])) {
35 $return .= sprintf('%s:%s ', $cacti_var, $status[$status_var]);
39 throw new Exception('Host not found');
42 - $fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
43 + $fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
45 if(!$fh || !is_resource($fh)){
46 throw new Exception($errstr, $errno);
48 throw new Exception('');
51 - $lines = explode("\n", $status);
52 + list($headers, $body) = explode("\r\n\r\n", $status);
53 + $headers = explode("\r\n", $headers);
55 // check response code
56 // should be "HTTP/1.1 200 OK"
57 - if(trim($lines[0]) != 'HTTP/1.1 200 OK'){
58 - throw new Exception($lines[0]);
59 + // can be also "HTTP/1.0 200 OK" if routed via proxy
60 + $http_status = trim($headers[0]);
61 + if ($http_status != 'HTTP/1.0 200 OK' && $http_status != 'HTTP/1.1 200 OK'){
62 + throw new Exception($http_status);
67 - foreach($lines as $line){
68 + $body = explode("\n", $body);
69 + foreach($body as $line){
72 - if(preg_match('/(.+): (.+)/', $line, $matches)){
73 + if (preg_match('/^(.+): (.+)/', $line, $matches)){
74 $vars[$matches[1]] = intval($matches[2]);