Skip to content

Commit

Permalink
- Update the HTTPSocket class from 2.7 to 2.8 to avoid plugin problem…
Browse files Browse the repository at this point in the history
…s when used with SSL (and when DirectAdmin uses the option "force_hostname" that requires a correct "host" header value).
  • Loading branch information
vbenincasa committed Apr 19, 2012
1 parent 5d66a4b commit 6c95b3e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions plugins/password/drivers/directadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* Driver to change passwords via DirectAdmin Control Panel
*
* @version 2.0
* @version 2.1
* @author Victor Benincasa <vbenincasa@gmail.com>
*
*/
Expand Down Expand Up @@ -62,16 +62,17 @@ public function save($curpass, $passwd)
*
* Very, very basic usage:
* $Socket = new HTTPSocket;
* echo $Socket->get('http://user:pass@somesite.com/somedir/some.file?query=string&this=that');
* echo $Socket->get('http://user:pass@somehost.com:2222/CMD_API_SOMEAPI?query=string&this=that');
*
* @author Phi1 'l0rdphi1' Stier <l0rdphi1@liquenox.net>
* @updates 2.7 and 2.8 by Victor Benincasa <vbenincasa @ gmail.com>
* @package HTTPSocket
* @version 2.7 (Updated by Victor Benincasa <vbenincasa@gmail.com>)
* @version 2.8
*/
class HTTPSocket {

var $version = '2.7';

var $version = '2.8';
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */

var $method = 'GET';
Expand Down Expand Up @@ -107,7 +108,7 @@ function connect($host, $port = '' )
{
if (!is_numeric($port))
{
$port = 80;
$port = 2222;
}

$this->remote_host = $host;
Expand Down Expand Up @@ -166,13 +167,13 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
$this->error = $this->warn = array();
$this->result_status_code = NULL;

// is our request a http:// ... ?
if (preg_match('!^http://!i',$request))
// is our request a http(s):// ... ?
if (preg_match('/^(http|https):\/\//i',$request))
{
$location = parse_url($request);
$this->connect($location['host'],$location['port']);
$this->set_login($location['user'],$location['pass']);

$request = $location['path'];
$content = $location['query'];

Expand All @@ -185,7 +186,7 @@ function query( $request, $content = '', $doSpeedCheck = 0 )

$array_headers = array(
'User-Agent' => "HTTPSocket/$this->version",
'Host' => ( $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port" ),
'Host' => ( $this->remote_port == 80 ? parse_url($this->remote_host,PHP_URL_HOST) : parse_url($this->remote_host,PHP_URL_HOST).":".$this->remote_port ),
'Accept' => '*/*',
'Connection' => 'Close' );

Expand Down Expand Up @@ -325,7 +326,7 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
}

}

list($this->result_header,$this->result_body) = preg_split("/\r\n\r\n/",$this->result,2);

if ($this->bind_host)
Expand Down Expand Up @@ -364,6 +365,7 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
$this->query($headers['location']);
}
}

}

function getTransferSpeed()
Expand Down Expand Up @@ -447,7 +449,7 @@ function fetch_result()
function fetch_header( $header = '' )
{
$array_headers = preg_split("/\r\n/",$this->result_header);

$array_return = array( 0 => $array_headers[0] );
unset($array_headers[0]);

Expand Down

0 comments on commit 6c95b3e

Please sign in to comment.