mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Update viewlog.php
This commit is contained in:
1 parent
cc74eca44d
commit
8690f1c2b6
1 file changed
+68
-13
+68
-13
@@ -44,11 +44,40 @@ 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_aux=escape_string($_GET['page']);
|
||||
if ( is_numeric($page_number_aux)){
|
||||
$page_number=$page_number_aux;
|
||||
}else{
|
||||
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,23 +96,46 @@ if ($error != 1) {
|
||||
$table_log = table_by_key('log');
|
||||
$page_size = isset($CONF['page_size']) ? intval($CONF['page_size']) : 35;
|
||||
|
||||
|
||||
$where = [];
|
||||
$params = [];
|
||||
if ($fDomain) {
|
||||
if($fDomain) {
|
||||
$where[] = 'domain = :domain' ;
|
||||
$params['domain'] = $fDomain;
|
||||
}
|
||||
|
||||
$where_sql = '';
|
||||
if (!empty($where)) {
|
||||
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 == 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 +151,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: */
|
||||
Reference in new issue
Block a user