Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 250 → Rev 251

/trunk/update/includes/http_class.class.php
12,90 → 12,90
*
*/
 
define('HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR', -1);
define('HTTP_CLIENT_ERROR_NO_ERROR', 0);
define('HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS', 1);
define('HTTP_CLIENT_ERROR_CANNOT_CONNECT', 2);
define('HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE', 3);
define('HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE', 4);
define('HTTP_CLIENT_ERROR_PROTOCOL_FAILURE', 5);
define('HTTP_CLIENT_ERROR_INVALID_PARAMETERS', 6);
class http_class {
 
class http_class
{
var $host_name="";
var $host_port=0;
var $proxy_host_name="";
var $proxy_host_port=80;
var $socks_host_name = '';
var $socks_host_port = 1080;
var $socks_version = '5';
public const HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR = -1;
public const HTTP_CLIENT_ERROR_NO_ERROR = 0;
public const HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS = 1;
public const HTTP_CLIENT_ERROR_CANNOT_CONNECT = 2;
public const HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE = 3;
public const HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE = 4;
public const HTTP_CLIENT_ERROR_PROTOCOL_FAILURE = 5;
public const HTTP_CLIENT_ERROR_INVALID_PARAMETERS = 6;
 
var $protocol="http";
var $request_method="GET";
var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.94 $)';
var $accept='';
var $authentication_mechanism="";
var $user;
var $password;
var $realm;
var $workstation;
var $proxy_authentication_mechanism="";
var $proxy_user;
var $proxy_password;
var $proxy_realm;
var $proxy_workstation;
var $request_uri="";
var $request="";
var $request_headers=array();
var $request_user;
var $request_password;
var $request_realm;
var $request_workstation;
var $proxy_request_user;
var $proxy_request_password;
var $proxy_request_realm;
var $proxy_request_workstation;
var $request_body="";
var $request_arguments=array();
var $protocol_version="1.1";
var $timeout=0;
var $data_timeout=0;
var $debug=0;
var $log_debug=0;
var $debug_response_body=1;
var $html_debug=0;
var $support_cookies=1;
var $cookies=array();
var $error="";
var $error_code = HTTP_CLIENT_ERROR_NO_ERROR;
var $exclude_address="";
var $follow_redirect=0;
var $redirection_limit=5;
var $response_status="";
var $response_message="";
var $file_buffer_length=8000;
var $force_multipart_form_post=0;
var $prefer_curl = 0;
var $keep_alive = 1;
var $sasl_authenticate = 1;
public $host_name="";
public $host_port=0;
public $proxy_host_name="";
public $proxy_host_port=80;
public $socks_host_name = '';
public $socks_host_port = 1080;
public $socks_version = '5';
 
public $protocol="http";
public $request_method="GET";
public $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.94 $)';
public $accept='';
public $authentication_mechanism="";
public $user;
public $password;
public $realm;
public $workstation;
public $proxy_authentication_mechanism="";
public $proxy_user;
public $proxy_password;
public $proxy_realm;
public $proxy_workstation;
public $request_uri="";
public $request="";
public $request_headers=array();
public $request_user;
public $request_password;
public $request_realm;
public $request_workstation;
public $proxy_request_user;
public $proxy_request_password;
public $proxy_request_realm;
public $proxy_request_workstation;
public $request_body="";
public $request_arguments=array();
public $protocol_version="1.1";
public $timeout=0;
public $data_timeout=0;
public $debug=0;
public $log_debug=0;
public $debug_response_body=1;
public $html_debug=0;
public $support_cookies=1;
public $cookies=array();
public $error="";
public $error_code = self::HTTP_CLIENT_ERROR_NO_ERROR;
public $exclude_address="";
public $follow_redirect=0;
public $redirection_limit=5;
public $response_status="";
public $response_message="";
public $file_buffer_length=8000;
public $force_multipart_form_post=0;
public $prefer_curl = 0;
public $keep_alive = 1;
public $sasl_authenticate = 1;
 
/* private variables - DO NOT ACCESS */
 
var $state="Disconnected";
var $use_curl=0;
var $connection=0;
var $content_length=0;
var $response="";
var $read_response=0;
var $read_length=0;
var $request_host="";
var $next_token="";
var $redirection_level=0;
var $chunked=0;
var $remaining_chunk=0;
var $last_chunk_read=0;
var $months=array(
public $state="Disconnected";
public $use_curl=0;
public $connection=0;
public $content_length=0;
public $response="";
public $read_response=0;
public $read_length=0;
public $request_host="";
public $next_token="";
public $redirection_level=0;
public $chunked=0;
public $remaining_chunk=0;
public $last_chunk_read=0;
public $months=array(
"Jan"=>"01",
"Feb"=>"02",
"Mar"=>"03",
108,12 → 108,12
"Oct"=>"10",
"Nov"=>"11",
"Dec"=>"12");
var $session='';
var $connection_close=0;
var $force_close = 0;
var $connected_host = '';
var $connected_port = -1;
var $connected_ssl = 0;
public $session='';
public $connection_close=0;
public $force_close = 0;
public $connected_host = '';
public $connected_port = -1;
public $connected_ssl = 0;
 
/* Private methods - DO NOT CALL */
 
146,13 → 146,13
return($name ? str_replace("=", "%25", $value) : str_replace(";", "%3B", $value));
}
 
