Skip to content

Commit a8a3288

Browse files
committed
Create getmail cronjobs only if the getmail user exists.
1 parent 2c8f940 commit a8a3288

File tree

3 files changed

+64
-36
lines changed

3 files changed

+64
-36
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ public function install_crontab()
690690
exec('crontab -u root -l > crontab.txt');
691691
$existing_root_cron_jobs = file('crontab.txt');
692692

693+
// remove existing ispconfig cronjobs, in case the syntax has changed
694+
foreach($existing_root_cron_jobs as $key => $val) {
695+
if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
696+
}
697+
693698
$root_cron_jobs = array(
694699
'* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
695700
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
@@ -704,19 +709,27 @@ public function install_crontab()
704709
unlink('crontab.txt');
705710

706711
//* Getmail crontab
707-
$cf = $conf['getmail'];
708-
exec('crontab -u getmail -l > crontab.txt');
709-
$existing_cron_jobs = file('crontab.txt');
710-
711-
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null');
712-
foreach($cron_jobs as $cron_job) {
713-
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
714-
$existing_cron_jobs[] = $cron_job."\n";
712+
if(is_user('getmail')) {
713+
$cf = $conf['getmail'];
714+
exec('crontab -u getmail -l > crontab.txt');
715+
$existing_cron_jobs = file('crontab.txt');
716+
717+
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null');
718+
719+
// remove existing ispconfig cronjobs, in case the syntax has changed
720+
foreach($cron_jobs as $key => $val) {
721+
if(stristr($val,$cf['program'])) unset($cron_jobs[$key]);
715722
}
723+
724+
foreach($cron_jobs as $cron_job) {
725+
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
726+
$existing_cron_jobs[] = $cron_job."\n";
727+
}
728+
}
729+
file_put_contents('crontab.txt', $existing_cron_jobs);
730+
exec('crontab -u getmail crontab.txt &> /dev/null');
731+
unlink('crontab.txt');
716732
}
717-
file_put_contents('crontab.txt', $existing_cron_jobs);
718-
exec('crontab -u getmail crontab.txt &> /dev/null');
719-
unlink('crontab.txt');
720733
}
721734

722735
}

install/dist/lib/opensuse.lib.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ public function install_crontab()
708708
exec('crontab -u root -l > crontab.txt');
709709
$existing_root_cron_jobs = file('crontab.txt');
710710

711+
// remove existing ispconfig cronjobs, in case the syntax has changed
712+
foreach($existing_root_cron_jobs as $key => $val) {
713+
if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
714+
}
715+
711716
$root_cron_jobs = array(
712717
'* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
713718
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
@@ -722,19 +727,27 @@ public function install_crontab()
722727
unlink('crontab.txt');
723728

724729
//* Getmail crontab
725-
$cf = $conf['getmail'];
726-
exec('crontab -u getmail -l > crontab.txt');
727-
$existing_cron_jobs = file('crontab.txt');
728-
729-
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null');
730-
foreach($cron_jobs as $cron_job) {
731-
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
732-
$existing_cron_jobs[] = $cron_job."\n";
730+
if(is_user('getmail')) {
731+
$cf = $conf['getmail'];
732+
exec('crontab -u getmail -l > crontab.txt');
733+
$existing_cron_jobs = file('crontab.txt');
734+
735+
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null');
736+
737+
// remove existing ispconfig cronjobs, in case the syntax has changed
738+
foreach($cron_jobs as $key => $val) {
739+
if(stristr($val,$cf['program'])) unset($cron_jobs[$key]);
733740
}
741+
742+
foreach($cron_jobs as $cron_job) {
743+
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
744+
$existing_cron_jobs[] = $cron_job."\n";
745+
}
746+
}
747+
file_put_contents('crontab.txt', $existing_cron_jobs);
748+
exec('crontab -u getmail crontab.txt &> /dev/null');
749+
unlink('crontab.txt');
734750
}
735-
file_put_contents('crontab.txt', $existing_cron_jobs);
736-
exec('crontab -u getmail crontab.txt &> /dev/null');
737-
unlink('crontab.txt');
738751
}
739752

740753
}

install/lib/installer_base.lib.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -918,25 +918,27 @@ public function install_crontab()
918918
unlink('crontab.txt');
919919

920920
//* Getmail crontab
921-
$cf = $conf['getmail'];
922-
exec('crontab -u getmail -l > crontab.txt');
923-
$existing_cron_jobs = file('crontab.txt');
921+
if(is_user('getmail')) {
922+
$cf = $conf['getmail'];
923+
exec('crontab -u getmail -l > crontab.txt');
924+
$existing_cron_jobs = file('crontab.txt');
924925

925-
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null');
926+
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null');
926927

927-
// remove existing ispconfig cronjobs, in case the syntax has changed
928-
foreach($cron_jobs as $key => $val) {
929-
if(stristr($val,$cf['program'])) unset($cron_jobs[$key]);
930-
}
928+
// remove existing ispconfig cronjobs, in case the syntax has changed
929+
foreach($cron_jobs as $key => $val) {
930+
if(stristr($val,$cf['program'])) unset($cron_jobs[$key]);
931+
}
931932

932-
foreach($cron_jobs as $cron_job) {
933-
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
934-
$existing_cron_jobs[] = $cron_job."\n";
933+
foreach($cron_jobs as $cron_job) {
934+
if(!in_array($cron_job."\n", $existing_cron_jobs)) {
935+
$existing_cron_jobs[] = $cron_job."\n";
936+
}
935937
}
938+
file_put_contents('crontab.txt', $existing_cron_jobs);
939+
exec('crontab -u getmail crontab.txt &> /dev/null');
940+
unlink('crontab.txt');
936941
}
937-
file_put_contents('crontab.txt', $existing_cron_jobs);
938-
exec('crontab -u getmail crontab.txt &> /dev/null');
939-
unlink('crontab.txt');
940942
}
941943

942944
}

0 commit comments

Comments
 (0)