From 93f66983ccb2a2f82314f4794c04936d09d9f04e Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 2 Jan 2009 22:56:48 +0000 Subject: [PATCH] MDL-17773 new get_login_url() function - fixes missing httpslogin tweaks --- admin/settings/users.php | 2 +- backup/backup.php | 7 +++--- backup/backup_check.html | 8 ++++--- backup/backup_execute.html | 8 ++++--- backup/backup_form.html | 8 ++++--- backup/restore.php | 8 ++++--- backup/restore_check.html | 6 +++-- backup/restore_execute.html | 8 ++++--- backup/restore_form.html | 6 +++-- backup/restore_precheck.html | 10 ++++---- blocks/login/block_login.php | 2 +- blocks/tags/block_tags.php | 2 +- course/enrol.php | 6 +---- enrol/manual/enrol.html | 7 +----- lib/moodlelib.php | 45 +++++++++++++++++++++--------------- lib/sessionlib.php | 23 ++++++++++++++++++ lib/weblib.php | 10 +++----- login/change_password.php | 2 +- login/forgot_password.php | 4 ++-- login/signup.php | 2 +- message/edit.php | 2 +- mod/chat/view.php | 6 +---- mod/choice/view.php | 6 +---- mod/forum/markposts.php | 7 +----- mod/forum/post.php | 7 +----- mod/forum/subscribe.php | 6 +---- mod/quiz/view.php | 7 +----- my/index.php | 7 +----- search/add.php | 2 +- search/delete.php | 2 +- search/indexer.php | 2 +- search/indexersplash.php | 2 +- search/tests/index.php | 2 +- search/update.php | 2 +- user/edit.php | 2 +- user/view.php | 2 +- 36 files changed, 121 insertions(+), 117 deletions(-) diff --git a/admin/settings/users.php b/admin/settings/users.php index c4ddfd17c9..84690cd180 100644 --- a/admin/settings/users.php +++ b/admin/settings/users.php @@ -22,7 +22,7 @@ if ($hassiteconfig $temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'), get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show')))); $temp->add(new admin_setting_configtext('alternateloginurl', get_string('alternateloginurl', 'auth'), - get_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php')), '')); + get_string('alternatelogin', 'auth', htmlspecialchars(get_login_url())), '')); $temp->add(new admin_setting_configtext('forgottenpasswordurl', get_string('forgottenpasswordurl', 'auth'), get_string('forgottenpassword', 'auth'), '')); $temp->add(new admin_setting_configtextarea('auth_instructions', get_string('instructions', 'auth'), diff --git a/backup/backup.php b/backup/backup.php index 861b122571..630bd51f55 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -14,22 +14,23 @@ $cancel = optional_param( 'cancel' ); $launch = optional_param( 'launch' ); + $loginurl = get_login_url(); if (!empty($id)) { require_login($id); if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) { - print_error('cannotuseadminadminorteacher', 'error', "$CFG->wwwroot/login/index.php"); + print_error('cannotuseadminadminorteacher', 'error', $loginurl); } } else { require_login(); if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { - print_error('cannotuseadmin', 'error', "$CFG->wwwroot/login/index.php"); + print_error('cannotuseadmin', 'error', $loginurl); } } if (!empty($to)) { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) { - print_error('cannotuseadminadminorteacher', 'error', "$CFG->wwwroot/login/index.php"); + print_error('cannotuseadminadminorteacher', 'error', $loginurl); } } diff --git a/backup/backup_check.html b/backup/backup_check.html index 09b6fd4e8e..94d92b6236 100644 --- a/backup/backup_check.html +++ b/backup/backup_check.html @@ -4,19 +4,21 @@ //Check login require_login(); + $loginurl = get_login_url(); + if (!empty($course->id)) { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/backup_execute.html b/backup/backup_execute.html index 7c4bfc86ae..1ca0344b41 100644 --- a/backup/backup_execute.html +++ b/backup/backup_execute.html @@ -4,19 +4,21 @@ //Check login require_login(); + $loginurl = get_login_url(); + if (!empty($course->id)) { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/backup_form.html b/backup/backup_form.html index b94e15f150..06653c394e 100644 --- a/backup/backup_form.html +++ b/backup/backup_form.html @@ -5,19 +5,21 @@ //Check login require_login(); + $loginurl = get_login_url(); + if (!empty($course->id)) { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/restore.php b/backup/restore.php index f79fd96499..ff4299cac0 100644 --- a/backup/restore.php +++ b/backup/restore.php @@ -61,21 +61,23 @@ $to = $SESSION->restore->course_id; } + $loginurl = get_login_url(); + if (!empty($id)) { require_login($id); if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/restore_check.html b/backup/restore_check.html index ac35bedda1..871febb379 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -190,14 +190,16 @@ //Check login require_login(); + $loginurl = get_login_url(); + //Check admin if (!empty($id)) { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/restore_execute.html b/backup/restore_execute.html index 1216fe3933..4c10580c15 100644 --- a/backup/restore_execute.html +++ b/backup/restore_execute.html @@ -20,21 +20,23 @@ //Check login require_login(); + $loginurl = get_login_url(); + //Check admin if (!empty($id)) { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/backup/restore_form.html b/backup/restore_form.html index 704e37f7be..d501cb20dd 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -25,14 +25,16 @@ //Check login require_login(); + $loginurl = get_login_url(); + //Check admin if (!empty($id)) { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { - print_error('cannotuseadminadminorteacher', '', '$CFG->wwwroot/login/index.php'); + print_error('cannotuseadminadminorteacher', '', $loginurl); } } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { - print_error('cannotuseadmin', '', '$CFG->wwwroot/login/index.php'); + print_error('cannotuseadmin', '', $loginurl); } } diff --git a/backup/restore_precheck.html b/backup/restore_precheck.html index e14d2fbe87..e6cecbab11 100644 --- a/backup/restore_precheck.html +++ b/backup/restore_precheck.html @@ -11,22 +11,24 @@ //Check login require_login(); - + + $loginurl = get_login_url(); + //Check admin if (!empty($id)) { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) { if (empty($to)) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to)) && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $to))) { - print_error("cannotuseadminadminorteacher", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadminadminorteacher", '', $loginurl); } } } } else { if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM))) { - print_error("cannotuseadmin", '', "$CFG->wwwroot/login/index.php"); + print_error("cannotuseadmin", '', $loginurl); } } diff --git a/blocks/login/block_login.php b/blocks/login/block_login.php index 8d924e885f..4befcac740 100644 --- a/blocks/login/block_login.php +++ b/blocks/login/block_login.php @@ -43,7 +43,7 @@ class block_login extends block_base { if (!isloggedin() or isguestuser()) { // Show the block - $this->content->text .= "\n".'
'; + $this->content->text .= "\n".''; $this->content->text .= '
'; $this->content->text .= '
'; diff --git a/blocks/tags/block_tags.php b/blocks/tags/block_tags.php index fecd63475f..67da56c802 100644 --- a/blocks/tags/block_tags.php +++ b/blocks/tags/block_tags.php @@ -309,7 +309,7 @@ EOT; } else { //if not logged in $this->content->footer = '
'.get_string('please', $tagslang).' - '.get_string('login', $tagslang).' + '.get_string('login', $tagslang).' '.get_string('tagunits', $tagslang); } } diff --git a/course/enrol.php b/course/enrol.php index 6d2e79c257..76b95bd4db 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -11,12 +11,8 @@ $loginasguest = optional_param('loginasguest', 0, PARAM_BOOL); // hmm, is this still needed? if (!isloggedin()) { - $wwwroot = $CFG->wwwroot; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } // do not use require_login here because we are usually comming from it - redirect($wwwroot.'/login/index.php'); + redirect(get_login_url()); } if (!$course = $DB->get_record('course', array('id'=>$id))) { diff --git a/enrol/manual/enrol.html b/enrol/manual/enrol.html index 93012ea3b5..919a2da826 100644 --- a/enrol/manual/enrol.html +++ b/enrol/manual/enrol.html @@ -39,12 +39,7 @@ if (isguestuser()) { print_box_start('centerpara'); - if (empty($CFG->loginhttps)) { - $loginurl = $CFG->wwwroot .'/login/index.php'; - } else { - $wwwroot = str_replace('http:','https:', $CFG->wwwroot); - $loginurl = $wwwroot .'/login/index.php'; - } + $loginurl = get_login_url(); print_single_button($loginurl, null, get_string('login')); print_box_end(); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a3b434924c..c63a6bcd6e 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1861,6 +1861,27 @@ function course_setup($courseorid=0) { } +/** + * Returns full login url. + * + * @param bool $loginguest add login guest param + * @return string login url + */ +function get_login_url($loginguest=false) { + global $CFG; + + if (empty($CFG->loginhttps) or $loginguest) { //do not require https for guest logins + $loginguest = $loginguest ? '?loginguest=true' : ''; + $url = "$CFG->wwwroot/login/index.php$loginguest"; + + } else { + $wwwroot = str_replace('http:','https:', $CFG->wwwroot); + $url = "$wwwroot/login/index.php"; + } + + return $url; +} + /** * This function checks that the current user is logged in and has the * required privileges @@ -1906,17 +1927,12 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu $SESSION->fromurl = $_SERVER['HTTP_REFERER']; } if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests) and ($COURSE->id == SITEID or $COURSE->guest) ) { - $loginguest = '?loginguest=true'; - } else { - $loginguest = ''; - } - if (empty($CFG->loginhttps) or $loginguest) { //do not require https for guest logins - redirect($CFG->wwwroot .'/login/index.php'. $loginguest); + $loginguest = true; } else { - $wwwroot = str_replace('http:','https:', $CFG->wwwroot); - redirect($wwwroot .'/login/index.php'); + $loginguest = false; } - exit; + redirect(get_login_url($loginguest)); + exit; // never reached } /// loginas as redirection if needed @@ -1956,13 +1972,6 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu redirect($CFG->wwwroot .'/user/edit.php?id='. $USER->id .'&course='. SITEID); } -/// Make sure current IP matches the one for this session (if required) - if (!empty($CFG->tracksessionip)) { - if ($USER->sessionIP != md5(getremoteaddr())) { - print_error('sessionipnomatch', 'error'); - } - } - /// Make sure the USER has a sesskey set up. Used for checking script parameters. sesskey(); @@ -2069,7 +2078,7 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu case 1: /// Guests always allowed if (!has_capability('moodle/course:view', $COURSE->context)) { // Prohibited by capability print_header_simple(); - notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), "$CFG->wwwroot/login/index.php"); + notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), get_login_url()); } if (!empty($cm) and !$cm->visible) { // Not allowed to see module, send to course page redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, @@ -2094,7 +2103,7 @@ function require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsu print_header_simple('', '', build_navigation(array(array('name' => $strloggedinasguest, 'link' => null, 'type' => 'misc')))); if (empty($USER->access['rsw'][$COURSE->context->path])) { // Normal guest - notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), "$CFG->wwwroot/login/index.php"); + notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), get_login_url()); } else { notify(get_string('guestsnotallowed', '', format_string($COURSE->fullname))); echo '
'.switchroles_form($COURSE->id).'
'; diff --git a/lib/sessionlib.php b/lib/sessionlib.php index 82a5b5595d..470e7701be 100644 --- a/lib/sessionlib.php +++ b/lib/sessionlib.php @@ -95,6 +95,29 @@ class moodle_session { session_set_user($user); } + protected function check_security() { + global $CFG; + + if (!empty($_SESSION['USER']->id)) { + /// Make sure current IP matches the one for this session (if required) + $remoteaddr = getremoteaddr(); + + if (empty($_SESSION['USER']->sessionip)) { + $_SESSION['USER']->sessionip = $remoteaddr; + } + + if ($_SESSION['USER']->sessionip != $remoteaddr) { + if (!is_guestuser($_SESSION['USER'])) { + $link = ''; + } else { + + } + print_error('sessionipnomatch', 'error'); + } + } + + } + /** * Terminates active moodle session */ diff --git a/lib/weblib.php b/lib/weblib.php index 39c5eb2847..464e6c8afb 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3506,11 +3506,7 @@ function user_login_string($course=NULL, $user=NULL) { $realuserinfo = ''; } - if (empty($CFG->loginhttps)) { - $wwwroot = $CFG->wwwroot; - } else { - $wwwroot = str_replace('http:','https:',$CFG->wwwroot); - } + $loginurl = get_login_url(); if (empty($course->id)) { // $course->id is not defined during installation @@ -3525,7 +3521,7 @@ function user_login_string($course=NULL, $user=NULL) { } if (isset($user->username) && $user->username == 'guest') { $loggedinas = $realuserinfo.get_string('loggedinasguest'). - " (frametarget href=\"$wwwroot/login/index.php\">".get_string('login').')'; + " (frametarget href=\"$loginurl\">".get_string('login').')'; } else if (!empty($user->access['rsw'][$context->path])) { $rolename = ''; if ($role = $DB->get_record('role', array('id'=>$user->access['rsw'][$context->path]))) { @@ -3540,7 +3536,7 @@ function user_login_string($course=NULL, $user=NULL) { } } else { $loggedinas = get_string('loggedinnot', 'moodle'). - " (frametarget href=\"$wwwroot/login/index.php\">".get_string('login').')'; + " (frametarget href=\"$loginurl\">".get_string('login').')'; } return '
'.$loggedinas.'
'; } diff --git a/login/change_password.php b/login/change_password.php index e4d895a610..5775936942 100644 --- a/login/change_password.php +++ b/login/change_password.php @@ -21,7 +21,7 @@ if (empty($SESSION->wantsurl)) { $SESSION->wantsurl = $CFG->httpswwwroot.'/login/change_password.php'; } - redirect($CFG->httpswwwroot.'/login/index.php'); + redirect(get_login_url()); } // do not require change own password cap if change forced diff --git a/login/forgot_password.php b/login/forgot_password.php index 8a04a55a37..1598ca6d89 100644 --- a/login/forgot_password.php +++ b/login/forgot_password.php @@ -18,7 +18,7 @@ $systemcontext = get_context_instance(CONTEXT_SYSTEM); $strforgotten = get_string('passwordforgotten'); $strlogin = get_string('login'); -$navigation = build_navigation(array(array('name' => $strlogin, 'link' => "$CFG->wwwroot/login/index.php", 'type' => 'misc'), +$navigation = build_navigation(array(array('name' => $strlogin, 'link' => get_login_url(), 'type' => 'misc'), array('name' => $strforgotten, 'link' => null, 'type' => 'misc'))); // if alternatepasswordurl is defined, then we'll just head there @@ -91,7 +91,7 @@ if ($p_secret !== false) { $mform = new login_forgot_password_form(); if ($mform->is_cancelled()) { - redirect($CFG->httpswwwroot.'/login/index.php'); + redirect(get_login_url()); } else if ($data = $mform->get_data()) { /// find the user in the database and mail info diff --git a/login/signup.php b/login/signup.php index 4ee44b361c..124759083e 100644 --- a/login/signup.php +++ b/login/signup.php @@ -29,7 +29,7 @@ $mform_signup = new login_signup_form(); if ($mform_signup->is_cancelled()) { - redirect($CFG->httpswwwroot.'/login/index.php'); + redirect(get_login_url()); } else if ($user = $mform_signup->get_data()) { $user->confirmed = 0; diff --git a/message/edit.php b/message/edit.php index a339fc9cea..491dd6d49f 100644 --- a/message/edit.php +++ b/message/edit.php @@ -51,7 +51,7 @@ if (empty($SESSION->wantsurl)) { $SESSION->wantsurl = $CFG->httpswwwroot.'/message/edit.php'; } - redirect($CFG->httpswwwroot.'/login/index.php'); + redirect(get_login_url()); } } diff --git a/mod/chat/view.php b/mod/chat/view.php index 028c3b9b36..60944b7eed 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -50,13 +50,9 @@ $navigation = build_navigation('', $cm); print_header_simple(format_string($chat->name), '', $navigation, '', '', true, '', navmenu($course, $cm)); - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } notice_yesno(get_string('noguests', 'chat').'

'.get_string('liketologin'), - $wwwroot, $CFG->wwwroot.'/course/view.php?id='.$course->id); + get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id); print_footer($course); exit; diff --git a/mod/choice/view.php b/mod/choice/view.php index c1664e9506..6b00ca3504 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -127,12 +127,8 @@ $sitecontext = get_context_instance(CONTEXT_SYSTEM); if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) { // Guest on whole site - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } notice_yesno(get_string('noguestchoose', 'choice').'

'.get_string('liketologin'), - $wwwroot, $_SERVER['HTTP_REFERER']); + get_login_url(), $_SERVER['HTTP_REFERER']); } else if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Guest in this course only $SESSION->wantsurl = $FULLME; diff --git a/mod/forum/markposts.php b/mod/forum/markposts.php index 564065d7ac..6210a9bd98 100644 --- a/mod/forum/markposts.php +++ b/mod/forum/markposts.php @@ -33,15 +33,10 @@ } if (isguest()) { // Guests can't change forum - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } - $navigation = build_navigation('', $cm); print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", navmenu($course, $cm)); notice_yesno(get_string('noguesttracking', 'forum').'

'.get_string('liketologin'), - $wwwroot, $returnto); + get_login_url(), $returnto); print_footer($course); exit; } diff --git a/mod/forum/post.php b/mod/forum/post.php index 28ef64cbc9..e451b88862 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -24,11 +24,6 @@ if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) { - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:', 'https:', $wwwroot); - } - if (!empty($forum)) { // User is starting a new discussion in a forum if (! $forum = $DB->get_record('forum', array('id' => $forum))) { print_error('invalidforumid', 'forum'); @@ -62,7 +57,7 @@ print_header($course->shortname, $course->fullname, $navigation, '' , '', true, "", navmenu($course, $cm)); notice_yesno(get_string('noguestpost', 'forum').'

'.get_string('liketologin'), - $wwwroot, get_referer(false)); + get_login_url(), get_referer(false)); print_footer($course); exit; } diff --git a/mod/forum/subscribe.php b/mod/forum/subscribe.php index fbcf8c61dc..c2876e4ece 100644 --- a/mod/forum/subscribe.php +++ b/mod/forum/subscribe.php @@ -46,16 +46,12 @@ require_login($course->id, false, $cm); if (isguest()) { // Guests can't subscribe - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } $navigation = build_navigation('', $cm); print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", navmenu($course, $cm)); notice_yesno(get_string('noguestsubscribe', 'forum').'

