Handle hostnames with upper-case letters
[webmin.git] / init / edit_upstart.cgi
1 #!/usr/local/bin/perl
2 # Show a form for creating or editing an upstart action
3
4 require './init-lib.pl';
5 $access{'bootup'} || &error($text{'edit_ecannot'});
6 &ReadParse();
7
8 if ($in{'new'}) {
9         &ui_print_header(undef, $text{'upstart_title1'}, "");
10         $u = { };
11         }
12 else {
13         &ui_print_header(undef, $text{'upstart_title2'}, "");
14         @upstarts = &list_upstart_services();
15         ($u) = grep { $_->{'name'} eq $in{'name'} } @upstarts;
16         $u || &error($text{'upstart_egone'});
17         $u->{'legacy'} && &error($text{'upstart_elegacy'});
18         }
19
20 print &ui_form_start("save_upstart.cgi", "post");
21 print &ui_hidden("new", $in{'new'});
22 print &ui_hidden("name", $in{'name'}) if (!$in{'new'});
23 print &ui_table_start($text{'upstart_header'}, undef, 2);
24
25 if ($in{'new'}) {
26         # Service name
27         print &ui_table_row($text{'upstart_name'},
28                             &ui_textbox("name", undef, 30));
29
30         # Description
31         print &ui_table_row($text{'upstart_desc'},
32                             &ui_textbox("desc", undef, 60));
33
34         # Pre-start script
35         print &ui_table_row($text{'upstart_prestart'},
36                             &ui_textarea("prestart", undef, 5, 80));
37
38         # Server command
39         print &ui_table_row($text{'upstart_server'},
40                             &ui_textbox("server", undef, 60)."<br>\n".
41                             &ui_checkbox("fork", 1, $text{'upstart_fork'}, 0));
42
43         # Start at boot?
44         print &ui_table_row($text{'upstart_boot'},
45                             &ui_yesno_radio("boot", 1));
46         }
47 else {
48         # Service name (non-editable)
49         print &ui_table_row($text{'upstart_name'},
50                             "<tt>$in{'name'}</tt>");
51
52         # Config file
53         $cfile = "/etc/init/$in{'name'}.conf";
54         $conf = &read_file_contents($cfile);
55         print &ui_table_row($text{'upstart_conf'},
56                             &ui_textarea("conf", $conf, 20, 80));
57
58         # Current status
59         if ($u->{'boot'} eq 'start' || $u->{'boot'} eq 'stop') {
60                 print &ui_table_row($text{'upstart_boot'},
61                             &ui_yesno_radio("boot", $u->{'boot'} eq 'start'));
62                 }
63         if ($u->{'status'} eq 'waiting' || $u->{'status'} eq 'running') {
64                 print &ui_table_row($text{'upstart_status'},
65                         $u->{'status'} eq 'waiting' ? $text{'upstart_status0'} :
66                                 &text('upstart_status1', $u->{'pid'}));
67                 }
68         }
69
70 print &ui_table_end();
71 if ($in{'new'}) {
72         print &ui_form_end([ [ undef, $text{'create'} ] ]);
73         }
74 else {
75         print &ui_form_end([ [ undef, $text{'save'} ],
76                              [ 'start', $text{'edit_startnow'} ],
77                              [ 'stop', $text{'edit_stopnow'} ],
78                              [ 'delete', $text{'delete'} ] ]);
79         }
80
81 &ui_print_footer("", $text{'index_return'});
82