" . $bandwidthd_index_file); } /* Cron job for graphs */ if (($bandwidthd_config['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(); /* Restart the service if enabled; otherwise stop it */ if ($bandwidthd_config['enable']) { restart_service("bandwidthd"); } else { stop_service("bandwidthd"); } } function bandwidthd_upgrade_config() { global $config, $changes; // The 'Advanced Filter' options and 'Database Password' are now base64-encoded // in order to now break config.xml if they contain some special chars. // If this is an old config, pick up the original unencoded values and upgrade $changes = 0; $bandwidthd_config = $config['installedpackages']['bandwidthd']['config'][0]; if (isset($bandwidthd_config['filter'])) { $config['installedpackages']['bandwidthd']['config'][0]['advfilter'] = base64_encode($bandwidthd_config['filter']); unset($config['installedpackages']['bandwidthd']['config'][0]['filter']); $changes++; } if (isset($bandwidthd_config['postgresqlpassword'])) { $config['installedpackages']['bandwidthd']['config'][0]['postgresqlpasswordenc'] = base64_encode($bandwidthd_config['postgresqlpassword']); unset($config['installedpackages']['bandwidthd']['config'][0]['postgresqlpassword']); $changes++; } // Subnet(s) for Statistics Collection - convert old subnets_custom to interface_array here as well. if (isset($bandwidthd_config['subnets_custom'])) { $i = 0; $subnets_custom = explode(';', $bandwidthd_config['subnets_custom']); // For each configured interface on this box... $iflist = get_configured_interface_list_by_realif(); foreach ($iflist as $if) { // first, gets its subnet... $sn = gen_subnet(get_interface_ip($if), get_interface_subnet($if)); foreach ($subnets_custom as $subnet_custom) { // next, strip the subnet mask from the old settings value... $subnet_custom = substr($subnet_custom, 0, strpos($subnet_custom, '/')); // next, try to match the originally configured subnet against configured interfaces... if ($subnet_custom != "" && $subnet_custom == $sn) { // skip PPPoE interfaces if any... $realif = get_real_interface($if); if (!preg_match("/pppoe[0-9]+/i", $realif)) { // and finally, set the new config value for config.xml echo $if; $config['installedpackages']['bandwidthd']['config'][0]['interface_array'][$i] = $if; $i++; } } } } // Remove the old settings value now that we are done with config upgrade unset($config['installedpackages']['bandwidthd']['config'][0]['subnets_custom']); } // Write the upgraded config.xml if something changed write_config("[bandwidthd] Upgraded old package configuration."); } function bandwidthd_validate_input($post, &$input_errors) { if ($post['active_interface']) { $realif = get_real_interface($post['active_interface']); $ip = find_interface_ip($realif); if (!is_ipaddrv4($ip)) { // IPv6-only interfaces are not supported $errif = convert_friendly_interface_to_friendly_descr($post['active_interface']); $input_errors[] = gettext("The \"{$errif}\" interface selected under 'BandwidthD Web Interface' has no IPv4 configured. Configured IPv4 is required."); } } else { $input_errors[] = "You must select the 'BandwidthD Web Interface'."; } // bandwidthd does not work with PPPoE; IPv6 is also not supported if ($post['interface_array']) { foreach ($post['interface_array'] as $ifname) { $realif = get_real_interface($ifname); $ip = find_interface_ip($realif); $errif = convert_friendly_interface_to_friendly_descr($ifname); if (preg_match("/pppoe[0-9]+/i", $realif)) { $input_errors[] = gettext("Sorry, BandwidthD does not support PPPoE interfaces. Remove \"{$errif}\" from 'Subnet(s) for Statistics Collection'."); } if (!is_ipaddrv4($ip)) { $input_errors[] = gettext("The \"{$errif}\" interface selected under 'Subnet(s) for Statistics Collection' has no IPv4 configured. Configured IPv4 is required."); } } } else { $input_errors[] = "You must select at least on interface under 'Subnet(s) for Statistics Collection'."; } // Only support sane characters in Sensor ID if ($post['sensorid']) { if ((!is_hostname($post['sensorid'])) && !preg_match("/^[a-zA-Z0-9\-\=\(\):. ]*$/", $post['sensorid'])) { $input_errors[] .= gettext('Sensor ID must be either a hostname or a string which may only contain characters matching ^[a-zA-Z0-9\-\(\):. ]*$ regexp.'); } } if (($post['meta_refresh']) && (!is_numericint($post['meta_refresh']))) { $input_errors[] = gettext("The value for 'Meta Refresh' must be a positive integer."); } if (($post['skipintervals']) && (!is_numericint($post['skipintervals']))) { $input_errors[] = gettext("The value for 'Skip Intervals' must be a positive integer."); } if (($post['graphcutoff']) && (!is_numericint($post['graphcutoff']))) { $input_errors[] = gettext("The value for 'Graph Cutoff' must be a positive integer."); } if ($post['outputpostgresql']) { if (!$post['postgresqlhost']) { $input_errors[] = gettext("The value for 'Database Host' must not be empty when 'Output to PostgreSQL' is enabled."); } if (!$post['postgresqldatabase']) { $input_errors[] = gettext("The value for 'Database Name' must not be empty when 'Output to PostgreSQL' is enabled."); } if (!$post['postgresqlusername']) { $input_errors[] = gettext("The value for 'Database User' must not be empty when 'Output to PostgreSQL' is enabled."); } if (!$post['postgresqlpasswordenc']) { $input_errors[] = gettext("The value for 'Database Password' must not be empty when 'Output to PostgreSQL' is enabled."); } } if (($post['postgresqlhost']) && (!is_hostname($post['postgresqlhost']))) { $input_errors[] = gettext("The value for 'Database Host' must be a valid hostname or IPv4."); } 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.'); } } ?>