'.get_string('liketologin'), - $wwwroot, $_SERVER['HTTP_REFERER']); + get_login_url(), $_SERVER['HTTP_REFERER']); print_footer($course); exit; } diff --git a/mod/quiz/view.php b/mod/quiz/view.php index dda980a588..388bdaebdb 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -117,13 +117,8 @@ /// Guests can't do a quiz, so offer them a choice of logging in or going back. if (isguestuser()) { - $loginurl = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $loginurl = str_replace('http:','https:', $loginurl); - } - notice_yesno('

' . get_string('guestsno', 'quiz') . "

\n\n

" . - get_string('liketologin') . "

\n", $loginurl, get_referer(false)); + get_string('liketologin') . "

\n", get_login_url(), get_referer(false)); finish_page($course); } diff --git a/my/index.php b/my/index.php index 449a9541e6..1c052e6291 100644 --- a/my/index.php +++ b/my/index.php @@ -12,14 +12,9 @@ $mymoodlestr = get_string('mymoodle','my'); if (isguest()) { - $wwwroot = $CFG->wwwroot.'/login/index.php'; - if (!empty($CFG->loginhttps)) { - $wwwroot = str_replace('http:','https:', $wwwroot); - } - print_header($mymoodlestr); notice_yesno(get_string('noguest', 'my').'

'.get_string('liketologin'), - $wwwroot, $CFG->wwwroot); + get_login_url(), $CFG->wwwroot); print_footer(); die(); } diff --git a/search/add.php b/search/add.php index 8973ed9e77..26eb4159d9 100644 --- a/search/add.php +++ b/search/add.php @@ -35,7 +35,7 @@ } if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { - print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php"); + print_error('beadmin', 'search', get_login_url()); } /// check for php5 (lib.php) diff --git a/search/delete.php b/search/delete.php index 4f4790d2b6..5ab8d5e3bb 100644 --- a/search/delete.php +++ b/search/delete.php @@ -32,7 +32,7 @@ } if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { - print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php"); + print_error('beadmin', 'search', get_login_url()); } //if try { diff --git a/search/indexer.php b/search/indexer.php index 84bfb842d7..c4b4e29415 100644 --- a/search/indexer.php +++ b/search/indexer.php @@ -49,7 +49,7 @@ $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; } if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { - print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php"); + print_error('beadmin', 'search', get_login_url()); } /// confirmation flag to prevent accidental reindexing (indexersplash.php is the correct entry point) diff --git a/search/indexersplash.php b/search/indexersplash.php index c5790ae1d1..b30b410301 100644 --- a/search/indexersplash.php +++ b/search/indexersplash.php @@ -33,7 +33,7 @@ ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path } if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { - print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php"); + print_error('beadmin', 'search', get_login_url()); } require_once("$CFG->dirroot/search/indexlib.php"); diff --git a/search/tests/index.php b/search/tests/index.php index 31cb5e6613..9b7cb7a7d1 100644 --- a/search/tests/index.php +++ b/search/tests/index.php @@ -24,7 +24,7 @@ } if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { - print_error('onlyadmins', 'error', "$CFG->wwwroot/login/index.php"); + print_error('onlyadmins', 'error', get_login_url()); } //if mtrace('
Server Time: '.date('r',time()));
diff --git a/search/update.php b/search/update.php
index b5eaa445e2..ab5d56d95e 100644
--- a/search/update.php
+++ b/search/update.php
@@ -35,7 +35,7 @@
     }
 
     if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
-        print_error('beadmin', 'search', "$CFG->wwwroot/login/index.php");
+        print_error('beadmin', 'search', get_login_url());
     }
 
     try {
diff --git a/user/edit.php b/user/edit.php
index 4544635bb2..15172d3d2a 100644
--- a/user/edit.php
+++ b/user/edit.php
@@ -22,7 +22,7 @@
         if (empty($SESSION->wantsurl)) {
             $SESSION->wantsurl = $CFG->httpswwwroot.'/user/edit.php';
         }
-        redirect($CFG->httpswwwroot.'/login/index.php');
+        redirect(get_login_url());
     }
 
     // Guest can not edit
diff --git a/user/view.php b/user/view.php
index e00bbcb18d..e8983df682 100644
--- a/user/view.php
+++ b/user/view.php
@@ -50,7 +50,7 @@
     if (!empty($CFG->forceloginforprofiles)) {
         require_login();
         if (isguest()) {
-            redirect("$CFG->wwwroot/login/index.php");
+            redirect(get_login_url());
         }
     }
 
-- 
2.39.5