aboutsummaryrefslogtreecommitdiffstats
path: root/config/bandwidthd
diff options
context:
space:
mode:
Diffstat (limited to 'config/bandwidthd')
-rw-r--r--config/bandwidthd/bandwidthd.inc190
-rw-r--r--config/bandwidthd/bandwidthd.xml85
2 files changed, 234 insertions, 41 deletions
diff --git a/config/bandwidthd/bandwidthd.inc b/config/bandwidthd/bandwidthd.inc
index 34532c18..00e3cd28 100644
--- a/config/bandwidthd/bandwidthd.inc
+++ b/config/bandwidthd/bandwidthd.inc
@@ -46,6 +46,8 @@ function bandwidthd_install_deinstall() {
exec("rm -f /usr/local/etc/rc.d/bandwidthd*");
exec("rm -rf " . PKG_BANDWIDTHD_BASE . "/htdocs");
exec("rm -f /usr/local/www/bandwidthd");
+ // Remove the cron job, if it is there
+ install_cron_job("/bin/kill -HUP `cat /var/run/bandwidthd.pid`", false);
conf_mount_ro();
config_unlock();
}
@@ -54,50 +56,76 @@ function bandwidthd_install_config() {
global $config, $g;
/* bandwidthd doesn't have a way to pass a custom config path, unfortunately */
+ /* the conf file must be ./etc/bandwidthd.conf relative to the current dir */
+ $bandwidthd_base_dir = PKG_BANDWIDTHD_BASE;
$bandwidthd_config_dir = PKG_BANDWIDTHD_BASE . "/etc";
conf_mount_rw();
config_lock();
/* user defined values */
- $meta_refresh = $config['installedpackages']['bandwidthd']['config'][0]['meta_refresh'];
+ $bandwidthd_config = $config['installedpackages']['bandwidthd']['config'][0];
+ $meta_refresh = $bandwidthd_config['meta_refresh'];
if($meta_refresh)
$meta_refresh = "meta_refresh $meta_refresh\n";
- $graph = $config['installedpackages']['bandwidthd']['config'][0]['drawgraphs'];
+ $graph = $bandwidthd_config['drawgraphs'];
if($graph)
$graph = "graph true\n";
else
$graph = "graph false\n";
- $filter_text = $config['installedpackages']['bandwidthd']['config'][0]['filter'];
+ $filter_text = $bandwidthd_config['filter'];
if($filter_text)
$filter_text = "filter $filter_text\n";
- $recover_cdf = $config['installedpackages']['bandwidthd']['config'][0]['recovercdf'];
+ $recover_cdf = $bandwidthd_config['recovercdf'];
if($recover_cdf)
$recover_cdf = "recover_cdf true\n";
- $output_cdf = $config['installedpackages']['bandwidthd']['config'][0]['outputcdf'];
+ $output_cdf = $bandwidthd_config['outputcdf'];
if($output_cdf)
- $output_cdf = "output_cdf true\n";
- $promiscuous = $config['installedpackages']['bandwidthd']['config'][0]['promiscuous'];
+ $output_cdf_string = "output_cdf true\n";
+ else
+ $output_cdf_string = "";
+
+ $output_postgresql = $bandwidthd_config['outputpostgresql'];
+ $postgresql_host = $bandwidthd_config['postgresqlhost'];
+ $postgresql_database = $bandwidthd_config['postgresqldatabase'];
+ $postgresql_username = $bandwidthd_config['postgresqlusername'];
+ $postgresql_password = $bandwidthd_config['postgresqlpassword'];
+ $postgresql_string = "";
+ if($output_postgresql) {
+ if ($postgresql_host && $postgresql_username && $postgresql_database && $postgresql_password)
+ $postgresql_string = "pgsql_connect_string \"user = $postgresql_username dbname = $postgresql_database password = $postgresql_password host = $postgresql_host\"\n";
+ else
+ log_error("You have to specify the postgreSQL Host, Database, Username and Password. Exiting.");
+ }
+
+ $sensor_id = $bandwidthd_config['sensorid'];
+
+ if($sensor_id)
+ $sensor_id_string = "sensor_id \"$sensor_id\"";
+ else
+ $sensor_id_string = "";
+
+ $promiscuous = $bandwidthd_config['promiscuous'];
if($promiscuous)
$promiscuous = "promiscuous true\n";
else
$promiscuous = "promiscuous false\n";
- $graph_cutoff = $config['installedpackages']['bandwidthd']['config'][0]['graphcutoff'];
+ $graph_cutoff = $bandwidthd_config['graphcutoff'];
if($graph_cutoff)
$graph_cutoff = "graph_cutoff $graph_cutoff\n";
- $skip_intervals = $config['installedpackages']['bandwidthd']['config'][0]['skipintervals'];
+ $skip_intervals = $bandwidthd_config['skipintervals'];
if($skip_intervals)
$skip_intervals = "skip_intervals $skip_intervals\n";
- if($config['installedpackages']['bandwidthd']['config'][0]['active_interface']){
- $ifdescrs = array($config['installedpackages']['bandwidthd']['config'][0]['active_interface']);
+ if($bandwidthd_config['active_interface']){
+ $ifdescrs = array($bandwidthd_config['active_interface']);
} else {
log_error("You should specify an interface for bandwidthd to listen on. Exiting.");
}
- $subnets_custom = explode(';',str_replace(' ','',$config['installedpackages']['bandwidthd']['config'][0]['subnets_custom']));
+ $subnets_custom = explode(';',str_replace(' ','',$bandwidthd_config['subnets_custom']));
/* initialize to "" */
$subnets = "";
@@ -143,7 +171,7 @@ function bandwidthd_install_config() {
# This file was automatically generated by the pfSense
# package management system. Changing this file
# will lead to it being overwritten again when
-# the package manage resyncs.
+# the package manager resyncs.
#
####################################################
# Bandwidthd.conf
@@ -178,11 +206,19 @@ $graph_cutoff
$promiscuous
#Log data to cdf file htdocs/log.cdf
-$output_cdf
+$output_cdf_string
#Read back the cdf file on startup
$recover_cdf
+# Standard postgres connect string, just like php, see postgres docs for
+# details
+$postgresql_string
+
+# Arbitrary sensor name, I recommend the sensors fully qualified domain
+# name
+$sensor_id_string
+
#Libpcap format filter string used to control what bandwidthd sees
#Please always include "ip" in the string to avoid strange problems
$filter_text
@@ -206,25 +242,123 @@ EOF;
fwrite($fd, $config_file);
fclose($fd);
- /* write out rc.d start/stop file */
- write_rcfile(array(
- "file" => "bandwidthd.sh",
- "start" => "/usr/local/bandwidthd/bandwidthd {$bandwidthd_config_dir}/bandwidthd.conf",
- "stop" => "/usr/bin/killall bandwidthd"
- )
- );
+ if ($g['platform'] == 'nanobsd') {
+ $bandwidthd_nano_dir = "/var/bandwidthd";
+ $bandwidthd_htdocs_dir = $bandwidthd_nano_dir . "/htdocs";
+ if (!is_dir($bandwidthd_nano_dir)) {
+ if (file_exists($bandwidthd_nano_dir)) {
+ unlink($bandwidthd_nano_dir);
+ }
+ mkdir($bandwidthd_nano_dir);
+ }
+ } else {
+ $bandwidthd_htdocs_dir = $bandwidthd_base_dir . "/htdocs";
+ }
- exec("rm /usr/local/www/bandwidthd");
- exec("/bin/ln -s " . PKG_BANDWIDTHD_BASE . "/htdocs /usr/local/www/bandwidthd");
+ $rc = array();
+ $rc['file'] = 'bandwidthd.sh';
+ $rc['stop'] = <<<EOD
+/usr/bin/killall bandwidthd
+EOD;
+
+ // If this is an old config before the enable checkbox was added, then enable by default
+ $bandwidthd_enable = (!isset($bandwidthd_config['enable']) || ($bandwidthd_config['enable']));
+ if ($bandwidthd_enable) {
+ if ($g['platform'] == 'nanobsd') {
+ // On nanobsd, /var/bandwidthd is created.
+ // In that is a real /var/bandwidth/htdocs, where the graph data is written
+ // A soft link to the real bandwidth program is made - /var/bandwidthd/bandwidthd
+ // A soft link to the etc folder with the conf file is made - /var/bandwidthd/etc
+ // bandwidthd is started from /var/bandwidthd with the current dir /var/bandwidth
+ // This way, it:
+ // looks in ./etc for the conf file
+ // writes graph files in ./htdocs
+ // writes cdf log files (if selected in the config) to ./
+ // All of this is on the /var filesystem, which is a read-write memory disk on nanobsd
+ $rc['start'] = <<<EOD
+if [ ! -d "{$bandwidthd_nano_dir}" ] ; then
+ if [ -e "{$bandwidthd_nano_dir}" ] ; then
+ /bin/rm -f {$bandwidthd_nano_dir}
+ fi
+ /bin/mkdir -p {$bandwidthd_nano_dir}
+fi
+if [ ! -d "{$bandwidthd_htdocs_dir}" ] ; then
+ if [ -e "{$bandwidthd_htdocs_dir}" ] ; then
+ /bin/rm -f {$bandwidthd_htdocs_dir}
+ fi
+ /bin/mkdir -p {$bandwidthd_htdocs_dir}
+fi
+if [ ! -L "{$bandwidthd_nano_dir}/bandwidthd" ] ; then
+ if [ -e "{$bandwidthd_nano_dir}/bandwidthd" ] ; then
+ /bin/rm -Rf {$bandwidthd_nano_dir}/bandwidthd
+ fi
+ /bin/ln -s {$bandwidthd_base_dir}/bandwidthd {$bandwidthd_nano_dir}/bandwidthd
+fi
+if [ ! -L "{$bandwidthd_nano_dir}/etc" ] ; then
+ if [ -e "{$bandwidthd_nano_dir}/etc" ] ; then
+ /bin/rm -Rf {$bandwidthd_nano_dir}/etc
+ fi
+ /bin/ln -s {$bandwidthd_config_dir} {$bandwidthd_nano_dir}/etc
+fi
+if [ ! -f "{$bandwidthd_htdocs_dir}/legend.gif" ] ; then
+ /bin/cp {$bandwidthd_base_dir}/htdocs/legend.gif {$bandwidthd_htdocs_dir}
+fi
+if [ ! -f "{$bandwidthd_htdocs_dir}/logo.gif" ] ; then
+ /bin/cp {$bandwidthd_base_dir}/htdocs/logo.gif {$bandwidthd_htdocs_dir}
+fi
+cd {$bandwidthd_nano_dir}
+{$bandwidthd_nano_dir}/bandwidthd
+cd -
+EOD;
+ } else {
+ $rc['start'] = <<<EOD
+/usr/local/bandwidthd/bandwidthd
+EOD;
+ }
+ } else {
+ // bandwidthd is disabled, so do not put any real start commands in the script.
+ // This effectively disables it but keeps all the files in place (e.g. saved logs) ready to reload when it is enabled.
+ $rc['start'] = "return";
+ }
+
+ /* write out rc.d start/stop file */
+ write_rcfile($rc);
- exec("echo \"Please start bandwidthd to populate this directory.\" > " . PKG_BANDWIDTHD_BASE . "/htdocs/index.html");
+ if (!is_dir($bandwidthd_htdocs_dir)) {
+ if (file_exists($bandwidthd_htdocs_dir)) {
+ unlink($bandwidthd_htdocs_dir);
+ }
+ mkdir($bandwidthd_htdocs_dir);
+ }
+ $bandwidthd_www_link = $g["www_path"] . "/bandwidthd";
+ if (!is_link($bandwidthd_www_link)) {
+ if (file_exists($bandwidthd_www_link)) {
+ // It is a file and not a link - clean it up.
+ unlink($bandwidthd_www_link);
+ }
+ symlink($bandwidthd_htdocs_dir, $bandwidthd_www_link);
+ }
+ $bandwidthd_index_file = $bandwidthd_htdocs_dir . "/index.html";
+ if (!file_exists($bandwidthd_index_file)) {
+ exec("echo \"Please start bandwidthd to populate this directory.\" > " . $bandwidthd_index_file);
+ }
+
+ if (($bandwidthd_enable) && ($output_cdf)) {
+ // Use cron job to rotate logs every day at 00:01
+ install_cron_job("/bin/kill -HUP `cat /var/run/bandwidthd.pid`", true, "1", "0");
+ }
+ else
+ {
+ // Remove the cron job, if it is there
+ install_cron_job("/bin/kill -HUP `cat /var/run/bandwidthd.pid`", false);
+ }
conf_mount_ro();
config_unlock();
-
stop_service("bandwidthd");
- start_service("bandwidthd");
-
+ if ($bandwidthd_enable) {
+ start_service("bandwidthd");
+ }
}
-?> \ No newline at end of file
+?>
diff --git a/config/bandwidthd/bandwidthd.xml b/config/bandwidthd/bandwidthd.xml
index 258772a7..1603e385 100644
--- a/config/bandwidthd/bandwidthd.xml
+++ b/config/bandwidthd/bandwidthd.xml
@@ -7,7 +7,7 @@
/* $Id$ */
/* ========================================================================== */
/*
- authng.xml
+ bandwidthd.xml
part of pfSense (http://www.pfSense.com)
Copyright (C) 2007 to whom it may belong
All rights reserved.
@@ -41,12 +41,12 @@
*/
/* ========================================================================== */
]]>
- </copyright>
- <description>Describe your package here</description>
- <requirements>Describe your package requirements here</requirements>
- <faq>Currently there are no FAQ items provided.</faq>
+ </copyright>
+ <description>Describe your package here</description>
+ <requirements>Describe your package requirements here</requirements>
+ <faq>Currently there are no FAQ items provided.</faq>
<name>bandwidthd</name>
- <version>1.0</version>
+ <version>2.0.1_5 pkg v.0.1</version>
<title>Bandwidthd</title>
<aftersaveredirect>/pkg_edit.php?xml=bandwidthd.xml&amp;id=0</aftersaveredirect>
<include_file>/usr/local/pkg/bandwidthd.inc</include_file>
@@ -60,7 +60,7 @@
<name>bandwidthd</name>
<rcfile>bandwidthd.sh</rcfile>
<executable>bandwidthd</executable>
- </service>
+ </service>
<tabs>
<tab>
<text>BandwidthD</text>
@@ -69,7 +69,7 @@
</tab>
<tab>
<text>Access BandwidthD</text>
- <url>/bandwidthd</url>
+ <url>/bandwidthd" target="_blank</url>
</tab>
</tabs>
<configpath>installedpackages->package->bandwidthd</configpath>
@@ -80,6 +80,12 @@
</additional_files_needed>
<fields>
<field>
+ <fielddescr>Enable bandwidthd</fielddescr>
+ <fieldname>enable</fieldname>
+ <type>checkbox</type>
+ <description></description>
+ </field>
+ <field>
<fielddescr>Interface</fielddescr>
<fieldname>active_interface</fieldname>
<description>The interface that bandwidthd will bind to.</description>
@@ -96,7 +102,7 @@
<field>
<fielddescr>Skip intervals</fielddescr>
<fieldname>skipintervals</fieldname>
- <description>Number of intervals (2.5 minute) to skip between graphing. Default 0.</description>
+ <description>Number of intervals to skip between graphing. Default 0. Each interval is 200 seconds = 3 min 20 sec.</description>
<type>input</type>
</field>
<field>
@@ -108,22 +114,60 @@
<field>
<fielddescr>Promiscuous</fielddescr>
<fieldname>promiscuous</fieldname>
- <description>Put interface in promiscuous mode to score to traffic that may not be routing through the host machine.</description>
+ <description>Put interface in promiscuous mode to see traffic that may not be routing through the host machine.&lt;br&gt;
+ Note: If the interface is connected to a switch then the interface will only see the traffic on its port.</description>
<type>checkbox</type>
</field>
<field>
<fielddescr>output_cdf</fielddescr>
<fieldname>outputcdf</fieldname>
- <description>Log data to cdf file htdocs/log.cdf</description>
+ <description>Log data to cdf files log*.cdf</description>
<type>checkbox</type>
</field>
<field>
<fielddescr>recover_cdf</fielddescr>
<fieldname>recovercdf</fieldname>
- <description>Read back the cdf file on startup</description>
+ <description>Read back the cdf files on startup</description>
+ <type>checkbox</type>
+ </field>
+ <field>
+ <fielddescr>output PostgreSQL</fielddescr>
+ <fieldname>outputpostgresql</fieldname>
+ <description>Log data to a PostgreSQL database.&lt;br&gt;
+ Get the postgreSQL schema and PHP files to display the results from: &lt;a target="_new" href="https://github.com/individual-it/bandwidthd-pSQL-frontend"&gt;https://github.com/individual-it/bandwidthd-pSQL-frontend&lt;/a&gt;</description>
<type>checkbox</type>
</field>
<field>
+ <fielddescr>Database host</fielddescr>
+ <fieldname>postgresqlhost</fieldname>
+ <description>Hostname of the postgreSQL database server.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Database name</fielddescr>
+ <fieldname>postgresqldatabase</fieldname>
+ <description>Database on the postgreSQL database server.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Database Username</fielddescr>
+ <fieldname>postgresqlusername</fieldname>
+ <description>Username of the postgreSQL database server.</description>
+ <type>input</type>
+ </field>
+ <field>
+ <fielddescr>Database Password</fielddescr>
+ <fieldname>postgresqlpassword</fieldname>
+ <description>Password of the postgreSQL database server.</description>
+ <type>password</type>
+ </field>
+ <field>
+ <fielddescr>sensor_id</fielddescr>
+ <fieldname>sensorid</fieldname>
+ <description>Arbitrary sensor name, I recommend the sensors fully qualified domain name.</description>
+ <type>input</type>
+ </field>
+ <field>
<fielddescr>Filter</fielddescr>
<fieldname>filter</fieldname>
<description>Libpcap format filter string used to control what bandwidthd sees. Please always include "ip" in the string to avoid strange problems.</description>
@@ -139,9 +183,24 @@
<field>
<fielddescr>Meta Refresh</fielddescr>
<fieldname>meta_refresh</fieldname>
- <description>Set META REFRESH seconds (default 150, use 0 to disable).</description>
+ <description>Sets the interval (seconds) at which the browser graph display refreshes (default 150, use 0 to disable).</description>
<type>input</type>
</field>
+ <field>
+ <fielddescr>Graph and Log Info</fielddescr>
+ <fieldname>graph_log_info</fieldname>
+ <description>If draw graphs is on, then the daily report and graph html data is regenerated every (skip intervals + 1) * 200 seconds. The data volumes in the report are for the same period as the span of the graph.&lt;br&gt;
+ If output_cdf is on, then a cron job is added to rotate the log files at 00:01 each day. 6 log files are kept for each log frequency (daily, weekly, monthly, yearly). At the respective rotation intervals, the oldest log is deleted, the others are shuffled back and a new log is created.&lt;br&gt;
+ &lt;table cellpadding=1 cellspacing=0 style=&quot;text-align: left;&quot;&gt; &lt;tbody&gt;
+ &lt;tr&gt;&lt;th&gt; &lt;/th&gt;&lt;th&gt; Data Interval &lt;/th&gt;&lt;th&gt; Graph Span &lt;/th&gt;&lt;th&gt; Log Rotation &lt;/th&gt;&lt;th&gt; Log File Name &lt;/th&gt;&lt;/tr&gt;
+ &lt;tr&gt;&lt;th&gt; Daily &lt;/th&gt;&lt;td&gt; 200 seconds &lt;/td&gt;&lt;td&gt; 2 days &lt;/td&gt;&lt;td&gt; 1 day &lt;/td&gt;&lt;td&gt; log.1.[0-5].cdf &lt;/td&gt;&lt;/tr&gt;
+ &lt;tr&gt;&lt;th&gt; Weekly &lt;/th&gt;&lt;td&gt; 10 minutes &lt;/td&gt;&lt;td&gt; 7 days &lt;/td&gt;&lt;td&gt; 7 days &lt;/td&gt;&lt;td&gt; log.2.[0-5].cdf &lt;/td&gt;&lt;/tr&gt;
+ &lt;tr&gt;&lt;th&gt; Monthly &lt;/th&gt;&lt;td&gt; 1 hour &lt;/td&gt;&lt;td&gt; 35 days &lt;/td&gt;&lt;td&gt; 35 days &lt;/td&gt;&lt;td&gt; log.3.[0-5].cdf &lt;/td&gt;&lt;/tr&gt;
+ &lt;tr&gt;&lt;th&gt; Yearly &lt;/th&gt;&lt;td&gt; 12 hours &lt;/td&gt;&lt;td&gt; 412.5 days &lt;/td&gt;&lt;td&gt; 412.5 days &lt;/td&gt;&lt;td&gt; log.4.[0-5].cdf &lt;/td&gt;&lt;/tr&gt;
+ &lt;/tbody&gt; &lt;/table&gt;
+ </description>
+ <type>info</type>
+ </field>
</fields>
<custom_php_resync_config_command>
bandwidthd_install_config();