diff --git a/at/at-lib.pl b/at/at-lib.pl index 1c8d8fe31..0dfc658c6 100755 --- a/at/at-lib.pl +++ b/at/at-lib.pl @@ -153,5 +153,18 @@ else { } } +# get_init_status() +# If the init module is installed and there is an atd bootup action, return +# its name, current running status and boot status +sub get_init_status +{ +return () if (!&foreign_available("init")); +my $init = defined(&get_init_name) ? &get_init_name() : undef; +return () if (!$init); +my $r = &init::status_action($init); +my $atboot = &init::action_status($init); +return ($init, $r, $atboot); +} + 1; diff --git a/at/index.cgi b/at/index.cgi index a6bf3e612..45b711c21 100755 --- a/at/index.cgi +++ b/at/index.cgi @@ -138,34 +138,31 @@ if ($access{'allow'} && $config{'allow_file'}) { } # If there is an init script that runs an atd server, show status -if (&foreign_available("init")) { - &foreign_require("init"); - my $init = defined(&get_init_name) ? &get_init_name() : undef; - if ($access{'stop'} && $init) { - print &ui_hr(); - print &ui_buttons_start(); +my ($init, $r, $atboot) = &get_init_status(); +if ($access{'stop'} && $init) { + print &ui_hr(); + print &ui_buttons_start(); - # Running now? - my $r = &init::status_action($init); - if ($r == 1) { - print &ui_buttons_row("stop.cgi", $text{'index_stop'}, - $text{'index_stopdesc'}); - } - elsif ($r == 0) { - print &ui_buttons_row("start.cgi", $text{'index_start'}, - $text{'index_startdesc'}); - } - - # Start at boot? - my $atboot = &init::action_status($init); - print &ui_buttons_row("bootup.cgi", $text{'index_boot'}, - $text{'index_bootdesc'}, undef, - &ui_radio("boot", $atboot == 2 ? 1 : 0, - [ [ 1, $text{'yes'} ], - [ 0, $text{'no'} ] ])); - - print &ui_buttons_end(); + # Running now? + my $r = &init::status_action($init); + if ($r == 1) { + print &ui_buttons_row("stop.cgi", $text{'index_stop'}, + $text{'index_stopdesc'}); } + elsif ($r == 0) { + print &ui_buttons_row("start.cgi", $text{'index_start'}, + $text{'index_startdesc'}); + } + + # Start at boot? + my $atboot = &init::action_status($init); + print &ui_buttons_row("bootup.cgi", $text{'index_boot'}, + $text{'index_bootdesc'}, undef, + &ui_radio("boot", $atboot == 2 ? 1 : 0, + [ [ 1, $text{'yes'} ], + [ 0, $text{'no'} ] ])); + + print &ui_buttons_end(); } &ui_print_footer("/", $text{'index'});