|
|
@ -84,31 +84,12 @@ class rcube_directadmin_password
|
|
|
|
* @author Phi1 'l0rdphi1' Stier <l0rdphi1@liquenox.net>
|
|
|
|
* @author Phi1 'l0rdphi1' Stier <l0rdphi1@liquenox.net>
|
|
|
|
* @package HTTPSocket
|
|
|
|
* @package HTTPSocket
|
|
|
|
* @version 3.0.2
|
|
|
|
* @version 3.0.2
|
|
|
|
|
|
|
|
|
|
|
|
* 3.0.2
|
|
|
|
|
|
|
|
* added longer curl timeouts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 3.0.1
|
|
|
|
|
|
|
|
* support for tcp:// conversion to http://
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 3.0.0
|
|
|
|
|
|
|
|
* swapped to use curl to address ssl certificate issues with php 5.6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 2.7.2
|
|
|
|
|
|
|
|
* added x-use-https header check
|
|
|
|
|
|
|
|
* added max number of location redirects
|
|
|
|
|
|
|
|
* added custom settable message if x-use-https is found, so users can be told where to set their scripts
|
|
|
|
|
|
|
|
* if a redirect host is https, add ssl:// to remote_host
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 2.7.1
|
|
|
|
|
|
|
|
* added isset to headers['location'], line 306
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class HTTPSocket {
|
|
|
|
class HTTPSocket
|
|
|
|
|
|
|
|
{
|
|
|
|
var $version = '3.0.2';
|
|
|
|
var $version = '3.0.2';
|
|
|
|
|
|
|
|
|
|
|
|
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */
|
|
|
|
// all vars are private except $error, $query_cache, and $doFollowLocationHeader
|
|
|
|
|
|
|
|
|
|
|
|
var $method = 'GET';
|
|
|
|
var $method = 'GET';
|
|
|
|
|
|
|
|
|
|
|
@ -123,28 +104,23 @@ class HTTPSocket {
|
|
|
|
var $result_status_code;
|
|
|
|
var $result_status_code;
|
|
|
|
|
|
|
|
|
|
|
|
var $lastTransferSpeed;
|
|
|
|
var $lastTransferSpeed;
|
|
|
|
|
|
|
|
|
|
|
|
var $bind_host;
|
|
|
|
var $bind_host;
|
|
|
|
|
|
|
|
|
|
|
|
var $error = array();
|
|
|
|
var $error = array();
|
|
|
|
var $warn = array();
|
|
|
|
var $warn = array();
|
|
|
|
var $query_cache = array();
|
|
|
|
var $query_cache = array();
|
|
|
|
|
|
|
|
var $doFollowLocationHeader = true;
|
|
|
|
var $doFollowLocationHeader = TRUE;
|
|
|
|
|
|
|
|
var $redirectURL;
|
|
|
|
var $redirectURL;
|
|
|
|
var $max_redirects = 5;
|
|
|
|
var $max_redirects = 5;
|
|
|
|
var $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://';
|
|
|
|
var $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://';
|
|
|
|
|
|
|
|
|
|
|
|
var $extra_headers = array();
|
|
|
|
var $extra_headers = array();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create server "connection".
|
|
|
|
* Create server "connection".
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function connect($host, $port = '' )
|
|
|
|
function connect($host, $port = '')
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!is_numeric($port))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!is_numeric($port)) {
|
|
|
|
$port = 2222;
|
|
|
|
$port = 2222;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -152,10 +128,9 @@ class HTTPSocket {
|
|
|
|
$this->remote_port = $port;
|
|
|
|
$this->remote_port = $port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function bind( $ip = '' )
|
|
|
|
function bind($ip = '')
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( $ip == '' )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($ip == '') {
|
|
|
|
$ip = $_SERVER['SERVER_ADDR'];
|
|
|
|
$ip = $_SERVER['SERVER_ADDR'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -167,7 +142,7 @@ class HTTPSocket {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string|null request method. supports GET, POST, and HEAD. default is GET
|
|
|
|
* @param string|null request method. supports GET, POST, and HEAD. default is GET
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function set_method( $method = 'GET' )
|
|
|
|
function set_method($method = 'GET')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->method = strtoupper($method);
|
|
|
|
$this->method = strtoupper($method);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -178,15 +153,13 @@ class HTTPSocket {
|
|
|
|
* @param string|null username. default is null
|
|
|
|
* @param string|null username. default is null
|
|
|
|
* @param string|null password. default is null
|
|
|
|
* @param string|null password. default is null
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function set_login( $uname = '', $passwd = '' )
|
|
|
|
function set_login($uname = '', $passwd = '')
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( strlen($uname) > 0 )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (strlen($uname) > 0) {
|
|
|
|
$this->remote_uname = $uname;
|
|
|
|
$this->remote_uname = $uname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( strlen($passwd) > 0 )
|
|
|
|
if (strlen($passwd) > 0) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->remote_passwd = $passwd;
|
|
|
|
$this->remote_passwd = $passwd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -197,66 +170,62 @@ class HTTPSocket {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too.
|
|
|
|
* @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too.
|
|
|
|
* @param string|array query to pass to url
|
|
|
|
* @param string|array query to pass to url
|
|
|
|
* @param int if connection KB/s drops below value here, will drop connection
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function query( $request, $content = '', $doSpeedCheck = 0 )
|
|
|
|
function query($request, $content = '')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->error = $this->warn = array();
|
|
|
|
$this->error = $this->warn = array();
|
|
|
|
$this->result_status_code = NULL;
|
|
|
|
$this->result_status_code = null;
|
|
|
|
|
|
|
|
|
|
|
|
$is_ssl = FALSE;
|
|
|
|
$is_ssl = false;
|
|
|
|
|
|
|
|
|
|
|
|
// is our request a http:// ... ?
|
|
|
|
// is our request a http:// ... ?
|
|
|
|
if (preg_match('!^http://!i',$request) || preg_match('!^https://!i',$request))
|
|
|
|
if (preg_match('!^http://!i',$request) || preg_match('!^https://!i',$request)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$location = parse_url($request);
|
|
|
|
$location = parse_url($request);
|
|
|
|
if (preg_match('!^https://!i',$request))
|
|
|
|
if (preg_match('!^https://!i',$request)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->connect('https://'.$location['host'],$location['port']);
|
|
|
|
$this->connect('https://'.$location['host'],$location['port']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else {
|
|
|
|
$this->connect('http://'.$location['host'],$location['port']);
|
|
|
|
$this->connect('http://'.$location['host'],$location['port']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->set_login($location['user'],$location['pass']);
|
|
|
|
$this->set_login($location['user'],$location['pass']);
|
|
|
|
|
|
|
|
|
|
|
|
$request = $location['path'];
|
|
|
|
$request = $location['path'];
|
|
|
|
$content = $location['query'];
|
|
|
|
$content = $location['query'];
|
|
|
|
|
|
|
|
|
|
|
|
if ( strlen($request) < 1 )
|
|
|
|
if (strlen($request) < 1) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$request = '/';
|
|
|
|
$request = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (preg_match('!^ssl://!i', $this->remote_host))
|
|
|
|
if (preg_match('!^ssl://!i', $this->remote_host)) {
|
|
|
|
$this->remote_host = 'https://'.substr($this->remote_host, 6);
|
|
|
|
$this->remote_host = 'https://'.substr($this->remote_host, 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (preg_match('!^tcp://!i', $this->remote_host))
|
|
|
|
if (preg_match('!^tcp://!i', $this->remote_host)) {
|
|
|
|
$this->remote_host = 'http://'.substr($this->remote_host, 6);
|
|
|
|
$this->remote_host = 'http://'.substr($this->remote_host, 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (preg_match('!^https://!i', $this->remote_host))
|
|
|
|
if (preg_match('!^https://!i', $this->remote_host)) {
|
|
|
|
$is_ssl = TRUE;
|
|
|
|
$is_ssl = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$array_headers = array(
|
|
|
|
$array_headers = array(
|
|
|
|
'Host' => ( $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port" ),
|
|
|
|
'Host' => $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port",
|
|
|
|
'Accept' => '*/*',
|
|
|
|
'Accept' => '*/*',
|
|
|
|
'Connection' => 'Close' );
|
|
|
|
'Connection' => 'Close' );
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $this->extra_headers as $key => $value )
|
|
|
|
foreach ($this->extra_headers as $key => $value) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$array_headers[$key] = $value;
|
|
|
|
$array_headers[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->result = $this->result_header = $this->result_body = '';
|
|
|
|
$this->result = $this->result_header = $this->result_body = '';
|
|
|
|
|
|
|
|
|
|
|
|
// was content sent as an array? if so, turn it into a string
|
|
|
|
// was content sent as an array? if so, turn it into a string
|
|
|
|
if (is_array($content))
|
|
|
|
if (is_array($content)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$pairs = array();
|
|
|
|
$pairs = array();
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $content as $key => $value )
|
|
|
|
foreach ($content as $key => $value) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$pairs[] = "$key=".urlencode($value);
|
|
|
|
$pairs[] = "$key=".urlencode($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -264,15 +233,15 @@ class HTTPSocket {
|
|
|
|
unset($pairs);
|
|
|
|
unset($pairs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$OK = TRUE;
|
|
|
|
$OK = true;
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->method == 'GET')
|
|
|
|
if ($this->method == 'GET') {
|
|
|
|
$request .= '?'.$content;
|
|
|
|
$request .= '?'.$content;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$ch = curl_init($this->remote_host.':'.$this->remote_port.$request);
|
|
|
|
$ch = curl_init($this->remote_host.':'.$this->remote_port.$request);
|
|
|
|
|
|
|
|
|
|
|
|
if ($is_ssl)
|
|
|
|
if ($is_ssl) {
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //1
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //1
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //2
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //2
|
|
|
|
//curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
|
|
|
|
//curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
|
|
|
@ -289,33 +258,23 @@ class HTTPSocket {
|
|
|
|
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512);
|
|
|
|
curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 512);
|
|
|
|
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120);
|
|
|
|
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 120);
|
|
|
|
|
|
|
|
|
|
|
|
//if ($this->doFollowLocationHeader)
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
|
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// instance connection
|
|
|
|
// instance connection
|
|
|
|
if ($this->bind_host)
|
|
|
|
if ($this->bind_host) {
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_INTERFACE, $this->bind_host);
|
|
|
|
curl_setopt($ch, CURLOPT_INTERFACE, $this->bind_host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if we have a username and password, add the header
|
|
|
|
// if we have a username and password, add the header
|
|
|
|
if ( isset($this->remote_uname) && isset($this->remote_passwd) )
|
|
|
|
if (isset($this->remote_uname) && isset($this->remote_passwd)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $this->remote_uname.':'.$this->remote_passwd);
|
|
|
|
curl_setopt($ch, CURLOPT_USERPWD, $this->remote_uname.':'.$this->remote_passwd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for DA skins: if $this->remote_passwd is NULL, try to use the login key system
|
|
|
|
// for DA skins: if $this->remote_passwd is NULL, try to use the login key system
|
|
|
|
if ( isset($this->remote_uname) && $this->remote_passwd == NULL )
|
|
|
|
if (isset($this->remote_uname) && $this->remote_passwd == NULL) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}";
|
|
|
|
$array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if method is POST, add content length & type headers
|
|
|
|
// if method is POST, add content length & type headers
|
|
|
|
if ( $this->method == 'POST' )
|
|
|
|
if ($this->method == 'POST') {
|
|
|
|
{
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
|
|
|
|
|
|
|
|
|
|
@ -325,18 +284,15 @@ class HTTPSocket {
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $array_headers);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $array_headers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!($this->result = curl_exec($ch))) {
|
|
|
|
if( !($this->result = curl_exec($ch)) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->error[] .= curl_error($ch);
|
|
|
|
$this->error[] .= curl_error($ch);
|
|
|
|
$OK = FALSE;
|
|
|
|
$OK = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
|
|
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
|
|
$this->result_header = substr($this->result, 0, $header_size);
|
|
|
|
$this->result_header = substr($this->result, 0, $header_size);
|
|
|
|
$this->result_body = substr($this->result, $header_size);
|
|
|
|
$this->result_body = substr($this->result, $header_size);
|
|
|
|
$this->result_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
$this->result_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
|
|
|
|
|
|
$this->lastTransferSpeed = curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD) / 1024;
|
|
|
|
$this->lastTransferSpeed = curl_getinfo($ch, CURLINFO_SPEED_DOWNLOAD) / 1024;
|
|
|
|
|
|
|
|
|
|
|
|
curl_close($ch);
|
|
|
|
curl_close($ch);
|
|
|
@ -346,29 +302,27 @@ class HTTPSocket {
|
|
|
|
$headers = $this->fetch_header();
|
|
|
|
$headers = $this->fetch_header();
|
|
|
|
|
|
|
|
|
|
|
|
// did we get the full file?
|
|
|
|
// did we get the full file?
|
|
|
|
if ( !empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body) )
|
|
|
|
if (!empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->result_status_code = 206;
|
|
|
|
$this->result_status_code = 206;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// now, if we're being passed a location header, should we follow it?
|
|
|
|
// now, if we're being passed a location header, should we follow it?
|
|
|
|
if ($this->doFollowLocationHeader)
|
|
|
|
if ($this->doFollowLocationHeader) {
|
|
|
|
{
|
|
|
|
|
|
|
|
//dont bother if we didn't even setup the script correctly
|
|
|
|
//dont bother if we didn't even setup the script correctly
|
|
|
|
if (isset($headers['x-use-https']) && $headers['x-use-https']=='yes')
|
|
|
|
if (isset($headers['x-use-https']) && $headers['x-use-https'] == 'yes') {
|
|
|
|
die($this->ssl_setting_message);
|
|
|
|
die($this->ssl_setting_message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($headers['location']))
|
|
|
|
if (isset($headers['location'])) {
|
|
|
|
{
|
|
|
|
if ($this->max_redirects <= 0) {
|
|
|
|
if ($this->max_redirects <= 0)
|
|
|
|
|
|
|
|
die("Too many redirects on: ".$headers['location']);
|
|
|
|
die("Too many redirects on: ".$headers['location']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->max_redirects--;
|
|
|
|
$this->max_redirects--;
|
|
|
|
$this->redirectURL = $headers['location'];
|
|
|
|
$this->redirectURL = $headers['location'];
|
|
|
|
$this->query($headers['location']);
|
|
|
|
$this->query($headers['location']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getTransferSpeed()
|
|
|
|
function getTransferSpeed()
|
|
|
@ -383,21 +337,19 @@ class HTTPSocket {
|
|
|
|
* @param boolean return as array? (like PHP's file() command)
|
|
|
|
* @param boolean return as array? (like PHP's file() command)
|
|
|
|
* @return string result body
|
|
|
|
* @return string result body
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function get($location, $asArray = FALSE )
|
|
|
|
function get($location, $asArray = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->query($location);
|
|
|
|
$this->query($location);
|
|
|
|
|
|
|
|
|
|
|
|
if ( $this->get_status_code() == 200 )
|
|
|
|
if ($this->get_status_code() == 200) {
|
|
|
|
{
|
|
|
|
if ($asArray) {
|
|
|
|
if ($asArray)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return preg_split("/\n/",$this->fetch_body());
|
|
|
|
return preg_split("/\n/",$this->fetch_body());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->fetch_body();
|
|
|
|
return $this->fetch_body();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -449,22 +401,20 @@ class HTTPSocket {
|
|
|
|
* @param string (optional) header to return
|
|
|
|
* @param string (optional) header to return
|
|
|
|
* @return array result header
|
|
|
|
* @return array result header
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function fetch_header( $header = '' )
|
|
|
|
function fetch_header($header = '')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$array_headers = preg_split("/\r\n/",$this->result_header);
|
|
|
|
$array_headers = preg_split("/\r\n/",$this->result_header);
|
|
|
|
|
|
|
|
|
|
|
|
$array_return = array( 0 => $array_headers[0] );
|
|
|
|
$array_return = array(0 => $array_headers[0]);
|
|
|
|
unset($array_headers[0]);
|
|
|
|
unset($array_headers[0]);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ( $array_headers as $pair )
|
|
|
|
foreach ($array_headers as $pair) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($pair == '' || $pair == "\r\n") continue;
|
|
|
|
if ($pair == '' || $pair == "\r\n") continue;
|
|
|
|
list($key,$value) = preg_split("/: /",$pair,2);
|
|
|
|
list($key,$value) = preg_split("/: /",$pair,2);
|
|
|
|
$array_return[strtolower($key)] = $value;
|
|
|
|
$array_return[strtolower($key)] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( $header != '' )
|
|
|
|
if ($header != '') {
|
|
|
|
{
|
|
|
|
|
|
|
|
return $array_return[strtolower($header)];
|
|
|
|
return $array_return[strtolower($header)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|