From 8356860945580d1f2d8434b2ae685d39aa93a554 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Wed, 17 Feb 2016 08:43:00 +0100 Subject: [PATCH] add syslog page for customer; pagination needs to be fixed Signed-off-by: Michael Kaufmann (d00p) --- customer_logger.php | 115 ++++++++++++++++++ lib/classes/logger/class.FileLogger.php | 27 +--- lib/navigation/00.froxlor.main.php | 17 ++- templates/Sparkle/customer/logger/logger.tpl | 48 ++++++++ .../Sparkle/customer/logger/logger_action.tpl | 3 + .../Sparkle/customer/logger/logger_log.tpl | 5 + 6 files changed, 183 insertions(+), 32 deletions(-) create mode 100644 customer_logger.php create mode 100644 templates/Sparkle/customer/logger/logger.tpl create mode 100644 templates/Sparkle/customer/logger/logger_action.tpl create mode 100644 templates/Sparkle/customer/logger/logger_log.tpl diff --git a/customer_logger.php b/customer_logger.php new file mode 100644 index 00000000..5d82e06c --- /dev/null +++ b/customer_logger.php @@ -0,0 +1,115 @@ + (2003-2009) + * @author Froxlor team (2010-) + * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt + * @package Panel + * + */ + +define('AREA', 'customer'); +require './lib/init.php'; + +if ($page == 'log' +) { + if ($action == '') { + $fields = array( + 'date' => $lng['logger']['date'], + 'type' => $lng['logger']['type'], + 'user' => $lng['logger']['user'], + 'text' => $lng['logger']['action'] + ); + $paging = new paging($userinfo, TABLE_PANEL_LOG, $fields, null, null, 0, 'desc'); + $result_stmt = Database::prepare(' + SELECT * FROM `' . TABLE_PANEL_LOG . '` WHERE `user` = :loginname ' . $paging->getSqlWhere(true) . ' ' . $paging->getSqlOrderBy() . ' ' . $paging->getSqlLimit() + ); + Database::pexecute($result_stmt, array("loginname" => $userinfo['loginname'])); + $paging->setEntries(Database::num_rows()); + $sortcode = $paging->getHtmlSortCode($lng); + $arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s); + $searchcode = $paging->getHtmlSearchCode($lng); + $pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s); + $clog = array(); + + while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { + + if (!isset($clog[$row['action']]) + || !is_array($clog[$row['action']]) + ) { + $clog[$row['action']] = array(); + } + $clog[$row['action']][$row['logid']] = $row; + } + + if ($paging->sortfield == 'date' + && $paging->sortorder == 'desc' + ) { + krsort($clog); + } else { + ksort($clog); + } + + $i = 0; + $count = 0; + $log_count = 0; + $log = ''; + foreach ($clog as $action => $logrows) { + $_action = 0; + foreach ($logrows as $row) { + if ($paging->checkDisplay($i)) { + $row = htmlentities_array($row); + $row['date'] = date("d.m.y H:i:s", $row['date']); + + if ($_action != $action) { + switch ($action) { + case USR_ACTION: + $_action = $lng['admin']['customer']; + break; + case RES_ACTION: + $_action = $lng['logger']['reseller']; + break; + case ADM_ACTION: + $_action = $lng['logger']['admin']; + break; + case CRON_ACTION: + $_action = $lng['logger']['cron']; + break; + case LOGIN_ACTION: + $_action = $lng['logger']['login']; + break; + case LOG_ERROR: + $_action = $lng['logger']['intern']; + break; + default: + $_action = $lng['logger']['unknown']; + break; + } + + $row['action'] = $_action; + eval("\$log.=\"" . getTemplate('logger/logger_action') . "\";"); + } + + $log_count++; + $row['type'] = getLogLevelDesc($row['type']); + eval("\$log.=\"" . getTemplate('logger/logger_log') . "\";"); + $count++; + $_action = $action; + } + } + $i++; + } + + eval("echo \"" . getTemplate('logger/logger') . "\";"); + + } +} diff --git a/lib/classes/logger/class.FileLogger.php b/lib/classes/logger/class.FileLogger.php index 5e7e881a..47a784c7 100644 --- a/lib/classes/logger/class.FileLogger.php +++ b/lib/classes/logger/class.FileLogger.php @@ -106,32 +106,7 @@ class FileLogger extends AbstractLogger { break; } - $_type = 'unknown'; - - switch($type) - { - case LOG_INFO: - $_type = 'information'; - break; - case LOG_NOTICE: - $_type = 'notice'; - break; - case LOG_WARNING: - $_type = 'warning'; - break; - case LOG_ERR: - $_type = 'error'; - break; - case LOG_CRIT: - $_type = 'critical'; - break; - case LOG_DEBUG: - $_type = 'debug'; - break; - default: - $_type = 'unknown'; - break; - } + $_type = getLogLevelDesc($type); if(!isset($this->userinfo['loginname']) || $this->userinfo['loginname'] == '') diff --git a/lib/navigation/00.froxlor.main.php b/lib/navigation/00.froxlor.main.php index b5e1845c..5e20f0e4 100644 --- a/lib/navigation/00.froxlor.main.php +++ b/lib/navigation/00.froxlor.main.php @@ -124,6 +124,11 @@ return array ( 'url' => 'customer_extras.php?page=htaccess', 'label' => $lng['menue']['extras']['pathoptions'], ), + array ( + 'url' => 'customer_logger.php?page=log', + 'label' => $lng['menue']['logger']['logger'], + 'show_element' => ( Settings::Get('logger.enabled') == true ) + ), ), ), 'traffic' => array ( @@ -220,6 +225,12 @@ return array ( 'label' => $lng['admin']['cron']['cronsettings'], 'required_resources' => 'change_serversettings', ), + array ( + 'url' => 'admin_logger.php?page=log', + 'label' => $lng['menue']['logger']['logger'], + 'required_resources' => 'change_serversettings', + 'show_element' => ( Settings::Get('logger.enabled') == true ), + ), array ( 'url' => 'admin_settings.php?page=rebuildconfigs', 'label' => $lng['admin']['rebuildconf'], @@ -284,12 +295,6 @@ return array ( 'url' => 'admin_templates.php?page=email', 'label' => $lng['admin']['templates']['email'], ), - array ( - 'url' => 'admin_logger.php?page=log', - 'label' => $lng['menue']['logger']['logger'], - 'required_resources' => 'change_serversettings', - 'show_element' => ( Settings::Get('logger.enabled') == true ), - ), array ( 'url' => 'admin_message.php?page=message', 'label' => $lng['admin']['message'], diff --git a/templates/Sparkle/customer/logger/logger.tpl b/templates/Sparkle/customer/logger/logger.tpl new file mode 100644 index 00000000..4e4cd2c1 --- /dev/null +++ b/templates/Sparkle/customer/logger/logger.tpl @@ -0,0 +1,48 @@ +$header +
+
+

+   + {$lng['menue']['logger']['logger']} +

+
+ +
+ +
+ + + + +
+ {$searchcode} +
+ +
+ {$pagingcode} +
+ + + + + + + + + + + $log + +
{$lng['logger']['date']} {$arrowcode['date']}{$lng['logger']['type']} {$arrowcode['type']}{$lng['logger']['action']}
+
+ + +
+ {$pagingcode} +
+
+ +
+ +
+$footer diff --git a/templates/Sparkle/customer/logger/logger_action.tpl b/templates/Sparkle/customer/logger/logger_action.tpl new file mode 100644 index 00000000..55f08a8f --- /dev/null +++ b/templates/Sparkle/customer/logger/logger_action.tpl @@ -0,0 +1,3 @@ + + {$row['action']} + diff --git a/templates/Sparkle/customer/logger/logger_log.tpl b/templates/Sparkle/customer/logger/logger_log.tpl new file mode 100644 index 00000000..f74b58b7 --- /dev/null +++ b/templates/Sparkle/customer/logger/logger_log.tpl @@ -0,0 +1,5 @@ + + {$row['date']} + {$row['type']} + {$row['text']} +