diff --git a/public_html/deployment/classes/actionlog.class.php b/public_html/deployment/classes/actionlog.class.php index b970b2495dd89702dd79a987463be1434b0a988f..f25221d6f332a8fd50f5af1ec4dde6f3d6832d7e 100644 --- a/public_html/deployment/classes/actionlog.class.php +++ b/public_html/deployment/classes/actionlog.class.php @@ -6,7 +6,8 @@ require_once 'user.class.php'; * * @author hahn */ -class Actionlog { +class Actionlog +{ private $_dbfile = ''; private $_aLoglevels = array("info", "warning", "error", "success"); // array of valid loglevels @@ -44,10 +45,11 @@ class Actionlog { * @global array $aConfig settings * @param string $sProject project ID */ - public function __construct($sProject = false) { + public function __construct($sProject = false) + { global $aConfig; if (!isset($aConfig["appRootDir"])) { - die(__CLASS__ . "::".__FUNCTION__." ERROR: configuration with \$aConfig was not loaded."); + die(__CLASS__ . "::" . __FUNCTION__ . " ERROR: configuration with \$aConfig was not loaded."); } $this->_dbfile = $aConfig['dataDir'] . '/database/logs.db'; if (!file_exists($this->_dbfile)) { @@ -57,13 +59,13 @@ class Actionlog { } } $this->_sProject = $sProject; - $oUser=new user(); + $oUser = new user(); if ($oUser->getUsername()) { $this->_sIP = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : 'local'; $this->_sUser = $oUser->getUsername() . " (web)"; } else { $this->_sIP = 'local'; - $aUser=posix_getpwuid(posix_geteuid()); + $aUser = posix_getpwuid(posix_geteuid()); $this->_sUser = $aUser['name'] . " (system)"; } } @@ -71,7 +73,8 @@ class Actionlog { /** * create sqlite database - called in constructor if the file does not exist */ - private function _createDb() { + private function _createDb() + { echo "try to create file $this->_dbfile ...<br>\n"; return $this->_makeQuery($this->_sCreate); } @@ -81,7 +84,8 @@ class Actionlog { * @param string $sSql sql statement * @return database object */ - private function _makeQuery($sSql) { + private function _makeQuery($sSql) + { // $this->_log(__FUNCTION__."($sSql)"); // echo "<pre>".htmlentities($sSql)."</pre>"; $db = new PDO("sqlite:" . $this->_dbfile); @@ -102,7 +106,8 @@ class Actionlog { * @param string $sLoglevel loglevel * @return type */ - public function add($sMessage, $sAction = "", $sLoglevel = "info", $sTimeStart = false) { + public function add($sMessage, $sAction = "", $sLoglevel = "info", $sTimeStart = false) + { if (array_search($sLoglevel, $this->_aLoglevels) === false) { die(__class__ . ": loglevel $sLoglevel is invalid"); } @@ -133,7 +138,7 @@ class Actionlog { * */ // echo $sql . "<br>"; - $oResult=$this->_makeQuery($sql); + $oResult = $this->_makeQuery($sql); return $oResult; } @@ -143,10 +148,11 @@ class Actionlog { * @param string $sOKChars good chars to keep * @return string */ - private function _filterAllowedChars($sVal, $sOKChars){ - return preg_replace('/[^'.$sOKChars. ']/i', '',$sVal); + private function _filterAllowedChars($sVal, $sOKChars) + { + return preg_replace('/[^' . $sOKChars . ']/i', '', $sVal); } - + /** * get log data * @param array $aFilter with the following keys: @@ -157,35 +163,36 @@ class Actionlog { * 'limit' - limit clausel - part behind "LIMIT " * @return array */ - public function getLogs($aFilter = array()) { + public function getLogs($aFilter = array()) + { // var_dump(R::findAll( 'log' )); $aReturn = array(); $sSql = 'SELECT `id`,`time`,`loglevel`,`ip`,`user`,`project`,`action`,`message` from logs '; $sWhere = false; - - $aWhere=array(); + + $aWhere = array(); if (isset($aFilter["project"]) && $aFilter["project"]) { - $aWhere[]='`project`="' . $this->_filterAllowedChars($aFilter["project"], '[a-z0-9\-\_]') . '"'; + $aWhere[] = '`project`="' . $this->_filterAllowedChars($aFilter["project"], '[a-z0-9\-\_]') . '"'; } if (isset($aFilter["from"]) && $aFilter["from"]) { - $aWhere[]='`time`>="' . $this->_filterAllowedChars($aFilter["from"], '[0-9\-\ \:]') . '"'; + $aWhere[] = '`time`>="' . $this->_filterAllowedChars($aFilter["from"], '[0-9\-\ \:]') . '"'; } if (isset($aFilter["to"]) && $aFilter["to"]) { - $aWhere[]='`time`<="' . $this->_filterAllowedChars($aFilter["to"], '[0-9\-\ \:]') . '"'; + $aWhere[] = '`time`<="' . $this->_filterAllowedChars($aFilter["to"], '[0-9\-\ \:]') . '"'; } - $sSql.=(count($aWhere) ? 'WHERE '. implode(' AND ', $aWhere) : ''); - + $sSql .= (count($aWhere) ? 'WHERE ' . implode(' AND ', $aWhere) : ''); + if (isset($aFilter["order"]) && $aFilter["order"]) { - $sSql.=' ORDER BY ' . $this->_filterAllowedChars($aFilter["order"], '[a-z\`0-9\,\ ]'); + $sSql .= ' ORDER BY ' . $this->_filterAllowedChars($aFilter["order"], '[a-z\`0-9\,\ ]'); } else { - $sSql.=' ORDER BY id DESC '; + $sSql .= ' ORDER BY id DESC '; } if (isset($aFilter["limit"]) && $aFilter["limit"]) { - $sSql.=' LIMIT ' . $this->_filterAllowedChars($aFilter["limit"], '[0-9\,\ ]'); + $sSql .= ' LIMIT ' . $this->_filterAllowedChars($aFilter["limit"], '[0-9\,\ ]'); } - + foreach ($this->_makeQuery($sSql) as $row) { for ($i = 0; $i <= 7; $i++) { unset($row[$i]); @@ -203,7 +210,8 @@ class Actionlog { * 'limit' - limit clausel - part behind "LIMIT " * @return string */ - public function renderLogs($aFilter = array(), $bIsFullsearch=false) { + public function renderLogs($aFilter = array(), $bIsFullsearch = false) + { $sReturn = ''; static $bWasShown; @@ -214,22 +222,22 @@ class Actionlog { require_once 'formgen.class.php'; // values for dropdowns - limit of lines; time - - $aLimits=array( - '20'=>array('label'=>20), - '50'=>array('label'=>50), - '100'=>array('label'=>100), - ''=>array('label'=>t("all")), + + $aLimits = array( + '20' => array('label' => 20), + '50' => array('label' => 50), + '100' => array('label' => 100), + '' => array('label' => t("all")), ); - $aTimes=array( - date("Y-m-d", date("U")) =>array('label'=>t("class-actionlog-time-today")), - date("Y-m-d", date("U") - 60*60*24*1) =>array('label'=>t("class-actionlog-time-since-yesterday")), - date("Y-m-d", date("U") - 60*60*24*7) =>array('label'=>t("class-actionlog-time-for-1-week")), - date("Y-m-d", date("U") - 60*60*24*7*2) =>array('label'=>sprintf(t("class-actionlog-time-for-n-weeks"), "2")), - date("Y-m-d", date("U") - 60*60*24*7*4) =>array('label'=>sprintf(t("class-actionlog-time-for-n-weeks"), "4")), - ''=>array('label'=>t("all")), + $aTimes = array( + date("Y-m-d", date("U")) => array('label' => t("class-actionlog-time-today")), + date("Y-m-d", date("U") - 60 * 60 * 24 * 1) => array('label' => t("class-actionlog-time-since-yesterday")), + date("Y-m-d", date("U") - 60 * 60 * 24 * 7) => array('label' => t("class-actionlog-time-for-1-week")), + date("Y-m-d", date("U") - 60 * 60 * 24 * 7 * 2) => array('label' => sprintf(t("class-actionlog-time-for-n-weeks"), "2")), + date("Y-m-d", date("U") - 60 * 60 * 24 * 7 * 4) => array('label' => sprintf(t("class-actionlog-time-for-n-weeks"), "4")), + '' => array('label' => t("all")), ); - + $aForms = array( 'filter' => array( 'meta' => array( @@ -239,86 +247,87 @@ class Actionlog { ), 'validate' => array(), 'form' => array(), - )); + ) + ); // generate filter for log table // $bIsFullsearch: true = show all inputs; false: no interactive search - - if ($bIsFullsearch){ - + + if ($bIsFullsearch) { + // --- list of all projects in log - $sSql='SELECT DISTINCT(project) from `logs` order by project asc'; + $sSql = 'SELECT DISTINCT(project) from `logs` order by project asc'; $aForms["filter"]["form"]['selectproject'] = array( - 'type' => 'select', - 'name' => 'selectproject', - 'label' => '<i class="glyphicon glyphicon-tag"></i> ' . t('project'), - 'class' => 'span2', - 'onchange'=>'updateActionlog();', - 'inline' => true, + 'type' => 'select', + 'name' => 'selectproject', + 'label' => '<i class="glyphicon glyphicon-tag"></i> ' . t('project'), + 'class' => 'span2', + 'onchange' => 'updateActionlog();', + 'inline' => true, ); - $aForms["filter"]["form"]['selectproject']['options']['']=array('label'=>t("all")); + $aForms["filter"]["form"]['selectproject']['options'][''] = array('label' => t("all")); foreach ($this->_makeQuery($sSql) as $row) { - if ($row[0]){ - $aForms["filter"]["form"]['selectproject']['options'][$row[0]]=array('label'=>$row[0]); + if ($row[0]) { + $aForms["filter"]["form"]['selectproject']['options'][$row[0]] = array('label' => $row[0]); } } $aForms["filter"]["form"]['selectfrom'] = array( - 'type' => 'select', - 'name' => 'selectWheretime', - 'label' => '<i class="glyphicon glyphicon-calendar"></i> '.t("class-actionlog-time"), - 'class' => 'span2', - 'onchange'=>'updateActionlog();', - 'options' => $aTimes, - 'inline' => true, + 'type' => 'select', + 'name' => 'selectWheretime', + 'label' => '<i class="glyphicon glyphicon-calendar"></i> ' . t("class-actionlog-time"), + 'class' => 'span2', + 'onchange' => 'updateActionlog();', + 'options' => $aTimes, + 'inline' => true, ); $aForms["filter"]["form"]['selectlimit'] = array( - 'type' => 'select', - 'name' => 'selectlimit', - 'label' => '<i class="glyphicon glyphicon-list"></i> '.t("class-actionlog-count"), - 'class' => 'span1', - 'onchange'=>'updateActionlog();', - 'options' => $aLimits, - 'inline' => true, + 'type' => 'select', + 'name' => 'selectlimit', + 'label' => '<i class="glyphicon glyphicon-list"></i> ' . t("class-actionlog-count"), + 'class' => 'span1', + 'onchange' => 'updateActionlog();', + 'options' => $aLimits, + 'inline' => true, ); + + // force a line break $aForms["filter"]["form"]['line'] = array( - 'type' => 'markup', - 'value' => '', + 'type' => 'markup', + 'value' => '<div class="col-sm-12"></div>', ); - - } else { - + // write filters as hidden fields - if (isset($aFilter["project"])){ + if (isset($aFilter["project"])) { $aForms["filter"]["form"]['selectproject'] = array( - 'type' => 'hidden', - 'value' => $aFilter["project"] + 'type' => 'hidden', + 'value' => $aFilter["project"] ); } - if (isset($aFilter["limit"])){ + if (isset($aFilter["limit"])) { $aForms["filter"]["form"]['selectlimit'] = array( - 'type' => 'hidden', - 'value' => $aFilter["limit"] + 'type' => 'hidden', + 'value' => $aFilter["limit"] ); } } $aForms["filter"]["form"]['efilterlogs'] = array( - 'type' => 'text', - 'name' => 'efilterlogs', - 'label' => '<i class="glyphicon glyphicon-filter"></i>' . t("overview-textsearch"), - 'inline'=> true, - 'onkeyup' => 'filterLogTable();', - 'onkeypress' => 'filterLogTable();', - 'onchange' => 'filterLogTable();', - 'size' => 20, - ); - if (!$bIsFullsearch){ + 'type' => 'text', + 'name' => 'efilterlogs', + 'label' => '<i class="glyphicon glyphicon-filter"></i>' . t("overview-textsearch"), + 'inline' => true, + 'onkeyup' => 'filterLogTable();', + 'onkeypress' => 'filterLogTable();', + 'onchange' => 'filterLogTable();', + //'size' => 20, + ); + if (!$bIsFullsearch) { $aForms["filter"]["form"]['btnalllogs'] = array( - 'type' => 'button', - 'value' => t('show all'), - 'class' => 'btn btn-secondary btnlogs', - 'href'=>'/deployment/all/setup/actionlog/', - 'onclick'=>'location.href=\'/deployment/all/setup/actionlog/\'; return false;', + 'type' => 'button', + 'value' => t('show all'), + 'class' => 'btn btn-secondary btnlogs', + 'href' => '/deployment/all/setup/actionlog/', + 'onclick' => 'location.href=\'/deployment/all/setup/actionlog/\'; return false;', ); } else { // $aForms["filter"]["form"]['closediv'] = array( @@ -327,14 +336,14 @@ class Actionlog { // ); } - + // generate html output - + $oForm = new formgen($aForms); - + $sReturn = '' - . ($bIsFullsearch ? t("class-actionlog-title") . ' :: '.t("class-actionlog-filter") : '') - .'<div id="divActionlogs">'.$oForm->renderHtml("filter").' + . ($bIsFullsearch ? t("class-actionlog-title") . ' :: ' . t("class-actionlog-filter") : '') + . '<div id="divActionlogs">' . $oForm->renderHtml("filter") . ' <div style="clear: both; margin-bottom: 1em;"></div> <div id="tableLogactions"></div> <!-- @@ -344,23 +353,23 @@ class Actionlog { --> </div> <script> - var sMsgNolog="'.t("class-actionlog-nolog").'"; + var sMsgNolog="' . t("class-actionlog-nolog") . '"; </script>'; - if ($bIsFullsearch){ - $sReturn.='<script> + if ($bIsFullsearch) { + $sReturn .= '<script> $(document).ready(function() { updateActionlog(); });</script>'; } else { - $sReturn= '<strong>' + $sReturn = '<strong>' . '<button onclick="setLogVisibility(\'block\');" id="btnShowLogs" class="btn btn-default btnLogs"><i class="fa-solid fa-chevron-right"></i> </button>' . '<button onclick="setLogVisibility(\'none\');" id="btnHideLogs" class="btn btn-default btnLogs"><i class="fa-solid fa-chevron-down"></i> </button>' - . ' ' . t("class-actionlog-title") .(isset($aFilter["project"]) ? ' ['.$aFilter["project"].'] ' : '') + . ' ' . t("class-actionlog-title") . (isset($aFilter["project"]) ? ' [' . $aFilter["project"] . '] ' : '') . '</strong>' - - . $sReturn.' + + . $sReturn . ' <script> function getLogVisibility(){ var sReturn=localStorage.getItem("bActionlogsVisible"); @@ -386,5 +395,4 @@ class Actionlog { } return $sReturn; } - }