diff --git a/admin/settings/server.php b/admin/settings/server.php index 3b6ca7776d7..57e682d4699 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -139,6 +139,9 @@ $ADMIN->add('server', $temp); $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'); +$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)); $temp->add(new admin_setting_configtext('proxyport', get_string('proxyport', 'admin'), get_string('configproxyport', 'admin'), 0, PARAM_INT)); diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 4e49981f0eb..5d2181dba96 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -136,6 +136,7 @@ $string['configfrontpageloggedin'] = 'The items selected above will be displayed $string['configfullnamedisplay'] = 'This defines how names are shown when they are displayed in full. For most mono-lingual sites the most efficient setting is the default \"First name + Surname\", but you may choose to hide surnames altogether, or to leave it up to the current language pack to decide (some languages have different conventions).'; $string['configgdversion'] = 'Indicate the version of GD that is installed. The version shown by default is the one that has been auto-detected. Don\'t change this unless you really know what you\'re doing.'; $string['configgeoipfile'] = 'Location of GeoIP City binary data file. This file is not part of Moodle distribution and must be obtained separately from MaxMind. You can either buy a commercial version or use the free version.
Simply download http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz and extract it into \"$a\" directory on your server.'; +$string['configgetremoteaddrconf'] = 'If your server is behind a reverse proxy, you can change this setting to use a different header a the IP address to log.'; $string['configgooglemapkey'] = 'You need to enter a special key to use Google Maps for IP address lookup visualization. You can obtain the key free of charge at http://code.google.com/apis/maps/signup.html.
Your web site URL is: $a'; $string['configgradebookroles'] = 'This setting allows you to control who appears on the gradebook. Users need to have at least one of these roles in a course to be shown in the gradebook for that course.'; $string['configgradeexport'] = 'Choose which gradebook export formats are your primary methods for exporting grades. Chosen plugins will then set and use a \"last exported\" field for every grade. For example, this might result in exported records being identified as being \"new\" or \"updated\". If you are not sure about this then leave everything unchecked.'; @@ -398,6 +399,7 @@ $string['fullnamedisplay'] = 'Full Name Format'; $string['gdversion'] = 'GD version'; $string['generalsettings'] = 'General settings'; $string['geoipfile'] = 'GeoIP City data file'; +$string['getremoteaddrconf'] = 'Logged IP address source'; $string['globalsquoteswarning'] = '

Security Warning: to operate properly, Moodle requires
that you make certain changes to your current PHP settings.

You must set register_globals=off and/or magic_quotes_gpc=on.
If possible, you should set register_globals=off to improve general
server security, setting magic_quotes_gpc=on is also recommended.

These settings are controlled by editing your php.ini, Apache/IIS
configuration or .htaccess file.

'; $string['globalswarning'] = '

SECURITY WARNING!

To operate properly, Moodle requires
that you make certain changes to your current PHP settings.

You must set register_globals=off.

This setting is controlled by editing your php.ini, Apache/IIS
configuration or .htaccess file.

'; $string['googlemapkey'] = 'Google Maps API key'; @@ -648,6 +650,7 @@ $string['requiredtemplate'] = 'Required. You may use template syntax here (%%l = $string['requires'] = 'Requires'; $string['restrictbydefault'] = 'Restrict modules by default'; $string['restrictmodulesfor'] = 'Restrict modules for'; +$string['reverseproxy'] = 'Reverse proxy'; $string['riskconfig'] = 'Users could change site configuration and behaviour'; $string['riskconfigshort'] = 'Configuration risk'; $string['riskmanagetrust'] = 'Users could change trust settings of other users'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 61a338878fb..8aa5763244d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7377,17 +7377,43 @@ function remoteip_in_list($list){ * * @return string The remote IP address */ - function getremoteaddr() { - if (!empty($_SERVER['HTTP_CLIENT_IP'])) { - return cleanremoteaddr($_SERVER['HTTP_CLIENT_IP']); +function getremoteaddr() { + global $CFG; + + switch ($CFG->getremoteaddr) { + 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($_SERVER['HTTP_X_FORWARDED_FOR'])) { - return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']); - } - if (!empty($_SERVER['REMOTE_ADDR'])) { - return cleanremoteaddr($_SERVER['REMOTE_ADDR']); - } - return ''; } /**