]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15008: mnet/environment.php: Update wwwroot/ip_address when key is deleted/recreated.
authorcataluke <cataluke>
Thu, 12 Jun 2008 01:16:49 +0000 (01:16 +0000)
committercataluke <cataluke>
Thu, 12 Jun 2008 01:16:49 +0000 (01:16 +0000)
mnet/environment.php

index 16e3f198d4a0ed430531611f905b3d6752835203..c8863ece009e0e1cb0ded5687864d58a9f3aef1b 100644 (file)
@@ -150,7 +150,7 @@ class mnet_environment {
     }
 
     function replace_keys() {
-        global $DB;
+        global $DB, $CFG;
 
         $this->keypair = array();
         $this->keypair = mnet_generate_keypair();
@@ -158,6 +158,20 @@ class mnet_environment {
         $details                  = openssl_x509_parse($this->public_key);
         $this->public_key_expires = $details['validTo_time_t'];
 
+        $this->wwwroot            = $CFG->wwwroot;
+        if (empty($_SERVER['SERVER_ADDR'])) {
+            // SERVER_ADDR is only returned by Apache-like webservers
+            $my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
+            $my_ip       = gethostbyname($my_hostname);  // Returns unmodified hostname on failure. DOH!
+            if ($my_ip == $my_hostname) {
+                $this->ip_address = 'UNKNOWN';
+            } else {
+                $this->ip_address = $my_ip;
+            }
+        } else {
+            $this->ip_address = $_SERVER['SERVER_ADDR'];
+        }
+
         set_config('openssl', implode('@@@@@@@@', $this->keypair), 'mnet');
 
         $DB->update_record('mnet_host', $this);