diff --git a/src/admin/charts.php b/src/admin/charts.php index e79defb..c1876b4 100644 --- a/src/admin/charts.php +++ b/src/admin/charts.php @@ -96,6 +96,7 @@ if ( isset($_GET['op']) ) $content['maxrecords'] = 5; $content['showpercent'] = 0; $content['CHECKED_ISSHOWPERCENT'] = ""; + $content['chart_defaultfilter'] = ""; // Chart Field $content['chart_field'] = SYSLOG_HOST; CreateChartFields($content['chart_field']); @@ -149,6 +150,7 @@ if ( isset($_GET['op']) ) $content['CHECKED_ISCHARTENABLED'] = ""; $content['chart_width'] = $myChart['chart_width']; $content['maxrecords'] = $myChart['maxrecords']; + $content['chart_defaultfilter'] = $myChart['chart_defaultfilter']; $content['showpercent'] = $myChart['showpercent']; if ( $myChart['showpercent'] == 1 ) $content['CHECKED_ISSHOWPERCENT'] = "checked"; @@ -261,6 +263,7 @@ if ( isset($_POST['op']) ) if ( isset($_POST['chart_field']) ) { $content['chart_field'] = DB_RemoveBadChars($_POST['chart_field']); } if ( isset($_POST['maxrecords']) ) { $content['maxrecords'] = intval(DB_RemoveBadChars($_POST['maxrecords'])); } if ( isset($_POST['showpercent']) ) { $content['showpercent'] = intval(DB_RemoveBadChars($_POST['showpercent'])); } else {$content['showpercent'] = 0; } + if ( isset($_POST['chart_defaultfilter']) ) { $content['chart_defaultfilter'] = DB_RemoveBadChars($_POST['chart_defaultfilter']); } // User & Group handeled specially if ( isset ($_POST['isuseronly']) ) @@ -310,12 +313,13 @@ if ( isset($_POST['op']) ) if ( $_POST['op'] == "addnewchart" ) { // Add custom search now! - $sqlquery = "INSERT INTO " . DB_CHARTS . " (DisplayName, chart_enabled, chart_type, chart_width, chart_field, maxrecords, showpercent, userid, groupid) + $sqlquery = "INSERT INTO " . DB_CHARTS . " (DisplayName, chart_enabled, chart_type, chart_width, chart_field, chart_defaultfilter, maxrecords, showpercent, userid, groupid) VALUES ('" . $content['Name'] . "', " . $content['chart_enabled'] . ", " . $content['chart_type'] . ", " . $content['chart_width'] . ", '" . $content['chart_field'] . "', + '" . $content['chart_defaultfilter'] . "', " . $content['maxrecords'] . ", " . $content['showpercent'] . ", " . $content['userid'] . ", @@ -344,7 +348,8 @@ if ( isset($_POST['op']) ) chart_enabled = " . $content['chart_enabled'] . ", chart_type = " . $content['chart_type'] . ", chart_width = " . $content['chart_width'] . ", - chart_field = '" . $content['chart_field'] . "', + chart_field = '" . $content['chart_field'] . "', + chart_defaultfilter = '" . $content['chart_defaultfilter'] . "', maxrecords = " . $content['maxrecords'] . ", showpercent = " . $content['showpercent'] . ", userid = " . $content['userid'] . ", @@ -439,6 +444,12 @@ if ( !isset($_POST['op']) && !isset($_GET['op']) ) $myChart['ChartEnabledImage'] = $content["MENU_SELECTION_DISABLED"]; // --- + // --- Set enabled or disabled state + if ( strlen($myChart['chart_defaultfilter']) > 0 ) + $myChart['chart_defaultfilter_urldecoded'] = urlencode($myChart['chart_defaultfilter']); + else + $myChart['chart_defaultfilter_urldecoded'] = ""; + // --- // --- Set CSS Class if ( $i % 2 == 0 ) diff --git a/src/chartgenerator.php b/src/chartgenerator.php index 1769d5c..9ff147a 100644 --- a/src/chartgenerator.php +++ b/src/chartgenerator.php @@ -114,6 +114,11 @@ if ( isset($_GET['showpercent']) ) } else $content['showpercent'] = 0; + +if ( isset($_GET['defaultfilter']) ) + $content['chart_defaultfilter'] = $_GET['defaultfilter']; +else + $content['chart_defaultfilter'] = ""; // --- // --- BEGIN CREATE TITLE @@ -132,10 +137,37 @@ if ( !$content['error_occured'] ) // Create LogStream Object $stream = $stream_config->LogStreamFactory($stream_config); - + $stream->SetFilter($content['chart_defaultfilter']); + // Set Columns we want to open! $content['ChartColumns'][] = SYSLOG_UID; $content['ChartColumns'][] = $content['chart_field']; + + // Append fields from defaultfilter as well ! + if ( strlen($content['chart_defaultfilter']) > 0 ) + { + $tmpFilters = explode(" ", $content['chart_defaultfilter']); + foreach($tmpFilters as $myFilter) + { + if ( strlen(trim($myFilter)) <= 0 ) + continue; + + if ( ($pos = strpos($myFilter, ":")) !== false + && + ($pos > 0 && substr($myFilter, $pos-1,1) != '\\') /* Only if character before is no backslash! */ ) + { + // Split key and value + $tmpArray = explode(":", $myFilter, 2); + + // Check if keyfield is valid and add to our Columns array if available + $newField = $stream->ReturnFilterKeyBySearchField($tmpArray[FILTER_TMP_KEY]); + if ( $newField ) + $content['ChartColumns'][] = $newField; + } + } + } + + // Open Data Connection! $res = $stream->Open( $content['ChartColumns'], true ); if ( $res == SUCCESS ) { diff --git a/src/classes/logstream.class.php b/src/classes/logstream.class.php index fa288af..3c52d8c 100644 --- a/src/classes/logstream.class.php +++ b/src/classes/logstream.class.php @@ -541,11 +541,28 @@ abstract class LogStream { return $this->_filters; } + /** + * Helper function to find a fieldkey by using the SearchField + */ + public function ReturnFilterKeyBySearchField($szSearchField) + { + global $fields; + + foreach ($fields as $myField) + { + if ( $myField['SearchField'] == $szSearchField ) + return $myField['FieldID']; + } + + + return FALSE; + } + /* * --- PIRVATE HELPERS! */ - + /** * Helper function to parse filters into a useful filter array we can work with. */ @@ -1016,7 +1033,7 @@ abstract class LogStream { } /* - * Helpre function needed in ParseFilters + * Helper function needed in SetFilterIncludeMode */ private function SetFilterIncludeMode(&$szValue) { diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index da377d3..67fe32b 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -885,11 +885,20 @@ class LogStreamDB extends LogStream { $myDBQueryFieldName = "DATE( " . $myDBFieldName . ") AS " . $mySelectFieldName ; } + // Create SQL Where Clause! + if ( $this->_SQLwhereClause == "" ) + { + $res = $this->CreateSQLWhereClause(); + if ( $res != SUCCESS ) + return $res; + } + // Create SQL String now! $szSql = "SELECT " . $myDBQueryFieldName . ", " . "count(" . $myDBFieldName . ") as TotalCount " . " FROM " . $this->_logStreamConfigObj->DBTableName . + $this->_SQLwhereClause . " GROUP BY " . $mySelectFieldName . " ORDER BY TotalCount DESC" . " LIMIT " . $nRecordLimit; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index c53d0cd..5929402 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -1045,11 +1045,20 @@ class LogStreamPDO extends LogStream { } } + // Create SQL Where Clause! + if ( $this->_SQLwhereClause == "" ) + { + $res = $this->CreateSQLWhereClause(); + if ( $res != SUCCESS ) + return $res; + } + // Create SQL String now! $szSql = "SELECT " . $myDBQueryFieldName . ", " . "count(" . $myDBFieldName . ") as totalcount " . " FROM " . $this->_logStreamConfigObj->DBTableName . + $this->_SQLwhereClause . " GROUP BY " . $mySelectFieldName . " ORDER BY totalcount DESC"; // Append LIMIT in this case! diff --git a/src/include/db_update_v10.txt b/src/include/db_update_v10.txt new file mode 100644 index 0000000..c1432bb --- /dev/null +++ b/src/include/db_update_v10.txt @@ -0,0 +1,7 @@ +-- New Database Structure Updates +ALTER TABLE `logcon_charts` ADD `chart_defaultfilter` VARCHAR( 1024 ) NOT NULL AFTER `chart_field` ; +ALTER TABLE `logcon_sources` ADD `defaultfilter` VARCHAR( 1024 ) NOT NULL AFTER `DBRecordsPerQuery` ; + +-- Insert data + +-- Updated Data diff --git a/src/include/functions_config.php b/src/include/functions_config.php index ed968d5..7c66bdf 100644 --- a/src/include/functions_config.php +++ b/src/include/functions_config.php @@ -823,6 +823,8 @@ function LoadChartsFromDatabase() if ( $content['database_installedversion'] < 3 ) return; + // Add new fields depending on DB Version! + // --- Create SQL Query // Create Where for USERID if ( isset($content['SESSION_LOGGEDIN']) && $content['SESSION_LOGGEDIN'] ) @@ -841,6 +843,7 @@ function LoadChartsFromDatabase() DB_CHARTS . ".chart_type, " . DB_CHARTS . ".chart_width, " . DB_CHARTS . ".chart_field, " . + DB_CHARTS . ".chart_defaultfilter, " . DB_CHARTS . ".maxrecords, " . DB_CHARTS . ".showpercent, " . DB_CHARTS . ".userid, " . diff --git a/src/include/functions_db.php b/src/include/functions_db.php index 39c4dbc..6edd0d1 100644 --- a/src/include/functions_db.php +++ b/src/include/functions_db.php @@ -45,7 +45,7 @@ $errdesc = ""; $errno = 0; // --- Current Database Version, this is important for automated database Updates! -$content['database_internalversion'] = "9"; // Whenever incremented, a database upgrade is needed +$content['database_internalversion'] = "10"; // Whenever incremented, a database upgrade is needed $content['database_installedversion'] = "0"; // 0 is default which means Prior Versioning Database // --- diff --git a/src/templates/admin/admin_charts.html b/src/templates/admin/admin_charts.html index 4802376..ceb9e63 100644 --- a/src/templates/admin/admin_charts.html +++ b/src/templates/admin/admin_charts.html @@ -54,7 +54,7 @@     -   +   @@ -112,6 +112,10 @@ {LN_CHART_SHOWPERCENT} + + {LN_CHARTS_FILTERSTRING} + {LN_CHARTS_FILTERSTRING_HELP}
+ {LN_GEN_USERONLY}