]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13894: saving a better source IP, following what the admin wants. (merge from...
authorscyrma <scyrma>
Thu, 18 Sep 2008 08:18:58 +0000 (08:18 +0000)
committerscyrma <scyrma>
Thu, 18 Sep 2008 08:18:58 +0000 (08:18 +0000)
admin/settings/server.php
lang/en_utf8/admin.php
lib/moodlelib.php

index 3b6ca7776d760e8a747f29794db126ab44c06b10..57e682d4699ba819710e407f7889caf4c041407e 100644 (file)
@@ -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));
index 4e49981f0eb2e951493d410d5ab20e88056d7206..5d2181dba96a0c0f9eef384358236549b8976510 100644 (file)
@@ -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 <a href=\"http://www.maxmind.com/\">MaxMind</a>. You can either buy a commercial version or use the free version.<br />Simply download <a href=\"http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz\" >http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz</a> 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 <a href=\"http://code.google.com/apis/maps/signup.html\" >http://code.google.com/apis/maps/signup.html</a>.<br />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'] = '<p><strong>Security Warning</strong>: to operate properly, Moodle requires <br />that you make certain changes to your current PHP settings.<p/><p>You <em>must</em> set <code>register_globals=off</code> and/or <code>magic_quotes_gpc=on</code>. <br />If possible, you should set <code>register_globals=off</code> to improve general <br /> server security, setting <code>magic_quotes_gpc=on</code> is also recommended.<p/><p>These settings are controlled by editing your <code>php.ini</code>, Apache/IIS <br />configuration or <code>.htaccess</code> file.</p>';
 $string['globalswarning'] = '<p><strong>SECURITY WARNING!</strong></p><p> To operate properly, Moodle requires <br />that you make certain changes to your current PHP settings.</p><p>You <em>must</em> set <code>register_globals=off</code>.</p><p>This setting is controlled by editing your <code>php.ini</code>, Apache/IIS <br />configuration or <code>.htaccess</code> file.</p>';
 $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';
index 61a338878fb4b447799ec39f68deb1d818268b99..8aa5763244d4da5c1a308db02b8c28a51cf963e1 100644 (file)
@@ -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']);
-    }
-    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
-        return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
-    }
-    if (!empty($_SERVER['REMOTE_ADDR'])) {
-        return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
+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']);
+            }
     }
-    return '';
 }
 
 /**