diff --git a/cron/crontime.php b/cron/crontime.php index ccaac15..4eabd79 100644 --- a/cron/crontime.php +++ b/cron/crontime.php @@ -20,9 +20,9 @@ class crontime { $day_week = $day_week % 6; // 7 and 0 both mean Sunday $now_day_week = $now_day_week % 6; // 7 and 0 both mean Sunday $next_day += abs($day_week - $now_day_week);} - new \SYSTEM\LOG\INFO(print_r(array($base_time,$min,$hour,$day,$day_week,$month),true)); - new \SYSTEM\LOG\INFO(print_r(array($now_min, $now_hour, $now_day, $now_month, $now_day_week),true)); - new \SYSTEM\LOG\INFO(print_r(array($next_hour, $next_min, 0, $next_month, $next_day, $next_year),true)); + //new \SYSTEM\LOG\INFO(print_r(array($base_time,$min,$hour,$day,$day_week,$month),true)); + //new \SYSTEM\LOG\INFO(print_r(array($now_min, $now_hour, $now_day, $now_month, $now_day_week),true)); + //new \SYSTEM\LOG\INFO(print_r(array($next_hour, $next_min, 0, $next_month, $next_day, $next_year),true)); return mktime($next_hour, $next_min, 0, $next_month, $next_day, $next_year); } public static function last($base_time,$min,$hour,$day,$day_week,$month){ diff --git a/db/connection/ConnectionSQLite.php b/db/connection/ConnectionSQLite.php index 78c195e..0f307ab 100644 --- a/db/connection/ConnectionSQLite.php +++ b/db/connection/ConnectionSQLite.php @@ -16,22 +16,17 @@ class ConnectionSQLite extends ConnectionAbstr { $this->close();} public function prepare($stmtName, $stmt, $values){ - $prepStmt = \sqlite_prepare($this->connection, $stmt,$error); + $prepStmt = $this->connection->prepare($stmt); if(!$prepStmt){ throw new \SYSTEM\LOG\ERROR('Prepared Statement prepare fail: '. $error);} - $types = ''; - $binds = array($prepStmt,null); - for($i =0; $i < \count($values);$i++){ - $types .= self::getPrepareValueType($values[$i]); - $binds[] = &$values[$i];} - $binds[1] = $types; - \call_user_func_array('sqlite_stmt_bind_param', $binds); //you need 2 append the parameters - thats the right way to do that. + foreach($values as $key=>$val){ + $prepStmt->bindParam($key,$val);} - if(!sqlite_stmt_execute($prepStmt,$error)){ + if(!($result = $prepStmt->execute())){ throw new \SYSTEM\LOG\ERROR("Could not execute prepare statement: ". $error);} - return new ResultSQLite($prepStmt,$this); + return new ResultSQLite($result,$this); } public function close(){ diff --git a/db/dbinfo/DBInfoSQLite.php b/db/dbinfo/DBInfoSQLite.php index 815e821..c89dd8e 100644 --- a/db/dbinfo/DBInfoSQLite.php +++ b/db/dbinfo/DBInfoSQLite.php @@ -9,8 +9,7 @@ class DBInfoSQLite extends \SYSTEM\DB\DBInfo { $this->m_host = $host; $this->m_port = $port; - if( $this->m_database == null || - $this->m_user == null){ + if( $this->m_database == null){ throw new \Exception("DBInfo not correct, database, permissions are null");} } } \ No newline at end of file diff --git a/db/result/ResultSQLite.php b/db/result/ResultSQLite.php index 2bd659e..5f514d5 100644 --- a/db/result/ResultSQLite.php +++ b/db/result/ResultSQLite.php @@ -5,17 +5,19 @@ namespace SYSTEM\DB; class ResultSQLite extends \SYSTEM\DB\Result{ private $res = NULL; + private $stmt = NULL; private $current = NULL; //Result from mysql_query - public function __construct($res){ - $this->res = $res;} + public function __construct($res,$stmt){ + $this->res = $res; + $this->stmt = $stmt;} public function __destruct(){ $this->close();} public function close(){ - $this->res->finalize();} + $this->stmt->close();} public function count(){ throw new Exception("Problem SQLite"); @@ -29,9 +31,10 @@ class ResultSQLite extends \SYSTEM\DB\Result{ */ public function affectedRows(){ + throw new Exception("Problem SQLite"); return mysqli_affected_rows($this->res);} - public function next($object = false, $result_type = SQLITE3_BOTH){ + public function next($object = false, $result_type = SQLITE3_ASSOC){ if($object){ throw new Exception("Problem SQLite"); } else { diff --git a/dbd/sql/mysql/data/sai_api.sql b/dbd/sql/mysql/data/sai_api.sql index 997a1c5..86088dc 100644 --- a/dbd/sql/mysql/data/sai_api.sql +++ b/dbd/sql/mysql/data/sai_api.sql @@ -50,6 +50,7 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam -- INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (220, 42, 0, 200, 'stats', 'name', null); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (221, 42, 3, 220, null, 'filter', 'UINT'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (222, 42, 3, 220, null, 'db', 'STRING'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (300, 42, 0, 0, '_SYSTEM_SAI_saimod_sys_security', 'action', NULL); diff --git a/sai/modules/saimod_sys_log/saimod_sys_log.js b/sai/modules/saimod_sys_log/js/saimod_sys_log.js similarity index 57% rename from sai/modules/saimod_sys_log/saimod_sys_log.js rename to sai/modules/saimod_sys_log/js/saimod_sys_log.js index b2fe0f2..fae24a8 100644 --- a/sai/modules/saimod_sys_log/saimod_sys_log.js +++ b/sai/modules/saimod_sys_log/js/saimod_sys_log.js @@ -22,11 +22,6 @@ function load_log_tab(action){ register_stats(); $('img#loader').hide();}); return; - case 'admin': - $('#tab_admin').load(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action='+action, function(){ - register_admin(); - $('img#loader').hide();}); - return; default: $('img#loader').hide(); } @@ -58,52 +53,25 @@ function register_log(){ load_table_log($(this).attr('filter')); }); } -var filter_time = 3600; -var last_active = "#basic_tab"; function register_stats(){ - filter_time = 3600; + load_visualisation(); + $('#vis_filter_time').change(function(){ + load_visualisation();}) + $('#vis_filter_type').change(function(){ + load_visualisation();}) $('#stats_tabs a').click(function (e) { e.preventDefault(); - $(this).tab('show'); - last_active = $(this).attr('href'); - $($(this).attr('href')+' .visualisation').each(function(){ - load_visualisation($(this).attr('id'),filter_time); - }); - }); - $("#stats_filter a").click(function(){ - $('#stats_filter li').each(function(){ - $(this).removeClass('active');}); - $(this).parent().addClass('active'); - filter_time = $(this).attr('filter'); - $(last_active+' .visualisation').each(function(){ - load_visualisation($(this).attr('id'),filter_time); - }); - }); - $('#basic_tab .visualisation').each(function(){ - load_visualisation($(this).attr('id'),filter_time); + $(this).tab('show'); + load_visualisation(); }); } -function register_admin(){ - $('#truncate_table').click(function(){ - $.ajax({ type :'GET', - url : SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=truncate', - success : function(data) { - if(data == 1){ - $('#info_box').html("deleting data..."); - $('#truncate_modal').modal('hide'); - $('#content-wrapper').load(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log'); - }else{ - $('#info_box').html("You do not have the permission to truncate table!"); - } - } - }); - }); -} - -function load_visualisation(id, filter){ - $('img#loader').show(); - $.getJSON(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=stats&name='+id+'&filter='+filter,function(json){ +function load_visualisation(){ + $('img#loader').show(); + var name = $('#vis_filter_type').val();; + var filter = $('#vis_filter_time').val(); + var db = $('#stats_tabs li.active').attr('db'); + $.getJSON(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_log&action=stats&name='+name+'&filter='+filter+'&db='+db,function(json){ if(!json || json.status != true || !json.result){ $('img#loader').hide(); return; @@ -122,7 +90,7 @@ function load_visualisation(id, filter){ }); $.each(json, function(key, value){first = true; data.addRow($.map(value, function(v) { if(first){first=false;return [new Date(v)];}else{return [(v == null || parseFloat(v) <= 0) ? 0.1 : parseFloat(v)];}}));}); - var options = {title: id, aggregationTarget: 'category', selectionMode: 'multiple', curveType: 'function', /*focusTarget: 'category',*/ chartArea:{left:100,top:40}, vAxis:{logScale: true}, interpolateNulls: false, width: "1200", height: "500"}; - new google.visualization.LineChart(document.getElementById(id)).draw(data, options); + var options = {title: name, aggregationTarget: 'category', selectionMode: 'multiple', curveType: 'function', /*focusTarget: 'category',*/ chartArea:{left:100,top:40}, vAxis:{logScale: true}, interpolateNulls: false, width: "1200", height: "500"}; + new google.visualization.LineChart(document.getElementById('vis')).draw(data, options); }); } \ No newline at end of file diff --git a/sai/modules/saimod_sys_log/saimod_sys_log.php b/sai/modules/saimod_sys_log/saimod_sys_log.php index f75f652..20cb337 100644 --- a/sai/modules/saimod_sys_log/saimod_sys_log.php +++ b/sai/modules/saimod_sys_log/saimod_sys_log.php @@ -8,51 +8,258 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule { return \SYSTEM\LOG\JsonResult::ok();} public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats(){ - $vars = array(); + $vars = array(); + $vars['dbfile_entries'] = ''; + $scanned_directory = array_diff(scandir(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH)), array('..', '.')); + foreach($scanned_directory as $file){ + $vars['dbfile_entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_stats_menu.tpl'), array('file' => $file));} return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_stats.tpl'), $vars);} - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_admin(){ - $vars = array(); - return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_admin.tpl'), $vars);} + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_system($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_SYSTEM::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('class_system', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\COUNTER" then 1 else 0 end) class_SYSTEM_LOG_COUNTER,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\INFO" then 1 else 0 end) class_SYSTEM_LOG_INFO,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\DEPRECATED" then 1 else 0 end) class_SYSTEM_LOG_DEPRECATED,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\WARNING" then 1 else 0 end) class_SYSTEM_LOG_WARNING,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\ERROR" then 1 else 0 end) class_SYSTEM_LOG_ERROR,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\ERROR_EXCEPTION" then 1 else 0 end) class_SYSTEM_LOG_ERROR_EXCEPTION,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\LOG\\SHUTDOWN_EXCEPTION" then 1 else 0 end) class_SYSTEM_LOG_SHUTDOWN_EXCEPTION' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_system($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_SYSTEM::QA(array($filter)); + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_other($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_OTHER::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('class_other', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'Exception\' then 1 else 0 end) class_Exception,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'RuntimeException\' then 1 else 0 end) class_RuntimeException,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'ErrorException\' then 1 else 0 end) class_ErrorException' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_basic($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_BASIC::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('class_basic', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'ERROR\' then 1 else 0 end) class_ERROR,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'WARNING\' then 1 else 0 end) class_WARNING,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'INFO\' then 1 else 0 end) class_INFO,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'DEPRECATED\' then 1 else 0 end) class_DEPRECATED,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = \'AppError\' then 1 else 0 end) class_AppError' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_basic($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_BASIC::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('unique_basic', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'count(distinct "'.\SYSTEM\DBD\system_log::FIELD_USER.'") as user_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_IP.') as ip_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_SERVER_NAME.') as server_name_unique' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_request($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_REQUEST::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('unique_request', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_SERVER_NAME.') as server_name_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_SERVER_PORT.') as server_port_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_REQUEST_URI.') as request_uri_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_POST.') as post_unique' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_exception($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_EXCEPTION::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('unique_exception', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_FILE.') as file_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_LINE.') as line_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_CLASS.') as class_unique' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_referer($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_REFERER::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('unique_referer', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'count(distinct "'.\SYSTEM\DBD\system_log::FIELD_USER.'") as user_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_IP.') as ip_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_HTTP_REFERER.') as http_referer_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_HTTP_USER_AGENT.') as http_user_agent_unique' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_visitor($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_VISITOR::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('basic_visitor', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'count(distinct "'.\SYSTEM\DBD\system_log::FIELD_USER.'") as user_unique,' + .'count(distinct '.\SYSTEM\DBD\system_log::FIELD_IP.') as ip_unique' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } + return \SYSTEM\LOG\JsonResult::toString($result); + } + + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_sucess($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_SUCCESS::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('basic_sucess', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'sum(case when not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\COUNTER" and' + .' not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\INFO" and' + .' not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "INFO" and' + .' not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\DEPRECATED" and' + .' not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "DEPRECATED" and ' + .' not '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "PreprocessingLog" ' + .'then 1 else 0 end) class_fail,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\INFO" or ' + .\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\INFO" or ' + .\SYSTEM\DBD\system_log::FIELD_CLASS.' = "INFO" or ' + .\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\DEPRECATE" or ' + .\SYSTEM\DBD\system_log::FIELD_CLASS.' = "DEPRECATED" or ' + .\SYSTEM\DBD\system_log::FIELD_CLASS.' = "PreprocessingLog" ' + .'then 1 else 0 end) class_log,' + .'sum(case when '.\SYSTEM\DBD\system_log::FIELD_CLASS.' = "SYSTEM\\\\LOG\\\\COUNTER" then 1 else 0 end) class_sucess' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } return \SYSTEM\LOG\JsonResult::toString($result);} - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_other($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_OTHER::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_class_basic($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_CLASS_BASIC::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_basic($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_BASIC::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_request($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_REQUEST::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_exception($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_EXCEPTION::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_unique_referer($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_UNIQUE_REFERER::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_visitor($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_VISITOR::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_sucess($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_SUCCESS::QA(array($filter)); - return \SYSTEM\LOG\JsonResult::toString($result);} - - public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_querytime($filter){ - $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_QUERYTIME::QA(array($filter)); + public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_stats_name_basic_querytime($filter,$db){ + $result = array(); + if(!$db){ + $result = \SYSTEM\DBD\SYS_SAIMOD_LOG_BASIC_QUERYTIME::QA(array($filter)); + } else { + $con = new \SYSTEM\DB\Connection(new \SYSTEM\DB\DBInfoSQLite(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CRON_LOG2SQLITE_PATH).$db)); + $res = $con->prepare('basic_querytime', + 'SELECT datetime(strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.') - strftime("%s",'.\SYSTEM\DBD\system_log::FIELD_TIME.')%:filter,"unixepoch", "localtime") as day,' + .'count(*) as count,' + .'avg('.\SYSTEM\DBD\system_log::FIELD_QUERYTIME.') as querytime_avg,' + .'max('.\SYSTEM\DBD\system_log::FIELD_QUERYTIME.') as querytime_max,' + .'min('.\SYSTEM\DBD\system_log::FIELD_QUERYTIME.') as querytime_min' + .' FROM '.\SYSTEM\DBD\system_log::NAME_MYS + .' GROUP BY day' + .' ORDER BY day DESC' + .' LIMIT 30;', + array(':filter' => $filter)); + while($row = $res->next()){ + $result[] = $row;} + } return \SYSTEM\LOG\JsonResult::toString($result);} public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_error($error){ @@ -141,5 +348,5 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule { public static function sai_mod__SYSTEM_SAI_saimod_sys_log_flag_css(){} public static function sai_mod__SYSTEM_SAI_saimod_sys_log_flag_js(){ return \SYSTEM\LOG\JsonResult::toString( - array(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/saimod_sys_log.js')));} + array(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/js/saimod_sys_log.js')));} } \ No newline at end of file diff --git a/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl b/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl index d14705f..d7fce53 100644 --- a/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl +++ b/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl @@ -4,13 +4,11 @@
This action will delete all error messages from database.
Are you sure?