Handle hostnames with upper-case letters
[webmin.git] / itsecur-firewall / save_bandwidth.cgi
1 #!/usr/bin/perl
2 # Save bandwidth monitoring settings
3
4 require './itsecur-lib.pl';
5 &can_edit_error("bandwidth");
6 &ReadParse();
7 &foreign_require("bandwidth", "bandwidth-lib.pl");
8
9 if ($in{'enabled'}) {
10         # Enable in config, so that log rules are generated
11         $config{'bandwidth'} = $in{'iface'};
12         &save_module_config();
13
14         # Setup firewall and bandwidth modules
15         $bandwidth::config{'iface'} = $in{'iface'};
16         &bandwidth::save_module_config();
17         $firewall::config{'direct'} = 1;
18         &firewall::save_module_config();
19
20         # Set up syslog.conf entry
21         $conf = &syslog::get_config();
22         $sysconf = &bandwidth::find_sysconf($conf);
23         if (!$sysconf) {
24                 &lock_file($syslog::config{'syslog_conf'});
25                 &syslog::create_log({ 'file' => $bandwidth::bandwidth_log,
26                                       'active' => 1,
27                                       'sel' => [ "kern.=debug" ] });
28                 &unlock_file($syslog::config{'syslog_conf'});
29                 $err = &syslog::restart_syslog();
30                 &error($err) if ($err);
31                 }
32
33         # Set up cron job
34         $job = &bandwidth::find_cron_job();
35         if (!$job) {
36                 &cron::create_wrapper($bandwidth::cron_cmd, $bandwidth::module_name, "rotate.pl");
37                 $job = { 'user' => 'root',
38                          'active' => 1,
39                          'command' => $bandwidth::cron_cmd,
40                          'special' => 'hourly' };
41                 &lock_file(&cron::cron_file($job));
42                 &cron::create_cron_job($job);
43                 &unlock_file(&cron::cron_file($job));
44                 }
45         }
46 else {
47         # Disable in config
48         $config{'bandwidth'} = undef;
49         &save_module_config();
50
51         # Remove cron job
52         $job = &bandwidth::find_cron_job();
53         if ($job) {
54                 &lock_file(&cron::cron_file($job));
55                 &cron::delete_cron_job($job);
56                 &unlock_file(&cron::cron_file($job));
57                 }
58
59
60         }
61
62 &redirect("");
63