#!/usr/local/bin/perl
#  This is version 0.3 of absent
#
#               Copyright (c) 1999 by AT&T.
#  Permission to use, copy, and modify this software without fee is
#  hereby granted, provided that this entire notice is included in all
#  copies of any software which is or includes a copy or modification
#  of this software and in all copies of the supporting documentation
#  for such software.
#
#  SOME PARTS OF ABSENT MAY BE RESTRICTED UNDER UNITED STATES EXPORT
#  REGULATIONS.
#
#  THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
#  IMPLIED WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE
#  ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
#  MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
#  PURPOSE.
#       
# Author          : Christian Gilmore
# Created On      : Fri Jul 24 21:42:10 EDT 1998
# Status          : Functional
# 
# NAME
#    cleanup_users.pl
#
# PURPOSE
#    Removes user entries and cookie files older than 1 1/2 hours
#
###############################################################################

# Location of non-standard libraries and included files


# Required libraries


# Environment Variables
$ENV{'PATH'} = "/usr/local/bin:$ENV{'PATH'}";


# Global Variables
my $PUSHWEBDIR = "/usr/local/pushweb/etc";
my $USERDIR = "$PUSHWEBDIR/users";
my $COOKIEDIR = "$PUSHWEBDIR/cookies";


###############################################################################
###############################################################################
# Main Program
###############################################################################
###############################################################################
{
  my @users = ();
  my $user, $currtime;
  my $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime;
  my $mtime, $ctime, $blksize, $blocks;
  
  chdir($USERDIR);
  opendir(DIR, '.') || die "Can't open directory $USERDIR: $!\n";
  @users = grep(!/(^\.|key|extra|personal_pages)/, readdir(DIR));
  foreach $user (@users) {
    ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, 
     $mtime, $ctime, $blksize, $blocks) = stat($user);
    $currtime = time;
    if ($currtime - $mtime > 5400) {
      unlink($user);
    }
  }
  closedir(DIR);

  chdir($COOKIEDIR);
  opendir(DIR, '.') || die "Can't open directory $USERDIR: $!\n";
  @users = grep(!/^\./, readdir(DIR));
  foreach $user (@users) {
    ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, 
     $mtime, $ctime, $blksize, $blocks) = stat($user);
    $currtime = time;
    if ($currtime - $mtime > 5400) {
      unlink($user);
    }
  }
  closedir(DIR);
}

# $Id: cleanup_users.pl,v 1.6 1999/12/16 23:39:43 cgilmore Exp $

# $Log: cleanup_users.pl,v $
# Revision 1.6  1999/12/16 23:39:43  cgilmore
# prepared for 0.3 release
#
# Revision 1.5  1999/02/11 17:57:31  cgilmore
# added personal_pages to the ignore list
#
# Revision 1.4  1999/02/11 17:49:38  cgilmore
# changed timeout value to 1 1/2 hours
#
# Revision 1.3  1999/01/20 17:31:01  cgilmore
# removed debug message that shouldn't have been there
#
# Revision 1.2  1999/01/20 16:12:19  cgilmore
# added cookie cleanup and ensured that valuable key files aren't removed
#
# Revision 1.1  1998/07/25 01:52:22  cgilmore
# Initial revision
#
