Commit 6cb5788f authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) move display_host_results into log.widget.php

The widget collection needs a cleanup, but is not at the top of the priority list. Lets make sure the legacy functionality delivers output and make sure the already cleaned components stay that way.

(cherry picked from commit d4d07fbb)
parent 95aa7297
<?php <?php
/* /*
Copyright (C) 2014 Deciso B.V. Copyright (C) 2014 Deciso B.V.
Copyright (C) 2007 Scott Dale Copyright (C) 2007 Scott Dale
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net> Copyright (C) 2009 Jim Pingle (jpingle@gmail.com)
and Jonathan Watt <jwatt@jwatt.org>. Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
All rights reserved. and Jonathan Watt <jwatt@jwatt.org>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: 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. 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 2. Redistributions in binary form must reproduce the above copyright
documentation and/or other materials provided with the distribution. 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 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
POSSIBILITY OF SUCH DAMAGE. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/ */
$nocsrf = true; $nocsrf = true;
...@@ -38,15 +39,64 @@ require_once("filter_log.inc"); ...@@ -38,15 +39,64 @@ require_once("filter_log.inc");
function find_action_image($action) function find_action_image($action)
{ {
if ((strstr(strtolower($action), 'p')) || (strtolower($action) == 'rdr')) { if ((strstr(strtolower($action), 'p')) || (strtolower($action) == 'rdr')) {
return 'glyphicon glyphicon-play text-success'; return 'glyphicon glyphicon-play text-success';
} }
if (strstr(strtolower($action), 'r')) { if (strstr(strtolower($action), 'r')) {
return 'glyphicon glyphicon-remove text-warning'; return 'glyphicon glyphicon-remove text-warning';
} }
return 'glyphicon glyphicon-remove text-danger'; 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;
} }
...@@ -85,7 +135,6 @@ if (is_numeric($_POST['filterlogentries'])) { ...@@ -85,7 +135,6 @@ if (is_numeric($_POST['filterlogentries'])) {
$nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5; $nentries = isset($config['widgets']['filterlogentries']) ? $config['widgets']['filterlogentries'] : 5;
//set variables for log //set variables for log
$nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All'; $nentriesacts = isset($config['widgets']['filterlogentriesacts']) ? $config['widgets']['filterlogentriesacts'] : 'All';
$nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All'; $nentriesinterfaces = isset($config['widgets']['filterlogentriesinterfaces']) ? $config['widgets']['filterlogentriesinterfaces'] : 'All';
...@@ -122,22 +171,22 @@ if (isset($config['syslog']['reverse'])) { ...@@ -122,22 +171,22 @@ if (isset($config['syslog']['reverse'])) {
/* Called by the AJAX updater */ /* Called by the AJAX updater */
function format_log_line(row) { function format_log_line(row) {
var line = '<td class="listMRlr" align="center">' + row[0] + '<\/td>' + var line = '<td class="listMRlr" align="center">' + row[0] + '<\/td>' +
'<td class="listMRr ellipsis" title="' + row[1] + '">' + row[1].slice(0,-3) + '<\/td>' + '<td class="listMRr ellipsis" title="' + row[1] + '">' + row[1].slice(0,-3) + '<\/td>' +
'<td class="listMRr ellipsis" title="' + row[2] + '">' + row[2] + '<\/td>' + '<td class="listMRr ellipsis" title="' + row[2] + '">' + row[2] + '<\/td>' +
'<td class="listMRr ellipsis" title="' + row[3] + '">' + row[3] + '<\/td>' + '<td class="listMRr ellipsis" title="' + row[3] + '">' + row[3] + '<\/td>' +
'<td class="listMRr ellipsis" title="' + row[4] + '">' + row[4] + '<\/td>'; '<td class="listMRr ellipsis" title="' + row[4] + '">' + row[4] + '<\/td>';
var nentriesacts = "<?php echo $nentriesacts; ?>"; var nentriesacts = "<?php echo $nentriesacts; ?>";
var nentriesinterfaces = "<?php echo $nentriesinterfaces; ?>"; var nentriesinterfaces = "<?php echo $nentriesinterfaces; ?>";
var Action = row[0].match(/alt=.*?(pass|block|reject)/i).join("").match(/pass|block|reject/i).join(""); var Action = row[0].match(/alt=.*?(pass|block|reject)/i).join("").match(/pass|block|reject/i).join("");
var Interface = row[2]; var Interface = row[2];
if ( !(in_arrayi(Action, nentriesacts.replace (/\s+/g, ',').split(',') ) ) && (nentriesacts != 'All') ) return false; if ( !(in_arrayi(Action, nentriesacts.replace (/\s+/g, ',').split(',') ) ) && (nentriesacts != 'All') ) return false;
if ( !(in_arrayi(Interface, nentriesinterfaces.replace(/\s+/g, ',').split(',') ) ) && (nentriesinterfaces != 'All') ) return false; if ( !(in_arrayi(Interface, nentriesinterfaces.replace(/\s+/g, ',').split(',') ) ) && (nentriesinterfaces != 'All') ) return false;
return line; return line;
} }
//]]> //]]>
</script> </script>
...@@ -145,55 +194,55 @@ function format_log_line(row) { ...@@ -145,55 +194,55 @@ function format_log_line(row) {
<input type="hidden" id="log-config" name="log-config" value="" /> <input type="hidden" id="log-config" name="log-config" value="" />
<div id="log-settings" class="widgetconfigdiv" style="display:none;"> <div id="log-settings" class="widgetconfigdiv" style="display:none;">
<form action="/widgets/widgets/log.widget.php" method="post" name="iforma"> <form action="/widgets/widgets/log.widget.php" method="post" name="iforma">
<table class="table table-striped"> <table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
<td> <td>
<?= gettext('Number of lines to display:') ?> <?= gettext('Number of lines to display:') ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<select name="filterlogentries" class="formfld unknown" id="filterlogentries"> <select name="filterlogentries" class="formfld unknown" id="filterlogentries">
<?php for ($i = 1; $i <= 20; $i++) { <?php for ($i = 1; $i <= 20; $i++) {
?> ?>
<option value="<?php echo $i;?>" <?php if ($nentries == $i) { <option value="<?php echo $i;?>" <?php if ($nentries == $i) {
echo "selected=\"selected\""; echo "selected=\"selected\"";
}?>><?php echo $i;?></option> }?>><?php echo $i;?></option>
<?php <?php
} ?> } ?>
</select> </select>
</td> </td>
</tr> </tr>
<?php <?php
$Include_Act = explode(" ", $nentriesacts); $Include_Act = explode(" ", $nentriesacts);
if ($nentriesinterfaces == "All") { if ($nentriesinterfaces == "All") {
$nentriesinterfaces = ""; $nentriesinterfaces = "";
} }
?> ?>
<tr> <tr>
<td> <td>
<input id="actpass" name="actpass" type="checkbox" value="Pass" <?php if (in_arrayi('Pass', $Include_Act)) { <input id="actpass" name="actpass" type="checkbox" value="Pass" <?php if (in_arrayi('Pass', $Include_Act)) {
echo "checked=\"checked\""; echo "checked=\"checked\"";
} ?> /> Pass } ?> /> Pass
<input id="actblock" name="actblock" type="checkbox" value="Block" <?php if (in_arrayi('Block', $Include_Act)) { <input id="actblock" name="actblock" type="checkbox" value="Block" <?php if (in_arrayi('Block', $Include_Act)) {
echo "checked=\"checked\""; echo "checked=\"checked\"";
} ?> /> Block } ?> /> Block
<input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) { <input id="actreject" name="actreject" type="checkbox" value="Reject" <?php if (in_arrayi('Reject', $Include_Act)) {
echo "checked=\"checked\""; echo "checked=\"checked\"";
} ?> /> Reject } ?> /> Reject
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<?= gettext('Interfaces:'); ?> <?= gettext('Interfaces:'); ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<select id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formselect"> <select id="filterlogentriesinterfaces" name="filterlogentriesinterfaces" class="formselect">
<option value="All"><?= gettext('ALL') ?></option> <option value="All"><?= gettext('ALL') ?></option>
<?php <?php
$interfaces = get_configured_interface_with_descr(); $interfaces = get_configured_interface_with_descr();
foreach ($interfaces as $iface => $ifacename) : foreach ($interfaces as $iface => $ifacename) :
...@@ -208,76 +257,76 @@ endforeach; ...@@ -208,76 +257,76 @@ endforeach;
unset($interfaces); unset($interfaces);
unset($Include_Act); unset($Include_Act);
?> ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input id="submita" name="submita" type="submit" class="btn btn-primary formbtn" value="<?= gettext('Save') ?>" /> <input id="submita" name="submita" type="submit" class="btn btn-primary formbtn" value="<?= gettext('Save') ?>" />
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
</div> </div>
<table class="table table-striped" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;" summary="logs"> <table class="table table-striped" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed;" summary="logs">
<colgroup> <colgroup>
<col style='width: 7%;' /> <col style='width: 7%;' />
<col style='width: 23%;' /> <col style='width: 23%;' />
<col style='width: 11%;' /> <col style='width: 11%;' />
<col style='width: 28%;' /> <col style='width: 28%;' />
<col style='width: 31%;' /> <col style='width: 31%;' />
</colgroup> </colgroup>
<thead> <thead>
<tr> <tr>
<td class="listhdrr"><?=gettext("Act");?></td> <td class="listhdrr"><?=gettext("Act");?></td>
<td class="listhdrr"><?=gettext("Time");?></td> <td class="listhdrr"><?=gettext("Time");?></td>
<td class="listhdrr"><?=gettext("IF");?></td> <td class="listhdrr"><?=gettext("IF");?></td>
<td class="listhdrr"><?=gettext("Source");?></td> <td class="listhdrr"><?=gettext("Source");?></td>
<td class="listhdrr"><?=gettext("Destination");?></td> <td class="listhdrr"><?=gettext("Destination");?></td>
</tr> </tr>
</thead> </thead>
<tbody id='filter-log-entries'> <tbody id='filter-log-entries'>
<?php <?php
$rowIndex = 0; $rowIndex = 0;
foreach ($filterlog as $filterent) : foreach ($filterlog as $filterent) :
$evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd"; $evenRowClass = $rowIndex % 2 ? " listMReven" : " listMRodd";
$rowIndex++; $rowIndex++;
?> ?>
<tr class="<?=$evenRowClass?>"> <tr class="<?=$evenRowClass?>">
<td class="listMRlr nowrap" align="center"> <td class="listMRlr nowrap" align="center">
<a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);"> <a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);">
<span class="<?php echo find_action_image($filterent['act']);?>" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" ></span> <span class="<?php echo find_action_image($filterent['act']);?>" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" ></span>
</a> </a>
</td> </td>
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['time']);?>"><?php echo substr(htmlspecialchars($filterent['time']), 0, -3);?></td> <td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['time']);?>"><?php echo substr(htmlspecialchars($filterent['time']), 0, -3);?></td>
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['interface']);?>"><?php echo htmlspecialchars($filterent['interface']);?></td> <td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['interface']);?>"><?php echo htmlspecialchars($filterent['interface']);?></td>
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['src']);?>"> <td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['src']);?>">
<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['srcip']}"; <a href="#" onclick="javascript:getURL('widgets/widgets/log.widget.php?host=<?php echo "{$filterent['srcip']}";
?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>"> ?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
<?php echo htmlspecialchars($filterent['srcip']);?></a></td> <?php echo htmlspecialchars($filterent['srcip']);?></a></td>
<td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['dst']);?>"> <td class="listMRr ellipsis nowrap" title="<?php echo htmlspecialchars($filterent['dst']);?>">
<a href="#" onclick="javascript:getURL('diag_dns.php?host=<?php echo "{$filterent['dstip']}"; <a href="#" onclick="javascript:getURL('widgets/widgets/log.widget.php?host=<?php echo "{$filterent['dstip']}";
?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>"> ?>&amp;dialog_output=true', outputrule);" title="<?=gettext("Reverse Resolve with DNS");?>">
<?php echo htmlspecialchars($filterent['dstip']);?></a><?php echo ":" . htmlspecialchars($filterent['dstport']);?></td> <?php echo htmlspecialchars($filterent['dstip']);?></a><?php echo ":" . htmlspecialchars($filterent['dstport']);?></td>
<?php <?php
if ($filterent['proto'] == "TCP") { if ($filterent['proto'] == "TCP") {
$filterent['proto'] .= ":{$filterent['tcpflags']}"; $filterent['proto'] .= ":{$filterent['tcpflags']}";
} }
?> ?>
</tr> </tr>
<?php <?php
endforeach; ?> endforeach; ?>
<tr style="display:none;"><td></td></tr> <tr style="display:none;"><td></td></tr>
</tbody> </tbody>
</table> </table>
<!-- needed to display the widget settings menu --> <!-- needed to display the widget settings menu -->
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
selectIntLink = "log-configure"; selectIntLink = "log-configure";
textlink = document.getElementById(selectIntLink); textlink = document.getElementById(selectIntLink);
textlink.style.display = "inline"; textlink.style.display = "inline";
//]]> //]]>
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment