diff options
author | Andrey Andreev <narf@devilix.net> | 2014-01-07 11:12:11 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-01-07 11:12:11 +0100 |
commit | dc53d7b68adc6fdc8d0917ee2d29f5670ff82b45 (patch) | |
tree | 5af18e8c2a2966500254e67a6dd0ed1100fb5b28 /system | |
parent | a9c7d18dc4ba53507d6e606221f06aa3fafeaa8e (diff) |
Add Basic HTTP authentication support to the XML-RPC library
(based on PR #1716)
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Xmlrpc.php | 31 |
1 files changed, 30 insertions, 1 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'])) @@ -569,6 +574,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 * * @var string @@ -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; |