Handle hostnames with upper-case letters
[webmin.git] / init / save_startscript.cgi
1 #!/usr/local/bin/perl
2 # save_startscript.cgi
3 # saves modifications to the StartupItems/script/script or
4 # the StartupItems/script/StartupItems.plist
5
6 # Even though it would be MUCH faster to pass the file to be edited
7 # in the form, forms are filled out by the browser, not the server.
8 #
9 # A malicious user could manipulate the form to write to
10 # any file they darned well please. While a user who has webmin access 
11 # to the bootup scripts could do a fair amount of damage anyway, I still
12 # would rather limit the possible files the cgi will write to to the
13 # actual bootup scripts.
14
15 # Written by Michael A. Peters <mpeters@mac.com> for
16 # webmin init module, based on save_local.cgi of same
17 # module. Written for Darwin/OS X.
18
19 require './init-lib.pl';
20 require './hostconfig-lib.pl';
21 use File::Basename;
22 $access{'bootup'} == 1 || &error("You are not allowed to edit the bootup script");
23 &ReadParse();
24
25 $action=$in{'action'};
26
27 if ( $in{'plist'} ne "" ) {
28         $in{'plist'} =~ s/\r//g;
29         $towrite = $in{'plist'};
30         %temphash = &hostconfig_gather(startscript);
31         $tempfile = $temphash{"$action"};
32         $dir = dirname("$tempfile");
33         $file = "$dir/$config{'plist'}";
34         $redirect = "edit_hostconfig.cgi?0+$action";
35         -e $file || &error("$file doesn't seem to exist");
36         }
37 elsif ( $in{'startup'} ne "" ) {
38         $in{'startup'} =~ s/\r//g;
39         $towrite = $in{'startup'};
40         %temphash = &hostconfig_gather(startscript);
41         $file = $temphash{"$action"};
42         $redirect = "edit_hostconfig.cgi?0+$action";
43         -e $file || &error("$file doesn't seem to exist");
44         }
45 elsif ( $in{'hostconfig'} ne "" ) {
46         $in{'hostconfig'} =~ s/\r//g;
47         $towrite = $in{'hostconfig'};
48         $file = $config{'hostconfig'};
49         $redirect = "edit_hostconfig.cgi?2";
50         }
51 else {
52         &error("I do not know what you want me to do");
53         }
54
55 &lock_file($file);
56 &open_tempfile(LOCAL, "> $file");
57 &print_tempfile(LOCAL, $towrite);
58 &close_tempfile(LOCAL);
59 &unlock_file($file);
60 &webmin_log("startup", undef, undef, \%in);
61 &redirect("$redirect");