2 # Create, update or delete a BSD RC script
4 require './init-lib.pl';
6 $access{'bootup'} || &error($text{'edit_ecannot'});
7 &foreign_require("proc", "proc-lib.pl");
9 @rcs = &list_rc_scripts();
11 ($rc) = grep { $_->{'name'} eq $in{'name'} } @rcs;
12 $rc || &error($text{'edit_egone'});
16 # Delete the action script
17 &delete_rc_script($in{'name'});
18 &webmin_log("delete", "action", $in{'name'});
21 elsif ($in{'start'} || $in{'stop'} || $in{'status'}) {
23 $mode = $in{'start'} ? "start" :
24 $in{'stop'} ? "stop" : "status";
25 &ui_print_header(undef, $text{'ss_'.$mode}, "");
26 print &text('ss_doing'.$mode, "<tt>$in{'name'}</tt>"),"<br>\n";
27 $cmd = "$rc->{'file'} $mode";
29 &foreign_call("proc", "safe_process_exec_logged", $cmd, 0, 0, STDOUT, undef, 1);
31 &webmin_log($mode, 'action', $in{'name'});
32 &ui_print_footer("edit_rc.cgi?name=".&urlize($in{'name'}),
33 $text{'edit_return'});
38 $in{'name'} =~ /^[A-z0-9\_\-\.]+$/ ||
39 &error($text{'save_ename'});
40 ($clash) = grep { $_->{'name'} eq $in{'name'} } @rcs;
41 $clash && &error($text{'save_eclash'});
42 $in{'start_cmd'} =~ /\S/ || &error($text{'save_estartcmd'});
44 @dirs = split(/\s+/, $config{'rc_dir'});
45 $file = $dirs[$#dir]."/".$in{'name'};
46 $data = "#!/bin/sh\n";
48 $data .= "# PROVIDE: $in{'name'}\n";
49 $data .= "# REQUIRE: LOGIN\n";
51 $data .= ". /etc/rc.subr\n";
53 $data .= "name=$in{'name'}\n";
54 $data .= "rcvar=`set_rcvar`\n";
55 $data .= "start_cmd=\"$in{'start_cmd'}\"\n";
56 if ($in{'stop_cmd'}) {
57 $data .= "stop_cmd=\"$in{'stop_cmd'}\"\n";
59 if ($in{'status_cmd'}) {
60 $data .= "status_cmd=\"$in{'status_cmd'}\"\n";
63 $data .= "load_rc_config \${name}\n";
64 $data .= "run_rc_command \"\$1\"\n";
67 $data = $in{'script'};
69 $data =~ /\S/ || &error($text{'save_escript'});
70 $file = $rc->{'file'};
74 &open_lock_tempfile(SCRIPT, ">$file");
75 &print_tempfile(SCRIPT, $data);
76 &close_tempfile(SCRIPT);
77 &set_ownership_permissions(undef, undef, 0755, $file);
79 if ($rc->{'enabled'} != 2) {
83 &enable_rc_script($in{'name'});
86 &disable_rc_script($in{'name'});
91 &webmin_log($in{'new'} ? "create" : "modify", "action", $in{'name'});