Handle hostnames with upper-case letters
[webmin.git] / firewall / coherent-linux-lib.pl
1 # coherant-linux-lib.pl
2 # Deal with redhat's /etc/sysconfig/iptables save file and startup script
3
4 &foreign_require("init", "init-lib.pl");
5 $init_script = "$init::config{'init_dir'}/iptables";
6
7 # check_iptables()
8 # Returns an error message if something is wrong with iptables on this system
9 sub check_iptables
10 {
11 if (!-r $init_script) {
12         return &text('coherent_escript', "<tt>$init_script</tt>");
13         }
14 if (!$config{'done_check_iptables'}) {
15         local $out = `$init_script status 2>&1`;
16         if ($out !~ /table:|INPUT|FORWARD|OUTPUT/) {
17                 return &text('coherent_eoutput',
18                              "<tt>$init_script status</tt>");
19                 }
20         $config{'done_check_iptables'} = 1;
21         &save_module_config();
22         }
23 return undef;
24 }
25
26 $iptables_save_file = "/etc/sysconfig/iptables";
27
28 # apply_iptables()
29 # Applies the current iptables configuration from the save file
30 sub apply_iptables
31 {
32 local $out = &backquote_logged("cd / ; $init_script restart 2>&1");
33 $out =~ s/\033[^m]+m//g;
34 return $? || $out =~ /FAILED/ ? "<pre>$out</pre>" : undef;
35 }
36
37 # unapply_iptables()
38 # Writes the current iptables configuration to the save file
39 sub unapply_iptables
40 {
41 $out = &backquote_logged("cd / ; $init_script save 2>&1 </dev/null");
42 $out =~ s/\033[^m]+m//g;
43 return $? || $out =~ /FAILED/ ? "<pre>$out</pre>" : undef;
44 }
45
46 # started_at_boot()
47 sub started_at_boot
48 {
49 return &init::action_status("iptables") == 2;
50 }
51
52 sub enable_at_boot
53 {
54 &init::enable_at_boot("iptables");       # Assumes init script exists
55 }
56
57 sub disable_at_boot
58 {
59 &init::disable_at_boot("iptables");
60 }
61
62 1;
63