1 --- lighttpd_stats_1.0.orig/ss_lighttpd_stats.php 2007-02-13 23:47:00.000000000 +0200
2 +++ lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 20:11:44.391167671 +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>
17 -/* display no errors */
19 +/* do NOT run this script through a web browser */
20 +if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
21 + die("<br><strong>This script is only meant to run at the command line.</strong>");
24 +$no_http_headers = true;
26 if (!isset($called_by_script_server)) {
27 - include_once(dirname(__FILE__) . "/../include/config.php");
28 + include_once(dirname(__FILE__) . "/../include/global.php");
29 array_shift($_SERVER["argv"]);
30 print call_user_func_array("ss_lighttpd_stats", $_SERVER["argv"]);
33 $status = lighttpdStatus::getStatus($host);
36 - foreach($variables as $status_var => $cacti_var){
37 - if(isset($status[$status_var])){
38 + foreach ($variables as $status_var => $cacti_var){
39 + if (isset($status[$status_var])) {
40 $return .= sprintf('%s:%s ', $cacti_var, $status[$status_var]);
44 throw new Exception('Host not found');
47 - $fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
48 + $fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
50 if(!$fh || !is_resource($fh)){
51 throw new Exception($errstr, $errno);
53 throw new Exception('');
56 - $lines = explode("\n", $status);
57 + list($headers, $body) = explode("\r\n\r\n", $status);
58 + $headers = explode("\r\n", $headers);
60 // check response code
61 // should be "HTTP/1.1 200 OK"
62 - if(trim($lines[0]) != 'HTTP/1.1 200 OK'){
63 - throw new Exception($lines[0]);
64 + // can be also "HTTP/1.0 200 OK" if routed via proxy
65 + $http_status = trim($headers[0]);
66 + if ($http_status != 'HTTP/1.0 200 OK' && $http_status != 'HTTP/1.1 200 OK'){
67 + throw new Exception($http_status);
72 - foreach($lines as $line){
73 + $body = explode("\n", $body);
74 + foreach($body as $line){
77 - if(preg_match('/(.+): (.+)/', $line, $matches)){
78 + if (preg_match('/^(.+): (.+)/', $line, $matches)){
79 $vars[$matches[1]] = intval($matches[2]);