3 # Edit or create a bootup action. Existing actions can either be in the
4 # init.d directory (and linked to from the appropriate runlevels), or
5 # just plain runlevel files
7 require './init-lib.pl';
8 $access{'bootup'} || &error($text{'edit_ecannot'});
12 # Editing an action in init.d, linked to from various runlevels
14 &ui_print_header(undef, $text{'edit_title'}, "");
15 $file = &action_filename($ac);
16 $data = &read_file_contents($file);
17 $hasarg = &get_action_args($file);
20 # Editing an action in one of the runlevels
26 &ui_print_header(undef, $text{'edit_title'}, "");
27 $file = &runlevel_filename($rl, $ss, $num, $ac);
28 $data = &read_file_contents($file);
31 # Creating a new action in init.d
32 &ui_print_header(undef, $text{'create_title'}, "");
35 print &ui_form_start("save_action.cgi", "form-data");
36 print &ui_table_start($text{'edit_details'}, "width=100%", 2);
37 print &ui_hidden("type", $ty);
40 print &ui_hidden("old", $ac);
41 print &ui_hidden("file", $file);
43 print &ui_hidden("runlevel", $rl);
44 print &ui_hidden("startstop", $ss);
45 print &ui_hidden("number", $num);
50 if ($ac =~ /^\// || $access{'bootup'} == 2) {
51 print &ui_table_row($text{'edit_name'}, "<tt>$ac</tt>");
52 print &ui_hidden("name", $ac);
53 print &ui_hidden("extra", 1);
56 print &ui_table_row($text{'edit_name'},
57 &ui_textbox("name", $ac, 30));
61 # Display fields for a template for a new action
62 print &ui_table_row($text{'edit_desc'},
63 &ui_textarea("desc", undef, 2, 80));
65 if ($config{'start_stop_msg'}) {
66 print &ui_table_row($text{'edit_startmsg'},
67 &ui_textbox("start_msg", undef, 40));
69 print &ui_table_row($text{'edit_stopmsg'},
70 &ui_textbox("stop_msg", undef, 40));
73 print &ui_table_row($text{'edit_start'},
74 &ui_textarea("start", undef, 5, 80));
76 print &ui_table_row($text{'edit_stop'},
77 &ui_textarea("stop", undef, 5, 80));
79 elsif ($access{'bootup'} == 2) {
80 # Just show current script
81 print &ui_table_row($text{'edit_script'},
82 &ui_textarea("data", $data, 15, 80, undef, undef,
86 # Allow direct editing of the script
87 print &ui_table_row($text{'edit_script'},
88 &ui_textarea("data", $data, 15, 80));
91 if ($ty == 1 && $access{'bootup'} == 1) {
92 # Display a message about the script being bogus
93 print &ui_table_end();
94 print "<b>",&text("edit_bad$ss", $rl),"</b><br>\n";
95 print "<a href=\"fix_action.cgi?$rl+$ss+$num+$ac\">",
96 "$text{'edit_fix'}</a>. <p>\n";
98 elsif (!$config{'expert'} || $access{'bootup'} == 2) {
99 # Just tell the user if this action is started at boot time
102 local @boot = &get_inittab_runlevel();
103 foreach $s (&action_levels('S', $ac)) {
104 local ($l, $p) = split(/\s+/, $s);
105 $boot = 1 if (&indexof($l, @boot) >= 0);
107 if ($boot && $config{'daemons_dir'} &&
108 &read_env_file("$config{'daemons_dir'}/$ac", \%daemon)) {
109 $boot = lc($daemon{'ONBOOT'}) eq 'yes' ? 1 : 0;
111 print &ui_hidden("oldboot", $boot);
113 if ($access{'bootup'} == 1) {
114 print &ui_table_row($text{'edit_boot'},
115 &ui_yesno_radio("boot", $boot || $ty == 2 ? 1 : 0));
118 print &ui_table_row($text{'edit_boot'},
119 $boot || $ty == 2 ? $text{'yes'} : $text{'no'});
122 # Show if action is currently running
123 if ($hasarg->{'status'} && $config{'status_check'}) {
124 $r = &action_running($file);
126 $status = "<font color=#ff0000>$text{'no'}</font>";
129 $status = $text{'yes'};
132 $status = "<i>$text{'edit_unknown'}</i>";
134 print &ui_table_row($text{'edit_status'}, $status);
136 print &ui_table_end();
139 if ($config{'daemons_dir'} && $ac &&
140 &read_env_file("$config{'daemons_dir'}/$ac", \%daemon)) {
141 # Display onboot flag from daemons file
142 $boot = lc($daemon{'ONBOOT'}) eq 'yes';
143 print &ui_table_row($text{'edit_boot'},
144 &ui_yesno_radio("boot", $boot ? 1 : 0));
146 print &ui_table_end();
148 # Display which runlevels the action is started/stopped in
149 print &ui_table_start($text{'edit_levels'}, "width=100%", 4);
151 foreach $s (&action_levels('S', $ac)) {
152 @s = split(/\s+/, $s);
153 $spri{$s[0]} = $s[1];
155 foreach $k (&action_levels('K', $ac)) {
156 @k = split(/\s+/, $k);
157 $kpri{$k[0]} = $k[1];
160 @boot = &get_inittab_runlevel();
161 foreach $rl (&list_runlevels()) {
162 if (&indexof($rl, @boot) == -1) {
163 $label = &text('edit_rl', $rl);
166 $label = "<i>".&text('edit_rl', $rl)."</i>";
169 $od = $config{'order_digits'};
170 $msg = &ui_checkbox("S$rl", 1, $text{'edit_startat'},
171 defined($spri{$rl}))." ".
172 &ui_textbox("pri_S$rl", $spri{$rl}, $od)."\n".
173 &ui_checkbox("K$rl", 1, $text{'edit_stopat'},
174 defined($kpri{$rl}))." ".
175 &ui_textbox("pri_K$rl", $kpri{$rl}, $od);
176 print &ui_table_row($label, $msg);
178 print &ui_table_end();
182 if ($access{'bootup'} == 1) {
183 push(@buts, [ undef, $text{'save'} ]);
186 # Buttons to start and stop
187 $args = join("+", @ARGV);
188 print &ui_hidden("back", "edit_action.cgi?$args");
189 foreach $a (@action_buttons) {
190 if ($a eq 'start' || $a eq 'stop' || $hasarg->{$a}) {
191 push(@buts, [ $a, $text{'edit_'.$a.'now'} ]);
196 if ($access{'bootup'} == 1) {
197 push(@buts, [ "delete", $text{'delete'} ]);
199 print &ui_form_end(\@buts);
202 print &ui_form_end([ [ undef, $text{'create'} ] ]);
205 &ui_print_footer("", $text{'index_return'});