From 7a184506e71d93eb636e1d7fa827584cf70b7429 Mon Sep 17 00:00:00 2001 From: Gnadelwartz Date: Mon, 25 Dec 2017 16:00:37 +0000 Subject: [PATCH 1/3] enable webmin to edit user crontabs without crontab command --- cron/config.info | 1 + cron/config.info.de | 2 ++ cron/cron-lib.pl | 46 ++++++++++++++++++++++++++++++++------------- cron/lang/de | 3 ++- cron/lang/en | 1 + 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/cron/config.info b/cron/config.info index b5da54181..5f0797706 100644 --- a/cron/config.info +++ b/cron/config.info @@ -11,6 +11,7 @@ hourly_only=Only allow jobs to be at most hourly?,1,0-No,1-Yes add_file=Add new jobs to file,3,User's regular crontab file line2=System configuration,11 cron_dir=Crontab Directory,0 +cron_crontab=System has crontab command availible?,1,0-No, webmin processes user files itself,1-Yes, use following crontab commands for users: cron_get_command=Command to read a user's cron job,0 cron_edit_command=Command to edit a user's cron job,0 cron_copy_command=Command to accept a user's cron job on stdin,0 diff --git a/cron/config.info.de b/cron/config.info.de index 025e789bb..59df6a317 100644 --- a/cron/config.info.de +++ b/cron/config.info.de @@ -11,6 +11,7 @@ hourly_only=Cronjobs auf 1x pro Stunde begrenzen?,1,0-Nein,1-Ja add_file=Fügt neue Jobs zu Datei hinzu,3,Reguläre crontab-Datei line2=Systemkonfiguration,11 cron_dir=Crontab-Verzeichnis,0 +cron_crontab=Der Befehl crontab ist im Sytem vorhanden?=,1,1-Yes,0-No Gefährlich, Webmin bearbeitet Dateien direkt! cron_get_command=Befehl zum Lesen der Cron-Aufträge eines Benutzers,0 cron_edit_command=Befehl zum Bearbeiten der Cron-Aufträge eines Benutzers,0 cron_copy_command=Befehl zum Akzeptieren eines Cron-Auftrags eines Benutzers auf stdin,0 @@ -23,4 +24,5 @@ vixie_cron=Unterstützt Vixie-Cron-Erweiterungen,1,1-Ja,0-Nein system_crontab=Pfad zur Vixie-Cron System Crontab-Datei,0 single_file=Pfad zur Single-User-crontab-Datei,0 cronfiles_dir=Pfad zum Verzeichnis mit zusätzlichen Cron-Dateien,3,Keiner +cron_crontab=Befehl crontab ist im Sytem verfügbar?,1,0-Nein, Webmin bearbeitet Benutzer Dateien selbst,1-Ja, nutze folgende Befehle für Benutzer: run_parts=run-parts Befehl,0 diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index ba65479fa..f631840b1 100755 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -281,7 +281,8 @@ else { $_[0]->{'type'} != 3); push(@c, $_[0]->{'command'}); } -return join(" ", @c); + # fix: some older/embedded crond needs tab instead of spaces +return join("\t", @c); } =head2 copy_cron_temp(&job) @@ -489,7 +490,13 @@ local($pwd); if (&read_file_contents($cron_temp_file) =~ /\S/) { local $temp = &transname(); local $rv; - if ($config{'cron_edit_command'}) { + if (!$config{'cron_crontab'}) { + # we have no crontab command + # emulate by copy back to user file + $rv = system("cat $cron_temp_file". + " >$config{'cron_dir'}/$_[0] 2>/dev/null"); + + } elsif ($config{'cron_edit_command'}) { # fake being an editor # XXX does not work in translated command mode! local $notemp = &transname(); @@ -515,8 +522,8 @@ if (&read_file_contents($cron_temp_file) =~ /\S/) { } unlink($notemp); chdir($oldpwd); - } - else { + + } else { # use the cron copy command if ($single_user) { $rv = &execute_command( @@ -528,7 +535,7 @@ if (&read_file_contents($cron_temp_file) =~ /\S/) { &user_sub($config{'cron_copy_command'}, $_[0]), $cron_temp_file, $temp, $temp); } - } + } local $out = &read_file_contents($temp); unlink($temp); if ($rv || $out =~ /error/i) { @@ -538,14 +545,22 @@ if (&read_file_contents($cron_temp_file) =~ /\S/) { } else { # No more cron jobs left, so just delete - if ($single_user) { - &execute_command($config{'cron_user_delete_command'}); - } - else { - &execute_command(&user_sub( - $config{'cron_delete_command'}, $_[0])); + if (!$config{'cron_crontab'}) { + # we have no crontab command + # emulate by deleting user crontab + $rv = system("rm >$config{'cron_dir'}/$_[0] 2>/dev/null"); + + } else { + if ($single_user) { + &execute_command($config{'cron_user_delete_command'}); + } + else { + &execute_command(&user_sub( + $config{'cron_delete_command'}, $_[0])); + } } } +if (!$config{'cron_crontab'}) { &kill_byname("crond", "SIGHUP"); } # to reload config unlink($cron_temp_file); } @@ -1508,14 +1523,19 @@ sub check_cron_config if ($config{'single_file'} && !-r $config{'single_file'}) { return &text('index_esingle', "$config{'single_file'}"); } -if ($config{'cron_get_command'} =~ /^(\S+)/ && !&has_command("$1")) { +if (!$config{'cron_crontab'} && $config{'cron_get_command'} =~ /^(\S+)/ && !&has_command("$1")) { return &text('index_ecmd', "$1"); } # Check for directory local $fcron = ($config{'cron_dir'} =~ /\/fcron$/); if (!$single_user && !$config{'single_file'} && !$fcron && !-d $config{'cron_dir'}) { - return &text('index_ecrondir', "$config{'cron_dir'}"); + if (!$in{'create_dir'}) { + return &text('index_ecrondir', "$config{'cron_dir'}"). + "

