示例#1
0
        $remove_days = $_POST['remove_days'];
    } else {
        $remove_days = 0;
    }
    if ($valid) {
        if (admin_prune_log($remove_type, $remove_days)) {
            header_redirect("admin_viewlog.php?webtag={$webtag}&sort_dir={$sort_dir}&sort_by={$sort_by}&group_by={$group_by}&pruned=true");
            exit;
        } else {
            $error_msg_array[] = gettext("Failed To Prune Admin Log");
            $valid = false;
        }
    }
}
html_draw_top(array('title' => gettext('Admin - Admin Access Log'), 'class' => 'window_title', 'main_css' => 'admin.css'));
$admin_log_array = admin_get_log_entries($page, $group_by, $sort_by, $sort_dir);
echo "<h1>", gettext("Admin"), html_style_image('separator'), gettext("Admin Access Log"), "</h1>\n";
if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
    html_display_error_array($error_msg_array, '86%', 'center');
} else {
    if (isset($_GET['pruned'])) {
        html_display_success_msg(gettext("Successfully Pruned Admin Log"), '86%', 'center');
    } else {
        if (sizeof($admin_log_array['admin_log_array']) < 1) {
            html_display_warning_msg(gettext("Admin Log is empty"), '86%', 'center');
        } else {
            html_display_warning_msg(gettext("This list shows the last actions sanctioned by users with Admin privileges."), '86%', 'center');
        }
    }
}
echo "<div align=\"center\">\n";
示例#2
0
function admin_get_log_entries($page = 1, $group_by = 'DAY', $sort_by = 'CREATED', $sort_dir = 'DESC')
{
    if (!($db = db::get())) {
        return false;
    }
    $group_by_array = array(ADMIN_LOG_GROUP_NONE => 'ADMIN_LOG.ID', ADMIN_LOG_GROUP_YEAR => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y')", ADMIN_LOG_GROUP_MONTH => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y%m')", ADMIN_LOG_GROUP_DAY => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y%m%d')", ADMIN_LOG_GROUP_HOUR => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y%m%d%H')", ADMIN_LOG_GROUP_MINUTE => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y%m%d%H%i')", ADMIN_LOG_GROUP_SECOND => "DATE_FORMAT(ADMIN_LOG.CREATED, '%Y%m%d%H%i%s')");
    $sort_by_array = array('CREATED', 'UID', 'ACTION', 'COUNT');
    $sort_dir_array = array('ASC', 'DESC');
    $admin_log_array = array();
    if (!is_numeric($page) || $page < 1) {
        $page = 1;
    }
    $offset = calculate_page_offset($page, 10);
    if (!isset($group_by_array[$group_by])) {
        $group_by = ADMIN_LOG_GROUP_NONE;
    }
    if (!in_array($sort_by, $sort_by_array)) {
        $sort_by = 'CREATED';
    }
    if (!in_array($sort_dir, $sort_dir_array)) {
        $sort_dir = 'DESC';
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (($uid = session::get_value('UID')) === false) {
        return false;
    }
    $sql = "SELECT SQL_CALC_FOUND_ROWS ADMIN_LOG.ID, ADMIN_LOG.UID, ADMIN_LOG.ACTION, ";
    $sql .= "ADMIN_LOG.ENTRY, UNIX_TIMESTAMP(MAX(ADMIN_LOG.CREATED)) AS CREATED, ";
    $sql .= "{$group_by_array[$group_by]} AS GROUP_BY, COUNT(*) AS COUNT, ";
    $sql .= "USER.LOGON, USER.NICKNAME, USER_PEER.PEER_NICKNAME ";
    $sql .= "FROM `{$table_prefix}ADMIN_LOG` ADMIN_LOG ";
    $sql .= "LEFT JOIN USER USER ON (USER.UID = ADMIN_LOG.UID) ";
    $sql .= "LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER ";
    $sql .= "ON (USER_PEER.PEER_UID = ADMIN_LOG.UID AND USER_PEER.UID = '{$uid}') ";
    $sql .= "GROUP BY GROUP_BY, ADMIN_LOG.UID, ADMIN_LOG.ACTION, ADMIN_LOG.ENTRY ";
    $sql .= "ORDER BY {$sort_by} {$sort_dir} ";
    $sql .= "LIMIT {$offset}, 10";
    if (!($result = $db->query($sql))) {
        return false;
    }
    $sql = "SELECT FOUND_ROWS() AS ROW_COUNT";
    if (!($result_count = $db->query($sql))) {
        return false;
    }
    list($admin_log_count) = $result_count->fetch_row();
    if ($result->num_rows == 0 && $admin_log_count > 0 && $page > 1) {
        return admin_get_log_entries($page - 1, $sort_by, $sort_dir);
    }
    while ($admin_log_data = $result->fetch_assoc()) {
        if (isset($admin_log_data['LOGON']) && isset($admin_log_data['PEER_NICKNAME'])) {
            if (!is_null($admin_log_data['PEER_NICKNAME']) && strlen($admin_log_data['PEER_NICKNAME']) > 0) {
                $admin_log_data['NICKNAME'] = $admin_log_data['PEER_NICKNAME'];
            }
        }
        if (!isset($admin_log_data['LOGON'])) {
            $admin_log_data['LOGON'] = gettext("Unknown user");
        }
        if (!isset($admin_log_data['NICKNAME'])) {
            $admin_log_data['NICKNAME'] = "";
        }
        $admin_log_data['ENTRY'] = unserialize(base64_decode($admin_log_data['ENTRY']));
        $admin_log_array[] = $admin_log_data;
    }
    return array('admin_log_count' => $admin_log_count, 'admin_log_array' => $admin_log_array);
}