2 # Create, update or delete an upstart service
4 require './init-lib.pl';
5 &error_setup($text{'upstart_err'});
6 $access{'bootup'} || &error($text{'edit_ecannot'});
8 @upstarts = &list_upstart_services();
9 $cfile = "/etc/init/$in{'name'}.conf";
13 ($u) = grep { $_->{'name'} eq $in{'name'} } @upstarts;
14 $u || &error($text{'upstart_egone'});
15 $u->{'legacy'} && &error($text{'upstart_elegacy'});
18 if ($in{'start'} || $in{'stop'}) {
19 # Just redirect to the start page
20 &redirect("mass_upstarts.cgi?d=".&urlize($in{'name'})."&".
21 ($in{'start'} ? "start=1" : "stop=1").
22 "&return=".&urlize($in{'name'}));
28 &disable_at_boot($in{'name'});
29 &stop_upstart_service($in{'name'});
30 &delete_upstart_service($in{'name'});
31 &webmin_log("delete", "upstart", $in{'name'});
34 # Validate inputs and check for clash
35 $in{'name'} =~ /^[a-z0-9\.\_\-]+$/i ||
36 &error($text{'upstart_ename'});
37 ($clash) = grep { $_->{'name'} eq $in{'name'} } @upstarts;
38 $clash && &error($text{'upstart_eclash'});
39 $in{'desc'} || &error($text{'upstart_edesc'});
40 $in{'server'} =~ /\S/ || &error($text{'upstart_eserver'});
41 ($bin, $args) = split(/\s+/, $in{'server'});
42 &has_command($bin) || &error($text{'upstart_eserver2'});
43 $in{'server'} =~ /;|\&\&|\|\|/ && &error($text{'upstart_eserver3'});
44 $in{'prestart'} =~ s/\r//g;
46 # Create the config file
47 &create_upstart_service($in{'name'}, $in{'desc'}, $in{'server'},
48 $in{'prestart'}, $in{'fork'});
50 # Enable at boot if selected
51 if ($in{'boot'} == 0) {
52 &disable_at_boot($in{'name'});
55 &enable_at_boot($in{'name'});
58 &webmin_log("create", "upstart", $in{'name'});
61 # Just save the config file
62 $in{'conf'} =~ /\S/ || &error($text{'upstart_econf'});
63 $in{'conf'} =~ s/\r//g;
64 &open_lock_tempfile(CONF, ">$cfile");
65 &print_tempfile(CONF, $in{'conf'});
66 &close_tempfile(CONF);
69 if (defined($in{'boot'})) {
70 if ($in{'boot'} == 0) {
71 &disable_at_boot($in{'name'});
74 &enable_at_boot($in{'name'});
78 &webmin_log("modify", "upstart", $in{'name'});