From d973e999333b473ee37943f042e0b463c51584bd Mon Sep 17 00:00:00 2001 From: onli Date: Wed, 22 Jun 2016 19:40:36 +0200 Subject: [PATCH] Workaround PHP < 5.6 bug, not verifying certs, stopping Request2 See http://board.s9y.org/viewtopic.php?f=10&t=20773 and #399 --- bundled-libs/Onyx/RSS.php | 14 ++++++++-- include/admin/images.inc.php | 4 +++ include/admin/importers/blogger.inc.php | 7 ++++- include/admin/importers/generic.inc.php | 7 ++++- include/functions_trackbacks.inc.php | 15 +++++++++- .../serendipity_event_gravatar.php | 28 ++++++++++++++++--- .../serendipity_event_spamblock.php | 13 +++++++-- .../serendipity_event_spartacus.php | 8 ++++-- .../serendipity_plugin_remoterss.php | 24 +++++----------- 9 files changed, 89 insertions(+), 31 deletions(-) diff --git a/bundled-libs/Onyx/RSS.php b/bundled-libs/Onyx/RSS.php index a59c6511..901a548e 100644 --- a/bundled-libs/Onyx/RSS.php +++ b/bundled-libs/Onyx/RSS.php @@ -125,7 +125,12 @@ class ONYX_RSS require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; serendipity_request_start(); - $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'max_redirects' => 5)); + $options = array('follow_redirects' => true, 'max_redirects' => 5); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, $options); try { $res = $req->send(); @@ -348,7 +353,12 @@ class ONYX_RSS { require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; serendipity_request_start(); - $req = new HTTP_Request2($uri); + $options = array(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, $options); try { $response = $req->send(); diff --git a/include/admin/images.inc.php b/include/admin/images.inc.php index 4b277356..ce5af7bd 100644 --- a/include/admin/images.inc.php +++ b/include/admin/images.inc.php @@ -271,6 +271,10 @@ switch ($serendipity['GET']['adminAction']) { $options = array('follow_redirects' => true, 'max_redirects' => 5); serendipity_plugin_api::hook_event('backend_http_request', $options, 'image'); serendipity_request_start(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } $req = new HTTP_Request2($serendipity['POST']['imageurl'], HTTP_Request2::METHOD_GET, $options); // Try to get the URL diff --git a/include/admin/importers/blogger.inc.php b/include/admin/importers/blogger.inc.php index e01936d9..c1a1e6c2 100644 --- a/include/admin/importers/blogger.inc.php +++ b/include/admin/importers/blogger.inc.php @@ -56,7 +56,12 @@ class Serendipity_Import_Blogger extends Serendipity_Import { if (!empty($_REQUEST['token'])) { // Prepare session token request - $req = new HTTP_Request2('https://www.google.com/accounts/AuthSubSessionToken'); + $options = array(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2('https://www.google.com/accounts/AuthSubSessionToken', HTTP_Request2::METHOD_GET, $options); $req->setHeader('Authorization', 'AuthSub token="'. $_REQUEST['token'] .'"'); // Request token diff --git a/include/admin/importers/generic.inc.php b/include/admin/importers/generic.inc.php index 2dbc0f30..bfaa2f6c 100644 --- a/include/admin/importers/generic.inc.php +++ b/include/admin/importers/generic.inc.php @@ -141,7 +141,12 @@ class Serendipity_Import_Generic extends Serendipity_Import { $uri = $this->data['url']; require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; serendipity_request_start(); - $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'max_redirects' => 5)); + $options = array('follow_redirects' => true, 'max_redirects' => 5); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, $options); try { $res = $req->send(); if ($res->getStatus() != '200') { diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index 16fda68d..2f843359 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -130,6 +130,10 @@ function _serendipity_send($loc, $data, $contenttype = null) { $options = array('follow_redirects' => true, 'max_redirects' => 5); serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_send'); serendipity_request_start(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } $req = new HTTP_Request2($uri, HTTP_Request2::METHOD_POST, $options); if (isset($contenttype)){ @@ -273,6 +277,10 @@ function serendipity_reference_autodiscover($loc, $url, $author, $title, $text) $options = array('follow_redirects' => true, 'max_redirects' => 5); serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_detect'); serendipity_request_start(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } $req = new HTTP_Request2($parsed_loc, HTTP_Request2::METHOD_GET, $options); try { @@ -541,7 +549,12 @@ function fetchPingbackData(&$comment) { if (function_exists('serendipity_request_start')) serendipity_request_start(); // Request the page - $req = new HTTP_Request2($url, array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 20)); + $options = array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 20); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $options); // code 200: OK, code 30x: REDIRECTION $responses = "/(200)|(30[0-9])/"; // |(30[0-9] Moved) diff --git a/plugins/serendipity_event_gravatar/serendipity_event_gravatar.php b/plugins/serendipity_event_gravatar/serendipity_event_gravatar.php index 97dd585c..bb6d6c73 100755 --- a/plugins/serendipity_event_gravatar/serendipity_event_gravatar.php +++ b/plugins/serendipity_event_gravatar/serendipity_event_gravatar.php @@ -8,7 +8,7 @@ if (IN_serendipity !== true) { @serendipity_plugin_api::load_language(dirname(__FILE__)); // Actual version of this plugin -@define('PLUGIN_EVENT_GRAVATAR_VERSION', '1.61'); // NOTE: This plugin is also in the central repository. Commit changes to the core, too :) +@define('PLUGIN_EVENT_GRAVATAR_VERSION', '1.61.1'); // NOTE: This plugin is also in the central repository. Commit changes to the core, too :) // Defines the maximum available method slots in the configuration. @define('PLUGIN_EVENT_GRAVATAR_METHOD_MAX', 6); @@ -759,7 +759,12 @@ class serendipity_event_gravatar extends serendipity_event } // Evaluate URL of P/Favatar - $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'max_redirects' => 3)); + $options = array('follow_redirects' => true, 'max_redirects' => 3); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $options); $favicon = false; // code 200: OK, code 30x: REDIRECTION $responses = "/(200 OK)|(30[0-9] Found)/"; // |(30[0-9] Moved) @@ -893,7 +898,12 @@ class serendipity_event_gravatar extends serendipity_event $twitter_search = 'http://search.twitter.com/search.atom?q=from%3A' . $twittername . '&rpp=1'; serendipity_request_start(); - $req = new HTTP_Request2($twitter_search); + $options = array(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($twitter_search, HTTP_Request2::METHOD_GET, $options); try { $response = $req->send(); @@ -951,7 +961,12 @@ class serendipity_event_gravatar extends serendipity_event $status_id = $matches[1]; $search = "http://identi.ca/api/statuses/show/$status_id.xml"; serendipity_request_start(); - $req = new HTTP_Request2($search); + $options = array(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($search, HTTP_Request2::METHOD_GET, $options); try { $response = $req->send(); $this->last_error = $response->getStatus(); @@ -1128,6 +1143,11 @@ class serendipity_event_gravatar extends serendipity_event $request_pars['follow_redirects'] = false; } + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $request_pars['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $request_pars); try { $response = $req->send(); diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index 22efa209..90190b66 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -25,7 +25,7 @@ class serendipity_event_spamblock extends serendipity_event 'smarty' => '2.6.7', 'php' => '4.1.0' )); - $propbag->add('version', '1.86'); + $propbag->add('version', '1.86.1'); $propbag->add('event_hooks', array( 'frontend_saveComment' => true, 'external_plugin' => true, @@ -482,6 +482,10 @@ class serendipity_event_spamblock extends serendipity_event 'follow_redirects' => true, 'max_redirects' => 3, ); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } // Default server type to akismet, in case user has an older version of the plugin // where no server was set @@ -1053,7 +1057,12 @@ class serendipity_event_spamblock extends serendipity_event require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; if (function_exists('serendipity_request_start')) serendipity_request_start(); - $req = new HTTP_Request2($addData['url'], HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 10)); + $options = array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 10); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the funcitonality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($addData['url'], HTTP_Request2::METHOD_GET, $options); $is_valid = false; try { $response = $req->send(); diff --git a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php index c920b7b1..eee6d6ab 100644 --- a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php +++ b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php @@ -27,11 +27,9 @@ class serendipity_event_spartacus extends serendipity_event $propbag->add('description', PLUGIN_EVENT_SPARTACUS_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '2.37'); + $propbag->add('version', '2.37.1'); $propbag->add('requirements', array( 'serendipity' => '1.6', - 'smarty' => '2.6.7', - 'php' => '4.1.0' )); $propbag->add('event_hooks', array( 'backend_plugins_fetchlist' => true, @@ -419,6 +417,10 @@ class serendipity_event_spartacus extends serendipity_event } else { require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; $options = array('follow_redirects' => true, 'max_redirects' => 5); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } serendipity_plugin_api::hook_event('backend_http_request', $options, 'spartacus'); serendipity_request_start(); diff --git a/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php b/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php index 0100339b..35cff8a5 100644 --- a/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php +++ b/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php @@ -49,7 +49,12 @@ class s9y_remoterss_XMLTree { require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; serendipity_request_start(); - $req = new HTTP_Request2($file); + $options = array(); + if (version_compare(PHP_VERSION, '5.6.0', '<')) { + // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 + $options['ssl_verify_peer'] = false; + } + $req = new HTTP_Request2($file, HTTP_Request2::METHOD_GET, $options); try { $response = $req->send(); @@ -273,7 +278,7 @@ class serendipity_plugin_remoterss extends serendipity_plugin $propbag->add('description', PLUGIN_REMOTERSS_BLAHBLAH); $propbag->add('stackable', true); $propbag->add('author', 'Udo Gerhards, Richard Thomas Harrison'); - $propbag->add('version', '1.22'); + $propbag->add('version', '1.22.1'); $propbag->add('requirements', array( 'serendipity' => '1.7', 'smarty' => '3.1.0', @@ -440,21 +445,6 @@ class serendipity_plugin_remoterss extends serendipity_plugin // Disabled by now. May get enabled in the future, but for now the extra HTTP call isn't worth trying. return true; - require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; - serendipity_request_start(); - $req = new HTTP_Request2($uri); - - try { - $response = $req->send(); - if (!preg_match('@^[23]..@', $req->getStatus)) { - throw new HTTP_Request2_Exception('Status code says url not reachable'); - } - serendipity_request_end(); - return true; - } catch (HTTP_Request2_Exception $e) { - serendipity_request_end(); - return false; - } } function debug($msg)