Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darkstat package improvements #264

Merged
merged 3 commits into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions net-mgmt/pfSense-pkg-darkstat/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-darkstat
PORTVERSION= 3.1.2
PORTREVISION= 1
PORTVERSION= 3.1.3
CATEGORIES= net-mgmt
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
86 changes: 46 additions & 40 deletions net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* darkstat.xml
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2009-2015 Rubicon Communications, LLC (Netgate)
* Copyright (c) 2009-2017 Rubicon Communications, LLC (Netgate)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -31,19 +31,18 @@
<name>Darkstat Settings</name>
<tooltiptext>Setup darkstat specific settings.</tooltiptext>
<section>Diagnostics</section>
<url>/pkg_edit.php?xml=darkstat.xml&amp;id=0</url>
<url>/pkg_edit.php?xml=darkstat.xml</url>
</menu>
<service>
<name>darkstat</name>
<rcfile>darkstat.sh</rcfile>
<executable>darkstat</executable>
<description>Darkstat bandwidth monitoring daemon</description>
</service>
<configpath>installedpackages->package->$packagename->configuration->settings</configpath>
<tabs>
<tab>
<text>Darkstat Settings</text>
<url>/pkg_edit.php?xml=darkstat.xml&amp;id=0</url>
<url>/pkg_edit.php?xml=darkstat.xml</url>
<active/>
</tab>
<tab>
Expand All @@ -62,8 +61,8 @@
<fielddescr>Capture Interfaces</fielddescr>
<fieldname>capture_interfaces</fieldname>
<description><![CDATA[
Capture traffic on the specified network interface(s).<br />
(Default is LAN.)
Capture traffic on the specified network interface(s).
<span class="text-info">Default: LAN.</span>
]]>
</description>
<type>interfaces_selection</type>
Expand All @@ -78,8 +77,8 @@
<fieldname>bind_interfaces</fieldname>
<description>
<![CDATA[
Bind the web interface to the IP address(es) of the specified interface(s).<br />
(The default is to listen on all interfaces.)
Bind the web interface to the IP address(es) of the specified interface(s).
<span class="text-info">Default: Listen on all interfaces.</span>
]]>
</description>
<type>interfaces_selection</type>
Expand Down Expand Up @@ -132,8 +131,8 @@
<sethelp>
<![CDATA[
Note that an interface may already be in promiscuous mode, or may later enter promiscuous mode,
due to circumstances beyond the control of darkstat.<br />
<strong>This cannot be used when the "local network" feature is enabled.</strong>
due to circumstances beyond the control of darkstat.
<strong><span class="text-info">This cannot be used when the "local network" feature is enabled.</span></strong>
]]>
</sethelp>
<type>checkbox</type>
Expand Down Expand Up @@ -162,9 +161,9 @@
<fieldname>hostsmax</fieldname>
<description>
<![CDATA[
The maximum number of hosts that will be kept in the hosts table.<br />
The maximum number of hosts that will be kept in the hosts table.
This is used to limit how much accounting data will be kept in memory.<br />
(If filled in, the number must be greater than 'Maximum number of hosts to keep' below.)
<span class="text-info">If filled in, the number must be greater than 'Maximum number of hosts to keep' below.</span>
]]>
</description>
<type>input</type>
Expand All @@ -175,9 +174,9 @@
<fieldname>hostskeep</fieldname>
<description>
<![CDATA[
When the hosts table hits 'Maximum hosts count' and traffic is seen from a new host,<br />
When the hosts table hits 'Maximum hosts count' and traffic is seen from a new host,
we clean out the hosts table, keeping only the top number of hosts, sorted by total traffic.<br />
(If filled in, the number must be lower than 'Maximum hosts count' above.)
<span class="text-info">If filled in, the number must be lower than 'Maximum hosts count' above.</span>
]]>
</description>
<type>input</type>
Expand All @@ -188,9 +187,9 @@
<fieldname>portsmax</fieldname>
<description>
<![CDATA[
The maximum number of ports that will be tracked for each host.<br />
The maximum number of ports that will be tracked for each host.
This is used to limit how much accounting data will be kept in memory.<br />
(If filled in, the number must be greater than 'Maximum number of ports to keep' below.)
<span class="text-info">If filled in, the number must be greater than 'Maximum number of ports to keep' below.</span>
]]>
</description>
<type>input</type>
Expand All @@ -202,7 +201,7 @@
<description>
<![CDATA[
When a ports table fills up, this many ports are kept and the rest are discarded.<br />
(If filled in, the number must be lower than 'Maximum ports count' above.)
<span class="text-info">If filled in, the number must be lower than 'Maximum ports count' above.</span>
]]>
</description>
<type>input</type>
Expand All @@ -213,17 +212,19 @@
<fieldname>advfilter</fieldname>
<description>
<![CDATA[
Use the specified filter expression when capturing traffic.<br /><br />
Example 1: We only want to account for SSH traffic.<br />
Use the specified filter expression when capturing traffic. <span class="text-info">Click Info for examples.</span>
<div class="infoblock">
<span class="text-info">Example 1:</span> We only want to account for SSH traffic.<br />
Filter expression: <em>port 22</em><br /><br />
Example 2: We don't want to account for traffic between internal IPs.<br />
<span class="text-info">Example 2:</span> We don't want to account for traffic between internal IPs.<br />
Filter expression: <em>not (src net 192.168.0 and dst net 192.168.0)</em><br /><br />
NOTE: Filter syntax is beyond the scope of this description; please refer to
<span class="text-info">NOTE:</span> Filter syntax is beyond the scope of this description; please refer to
<a href="https://www.freebsd.org/cgi/man.cgi?query=tcpdump&amp;sektion=1&amp;apropos=0&amp;manpath=FreeBSD+10.1-RELEASE+and+Ports">tcpdump(1)</a>,
<a href="https://www.freebsd.org/cgi/man.cgi?query=pcap-filter&amp;sektion=7&amp;apropos=0&amp;manpath=FreeBSD+10.1-RELEASE+and+Ports">pcap-filter(7)</a>
and <a href="https://www.freebsd.org/cgi/man.cgi?query=darkstat&apropos=0&sektion=0&manpath=FreeBSD+10.1-RELEASE+and+Ports&arch=default&format=html">darkstat(8)</a>
documentation.<br />
<strong>WARNING: You are completely on your own with this! If misconfigured, darkstat will malfunction or even not start at all.</strong>
<strong><span class="text-danger">WARNING: You are completely on your own with this!</span> If misconfigured, darkstat will malfunction or even not start at all.</strong>
</div>
]]>
</description>
<type>textarea</type>
Expand All @@ -240,6 +241,15 @@
global $config, $darkstat_config;
$darkstat_config =& $config['installedpackages']['darkstat']['config'][0];

