Handle hostnames with upper-case letters
[webmin.git] / init / modifyhostconfig.cgi
1 #!/usr/local/bin/perl
2 # modifyhostconfig.cgi
3 # Rewrites the hostconfig file
4
5 # Written by Michael A. Peters <mpeters@mac.com>
6 # for OSX/Darwin
7
8 require './init-lib.pl';
9 $access{'bootup'} == 1 || &error("You are not allowed to edit the bootup script");
10 &ReadParse();
11
12 if ( $in{'choice'} eq "custom" ) {
13         $setting = $in{'custom'};
14         }
15 else {
16         $setting = $in{'choice'};
17         }
18         
19 if ( $setting =~ /^\%22(.*)\%22$/ ) {
20         $setting = $1;
21         }
22         
23 $setting =~ s/\+/ /g;
24 if ( $setting =~ /[ ]/ ) {
25         $setting = "\"$setting\"";
26         }
27
28 # not all possibile blunders are fixed, but at least intelligently
29 # made ones...
30
31 $setting = "$in{'action'}=$setting";
32
33 $hostc = $config{'hostconfig'};
34 # modify and write the hostconfig file
35 @new = ();
36 &lock_file($config{'hostconfig'});
37 open(LOCAL, "$hostc");
38 @old = <LOCAL>;
39 close(LOCAL);
40 foreach $line (@old) {
41         $line =~ s/^$in{'action'}=(.*)$/$setting/;
42         push @new, $line;
43         }
44
45 &open_tempfile(LOCAL, "> $config{'hostconfig'}");
46 &print_tempfile(LOCAL, @new);
47 &close_tempfile(LOCAL);
48 &unlock_file($config{'hostconfig'});
49 &webmin_log("hostconfig", undef, undef, "\%in");
50 &redirect("");