Validate cron configuration
authorJamie Cameron <jcameron@webmin.com>
Mon, 25 Feb 2008 20:04:46 +0000 (20:04 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 25 Feb 2008 20:04:46 +0000 (20:04 +0000)
cron/CHANGELOG
cron/cron-lib.pl
cron/index.cgi
cron/lang/en

index 15065b6..b91623d 100644 (file)
@@ -25,3 +25,6 @@ Added a Module Config option to limit Cron jobs to hourly at most, thanks to Fil
 If there are more than 100 jobs (by default), a search form is shown on the main page instead of a list of all jobs.
 Re-wrote all user interface code to use the new Webmin UI library.
 Handle the daily / monthly / weekly Cron specification used on Ubuntu 7.
+---- Changes since 1.400 ----
+Fixed a bug that prevented new cron jobs from being created unless the 'Date range to execute' setting was changed.
+Added a check for a valid module configuration, especially the cron jobs directory, to prevent accidental deletion of jobs.
index c9e9c93..a5b73b4 100644 (file)
@@ -265,6 +265,7 @@ else {
 # Add a Cron job to a user's file
 sub create_cron_job
 {
+&check_cron_config_or_error();
 &list_cron_jobs();     # init cache
 if ($config{'single_file'} && !$config{'cron_dir'}) {
        # Add to the single file
@@ -292,6 +293,7 @@ else {
 # Add a Cron job at the top of the user's file
 sub insert_cron_job
 {
+&check_cron_config_or_error();
 &list_cron_jobs();     # init cache
 if ($config{'single_file'} && !$config{'cron_dir'}) {
        # Insert into single file
@@ -1080,5 +1082,32 @@ if ($job->{'comment'} =~ /\S/) {
 return 0;
 }
 
+# check_cron_config()
+# Returns an error message if the cron config doesn't look valid
+sub check_cron_config
+{
+# Check for single file and getter command
+if ($config{'single_file'} && !-r $config{'single_file'}) {
+       return &text('index_esingle', "<tt>$config{'single_file'}</tt>");
+       }
+if ($config{'cron_get_command'} =~ /^(\S+)/ && !&has_command("$1")) {
+       return &text('index_ecmd', "<tt>$1</tt>");
+       }
+# Check for directory
+local $fcron = ($config{'cron_dir'} =~ /\/fcron$/);
+if (!$single_user && !$fcron && !-d $config{'cron_dir'}) {
+       return &text('index_ecrondir', "<tt>$config{'cron_dir'}</tt>");
+       }
+return undef;
+}
+
+sub check_cron_config_or_error
+{
+local $err = &check_cron_config();
+if ($err) {
+       &error(&text('index_econfigcheck', $err));
+       }
+}
+
 1;
 
index 5f7fd2d..ae501b1 100755 (executable)
@@ -8,12 +8,7 @@ require './cron-lib.pl';
 $max_jobs = $userconfig{'max_jobs'} || $config{'max_jobs'};
 
 # Make sure cron is installed (very likely!)
-if ($config{'single_file'} && !-r $config{'single_file'}) {
-       $err = &text('index_esingle', "<tt>$config{'single_file'}</tt>");
-       }
-if ($config{'cron_get_command'} =~ /^(\S+)/ && !&has_command("$1")) {
-       $err = &text('index_ecmd', "<tt>$1</tt>");
-       }
+$err = &check_cron_config();
 if ($err) {
        print $err,"<p>\n";
        &ui_print_footer("/", $text{'index'});
index eae06ef..2f76e3f 100644 (file)
@@ -16,6 +16,7 @@ index_move=Move
 index_run=Running?
 index_ecmd=The command $1 for managing user Cron configurations was not found. Maybe Cron is not installed on this system?
 index_esingle=The file $1 listing Cron jobs does not exist. Maybe Cron is not installed on this system?
+index_ecrondir=The Cron jobs directory $1 does not exist. Maybe the module's configuration is incorrect, or Cron is not installed?
 index_delete=Delete Selected Jobs
 index_disable=Disable Selected Jobs
 index_enable=Enable Selected Jobs
@@ -24,6 +25,7 @@ index_toomany=There are too many jobs to show. Find those matching :
 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
 
 edit_title=Edit Cron Job
 create_title=Create Cron Job