".&text('index_ecrondir_create' ,"$config{'cron_dir'}")."

"; + } else { + system("mkdir $config{'cron_dir'}"); + } } return undef; } diff --git a/cron/lang/de b/cron/lang/de index 9bbd7d4c4..d6cf8f626 100644 --- a/cron/lang/de +++ b/cron/lang/de @@ -87,7 +87,8 @@ index_disable=Deaktiviere ausgewählte Aufträge index_ecmd=Das Kommando $1 um Cron Benutzer Konfigurationen zu bearbeiten wurde nicht gefunden. Vielleicht ist Cron nicht auf Ihrem System installiert? index_econfigcheck=Cron Aufträge können auf Ihrem System nicht gesteuert werden, weil die Modul-Konfiguration nicht gültig ist. index_ecreate=Eine neue Umgebungsvariable erzeugen. -index_ecrondir=Das Cron Aufträge Verzeichnis existiert nicht. Vielleicht ist die Modul-Konfiguration falsch oder Cron ist nicht installiert? +index_ecrondir=Das Cron Aufträge Verzeichnis $1 existiert nicht. Vielleicht ist die Modul-Konfiguration falsch oder Cron ist nicht installiert? +index_ecrondir_create=Versuchen Verzeichnis $1 zu erstellen? index_enable=Aktiviere ausgewählte Aufträge index_env=Umgebungsvariable index_esearch=Keine Aufträge für Ihre Suche nach $1 gefunden. diff --git a/cron/lang/en b/cron/lang/en index dc018c8ea..18d9aeefe 100644 --- a/cron/lang/en +++ b/cron/lang/en @@ -18,6 +18,7 @@ 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_ecrondir_create=Try to create jobs directory $1 ? index_delete=Delete Selected Jobs index_disable=Disable Selected Jobs index_enable=Enable Selected Jobs From 4d13ad56edef824f2633d44a95b306845dd4bc93 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (hc)" Date: Mon, 25 Dec 2017 17:07:52 +0100 Subject: [PATCH 2/3] fix double entry in config-info.de --- cron/config.info.de | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cron/config.info.de b/cron/config.info.de index 59df6a317..d7fdc29a0 100644 --- a/cron/config.info.de +++ b/cron/config.info.de @@ -11,7 +11,7 @@ hourly_only=Cronjobs auf 1x pro Stunde begrenzen?,1,0-Nein,1-Ja add_file=Fügt neue Jobs zu Datei hinzu,3,Reguläre crontab-Datei line2=Systemkonfiguration,11 cron_dir=Crontab-Verzeichnis,0 -cron_crontab=Der Befehl crontab ist im Sytem vorhanden?=,1,1-Yes,0-No Gefährlich, Webmin bearbeitet Dateien direkt! +cron_crontab=Befehl crontab ist im Sytem verfügbar?,1,0-Nein, Webmin bearbeitet Benutzer Dateien selbst,1-Ja, nutze folgende Befehle für Benutzer: cron_get_command=Befehl zum Lesen der Cron-Aufträge eines Benutzers,0 cron_edit_command=Befehl zum Bearbeiten der Cron-Aufträge eines Benutzers,0 cron_copy_command=Befehl zum Akzeptieren eines Cron-Auftrags eines Benutzers auf stdin,0 @@ -24,5 +24,4 @@ vixie_cron=Unterstützt Vixie-Cron-Erweiterungen,1,1-Ja,0-Nein system_crontab=Pfad zur Vixie-Cron System Crontab-Datei,0 single_file=Pfad zur Single-User-crontab-Datei,0 cronfiles_dir=Pfad zum Verzeichnis mit zusätzlichen Cron-Dateien,3,Keiner -cron_crontab=Befehl crontab ist im Sytem verfügbar?,1,0-Nein, Webmin bearbeitet Benutzer Dateien selbst,1-Ja, nutze folgende Befehle für Benutzer: run_parts=run-parts Befehl,0 From 4dc1c96843fddf737195d8c6fea37dbf8f8b2b2e Mon Sep 17 00:00:00 2001 From: Gnadelwartz Date: Tue, 26 Dec 2017 07:40:56 +0000 Subject: [PATCH 3/3] use webmin provided functions instead of system --- cron/cron-lib.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index f631840b1..ad98f62f0 100755 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -548,7 +548,7 @@ else { if (!$config{'cron_crontab'}) { # we have no crontab command # emulate by deleting user crontab - $rv = system("rm >$config{'cron_dir'}/$_[0] 2>/dev/null"); + &unlink_logged("$config{'cron_dir'}/$_[0]"); } else { if ($single_user) { @@ -1534,7 +1534,7 @@ if (!$single_user && !$config{'single_file'} && return &text('index_ecrondir', "$config{'cron_dir'}"). "

".&text('index_ecrondir_create' ,"$config{'cron_dir'}")."

"; } else { - system("mkdir $config{'cron_dir'}"); + &make_dir($config{'cron_dir'}, 0755); } } return undef;