2 # Add needed firewall rules and syslog entry, and apply configurations
4 require './bandwidth-lib.pl';
6 $access{'setup'} || &error($text{'setup_ecannot'});
9 $iface = $in{'iface'} || $in{'other'};
10 $iface =~ /^\S+$/ || &error($text{'setup_eiface'});
12 # Add missing firewall rules
13 $err = &setup_rules($iface);
14 &error($err) if ($err);
16 if ($syslog_module eq "syslog") {
18 $conf = &syslog::get_config();
19 $sysconf = &find_sysconf($conf);
21 &lock_file($syslog::config{'syslog_conf'});
22 if ($syslog::config{'tags'}) {
23 local $conf = &syslog::get_config();
24 ($tag) = grep { $_->{'tag'} eq '*' } @$conf;
26 &syslog::create_log({ 'file' => $bandwidth_log,
29 'sel' => [ &get_loglevel() ] });
30 &unlock_file($syslog::config{'syslog_conf'});
31 $err = &syslog::restart_syslog();
32 &error($err) if ($err);
37 $conf = &syslog_ng::get_config();
38 ($dest, $filter, $log) = &find_sysconf_ng($conf);
39 &lock_file($syslog_ng::config{'syslogng_conf'});
41 # Create destination file entry
42 $dest = { 'name' => 'destination',
44 'values' => [ 'd_bandwidth' ],
47 'values' => [ $bandwidth_log ] }
50 &syslog_ng::save_directive($conf, undef, undef, $dest, 0);
53 # Create filter for facility and level
54 local @ll = &get_loglevel();
55 ($fac, $lvl) = split(/\./, $ll[0]);
57 $filter = { 'name' => 'filter',
59 'values' => [ 'f_bandwidth' ],
63 push(@{$filter->{'members'}},
64 { 'name' => 'facility',
65 'values' => [ $fac ] });
67 if ($fac ne "*" && $lvl ne "*") {
68 push(@{$filter->{'members'}}, "and");
71 push(@{$filter->{'members'}},
72 { 'name' => 'priority',
73 'values' => [ $lvl ] });
75 &syslog_ng::save_directive($conf, undef, undef, $filter, 0);
78 # Create log for the default source, destination and filter
79 @sources = &syslog_ng::find("source", $conf);
80 $log = { 'name' => 'log',
85 'values' => [ $sources[0]->{'value'} ], },
87 'values' => [ "f_bandwidth" ], },
88 { 'name' => 'destination',
89 'values' => [ "d_bandwidth" ], },
92 &syslog_ng::save_directive($conf, undef, undef, $log, 0);
94 &unlock_file($syslog_ng::config{'syslogng_conf'});
98 &lock_file($module_config_file);
99 $config{'iface'} = $iface;
100 &save_module_config();
101 &unlock_file($module_config_file);
103 # Setup the rotation cron job
104 $job = &find_cron_job();
106 &cron::create_wrapper($cron_cmd, $module_name, "rotate.pl");
107 $job = { 'user' => 'root',
109 'command' => $cron_cmd,
116 &lock_file(&cron::cron_file($job));
117 &cron::create_cron_job($job);
118 &unlock_file(&cron::cron_file($job));
121 &webmin_log("setup", undef, $iface);