Handle hostnames with upper-case letters
[webmin.git] / heartbeat / save_conf.cgi
1 #!/usr/local/bin/perl
2 # save_conf.cgi
3 # Save configuration options
4
5 require './heartbeat-lib.pl';
6 &ReadParse();
7 @conf = &get_ha_config();
8 &error_setup($text{'conf_err'});
9
10 # Parse and validate inputs
11 for($i=0; defined($in{"serial_$i"}); $i++) {
12         push(@serials, $in{"serial_$i"}) if ($in{"serial_$i"});
13         }
14 &save_directive(\@conf, 'serial', \@serials );
15
16 if ($in{'baud_def'}) {
17         &save_directive(\@conf, 'baud', [ ]);
18         }
19 else {
20         $in{'baud'} =~ /^\d+$/ || &error($text{'conf_ebaud'});
21         &save_directive(\@conf, 'baud', [ $in{'baud'} ]);
22         }
23
24 # changed (Christof Amelunxen, 22.08.2003)
25 # udp now bcast
26 if ($in{'bcasts_def'}) {
27         &save_directive(\@conf, 'bcast', [ ]);
28         }
29 else {
30         @bcasts = split(/\s+/, $in{'bcasts'});
31         foreach $b (@bcasts) {
32                 $b =~ /^\S+\d+$/ || &error(&text('conf_ebcastif', $b));
33                 }
34         @bcasts || &error($text{'conf_ebcasts'});
35         &save_directive(\@conf, 'bcast', \@bcasts);
36         }
37
38 if ($in{'udpport_def'}) {
39         &save_directive(\@conf, 'udpport', [ ]);
40         }
41 else {
42         $in{'udpport'} =~ /^\d+$/ || &error($text{'conf_eudpport'});
43         &save_directive(\@conf, 'udpport', [ $in{'udpport'} ]);
44         }
45
46 if ($in{'mcast_def'}) {
47         &save_directive(\@conf, 'mcast', [ ]);
48         }
49 else {
50         $in{'mcast_dev'} =~ /^\S+\d+$/ || &error($text{'conf_emcast_dev'});
51         &check_ipaddress($in{'mcast_ip'}) || &error($text{'conf_emcast_ip'});
52         $in{'mcast_port'} =~ /^\d+$/ || &error($text{'conf_emcast_port'});
53         $in{'mcast_ttl'} =~ /^\d+$/ || &error($text{'conf_emcast_ttl'});
54         &save_directive(\@conf, 'mcast', [ join(" ",
55                 $in{'mcast_dev'}, $in{'mcast_ip'}, $in{'mcast_port'},
56                 $in{'mcast_ttl'}, $in{'mcast_loop'}) ] );
57         }
58
59 if ($in{'keepalive_def'}) {
60         &save_directive(\@conf, 'keepalive', [ ]);
61         }
62 else {
63         $in{'keepalive'} =~ /^\d+$/ || &error($text{'conf_ekeepalive'});
64         &save_directive(\@conf, 'keepalive', [ $in{'keepalive'} ]);
65         }
66
67 if ($in{'deadtime_def'}) {
68         &save_directive(\@conf, 'deadtime', [ ]);
69         }
70 else {
71         $in{'deadtime'} =~ /^\d+$/ || &error($text{'conf_edeadtime'});
72         &save_directive(\@conf, 'deadtime', [ $in{'deadtime'} ]);
73         }
74
75 if ($in{'watchdog_def'}) {
76         &save_directive(\@conf, 'watchdog', [ ]);
77         }
78 else {
79         -r $in{'watchdog'} || &error($text{'conf_ewatchdog'});
80         &save_directive(\@conf, 'watchdog', [ $in{'watchdog'} ]);
81         }
82
83 @node = split(/\s+/, $in{'node'});
84 @node || &error($text{'conf_enonode'});
85 $uname = `uname -n 2>/dev/null`;
86 $uname =~ s/\r|\n//g;
87 foreach $n (@node) {
88         $found++ if ($n eq $uname);
89         }
90 !$uname || $found || &error(&text('conf_ethisnode', "<tt>$uname</tt>"));
91 &save_directive(\@conf, 'node', \@node);
92
93 if ($in{'logfile_def'}) {
94         &save_directive(\@conf, 'logfile', [ ]);
95         }
96 else {
97         $in{'logfile'} =~ /^\S+$/ || &error($text{'conf_elogfile'});
98         &save_directive(\@conf, 'logfile', [ $in{'logfile'} ]);
99         }
100
101 if ($in{'logfacility_def'}) {
102         &save_directive(\@conf, 'logfacility', [ ]);
103         }
104 else {
105         &save_directive(\@conf, 'logfacility', [ $in{'logfacility'} ]);
106         }
107
108 if ($in{'initdead_def'}) {
109         &save_directive(\@conf, 'initdead', [ ]);
110         }
111 else {
112         $in{'initdead'} =~ /^\d+$/ || &error($text{'conf_einitdead'});
113         $in{'deadtime_def'} || $in{'initdead'} >= $in{'deadtime'}*2 ||
114                 &error($text{'conf_einitdead2'});
115         &save_directive(\@conf, 'initdead', [ $in{'initdead'} ]);
116         }
117
118 # save nice failback behaviour
119 if (&version_atleast(1, 2, 0)) {
120         # New-style option
121         if ($in{'auto_failback'}) {
122                 &save_directive(\@conf, 'auto_failback',
123                                 [ $in{'auto_failback'} ]);
124                 }
125         else {
126                 &save_directive(\@conf, 'auto_failback', [ ]);
127                 }
128         }
129 else {
130         # Old-style option
131         if ($in{'nice_failback_def'}) {
132                 &save_directive(\@conf,'nice_failback',[ 'on' ]);
133                 }
134         else {
135                 &save_directive(\@conf,'nice_failback', [ 'off' ]);
136                 }
137         }
138         
139
140 &flush_file_lines();
141 &redirect("");
142