}
}
+=head2 cleanup_temp_files
+
+Called from cron to delete old files in the Webmin /tmp directory
+
+=cut
+sub cleanup_temp_files
+{
+# Don't run if disabled
+if (!$gconfig{'tempdelete_days'}) {
+ print STDERR "Temp file clearing is disabled\n";
+ return;
+ }
+if ($gconfig{'tempdir'} && !$gconfig{'tempdirdelete'}) {
+ print STDERR "Temp file clearing is not done for the custom directory $gconfig{'tempdir'}\n";
+ return;
+ }
+
+local $tempdir = &transname();
+$tempdir =~ s/\/([^\/]+)$//;
+if (!$tempdir || $tempdir eq "/") {
+ $tempdir = "/tmp/.webmin";
+ }
+
+local $cutoff = time() - $gconfig{'tempdelete_days'}*24*60*60;
+opendir(DIR, $tempdir);
+foreach my $f (readdir(DIR)) {
+ next if ($f eq "." || $f eq "..");
+ local @st = lstat("$tempdir/$f");
+ if ($st[9] < $cutoff) {
+ &unlink_file("$tempdir/$f");
+ }
+ }
+closedir(DIR);
+}
+
1;
sub module_install
{
-# Create a cron job to delete old files in /tmp/.webmin
+# Create a Webmin cron job to delete old files in /tmp/.webmin
eval {
$main::error_must_die = 1;
- local @jobs = &list_cron_jobs();
- local ($job) = grep { $_->{'user'} eq 'root' &&
- $_->{'command'} eq $temp_delete_cmd } @jobs;
- if (!$job) {
- $job = { 'user' => 'root',
- 'active' => 1,
- 'command' => $temp_delete_cmd,
- 'mins' => int(rand()*60),
- 'hours' => int(rand()*24),
- 'days' => '*',
- 'months' => '*',
- 'weekdays' => '*',
- 'comment' => 'Delete Webmin temporary files' };
- &unconvert_comment($job);
- &create_cron_job($job);
- &create_wrapper($temp_delete_cmd, $module_name,"tempdelete.pl");
- }
+ &foreign_require("webmincron");
+ local $cron = { 'module' => $module_name,
+ 'func' => 'cleanup_temp_files',
+ 'interval' => 60 };
+ &webmincron::create_webmin_cron($cron, $temp_delete_cmd);
};
if ($@) {
print STDERR "Failed to setup /tmp cleanup cron job : $@\n";
+++ /dev/null
-#!/usr/local/bin/perl
-# Delete any Webmin temp files older than 7 days
-
-$no_acl_check++;
-require './cron-lib.pl';
-
-if ($ARGV[0] eq "-debug" || $ARGV[0] eq "--debug") {
- shift(@ARGV);
- $debug = 1;
- }
-
-# Don't run if disabled
-if (!$gconfig{'tempdelete_days'}) {
- print "Temp file clearing is disabled\n";
- exit(0);
- }
-if ($gconfig{'tempdir'} && !$gconfig{'tempdirdelete'}) {
- print "Temp file clearing is not done for the custom directory $gconfig{'tempdir'}\n";
- exit(0);
- }
-
-$tempdir = &transname();
-$tempdir =~ s/\/([^\/]+)$//;
-if ($debug) {
- print "Checking temp directory $tempdir\n";
- }
-
-$cutoff = time() - $gconfig{'tempdelete_days'}*24*60*60;
-opendir(DIR, $tempdir);
-foreach my $f (readdir(DIR)) {
- next if ($f eq "." || $f eq "..");
- local @st = lstat("$tempdir/$f");
- if ($st[9] < $cutoff) {
- if ($debug) {
- print "Deleting $tempdir/$f\n";
- }
- &unlink_file("$tempdir/$f");
- }
- }
-closedir(DIR);
-
&lock_file($file);
&write_file($file, $cron);
&unlock_file($file);
+&reload_miniserv();
}
=head2 delete_webmin_cron(&cron)
&lock_file($file);
&unlink_file($file);
&unlock_file($file);
+&reload_miniserv();
}
=head2 create_webmin_cron(&cron, [old-cron-command])
foreach my $oc (@crons) {
next if ($oc->{'module'} ne $cron->{'module'});
next if ($oc->{'func'} ne $cron->{'func'});
+ my $sameargs = 1;
for(my $i=0; defined($oc->{'arg'.$i}) ||
- defined($cron->{'arg'.$i}); $i++) { }
- $already = $c;
+ defined($cron->{'arg'.$i}); $i++) {
+ $sameargs = 0 if ($oc->{'arg'.$i} ne $cron->{'arg'.$i});
+ }
+ next if (!$sameargs);
+ $already = $oc;
last;
}
if ($already) {