diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index ccf984573..0b568d2c0 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -768,20 +768,14 @@ function system_syslogd_start() $syslogcfg = $config['syslog']; - if (file_exists("/var/run/booting")) - echo gettext("Starting syslog..."); - - // Which logging type are we using this week?? - if (isset($config['system']['disablesyslogclog'])) { - $log_directive = ""; - $log_create_directive = "/usr/bin/touch "; - $log_size = ""; - } else { // Defaults to CLOG - $log_directive = "%"; - $log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "10240"; - $log_create_directive = "/usr/local/sbin/clog -i -s "; + if (file_exists('/var/run/booting')) { + echo gettext('Starting syslog...'); } + $log_directive = '%'; + $log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : '511488'; + $log_create_directive = '/usr/local/sbin/clog -i -s '; + $syslogd_extra = ""; if (isset($syslogcfg)) { $separatelogfacilities = array('ntp','ntpd','ntpdate','charon','openvpn','pptps','poes','l2tps','relayd','hostapd','dnsmasq','filterdns','unbound','dhcpd','dhcrelay','dhclient','dhcp6c','apinger','radvd','routed','olsrd','zebra','ospfd','bgpd','miniupnpd','filterlog'); diff --git a/src/etc/rc b/src/etc/rc index 9d902f2e6..6bbf5f43e 100755 --- a/src/etc/rc +++ b/src/etc/rc @@ -165,7 +165,6 @@ rm -rf /tmp/* chmod 1777 /tmp echo -n "." -DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /conf/config.xml` LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppps relayd wireless lighttpd ntpd gateways resolver routing" DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//opnsense/syslog/logfilesize)' /conf/config.xml` @@ -174,12 +173,8 @@ if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then fi for logfile in $LOG_FILES; do - if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then - touch /var/log/$logfile.log - else - if [ ! -f /var/log/$logfile.log ]; then - clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log - fi + if [ ! -f /var/log/$logfile.log ]; then + clog -i -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log fi chmod 0600 /var/log/$logfile.log done diff --git a/src/www/diag_logs.php b/src/www/diag_logs.php index 2a3beacb1..1f1b9dc7b 100644 --- a/src/www/diag_logs.php +++ b/src/www/diag_logs.php @@ -41,7 +41,7 @@ if (empty($config['syslog']['nentries'])) { } if (isset($_POST['clear'])) { - clear_log_file($system_logfile); + clear_clog($system_logfile); } if ($_GET['filtertext']) { diff --git a/src/www/diag_logs_auth.php b/src/www/diag_logs_auth.php index 4541ba673..1ee0b5996 100644 --- a/src/www/diag_logs_auth.php +++ b/src/www/diag_logs_auth.php @@ -41,7 +41,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($portal_logfile); + clear_clog($portal_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("Portal Auth")); diff --git a/src/www/diag_logs_dhcp.php b/src/www/diag_logs_dhcp.php index e5f3297b8..bbbf71700 100644 --- a/src/www/diag_logs_dhcp.php +++ b/src/www/diag_logs_dhcp.php @@ -42,7 +42,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($dhcpd_logfile); + clear_clog($dhcpd_logfile); killbyname("dhcpd"); services_dhcpd_configure(); } diff --git a/src/www/diag_logs_filter.php b/src/www/diag_logs_filter.php index 131842c1c..3083b74b3 100644 --- a/src/www/diag_logs_filter.php +++ b/src/www/diag_logs_filter.php @@ -586,9 +586,8 @@ if (isset($filterlogentries_qty) && $filterlogentries_qty != null) { $nentries = $filterlogentries_qty; } - if (isset($_POST['clear'])) { - clear_log_file($filter_logfile); + clear_clog($filter_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("Firewall")); @@ -599,7 +598,6 @@ include("head.inc"); - diff --git a/src/www/diag_logs_filter_dynamic.php b/src/www/diag_logs_filter_dynamic.php index 1531fd34e..d9a8af76c 100644 --- a/src/www/diag_logs_filter_dynamic.php +++ b/src/www/diag_logs_filter_dynamic.php @@ -42,7 +42,7 @@ $nentries = 50; handle_ajax($nentries, $nentries + 20); if (isset($_POST['clear'])) { - clear_log_file($filter_logfile); + clear_clog($filter_logfile); } $filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100); diff --git a/src/www/diag_logs_filter_summary.php b/src/www/diag_logs_filter_summary.php index ab861872f..931155364 100644 --- a/src/www/diag_logs_filter_summary.php +++ b/src/www/diag_logs_filter_summary.php @@ -1,4 +1,5 @@ - @@ -96,17 +74,7 @@ include("head.inc");
- \n"; - $entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3))); - echo "\n"; - echo "\n"; - echo "\n"; - } - ?> +
" . $entry_date_time . "" . $logent[4] . " " . $logent[5] . "
diff --git a/src/www/diag_logs_ntpd.php b/src/www/diag_logs_ntpd.php index 38c7f60d8..e53b59ab4 100644 --- a/src/www/diag_logs_ntpd.php +++ b/src/www/diag_logs_ntpd.php @@ -43,7 +43,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($ntpd_logfile); + clear_clog($ntpd_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("NTP")); diff --git a/src/www/diag_logs_openvpn.php b/src/www/diag_logs_openvpn.php index 8223d1e51..2f866df68 100644 --- a/src/www/diag_logs_openvpn.php +++ b/src/www/diag_logs_openvpn.php @@ -46,7 +46,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($openvpn_logfile); + clear_clog($openvpn_logfile); } include("head.inc"); diff --git a/src/www/diag_logs_pills.php b/src/www/diag_logs_pills.php index f5b483bbe..d4826f0d6 100644 --- a/src/www/diag_logs_pills.php +++ b/src/www/diag_logs_pills.php @@ -1,4 +1,5 @@
-

