SOURCES: cacti-plugin-lighttpd.patch - allow http/1.0 status (if routed via...

glen glen at pld-linux.org
Sun Oct 5 17:09:40 CEST 2008


Author: glen                         Date: Sun Oct  5 15:09:40 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- allow http/1.0 status (if routed via proxy)
- separate http headers/body and process only body to be on safe side what we process

---- Files affected:
SOURCES:
   cacti-plugin-lighttpd.patch (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/cacti-plugin-lighttpd.patch
diff -u SOURCES/cacti-plugin-lighttpd.patch:1.1 SOURCES/cacti-plugin-lighttpd.patch:1.2
--- SOURCES/cacti-plugin-lighttpd.patch:1.1	Sun Oct  5 17:07:51 2008
+++ SOURCES/cacti-plugin-lighttpd.patch	Sun Oct  5 17:09:35 2008
@@ -1,5 +1,5 @@
---- lighttpd_stats_1.0/ss_lighttpd_stats.php	2008-10-05 17:56:08.979584683 +0300
-+++ lighttpd_stats_1.0/ss_lighttpd_stats.php	2008-10-05 17:59:04.134098093 +0300
+--- lighttpd_stats_1.0/ss_lighttpd_stats.php	2008-10-05 17:59:04.134098093 +0300
++++ lighttpd_stats_1.0/ss_lighttpd_stats.php	2008-10-05 18:07:11.707053483 +0300
 @@ -1,3 +1,4 @@
 +#!/usr/bin/php
  <?php
@@ -15,3 +15,56 @@
  if (!isset($called_by_script_server)) {
          include_once(dirname(__FILE__) . "/../include/config.php");
          array_shift($_SERVER["argv"]);
+@@ -47,8 +45,8 @@
+ 		$status = lighttpdStatus::getStatus($host);
+ 		$return = '';
+ 
+-		foreach($variables as $status_var => $cacti_var){
+-			if(isset($status[$status_var])){
++		foreach ($variables as $status_var => $cacti_var){
++			if (isset($status[$status_var])) {
+ 				$return .= sprintf('%s:%s ', $cacti_var, $status[$status_var]);
+ 			}
+ 		}
+@@ -84,7 +82,7 @@
+ 				throw new Exception('Host not found');
+ 			}
+ 
+-			$fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
++			$fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT);
+ 
+ 			if(!$fh || !is_resource($fh)){
+ 				throw new Exception($errstr, $errno);
+@@ -112,20 +110,24 @@
+ 				throw new Exception('');
+ 			}
+ 
+-			$lines = explode("\n", $status);
++			list($headers, $body) = explode("\r\n\r\n", $status);
++			$headers = explode("\r\n", $headers);
+ 
+ 			// check response code
+ 			// should be "HTTP/1.1 200 OK"
+-			if(trim($lines[0]) != 'HTTP/1.1 200 OK'){
+-				throw new Exception($lines[0]);
++			// can be also "HTTP/1.0 200 OK" if routed via proxy
++			$http_status = trim($headers[0]);
++			if ($http_status != 'HTTP/1.0 200 OK' && $http_status != 'HTTP/1.1 200 OK'){
++				throw new Exception($http_status);
+ 			}
+ 
+ 			$vars = array();
+ 
+-			foreach($lines as $line){
++			$body = explode("\n", $body);
++			foreach($body as $line){
+ 				$line = trim($line);
+ 
+-				if(preg_match('/(.+): (.+)/', $line, $matches)){
++				if (preg_match('/^(.+): (.+)/', $line, $matches)){
+ 					$vars[$matches[1]] = intval($matches[2]);
+ 				}
+ 			}
+@@ -140,2 +141,0 @@
+-
+-?>
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/cacti-plugin-lighttpd.patch?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list