From 44b35a85dd7fcfea423a86b91272422acc413f6b Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 12 Jul 2011 16:48:38 -0700 Subject: [PATCH] Fix save and run cron job when changing user http://www.virtualmin.com/node/18806 --- cron/cron-lib.pl | 3 ++- cron/lang/en | 1 + cron/save_cron.cgi | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index d6216c36c..daafd48af 100755 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -338,7 +338,8 @@ else { $_[0]->{'line'} = scalar(@$lref); push(@$lref, &cron_job_line($_[0])); &flush_file_lines(); - system("chown $_[0]->{'user'} $cron_temp_file"); + &set_ownership_permissions($_[0]->{'user'}, undef, undef, + $cron_temp_file); ©_crontab($_[0]->{'user'}); $_[0]->{'file'} = "$config{'cron_dir'}/$_[0]->{'user'}"; $_[0]->{'index'} = scalar(@cron_jobs_cache); diff --git a/cron/lang/en b/cron/lang/en index c1d697374..064a30b60 100644 --- a/cron/lang/en +++ b/cron/lang/en @@ -75,6 +75,7 @@ save_eallow=The user '$1' is not allowed to access cron save_ecannot=You are not allowed to create or edit cron jobs for '$1' save_enone=You did not choose any $1 to execute save_ecannot2=You are not allowed to create cron jobs +save_eidx=Cron job was successfully saved, but cannot be run as it was not found! allow_title=Control Cron Access allow_desc=This form allows you to control which users can create and run cron jobs. diff --git a/cron/save_cron.cgi b/cron/save_cron.cgi index 54b1032db..7a13f0cf6 100755 --- a/cron/save_cron.cgi +++ b/cron/save_cron.cgi @@ -79,6 +79,17 @@ if (!$in{'new'}) { else { &delete_cron_job($oldjob); &create_cron_job($job); + + # Find new index, which will change due to user move + undef(@cron_jobs_cache); + $in{'idx'} = undef; + foreach $newjob (&list_cron_jobs()) { + if ($newjob->{'user'} eq $job->{'user'} && + $newjob->{'active'} eq $job->{'active'} && + $newjob->{'command'} eq $job->{'command'}) { + $in{'idx'} = $newjob->{'index'}; + } + } } } else { @@ -96,6 +107,7 @@ else { if ($in{'saverun'}) { # Redirect to execute form + defined($in{'idx'}) || &error($text{'save_eidx'}); &redirect("exec_cron.cgi?idx=$in{'idx'}"); } else {