]>
Commit | Line | Data |
---|---|---|
a6f0521c | 1 | --- lighttpd_stats_1.0.orig/ss_lighttpd_stats.php 2007-02-13 23:47:00.000000000 +0200 |
f09aeb85 | 2 | +++ lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 20:11:44.391167671 +0300 |
c821d0f8 ER |
3 | @@ -1,3 +1,4 @@ |
4 | +#!/usr/bin/php | |
5 | <?php | |
6 | // | |
7 | // +----------------------------------------------------------------------+ | |
f09aeb85 | 8 | @@ -16,15 +17,19 @@ |
5ec3f4f4 ER |
9 | // ss_lighttpd_stats.php <hostname> |
10 | // | |
11 | // As a script server object: | |
12 | -// ss_lighttpd_stats.php ss_apache_stats <hostname> | |
13 | +// ss_lighttpd_stats.php ss_lighttpd_stats <hostname> | |
14 | // | |
15 | // | |
16 | ||
c821d0f8 ER |
17 | -/* display no errors */ |
18 | -error_reporting(0); | |
f09aeb85 ER |
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>"); | |
22 | +} | |
23 | + | |
24 | +$no_http_headers = true; | |
25 | ||
c821d0f8 | 26 | if (!isset($called_by_script_server)) { |
f09aeb85 ER |
27 | - include_once(dirname(__FILE__) . "/../include/config.php"); |
28 | + include_once(dirname(__FILE__) . "/../include/global.php"); | |
c821d0f8 | 29 | array_shift($_SERVER["argv"]); |
f09aeb85 ER |
30 | print call_user_func_array("ss_lighttpd_stats", $_SERVER["argv"]); |
31 | } | |
32 | @@ -47,8 +52,8 @@ | |
74be4dde ER |
33 | $status = lighttpdStatus::getStatus($host); |
34 | $return = ''; | |
35 | ||
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]); | |
41 | } | |
42 | } | |
f09aeb85 | 43 | @@ -84,7 +89,7 @@ |
74be4dde ER |
44 | throw new Exception('Host not found'); |
45 | } | |
46 | ||
47 | - $fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT); | |
48 | + $fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT); | |
49 | ||
50 | if(!$fh || !is_resource($fh)){ | |
51 | throw new Exception($errstr, $errno); | |
f09aeb85 | 52 | @@ -112,20 +117,24 @@ |
74be4dde ER |
53 | throw new Exception(''); |
54 | } | |
55 | ||
56 | - $lines = explode("\n", $status); | |
57 | + list($headers, $body) = explode("\r\n\r\n", $status); | |
58 | + $headers = explode("\r\n", $headers); | |
59 | ||
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); | |
68 | } | |
69 | ||
70 | $vars = array(); | |
71 | ||
72 | - foreach($lines as $line){ | |
73 | + $body = explode("\n", $body); | |
74 | + foreach($body as $line){ | |
75 | $line = trim($line); | |
76 | ||
77 | - if(preg_match('/(.+): (.+)/', $line, $matches)){ | |
78 | + if (preg_match('/^(.+): (.+)/', $line, $matches)){ | |
79 | $vars[$matches[1]] = intval($matches[2]); | |
80 | } | |
81 | } | |
f09aeb85 | 82 | @@ -137,5 +146,3 @@ |
a6f0521c ER |
83 | } |
84 | ||
85 | } | |
74be4dde ER |
86 | - |
87 | -?> |