From 8ed4fcafdaa7764747b60f62bffa4dd2279757f6 Mon Sep 17 00:00:00 2001 From: kapustko Date: Wed, 20 Feb 2019 14:40:37 +0300 Subject: [PATCH 1/5] Add two boolean variables to http_class and BasicPP $is_verify_peer (default true) $is_verify_peer_name (default true) Those changes enable to skip peer verification. Useful for self signed certificates. --- lib/BasicIPP.php | 6 +++++- lib/http_class.php | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/BasicIPP.php b/lib/BasicIPP.php index 4b3feb6..66eef31 100644 --- a/lib/BasicIPP.php +++ b/lib/BasicIPP.php @@ -73,7 +73,9 @@ class BasicIPP public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30. public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30. public $ssl = false; - public $debug_level = 3; // max 3: almost silent + public $is_verify_peer = true; + public $is_verify_peer_name = true; + public $debug_level = 3; // max 3: almost silent public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and reads while end tag) public $with_exceptions = 0; // compatibility mode for old scripts public $handle_http_exceptions = 1; @@ -807,6 +809,8 @@ protected function _sendHttp($post_values, $uri) } $http->port = $this->port; $http->timeout = $this->http_timeout; + $http->is_verify_peer = $this->is_verify_peer; + $http->is_verify_peer_name = $this->is_verify_peer_name; $http->data_timeout = $this->http_data_timeout; $http->force_multipart_form_post = false; $http->user = $this->username; diff --git a/lib/http_class.php b/lib/http_class.php index 06bceb9..252839a 100644 --- a/lib/http_class.php +++ b/lib/http_class.php @@ -136,6 +136,8 @@ class http_class public $data_timeout = 30; // time waiting for data, milliseconds public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond public $force_multipart_form_post; + public $is_verify_peer = true; + public $is_verify_peer_name = true; public $username; public $password; public $request_headers = array(); @@ -232,7 +234,17 @@ public function Open($arguments) } } } - $this->connection = @fsockopen($transport_type . $url, $port, $errno, $errstr, $this->timeout); + if ($transport_type == 'tls://'){ + $context = stream_context_create([ + 'ssl' => [ + 'verify_peer' => $this->is_verify_peer, + 'verify_peer_name' => $this->is_verify_peer_name + ] + ]); + $this->connection = @stream_socket_client($transport_type . $url.':'.$port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context); + }else { + $this->connection = @fsockopen($transport_type . $url, $port, $errno, $errstr, $this->timeout); + } $error = sprintf(_('Unable to connect to "%s%s port %s": %s'), $transport_type, $url, $port, $errstr); From 98dd5fa3b62d0e8006bf94b2f14b14fddfcc5ca0 Mon Sep 17 00:00:00 2001 From: kapustko Date: Wed, 20 Feb 2019 18:25:03 +0300 Subject: [PATCH 2/5] Add two boolean variables to http_class and BasicPP $is_verify_peer (default true) $is_verify_peer_name (default true) Those changes enable to skip peer verification. Useful for self signed certificates. --- lib/BasicIPP.php | 4 ++-- lib/http_class.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/BasicIPP.php b/lib/BasicIPP.php index 66eef31..a4b7965 100644 --- a/lib/BasicIPP.php +++ b/lib/BasicIPP.php @@ -73,8 +73,8 @@ class BasicIPP public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30. public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30. public $ssl = false; - public $is_verify_peer = true; - public $is_verify_peer_name = true; + public $is_verify_peer = true; + public $is_verify_peer_name = true; public $debug_level = 3; // max 3: almost silent public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and reads while end tag) public $with_exceptions = 0; // compatibility mode for old scripts diff --git a/lib/http_class.php b/lib/http_class.php index 252839a..06885e4 100644 --- a/lib/http_class.php +++ b/lib/http_class.php @@ -136,8 +136,8 @@ class http_class public $data_timeout = 30; // time waiting for data, milliseconds public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond public $force_multipart_form_post; - public $is_verify_peer = true; - public $is_verify_peer_name = true; + public $is_verify_peer = true; + public $is_verify_peer_name = true; public $username; public $password; public $request_headers = array(); From 08e45960ada4fffd56886f186aa8c64631391e9e Mon Sep 17 00:00:00 2001 From: kapustko Date: Wed, 20 Feb 2019 18:41:00 +0300 Subject: [PATCH 3/5] Add two boolean variables to http_class and BasicPP $is_verify_peer (default true) $is_verify_peer_name (default true) Those changes enable to skip peer verification. Useful for self signed certificates. --- lib/BasicIPP.php | 2 +- lib/http_class.php | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/BasicIPP.php b/lib/BasicIPP.php index a4b7965..c4dff15 100644 --- a/lib/BasicIPP.php +++ b/lib/BasicIPP.php @@ -75,7 +75,7 @@ class BasicIPP public $ssl = false; public $is_verify_peer = true; public $is_verify_peer_name = true; - public $debug_level = 3; // max 3: almost silent + public $debug_level = 3; // max 3: almost silent public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and reads while end tag) public $with_exceptions = 0; // compatibility mode for old scripts public $handle_http_exceptions = 1; diff --git a/lib/http_class.php b/lib/http_class.php index 06885e4..1c8c893 100644 --- a/lib/http_class.php +++ b/lib/http_class.php @@ -234,17 +234,17 @@ public function Open($arguments) } } } - if ($transport_type == 'tls://'){ - $context = stream_context_create([ - 'ssl' => [ - 'verify_peer' => $this->is_verify_peer, - 'verify_peer_name' => $this->is_verify_peer_name - ] - ]); - $this->connection = @stream_socket_client($transport_type . $url.':'.$port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context); - }else { - $this->connection = @fsockopen($transport_type . $url, $port, $errno, $errstr, $this->timeout); - } + if ($transport_type == 'tls://'){ + $context = stream_context_create([ + 'ssl' => [ + 'verify_peer' => $this->is_verify_peer, + 'verify_peer_name' => $this->is_verify_peer_name + ] + ]); + $this->connection = @stream_socket_client($transport_type . $url.':'.$port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context); + }else { + $this->connection = @fsockopen($transport_type . $url, $port, $errno, $errstr, $this->timeout); + } $error = sprintf(_('Unable to connect to "%s%s port %s": %s'), $transport_type, $url, $port, $errstr); From 383380cf0661283ad8c1e5cbff3e1502bbd76988 Mon Sep 17 00:00:00 2001 From: kapustko Date: Wed, 20 Feb 2019 18:43:08 +0300 Subject: [PATCH 4/5] Add two boolean variables to http_class and BasicPP $is_verify_peer (default true) $is_verify_peer_name (default true) Those changes enable to skip peer verification. Useful for self signed certificates. --- lib/BasicIPP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/BasicIPP.php b/lib/BasicIPP.php index c4dff15..8046a58 100644 --- a/lib/BasicIPP.php +++ b/lib/BasicIPP.php @@ -809,8 +809,8 @@ protected function _sendHttp($post_values, $uri) } $http->port = $this->port; $http->timeout = $this->http_timeout; - $http->is_verify_peer = $this->is_verify_peer; - $http->is_verify_peer_name = $this->is_verify_peer_name; + $http->is_verify_peer = $this->is_verify_peer; + $http->is_verify_peer_name = $this->is_verify_peer_name; $http->data_timeout = $this->http_data_timeout; $http->force_multipart_form_post = false; $http->user = $this->username; From 779f5e002b18526529972fae42ca67c7ffcf3061 Mon Sep 17 00:00:00 2001 From: kapustko Date: Thu, 7 Mar 2019 21:05:16 +0300 Subject: [PATCH 5/5] Fix switch case orientation (even if sides are "2CE" it still returned two-sided-long-edge ) --- lib/BasicIPP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/BasicIPP.php b/lib/BasicIPP.php index 8046a58..8a8188f 100644 --- a/lib/BasicIPP.php +++ b/lib/BasicIPP.php @@ -411,11 +411,11 @@ public function setSides($sides = 2) switch ($sides) { - case 1: + case "1": $sides = "one-sided"; break; - case 2: + case "2": $sides = "two-sided-long-edge"; break;