#!/usr/local/bin/php
.
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.
*/
$pgtitle = array("Diagnostics", "Logs");
require("guiconfig.inc");
$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPv6 IGMP any");
$nentries = $config['syslog']['nentries'];
$resolve = isset($config['syslog']['resolve']);
if (!$nentries)
$nentries = 50;
if ($_POST['clear']) {
exec("/usr/sbin/clog -i -s 262144 /var/log/filter.log");
/* redirect to avoid reposting form data on refresh */
header("Location: diag_logs_filter.php");
exit;
}
if (isset($_GET['act']) && preg_match("/^[pb]+$/", $_GET['act'])) {
$action = $_GET['act'];
$ifstring .= "&act=" . urlencode($action);
$srcstring .= "&act=" . urlencode($action);
$dststring .= "&act=" . urlencode($action);
$prstring .= "&act=" . urlencode($action);
}
if (isset($_GET['if']) && ($_GET['if'] != "")) {
$iface = $_GET['if'];
$actstring .= "&if=" . urlencode($iface);
$srcstring .= "&if=" . urlencode($iface);
$dststring .= "&if=" . urlencode($iface);
$prstring .= "&if=" . urlencode($iface);
}
if (isset($_GET['pr']) && in_array($_GET['pr'], $protocols)) {
$proto = $_GET['pr'];
$actstring .= "&pr=" . urlencode($proto);
$ifstring .= "&pr=" . urlencode($proto);
$srcstring .= "&pr=" . urlencode($proto);
$dststring .= "&pr=" . urlencode($proto);
}
if (isset($_GET['sp']) && (is_numeric($_GET['sp']))) {
$srcport = $_GET['sp'];
$actstring .= "&sp=" . urlencode($srcport);
$ifstring .= "&sp=" . urlencode($srcport);
$dststring .= "&sp=" . urlencode($srcport);
$prstring .= "&sp=" . urlencode($srcport);
}
if (isset($_GET['dp']) && (is_numeric($_GET['dp']))) {
$dstport = $_GET['dp'];
$actstring .= "&dp=" . urlencode($dstport);
$ifstring .= "&dp=" . urlencode($dstport);
$srcstring .= "&dp=" . urlencode($dstport);
$prstring .= "&dp=" . urlencode($dstport);
}
function dump_clog($logfile, $tail, $withorig = true) {
global $g, $config;
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
exec("/usr/sbin/clog " . $logfile . " | tail {$sor} -n " . $tail, $logarr);
foreach ($logarr as $logent) {
$logent = preg_split("/\s+/", $logent, 6);
echo "
\n";
if ($withorig) {
echo "" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . " | \n";
echo "" . htmlspecialchars($logent[4] . " " . $logent[5]) . " | \n";
} else {
echo "" . htmlspecialchars($logent[5]) . " | \n";
}
echo "
\n";
}
}
function conv_clog($logfile, $tail) {
global $g, $config, $iface, $action, $proto, $srcport, $dstport;
/* make interface/port table */
$iftable = array();
$iftable[$config['interfaces']['lan']['if']] = "LAN";
$iftable[get_real_wan_interface()] = "WAN";
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++)
$iftable[$config['interfaces']['opt' . $i]['if']] = $config['interfaces']['opt' . $i]['descr'];
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
exec("/usr/sbin/clog " . $logfile . " | tail {$sor} -n " . $tail, $logarr);
$filterlog = array();
foreach ($logarr as $logent) {
$logent = preg_split("/\s+/", $logent, 6);
$ipfa = explode(" ", $logent[5]);
$flent = array();
$i = 0;
$flent['time'] = $ipfa[$i];
$i++;
if (substr($ipfa[$i], -1) == "x") {
$flent['count'] = substr($ipfa[$i], 0, -1);
$i++;
}
if ($iftable[$ipfa[$i]])
$flent['interface'] = $iftable[$ipfa[$i]];
else if (strpos($ipfa[$i], "ng") !== false)
$flent['interface'] = "PPTP";
else if (strpos($ipfa[$i], "l2tp") !== false)
$flent['interface'] = "L2TP";
else if ($ipfa[$i] == "enc0")
$flent['interface'] = "IPsec";
else if ($ipfa[$i] == "gif0")
$flent['interface'] = "WAN";
else if ($ipfa[$i] == "stf0")
$flent['interface'] = "WAN";
else
$flent['interface'] = $ipfa[$i];
if (isset($iface)) {
if ($iface != $flent['interface'])
continue;
}
$i += 2;
if (!isset($action) || strstr($action, $ipfa[$i]))
$flent['act'] = $ipfa[$i];
else
continue;
$i++;
list($flent['src'], $flent['srcport']) = format_ipf_ip($ipfa[$i],$srcport);
if (!isset($flent['src']))
continue;
$i += 2;
list($flent['dst'], $flent['dstport']) = format_ipf_ip($ipfa[$i],$dstport);
if (!isset($flent['dst']))
continue;
$i += 2;
$protocol = strtoupper($ipfa[$i]);
if (!isset($proto) || ($proto == $protocol))
$flent['proto'] = $protocol;
else
continue;
if ($protocol == "ICMP") {
$i += 5;
$flent['dst'] = $flent['dst'] . ", type " . $ipfa[$i];
}
$filterlog[] = $flent;
}
return $filterlog;
}
function format_ipf_ip($ipfip,$uport) {
global $resolve;
list($ip,$port) = explode(",", $ipfip);
if ($resolve) {
if (!$port)
return array(gethostbyaddr($ip), "");
if ($uport == "" || ($uport == $port))
return array(gethostbyaddr($ip) . ", port " . $port, $port);
return;
}
if (!$port)
return array($ip, "");
if ($uport == "" || ($uport == $port))
return array($ip . ", port " . $port, $port);
return;
}
?>
'diag_logs.php',
'Firewall' => 'diag_logs_filter.php',
'DHCP' => 'diag_logs_dhcp.php',
'Captive portal' => 'diag_logs_portal.php',
'PPTP/L2TP VPN' => 'diag_logs_vpn.php',
'Settings' => 'diag_logs_settings.php');
dynamic_tab_menu($tabs);
?>
|
Last =$nentries;?> firewall log entries |
|