From dc53d7b68adc6fdc8d0917ee2d29f5670ff82b45 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 12:12:11 +0200 Subject: Add Basic HTTP authentication support to the XML-RPC library (based on PR #1716) --- system/libraries/Xmlrpc.php | 31 ++++++++++++++++++++++++++++++- user_guide_src/source/changelog.rst | 8 ++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index fe9781b28..bd59c933d 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -348,6 +348,11 @@ class CI_Xmlrpc { $parts = parse_url($url); + if (isset($parts['user'], $parts['pass'])) + { + $parts['host'] = $parts['user'].':'.$parts['pass'].'@'.$parts['host']; + } + $path = isset($parts['path']) ? $parts['path'] : '/'; if ( ! empty($parts['query'])) @@ -568,6 +573,21 @@ class XML_RPC_Client extends CI_Xmlrpc */ public $port = 80; + /** + * + * Server username + * + * @var string + */ + public $username; + + /** + * Server password + * + * @var string + */ + public $password; + /** * Proxy hostname * @@ -626,8 +646,16 @@ class XML_RPC_Client extends CI_Xmlrpc { parent::__construct(); + $url = parse_url('http://'.$server); + + if (isset($url['user'], $url['pass'])) + { + $this->username = $url['user']; + $this->password = $url['pass']; + } + $this->port = $port; - $this->server = $server; + $this->server = $url['host']; $this->path = $path; $this->proxy = $proxy; $this->proxy_port = $proxy_port; @@ -691,6 +719,7 @@ class XML_RPC_Client extends CI_Xmlrpc $op = 'POST '.$this->path.' HTTP/1.0'.$r .'Host: '.$this->server.$r .'Content-Type: text/xml'.$r + .(isset($this->username, $this->password) ? 'Authorization: Basic '.base64_encode($this->username.':'.$this->password).$r : '') .'User-Agent: '.$this->xmlrpcName.$r .'Content-Length: '.strlen($msg->payload).$r.$r .$msg->payload; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 6d0ceb6c3..27031b941 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -342,7 +342,6 @@ Release Date: Not Released - Deprecated usage of the "anchor_class" setting (use the new "attributes" setting instead). - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments. - Removed the default `` `` from a number of the configuration variables. - - Added the ability to use a proxy with the :doc:`XML-RPC Library `. - :doc:`Encryption Library ` changes include: @@ -354,13 +353,18 @@ Release Date: Not Released - Database object names are now being displayed. - The sum of all queries running times in seconds is now being displayed. - Added support for displaying the HTTP DNT ("Do Not Track") header. - - Added support for displaying $_FILES. + - Added support for displaying ``$_FILES``. - :doc:`Migration Library ` changes include: - Added support for timestamp-based migrations (enabled by default). - Added ``$config['migration_type']`` to allow switching between *sequential* and *timestamp* migrations. + - :doc:`XML-RPC Library ` changes include: + + - Added the ability to use a proxy. + - Added Basic HTTP authentication support. + - :doc:`User Agent Library ` will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions). - Added support for setting :doc:`Table ` class defaults in a config file. -- cgit v1.2.3-24-g4f1b