From 1953a3751b3cea2305239e3cb3f0c69c8ce6c770 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 10:07:02 +0100 Subject: [PATCH 1/8] Add a description field to work around Bug #7178 --- net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml index ecff1d00fd98..0b9c638fdd51 100644 --- a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml +++ b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml @@ -56,6 +56,7 @@ Enable darkstat enable checkbox + Check to enable darkstat. Capture Interfaces From acdd78af5a304fc6080f5d2bf507b0f777673434 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 10:08:02 +0100 Subject: [PATCH 2/8] Bump port revision --- net-mgmt/pfSense-pkg-darkstat/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/net-mgmt/pfSense-pkg-darkstat/Makefile b/net-mgmt/pfSense-pkg-darkstat/Makefile index fe83d18eefd4..8ddb5b035fc6 100644 --- a/net-mgmt/pfSense-pkg-darkstat/Makefile +++ b/net-mgmt/pfSense-pkg-darkstat/Makefile @@ -2,6 +2,7 @@ PORTNAME= pfSense-pkg-darkstat PORTVERSION= 3.1.3 +PORTREVISION= 1 CATEGORIES= net-mgmt MASTER_SITES= # empty DISTFILES= # empty From 1857aae8735bf8c174430791a6bbe54791709778 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 12:39:40 +0100 Subject: [PATCH 3/8] Make port configurable and move PHP code out of XML --- .../files/usr/local/pkg/darkstat.xml | 172 ++---------------- 1 file changed, 15 insertions(+), 157 deletions(-) diff --git a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml index 0b9c638fdd51..376d69eb2b38 100644 --- a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml +++ b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml @@ -27,12 +27,19 @@ Darkstat Diagnostics: Darkstat + /usr/local/pkg/darkstat.inc - Darkstat Settings + darkstat Settings Setup darkstat specific settings.
Diagnostics
/pkg_edit.php?xml=darkstat.xml
+ + darkstat + Access darkstat +
Diagnostics
+ /darkstat_redirect.php +
darkstat darkstat.sh @@ -41,13 +48,13 @@ - Darkstat Settings + darkstat Settings /pkg_edit.php?xml=darkstat.xml - Access Darkstat - http://$myurl:666 + Access darkstat + /darkstat_redirect.php enabled @@ -86,22 +93,20 @@ 3 true
- - Local Network Traffic localnetworkenable @@ -235,153 +240,6 @@ - - 0) && ($hostsmax > $hostskeep)) { - $start .= " --hosts-max {$hostsmax}"; - } - if (($hostskeep > 0) && ($hostskeep < $hostsmax)) { - $start .= " --hosts-keep {$hostskeep}"; - } - $portsmax = $darkstat_config['portsmax']; - $portskeep = $darkstat_config['portskeep']; - if (($portsmax > 0) && ($portsmax > $portskeep)) { - $start .= " --ports-max {$portsmax}"; - } - if (($portskeep > 0) && ($portskeep < $portsmax)) { - $start .= " --ports-keep {$portskeep}"; - } - $advfilter = $darkstat_config['advfilter']; - if ($advfilter != "") { - $start .= " -f " . escapeshellarg(base64_decode($advfilter)); - } - - write_rcfile(array( - "file" => "darkstat.sh", - "start" => $start, - "stop" => "/usr/bin/killall darkstat" - ) - ); - - /* Do not (re)start service on boot */ - if (platform_booting()) { - return; - } elseif (is_process_running("darkstat")) { - restart_service("darkstat"); - } else { - start_service("darkstat"); - } - - conf_mount_ro(); - } - - function validate_input_darkstat($post, &$input_errors) { - if (($_POST['port']) && ($_POST['port'] < 1 || $_POST['port'] < 65535 || !is_numericint($_POST['port']))) { - $input_errors[] = gettext("The value for 'Maximum number of ports' to keep' must be a positive integer between 1 and 65535."); - } - if (($_POST['hostsmax']) && ($_POST['hostsmax'] < 1 || !is_numericint($_POST['hostsmax']))) { - $input_errors[] = gettext("The value for 'Maximum hosts count' must be a positive integer."); - } - if (($_POST['hostskeep']) && ($_POST['hostskeep'] < 1 || !is_numericint($_POST['hostskeep']))) { - $input_errors[] = gettext("The value for 'Maximum number of hosts to keep' must be a positive integer."); - } - if ($_POST['hostsmax'] || $_POST['hostskeep']) { - if ($_POST['hostsmax'] <= $_POST['hostskeep']) { - $input_errors[] = gettext("'Maximum hosts count' must be greater than 'Maximum number of hosts to keep'."); - } - } - if (($_POST['portsmax']) && ($_POST['portsmax'] < 1 || !is_numericint($_POST['portsmax']))) { - $input_errors[] = gettext("The value for 'Maximum ports count' must be a positive integer."); - } - if (($_POST['portskeep']) && ($_POST['portskeep'] < 1 || !is_numericint($_POST['portskeep']))) { - $input_errors[] = gettext("The value for 'Maximum number of ports' to keep' must be a positive integer."); - } - if ($_POST['portsmax'] || $_POST['portskeep']) { - if ($_POST['portsmax'] <= $_POST['portskeep']) { - $input_errors[] = gettext("'Maximum ports count' must be greater than 'Maximum number of ports to keep'."); - } - } - if ($_POST['localnetworkenable'] && $_POST['nopromisc'] != "") { - $input_errors[] = gettext("'Do not use promiscuous mode to capture' cannot be used when the 'local network' feature is enabled."); - } - if ($_POST['localnetwork']) { - $int = convert_friendly_interface_to_real_interface_name($post['localnetwork']); - $ip = find_interface_ip($int); - if (!is_ipaddrv4($ip)) { - $input_errors[] = gettext("The selected 'local network' interface has no IPv4 configured. Configured IPv4 is required."); - } - } - if (($post['advfilter']) && !preg_match("/^[a-zA-Z0-9\+\-\=\(\):. ]*$/", $post['advfilter'])) { - $input_errors[] = gettext('Advanced traffic filtering options may only contain characters matching ^[a-zA-Z0-9\+\-\=\(\):. ]*$ regexp.'); - } - } - ]]> - sync_package_darkstat(); From 899616ea5bf37a1618edab68d635e366b76631be Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 12:41:22 +0100 Subject: [PATCH 4/8] Move PHP code out of XML --- .../files/usr/local/pkg/darkstat.inc | 221 ++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc diff --git a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc new file mode 100644 index 000000000000..b999bdbf246f --- /dev/null +++ b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc @@ -0,0 +1,221 @@ + 0) && ($hostsmax > $hostskeep)) { + $start .= " --hosts-max {$hostsmax}"; + } + /* Maximum Hosts to Keep */ + if (($hostskeep > 0) && ($hostskeep < $hostsmax)) { + $start .= " --hosts-keep {$hostskeep}"; + } + /* Maximum Ports Count */ + $portsmax = $darkstat_config['portsmax']; + $portskeep = $darkstat_config['portskeep']; + if (($portsmax > 0) && ($portsmax > $portskeep)) { + $start .= " --ports-max {$portsmax}"; + } + /* Maximum Ports to Keep */ + if (($portskeep > 0) && ($portskeep < $portsmax)) { + $start .= " --ports-keep {$portskeep}"; + } + /* Advanced Filtering Options */ + $advfilter = $darkstat_config['advfilter']; + if ($advfilter != "") { + $start .= " -f " . escapeshellarg(base64_decode($advfilter)); + } + + /* Create rc script */ + write_rcfile(array( + "file" => "darkstat.sh", + "start" => $start, + "stop" => "/usr/bin/killall darkstat" + ) + ); + + /* Do not (re)start service on boot */ + if (platform_booting()) { + return; + } elseif (is_process_running("darkstat")) { + restart_service("darkstat"); + } else { + start_service("darkstat"); + } + + conf_mount_ro(); +} + +function validate_input_darkstat($post, &$input_errors) { + global $config; + /* Validate Web Interface Port */ + if ($post['port']) { + if (!is_port($post['port'])) { + $input_errors[] = gettext("The value for 'Web Interface Port' must be a valid port (1-65535)."); + } + // Check webGUI port conflicts + $webgui_port = $config['system']['webgui']['port']; + if ($config['system']['webgui']['port'] == "") { + if ($config['system']['webgui']['protocol'] == "http") { + $webgui_port = 80; + } elseif ($config['system']['webgui']['protocol'] == "https") { + $webgui_port = 443; + } + } + if ($post['port'] == "{$webgui_port}") { + $input_errors[] = gettext("The value for 'Web Interface Port' must not be the same port where pfSense WebGUI is running ($webgui_port)."); + } + } + /* Validate Maximum Hosts Count */ + if ($post['hostsmax']) { + if ($post['hostsmax'] < 1 || !is_numericint($post['hostsmax'])) { + $input_errors[] = gettext("The value for 'Maximum Hosts Count' must be a positive integer."); + } + } + /* Validate Maximum Hosts to Keep */ + if ($post['hostskeep']) { + if ($post['hostskeep'] < 1 || !is_numericint($post['hostskeep'])) { + $input_errors[] = gettext("The value for 'Maximum Hosts to Keep' must be a positive integer."); + } + } + /* Validate sanity for hosts limits */ + if ($post['hostsmax'] || $post['hostskeep']) { + if ($post['hostsmax'] <= $post['hostskeep']) { + $input_errors[] = gettext("'Maximum Hosts Count' must be greater than 'Maximum Hosts to Keep'."); + } + } + /* Validate Maximum Ports Count */ + if ($post['portsmax']) { + if ($post['portsmax'] < 1 || !is_numericint($post['portsmax'])) { + $input_errors[] = gettext("The value for 'Maximum Ports Count' must be a positive integer."); + } + } + /* Validate Maximum Ports to Keep */ + if ($post['portskeep']) { + if ($post['portskeep'] < 1 || !is_numericint($post['portskeep'])) { + $input_errors[] = gettext("The value for 'Maximum Ports to Keep' to keep' must be a positive integer."); + } + } + /* Validate sanity for ports limits */ + if ($post['portsmax'] || $post['portskeep']) { + if ($post['portsmax'] <= $post['portskeep']) { + $input_errors[] = gettext("'Maximum Ports to Keep' must be greater than 'Maximum Ports Count'."); + } + } + /* Validate Local Network Traffic */ + if ($post['localnetworkenable'] && $post['nopromisc'] != "") { + $input_errors[] = gettext("'No Promiscuous Mode' cannot be used when the 'Local Network' feature is enabled."); + } + /* Local Network must be IPv4 - no IPv6 support in darkstat */ + if ($post['localnetwork']) { + $int = convert_friendly_interface_to_real_interface_name($post['localnetwork']); + $ip = find_interface_ip($int); + if (!is_ipaddrv4($ip)) { + $input_errors[] = gettext("The selected 'local network' interface has no IPv4 configured. Configured IPv4 is required."); + } + } + /* Basic sanity validation for Advanced Filtering Options*/ + if (($post['advfilter']) && !preg_match("/^[a-zA-Z0-9\+\-\=\(\):. ]*$/", $post['advfilter'])) { + $input_errors[] = gettext('Advanced traffic filtering options may only contain characters matching ^[a-zA-Z0-9\+\-\=\(\):. ]*$ regexp.'); + } +} From 086d2dafd9d388a54fb65964781b093b7f983e90 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 12:44:28 +0100 Subject: [PATCH 5/8] Add a required redirect file to make darkstat port configurable --- .../files/usr/local/www/darkstat_redirect.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 net-mgmt/pfSense-pkg-darkstat/files/usr/local/www/darkstat_redirect.php diff --git a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/www/darkstat_redirect.php b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/www/darkstat_redirect.php new file mode 100644 index 000000000000..d5f223275f84 --- /dev/null +++ b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/www/darkstat_redirect.php @@ -0,0 +1,47 @@ + From 51c6e5140902e284bd72a7f9fac0464a95e02299 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 12:48:57 +0100 Subject: [PATCH 6/8] Add newly added port files to Makefile --- net-mgmt/pfSense-pkg-darkstat/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net-mgmt/pfSense-pkg-darkstat/Makefile b/net-mgmt/pfSense-pkg-darkstat/Makefile index 8ddb5b035fc6..d6dbe3699f26 100644 --- a/net-mgmt/pfSense-pkg-darkstat/Makefile +++ b/net-mgmt/pfSense-pkg-darkstat/Makefile @@ -26,10 +26,15 @@ do-extract: do-install: ${MKDIR} ${STAGEDIR}${PREFIX}/pkg + ${MKDIR} ${STAGEDIR}${PREFIX}/www ${MKDIR} ${STAGEDIR}/etc/inc/priv ${MKDIR} ${STAGEDIR}${DATADIR} - ${INSTALL_DATA} -m 0644 ${FILESDIR}${PREFIX}/pkg/darkstat.xml \ + ${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/darkstat.xml \ ${STAGEDIR}${PREFIX}/pkg + ${INSTALL_DATA} ${FILESDIR}${PREFIX}/pkg/darkstat.inc \ + ${STAGEDIR}${PREFIX}/pkg + ${INSTALL_DATA} ${FILESDIR}${PREFIX}/www/darkstat_redirect.php \ + ${STAGEDIR}${PREFIX}/www ${INSTALL_DATA} ${FILESDIR}/etc/inc/priv/darkstat.priv.inc \ ${STAGEDIR}/etc/inc/priv ${INSTALL_DATA} ${FILESDIR}${DATADIR}/info.xml \ From b14ff00109e637258b3ebd768e861d59c2bace64 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 12:51:26 +0100 Subject: [PATCH 7/8] Add newly added port files to pkg-plist --- net-mgmt/pfSense-pkg-darkstat/pkg-plist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net-mgmt/pfSense-pkg-darkstat/pkg-plist b/net-mgmt/pfSense-pkg-darkstat/pkg-plist index acd30c17072b..90673f11df9c 100644 --- a/net-mgmt/pfSense-pkg-darkstat/pkg-plist +++ b/net-mgmt/pfSense-pkg-darkstat/pkg-plist @@ -1,4 +1,6 @@ pkg/darkstat.xml +pkg/darkstat.inc +www/darkstat_redirect.php /etc/inc/priv/darkstat.priv.inc %%DATADIR%%/info.xml @dir /etc/inc/priv From bbc23cafaa34edd17d3641d08130dfeaafb817d5 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Tue, 31 Jan 2017 17:50:52 +0100 Subject: [PATCH 8/8] Remove useless line that has been there for ages --- net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc index b999bdbf246f..617eb22d0bb3 100644 --- a/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc +++ b/net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.inc @@ -55,7 +55,6 @@ function sync_package_darkstat() { /* Configure bind interface(s) */ foreach (explode(",", $darkstat_config['bind_interfaces']) as $iface) { - $if = convert_friendly_interface_to_real_interface_name($iface); $if = get_interface_ip("$iface"); if ($if) { $bind_ifaces_final .= " -b {$if}";