home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / maintain.pl < prev    next >
Text File  |  2009-11-06  |  4KB  |  115 lines

  1. # FILE: maintain.pl
  2. # DESCRIPTION: Maintenance subroutines
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### cleaning_jobs
  20. ###
  21. ### Cleans up old junk in directories (temp files, old search results, etc.)
  22. ### when invoked from resource-nonintensive activities
  23. ###
  24.  
  25. sub cleaning_jobs {
  26.     my $set;
  27.     if (!($set = shift @_)) {
  28.         my $proc = $$;
  29.         $proc =~ s/\D//g;
  30.         $proc = int(rand(100)) if $proc == 0;
  31.         $set = $proc % 3;
  32.     }
  33.     if ($set == 0) {
  34.         cleaning_remove_old_files("$DCONF->{admin_dir}/msg_index/searches", '^\d+\.txt$', 2, 0);
  35.         cleaning_remove_old_files("$DCONF->{admin_dir}/backups", '^\w+-\d+\.conf$', 14*24, 0);
  36.         cleaning_remove_old_files("$DCONF->{admin_dir}/msg_index/temp", '^\d+\.TMP$', 48, 0);
  37.         cleaning_remove_old_files("$DCONF->{admin_dir}/msg_index/uploads", '^\d+\.\w+\-?\d*$', 48, 0);
  38.     }
  39.     if ($set == 1) {
  40.         cleaning_remove_old_files("$DCONF->{admin_dir}/backups", '\.TMP$', 3*24, 0);
  41.         cleaning_remove_old_files("$DCONF->{admin_dir}/msg_index", '\.TMP$', 3, 0);
  42.         cleaning_remove_old_files("$DCONF->{admin_dir}/msg_index/lim-accs", '^[\d\.]+$', 1, 0);
  43.         cleaning_remove_old_files("$DCONF->{admin_dir}/data/tokens", '^[\d\-]+\.txt$', 3, 0);
  44.         cleaning_set_permissions();
  45.     }
  46.     if ($set == 2 && $DCONF->{pro}) {
  47.         dreq("fcn-user-PRO");
  48.         user_do_password_mailing(1);
  49.     }
  50. }
  51.  
  52. ###
  53. ### cleaning_remove_old_files
  54. ###
  55. ### General subroutine to remove files from a directory if they are old
  56. ###
  57.  
  58. sub cleaning_remove_old_files {
  59.     my ($dir, $pattern, $mtime, $atime, $timecache) = @_;
  60.     $timecache = time if $timecache <= 0;
  61.     my $mcut = $timecache - $mtime*3600;
  62.     my $acut = $timecache - $atime*3600;
  63.     my $ctr1 = 0;
  64.     my $ctr2 = 0;
  65.     if (opendir(DIR, "$dir")) {
  66.         while (my $d = readdir(DIR)) {
  67.             my $fn = join("/", $dir, $d);
  68.             next if ! -f $fn;
  69.             next if $d =~ m|^\.+$|;
  70.             next if ($pattern ne "" && $d !~ /$pattern/);
  71.             my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$a_time,$m_time,$ctime,$blksize,$blocks) = stat $fn;
  72.             if (($mtime == 0 || $m_time < $mcut) && ($atime == 0 || $a_time < $acut)) {
  73.                 $ctr1++;
  74.                 $ctr2 += unlink $fn;
  75.             }
  76.         }
  77.         closedir(DIR);
  78.     }
  79.     return ($ctr1, $ctr2);
  80. }
  81.  
  82. ###
  83. ### cleaning_set_permissions
  84. ###
  85. ### Sets proper permissions on various files
  86. ###
  87.  
  88. sub cleaning_set_permissions {
  89.     if ($^O ne "MSWin32") {
  90.         opendir(DIR, "$DCONF->{admin_dir}");
  91.         while (my $dir = readdir(DIR)) {
  92.             chmod(oct($DCONF->{perms0666}),"$DCONF->{admin_dir}/$dir") if $dir =~ m|\.txt$|;
  93.             next if $dir =~ m|^\.+$|;
  94.             chmod(oct($DCONF->{perms0777}),"$DCONF->{admin_dir}/$dir") if (-d "$DCONF->{admin_dir}/$dir" && $dir ne "source");
  95.         }
  96.         closedir(DIR);
  97.         opendir(DIR, "$DCONF->{message_dir}");
  98.         while (my $dir = readdir(DIR)) {
  99.             next if $dir =~ m|^\.+$|;
  100.             chmod(oct($DCONF->{perms0777}),"$DCONF->{message_dir}/$dir") if -d "$DCONF->{message_dir}/$dir";
  101.         }
  102.         closedir(DIR);
  103.         opendir(DIR, "$DCONF->{secdir}");
  104.         while (my $dir = readdir(DIR)) {
  105.             next if $dir =~ m|^\.+$|;
  106.             chmod(oct($DCONF->{perms0777}),"$DCONF->{secdir}/$dir") if -d "$DCONF->{secdir}/$dir";
  107.         }
  108.         closedir(DIR);
  109.         chmod(oct($DCONF->{perms0666}),"$DCONF->{message_dir}/$DCONF->{board_topics_file}") if -e "$DCONF->{message_dir}/$DCONF->{board_topics_file}";
  110.         chmod(oct($DCONF->{perms0666}),"$DCONF->{admin_dir}/secure/$DCONF->{board_topics_file}") if -e "$DCONF->{admin_dir}/secure/$DCONF->{board_topics_file}";
  111.     }
  112. }
  113.  
  114. 1;
  115.