Просмотр исходного кода

eternal storage of logs is allowed

Roman Dmitriev 1 год назад
Родитель
Сommit
498856e2af

+ 4 - 4
docs/mysql/mysql.sql

@@ -140,16 +140,16 @@ INSERT INTO `config_options` (`id`, `option_name`, `description.russian`, `descr
 (44, 'Ignore hotspot dhcp log', 'Не писать лог событий dhcp-сервера хотспота. Имеет смысл вклчючать, поскольку время аренды в хот-споте как правило маленькое и в записях хот-спота становятся незаметны логи обычных пользователей', 'Do not write the event log of the hotspot dhcp server. It makes sense to include it, since the rental time in the hotspot is usually small and the logs of ordinary users become invisible in the hotspot records', 1, 'bool', '1', 0, 1),
 (45, 'ignore update dhcp event', 'Не писать события обновления ip-адреса dhcp-сервера. ', 'Do not write events for updating the IP address of the dhcp server. ', 1, 'bool', '0', 0, 1),
 (46, 'update hostname from dhcp', 'Обновлять имя хоста в DNS при получении адреса по DHCP', 'Update the hostname in DNS when receiving the address via DHCP', 1, 'bool', '0', 0, 1),
-(47, 'history worklog', 'Глубина хранения логов работы в интерфейсе администратора', 'Depth of work logs storage in the admin interface', 1, 'int', '90', 30, 1095),
-(48, 'history syslog', 'Глубина хранения логов работы syslog-сервера', 'Syslog server logs storage depth', 1, 'int', '90', 30, 1095),
-(49, 'history traffic stats', 'Глубина хранения статистики трафика юзеров', 'User traffic statistics storage depth', 1, 'int', '365', 30, 0),
+(47, 'history worklog', 'Глубина хранения VERBOSE логов работы в интерфейсе администратора', 'Depth of VERBOSE work logs storage in the admin interface', 1, 'int', '90', 0, 1095),
+(48, 'history syslog', 'Глубина хранения логов работы syslog-сервера', 'Syslog server logs storage depth', 1, 'int', '90', 0, 1095),
+(49, 'history traffic stats', 'Глубина хранения статистики трафика юзеров', 'User traffic statistics storage depth', 1, 'int', '365', 0, 0),
 (50, 'urgent sync access', 'Немедленное изменение списков доступа на роутере после правки записи пользователя', 'Immediate change of access lists on the router after editing the user record ', 1, 'bool', '0', 0, 1),
 (51, 'Email_alert', 'Отправлять e-mail сообщения для уровней сообщений WARNING & ERROR', 'Send e-mail messages for message levels WARNING & ERROR', 1, 'bool', '1', 0, 1),
 (52, 'Sender email', 'E-mail адрес, с которого рассылается почта', 'E-mail address from which mail is sent', 1, 'text', 'root', 0, 0),
 (53, 'log level', 'Каждый уровень включает в себя предыдущий:\r\n0 - ERROR - писать только ошибки\r\n1 - WARNING - писать предупреждения\r\n2 - INFO - писать информационные сообщения\r\n3 - VERBOSE - писать подробную информацию о выполняемых операциях', 'Each level includes the previous one:\r\n0 - ERROR - write only errors\r\n1 - WARNING - write warnings\r\n2 - INFO - write informational\r\n3 - VERBOSE - write detailed information about the operations performed ', 1, 'int', '2', 0, 3),
 (54, 'enable_quotes', 'Включить обработку квот по трафику', 'Enable traffic quota processing', 1, 'bool', '0', 0, 1),
 (55, 'netflow_step', 'Интервал сброса данных из коллектора netflow, минуты', 'Data reset interval from netflow collector, minutes', 1, 'int', '10', 1, 60),
-(56, 'traffic_ipstat_history', 'Время хранения полной статистики по трафику для каждого ip-адреса в сутках. Таблица в 6 раз больше обычной часовой статистики. Врядли кому-то потребуется глубина хранения более месяца.', 'The storage time of complete traffic statistics for each ip address in days. The table is 6 times larger than the usual hourly statistic Hardly anyone will need a storage depth of more than a month.', 1, 'int', '30', 7, 365),
+(56, 'traffic_ipstat_history', 'Время хранения полной статистики по трафику для каждого ip-адреса в сутках. Таблица в 6 раз больше обычной часовой статистики. Врядли кому-то потребуется глубина хранения более месяца.', 'The storage time of complete traffic statistics for each ip address in days. The table is 6 times larger than the usual hourly statistic Hardly anyone will need a storage depth of more than a month.', 1, 'int', '30', 0, 365),
 (57, 'nagios_url', 'Адрес сайта nagios', 'nagios site address', 1, 'text', 'http://127.0.0.1/nagios', 0, 0),
 (58, 'cacti_url', 'Адрес сайта cacti', 'cacti site address', 1, 'text', 'http://127.0.0.1/cacti', 0, 0),
 (59, 'torrus_url', 'Адрес сайта Torrus', 'Torrus website address', 1, 'text', 'http://127.0.0.1/torrus/CollectorName/', 0, 0),

+ 3 - 2
html/admin/customers/control-options.php

@@ -83,7 +83,8 @@ print_control_submenu($page_url);
 
             <?php
             $descr_field = "description." . HTML_LANG;
-            $t_config = mysqli_query($db_link, "SELECT `config`.`id`,`option_id`,`option_name`,`value`,`type`,`" . $descr_field . "`,`min_value`,`max_value` FROM `config`,`config_options` WHERE `config`.`option_id`=`config_options`.`id` ORDER BY `option_name`");
+            $config_sql = "SELECT `config`.`id`,`option_id`,`option_name`,`value`,`type`,`" . $descr_field . "`,`min_value`,`max_value` FROM `config`,`config_options` WHERE `config`.`option_id`=`config_options`.`id` ORDER BY `option_name`";
+            $t_config = mysqli_query($db_link, $config_sql);
             while ($row = mysqli_fetch_array($t_config)) {
                 print "<tr align=center>\n";
                 print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_id[" . $row["option_id"] . "] value='" . $row['id'] . "'></td>\n";
@@ -101,7 +102,7 @@ print_control_submenu($page_url);
                 if ($type == 'int') {
                     $min = '';
                     $max = '';
-                    if (!empty($row['min_value']) or $row['min_value'] == 0) {
+                    if (!empty($row['min_value']) or $row['min_value']==0) {
                         $min = "min=" . $row['min_value'];
                     }
                     if (!empty($row['max_value'])) {

+ 67 - 58
scripts/garbage.pl

@@ -37,6 +37,8 @@ my @db_tables =(
 'Traffic_detail',
 );
 
+my $debug_history = 3;
+
 db_log_info($dbh,'Garbage started.');
 
 sub is_dhcp_pool {
@@ -134,27 +136,30 @@ if ($dhcp_networks->match_string($row->{ip})) {
 db_log_info($dbh,'Finished');
 
 $now = DateTime->now(time_zone=>'local');
-my $day_dur = DateTime::Duration->new( days => $history_dhcp );
-my $clean_date = $now - $day_dur;
-my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
 
 #clean dhcp log
-db_log_info($dbh,'Clearing outdated records dhcp log');
-do_sql($dbh,"DELETE FROM dhcp_log WHERE `timestamp` < $clean_str" );
-db_log_verbose($dbh,"Clean dhcp leases for all older that ".$clean_str);
+if ($history_dhcp) {
+    my $day_dur = DateTime::Duration->new( days => $history_dhcp );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,'Clearing outdated records dhcp log');
+    do_sql($dbh,"DELETE FROM dhcp_log WHERE `timestamp` < $clean_str" );
+    db_log_verbose($dbh,"Clean dhcp leases for all older that ".$clean_str);
+}
 
 ##### clean old connections ########
-db_log_info($dbh,'Clearing outdated connection records');
-$day_dur = DateTime::Duration->new( days => $connections_history );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-$users_sql = "SELECT id FROM User_auth WHERE `last_found` < $clean_str and last_found>0";
-db_log_debug($dbh,$users_sql) if ($debug);
-@users_auth=get_records_sql($dbh,$users_sql);
-foreach my $row (@users_auth) {
-db_log_debug($dbh,"Clear old connection for user_auth ".$row->{id});
-do_sql($dbh,"DELETE FROM connections WHERE auth_id='".$row->{id}."'");
+if ($connections_history) {
+    db_log_info($dbh,'Clearing outdated connection records');
+    my $day_dur = DateTime::Duration->new( days => $connections_history );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    $users_sql = "SELECT id FROM User_auth WHERE `last_found` < $clean_str and last_found>0";
+    db_log_debug($dbh,$users_sql) if ($debug);
+    @users_auth=get_records_sql($dbh,$users_sql);
+    foreach my $row (@users_auth) {
+        db_log_debug($dbh,"Clear old connection for user_auth ".$row->{id});
+        do_sql($dbh,"DELETE FROM connections WHERE auth_id='".$row->{id}."'");
+    }
 }
 
 ##### clean dup connections ########
@@ -231,59 +236,63 @@ do_sql($dbh,"DELETE FROM Unknown_mac WHERE mac='".mac_simplify($row->{mac})."'")
 
 ##### traffic detail ######
 
-$day_dur = DateTime::Duration->new( days => $history );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-db_log_info($dbh,"Clean traffic detail older that ".$clean_str);
-#clean old traffic detail
-do_sql($dbh,"DELETE FROM Traffic_detail WHERE `timestamp` < $clean_str" );
+if ($history) {
+    my $day_dur = DateTime::Duration->new( days => $history );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean traffic detail older that ".$clean_str);
+    #clean old traffic detail
+    do_sql($dbh,"DELETE FROM Traffic_detail WHERE `timestamp` < $clean_str" );
+}
 
 ##### log  ######
 
-$day_dur = DateTime::Duration->new( days => $history_log_day );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-db_log_info($dbh,"Clean VERBOSE worklog older that ".$clean_str);
-do_sql($dbh,"DELETE FROM worklog WHERE level>$L_INFO AND `timestamp` < $clean_str" );
-
-#clean debug logs older than 2 days
-$day_dur = DateTime::Duration->new( days => 2 );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+if ($history_log_day) {
+    $day_dur = DateTime::Duration->new( days => $history_log_day );
+    $clean_date = $now - $day_dur;
+    $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean VERBOSE worklog older that ".$clean_str);
+    $ql($dbh,"DELETE FROM worklog WHERE level>$L_INFO AND `timestamp` < $clean_str" );
+}
 
-db_log_info($dbh,"Clean debug worklog older that ".$clean_str);
-do_sql($dbh,"DELETE FROM worklog WHERE level>$L_DEBUG AND `timestamp` < $clean_str" );
+#clean debug logs older than $debug_history days
+if ($debug_history) {
+    my $day_dur = DateTime::Duration->new( days => 3 );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean debug worklog older that ".$clean_str);
+    do_sql($dbh,"DELETE FROM worklog WHERE level>$L_DEBUG AND `timestamp` < $clean_str" );
+}
 
 ##### remote syslog  ######
 
-$day_dur = DateTime::Duration->new( days => $history_syslog_day );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-db_log_info($dbh,"Clean syslog older that ".$clean_str);
-do_sql($dbh,"DELETE FROM remote_syslog WHERE `date` < $clean_str" );
+if ($history_syslog_day) {
+    my $day_dur = DateTime::Duration->new( days => $history_syslog_day );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean syslog older that ".$clean_str);
+    do_sql($dbh,"DELETE FROM remote_syslog WHERE `date` < $clean_str" );
+}
 
 ##### Traffic stats  ######
 
-$day_dur = DateTime::Duration->new( days => $history_trafstat_day );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-db_log_info($dbh,"Clean traffic statistics older that ".$clean_str);
-do_sql($dbh,"DELETE FROM User_stats WHERE `timestamp` < $clean_str" );
+if ($history_trafstat_day) {
+    my $day_dur = DateTime::Duration->new( days => $history_trafstat_day );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean traffic statistics older that ".$clean_str);
+    do_sql($dbh,"DELETE FROM User_stats WHERE `timestamp` < $clean_str" );
+}
 
 ##### Traffic stats full ######
-
-my $iptraf_history = $config_ref{traffic_ipstat_history} || 30;
-
-$day_dur = DateTime::Duration->new( days => $iptraf_history );
-$clean_date = $now - $day_dur;
-$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
-
-db_log_info($dbh,"Clean traffic full statistics older that ".$clean_str);
-do_sql($dbh,"DELETE FROM User_stats_full WHERE `timestamp` < $clean_str" );
+my $iptraf_history = $config_ref{traffic_ipstat_history};
+if ($iptraf_history) {
+    my $day_dur = DateTime::Duration->new( days => $iptraf_history );
+    my $clean_date = $now - $day_dur;
+    my $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+    db_log_info($dbh,"Clean traffic full statistics older that ".$clean_str);
+    do_sql($dbh,"DELETE FROM User_stats_full WHERE `timestamp` < $clean_str" );
+}
 
 #### clean unknown user ip
 do_sql($dbh,"DELETE FROM User_auth WHERE (mac is NULL or mac='') and deleted=1");

+ 7 - 1
scripts/updates/2-5-3/mysql-acl.sql

@@ -1,3 +1,4 @@
+RENAME TABLE `syslog` TO `worklog`;
 CREATE TABLE `acl` (`id` int(11) NOT NULL,`name` varchar(30) NOT NULL,`description.english` varchar(250) NOT NULL,`description.russian` varchar(250) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 INSERT INTO `acl` VALUES(1, 'Full access', 'Full access', 'Полный доступ');
 INSERT INTO `acl` VALUES(2, 'Operator', 'Editing parameters that are not related to access rights', 'Редактирование параметров, не связанных с правами доступа');
@@ -8,4 +9,9 @@ UPDATE `Customers` set rights=1 WHERE rights=0;
 ALTER TABLE `acl`  ADD PRIMARY KEY (`id`);
 ALTER TABLE `acl`  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
 ALTER TABLE `Customers` ADD `comment` VARCHAR(100) NULL AFTER `Login`;
-RENAME TABLE `syslog` TO `worklog`;
+UPDATE `config_options` SET `description.russian` = 'Глубина хранения VERBOSE логов работы в интерфейсе администратора' WHERE `config_options`.`id` = 47;
+UPDATE `config_options` SET `description.english` = 'Depth of VERBOSE work logs storage in the admin interface' WHERE `config_options`.`id` = 47;
+UPDATE `config_options` SET `min_value` = '0' WHERE `config_options`.`id` = 47;
+UPDATE `config_options` SET `min_value` = '0' WHERE `config_options`.`id` = 48;
+UPDATE `config_options` SET `min_value` = '0' WHERE `config_options`.`id` = 49;
+UPDATE `config_options` SET `min_value` = '0' WHERE `config_options`.`id` = 56;