From 26cb04d56f271313be6e2f0e8ef55bb9458a5f6a Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 6 Nov 2017 22:22:19 +0100 Subject: [PATCH] firewall live log, trash old dynamic view and refactor log widget to use the same service call. for https://github.com/opnsense/core/issues/1788 --- src/www/diag_logs_filter_dynamic.php | 166 ----------- src/www/widgets/widgets/log.widget.php | 366 ++++++++++--------------- 2 files changed, 141 insertions(+), 391 deletions(-) delete mode 100644 src/www/diag_logs_filter_dynamic.php diff --git a/src/www/diag_logs_filter_dynamic.php b/src/www/diag_logs_filter_dynamic.php deleted file mode 100644 index 17f318495..000000000 --- a/src/www/diag_logs_filter_dynamic.php +++ /dev/null @@ -1,166 +0,0 @@ - - Copyright (C) 2003-2004 Manuel Kasper . - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ - -require_once("guiconfig.inc"); -require_once("filter_log.inc"); -require_once("system.inc"); -require_once("interfaces.inc"); - -$filter_logfile = '/var/log/filter.log'; - -/* Hardcode this. AJAX doesn't do so well with large numbers */ -$nentries = 50; - -/* AJAX related routines */ -handle_ajax($nentries, $nentries + 20); - -if (isset($_POST['clear'])) { - system_clear_clog($filter_logfile); -} - -$filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100); - -include("head.inc"); - -?> - - - - -
-
-
- - 0) print_input_errors($input_errors); ?> -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-   - -
-
- " /> -   -
-
-
- ', outputrule);" title=""> - "> - - -
-
-
-
-
-
-
- - diff --git a/src/www/widgets/widgets/log.widget.php b/src/www/widgets/widgets/log.widget.php index dd4c4b2bd..eb15709e7 100644 --- a/src/www/widgets/widgets/log.widget.php +++ b/src/www/widgets/widgets/log.widget.php @@ -33,70 +33,6 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); -require_once("filter_log.inc"); - -function find_action_image($action) -{ - if ((strstr(strtolower($action), 'p')) || (strtolower($action) == 'rdr')) { - return 'glyphicon glyphicon-play text-success'; - } - - if (strstr(strtolower($action), 'r')) { - return 'glyphicon glyphicon-remove text-warning'; - } - - return 'glyphicon glyphicon-remove text-danger'; -} - -/** - * original from diag_dns.php - * temporary solution. - */ -function display_host_results ($address,$hostname,$dns_speeds) { - $map_lengths = function($element) { return strlen($element[0]); }; - echo gettext("IP Address") . ": {$address} \n"; - echo gettext("Host Name") . ": {$hostname} \n"; - echo "\n"; - $text_table = array(); - $text_table[] = array(gettext("Server"), gettext("Query Time")); - if (is_array($dns_speeds)) { - foreach ($dns_speeds as $qt) { - $text_table[] = array(trim($qt['dns_server']), trim($qt['query_time'])); - } - } - $col0_padlength = max(array_map($map_lengths, $text_table)) + 4; - foreach ($text_table as $text_row) { - echo str_pad($text_row[0], $col0_padlength) . $text_row[1] . "\n"; - } -} - -if (!empty($_GET['host']) && !empty($_GET['dialog_output'])) { - $host = trim($_GET['host'], " \t\n\r\0\x0B[];\"'"); - $host_esc = escapeshellarg($host); - $dns_servers = array(); - exec("/usr/bin/grep nameserver /etc/resolv.conf | /usr/bin/cut -f2 -d' '", $dns_servers); - foreach ($dns_servers as $dns_server) { - $query_time = exec("/usr/bin/drill {$host_esc} " . escapeshellarg("@" . trim($dns_server)) . " | /usr/bin/grep Query | /usr/bin/cut -d':' -f2"); - if ($query_time == "") { - $query_time = gettext("No response"); - } - $dns_speeds[] = array('dns_server' => $dns_server, 'query_time' => $query_time); - } - $ipaddr = ""; - if (count($input_errors) == 0) { - if (is_ipaddr($host)) { - $resolved[] = " " . gethostbyaddr($host); // add a space to provide an empty type field - $ipaddr = $host; - } elseif (is_hostname($host)) { - exec("/usr/bin/drill {$host_esc} A | /usr/bin/grep 'IN' | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $4 \" \" $5 }'", $resolved); - $ipaddr = explode(" ", $resolved[count($resolved)-1])[1]; - } - } - - display_host_results ($host, $resolved[0], $dns_speeds); - exit; -} - if (is_numeric($_POST['filterlogentries'])) { $config['widgets']['filterlogentries'] = $_POST['filterlogentries']; @@ -117,9 +53,8 @@ if (is_numeric($_POST['filterlogentries'])) { } else { unset($config['widgets']['filterlogentriesacts']); } - unset($acts); - if (($_POST['filterlogentriesinterfaces']) and ($_POST['filterlogentriesinterfaces'] != "All")) { + if (($_POST['filterlogentriesinterfaces']) && ($_POST['filterlogentriesinterfaces'] != "All")) { $config['widgets']['filterlogentriesinterfaces'] = trim($_POST['filterlogentriesinterfaces']); } else { unset($config['widgets']['filterlogentriesinterfaces']); @@ -133,188 +68,169 @@ if (is_numeric($_POST['filterlogentries'])) { $nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5; //set variables for log -$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All'; +$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? explode(" ", $config['widgets']['filterlogentriesacts']) : array('All'); $nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All'; - -$filterfieldsarray = array( - "act" => $nentriesacts, - "interface" => $nentriesinterfaces -); - -$filter_logfile = '/var/log/filter.log'; -$filterlog = conv_log_filter($filter_logfile, $nentries, 50, $filterfieldsarray); - -/* AJAX related routines */ -handle_ajax($nentries, $nentries + 20); - ?> - - +
- - - - - + + + + + - - - - - - - - - - - - + +
- ', outputrule);"> - - - - - - : -
- - -