15
15
*
16
16
* @author Phi1 'l0rdphi1' Stier <[email protected] >
17
17
* @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
19
25
20
26
* 2.7.1
21
27
* added isset to headers['location'], line 306
22
28
23
29
*/
24
30
class DirectAdmin {
25
31
26
- var $ version = '2.7 ' ;
32
+ var $ version = '2.7.2 ' ;
27
33
28
34
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */
29
35
@@ -49,6 +55,8 @@ class DirectAdmin {
49
55
50
56
var $ doFollowLocationHeader = TRUE ;
51
57
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:// ' ;
52
60
53
61
var $ extra_headers = array ();
54
62
@@ -120,15 +128,19 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
120
128
$ this ->result_status_code = NULL ;
121
129
122
130
// is our request a http:// ... ?
123
- if (preg_match ('!^http://!i ' ,$ request ))
131
+ if (preg_match ('!^http://!i ' ,$ request ) || preg_match ( ' !^https://!i ' , $ request ) )
124
132
{
125
133
$ 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 ' ]);
127
138
$ this ->set_login ($ location ['user ' ],$ location ['pass ' ]);
128
-
139
+
129
140
$ request = $ location ['path ' ];
130
141
$ content = $ location ['query ' ];
131
142
143
+
132
144
if ( strlen ($ request ) < 1 )
133
145
{
134
146
$ request = '/ ' ;
@@ -311,8 +323,16 @@ function query( $request, $content = '', $doSpeedCheck = 0 )
311
323
// now, if we're being passed a location header, should we follow it?
312
324
if ($ this ->doFollowLocationHeader )
313
325
{
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
+
314
330
if (isset ($ headers ['location ' ]))
315
331
{
332
+ if ($ this ->max_redirects <= 0 )
333
+ die ("Too many redirects on: " .$ headers ['location ' ]);
334
+
335
+ $ this ->max_redirects --;
316
336
$ this ->redirectURL = $ headers ['location ' ];
317
337
$ this ->query ($ headers ['location ' ]);
318
338
}
@@ -440,4 +460,12 @@ function fetch_parsed_body()
440
460
return $ x ;
441
461
}
442
462
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
+ }
443
471
}
0 commit comments