mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
2 files changed
+145
-13
No files matched your search
+68
-11
@@ -44,11 +44,38 @@ if (authentication_has_role('global-admin')) {
|
||||
$fDomain = '';
|
||||
$error = 0;
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||
if ((is_array($list_domains) and sizeof($list_domains) > 0) and !authentication_has_role('global-admin')) {
|
||||
$fDomain = $list_domains[0];
|
||||
if (isset($_GET['page']) && $_GET['fDomain']){
|
||||
$fDomain_aux = escape_string($_GET['fDomain']);
|
||||
$flag_fDomain = 0;
|
||||
if ((is_array($list_domains) and sizeof($list_domains) > 0)) {
|
||||
foreach ($list_domains as $domain){
|
||||
if ($domain == $fDomain_aux){
|
||||
$fDomain=$domain;
|
||||
$flag_fDomain=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($flag_fDomain == 0 ){
|
||||
die('Unknown domain');
|
||||
}
|
||||
|
||||
$page_number = (int) ($_GET['page'] ?? 0);
|
||||
if ($page_number == 0){
|
||||
die('Unknown page number');
|
||||
}
|
||||
|
||||
}else{
|
||||
$page_number=1;
|
||||
if ((is_array($list_domains) and sizeof($list_domains) > 0)) {
|
||||
$fDomain = $list_domains[0];
|
||||
}
|
||||
}
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$page_number=1;
|
||||
if (isset($_POST['fDomain'])) {
|
||||
$fDomain = escape_string($_POST['fDomain']);
|
||||
}
|
||||
@@ -67,6 +94,7 @@ if ($error != 1) {
|
||||
$table_log = table_by_key('log');
|
||||
$page_size = isset($CONF['page_size']) ? intval($CONF['page_size']) : 35;
|
||||
|
||||
|
||||
$where = [];
|
||||
$params = [];
|
||||
if ($fDomain) {
|
||||
@@ -77,13 +105,39 @@ if ($error != 1) {
|
||||
$where_sql = '';
|
||||
if (!empty($where)) {
|
||||
$where_sql = 'WHERE ' . implode(' AND ', $where);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$number_of_logs=0;
|
||||
$number_of_pages=0;
|
||||
//get number of total logs
|
||||
$query = "SELECT count(*) as number_of_logs FROM $table_log $where_sql";
|
||||
|
||||
|
||||
$result = db_query_all($query, $params);
|
||||
foreach ($result as $r ){
|
||||
$number_of_logs=$r['number_of_logs'];
|
||||
}
|
||||
$number_of_pages = ceil($number_of_logs/$page_size);
|
||||
|
||||
if ($page_number > $number_of_pages){
|
||||
die('Unknown page number');
|
||||
}
|
||||
|
||||
if($page_number == 1 ){
|
||||
$offset=0;
|
||||
}else{
|
||||
$offset=($page_number-1)*$page_size;
|
||||
}
|
||||
|
||||
$query = "SELECT timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size";
|
||||
$query = "SELECT timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size OFFSET $offset";
|
||||
|
||||
if (db_pgsql()) {
|
||||
$query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size";
|
||||
$query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,data FROM $table_log $where_sql ORDER BY timestamp DESC LIMIT $page_size OFFSET $offset";
|
||||
}
|
||||
|
||||
|
||||
$result = db_query_all($query, $params);
|
||||
foreach ($result as $row) {
|
||||
if (is_array($row) && db_pgsql()) {
|
||||
@@ -99,18 +153,21 @@ foreach ($tLog as $k => $v) {
|
||||
$tLog[$k] = $v;
|
||||
}
|
||||
}
|
||||
//get url
|
||||
$url=explode("?",(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")[0];
|
||||
|
||||
$domain_options = array();
|
||||
if (authentication_has_role('global-admin')) {
|
||||
$domain_options = array('' => '');
|
||||
}
|
||||
$domain_options = array_merge($domain_options, array_combine($list_domains, $list_domains));
|
||||
|
||||
$smarty->assign('domain_options', $domain_options);
|
||||
$smarty->assign('domain_list', $list_domains);
|
||||
$smarty->assign('domain_selected', $fDomain);
|
||||
$smarty->assign('tLog', $tLog, false);
|
||||
$smarty->assign('fDomain', $fDomain);
|
||||
|
||||
$smarty->assign('number_of_pages', $number_of_pages);
|
||||
$smarty->assign('page_number', $page_number);
|
||||
$smarty->assign('url',$url);
|
||||
|
||||
$smarty->assign('smarty_template', 'viewlog');
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
|
||||
|
||||
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
|
||||
+77
-2
@@ -1,13 +1,13 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<form name="frmOverview" method="post" action="">
|
||||
{html_options name='fDomain' options=$domain_options selected=$domain_selected onchange="this.form.submit();"}
|
||||
{html_options name='fDomain' output=$domain_list values=$domain_list selected=$domain_selected onchange="this.form.submit();"}
|
||||
<noscript><input class="button" type="submit" name="go" value="{$PALANG.go}"/></noscript>
|
||||
</form>
|
||||
</div>
|
||||
{if $tLog}
|
||||
<div class="panel-body">
|
||||
{if $domain_selected}
|
||||
{if $domain_selected}
|
||||
<h4>{$PALANG.pViewlog_welcome|replace:"%s":$CONF.page_size} {$fDomain} </h4>
|
||||
{else}
|
||||
<h4>{$PALANG.pViewlog_welcome_all|replace:"%s":$CONF.page_size}</h4>
|
||||
@@ -35,5 +35,80 @@
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="container">
|
||||
|
||||
<div class="col-md-4">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
<div class="pull-right" style="margin: 10px;">
|
||||
|
||||
{if $number_of_pages < 6}
|
||||
<div class="btn-group mr-2" role="group">
|
||||
{for $i=1 to $number_of_pages}
|
||||
<button type="button" onclick=go2page({$i}) class="btn btn-secondary">{$i}</button>
|
||||
{/for}
|
||||
</div>
|
||||
{elseif $page_number > 3 && $page_number < ($number_of_pages -2 )}
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page(1) class="btn btn-secondary">1</button>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page({$page_number-1}) class="btn btn-secondary">{$page_number-1}</button>
|
||||
<button type="button" onclick=go2page({$page_number}) class="btn btn-secondary">{$page_number}</button>
|
||||
<button type="button" onclick=go2page({$page_number+1}) class="btn btn-secondary">{$page_number+1}</button>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page({$number_of_pages}) class="btn btn-secondary">{$number_of_pages}</button>
|
||||
</div>
|
||||
|
||||
|
||||
{else}
|
||||
{if $page_number < 4}
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page(1) class="btn btn-secondary">1</button>
|
||||
<button type="button" onclick=go2page(2) class="btn btn-secondary">2</button>
|
||||
<button type="button" onclick=go2page(3) class="btn btn-secondary">3</button>
|
||||
<button type="button" onclick=go2page(4) class="btn btn-secondary">4</button>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page({$number_of_pages}) class="btn btn-secondary">{$number_of_pages}</button>
|
||||
</div>
|
||||
|
||||
{else}
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page(1) class="btn btn-secondary">1</button>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group">
|
||||
<button type="button" onclick=go2page({$number_of_pages-3}) class="btn btn-secondary">{$number_of_pages-3}</button>
|
||||
<button type="button" onclick=go2page({$number_of_pages-2}) class="btn btn-secondary">{$number_of_pages-2}</button>
|
||||
<button type="button" onclick=go2page({$number_of_pages-1}) class="btn btn-secondary">{$number_of_pages-1}</button>
|
||||
<button type="button" onclick=go2page({$number_of_pages}) class="btn btn-secondary">{$number_of_pages}</button>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<div class="btn-group" role="group"><div class="dropdown">
|
||||
<button class="btn dropdown-toggle" type="button" data-toggle="dropdown">Page <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu" style="max-height: 200px; overflow: auto">
|
||||
{for $i=1 to $number_of_pages}
|
||||
<li><a onclick=go2page({$i}) href="#">{$i}</a></li>
|
||||
{/for}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function go2page(page){
|
||||
window.location.href = '{$url}?page='+page+'&fDomain={$fDomain}';
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user