/* If the service is (being) disabled, stop it (if running), remove rc script and do nothing else */
if ($darkstat_config['enable'] != "on") {
if (is_process_running("darkstat")) {
stop_service("darkstat");
}
unlink_if_exists('/usr/local/etc/rc.d/darkstat.sh');
return;
}

/* Configure capture interface(s) */
$capture_interfaces = $darkstat_config['capture_interfaces'] ?: 'lan';
foreach (explode(",", $capture_interfaces) as $iface) {
Expand Down Expand Up @@ -317,64 +327,60 @@
)
);

/* If the service is (being) disabled, stop it (if running) and do nothing else */
if (!($darkstat_config['enable'])) {
if (is_process_running("darkstat")) {
stop_service("darkstat");
}
/* Do not (re)start service on boot */
if (platform_booting()) {
return;
} else {
} 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.");
$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.");
$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'.");
$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.");
$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.");
$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'.");
$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.");
$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.");
$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.');
$input_errors[] = gettext('Advanced traffic filtering options may only contain characters matching ^[a-zA-Z0-9\+\-\=\(\):. ]*$ regexp.');
}
}
]]>
</custom_php_global_functions>
<custom_add_php_command>
sync_package_darkstat();
</custom_add_php_command>
<custom_php_resync_config_command>
sync_package_darkstat();
</custom_php_resync_config_command>
Expand Down