From 5c84ce30d6437917358fdeef632d0a59391f599b Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 12 Aug 2015 04:04:59 +0200 Subject: diag_new_states - code style fixes Fix copyright header, indentation, permissions, remove useless stuff. --- config/diag_states_pt/diag_new_states.xml | 78 ++++++++++++++----------------- 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/config/diag_states_pt/diag_new_states.xml b/config/diag_states_pt/diag_new_states.xml index 0e4e6c7d..849c4b55 100644 --- a/config/diag_states_pt/diag_new_states.xml +++ b/config/diag_states_pt/diag_new_states.xml @@ -2,51 +2,47 @@ - - +. - All rights reserved. - */ -/* ========================================================================== */ + diag_new_states.xml + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2002 Paul Taylor + Copyright (C) 2015 ESF, LLC + 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 + documentation and/or other materials provided with the distribution. - 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. - */ -/* ========================================================================== */ - ]]> - - Describe your package here - Describe your package requirements here - Currently there are no FAQ items provided. + 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. +*/ +/* ====================================================================================== */ + ]]> + diag_new_states - 0.2 + 0.3 Diagnostics: States New States New @@ -55,11 +51,7 @@ diag_new_states.php - /usr/local/www/ - 0755 + /usr/local/www/ https://packages.pfsense.org/packages/config/diag_states_pt/diag_new_states.php - - mwexec("rm /usr/local/www/diag_new_states.php"); - -- cgit v1.2.3 From 3496edaf0bd97490d7d6e1640da6a53453842a0d Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 12 Aug 2015 04:08:43 +0200 Subject: diag_new_states - code style fixes - Fix copyright header - Code style - Fix indentation - Fix XHTML validation --- config/diag_states_pt/diag_new_states.php | 360 +++++++++++++++--------------- 1 file changed, 175 insertions(+), 185 deletions(-) diff --git a/config/diag_states_pt/diag_new_states.php b/config/diag_states_pt/diag_new_states.php index d187068f..8c82ca4d 100644 --- a/config/diag_states_pt/diag_new_states.php +++ b/config/diag_states_pt/diag_new_states.php @@ -1,43 +1,35 @@ = 6) - $pgtitle = array("Diagnostics", "Show States"); -else - $pgtitle = "Diagnostics: Show States"; - -/* put your custom HTML head content here */ -/* using some of the $pfSenseHead function calls */ - function displayIP($ip, $col) { global $viewPassThru; @@ -55,10 +47,10 @@ function displayIP($ip, $col) { case 'dstip': if ($_GET['dfilter']) { - if ($_GET['dfilter'] == $ip) + if ($_GET['dfilter'] == $ip) { return $ip; - } - else { + } + } else { return ''. $ip .''; } break; @@ -69,32 +61,34 @@ function displayIP($ip, $col) { function sortOrder($column) { if ($_GET['order'] == $column) { - if ($_GET['sort'] == 'des') - return "&sort=asc"; - return "&sort=des"; + if ($_GET['sort'] == 'des') { + return "&sort=asc"; + } + return "&sort=des"; + } else { + return "&sort=asc"; } - else - return "&sort=asc"; } +// FIXME: Needs changes to handle IPv6 addresses properly function stripPort($ip, $showPort = false) { if (!$showPort) { - if (strpos($ip,':') > 0) - return substr($ip,0,strpos($ip,":")); - else + if (strpos($ip, ':') > 0) { + return substr($ip, 0, strpos($ip, ":")); + } else { return ($ip); - } - else { - if (strpos($ip,':') > 0) { - return substr($ip,(strpos($ip,":")+1)); } - else + } else { + if (strpos($ip, ':') > 0) { + return substr($ip, (strpos($ip, ":")+1)); + } else { return " "; + } } } // sfilter and dfilter allow setting of source and dest IP filters -// on the output. $filterPassThru allows these source and dest +// on the output. $filterPassThru allows these source and dest // filters to be passed on in the column sorting links. if (($_GET['sfilter']) or ($_GET['dfilter'])) { @@ -102,18 +96,18 @@ if (($_GET['sfilter']) or ($_GET['dfilter'])) { if ($_GET['sfilter']) { if (is_ipaddr($_GET['sfilter'])) { $sfilter = $_GET['sfilter']; - $filterPassThru = '&sfilter=' . $_GET['sfilter']; - } - else + $filterPassThru = '&sfilter=' . $_GET['sfilter']; + } else { unset ($_GET['sfilter']); + } } if ($_GET['dfilter']) { if (is_ipaddr($_GET['dfilter'])) { $dfilter = $_GET['dfilter']; - $filterPassThru = '&dfilter=' . $_GET['dfilter']; - } - else + $filterPassThru = '&dfilter=' . $_GET['dfilter']; + } else { unset ($_GET['dfilter']); + } } } @@ -129,28 +123,29 @@ $rawdata = array(); // [5] => tcp I 192.168.111.99:61221 192.168.111.150:22 4:4 710 86399 726 242K // -w 132 sets width of data to 132 // $dataRows defaults to 300 for embedded hardware -exec("echo q | /usr/local/sbin/pftop -w 132 $dataRows",$rawdata); +exec("echo q | /usr/local/sbin/pftop -w 132 $dataRows", $rawdata); -// exporting TERM set to nothing gets you a "dumb" term. echo q to pftop makes it +// exporting TERM set to nothing gets you a "dumb" term. echo q to pftop makes it // quit out after displaying the first page of data. // Get top line with total state data $topDataLine = $rawdata[2]; //pfTop: Up State 1-5/5, View: default, Order: none -$slashPos = strpos($topDataLine,'/') + 1; -$commaPos = strpos($topDataLine,','); +$slashPos = strpos($topDataLine, '/') + 1; +$commaPos = strpos($topDataLine, ','); if (($slashPos > 1) and ($commaPos > 1)) { - $totalStates = substr($topDataLine,$slashPos,($commaPos - $slashPos)); -} else $totalStates = 0; + $totalStates = substr($topDataLine, $slashPos, ($commaPos - $slashPos)); +} else { + $totalStates = 0; +} // Get rid of the header data -unset($rawdata[0],$rawdata[1],$rawdata[2],$rawdata[3]); +unset($rawdata[0], $rawdata[1], $rawdata[2], $rawdata[3]); if (isset($rawdata)) { $count = 0; foreach ($rawdata as $line) { - if (!strlen(trim($line)) < 70) - { + if (!strlen(trim($line)) < 70) { //PR DIR SRC DEST STATE AGE EXP PKTS BYTES //tcp Out 192.168.111.99:62831 66.84.12.81:110 FIN_WAIT_2:FIN_WAIT_2 00:01:20 00:00:11 28 1933 // 0 1 2 3 4 5 6 7 8 @@ -160,23 +155,24 @@ if (isset($rawdata)) { $data[$count]['dir'] = strtolower($split[1]); $srcTmp = $split[2]; $data[$count]['srcip'] = stripPort($srcTmp); - $data[$count]['srcport'] = stripPort($srcTmp,true); + $data[$count]['srcport'] = stripPort($srcTmp, true); $dstTmp = $split[3]; $data[$count]['expire'] = $split[6]; $data[$count]['dstip'] = stripPort($dstTmp); - $data[$count]['dstport'] = stripPort($dstTmp,true); + $data[$count]['dstport'] = stripPort($dstTmp, true); $data[$count]['packets'] = $split[7]; $data[$count]['bytes'] = $split[8]; $count++; } } // Clear the statistics snapshot files, which track the packets and bytes of connections - if (isset($_GET['clear'])) - { - if (file_exists('/tmp/packets')) + if (isset($_GET['clear'])) { + if (file_exists('/tmp/packets')) { unlink('/tmp/packets'); - if (file_exists('/tmp/bytes')) + } + if (file_exists('/tmp/bytes')) { unlink('/tmp/bytes'); + } // Redirect so we don't hit "clear" every time we refresh the screen. header("Location: diag_new_states.php?".$filterPassThru); @@ -184,8 +180,7 @@ if (isset($rawdata)) { } // Create a new set of stats snapshot files - if (isset($_GET['new'])) - { + if (isset($_GET['new'])) { $packets = array(); $bytes = array(); @@ -198,36 +193,33 @@ if (isset($rawdata)) { } // Write the files out - writeStats("packets",$packets); - writeStats("bytes",$bytes); + writeStats("packets", $packets); + writeStats("bytes", $bytes); // If we're in view mode, pass that on. - if (isset($_GET['view'])) - $filterPassThru .= "&view=1"; + if (isset($_GET['view'])) { + $filterPassThru .= "&view=1"; + } // Redirect so we don't hit "new" every time we refresh the screen. - header("Location: diag_new_states.php?&order=bytes&sort=des".$filterPassThru); + header("Location: diag_new_states.php?&order=bytes&sort=des".$filterPassThru); exit; } // View the delta from the last snapshot against the current data. - if (isset($_GET['view'])) - { + if (isset($_GET['view'])) { // Read the stats data files - readStats("packets",$packets); - readStats("bytes",$bytes); + readStats("packets", $packets); + readStats("bytes", $bytes); if (is_array($data)) { foreach ($data as $key => $row) { - if (isset($packets[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']])) - { - if (isset($bytes[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']])) - { + if (isset($packets[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']])) { + if (isset($bytes[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']])) { $tempPackets = $data[$key]['packets'] - $packets[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']]; $tempBytes = $data[$key]['bytes'] - $bytes[$row['srcip']][$row['srcport']][$row['dstip']][$row['dstport']][$row['protocol']]; - if (($tempPackets > -1) && ($tempBytes > -1)) - { + if (($tempPackets > -1) && ($tempBytes > -1)) { $data[$key]['packets'] = $tempPackets; $data[$key]['bytes'] = $tempBytes; } @@ -237,51 +229,48 @@ if (isset($rawdata)) { } } - $filterPassThru .= "&view=1"; - $viewPassThru = "&view=1"; + $filterPassThru .= "&view=1"; + $viewPassThru = "&view=1"; } // Sort it by the selected order if ($_GET['order']) { - natsort2d($data,$_GET['order']); - if ($_GET['sort']) - { - if ($_GET['sort'] == "des") - $data = array_reverse($data); + natsort2d($data, $_GET['order']); + if ($_GET['sort']) { + if ($_GET['sort'] == "des") { + $data = array_reverse($data); + } } } } -function natsort2d( &$arrIn, $index = null ) -{ - - $arrTemp = array(); - $arrOut = array(); +function natsort2d( &$arrIn, $index = null ) { - if (is_array($arrIn)) { - foreach ( $arrIn as $key=>$value ) { + $arrTemp = array(); + $arrOut = array(); - reset($value); - $arrTemp[$key] = is_null($index) - ? current($value) - : $value[$index]; - } - } + if (is_array($arrIn)) { + foreach ( $arrIn as $key=>$value ) { + reset($value); + $arrTemp[$key] = is_null($index) ? current($value) : $value[$index]; + } + } - natsort($arrTemp); + natsort($arrTemp); - foreach ( $arrTemp as $key=>$value ) { - $arrOut[$key] = $arrIn[$key]; - } + foreach ( $arrTemp as $key=>$value ) { + $arrOut[$key] = $arrIn[$key]; + } - $arrIn = $arrOut; + $arrIn = $arrOut; } function writeStats($fname, &$data) { $fname = "/tmp/" . $fname; - if (file_exists($fname)) + if (file_exists($fname)) { unlink($fname); + } $file = fopen($fname, 'a'); fwrite($file, serialize($data)); fclose($file); @@ -289,8 +278,7 @@ function writeStats($fname, &$data) { function readStats($fname, &$data) { $fname = "/tmp/" . $fname; - if (file_exists($fname)) - { + if (file_exists($fname)) { $file = fopen($fname,'r'); $data = unserialize(fread($file, filesize($fname))); fclose($file); @@ -300,11 +288,11 @@ function readStats($fname, &$data) { // Get timestamp of snapshot file, if it exists, for display later. if (!(file_exists('/tmp/packets'))) { $lastSnapshot = "Never"; -} -else { +} else { $lastSnapshot = strftime("%m/%d/%y %H:%M:%S",filectime('/tmp/packets')); } // The next include must be here because we use redirection above +$pgtitle = "Diagnostics: Show States"; include("head.inc"); ?> @@ -315,75 +303,77 @@ include("head.inc"); -' . $pgtitle . '

