Skip to content

Commit

Permalink
Workaround PHP < 5.6 bug, not verifying certs, stopping Request2
Browse files Browse the repository at this point in the history
  • Loading branch information
onli committed Jun 22, 2016
1 parent b39bf70 commit d973e99
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 31 deletions.
14 changes: 12 additions & 2 deletions bundled-libs/Onyx/RSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ function parse($uri, $file=false, $time=false, $local=false)

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();

Expand Down Expand Up @@ -348,7 +353,12 @@ function mod_time($uri)
{
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();
Expand Down
4 changes: 4 additions & 0 deletions include/admin/images.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
$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
Expand Down
7 changes: 6 additions & 1 deletion include/admin/importers/blogger.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ function getInputFields() {
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
Expand Down
7 changes: 6 additions & 1 deletion include/admin/importers/generic.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ function import_wpxrss() {
$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') {
Expand Down
15 changes: 14 additions & 1 deletion include/functions_trackbacks.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 24 additions & 4 deletions plugins/serendipity_event_gravatar/serendipity_event_gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@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);
Expand Down Expand Up @@ -759,7 +759,12 @@ function fetchPFavatar(&$eventData, $mode="F")
}

// 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)
Expand Down Expand Up @@ -893,7 +898,12 @@ function fetchTwitter(&$eventData)

$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();

Expand Down Expand Up @@ -951,7 +961,12 @@ function fetchIdentica(&$eventData)
$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();
Expand Down Expand Up @@ -1128,6 +1143,11 @@ function saveAndResponseAvatar($eventData, $url, $allow_redirection = 3)
$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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function introspect(&$propbag)
'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,
Expand Down Expand Up @@ -482,6 +482,10 @@ function akismetRequest($api_key, $data, &$ret, $action = 'comment-check', $even
'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
Expand Down Expand Up @@ -1053,7 +1057,12 @@ function event_hook($event, &$bag, &$eventData, $addData = null)
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ function introspect(&$propbag)
$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,
Expand Down Expand Up @@ -419,6 +417,10 @@ function &fetchfile($url, $target, $cacheTimeout = 0, $decode_utf8 = false, $sub
} 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function GetXMLTree($file)
{
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();
Expand Down Expand Up @@ -273,7 +278,7 @@ function introspect(&$propbag)
$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',
Expand Down Expand Up @@ -440,21 +445,6 @@ function urlcheck($uri)

// 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)
Expand Down

4 comments on commit d973e99

@garvinhicking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onli We need a way to create a generic API function which sets this $options and PHP dependant stuff. We have that backend_http_request start hook which serendipity_event_proxy (or sth like that) uses, it would be good to propagate that to every call.

The complex thing might be to properly make all this HTTP_Request2 be properly compatible with the spartacus plugins, so that a spartacus plugin can work with s9y 2.0 but also 2.1...

@onli
Copy link
Member Author

@onli onli commented on d973e99 Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Did not want to introduce that without discussion (because it is a big thing to introduce a custom s9y request api), but during this thought that it would be nice to let s9y care about all of this. You think the best way would be to just give the request to backend_http_request? Not serendipity_request_start()? Or offering a serendipity_request() that makes the result itself?

so that a spartacus plugin can work with s9y 2.0 but also 2.1...

Yes, for the moment that might introduce the same ifs/complexity we wanted to avoid… but we could do it for the core and core plugins and see where that leads us.

@garvinhicking
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onli Might need to think about this. We could of course add new parameteres to serendipity_request_start() that when given, can perform the whole request and return it. That way old plugins can use the function as is, but the new core can utilize the method. The only thing that might get awkward is if we update our spartacus plugin to use the new function, we'll still have the legacy code for s9y < 2.1 versions in them.

But yeah, better to get started with the core and see which and how many plugins would look like with this added complexity.

@onli
Copy link
Member Author

@onli onli commented on d973e99 Jun 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to hurry. For now the workaround should work, confirmed by mario for php < 5.6, and dirks issue showed that also in higher versions all is fine (in addition to my own test).

With spartacus plugin, you do not mean the spartacus plugin itself though, do you? Because this one is bundled and would be one of the cases where there is no issue, we can just change it for 2.1. Assuming I don't miss something :)

Please sign in to comment.