Function SetError($error, $error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
Function SetError($error, $error_code = self::HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
{
$this->error_code = $error_code;
return($this->error=$error);
}
 
Function SetPHPError($error, &$php_error_message, $error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
Function SetPHPError($error, &$php_error_message, $error_code = self::HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR)
{
if(IsSet($php_error_message)
&& strlen($php_error_message))
163,7 → 163,7
Function SetDataAccessError($error,$check_connection=0)
{
$this->error=$error;
$this->error_code = HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE;
$this->error_code = self::HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE;
if(!$this->use_curl
&& function_exists("socket_get_status"))
{
341,7 → 341,7
if($this->remaining_chunk==0)
{
if(feof($this->connection))
return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
$data=@fread($this->connection,2);
if(strcmp($data,"\r\n"))
{
392,7 → 392,7
if(strlen($ip)==0
|| (strlen($this->exclude_address)
&& !strcmp(@gethostbyname($this->exclude_address),$ip)))
return($this->SetError("could not resolve the host domain \"".$domain."\"", HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS));
return($this->SetError("could not resolve the host domain \"".$domain."\"", self::HTTP_CLIENT_ERROR_INVALID_SERVER_ADDRESS));
return('');
}
 
429,7 → 429,7
$ip="ssl://".$host_name;
if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
{
$error_code = HTTP_CLIENT_ERROR_CANNOT_CONNECT;
$error_code = self::HTTP_CLIENT_ERROR_CANNOT_CONNECT;
switch($errno)
{
case -3:
583,14 → 583,14
Function GetRequestArguments($url, &$arguments)
{
$this->error = '';
$this->error_code = HTTP_CLIENT_ERROR_NO_ERROR;
$this->error_code = self::HTTP_CLIENT_ERROR_NO_ERROR;
$arguments=array();
$url = str_replace(' ', '%20', $url);
$parameters=@parse_url($url);
if(!$parameters)
return($this->SetError("it was not specified a valid URL", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid URL", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if(!IsSet($parameters["scheme"]))
return($this->SetError("it was not specified the protocol type argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified the protocol type argument", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
switch(strtolower($parameters["scheme"]))
{
case "http":
601,7 → 601,7
return($parameters["scheme"]." connection scheme is not yet supported");
}
if(!IsSet($parameters["host"]))
return($this->SetError("it was not specified the connection host argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified the connection host argument", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$arguments["HostName"]=$parameters["host"];
$arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : ""));
if(IsSet($parameters["user"]))
619,7 → 619,7
if(IsSet($parameters["port"]))
{
if(strcmp($parameters["port"],strval(intval($parameters["port"]))))
return($this->SetError("it was not specified a valid connection host argument", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid connection host argument", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$arguments["HostPort"]=intval($parameters["port"]);
}
else
636,7 → 636,7
{
if(strlen($this->error))
return($this->error);
$error_code = HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR;
$error_code = self::HTTP_CLIENT_ERROR_UNSPECIFIED_ERROR;
if(IsSet($arguments["HostName"]))
$this->host_name=$arguments["HostName"];
if(IsSet($arguments["HostPort"]))
664,12 → 664,12
$default_port=443;
break;
default:
return($this->SetError("it was not specified a valid connection protocol", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid connection protocol", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
if(strlen($this->proxy_host_name)==0)
{
if(strlen($this->host_name)==0)
return($this->SetError("it was not specified a valid hostname", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid hostname", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$host_name=$this->host_name;
$host_port=($this->host_port ? $this->host_port : $default_port);
$server_type = 'HTTP';
683,7 → 683,7
$ssl=(strtolower($this->protocol)=="https" && strlen($this->proxy_host_name)==0);
if($ssl
&& strlen($this->socks_host_name))
return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported', HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported', self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$this->use_curl=($ssl && $this->prefer_curl && function_exists("curl_init"));
switch($this->state)
{
1053,7 → 1053,7
if(!stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
{
$this->OutputDebug('Failed establishing the cryptography layer with host '.$host);
$this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
$this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, self::HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
$this->Disconnect();
return($this->error);
}
1065,7 → 1065,7
return($error);
break;
default:
return($this->SetError("unable to send request via proxy", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("unable to send request via proxy", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
}
return("");
}
1093,7 → 1093,7
switch($this->state)
{
case "Disconnected":
return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "Connected":
$connect = 0;
break;
1103,7 → 1103,7
$connect = 1;
break;
default:
return($this->SetError("can not send request in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("can not send request in the current connection state", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
if(IsSet($arguments["RequestMethod"]))
$this->request_method=$arguments["RequestMethod"];
1123,12 → 1123,12
&& strlen($this->accept))
$arguments["Headers"]["Accept"]=$this->accept;
if(strlen($this->request_method)==0)
return($this->SetError("it was not specified a valid request method", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid request method", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if(IsSet($arguments["RequestURI"]))
$this->request_uri=$arguments["RequestURI"];
if(strlen($this->request_uri)==0
|| substr($this->request_uri,0,1)!="/")
return($this->SetError("it was not specified a valid request URI", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid request URI", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$this->request_arguments=$arguments;
$this->request_headers=(IsSet($arguments["Headers"]) ? $arguments["Headers"] : array());
$body_length=0;
1153,7 → 1153,7
{
$values=$arguments["PostValues"];
if(GetType($values)!="array")
return($this->SetError("it was not specified a valid POST method values array", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid POST method values array", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
{
$input=Key($values);
1192,7 → 1192,7
{
$values=$arguments["PostValues"];
if(GetType($values)!="array")
return($this->SetError("it was not specified a valid POST method values array", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid POST method values array", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
{
$k=Key($values);
1233,12 → 1233,12
elseif(IsSet($stream[$part]["File"]))
{
if(!($file=@fopen($stream[$part]["File"],"rb")))
return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE));
return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE));
while(!feof($file))
{
if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
{
$error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
fclose($file);
return($error);
}
1341,7 → 1341,7
if($this->use_curl)
{
if(IsSet($arguments['StreamRequest']))
return($this->SetError("Streaming request data is not supported when using Curl", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("Streaming request data is not supported when using Curl", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if($body_length
&& strlen($this->request_body)==0)
{
1352,7 → 1352,7
{
if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
{
$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$success=0;
break;
}
1360,7 → 1360,7
{
if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
{
$this->SetPHPError("could not read upload file", $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$this->SetPHPError("could not read upload file", $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$success=0;
break;
}
1389,7 → 1389,7
if(!($success=(strlen($this->response=@curl_exec($this->connection))!=0)))
{
$error=curl_error($this->connection);
$this->SetError("Could not execute the request".(strlen($error) ? ": ".$error : ""), HTTP_CLIENT_ERROR_PROTOCOL_FAILURE);
$this->SetError("Could not execute the request".(strlen($error) ? ": ".$error : ""), self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE);
}
}
else
1421,7 → 1421,7
{
if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
{
$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$success=0;
break;
}
1429,7 → 1429,7
{
if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
{
$this->SetPHPError("could not read upload file", $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$this->SetPHPError("could not read upload file", $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$success=0;
break;
}
1463,13 → 1463,13
if(strlen($this->error))
return($this->error);
if(strlen($name)==0)
return($this->SetError("it was not specified a valid cookie name", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("it was not specified a valid cookie name", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if(strlen($path)==0
|| strcmp($path[0],"/"))
return($this->SetError($path." is not a valid path for setting cookie ".$name, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError($path." is not a valid path for setting cookie ".$name, self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if($domain==""
|| !strpos($domain,".",$domain[0]=="." ? 1 : 0))
return($this->SetError($domain." is not a valid domain for setting cookie ".$name, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError($domain." is not a valid domain for setting cookie ".$name, self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$domain=strtolower($domain);
if(!strcmp($domain[0],"."))
$domain=substr($domain,1);
1497,16 → 1497,16
switch($this->state)
{
case "Disconnected":
return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "Connected":
case "ConnectedToProxy":
return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("request was not sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "SendingRequestBody":
break;
case "RequestSent":
return($this->SetError("request body was already sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("request body was already sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
default:
return($this->SetError("can not send the request body in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("can not send the request body in the current connection state", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
$length = strlen($data);
if($length)
1534,13 → 1534,13
switch($this->state)
{
case "Disconnected":
return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "Connected":
return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("request was not sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "ConnectedToProxy":
return($this->SetError("connection from the remote server from the proxy was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("connection from the remote server from the proxy was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "SendingRequestBody":
return($this->SetError("request body data was not completely sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("request body data was not completely sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "ConnectSent":
$connect = 1;
break;
1548,7 → 1548,7
$connect = 0;
break;
default:
return($this->SetError("can not get request headers in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("can not get request headers in the current connection state", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
$this->content_length=$this->read_length=$this->read_response=$this->remaining_chunk=0;
$this->content_length_set=$this->chunked=$this->last_chunk_read=$chunked=0;
1561,7 → 1561,7
if(strlen($this->response_status)==0)
{
if(!preg_match($match="/^http\\/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$/i",$line,$matches))
return($this->SetError("it was received an unexpected HTTP response status", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("it was received an unexpected HTTP response status", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
$this->response_status=$matches[1];
$this->response_message=$matches[2];
if($this->response_status == 204)
1573,7 → 1573,7
if($line=="")
{
if(strlen($this->response_status)==0)
return($this->SetError("it was not received HTTP response status", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("it was not received HTTP response status", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
$this->state=($connect ? "GotConnectHeaders" : "GotReplyHeaders");
break;
}
1667,11 → 1667,11
&& strlen($location=$headers["location"])==0)
|| (GetType($headers["location"])=="array"
&& strlen($location=$headers["location"][0])==0))
return($this->SetError("it was received a redirect without location URL", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("it was received a redirect without location URL", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
if(strcmp($location[0],"/"))
{
if(!($location_arguments=@parse_url($location)))
return($this->SetError("the server did not return a valid redirection location URL", HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("the server did not return a valid redirection location URL", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
if(!IsSet($location_arguments["scheme"]))
$location=((GetType($end=strrpos($this->request_uri,"/"))=="integer" && $end>1) ? substr($this->request_uri,0,$end) : "")."/".$location;
}
1679,7 → 1679,7
$location=$this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location;
$error=$this->GetRequestArguments($location,$arguments);
if(strlen($error))
return($this->SetError("could not process redirect url: ".$error, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("could not process redirect url: ".$error, self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
$arguments["RequestMethod"]="GET";
if(strlen($error=$this->Close())==0
&& strlen($error=$this->Open($arguments))==0
1689,7 → 1689,7
if($this->redirection_level>$this->redirection_limit)
{
$error="it was exceeded the limit of request redirections";
$this->error_code = HTTP_CLIENT_ERROR_PROTOCOL_FAILURE;
$this->error_code = self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE;
}
else
$error=$this->ReadReplyHeaders($headers);
1722,7 → 1722,7
{
if(function_exists("class_exists")
&& !class_exists("sasl_client_class"))
return($this->SetError("the SASL client class needs to be loaded to be able to authenticate".($proxy ? " with the proxy server" : "")." and access this site", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("the SASL client class needs to be loaded to be able to authenticate".($proxy ? " with the proxy server" : "")." and access this site", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
if(GetType($headers[$authenticate_header])=="array")
$authenticate=$headers[$authenticate_header];
else
1764,9 → 1764,9
case SASL_CONTINUE:
break;
case SASL_NOMECH:
return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".(strlen($authentication_mechanism) ? "authentication mechanism ".$authentication_mechanism." may not be used: " : "").$sasl->error, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".(strlen($authentication_mechanism) ? "authentication mechanism ".$authentication_mechanism." may not be used: " : "").$sasl->error, self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
default:
return($this->SetError("Could not start the SASL ".($proxy ? "proxy " : "")."authentication client: ".$sasl->error, HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("Could not start the SASL ".($proxy ? "proxy " : "")."authentication client: ".$sasl->error, self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
if($proxy >= 0)
{
1841,7 → 1841,7
$authenticated=1;
break;
}
return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message, self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
}
}
for(;!$authenticated;)
1923,7 → 1923,7
}
break;
default:
return($this->SetError("Could not process the SASL ".($proxy ? "proxy " : "")."authentication step: ".$sasl->error, HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
return($this->SetError("Could not process the SASL ".($proxy ? "proxy " : "")."authentication step: ".$sasl->error, self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
}
}
}
1969,10 → 1969,10
switch($this->state)
{
case "Disconnected":
return($this->SetError("connection was not yet established", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "Connected":
case "ConnectedToProxy":
return($this->SetError("request was not sent", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("request was not sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
case "RequestSent":
if(($error=$this->ReadReplyHeaders($headers))!="")
return($error);
1983,7 → 1983,7
$body = '';
return('');
default:
return($this->SetError("can not get request headers in the current connection state", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("can not get request headers in the current connection state", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
}
if($this->content_length_set)
$length=min($this->content_length-$this->read_length,$length);
2019,7 → 2019,7
Function ReadWholeReplyIntoTemporaryFile(&$file)
{
if(!($file = tmpfile()))
return $this->SetPHPError('could not create the temporary file to save the response', $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
return $this->SetPHPError('could not create the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
for(;;)
{
if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
2031,7 → 2031,7
{
if(@fseek($file, 0) != 0)
{
$error = $this->SetPHPError('could not seek to the beginning of temporary file with the response', $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$error = $this->SetPHPError('could not seek to the beginning of temporary file with the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
fclose($file);
return $error;
}
2039,7 → 2039,7
}
if(!@fwrite($file, $block))
{
$error = $this->SetPHPError('could not write to the temporary file to save the response', $php_errormsg, HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
$error = $this->SetPHPError('could not write to the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
fclose($file);
return $error;
}
2104,18 → 2104,18
{
$secure=Key($cookies);
if(GetType($secure)!="integer")
return($this->SetError("invalid cookie secure value type (".serialize($secure).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("invalid cookie secure value type (".serialize($secure).")", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
for($cookie_domain=0,Reset($cookies[$secure]);$cookie_domain<count($cookies[$secure]);Next($cookies[$secure]),$cookie_domain++)
{
$domain_pattern=Key($cookies[$secure]);
if(GetType($domain_pattern)!="string")
return($this->SetError("invalid cookie domain value type (".serialize($domain_pattern).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("invalid cookie domain value type (".serialize($domain_pattern).")", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
for(Reset($cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($cookies[$secure][$domain_pattern]);Next($cookies[$secure][$domain_pattern]),$path_part++)
{
$path=Key($cookies[$secure][$domain_pattern]);
if(GetType($path)!="string"
|| strcmp(substr($path, 0, 1), "/"))
return($this->SetError("invalid cookie path value type (".serialize($path).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("invalid cookie path value type (".serialize($path).")", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
for(Reset($cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($cookies[$secure][$domain_pattern][$path]);Next($cookies[$secure][$domain_pattern][$path]),$cookie++)
{
$cookie_name=Key($cookies[$secure][$domain_pattern][$path]);
2124,7 → 2124,7
if(GetType($expires)!="string"
|| (strlen($expires)
&& !preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$/", $expires)))
return($this->SetError("invalid cookie expiry value type (".serialize($expires).")", HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
return($this->SetError("invalid cookie expiry value type (".serialize($expires).")", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
$new_cookies[$secure][$domain_pattern][$path][$cookie_name]=array(
"name"=>$cookie_name,
"value"=>$value,
/trunk/update/includes/phpsvnclient.class.php
25,16 → 25,6
* - Converted class into a single function and added that function into the phpsvnclient class
*/
 
define("PHPSVN_NORMAL_REQUEST", '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop>
<getlastmodified xmlns="DAV:"/> <checked-in xmlns="DAV:"/><version-name xmlns="DAV:"/><version-controlled-configuration xmlns="DAV:"/><resourcetype xmlns="DAV:"/><baseline-relative-path xmlns="http://subversion.tigris.org/xmlns/dav/"/><repository-uuid xmlns="http://subversion.tigris.org/xmlns/dav/"/></prop></propfind>');
define("PHPSVN_VERSION_REQUEST", '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><checked-in xmlns="DAV:"/></prop></propfind>');
define("PHPSVN_LOGS_REQUEST", '<?xml version="1.0" encoding="utf-8"?> <S:log-report xmlns:S="svn:"> <S:start-revision>%d</S:start-revision><S:end-revision>%d</S:end-revision><S:path></S:path><S:discover-changed-paths/></S:log-report>');
 
define("NOT_FOUND", 2);
define("AUTH_REQUIRED", 3);
define("UNKNOWN_ERROR", 4);
define("NO_ERROR", 1);
 
/**
* PHP SVN CLIENT
*
46,8 → 36,19
* @author Cesar D. Rodas <cesar@sixdegrees.com.br>
* @license BSD License
*/
class phpsvnclient
{
class phpsvnclient {
 
protected const PHPSVN_NORMAL_REQUEST = '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><getlastmodified xmlns="DAV:"/> <checked-in xmlns="DAV:"/><version-name xmlns="DAV:"/><version-controlled-configuration xmlns="DAV:"/><resourcetype xmlns="DAV:"/><baseline-relative-path xmlns="http://subversion.tigris.org/xmlns/dav/"/><repository-uuid xmlns="http://subversion.tigris.org/xmlns/dav/"/></prop></propfind>';
protected const PHPSVN_VERSION_REQUEST = '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><checked-in xmlns="DAV:"/></prop></propfind>';
protected const PHPSVN_LOGS_REQUEST = '<?xml version="1.0" encoding="utf-8"?> <S:log-report xmlns:S="svn:"> <S:start-revision>%d</S:start-revision><S:end-revision>%d</S:end-revision><S:path></S:path><S:discover-changed-paths/></S:log-report>';
protected const NO_ERROR = 1;
protected const NOT_FOUND = 2;
protected const AUTH_REQUIRED = 3;
protected const UNKNOWN_ERROR = 4;
 
/**
* SVN Repository URL
*
340,8 → 341,8
}
$url = $this->cleanURL($this->_url . "/!svn/bc/" . $version . "/" . $folder . "/");
$this->initQuery($args, "PROPFIND", $url);
$args['Body'] = PHPSVN_NORMAL_REQUEST;
$args['Headers']['Content-Length'] = strlen(PHPSVN_NORMAL_REQUEST);
$args['Body'] = self::PHPSVN_NORMAL_REQUEST;
$args['Headers']['Content-Length'] = strlen(self::PHPSVN_NORMAL_REQUEST);
 
if (!$this->Request($args, $headers, $body))
throw new OIDplusException("Cannot get rawDirectoryDump (Request failed)");
515,7 → 516,7
 
$url = $this->cleanURL($this->_url . "/!svn/bc/" . $this->actVersion . "/" . $file . "/");
$this->initQuery($args, "REPORT", $url);
$args['Body'] = sprintf(PHPSVN_LOGS_REQUEST, $vini, $vend);
$args['Body'] = sprintf(self::PHPSVN_LOGS_REQUEST, $vini, $vend);
$args['Headers']['Content-Length'] = strlen($args['Body']);
$args['Headers']['Depth'] = 1;
 
632,8 → 633,8
 
$this->_repVersion = -1;
$this->initQuery($args, "PROPFIND", $this->cleanURL($this->_url . "/!svn/vcc/default"));
$args['Body'] = PHPSVN_VERSION_REQUEST;
$args['Headers']['Content-Length'] = strlen(PHPSVN_NORMAL_REQUEST);
$args['Body'] = self::PHPSVN_VERSION_REQUEST;
$args['Headers']['Content-Length'] = strlen(self::PHPSVN_NORMAL_REQUEST);
$args['Headers']['Depth'] = 0;
 
if (!$this->Request($args, $tmp, $body))
690,13 → 691,13
if ($http->response_status[0] != 2) {
switch ($http->response_status) {
case 404:
$this->errNro = NOT_FOUND;
$this->errNro = self::NOT_FOUND;
break;
case 401:
$this->errNro = AUTH_REQUIRED;
$this->errNro = self::AUTH_REQUIRED;
break;
default:
$this->errNro = UNKNOWN_ERROR;
$this->errNro = self::UNKNOWN_ERROR;
break;
}
// trigger_error("request to $args[RequestURI] failed: $http->response_status
704,7 → 705,7
$http->close();
return false;
}
$this->errNro = NO_ERROR;
$this->errNro = self::NO_ERROR;
$body = '';
$tbody = '';
for (;;) {
/trunk/update/includes/vnag_framework.inc.php
1,26 → 1,26
<?php /* <ViaThinkSoftSignature>
NaPwmsdxevoUCRUvsIGaPelbEBiAfbM7gA3D2K5jlIgbWKWA25LiHdgmsp3s6/b78
Oo/te1cJG+X3aGZWNy+0X23FcwngkqrYfh/Vt+LcLN2+qVrUPqM9grCLqOXvbYzrN
pl3Emp+LPT2FaaPu2HB3HGsszXWAh/yg5PoV1TuF7zZS5sEsZ6u2thSlY1SwMKu+R
0fWGb9DFX/xJYmoM3Z5ZGMEjMQwjSr9+etCXO738A7SxqbptquziYryaXFmUdos4r
xM5VXa/OvXqFvoQo1dHH6m+aq8hdN2ol230+neuWULEJsx37jH4FVLOgE5rmkK5BI
8D+9fHCzqpAhlg7FN0S5dq+bMQ1Cl8egbSvOtM7l3qNKWY6sBjtKiJifmO8cKY6IA
mrs0lOsr7rCMoyx9P0TEgwH4u4i/PLV5pNiKvup+LWvicqkmasNAWVdlHXO8iZ4RJ
8oqk+XvXbLVzgd++7lfRjU9cSGIRCK+HrbTRKErGK4Jk4wN7vHw94q2l4EId4UFni
n4yy6I1Ep6ibqDPHvTJ729n3HJtIhNSPffLaeJYE67Pptz3OHU3IlDzBs7Mn2cktZ
zI4JZjXD3qRvP6QxPETzSn7w4hqIzJkJtbWBF7TdiYZIYoCUhO34OV80MeZUN5lfO
mTB2fD0iTtP2lc2bQQtlYYya8oi5zmgE3mFSUkNZeBflAdRiUNfhfbfeawfBW6TBM
Q33bJcKu4PSDnkgHfwHMzmeuvCI8XKzL6OhG2I8uvZhF2/7q6hfh8bQdKBMH7yOjv
SO0g34dNwTGZVovtj5MrfbtlcVhoSaJq4S+NA9eAa4m5rBLa8MIgPIcGivBkNiBoD
wxuiEmvfY+zyffr9OfuTQMwKxU1iGYCfZJh9W+XqRIFrCkfU0IWCZKdKsZ6f/Usck
WqnVa+TMm6WNCpb6BxqWt4JJO6BZN2NIjhbvLOEPUN9D5niYu0R/w0hhVrKmTobHG
xdhLrfkmJ88nNNRjoCsqIpByuClfsp5o4h66bkSyOQ8RDKfkOtx+bU1KWek2MAEFh
873MNHFmtnadWgwe+GjXJb1jUS8w+eTq/X53b07uvShwri13HobMYeKmJEawHIRDE
6Tf4z+M8dBiBGDAISG4cFlp3dBjVkLC1uxv39yJ4CfL0flMBOzEZ4dydBxs51uI9Z
StB/4nKpVJ+KARV8ERdnOCnZINAD2YsfE3Kc4MLPT9WmSRxKgJQ2NmyjlD7/sMXBH
0t/YW70Zy/A0WB74GAyhfMQgwMWIi4bfTsG+k7UUefWzt6fVtuLlY02GZ+brq45HX
f5h551C4dKMSHSAmBEqRUr7JmOlJr9QU1Aim79Q6eBF6y3KJ2P0oU1Ym1Ev5EgOSE
w==
TMKHe6m9e4EBz6rT5RAMpHJZXV6Oy0+hV2ySTE+s+2C1rOZM2OqsmkOHIJ/twUNTY
vbVR55Y5YoXXcSVprQ757CJjRHCgVphAJ/H8ObIrfXGOguz5tpdXij29Y94tf6WBV
NlKZsjIypi2Zo2jqpeCiReJb2qEGP64REC9OVFtQVfFp6LgN1kIjJRpPCFTRKOoVM
Gyi41SyOPEw5MK512g33dB4yWUbVe3slLobJT4gBmKshvyuNm2P+eDf51hsEf9MeH
ZrRqUaAbWtM/Nn0px1IPs5Ceudf6AhHIih6pPj4KINt/gYFgDTG0L2XU9myYXTlkM
ruAssPVyqLY8IrT/B3i7fYYEsIE3N1NC7D3KW8tzaotaRu7IhOBUpd4e1qrmiPFpZ
DxcR2KctLmZkIygOQZbwQIF7L3DZxzSjp6fUkv/SxlrYtKU+eV5/3HUBBgIZcW+0l
T1b76Rx505ULlRzl37zGoXi5NFY+ntjGAEyWsxWZIscEdcs5W+hCzaLBcQXzYGkIp
3a4cyNzMe/aDBAPPHOtefUudiC1PGTBF9FnSlmxWQVMEO1Yq5A0pAIoycENke3Zqr
fE36xV4eq/kn7Z8pquDvsn9ip8q6mw41beGzZSWSuDAQnJSv+zxgpECZoHCo3ejd2
v9iJ3wwuLcuY88R4ec58W/po4k6SwoZ1EobTqNS2trhcv7zd/N78NwFqHaYmSxMwh
RPWLhOCIlPeCyTO2tGWVxCatC9mDY9yXaK2cpWBdJxawZFoEcVvJDkkRqjXbpjbk9
dbGeI+RecwUqi9/F6dQlKyGdLuGjgLDQBGfeQbeAFFpnO7hMw8jlBS0/pP/PNZAyS
4zW61qZY8mdSWK2UGh/S3mcfkizFTnHQzqzhNDnfiFkMfIJelPxl+XzCBzemQ1WGL
n0ejvPQQomKTBN28ue4HflIEnqfhnHycUHv7mONgtbYSxGKolzyLWjzvmexfM4kSw
SfGx42xckQkmnxAalQHgfb69/6PxQ1tsGY0sovuz10IXSMI9OZCTn0MsgVZ8tjy7Z
TOTFOmhWHTWyhLpyJTIPNsEjXoXRKPozppUO7JTwXRo8gLPis/YoIZUMSQij12Cyi
fsAl0m/3LTvQ/VG6ZYMFsnXjglA5DOQ8vkI/tiC75l3ht3v0oUx566uSE30xwkzPx
OBNfsKJmqn0V4M8vl6tTA9RlzFKLYSEX2ypgFZzLGq0eH5OLKz9YeZ9+uyInLacxT
RGhwTLWcOzkEizvQONq7Qq/G9JGQgjp6PSO/IbJYMfgPYmtJ727uKn241Z8PVOrTR
XJeXJvR9MnHrixMbaO2YsImllvHO+wmJvU2JK2wibrWhxx3RW/f+7jch0qkXVVmUb
Q==
</ViaThinkSoftSignature> */ ?>
<?php
 
35,7 → 35,7
 
Developed by Daniel Marschall www.viathinksoft.com
Licensed under the terms of the Apache 2.0 license
Revision 2020-04-10
Revision 2020-04-14
 
*/
 
335,39 → 335,38
$OVERWRITE_ARGUMENTS = null;
 
function _empty($x) {
if (is_array($x)) debug_print_stacktrace();
// Returns true for '' or null. Does not return true for value 0 or '0' (like empty() does)
return trim($x) == '';
}
 
abstract class VNag {
const VNAG_VERSION = '2019-11-12';
public const VNAG_VERSION = '2020-04-14';
 
// Status 0..3 for STATUSMODEL_SERVICE (the default status model):
# The guideline states: "Higher-level errors (such as name resolution errors, socket timeouts, etc) are outside of the control of plugins and should generally NOT be reported as UNKNOWN states."
# We choose 4 as exitcode. The plugin developer is free to return any other status.
const STATUS_OK = 0;
const STATUS_WARNING = 1;
const STATUS_CRITICAL = 2;
const STATUS_UNKNOWN = 3;
const STATUS_ERROR = 4; // and upwards
public const STATUS_OK = 0;
public const STATUS_WARNING = 1;
public const STATUS_CRITICAL = 2;
public const STATUS_UNKNOWN = 3;
public const STATUS_ERROR = 4; // and upwards
 
// Status 0..1 for STATUSMODEL_HOST:
// The page https://blog.centreon.com/good-practices-how-to-develop-monitoring-plugin-nagios/
// states that host plugins may return following status codes:
// 0=UP, 1=DOWN, Other=Maintains last known state
const STATUS_UP = 0;
const STATUS_DOWN = 1;
const STATUS_MAINTAIN = 2; // and upwards
public const STATUS_UP = 0;
public const STATUS_DOWN = 1;
public const STATUS_MAINTAIN = 2; // and upwards
 
const VERBOSITY_SUMMARY = 0;
const VERBOSITY_ADDITIONAL_INFORMATION = 1;
const VERBOSITY_CONFIGURATION_DEBUG = 2;
const VERBOSITY_PLUGIN_DEBUG = 3;
const MAX_VERBOSITY = self::VERBOSITY_PLUGIN_DEBUG;
public const VERBOSITY_SUMMARY = 0;
public const VERBOSITY_ADDITIONAL_INFORMATION = 1;
public const VERBOSITY_CONFIGURATION_DEBUG = 2;
public const VERBOSITY_PLUGIN_DEBUG = 3;
public const MAX_VERBOSITY = self::VERBOSITY_PLUGIN_DEBUG;
 
const STATUSMODEL_SERVICE = 0;
const STATUSMODEL_HOST = 1;
public const STATUSMODEL_SERVICE = 0;
public const STATUSMODEL_HOST = 1;
 
private $initialized = false;
 
382,16 → 381,14
private $helpObj = null;
private $argHandler = null;
 
const OUTPUT_SPECIAL = 1; // illegal usage / help page, version page
const OUTPUT_NORMAL = 2;
const OUTPUT_EXCEPTION = 4;
const OUTPUT_ALWAYS = 7;
const OUTPUT_NEVER = 0;
public const OUTPUT_NEVER = 0;
public const OUTPUT_SPECIAL = 1; // illegal usage / help page, version page
public const OUTPUT_NORMAL = 2;
public const OUTPUT_EXCEPTION = 4;
public const OUTPUT_ALWAYS = 7; // = OUTPUT_SPECIAL+OUTPUT_NORMAL+OUTPUT_EXCEPTION
 
// set to true if you want the output being shown in the HTML beside of the invisible tag
// set to false if you just want to send the invisible tag
public $http_visual_output = self::OUTPUT_ALWAYS;
public $http_invisible_output = self::OUTPUT_ALWAYS;
public $http_visual_output = self::OUTPUT_ALWAYS; // show a human-readable panel? ...
public $http_invisible_output = self::OUTPUT_ALWAYS; // ... and/or show an invisible machine-readable tag?
 
// $html_before and $html_after contain the output HTML which were sent by the user
 
744,6 → 741,10
 
// $optional_args will be forwarded to the callback function cbRun()
public function run($optional_args=array()) {
global $inside_vnag_run;
$inside_vnag_run = true;
try {
if (!$this->constructed) {
throw new VNagNotConstructed(VNagLang::$notConstructed);
}
850,7 → 851,10
}
 
Timeouter::end();
} finally {
$inside_vnag_run = false;
}
}
 
private function getNagiosConsoleText() {
// see https://nagios-plugins.org/doc/guidelines.html#AEN200
1239,7 → 1243,10
protected function handleException($exception) {
$this->checkInitialized(); // if (!$this->initialized) return;
 
if (!VNag::is_http_mode()) {
// On console output, remove anything we have written so far!
while (ob_get_level() > 0) @ob_end_clean();
}
$this->clearVerboseInfo();
$this->clearPerformanceData();
 
2451,13 → 2458,21
}
 
function vnagErrorHandler($errorkind, $errortext, $file, $line) {
// This function "converts" PHP runtime errors into Exceptions, which can then be handled by VNag::handleException()
global $inside_vnag_run;
if (!$inside_vnag_run && VNag::is_http_mode()) {
// We want to avoid that the VNag-Exception will show up in a website that contains
// an embedded VNag monitor, so if we are not inside a running VNag code,
// we will call the normal PHP error handler.
return false;
}
if (!(error_reporting() & $errorkind)) {
// Code is not included in error_reporting. Don't do anything.
return;
return true;
}
 
while (ob_get_level() > 0) @ob_end_clean();
 
// We want 100% clean scripts, so any error, warning or notice will shutdown the script
// This also fixes the issue that PHP will end with result code 0, showing an error.
 
2479,10 → 2494,11
if (defined('E_USER_DEPRECATED') && ($errorkind == E_USER_DEPRECATED)) $errorkind = 'User Deprecated';
throw new VNagException(VNagLang::$php_error . " $errortext at $file:$line (kind $errorkind)");
 
// true = the PHP internal error handling will not be called.
// true = the PHP internal error handling will NOT be called.
return true;
}
 
$inside_vnag_run = false;
$old_error_handler = set_error_handler("vnagErrorHandler");
 
// === End of document ===
/trunk/update/index.php
129,13 → 129,13
if ($svn_wc_exists && $snapshot_exists) {
echo '<font color="red">ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!</font>';
$job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "ERROR: Both, oidplus_version.txt and .svn directory exist! Therefore, the version is ambigous!");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
} else if (!$svn_wc_exists && !$snapshot_exists) {
echo '<font color="red">ERROR: Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!</font>';
$job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, "Neither oidplus_version.txt, nor .svn directory exist! Therefore, the version cannot be determined and the update needs to be applied manually!");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
} else if ($svn_wc_exists) {
150,11 → 150,16
 
if (!$local_installation) {
echo '<p><font color="red">The system could not determine the version of your system. (Required: svnupdate shell access or SQLite3). Please update your system manually via the SVN "update" command regularly.</font></p>';
 
$job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'The system could not determine the version of your system. (Required: svnupdate shell access or SQLite3). Please update your system manually via the SVN "update" command regularly.');
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
} else if ($local_installation == $newest_version) {
echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
 
$job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
} else {
167,7 → 172,7
echo '</pre>';
 
$job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
}
185,7 → 190,7
echo '<p><font color="green">You are already using the latest version of OIDplus.</font></p>';
 
$job = new VNagMonitorDummy(VNag::STATUS_OK, "You are using the latest version of OIDplus ($local_installation local / $newest_version remote)");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
} else {
213,7 → 218,7
echo '</pre>';
 
$job = new VNagMonitorDummy(VNag::STATUS_WARNING, "OIDplus is outdated. ($local_installation local / $newest_version remote)");
$job->http_visual_output = false;
$job->http_visual_output = VNag::OUTPUT_NEVER;
$job->run();
unset($job);
}