mirror of
https://github.com/webmin/webmin.git
synced 2025-08-16 14:51:18 +00:00
64 lines
1.6 KiB
Perl
Executable File
64 lines
1.6 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# Save bandwidth monitoring settings
|
|
|
|
require './itsecur-lib.pl';
|
|
&can_edit_error("bandwidth");
|
|
&ReadParse();
|
|
&foreign_require("bandwidth", "bandwidth-lib.pl");
|
|
|
|
if ($in{'enabled'}) {
|
|
# Enable in config, so that log rules are generated
|
|
$config{'bandwidth'} = $in{'iface'};
|
|
&save_module_config();
|
|
|
|
# Setup firewall and bandwidth modules
|
|
$bandwidth::config{'iface'} = $in{'iface'};
|
|
&bandwidth::save_module_config();
|
|
$firewall::config{'direct'} = 1;
|
|
&firewall::save_module_config();
|
|
|
|
# Set up syslog.conf entry
|
|
$conf = &syslog::get_config();
|
|
$sysconf = &bandwidth::find_sysconf($conf);
|
|
if (!$sysconf) {
|
|
&lock_file($syslog::config{'syslog_conf'});
|
|
&syslog::create_log({ 'file' => $bandwidth::bandwidth_log,
|
|
'active' => 1,
|
|
'sel' => [ "kern.=debug" ] });
|
|
&unlock_file($syslog::config{'syslog_conf'});
|
|
$err = &syslog::restart_syslog();
|
|
&error($err) if ($err);
|
|
}
|
|
|
|
# Set up cron job
|
|
$job = &bandwidth::find_cron_job();
|
|
if (!$job) {
|
|
&cron::create_wrapper($bandwidth::cron_cmd, $bandwidth::module_name, "rotate.pl");
|
|
$job = { 'user' => 'root',
|
|
'active' => 1,
|
|
'command' => $bandwidth::cron_cmd,
|
|
'special' => 'hourly' };
|
|
&lock_file(&cron::cron_file($job));
|
|
&cron::create_cron_job($job);
|
|
&unlock_file(&cron::cron_file($job));
|
|
}
|
|
}
|
|
else {
|
|
# Disable in config
|
|
$config{'bandwidth'} = undef;
|
|
&save_module_config();
|
|
|
|
# Remove cron job
|
|
$job = &bandwidth::find_cron_job();
|
|
if ($job) {
|
|
&lock_file(&cron::cron_file($job));
|
|
&cron::delete_cron_job($job);
|
|
&unlock_file(&cron::cron_file($job));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
&redirect("");
|
|
|