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 // +----------------------------------------------------------------------+
12 -/* display no errors */
15 if (!isset($called_by_script_server)) {
16 include_once(dirname(__FILE__) . "/../include/config.php");
17 array_shift($_SERVER["argv"]);
19 $status = lighttpdStatus::getStatus($host);
22 - foreach($variables as $status_var => $cacti_var){
23 - if(isset($status[$status_var])){
24 + foreach ($variables as $status_var => $cacti_var){
25 + if (isset($status[$status_var])) {
26 $return .= sprintf('%s:%s ', $cacti_var, $status[$status_var]);
30 throw new Exception('Host not found');
33 - $fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
34 + $fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
36 if(!$fh || !is_resource($fh)){
37 throw new Exception($errstr, $errno);
39 throw new Exception('');
42 - $lines = explode("\n", $status);
43 + list($headers, $body) = explode("\r\n\r\n", $status);
44 + $headers = explode("\r\n", $headers);
46 // check response code
47 // should be "HTTP/1.1 200 OK"
48 - if(trim($lines[0]) != 'HTTP/1.1 200 OK'){
49 - throw new Exception($lines[0]);
50 + // can be also "HTTP/1.0 200 OK" if routed via proxy
51 + $http_status = trim($headers[0]);
52 + if ($http_status != 'HTTP/1.0 200 OK' && $http_status != 'HTTP/1.1 200 OK'){
53 + throw new Exception($http_status);
58 - foreach($lines as $line){
59 + $body = explode("\n", $body);
60 + foreach($body as $line){
63 - if(preg_match('/(.+): (.+)/', $line, $matches)){
64 + if (preg_match('/^(.+): (.+)/', $line, $matches)){
65 $vars[$matches[1]] = intval($matches[2]);