Files
newznab-tmux/public/admin/view-logs.php
T

87 lines
1.8 KiB
PHP

<?php
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'smarty.php';
use nntmux\Logger;
$page = new AdminPage();
$page->title = 'View Logs';
$type = isset($_GET['t']) ? $_GET['t'] : 'all';
$page->smarty->assign('type', $type);
$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
$logPath = Logger::getDefaultLogPaths();
$logPath = $logPath['LogPath'];
$regex = false;
switch($type) {
case 'info':
$regex = '/\[INFO\]/';
break;
case 'notice':
$regex = '/\[NOTICE\]/';
break;
case 'warning':
$regex = '/\[WARN\]/';
break;
case 'error':
$regex = '/\[ERROR\]/';
break;
case 'fatal':
$regex = '/\[FATAL\]/';
break;
case 'sql':
$regex = '/\[SQL\]/';
break;
case 'all':
default:
break;
}
$data = $file = false;
if (is_file($logPath)) {
$file = file($logPath);
}
$total = 0;
if ($file !== false) {
rsort($file);
$data = [];
foreach ($file as $line) {
$line = str_replace(array('>', '<'), '', $line);
if ($regex !== false) {
if (preg_match($regex, $line)) {
$data[] = $line;
}
} else {
$data[] = $line;
}
}
if (count($data) === 0) {
$data = false;
} else {
$total = count($data);
$data = array_slice($data, $offset, ITEMS_PER_PAGE);
}
}
$page->smarty->assign(
array(
'data' => $data,
'types' => ['all', 'info', 'notice', 'warning', 'error', 'fatal', 'sql'],
'path' => NN_WWW . 'smarty.php'
)
);
$page->smarty->assign('pagertotalitems', $total);
$page->smarty->assign('pageroffset', $offset);
$page->smarty->assign('pageritemsperpage', ITEMS_PER_PAGE);
$page->smarty->assign('pagerquerybase', WWW_TOP . "/view-logs.php?t=" . $type . "&amp;offset=");
$pager = $page->smarty->fetch("pager.tpl");
$page->smarty->assign('pager', $pager);
$page->content = $page->smarty->fetch('view-logs.tpl');
$page->render();