- {if $domain_selected}
+ {if $domain_selected}
{$PALANG.pViewlog_welcome|replace:"%s":$CONF.page_size} {$fDomain}
{else}
{$PALANG.pViewlog_welcome_all|replace:"%s":$CONF.page_size}
@@ -35,5 +35,80 @@
{/foreach}
+
+
+
+
+
+
+
+
+
+
+ {if $number_of_pages < 6}
+
+ {for $i=1 to $number_of_pages}
+
+ {/for}
+
+ {elseif $page_number > 3 && $page_number < ($number_of_pages -2 )}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {else}
+ {if $page_number < 4}
+
+
+
+
+
+
+
+
+
+
+ {else}
+
+
+
+
+
+
+
+
+
+ {/if}
+ {/if}
+
+
+
+
+
+
{/if}
+
+
From 8690f1c2b66ef7d84a5deb486745d4a50f843bcd Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 10:37:29 +0200
Subject: [PATCH 2/7] Update viewlog.php
---
public/viewlog.php | 81 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 68 insertions(+), 13 deletions(-)
diff --git a/public/viewlog.php b/public/viewlog.php
index 6b05a09e..a1048424 100644
--- a/public/viewlog.php
+++ b/public/viewlog.php
@@ -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: */
From d80041bf4e19b96b406f79f663cecf95724ac374 Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 10:39:16 +0200
Subject: [PATCH 3/7] Update viewlog.php
---
public/viewlog.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/public/viewlog.php b/public/viewlog.php
index a1048424..04214c6d 100644
--- a/public/viewlog.php
+++ b/public/viewlog.php
@@ -99,13 +99,13 @@ if ($error != 1) {
$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);
}
From d583cb396b90cea2a7146ba0443120ef2edd5745 Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 10:40:52 +0200
Subject: [PATCH 4/7] Update viewlog.tpl
---
templates/viewlog.tpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/viewlog.tpl b/templates/viewlog.tpl
index 5c2f480a..0514a842 100644
--- a/templates/viewlog.tpl
+++ b/templates/viewlog.tpl
@@ -1,7 +1,7 @@
From 951b202ff1a3e78d29d7c004e0e0fc5085bea847 Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 10:44:54 +0200
Subject: [PATCH 5/7] Update viewlog.tpl
---
templates/viewlog.tpl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/viewlog.tpl b/templates/viewlog.tpl
index 0514a842..ae809af7 100644
--- a/templates/viewlog.tpl
+++ b/templates/viewlog.tpl
@@ -1,7 +1,7 @@
From 985273d07aa8ebf83e1d2f7418ab935d94729638 Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 11:44:55 +0200
Subject: [PATCH 6/7] Update viewlog.php
---
public/viewlog.php | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/public/viewlog.php b/public/viewlog.php
index 04214c6d..ad98b01d 100644
--- a/public/viewlog.php
+++ b/public/viewlog.php
@@ -63,12 +63,10 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
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');
- }
+ $page_number = (int) ($_GET['page'] ?? 0);
+ if ($page_number == 0){
+ die('Unknown page number');
+ }
}else{
$page_number=1;
From ec6e974f10c115cdd0a65c4857c3c855b165ca1e Mon Sep 17 00:00:00 2001
From: benchea dan <30780133+bnchdan@users.noreply.github.com>
Date: Wed, 12 Jan 2022 11:54:18 +0200
Subject: [PATCH 7/7] Update viewlog.php
---
public/viewlog.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/public/viewlog.php b/public/viewlog.php
index ad98b01d..51282393 100644
--- a/public/viewlog.php
+++ b/public/viewlog.php
@@ -120,7 +120,11 @@ if ($error != 1) {
$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{