MDL-13894 Impoved fix with less duplicated code, no notices displayed before you get to the 'New settings' screen, and named constants instead of magic numbers.
This commit is contained in:
@@ -140,7 +140,11 @@ $temp = new admin_settingpage('http', get_string('http', 'admin'));
|
||||
$temp->add(new admin_setting_configtext('framename', get_string('framename', 'admin'), get_string('configframename', 'admin'), '_top', PARAM_ALPHAEXT));
|
||||
$temp->add(new admin_setting_configcheckbox('slasharguments', get_string('slasharguments', 'admin'), get_string('configslasharguments', 'admin'), 1));
|
||||
$temp->add(new admin_setting_heading('reverseproxy', get_string('reverseproxy', 'admin'), '', ''));
|
||||
$options = array(0=>'HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR', 1=>'HTTP_X_FORWARDED_FOR, REMOTE_ADDR', 2=>'HTTP_CLIENT, REMOTE_ADDR', 3=>'REMOTE_ADDR');
|
||||
$options = array(
|
||||
0 => 'HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR',
|
||||
GETREMOTEADDR_SKIP_HTTP_CLIENT_IP => 'HTTP_X_FORWARDED_FOR, REMOTE_ADDR',
|
||||
GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR => 'HTTP_CLIENT, REMOTE_ADDR',
|
||||
GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR|GETREMOTEADDR_SKIP_HTTP_CLIENT_IP => 'REMOTE_ADDR');
|
||||
$temp->add(new admin_setting_configselect('getremoteaddrconf', get_string('getremoteaddrconf', 'admin'), get_string('configgetremoteaddrconf', 'admin'), 0, $options));
|
||||
$temp->add(new admin_setting_heading('webproxy', get_string('webproxy', 'admin'), get_string('webproxyinfo', 'admin')));
|
||||
$temp->add(new admin_setting_configtext('proxyhost', get_string('proxyhost', 'admin'), get_string('configproxyhost', 'admin'), '', PARAM_HOST));
|
||||
|
||||
+19
-33
@@ -7377,43 +7377,29 @@ function remoteip_in_list($list){
|
||||
*
|
||||
* @return string The remote IP address
|
||||
*/
|
||||
define('GETREMOTEADDR_SKIP_HTTP_CLIENT_IP', '1');
|
||||
define('GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR', '2');
|
||||
function getremoteaddr() {
|
||||
global $CFG;
|
||||
|
||||
switch ($CFG->getremoteaddrconf) {
|
||||
case 3:
|
||||
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_CLIENT_IP']);
|
||||
}
|
||||
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
}
|
||||
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_CLIENT_IP']);
|
||||
}
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
}
|
||||
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
if (empty($CFG->getremoteaddrconf)) {
|
||||
// This will happen, for example, before just after the upgrade, as the
|
||||
// user is redirected to the admin screen.
|
||||
$variablestoskip = 0;
|
||||
} else {
|
||||
$variablestoskip = $CFG->getremoteaddrconf;
|
||||
}
|
||||
if (!($variablestoskip & GETREMOTEADDR_SKIP_HTTP_CLIENT_IP)) {
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_CLIENT_IP']);
|
||||
}
|
||||
}
|
||||
if (!($variablestoskip & GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR)) {
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
}
|
||||
}
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user