-
+

+
+ + +
+
" />
diff --git a/src/www/diag_logs_relayd.php b/src/www/diag_logs_relayd.php index daf269efc..b7de84dc1 100644 --- a/src/www/diag_logs_relayd.php +++ b/src/www/diag_logs_relayd.php @@ -42,7 +42,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($relayd_logfile); + clear_clog($relayd_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("Load Balancer")); diff --git a/src/www/diag_logs_resolver.php b/src/www/diag_logs_resolver.php index 0e775e518..36cb19523 100644 --- a/src/www/diag_logs_resolver.php +++ b/src/www/diag_logs_resolver.php @@ -43,7 +43,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($system_logfile); + clear_clog($system_logfile); } if ($_GET['filtertext']) { diff --git a/src/www/diag_logs_routing.php b/src/www/diag_logs_routing.php index 857894c41..9dd92d6a4 100644 --- a/src/www/diag_logs_routing.php +++ b/src/www/diag_logs_routing.php @@ -40,7 +40,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($routing_logfile); + clear_clog($routing_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("Routing")); diff --git a/src/www/diag_logs_settings.php b/src/www/diag_logs_settings.php index e9563ce5b..3be7ec358 100644 --- a/src/www/diag_logs_settings.php +++ b/src/www/diag_logs_settings.php @@ -1,4 +1,5 @@ + +$active_tab = isset($active_tab) ? $active_tab : $_SERVER['PHP_SELF']; +$tab_array = array(); +$tab_array[] = array(gettext("System"), $active_tab == "/diag_logs.php", "diag_logs.php"); +$tab_array[] = array(gettext("Firewall"), $active_tab == "/diag_logs_filter.php", "diag_logs_filter.php"); +$tab_array[] = array(gettext("DHCP"), $active_tab == "/diag_logs_dhcp.php", "diag_logs_dhcp.php"); +$tab_array[] = array(gettext("Portal Auth"), $active_tab == "/diag_logs_auth.php", "diag_logs_auth.php"); +$tab_array[] = array(gettext("IPsec"), $active_tab == "/diag_logs_ipsec.php", "diag_logs_ipsec.php"); +$tab_array[] = array(gettext("PPP"), $active_tab == "/diag_logs_ppp.php", "diag_logs_ppp.php"); +$tab_array[] = array(gettext("VPN"), $active_tab == "/diag_logs_vpn.php", "diag_logs_vpn.php"); +$tab_array[] = array(gettext("Load Balancer"), $active_tab == "/diag_logs_relayd.php", "diag_logs_relayd.php"); +$tab_array[] = array(gettext("OpenVPN"), $active_tab == "/diag_logs_openvpn.php", "diag_logs_openvpn.php"); +$tab_array[] = array(gettext("NTP"), $active_tab == "/diag_logs_ntpd.php", "diag_logs_ntpd.php"); +$tab_array[] = array(gettext("Proxy"), $active_tab == "/diag_logs_proxy.php", "diag_logs_proxy.php"); +$tab_array[] = array(gettext("Settings"), $active_tab == "/diag_logs_settings.php", "diag_logs_settings.php"); +display_top_tabs($tab_array); diff --git a/src/www/diag_logs_vpn.php b/src/www/diag_logs_vpn.php index 6ec4ff951..18e0484a5 100644 --- a/src/www/diag_logs_vpn.php +++ b/src/www/diag_logs_vpn.php @@ -66,10 +66,11 @@ switch ($vpntype) { } if ($_POST['clear']) { - if ($mode != "raw") - clear_log_file("/var/log/vpn.log"); - else - clear_log_file("/var/log/{$logname}.log"); + if ($mode != "raw") { + clear_clog("/var/log/vpn.log"); + } else { + clear_clog("/var/log/{$logname}.log"); + } } function dump_clog_vpn($logfile, $tail) { diff --git a/src/www/diag_logs_wireless.php b/src/www/diag_logs_wireless.php index 3e3de0c6b..b612de293 100644 --- a/src/www/diag_logs_wireless.php +++ b/src/www/diag_logs_wireless.php @@ -42,7 +42,7 @@ if (empty($config['syslog']['nentries'])) { } if ($_POST['clear']) { - clear_log_file($wireless_logfile); + clear_clog($wireless_logfile); } $pgtitle = array(gettext("Status"),gettext("System logs"),gettext("Wireless")); diff --git a/src/www/guiconfig.inc b/src/www/guiconfig.inc index e5eba28e0..9d64bd734 100644 --- a/src/www/guiconfig.inc +++ b/src/www/guiconfig.inc @@ -347,59 +347,121 @@ function update_changedesc($update) { $changecount++; } -function clear_log_file($logfile = '/var/log/system.log', $restart_syslogd = true) +function clear_log($logfile, $restart_syslogd = true) { - global $config, $g; - if ($restart_syslogd) - exec("/usr/bin/killall syslogd"); - if(isset($config['system']['disablesyslogclog'])) { - unlink($logfile); - touch($logfile); - } else { - $log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "511488"; - exec("/usr/local/sbin/clog -i -s {$log_size} " . escapeshellarg($logfile)); + if ($restart_syslogd) { + killbyname('syslogd'); } + + foreach (glob($logfile . '.*') as $rotated) { + @unlink($rotated); + } + + /* preserve file ownership and permissions */ + $handle = fopen($logfile, 'r+'); + if ($handle) { + ftruncate($handle, 0); + fclose($handle); + } + if ($restart_syslogd) { system_syslogd_start(); } } -function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") { - global $g, $config; - $sor = isset($config['syslog']['reverse']) ? "-r" : ""; - $logarr = ""; - $grepline = " "; - if(is_array($grepfor)) - $grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor)); - if(is_array($grepinvert)) - $grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert)); - if (is_dir($logfile)) { - $logarr = array("File $logfile is a directory."); - } elseif (file_exists($logfile) && filesize($logfile) == 0) { - $logarr = array("Log file started."); - } else { - if($config['system']['disablesyslogclog']) { - exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr); - } else { - exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr); - } +function clear_clog($logfile, $restart_syslogd = true) +{ + global $config; + + if ($restart_syslogd) { + killbyname('syslogd'); } - foreach ($logarr as $logent) { - $logent = preg_split("/\s+/", $logent, 6); - echo "\n"; - if ($withorig) { - $entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3))); - $entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " "; - $entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]); - echo "{$entry_date_time}\n"; - echo "{$entry_text}\n"; - } else { - echo "" . htmlspecialchars($logent[5]) . "\n"; - } - echo "\n"; + + $log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : '511488'; + mwexecf('/usr/local/sbin/clog -i -s %s %s', array($log_size, $logfile)); + + if ($restart_syslogd) { + system_syslogd_start(); } } +function print_dump($logarr, $withorig) +{ + global $config; + + foreach ($logarr as $logent) { + $logent = preg_split("/\s+/", $logent, 6); + echo "\n"; + if ($withorig) { + $entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3))); + $entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " "; + $entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]); + echo "{$entry_date_time}\n"; + echo "{$entry_text}\n"; + } else { + echo "" . htmlspecialchars($logent[5]) . "\n"; + } + echo "\n"; + } +} + +function dump_clog($logfile, $tail, $withorig = true, $grepfor = '', $grepinvert = '') +{ + global $config; + + $sor = isset($config['syslog']['reverse']) ? '-r' : ''; + $grepline = ' '; + $logarr = ''; + + if (is_array($grepfor)) { + $grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor)); + } + + if (is_array($grepinvert)) { + $grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert)); + } + + if (is_dir($logfile)) { + $logarr = array("File $logfile is a directory."); + } elseif (!file_exists($logfile)) { + $logarr = array("File $logfile doesn't exist."); + } elseif (filesize($logfile) == 0) { + $logarr = array("Log file started."); + } else { + exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr); + } + + print_dump($logarr, $withorig); +} + +function dump_log($logfile, $tail, $withorig = true, $grepfor = '', $grepinvert = '') +{ + global $config; + + $sor = isset($config['syslog']['reverse']) ? '-r' : ''; + $grepline = ' '; + $logarr = ''; + + if (is_array($grepfor)) { + $grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor)); + } + + if (is_array($grepinvert)) { + $grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert)); + } + + if (is_dir($logfile)) { + $logarr = array("File $logfile is a directory."); + } elseif (!file_exists($logfile)) { + $logarr = array("File $logfile doesn't exist."); + } elseif (filesize($logfile) == 0) { + $logarr = array("Log file started."); + } else { + exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr); + } + + print_dump($logarr, $withorig); +} /* Check if variable has changed, update and log if it has * returns true if var changed @@ -523,9 +585,10 @@ function is_specialnet($net) { * RESULT * null ******/ -function display_top_tabs(& $tab_array, $no_drop_down = false) { +function display_top_tabs(& $tab_array, $no_drop_down = false) +{ global $config; - global $g; + $tab_array_char_limit = 92; /* does the user have access to this tab? @@ -583,9 +646,6 @@ function display_top_tabs(& $tab_array, $no_drop_down = false) { } } - - - $timezone = $config['system']['timezone']; if (!$timezone) { $timezone = 'Etc/UTC';