3 # Display a list of run-levels and the actions that are run at boot and
4 # shutdown time for each level
6 require './init-lib.pl';
7 require './hostconfig-lib.pl';
8 &ui_print_header(&text('index_mode', $text{'mode_'.$init_mode}),
9 $text{'index_title'}, "", undef, 1, 1);
11 if ($init_mode eq "osx" && $access{'bootup'}) {
12 # This hostconfig if block written by Michael A Peters <mpeters@mac.com>
14 # build hostconfig table
16 @hconf_set = &hostconfig_settings();
17 %description_list = &hostconfig_gather(description);
19 print &ui_columns_start([ &text('index_action'),
20 &text('index_setting'),
21 &text('index_desc') ], 100, 0);
23 while (<@hconf_set>) {
24 $action_description = $description_list{"$hconf_set[$i][0]"};
25 print &hostconfig_table($hconf_set[$i][0], $hconf_set[$i][1], $action_description);
28 print &ui_columns_end();
29 if ($access{'bootup'} == 1) {
31 "<a href='edit_hostconfig.cgi?1'>".
32 "$text{'index_add_mac'}</a>",
33 "<a href='edit_hostconfig.cgi?2'>".
34 &text('index_editconfig',
35 "<tt>$config{'hostconfig'}</tt>")."</a>"
39 elsif ($init_mode eq "init" && $access{'bootup'}) {
40 # build list of normal and broken actions
41 @iacts = &list_actions();
43 @ac = split(/\s+/, $a);
44 $nodemap{$ac[1]} = $ac[0];
46 push(@actsl, "0+$ac[0]");
47 push(@actsf, $ac[0] =~ /^\// ? $ac[0]
48 : "$config{'init_dir'}/$ac[0]");
50 @runlevels = &list_runlevels();
51 foreach $r (@runlevels) {
52 foreach $w ("S", "K") {
53 foreach $a (&runlevel_actions($r, $w)) {
54 @ac = split(/\s+/, $a);
55 if (!$nodemap{$ac[2]}) {
58 "1+$r+$ac[0]+$ac[1]+$ac[2]+$w");
59 push(@actsf, "$config{'init_base'}/rc$r.d/$w$ac[0]$ac[1]");
65 # For each action, look at /etc/rc*.d/* files to see if it is
67 @boot = &get_inittab_runlevel();
68 for($i=0; $i<@acts; $i++) {
69 foreach $s (&action_levels('S', $acts[$i])) {
70 local ($l, $p) = split(/\s+/, $s);
71 local ($lvl) = (&indexof($l, @boot) >= 0);
73 if ($lvl && $config{'daemons_dir'} &&
74 &read_env_file("$config{'daemons_dir'}/$acts[$i]",
76 $lvl = lc($daemon{'ONBOOT'}) eq 'yes' ? 1 : 0;
78 push(@{$actsb[$i]}, [ $l, $p, $lvl ]);
80 @{$actsb[$i]} = sort { $b->[2] <=> $a->[2] } @{$actsb[$i]};
83 # Sort the actions if necessary
84 @order = ( 0 .. $#acts );
85 if ($config{'sort_mode'}) {
86 @order = sort { local $aa = $actsb[$a]->[0];
87 local $bb = $actsb[$b]->[0];
88 $bb->[2] <=> $aa->[2] ||
89 $bb->[1] <=> $aa->[1] }
92 @acts = map { $acts[$_] } @order;
93 @actsl = map { $actsl[$_] } @order;
94 @actsf = map { $actsf[$_] } @order;
95 @actsb = map { $actsb[$_] } @order;
98 if ($access{'bootup'} == 1) {
100 "<a href='edit_action.cgi?2'>$text{'index_add'}</a>");
102 if (!$config{'desc'}) {
103 # Display actions by name only
104 print &ui_links_row(\@links);
106 for($i=0; $i<@acts; $i++) {
108 push(@grid, "<a href=\"edit_action.cgi?".
109 "$actsl[$i]\">$acts[$i]</a>");
112 print &ui_grid_table(\@grid, 4, 100,
113 [ "width=25%", "width=25%", "width=25%", "width=25%" ],
114 undef, $text{'index_title'});
115 print &ui_links_row(\@links);
118 # Display actions and descriptions
119 print &ui_form_start("mass_start_stop.cgi", "post");
120 print &ui_links_row(\@links);
121 print &ui_columns_start([
123 $text{'index_action'},
124 $config{'desc'} == 2 ? $text{'index_levels'}
125 : $text{'index_boot'},
126 $config{'order'} ? ( $text{'index_order'} ) : ( ),
127 $config{'status_check'} == 2 ? ( $text{'index_status'} ) : ( ),
128 $text{'index_desc'} ],
129 100, 0, [ "", "nowrap", "nowrap", "nowrap", "nowrap" ]);
131 for($i=0; $i<@acts; $i++) {
132 local ($boot, %daemon, @levels, $order);
133 foreach $s (@{$actsb[$i]}) {
137 "<font color=#ff0000>$s->[0]</font>");
140 push(@levels, $s->[0]);
143 $order = $actsb[$i]->[0]->[1];
145 push(@cols, "<a href=\"edit_action.cgi?".
146 "$actsl[$i]\">$acts[$i]</a>");
148 $d = &html_escape(&init_description($actsf[$i],
149 $config{'status_check'} == 2 ? \%has : undef));
150 if ($config{'desc'} == 2) {
151 push(@cols, join(" ", @levels));
154 push(@cols,$boot ? $text{'yes'} :
155 "<font color=#ff0000>$text{'no'}</font>");
157 if ($config{'order'}) {
160 if ($config{'status_check'} == 2) {
161 if ($actsl[$i] =~ /^0/ && $has{'status'}) {
162 local $r = &action_running($actsf[$i]);
165 "<font color=#ff0000>".
166 "$text{'no'}</font>");
169 push(@cols, $text{'yes'});
180 if ($actsl[$i] =~ /^0/) {
181 print &ui_checked_columns_row(
182 \@cols, undef, "idx", $order[$i]);
185 print &ui_columns_row([ undef, @cols ]);
188 print &ui_columns_end();
189 print &ui_links_row(\@links);
190 @buts = ( [ "start", $text{'index_start'} ],
191 [ "stop", $text{'index_stop'} ],
192 [ "restart", $text{'index_restart'} ] );
193 if ($access{'bootup'} == 1) {
194 # Show buttons to enable/disable at boot
196 [ "addboot", $text{'index_addboot'} ],
197 [ "delboot", $text{'index_delboot'} ],
199 [ "addboot_start", $text{'index_addboot_start'} ],
200 [ "delboot_stop", $text{'index_delboot_stop'} ],
203 print &ui_form_end(\@buts);
206 elsif ($init_mode eq "local" && $access{'bootup'} == 1) {
207 # Display local bootup script
208 if ($config{'hostconfig'}) {
209 # This means a darwin system where
210 # daemons are not started in the rc script
211 print &text('index_script_mac',
212 "<tt>$config{'local_script'}</tt>"),"<br>\n";
215 print &text('index_script',
216 "<tt>$config{'local_script'}</tt>"),"<br>\n";
218 print &ui_form_start("save_local.cgi", "post");
219 print &ui_textarea("local",
220 &read_file_contents($config{'local_script'}), 15, 80)."<br>\n";
222 # Show shutdown script too, if any
223 if ($config{'local_down'}) {
224 print &text('index_downscript',
225 "<tt>$config{'local_down'}</tt>"),"<br>\n";
226 print &ui_textarea("down",
227 &read_file_contents($config{'local_down'}), 15, 80).
231 print &ui_form_end([ [ undef, $text{'save'} ] ]);
233 elsif ($init_mode eq "win32" && $access{'bootup'}) {
234 # Show Windows services
235 print &ui_form_start("save_services.cgi", "post");
236 print &select_all_link("d"),"\n";
237 print &select_invert_link("d"),"<br>\n";
238 print &ui_columns_start([ "", $text{'index_sname'},
239 $text{'index_sdesc'},
240 $text{'index_sboot'},
241 $text{'index_sstate'} ]);
242 foreach $svc (&list_win32_services()) {
243 print &ui_columns_row([
244 &ui_checkbox("d", $svc->{'name'}, undef),
247 $text{'index_sboot'.$svc->{'boot'}} ||
249 $text{'index_sstate'.$svc->{'state'}} ||
250 $svc->{'state_desc'},
253 print &ui_columns_end();
254 print &select_all_link("d"),"\n";
255 print &select_invert_link("d"),"<br>\n";
256 print &ui_form_end([ [ "start", $text{'index_start'} ],
257 [ "stop", $text{'index_stop'} ],
259 [ "addboot", $text{'index_addboot'} ],
260 [ "delboot", $text{'index_delboot'} ],
262 [ "addboot_start", $text{'index_addboot_start'} ],
263 [ "delboot_stop", $text{'index_delboot_stop'} ],
267 elsif ($init_mode eq "rc" && $access{'bootup'}) {
268 # Show FreeBSD scripts
269 print &ui_form_start("mass_rcs.cgi", "post");
270 @links = ( &select_all_link("d"),
271 &select_invert_link("d"),
272 "<a href='edit_rc.cgi?new=1'>$text{'index_radd'}</a>" );
273 print &ui_links_row(\@links);
274 print &ui_columns_start([ "", $text{'index_rname'},
275 $text{'index_rdesc'},
276 $text{'index_rboot'} ]);
277 foreach $rc (&list_rc_scripts()) {
278 print &ui_columns_row([
279 &ui_checkbox("d", $rc->{'name'}, undef),
280 "<a href='edit_rc.cgi?name=".
281 &urlize($rc->{'name'})."'>$rc->{'name'}</a>",
283 $rc->{'enabled'} == 1 ? $text{'yes'} :
284 $rc->{'enabled'} == 2 ? "<i>$text{'index_unknown'}</i>":
285 "<font color=#ff0000>$text{'no'}</font>",
288 print &ui_columns_end();
289 print &ui_links_row(\@links);
290 print &ui_form_end([ [ "start", $text{'index_start'} ],
291 [ "stop", $text{'index_stop'} ],
293 [ "addboot", $text{'index_addboot'} ],
294 [ "delboot", $text{'index_delboot'} ],
296 [ "addboot_start", $text{'index_addboot_start'} ],
297 [ "delboot_stop", $text{'index_delboot_stop'} ],
300 elsif ($init_mode eq "upstart" && $access{'bootup'}) {
301 # Show upstart actions
302 print &ui_form_start("mass_upstarts.cgi", "post");
303 @links = ( &select_all_link("d"),
304 &select_invert_link("d"),
305 "<a href='edit_upstart.cgi?new=1'>$text{'index_uadd'}</a>" );
306 print &ui_links_row(\@links);
307 print &ui_columns_start([ "", $text{'index_uname'},
308 $text{'index_udesc'},
309 $text{'index_uboot'},
310 $text{'index_ustatus'}, ]);
311 foreach $u (&list_upstart_services()) {
312 if ($u->{'legacy'}) {
313 $l = "edit_action.cgi?0+".&urlize($u->{'name'});
316 $l = "edit_upstart.cgi?name=".&urlize($u->{'name'});
318 print &ui_columns_row([
319 &ui_checkbox("d", $u->{'name'}, undef),
320 "<a href='$l'>$u->{'name'}</a>",
322 $u->{'boot'} eq 'start' ? $text{'yes'} :
323 $u->{'boot'} eq 'stop' ?
324 "<font color=#ff0000>$text{'no'}</font>" :
325 "<i>$text{'index_unknown'}</i>",
326 $u->{'status'} eq 'running' ? $text{'yes'} :
327 $u->{'status'} eq 'waiting' ?
328 "<font color=#ff0000>$text{'no'}</font>" :
329 "<i>$text{'index_unknown'}</i>",
332 print &ui_columns_end();
333 print &ui_links_row(\@links);
334 print &ui_form_end([ [ "start", $text{'index_start'} ],
335 [ "stop", $text{'index_stop'} ],
336 [ "restart", $text{'index_restart'} ],
338 [ "addboot", $text{'index_addboot'} ],
339 [ "delboot", $text{'index_delboot'} ],
341 [ "addboot_start", $text{'index_addboot_start'} ],
342 [ "delboot_stop", $text{'index_delboot_stop'} ],
347 # reboot/shutdown buttons
349 print &ui_buttons_start();
350 if ($init_mode eq 'init' && $access{'bootup'} == 1) {
351 print &ui_buttons_row("change_rl.cgi", $text{'index_rlchange'},
352 $text{'index_rlchangedesc'}, undef,
353 &ui_select("level", $boot[0], \@runlevels));
355 if ($access{'reboot'}) {
356 print &ui_buttons_row("reboot.cgi", $text{'index_reboot'},
357 $text{'index_rebootmsg'});
359 if ($access{'shutdown'}) {
360 print &ui_buttons_row("shutdown.cgi", $text{'index_shutdown'},
361 $text{'index_shutdownmsg'});
363 print &ui_buttons_end();
365 &ui_print_footer("/", $text{'index'});