File inc/util.inc.php changed (mode: 100644) (index e48ef9a..44ecd5c) |
... |
... |
function rg_base_url() |
246 |
246 |
|
|
247 |
247 |
/* |
/* |
248 |
248 |
* Builds a correct URL to refer to the current virtualhost |
* Builds a correct URL to refer to the current virtualhost |
|
249 |
|
* @http(s)_allow: '0' if not allowed, FALSE if unknown, else port number |
|
250 |
|
* Note: at least one of http_allow or https_allow will be set to a port number. |
249 |
251 |
*/ |
*/ |
250 |
252 |
function rg_base_url_build($hostname, $http_allow, $https_allow) |
function rg_base_url_build($hostname, $http_allow, $https_allow) |
251 |
253 |
{ |
{ |
252 |
254 |
global $rg_base_url; |
global $rg_base_url; |
253 |
255 |
|
|
254 |
256 |
// We are forced to use something if we cannot get them from cache/db |
// We are forced to use something if we cannot get them from cache/db |
255 |
|
if ($hostname === FALSE) |
|
|
257 |
|
if (($hostname === FALSE) || empty($hostname)) |
256 |
258 |
$hostname = php_uname('n'); |
$hostname = php_uname('n'); |
257 |
|
if ($http_allow === FALSE) |
|
258 |
|
$http_allow = 80; |
|
259 |
|
if ($https_allow === FALSE) |
|
260 |
|
$https_allow = 443; |
|
261 |
259 |
|
|
262 |
|
$add = ''; |
|
263 |
|
if (strcmp($https_allow, '443') != 0) |
|
264 |
|
$add = ':' . $https_allow; |
|
|
260 |
|
// Prefer httpS |
|
261 |
|
if (intval($https_allow) > 0) { |
|
262 |
|
$add = ''; |
|
263 |
|
if (strcmp($https_allow, '443') != 0) |
|
264 |
|
$add = ':' . $https_allow; |
265 |
265 |
|
|
266 |
|
if (strcmp($https_allow, '0') != 0) { |
|
267 |
266 |
$rg_base_url = 'https://' . $hostname . $add; |
$rg_base_url = 'https://' . $hostname . $add; |
268 |
267 |
return; |
return; |
269 |
268 |
} |
} |
File root/index.php changed (mode: 100644) (index d6d1b36..3038b86) |
... |
... |
if ($r === FALSE) { |
112 |
112 |
} |
} |
113 |
113 |
|
|
114 |
114 |
// Sets http(s)_allow and hostname |
// Sets http(s)_allow and hostname |
|
115 |
|
$hostname = rg_state_get($db, 'hostname'); |
115 |
116 |
$http_allow = rg_state_get($db, 'http_allow'); |
$http_allow = rg_state_get($db, 'http_allow'); |
116 |
117 |
$https_allow = rg_state_get($db, 'https_allow'); |
$https_allow = rg_state_get($db, 'https_allow'); |
117 |
|
$hostname = rg_state_get($db, 'hostname'); |
|
118 |
118 |
if (isset($_SERVER['SERVER_NAME'])) { |
if (isset($_SERVER['SERVER_NAME'])) { |
119 |
119 |
$sn = $_SERVER['SERVER_NAME']; |
$sn = $_SERVER['SERVER_NAME']; |
120 |
120 |
$port = $_SERVER['SERVER_PORT']; |
$port = $_SERVER['SERVER_PORT']; |
|
... |
... |
if (isset($_SERVER['SERVER_NAME'])) { |
133 |
133 |
$https_allow = $port; |
$https_allow = $port; |
134 |
134 |
rg_state_set($db, 'https_allow', $https_allow); |
rg_state_set($db, 'https_allow', $https_allow); |
135 |
135 |
} |
} |
136 |
|
|
|
137 |
|
// We have https, no need for http! |
|
138 |
|
if (($http_allow === FALSE) || (strcmp($http_allow, '') == 0)) |
|
139 |
|
$http_allow = '0'; |
|
140 |
136 |
} else { |
} else { |
141 |
137 |
if ($http_allow === FALSE) { |
if ($http_allow === FALSE) { |
142 |
138 |
$http_allow = $port; |
$http_allow = $port; |
|
... |
... |
if ($rg['login_ui']['uid'] > 0) { |
264 |
260 |
} |
} |
265 |
261 |
|
|
266 |
262 |
|
|
267 |
|
// Redirect if http is not allowed and https is and the user is not logged in |
|
|
263 |
|
// Redirect if http is not allowed and the user is not logged in |
268 |
264 |
if (($rg['https'] == 0) |
if (($rg['https'] == 0) |
269 |
265 |
&& ($rg['login_ui']['uid'] == 0) |
&& ($rg['login_ui']['uid'] == 0) |
270 |
|
&& (strcmp($http_allow, '0') == 0) |
|
271 |
|
&& (strcmp($https_allow, '0') != 0)) |
|
|
266 |
|
&& (strcmp($http_allow, '0') == 0)) |
272 |
267 |
rg_redirect(rg_base_url() . $sparas); |
rg_redirect(rg_base_url() . $sparas); |
273 |
268 |
|
|
274 |
269 |
|
|