From: skodak Date: Mon, 25 May 2009 20:55:27 +0000 (+0000) Subject: MDL-15249 $_SERVER['HTTP_HOST'] not availabel in CLI script, replaced by parsing... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=aa282b10fbc46e23917bb565d9afc11dda2cff89;p=moodle.git MDL-15249 $_SERVER['HTTP_HOST'] not availabel in CLI script, replaced by parsing of wwwroot which should give the same info --- diff --git a/admin/settings/server.php b/admin/settings/server.php index 8bdaa938a7..6336c771b3 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -22,7 +22,7 @@ $temp->add(new admin_setting_configtext('smtphosts', get_string('smtphosts', 'ad $temp->add(new admin_setting_configtext('smtpuser', get_string('smtpuser', 'admin'), get_string('configsmtpuser', 'admin'), '', PARAM_NOTAGS)); $temp->add(new admin_setting_configpasswordunmask('smtppass', get_string('smtppass', 'admin'), get_string('configsmtpuser', 'admin'), '')); $temp->add(new admin_setting_configtext('smtpmaxbulk', get_string('smtpmaxbulk', 'admin'), get_string('configsmtpmaxbulk', 'admin'), 1, PARAM_INT)); -$temp->add(new admin_setting_configtext('noreplyaddress', get_string('noreplyaddress', 'admin'), get_string('confignoreplyaddress', 'admin'), 'noreply@' . $_SERVER['HTTP_HOST'], PARAM_NOTAGS)); +$temp->add(new admin_setting_configtext('noreplyaddress', get_string('noreplyaddress', 'admin'), get_string('confignoreplyaddress', 'admin'), 'noreply@' . get_host_from_url($CFG->wwwroot), PARAM_NOTAGS)); $temp->add(new admin_setting_configselect('digestmailtime', get_string('digestmailtime', 'admin'), get_string('configdigestmailtime', 'admin'), 17, array('00' => '00', '01' => '01', '02' => '02', diff --git a/lib/db/install.php b/lib/db/install.php index 7c441bf0a2..b0e092cc93 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -51,7 +51,7 @@ function xmldb_main_install() { 'template' => 'default', 'theme' => 'standardwhite', 'filter_multilang_converted' => 1, - 'siteidentifier' => random_string(32).$_SERVER['HTTP_HOST'], + 'siteidentifier' => random_string(32).get_host_from_url($CFG->wwwroot), 'backup_version' => 2008111700, 'backup_release' => '2.0 dev', 'blocks_version' => 2007081300, // might be removed soon @@ -158,7 +158,7 @@ function xmldb_main_install() { $admin->lang = $CFG->lang; $admin->maildisplay = 1; $admin->timemodified = time(); - $admin->lastip = getremoteaddr(); // installation hijacking prevention + $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention $admin->id = $DB->insert_record('user', $admin); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 664d8bf8f5..8ea7e01f06 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -661,6 +661,19 @@ function is_number($value) { } } +/** + * Returns host part from url + * @param string $url full url + * @return string host, null if not found + */ +function get_host_from_url($url) { + preg_match('|^[a-z]+://([a-zA-Z0-9-.]+)|i', $url, $matches); + if ($matches) { + return $matches[1]; + } + return null; +} + /** * Tests whether anything was returned by text editor * diff --git a/mod/chat/settings.php b/mod/chat/settings.php index 7769d5af79..46f8b6d7d9 100644 --- a/mod/chat/settings.php +++ b/mod/chat/settings.php @@ -33,7 +33,7 @@ $settings->add(new admin_setting_heading('chat_daemon_heading', get_string('meth get_string('explainmethoddaemon', 'chat'))); $settings->add(new admin_setting_configtext('chat_serverhost', get_string('serverhost', 'chat'), - get_string('configserverhost', 'chat'), $_SERVER['HTTP_HOST'])); + get_string('configserverhost', 'chat'), get_host_from_url($CFG->wwwroot))); $settings->add(new admin_setting_configtext('chat_serverip', get_string('serverip', 'chat'), get_string('configserverip', 'chat'), '127.0.0.1'));