10.0) {
die ('Load too high...please try again later.');
}
//ob_start("ob_gzhandler");
ob_start();
/*
if (!preg_match('/^130\.22(5|6)/', $_SERVER['REMOTE_ADDR'])) {
die('Being worked on...');
}
//*/
?>
Logs
Logs are currently locked to anyone below administrator status.";
} else if ($pass == 0 && $logblock == 2) {
echo "Logs are currently locked to anyone below moderators status.";
} else if ($pass == 0) {
echo "Logs are currently blocked for anyone not logged into the chat.";
} else {
if (empty($_REQUEST['a']) && empty($_REQUEST['qid'])) {
$rez = count_mysql_query(
"SELECT
DATE_FORMAT(stamp,'%x') as dyear,
DATE_FORMAT(stamp,'%v') as dweek,
count(*) as cnt
FROM uo_chat_biglog
WHERE chat_id={$GLOBALS['biglog']['chat_id']}
GROUP BY DATE_FORMAT(stamp,'%x%v')
", $handler);
if (mysql_num_rows($rez)) {
$output .= "
Browse:";
$output .= "
- Last 24 hours";
$output .= "
- Last 72 hours";
$output .= "
- Last week";
$output .= "
- Last fortnight";
$output .= "
- Last month";
$output .= "
- Last season";
$output .= "
- Last year";
$output .= "
- Last aeon";
$output .= "
Or browse individual weeks. Format is: Year/Week: Lines";
while($row = mysql_fetch_assoc($rez)) {
$output .= "
\n";
}
$output .= "
";
} else {
$output .= "Logs are empty...";
}
mysql_free_result($rez);
} else {
$output .= "Return to overview...
\n";
// Initialization
$count = "SELECT count(*) as cnt FROM uo_chat_biglog WHERE chat_id={$GLOBALS['biglog']['chat_id']} ";
$fetch =
"SELECT message_id,
uncompress(message) as message,
DATE_FORMAT(stamp, '%y%m%d %H:%i') as shortstamp,
DATE_FORMAT(DATE_SUB(stamp, INTERVAL 15 MINUTE), '%Y%m%d%H%i%s') as contextstamp
FROM uo_chat_biglog
WHERE chat_id={$GLOBALS['biglog']['chat_id']} ";
$cond = "";
$pages = "";
// Input sanitation
$_REQUEST['year'] = abs(intval($_REQUEST['year']));
$_REQUEST['week'] = abs(intval($_REQUEST['week']));
$_REQUEST['limit'] = abs(intval($_REQUEST['limit']));
$_REQUEST['offset'] = abs(intval($_REQUEST['offset']));
$_REQUEST['from'] = preg_replace('/[^0-9]+/', '', $_REQUEST['from']);
if (!empty($_REQUEST['keywords'])) {
if (!is_array($_REQUEST['keywords'])) {
if (strpos($_REQUEST['keywords'], ' ') === false) {
$_REQUEST['keywords'] = array($_REQUEST['keywords']);
} else {
$_REQUEST['keywords'] = preg_replace("@[ \t\r\n]+@s", ' ', $_REQUEST['keywords']);
$_REQUEST['keywords'] = explode(' ', $_REQUEST['keywords']);
}
}
$keyw = array();
foreach($_REQUEST['keywords'] as $val) {
$val = strtolower(trim($val));
if (!empty($val)) {
$keyw[] = $val;
}
}
unset($_REQUEST['keywords']);
$keyw = array_unique($keyw);
sort($keyw);
$_REQUEST['keywords'] = $keyw;
} else {
unset($_REQUEST['keywords']);
}
$entry = 0;
if ($_REQUEST['entry'] == 'last') {
$entry = 1;
} else if ($_REQUEST['entry'] == 'first') {
$entry = 2;
}
unset($_REQUEST['entry']);
// Input fixup
if (empty($_REQUEST['limit']))
$_REQUEST['limit'] = 500;
else if ($_REQUEST['limit'] > 20000)
$_REQUEST['limit'] = 20000;
// Input caching
$limit = $_REQUEST['limit'];
$offset = $_REQUEST['offset'];
if (empty($_REQUEST['qid'])) {
unset($_REQUEST['a']);
unset($_REQUEST['qid']);
unset($_REQUEST['limit']);
unset($_REQUEST['offset']);
ksort($_REQUEST);
$qid = md5(serialize($_REQUEST));
MMC_Set($qid, $_REQUEST);
$_REQUEST['qid'] = $qid;
} else if (strlen($_REQUEST['qid']) == 32 && preg_match('/^[a-f0-9]{32}$/', $_REQUEST['qid'])) {
$qid = $_REQUEST['qid'];
$get = MMC_Get($_REQUEST['qid']);
echo "";
if (is_array($get))
$_REQUEST = $get;
$_REQUEST['qid'] = $qid;
} else {
die("Invalid QID: {$_REQUEST['qid']}\n");
}
$_REQUEST['limit'] = $limit;
$_REQUEST['offset'] = $offset;
// Query building
if (!empty($_REQUEST['year'])) {
$cond .= " AND DATE_FORMAT(stamp,'%x')={$_REQUEST['year']}";
}
if (!empty($_REQUEST['week'])) {
$cond .= " AND DATE_FORMAT(stamp,'%v')={$_REQUEST['week']}";
}
if (!empty($_REQUEST['from'])) {
$cond .= " AND stamp>='{$_REQUEST['from']}'";
}
if (!empty($_REQUEST['keywords']) && is_array($_REQUEST['keywords'])) {
foreach($_REQUEST['keywords'] as $val) {
if ($val[0] == '!') {
$val = substr($val, 1);
$cond .= " AND uncompress(message) NOT LIKE CONVERT( _utf8 '%".mysql_escape_string($val)."%' USING latin1 )";
} else {
$cond .= " AND uncompress(message) LIKE CONVERT( _utf8 '%".mysql_escape_string($val)."%' USING latin1 )";
}
}
}
// Fetch number of rows for pagination
$rez = count_mysql_query($count.$cond, $handler);
$numrows = mysql_fetch_assoc($rez);
$numrows = intval($numrows['cnt']);
mysql_free_result($rez);
$cond .= " ORDER BY message_id ASC";
// Create the pagination, if applicable
if (!empty($_REQUEST['limit']) && $_REQUEST['limit'] < $numrows) {
if ($entry == 1) {
$_REQUEST['offset'] = max(0, ($numrows-$_REQUEST['limit']));
} else if ($entry == 2) {
$_REQUEST['offset'] = 0;
}
$numpages = ceil($numrows/$_REQUEST['limit']);
$curpage = floor($_REQUEST['offset']/$_REQUEST['limit'])+1;
$range = range(1, $numpages);
$offset = ($curpage-2)*$limit;
$pages .= "\n
Page: ";
$pages .= "<< previous, ";
foreach($range as $page) {
if ($page == $curpage) {
$pages .= $page.", ";
} else {
$offset = ($page-1)*$limit;
$pages .= "".$page.", ";
}
}
$offset = ($curpage)*$limit;
$pages .= "next >>";
$pages .= "
\n";
$cond .= " LIMIT {$_REQUEST['offset']},{$_REQUEST['limit']}";
}
$rez = count_mysql_query($fetch.$cond, $handler);
if (mysql_num_rows($rez)) {
$output .= "{$numrows} lines found
\n";
if (!empty($_REQUEST['keywords']) && is_array($_REQUEST['keywords'])) {
$output .= "You can click the line's timestamp to get 15 minutes context of it.
";
}
$output .= $pages;
while($row = mysql_fetch_assoc($rez)) {
$output .= "\n";
}
$output .= $pages;
} else {
$output .= "No rows matching that query...";
}
mysql_free_result($rez);
}
}
?>
Keywords are inclusive, so the more keywords you put in, the less lines you'll find.
You can specifically ask for a keyword to not exist by prefixing it with !.
For example, searching for "mouse !cheese milk" would find lines that contain both mouse and milk but not cheese.
=$output;?>