Skip to content

Commit 1037c88

Browse files
committed
Updated to 2.7.2
1 parent 25b7b28 commit 1037c88

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

lib/DirectAdmin/DirectAdmin.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@
1515
*
1616
* @author Phi1 'l0rdphi1' Stier <[email protected]>
1717
* @package HTTPSocket
18-
* @version 2.7.1
18+
* @version 2.7.2
19+
20+
* 2.7.2
21+
* added x-use-https header check
22+
* added max number of location redirects
23+
* added custom settable message if x-use-https is found, so users can be told where to set their scripts
24+
* if a redirect host is https, add ssl:// to remote_host
1925
2026
* 2.7.1
2127
* added isset to headers['location'], line 306
2228
2329
*/
2430
class DirectAdmin {
2531

26-
var $version = '2.7';
32+
var $version = '2.7.2';
2733

2834
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */
2935

@@ -49,6 +55,8 @@ class DirectAdmin {
4955

5056
var $doFollowLocationHeader = TRUE;
5157
var $redirectURL;
58+
var $max_redirects = 5;
59+
var $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://';
5260

5361
var $extra_headers = array();
5462

@@ -120,15 +128,19 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
120128
$this->result_status_code = NULL;
121129

122130
// is our request a http:// ... ?
123-
if (preg_match('!^http://!i',$request))
131+
if (preg_match('!^http://!i',$request) || preg_match('!^https://!i',$request))
124132
{
125133
$location = parse_url($request);
126-
$this->connect($location['host'],$location['port']);
134+
if (preg_match('!^https://!i',$request))
135+
$this->connect('ssl://'.$location['host'],$location['port']);
136+
else
137+
$this->connect($location['host'],$location['port']);
127138
$this->set_login($location['user'],$location['pass']);
128-
139+
129140
$request = $location['path'];
130141
$content = $location['query'];
131142

143+
132144
if ( strlen($request) < 1 )
133145
{
134146
$request = '/';
@@ -311,8 +323,16 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
311323
// now, if we're being passed a location header, should we follow it?
312324
if ($this->doFollowLocationHeader)
313325
{
326+
//dont bother if we didn't even setup the script correctly
327+
if (isset($headers['x-use-https']) && $headers['x-use-https']=='yes')
328+
die($this->ssl_setting_message);
329+
314330
if (isset($headers['location']))
315331
{
332+
if ($this->max_redirects <= 0)
333+
die("Too many redirects on: ".$headers['location']);
334+
335+
$this->max_redirects--;
316336
$this->redirectURL = $headers['location'];
317337
$this->query($headers['location']);
318338
}
@@ -440,4 +460,12 @@ function fetch_parsed_body()
440460
return $x;
441461
}
442462

463+
464+
/**
465+
* Set a specifc message on how to change the SSL setting, in the event that it's not set correctly.
466+
*/
467+
function set_ssl_setting_message($str)
468+
{
469+
$this->ssl_setting_message = $str;
470+
}
443471
}

0 commit comments

Comments
 (0)