~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to auth/mnet/auth.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
        global $CFG, $USER, $DB;
142
142
        require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
143
143
 
144
 
        if (session_is_loggedinas()) {
 
144
        if (\core\session\manager::is_loggedinas()) {
145
145
            print_error('notpermittedtojumpas', 'mnet');
146
146
        }
147
147
 
148
148
        // check remote login permissions
149
 
        if (! has_capability('moodle/site:mnetlogintoremote', get_system_context())
 
149
        if (! has_capability('moodle/site:mnetlogintoremote', context_system::instance())
150
150
                or is_mnet_remote_user($USER)
151
151
                or isguestuser()
152
152
                or !isloggedin()) {
216
216
        global $CFG, $DB;
217
217
        require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
218
218
        require_once $CFG->libdir . '/gdlib.php';
 
219
        require_once($CFG->dirroot.'/user/lib.php');
219
220
 
220
221
        // verify the remote host is configured locally before attempting RPC call
221
222
        if (! $remotehost = $DB->get_record('mnet_host', array('wwwroot' => $remotepeer->wwwroot, 'deleted' => 0))) {
361
362
        if (empty($localuser->firstaccess)) { // Now firstaccess, grab it here
362
363
            $localuser->firstaccess = time();
363
364
        }
364
 
 
365
 
        $DB->update_record('user', $localuser);
 
365
        user_update_user($localuser, false);
366
366
 
367
367
        if (!$firsttime) {
368
368
            // repeat customer! let the IDP know about enrolments
766
766
            }
767
767
            $mnethostlogssql = "
768
768
            SELECT
769
 
                mhostlogs.remoteid, mhostlogs.time, mhostlogs.userid, mhostlogs.ip,
770
 
                mhostlogs.course, mhostlogs.module, mhostlogs.cmid, mhostlogs.action,
771
 
                mhostlogs.url, mhostlogs.info, mhostlogs.username, c.fullname as coursename,
772
 
                c.modinfo
 
769
                l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
 
770
                l.action, l.url, l.info, u.username
773
771
            FROM
774
 
                (
775
 
                    SELECT
776
 
                        l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
777
 
                        l.action, l.url, l.info, u.username
778
 
                    FROM
779
 
                        {user} u
780
 
                        INNER JOIN {log} l on l.userid = u.id
781
 
                    WHERE
782
 
                        u.mnethostid = ?
783
 
                        AND l.id > ?
784
 
                    ORDER BY remoteid ASC
785
 
                    LIMIT 500
786
 
                ) mhostlogs
787
 
                INNER JOIN {course} c on c.id = mhostlogs.course
788
 
            ORDER by mhostlogs.remoteid ASC";
 
772
                {user} u
 
773
                INNER JOIN {log} l on l.userid = u.id
 
774
            WHERE
 
775
                u.mnethostid = ?
 
776
                AND l.id > ?
 
777
                AND l.course IS NOT NULL
 
778
             ORDER by l.id ASC";
789
779
 
790
 
            $mnethostlogs = $DB->get_records_sql($mnethostlogssql, array($mnethostid, $mnet_request->response['last log id']));
 
780
            $mnethostlogs = $DB->get_records_sql($mnethostlogssql, array($mnethostid, $mnet_request->response['last log id']), 0, 500);
791
781
 
792
782
            if ($mnethostlogs == false) {
793
783
                continue;
796
786
            $processedlogs = array();
797
787
 
798
788
            foreach($mnethostlogs as $hostlog) {
799
 
                // Extract the name of the relevant module instance from the
800
 
                // course modinfo if possible.
801
 
                if (!empty($hostlog->modinfo) && !empty($hostlog->cmid)) {
802
 
                    $modinfo = unserialize($hostlog->modinfo);
803
 
                    unset($hostlog->modinfo);
804
 
                    $modulearray = array();
805
 
                    foreach($modinfo as $module) {
806
 
                        $modulearray[$module->cm] = $module->name;
 
789
                try {
 
790
                    // Get impersonalised course information. If it is cached there will be no DB queries.
 
791
                    $modinfo = get_fast_modinfo($hostlog->course, -1);
 
792
                    $hostlog->coursename = $modinfo->get_course()->fullname;
 
793
                    if (!empty($hostlog->cmid) && isset($modinfo->cms[$hostlog->cmid])) {
 
794
                        $hostlog->resource_name = $modinfo->cms[$hostlog->cmid]->name;
 
795
                    } else {
 
796
                        $hostlog->resource_name = '';
807
797
                    }
808
 
                    $hostlog->resource_name = $modulearray[$hostlog->cmid];
809
 
                } else {
810
 
                    $hostlog->resource_name = '';
 
798
                } catch (moodle_exception $e) {
 
799
                    // Course not found
 
800
                    continue;
811
801
                }
812
802
 
813
803
                $processedlogs[] = array (
928
918
                $returnString .= "We failed to refresh the session for the following usernames: \n".implode("\n", $subArray)."\n\n";
929
919
            } else {
930
920
                foreach($results as $emigrant) {
931
 
                    session_touch($emigrant->session_id);
 
921
                    \core\session\manager::touch_session($emigrant->session_id);
932
922
                }
933
923
            }
934
924
        }
1084
1074
                                 array('useragent'=>$useragent, 'userid'=>$userid));
1085
1075
 
1086
1076
        if (isset($remoteclient) && isset($remoteclient->id)) {
1087
 
            session_kill_user($userid);
 
1077
            \core\session\manager::kill_user_sessions($userid);
1088
1078
        }
1089
1079
        return $returnstring;
1090
1080
    }
1104
1094
        $session = $DB->get_record('mnet_session', array('username'=>$username, 'mnethostid'=>$remoteclient->id, 'useragent'=>$useragent));
1105
1095
        $DB->delete_records('mnet_session', array('username'=>$username, 'mnethostid'=>$remoteclient->id, 'useragent'=>$useragent));
1106
1096
        if (false != $session) {
1107
 
            session_kill($session->session_id);
 
1097
            \core\session\manager::kill_session($session->session_id);
1108
1098
            return true;
1109
1099
        }
1110
1100
        return false;
1121
1111
        global $CFG;
1122
1112
        if (is_array($sessionArray)) {
1123
1113
            while($session = array_pop($sessionArray)) {
1124
 
                session_kill($session->session_id);
 
1114
                \core\session\manager::kill_session($session->session_id);
1125
1115
            }
1126
1116
            return true;
1127
1117
        }