Handle hostnames with upper-case letters
[webmin.git] / init / edit_hostconfig.cgi
1 #!/usr/local/bin/perl
2 # edit_hostconfig.cgi
3 #
4 # Edit the settings in the hostconfig file, or the
5 # StartupItems script or plist associated with the
6 # action described in the hostconfig file.
7 #
8 # Also create a new startup action with associated script and plist
9 # and manually modify hostconfig file.
10
11 require './init-lib.pl';
12 require './hostconfig-lib.pl';
13 use File::Basename;
14 $access{'bootup'} == 1 || &error($text{'edit_ecannot'});
15
16 $ty = $ARGV[0];
17 if ($ty == 0) {
18         # Editing an existing action in /etc/hostconfig
19         $action_to_edit = $ARGV[1];
20         &ui_print_header(undef, $text{'edit_title'}, "");
21         %startuphash = &hostconfig_gather(startscript);
22         $startscript = $startuphash{"$action_to_edit"};
23         if ( $startscript ne "") {
24                 $startupdir = dirname("$startscript");
25                 $plistedit = "$startupdir/$config{'plist'}";
26                 }
27         else {
28                 $plistedit = "";
29                 }
30
31         #create the action edit table
32         $actionedit = &hostconfig_editaction("$action_to_edit", "$startscript");
33         print "<form action=modifyhostconfig.cgi method=post name=hostmod>\n";
34         print "<table width=\"100%\" border><tr $tb> <td><b>", &text('index_action'), "</b></td>\n";
35         print "<td><b>", &text('index_setting'), "</b></td></tr>\n";
36         print "<tr $cb><td valign=middle>$action_to_edit</td>\n";
37         print "<td>$actionedit</td></tr></table>\n";
38         print "<input type=submit value='$text{'save'}'></form>\n";
39         
40         
41         #create the edit file forms
42         if ($startscript ne "") {
43                 print &ui_hr();
44                 print &text('edit_hostconfig_startup',
45                         "<tt>$startscript</tt>"),"<br>\n";
46                 #       }
47                 print "<form action=save_startscript.cgi method=post>\n";
48                 print "<textarea name=startup rows=20 cols=80>";
49                 open(STARTSCRIPT, $startscript);
50                 while(<STARTSCRIPT>) { print; }
51                 close(STARTSCRIPT);
52                 print "</textarea><br>\n";
53                 print "<input type=hidden name=\"action\" value=\"$action_to_edit\">\n";
54                 print "<input type=submit value='$text{'save'}'></form>\n";
55                 }
56         if ($plistedit ne "") {
57                 print &ui_hr();
58                 print &text('edit_hostconfig_plist',
59                         "<tt>$plistedit</tt>"),"<br>\n";
60                 #       }
61                 print "<form action=save_startscript.cgi method=post>\n";
62                 print "<textarea name=plist rows=20 cols=80>";
63                 open(PLIST, $plistedit);
64                 while(<PLIST>) { print; }
65                 close(PLIST);
66                 print "</textarea><br>\n";
67                 print "<input type=hidden name=\"action\" value=\"$action_to_edit\">\n";
68 #               print "$plistedit</textarea><br>\n";
69                 print "<input type=submit value='$text{'save'}'></form>\n";
70                 }
71         }
72
73 if ($ty == 1) {
74         &ui_print_header(undef, $text{'edit_hostconfig_new'}, "");
75         print "<HR>\n";
76
77         print "<P>\n", &text('edit_hostconfig_noquotes',
78                 "<tt>$text{'edit_start'}</tt>"),"\n";
79
80         print "<P>\n", &text('edit_hostconfig_startitems',
81                 "<tt>$text{'edit_hostconfig_actionname'}</tt>",
82                 "<tt>$text{'edit_hostconfig_scriptname'}</tt>"),"\n";
83
84         print "<P>\n", &text('edit_hostconfig_array',
85                 "<tt>Provides</tt>", "<tt>Requires</tt>", "<tt>Uses</tt>"),"\n";
86         
87         print "<P>\n $text{'edit_hostconfig_further'}\n";
88
89         #print "<form method=post action=save_hostconfig_action.cgi enctype=multipart/form-data>\n";
90         print "<form method=post action=save_hostconfig_action.cgi>\n";
91         print "<table border>\n";
92         print "<tr $tb><td><b>Action Details</b></td></tr>\n";
93         print "<tr $cb><td><table cellpadding=3>\n";
94
95         # create the form fields
96
97         $textt=&hostconfig_createtext("Action Name","req");
98         print "<tr>", &hostconfig_createtext("$text{'edit_hostconfig_actionname'}","req");
99         print "<td><input size=20 name=action_name value=\"\"></td></tr>\n";
100         
101         print "<tr>", &hostconfig_createtext("$text{'edit_hostconfig_scriptname'}","req");
102         print "<td><input size=20 name=script_name value=\"\"></td></tr>\n";
103
104         print "<tr>", &hostconfig_createtext("$text{'edit_start'}","req");
105         print "<td><font size=-1><textarea rows=5 cols=80 name=execute></textarea></font></td></tr>\n";
106
107         print "<tr>", &hostconfig_createtext("$text{'index_desc'}","");
108         print "<td><input size=60 name=description value=\"\"></td></tr>\n";
109
110         print "<tr>", &hostconfig_createtext("Provides","");
111         print "<td><input size=60 name=provides value=\"\"></td></tr>\n";
112
113         print "<tr>", &hostconfig_createtext("Requires","");
114         print "<td><input size=60 name=requires value=\"\"></td></tr>\n";
115
116         print "<tr>", &hostconfig_createtext("Uses","");
117         print "<td><input size=60 name=uses value=\"\"></td></tr>\n";
118
119         print "<tr>", &hostconfig_createtext("OrderPreference","");
120         print "<td><SELECT name=order><option value=First>First<option value=Early>Early<option value=None selected>None<option value=Late>Late<option value=Last>Last</select></td></tr>\n";
121
122         print "<tr>", &hostconfig_createtext("Start Message","");
123         print "<td><input size=60 name=start value=\"\"></td></tr>\n";
124
125         print "<tr>", &hostconfig_createtext("Stop Message","");
126         print "<td><input size=60 name=stop value=\"\"></td></tr>\n";
127
128         print "<tr>", &hostconfig_createtext("Start at boot time?","");
129         print "<td><input name=boot type=radio value=\"-YES-\"> Yes\n";
130         print "<input name=boot type=radio value=\"-NO-\" checked> No</td></tr>\n";
131
132         print "<tr><td><font size=-1 color=#ff0000>* required field</font></td><td> </td></tr>\n";
133         print "</table>";
134         print "</td></tr></table>\n";
135         print "<input type=submit value=\"Create\"></form>\n";
136
137         }
138
139 if ($ty == 2) {
140         
141         &ui_print_header(undef, $text{'edit_hostconfig_title'}, "");
142         print &text('edit_hostconfig_hostconfig',
143                 "<tt>$config{'hostconfig'}</tt>"),"<br>\n";
144         print "<form action=save_startscript.cgi method=post>\n";
145         print "<textarea name=hostconfig rows=20 cols=80>";
146         open(LOCAL, $config{'hostconfig'});
147         while(<LOCAL>) { print; }
148         close(LOCAL);
149         print "</textarea><br>\n";
150         print "<input type=submit value='$text{'save'}'></form>\n";
151         print &ui_hr();
152
153         #add reboot and shutdown messages to this page as well...
154         print "<table cellpadding=5 width=100%>\n";
155         if ($access{'reboot'}) {
156                 print "<form action=reboot.cgi>\n";
157                 print "<tr> <td><input type=submit ",
158                         "value=\"$text{'index_reboot'}\"></td>\n";
159                 print "</form>\n";
160                 print "<td>$text{'index_rebootmsg'}</td> </tr>\n";
161                 }
162
163         if ($access{'shutdown'}) {
164                 print "<form action=shutdown.cgi>\n";
165                 print "<tr> <td><input type=submit ",
166                         "value=\"$text{'index_shutdown'}\"></td>\n";
167                 print "</form>\n";
168                 print "<td>$text{'index_shutdownmsg'}</td> </tr>\n";
169                 }
170         print "</table>\n";
171         }
172         
173 &ui_print_footer("", $text{'index_return'});