Add stop/start buttons

This commit is contained in:
Jamie Cameron
2021-12-31 23:11:53 -08:00
parent 8a51d178df
commit b8d5b7afde
14 changed files with 105 additions and 4 deletions

View File

@@ -45,3 +45,5 @@ Added buttons to move cron jobs to the top and bottom of the list.
Added a page for manually editing cron jobs.
---- Changes since 1.900 ----
The next run time of each cron job can be displayed by enable a new config option.
---- Changes since 1.980 ----
Added buttons to stop and start crond on the main page.

View File

@@ -56,6 +56,10 @@ print &ui_table_row($text{'acl_hourly'},
&ui_radio("hourly", $_[0]->{'hourly'},
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ],
[ 2, $text{'acl_hourlydef'} ] ]), 3);
print &ui_table_row($text{'acl_stop'},
&ui_radio("stop", $_[0]->{'stop'},
[ [ 1, $text{'yes'} ], [ 0, $text{'no'} ] ]));
}
# acl_security_save(&options)
@@ -77,5 +81,6 @@ $_[0]->{'delete'} = $in{'delete'};
$_[0]->{'move'} = $in{'move'};
$_[0]->{'kill'} = $in{'kill'};
$_[0]->{'hourly'} = $in{'hourly'};
$_[0]->{'stop'} = $in{'stop'};
}

17
cron/bootup.cgi Executable file
View File

@@ -0,0 +1,17 @@
#!/usr/local/bin/perl
# Enable or disable crond at boot time
require './cron-lib.pl';
&ReadParse();
&foreign_require("init");
$access{'stop'} || &error($text{'bootup_ecannot'});
$init = $config{'init_name'};
if ($in{'boot'}) {
&init::enable_at_boot($init);
}
else {
&init::disable_at_boot($init);
}
&webmin_log($in{'boot'} ? "bootup" : "bootdown");
&redirect("");

View File

@@ -21,3 +21,4 @@ show_comment=0
hourly_only=0
max_jobs=100
show_next=0
init_name=cron

View File

@@ -23,3 +23,4 @@ show_comment=0
hourly_only=0
max_jobs=100
show_next=0
init_name=cron

View File

@@ -23,3 +23,4 @@ show_comment=0
hourly_only=0
max_jobs=100
show_next=0
init_name=crond

View File

@@ -25,3 +25,4 @@ system_crontab=Path to Vixie-Cron system crontab file,0
single_file=Path to single user crontab file,0
cronfiles_dir=Path to extra cron files directory,3,None
run_parts=run-parts command,0
init_name=Cron daemon bootup action name,3,None exists

View File

@@ -8,3 +8,4 @@ delete=1
move=1
kill=1
hourly=2
stop=1

View File

@@ -286,5 +286,34 @@ else {
print &ui_links_row(\@crlinks);
}
# If there is an init script that runs crond, show status
&foreign_require("init");
my $init = $config{'init_name'};
my $atboot;
if ($access{'stop'} && $init && ($atboot = &init::action_status($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?
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'});

View File

@@ -31,6 +31,12 @@ index_ok=Search
index_searchres=Cron jobs matching $1 ..
index_reset=Reset search.
index_econfigcheck=Cron jobs cannot be managed on your system, as the module configuration is not valid : $1
index_stop=Stop Cron Daemon
index_stopdesc=Shut down the <tt>crond</tt> background server process that runs scheduled cron jobs. This will prevent commands from executing at their specified times.
index_start=Start Cron Daemon
index_startdesc=Start up the <tt>crond</tt> background server process that runs scheduled cron jobs. This is required for commands to execute at their specified times.
index_boot=Start Cron Daemon Boot?
index_bootdesc=Change this setting to enable or disable starting the scheduled cron jobs daemon at system boot time.
edit_title=Edit Cron Job
create_title=Create Cron Job
@@ -128,6 +134,7 @@ acl_move=Can move Cron jobs?
acl_kill=Can terminate Cron jobs?
acl_hourly=Limit jobs to at most hourly?
acl_hourlydef=As set in Module Config
acl_stop=Can stop and start the Cron daemon?
log_modify=Modified Cron job for $1
log_modify_l=Modified Cron job "$2" for $1
@@ -146,6 +153,10 @@ log_move=Moved Cron job for $1
log_crons_delete=Deleted $1 Cron jobs
log_crons_disable=Disabled $1 Cron jobs
log_crons_enable=Enabled $1 Cron jobs
log_stop=Stopped cron daemon
log_start=Started cron daemon
log_bootup=Enabled cron daemon at boot
log_bootdown=Disabled cron daemon at boot
ecopy=An error was detected in the new Cron configuration : $1 $2
@@ -195,4 +206,10 @@ manual_editing=Use the text box below to edit Cron jobs in $1. Be careful, as no
manual_efile=Selected file is not valid!
manual_ecannot=You are not allowed to manually edit cron jobs
stop_err=Failed to stop daemon
start_err=Failed to start daemon
stop_ecannot=You are not allowed to stop the daemon
start_ecannot=You are not allowed to start the daemon
bootup_ecannot=You are not allowed to enable the daemon at boot
__norefs=1

View File

@@ -37,11 +37,8 @@ elsif ($action eq 'exec' || $action eq 'kill') {
"<tt>$object</tt>",
"<tt>".&html_escape($p->{'command'})."</tt>");
}
elsif ($action eq 'allow') {
return $text{'log_allow'};
}
else {
return undef;
return $text{'log_'.$action};
}
}

1
cron/negativeacl Normal file
View File

@@ -0,0 +1 @@
stop=0

14
cron/start.cgi Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/local/bin/perl
# Start crond
require './cron-lib.pl';
&error_setup($text{'start_err'});
$access{'stop'} || &error($text{'start_ecannot'});
&foreign_require("init");
my $init = $config{'init_name'};
my ($ok, $err) = &init::start_action($init);
&error($err) if (!$ok);
&webmin_log("start");
&redirect("");

14
cron/stop.cgi Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/local/bin/perl
# Stop crond
require './cron-lib.pl';
&error_setup($text{'stop_err'});
$access{'stop'} || &error($text{'stop_ecannot'});
&foreign_require("init");
my $init = $config{'init_name'};
my ($ok, $err) = &init::stop_action($init);
&error($err) if (!$ok);
&webmin_log("stop");
&redirect("");