From 14c86dfab0e9856a1aaaf345a5d655201eb9b2bf Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 27 Aug 2007 04:38:04 +0000 Subject: [PATCH] Added cron job to cleanup /tmp/.webmin --- config-aix | 1 + config-cobalt-linux | 1 + config-coherent-linux | 1 + config-corel-linux | 1 + config-debian-linux | 1 + config-freebsd | 1 + config-generic-linux | 1 + config-gentoo-linux | 1 + config-hpux | 1 + config-irix | 1 + config-lib.pl | 2 -- config-macos | 1 + config-mandrake-linux | 1 + config-msc-linux | 1 + config-netbsd | 1 + config-open-linux | 1 + config-openbsd | 1 + config-openmamba-linux | 10 ++++++++++ config-openserver | 1 + config-osf1 | 1 + config-redhat-linux | 1 + config-slackware-linux | 1 + config-sol-linux | 1 + config-solaris | 1 + config-suse-linux | 1 + config-trustix-linux | 1 + config-turbo-linux | 1 + config-united-linux | 1 + config-unixware | 1 + config-windows | 1 + cron/cron-lib.pl | 1 + cron/postinstall.pl | 30 ++++++++++++++++++++++++++++ cron/tempdelete.pl | 41 ++++++++++++++++++++++++++++++++++++++ cron/uninstall.pl | 21 +++++++++++++++++++ webmin/CHANGELOG | 2 ++ webmin/change_advanced.cgi | 11 ++++++++++ webmin/edit_advanced.cgi | 10 +++++++++- webmin/lang/en | 5 +++++ 38 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 config-openmamba-linux create mode 100644 cron/postinstall.pl create mode 100644 cron/tempdelete.pl create mode 100644 cron/uninstall.pl diff --git a/config-aix b/config-aix index e1ab67af0..af95a258a 100644 --- a/config-aix +++ b/config-aix @@ -5,3 +5,4 @@ by_view=0 passwd_file=/etc/security/passwd passwd_uindex=0 passwd_pindex=1 +tempdelete_days=7 diff --git a/config-cobalt-linux b/config-cobalt-linux index d91998298..962fac8be 100644 --- a/config-cobalt-linux +++ b/config-cobalt-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-coherent-linux b/config-coherent-linux index d91998298..962fac8be 100644 --- a/config-coherent-linux +++ b/config-coherent-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-corel-linux b/config-corel-linux index d91998298..962fac8be 100644 --- a/config-corel-linux +++ b/config-corel-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-debian-linux b/config-debian-linux index d91998298..962fac8be 100644 --- a/config-debian-linux +++ b/config-debian-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-freebsd b/config-freebsd index b6a94fc12..5e7c0ae6b 100644 --- a/config-freebsd +++ b/config-freebsd @@ -5,3 +5,4 @@ passwd_file=/etc/master.passwd passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-generic-linux b/config-generic-linux index d91998298..962fac8be 100644 --- a/config-generic-linux +++ b/config-generic-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-gentoo-linux b/config-gentoo-linux index d91998298..962fac8be 100644 --- a/config-gentoo-linux +++ b/config-gentoo-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-hpux b/config-hpux index 3e1e7a66a..70a142b38 100644 --- a/config-hpux +++ b/config-hpux @@ -5,3 +5,4 @@ passwd_file=/etc/passwd passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-irix b/config-irix index 038a99779..296d4715f 100644 --- a/config-irix +++ b/config-irix @@ -6,3 +6,4 @@ passwd_file=/etc/passwd passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-lib.pl b/config-lib.pl index dcf21250b..4a78f8ea2 100644 --- a/config-lib.pl +++ b/config-lib.pl @@ -351,7 +351,5 @@ foreach my $c (@$info_order) { return @new_order; } - - 1; diff --git a/config-macos b/config-macos index 4dde761a8..79ec4a6d4 100644 --- a/config-macos +++ b/config-macos @@ -5,3 +5,4 @@ passwd_file=nidump passwd . | passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-mandrake-linux b/config-mandrake-linux index d91998298..962fac8be 100644 --- a/config-mandrake-linux +++ b/config-mandrake-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-msc-linux b/config-msc-linux index d91998298..962fac8be 100644 --- a/config-msc-linux +++ b/config-msc-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-netbsd b/config-netbsd index e204beab6..4e13a7a46 100644 --- a/config-netbsd +++ b/config-netbsd @@ -5,3 +5,4 @@ passwd_file=/etc/master.passwd passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-open-linux b/config-open-linux index d91998298..962fac8be 100644 --- a/config-open-linux +++ b/config-open-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-openbsd b/config-openbsd index 0d8071a76..8f4ca83d2 100644 --- a/config-openbsd +++ b/config-openbsd @@ -6,3 +6,4 @@ passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-openmamba-linux b/config-openmamba-linux new file mode 100644 index 000000000..962fac8be --- /dev/null +++ b/config-openmamba-linux @@ -0,0 +1,10 @@ +find_pid_command=ps auwwwx | grep NAME | grep -v grep | awk '{ print $2 }' +path=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin +ld_env=LD_LIBRARY_PATH +passwd_file=/etc/shadow +passwd_uindex=0 +passwd_pindex=1 +passwd_cindex=2 +passwd_mindex=4 +by_view=0 +tempdelete_days=7 diff --git a/config-openserver b/config-openserver index cc343f9d9..19e718327 100644 --- a/config-openserver +++ b/config-openserver @@ -6,3 +6,4 @@ passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-osf1 b/config-osf1 index 50bf57784..91f89100a 100644 --- a/config-osf1 +++ b/config-osf1 @@ -6,3 +6,4 @@ passwd_file=/etc/shadow passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-redhat-linux b/config-redhat-linux index d91998298..962fac8be 100644 --- a/config-redhat-linux +++ b/config-redhat-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-slackware-linux b/config-slackware-linux index f3e8d4279..ae796c662 100644 --- a/config-slackware-linux +++ b/config-slackware-linux @@ -8,3 +8,4 @@ passwd_cindex=2 passwd_mindex=4 by_view=0 no_hostname_f=1 +tempdelete_days=7 diff --git a/config-sol-linux b/config-sol-linux index d91998298..962fac8be 100644 --- a/config-sol-linux +++ b/config-sol-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-solaris b/config-solaris index d51513c68..6821580e5 100644 --- a/config-solaris +++ b/config-solaris @@ -8,3 +8,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-suse-linux b/config-suse-linux index d91998298..962fac8be 100644 --- a/config-suse-linux +++ b/config-suse-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-trustix-linux b/config-trustix-linux index d91998298..962fac8be 100644 --- a/config-trustix-linux +++ b/config-trustix-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-turbo-linux b/config-turbo-linux index d91998298..962fac8be 100644 --- a/config-turbo-linux +++ b/config-turbo-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-united-linux b/config-united-linux index d91998298..962fac8be 100644 --- a/config-united-linux +++ b/config-united-linux @@ -7,3 +7,4 @@ passwd_pindex=1 passwd_cindex=2 passwd_mindex=4 by_view=0 +tempdelete_days=7 diff --git a/config-unixware b/config-unixware index 5dba40834..c6fefad8b 100644 --- a/config-unixware +++ b/config-unixware @@ -6,3 +6,4 @@ passwd_file=/etc/shadow passwd_uindex=0 passwd_pindex=1 by_view=0 +tempdelete_days=7 diff --git a/config-windows b/config-windows index e94c6dab6..b480179e3 100644 --- a/config-windows +++ b/config-windows @@ -1,2 +1,3 @@ path=c:/perl/bin;c:/windows/system32;c:/windows tempdir=c:/webmintemp +tempdelete_days=7 diff --git a/cron/cron-lib.pl b/cron/cron-lib.pl index 5c4d0c704..f10713952 100644 --- a/cron/cron-lib.pl +++ b/cron/cron-lib.pl @@ -16,6 +16,7 @@ if ($module_info{'usermin'}) { else { $range_cmd = "$module_config_directory/range.pl"; } +$temp_delete_cmd = "$module_config_directory/tempdelete.pl"; $cron_temp_file = &transname(); use Time::Local; diff --git a/cron/postinstall.pl b/cron/postinstall.pl new file mode 100644 index 000000000..5728ba38f --- /dev/null +++ b/cron/postinstall.pl @@ -0,0 +1,30 @@ + +require 'cron-lib.pl'; + +sub module_install +{ +# Create a cron job to delete old files in /tmp/.webmin +eval { + $main::error_must_die = 1; + local @jobs = &cron::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' => '*', }; + &create_cron_job($job); + &create_wrapper($temp_delete_cmd, $module_name,"tempdelete.pl"); + } + }; +if ($@) { + print STDERR "Failed to setup /tmp cleanup cron job : $@\n"; + } +} + + diff --git a/cron/tempdelete.pl b/cron/tempdelete.pl new file mode 100644 index 000000000..fe1f1b17e --- /dev/null +++ b/cron/tempdelete.pl @@ -0,0 +1,41 @@ +#!/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'}) { + 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); + diff --git a/cron/uninstall.pl b/cron/uninstall.pl new file mode 100644 index 000000000..325ad8167 --- /dev/null +++ b/cron/uninstall.pl @@ -0,0 +1,21 @@ + +require 'cron-lib.pl'; + +sub module_uninstall +{ +# Remove the cron job to delete old files in /tmp/.webmin +eval { + $main::error_must_die = 1; + local @jobs = &cron::list_cron_jobs(); + local ($job) = grep { $_->{'user'} eq 'root' && + $_->{'command'} eq $temp_delete_cmd } @jobs; + if ($job) { + &delete_cron_job($job); + } + }; +if ($@) { + print STDERR "Failed to remove /tmp cleanup cron job : $@\n"; + } +} + + diff --git a/webmin/CHANGELOG b/webmin/CHANGELOG index 9fab0e234..8d787bd56 100644 --- a/webmin/CHANGELOG +++ b/webmin/CHANGELOG @@ -64,3 +64,5 @@ Added a tab showing details of the current cert, with a link to download in PEM Added an option to the Authentication page to block users with too many failed logins, as well as hosts. Created the new Blocked Hosts and Users page to show blocks currently in force, and allow them to be cleared. Added an option to the Ports and Addresses page to control if Webmin attempts to to reverse-resolve the connected-to IP address when issuing redirects, such as from non-SSL to SSL mode. +---- Changes since 1.360 ---- +Added a field to the Advanced Options page to control the number of days that files in /tmp/.webmin are kept before automatic deletion. diff --git a/webmin/change_advanced.cgi b/webmin/change_advanced.cgi index 9179fcb40..38e970fe6 100755 --- a/webmin/change_advanced.cgi +++ b/webmin/change_advanced.cgi @@ -15,6 +15,17 @@ else { $gconfig{'tempdir'} = $in{'tempdir'}; } +# Save temp clearing options +$gconfig{'tempdirdelete'} = $in{'tempdirdelete'}; +if ($in{'tempdelete_def'}) { + $gconfig{'tempdelete_days'} = ''; + } +else { + $in{'tempdelete'} =~ /^[0-9\.]+$/ || + &error($text{'advanced_etempdelete'}); + $gconfig{'tempdelete_days'} = $in{'tempdelete'}; + } + # Save per-module temp dirs for($i=0; defined($tmod = $in{'tmod_'.$i}); $i++) { next if (!$tmod); diff --git a/webmin/edit_advanced.cgi b/webmin/edit_advanced.cgi index 19b0d3655..26abe675b 100755 --- a/webmin/edit_advanced.cgi +++ b/webmin/edit_advanced.cgi @@ -11,7 +11,15 @@ print &ui_table_start($text{'advanced_header'}, undef, 2); # Global temp directory print &ui_table_row($text{'advanced_temp'}, &ui_opt_textbox("tempdir", $gconfig{'tempdir'}, - 30, $text{'advanced_tempdef'})); + 30, $text{'advanced_tempdef'})."
". + &ui_checkbox("tempdirdelete", 1, $text{'advanced_tdd'}, + $gconfig{'tempdirdelete'})); + +# Temp files clearing period +print &ui_table_row($text{'advanced_tempdelete'}, + &ui_opt_textbox("tempdelete", $gconfig{'tempdelete_days'}, + 5, $text{'advanced_nodelete'})." ". + $text{'advanced_days'}); # Per-module temp directories @mods = sort { $a->{'desc'} cmp $b->{'desc'} } &get_all_module_infos(); diff --git a/webmin/lang/en b/webmin/lang/en index c69724f88..6c40fd59a 100644 --- a/webmin/lang/en +++ b/webmin/lang/en @@ -720,6 +720,10 @@ advanced_title=Advanced Options advanced_header=Advanced and experimental options advanced_temp=Temporary files directory advanced_tempdef=Default (/tmp/.webmin) +advanced_tdd=Clear temp files in non-standard directory? +advanced_tempdelete=Maximum age of temporary files +advanced_nodelete=Unlimited +advanced_days=days advanced_preload=Pre-load Webmin functions library? advanced_err=Failed to save advanced options advanced_etemp=Missing or non-existant temporary files directory @@ -732,6 +736,7 @@ advanced_stack=Show stack trace for error messages? advanced_showstderr=Show Perl errors in browser? advanced_umask=Umask (unset permission bits) for created files advanced_eumask=Umask must be a 3-digit octal number +advanced_etempdelete=Missing or invalid maximum age of temporary files syslog_errorlog=Webmin error log