From 58c62f45b766f31740c5bbfb3da9e27abb086acf Mon Sep 17 00:00:00 2001 From: phildd Date: Sun, 29 Dec 2013 19:58:43 -0800 Subject: bandwidthd belts and braces checks when generating conf Forum: http://forum.pfsense.org/index.php/topic,68477.0.html Allows users to put "0" in various fields and have it come through validly into the bandwidthd conf file. Previously bare "0"s would appear in the conf file, which were wrong. --- config/bandwidthd/bandwidthd.inc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'config/bandwidthd/bandwidthd.inc') diff --git a/config/bandwidthd/bandwidthd.inc b/config/bandwidthd/bandwidthd.inc index 1220e033..7cdc8006 100644 --- a/config/bandwidthd/bandwidthd.inc +++ b/config/bandwidthd/bandwidthd.inc @@ -40,6 +40,10 @@ switch ($pfs_version) { } // End: Check pfSense version +function is_blank($value) { + return empty($value) && !is_numeric($value); +} + function bandwidthd_install_deinstall() { conf_mount_rw(); config_lock(); @@ -66,8 +70,11 @@ function bandwidthd_install_config() { /* user defined values */ $bandwidthd_config = $config['installedpackages']['bandwidthd']['config'][0]; $meta_refresh = $bandwidthd_config['meta_refresh']; - if ($meta_refresh) + if (is_numeric($meta_refresh)) $meta_refresh = "meta_refresh $meta_refresh\n"; + else + $meta_refresh = ""; + $graph = $bandwidthd_config['drawgraphs']; if ($graph) $graph = "graph true\n"; @@ -75,11 +82,17 @@ function bandwidthd_install_config() { $graph = "graph false\n"; $filter_text = $bandwidthd_config['filter']; - if ($filter_text) + if (!is_blank($filter_text)) $filter_text = "filter $filter_text\n"; + else + $filter_text = ""; + $recover_cdf = $bandwidthd_config['recovercdf']; if ($recover_cdf) $recover_cdf = "recover_cdf true\n"; + else + $recover_cdf = ""; + $output_cdf = $bandwidthd_config['outputcdf']; if ($output_cdf) $output_cdf_string = "output_cdf true\n"; @@ -93,15 +106,15 @@ function bandwidthd_install_config() { $postgresql_password = $bandwidthd_config['postgresqlpassword']; $postgresql_string = ""; if ($output_postgresql) { - if ($postgresql_host && $postgresql_username && $postgresql_database && $postgresql_password) + if (!is_blank($postgresql_host) && !is_blank($postgresql_username) && !is_blank($postgresql_database) && !is_blank($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."); + log_error("bandwidthd: You have to specify the postgreSQL Host, Database, Username and Password. postgreSQL details have been ignored."); } $sensor_id = $bandwidthd_config['sensorid']; - if ($sensor_id) + if (!is_blank($sensor_id)) $sensor_id_string = "sensor_id \"$sensor_id\""; else $sensor_id_string = ""; @@ -113,13 +126,20 @@ function bandwidthd_install_config() { $promiscuous = "promiscuous false\n"; $graph_cutoff = $bandwidthd_config['graphcutoff']; - if ($graph_cutoff) + if (!is_blank($graph_cutoff)) $graph_cutoff = "graph_cutoff $graph_cutoff\n"; + else + $graph_cutoff = ""; + $skip_intervals = $bandwidthd_config['skipintervals']; - if ($skip_intervals) + if ($skip_intervals) { $skip_intervals = "skip_intervals $skip_intervals\n"; + } else { + /* Includes the case where 0 is explicitly specified, which is the default anyway. */ + $skip_intervals = ""; + } - if ($bandwidthd_config['active_interface']){ + if (!is_blank($bandwidthd_config['active_interface'])){ $ifdescrs = array($bandwidthd_config['active_interface']); } else { log_error("You should specify an interface for bandwidthd to listen on. Exiting."); -- cgit v1.2.3