'; -?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Statistics snapshot control
View deltaStart newClear snapshotLast statistics snapshot: Start newClearViewing delta of statistics snapshot: Start newLast statistics snapshot:
 
SourcePortDirDestinationPortProtocolPacketsBytesExpires
Statistics snapshot control
View deltaStart newClear snapshotLast statistics snapshot: Start newClearViewing delta of statistics snapshot: Start newLast statistics snapshot:
 
SourcePortDirDestinationPortProtocolPacketsBytesExpires
-
Firewall connection states displayed: / +
Firewall connection states displayed: / -

-

- - - -
-

+
+
+ +
+ +
+
-- cgit v1.2.3 From 31aed79f558e1bfc5b5c4eb075838f057b9fbdb1 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 12 Aug 2015 04:11:06 +0200 Subject: Bump diag_new_states package version --- pkg_config.10.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg_config.10.xml b/pkg_config.10.xml index c66d2b96..8adcaca4 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -832,7 +832,7 @@ diag_new_states Paul Taylor's version of Diagnostics States which utilizes pftop. Network Management - 0.2 + 0.3 ptaylor@addressplus.net 2.2 BETA -- cgit v1.2.3 From 27562d6eef959b08d16ef6e9b44e32e5df6cd793 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 12 Aug 2015 10:13:19 +0200 Subject: diag_new_states - code style fixes Fix indentation and bunch of missing spaces between function arguments. --- config/diag_states_pt/diag_new_states.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/diag_states_pt/diag_new_states.php b/config/diag_states_pt/diag_new_states.php index 8c82ca4d..00b22e33 100644 --- a/config/diag_states_pt/diag_new_states.php +++ b/config/diag_states_pt/diag_new_states.php @@ -279,7 +279,7 @@ function writeStats($fname, &$data) { function readStats($fname, &$data) { $fname = "/tmp/" . $fname; if (file_exists($fname)) { - $file = fopen($fname,'r'); + $file = fopen($fname, 'r'); $data = unserialize(fread($file, filesize($fname))); fclose($file); } @@ -346,12 +346,12 @@ include("head.inc"); if ((!isset($sfilter) && (!isset($dfilter))) || ((isset($sfilter)) && ($entry['srcip'] == $sfilter)) || ((isset($dfilter)) && ($entry['dstip'] == $dfilter))) { - ?> + ?> - + - + -- cgit v1.2.3