#!/usr/local/bin/perl -wuse strict;use diagnostics;require 5.003; # Will only work correctly under 5.003+ :-)# Must run as root!($> == 0) or die("\n\n\nNot Authorized:  Can only be run by root user.  Goodbye...\n\n");# Data files must exist!foreach(@ARGV) {(-f) ? print "Data file exists... Continuing!\n\n" : exit; # Otherwise, no peep from me!}# Date/Time of execution - important...my($sec,   $min,   $hour,   $mday,   $mon,   $year,   $wday,   $yday,   $isdst) = localtime(time()); # The time now...# Y2k issue repairs start here...$year += 1900; # The current year is exactly 'num yrs since 1900.'  Trust me...$mday  = sprintf("%02d", $mday);  # Make sure we have two digits, even zero...$mon   = sprintf("%02d", ++$mon); # Ditto here...$sec   = sprintf("%02d", $sec);   # Ditto here...$min   = sprintf("%02d", $min);   # Ditto here...$hour  = sprintf("%02d", $hour);  # Ditto here...$yday  = sprintf("%03d", $yday);  # 3 digits here...   #IE - 183417101219995343#      1 2 3 4 5   67  8   # Are -  #   1 - seconds#   2 - minutes#   3 - hours#   4 - day of month#   5 - month#   6 - year#   7 - day of week (5 = Friday)#   8 - Julian date (day 343 into this year :)   # Y2k issue repairs end...my $inputDate = $min . $hour . $mday . $mon . $year;# ... FTP File Translation Layout ...## ADD Record Layout...##  [User] #  yyyyyyy,Telfair S Rogers Jr.,FCCJ1965,,,,,#  [Global] #  ,,, #  [Local] #  ,,,## End ADD Record Layout...## DEL Record layout...##  [User] #  yyyyyyy, ,,,,,#  [Global] #  ,,, #  [Local] #  ,,, ## End DEL Record Layout...## ... End FTP File Translation Layout ...my $count   = 0;     # Generic Counter...my $cntr    = 0;     # Another generic counter :-)my $hUID    = 0;     # Highest UID, if finished looking...my $cUID    = 0;     # Highest UID Last Found...my $account = 0;     # The LOGIN Name we want to use...my $acct    = 0;     # The LOGIN Name found, if any...my $passwd  = 0;     # The Password we want to set...my $pswd    = 0;     # The Password we found, if any...my $uid     = 0;     # Use to determine the NEXT ID we will use...my $gid     = 0;     # Not used...my $quota   = 0;     # Not used...my $comment = 0;     # The Real Name data we want to set...my $cmt     = 0;     # The Real name data we found, if any...my $gcos    = 0;     # Not used...my $home    = 0;     # Auto-Magical, if user successfully set...my $shell   = 0;     # Auto-Magical, if user successfully set...my $erc     = 0;     # Any returned error codes from the System Call...my $x       = @ARGV; # How many arguments did we get?  We only want one...my $y       = 0;     # Set ONLY if we find $account in /etc/passwd...my $z       = '';    # Used to 'build Add User' command string...# First, we find the highest good UserID...print "Looking for highest good UID in /etc/passwd;\n\nReading File ";while (($account, $passwd, $uid, $gid, $quota, $comment, $gcos, $home, $shell) = getpwent()){        ($uid < 30000 && $uid > $cUID) ? $cUID = $uid : print ".";        $account = ''; # The following are not used this time around...        $passwd  = '';        $gid     = '';        $quota   = '';        $comment = '';        $gcos    = '';        $home    = '';        $shell   = '';        # Increment the count...        $count++;}print " Done!\n\n";# Now set the Highest UID correctly...$hUID = $cUID + 1;print "Completed reading $count User \'/etc/passwd\' Records; the next valid ID is $hUID.\nContinuing...\n\n";$count = 0; # Reset it...# See if Input Data file was given, and validate that it is in correct format...if ($x) {        print "Setting default STAFF UNIX Environment...\n";        # Setup the default staff account environment...        $erc = system("useradd -D -g staff -b /drv2/home/staff") / 256;        if ($erc) {                print "\n\nSystem Call to \'useradd \-D \(set environment\)\' generated an error of type $erc!\nExiting...\n\n";                exit $erc;        } else {                print "\n\nChecking input data file... Please wait...\n\n";        }        while(<>) {                $count++;                chomp; # Cut-off CR at eol...                ( $account, $comment, $passwd ) = split(',');                next if (substr($account,1,4) eq 'User');                last if (substr($account,1,4) eq 'Glob');                print "... $comment ... ";if (substr($ARGV, rindex($ARGV,'.') + 1, 3) eq 'DEL' && length($account) >=  3) {# DEL Area...        setpwent(); # Reset so we can re-read the /etc/passwd file...        while (($acct, $pswd, $uid, $gid, $quota, $cmt, $gcos, $home, $shell) = getpwent()) {                next if $acct ne $account;                $y = 1;                last;        }        if ($y) {                my $usrID = $acct;        if ($uid < 100 || $usrID eq "webmaster" || $usrID eq "wcjones" || $usrID eq "listserv" || $usrID eq "mta" || $usrID eq "coned" || $usrID eq "dharris") {                print "Deletion/Modification of Protected Account: $usrID, was not allowed...";                exit 1;        }                print "Tarring/GZipping $acct Mail & Directory $home...  Please wait...\n";          $erc = system("/usr/sbin/tar cvf /drv2/User.HOME.Archive/$acct.$inputDate.tar $home") / 256;          $erc = system("/usr/bin/gzip -9 /drv2/User.HOME.Archive/$acct.$inputDate.tar") / 256 unless $erc;  if (-e "/var/mail/$acct") {          $erc = system("/usr/bin/gzip -9 /var/mail/$acct") / 256 unless $erc;          $erc = system("/usr/bin/mv /var/mail/$acct.gz /drv2/User.HOME.Archive/") / 256 unless $erc;  }          $erc = system("/usr/sbin/userdel -r $acct") / 256 unless $erc;          if ($erc) {                print "\n\nSystem Call to \'TAR/GZip/UserDel $home\' generated an error of type $erc!\nExiting...\n\n";                exit $erc;          } else {                print "\n\nUser $acct Archived as /drv2/User.HOME.Archive/$acct.$inputDate.tar.gz and $acct was Deleted...\n";                print " OK!\nRemoving E-Mail Address for $acct .. ";                # &mooniAlias("$acct $acct\@exchange.fccj.org");                &mooniAlias("$acct $acct\@fccjmail.fccj.org");                # &astroAlias("$acct $acct\@astro.fccj.cc.fl.us");                $cntr++;          }        } else {                print "\nWARNING:  User $acct does not exist...\n";        }        $y = 0; # Reset for next time...        next;# End of DEL Area...} else { # ADD Area...                if (length($account) < 3 || $comment eq ' ' || length($passwd) < 3) {                        if (length($account) < 3) { print "\nError Found:  Login must be at least 3 characters..."; }                        if (length($comment) < 3) { print "\nError Found:  Account Name Comment missing..."; }                        if (length($passwd)  < 3) { print "\nError Found:  Password must be at least 3 characters..."; }                        print "\n\nErroneous input file data was found.  See last record displayed...\n\n";                        exit 1;                }                setpwent(); # Reset so we can re-read the /etc/passwd file...                while (($acct, $pswd, $uid, $gid, $quota, $cmt, $gcos, $home, $shell) = getpwent())                {                        next if $acct ne $account;                        $y = 1;                        last;                }                if ($y) {                        print "\: LOGIN already exists...Skipping!\n";                        $y = 0; # Reset for next time...                        next;                } else {                #                # USERADD Command Format:                # To create users -                # usage:  useradd [-u uid [-o] | -g group | -G group[[,group]...] | -d dir | -s shell | -c comment | -m [-k skel_dir] | -f inactive | -e expire ] login                # - or, to set creation environment -                # useradd -D [-g group | -b base_dir | -f inactive | -e expire ]                #                        # Assemble the command string...  Then execute it...                        $z = "useradd -u " . ++$hUID . " -s /usr/bin/csh" . " -c " . "\"" . $comment . "\"" . " -m " . $account;                        $erc = system($z) / 256;                                        if ($erc) {                                print "\n\nSystem Call to \'useradd\' generated an error of type $erc!\nExiting...\n\n";                                exit $erc;                        } else {                                print "\: Created. Setting Password .. ";                                # Calls an Expect-script...  Trust me, it's the only way...                                $z = "/export/home/bill/passwd.expect $account $passwd";                                $erc = system($z) / 256;                                if ($erc) {                                        print "\n\nSystem Call to \'passwd.expect\' generated an error of type $erc!\nExiting...\n\n";                                        exit $erc;                                } else {                                        print " OK!\nSetting E-Mail Address for $account .. ";                                        &mooniAlias("$account END");                                        # &astroAlias("$account END");                                        $cntr++;                                }                        }                }} # End of ADD Area...        }        print "\nDone checking $count New Staff Input Data File Records...\nProcessed $cntr Staff Records...\n\n";        print "Shutting Down \& Restarting the WWW Server... Please wait...\n";        $erc = system("/usr/netscape/suitespot/https-mooni/restart") / 256 unless $erc;print "\n\nSystem Call to \'WWW Restart\' generated an error of type $erc!\nExiting...\n\n" if ($erc);        # Archive input file(s)...        if (substr($ARGV, rindex($ARGV,'.') + 1, 3) eq 'ADD') {                $erc = system("mv $ARGV /drv2/User.HOME.Archive/WINNT.ADD.$inputDate") / 256;                $erc = system("/usr/bin/gzip -9 /drv2/User.HOME.Archive/WINNT.ADD.$inputDate") / 256 unless $erc;                $erc = system("chmod u-wx,og-rwx /drv2/User.HOME.Archive/*ADD*.gz") / 256 unless $erc;        } elsif (substr($ARGV, rindex($ARGV,'.') + 1, 3) eq 'DEL') {                $erc = system("mv $ARGV /drv2/User.HOME.Archive/WINNT.DEL.$inputDate") / 256;                $erc = system("/usr/bin/gzip -9 /drv2/User.HOME.Archive/WINNT.DEL.$inputDate") / 256 unless $erc;                $erc = system("chmod u-wx,og-rwx /drv2/User.HOME.Archive/*DEL*.gz") / 256 unless $erc;        } else {                print "Archive Input File: Unknown Error... Could Not Archive Input File: $ARGV\n\n";                $erc = 1; # An UNKNOWN Error...        }        if ($erc) {                print "\n\nSystem Call to \'Archive Input File\' generated an error of type $erc!\n\n";        }        print "\n\nProgram done...\n\n\n";} else {        print "\n\nError:  No input data file given...\n";        print "Usage: \.\/$0 filename \[enter\]\n\     (NOTE: Do not use the \'\<\' I/O redirection symbol!\)\n\n";        print "See the FCCJ Solaris SysAdmin for assistance...\n\n";        exit 1;}#............................................................................sub mooniAlias { # Was there an error?open (MAIL, "| /usr/lib/sendmail mailADS\@fccjmail.fccj.cc.fl.us") ||         die ("$0:  Fatal Error!  Cannot open sendmail: $!\n");print MAIL "Reply-to: crazyguys\@fccj.org\n"; # Who would know what to do?print MAIL "From: 'Mail.Aliases.Server'\n";print MAIL "To: 'Mail.Aliases.ADS.Mooni.Server'\n";print MAIL "Subject: =Informational Only=\n";print MAIL "X-Comments: ===== A Message from the $0 application... =====\n";print MAIL "X-Comments: us (NJE origin SERVER\@FCCJ) by FCCJVM\n";print MAIL "SECURITY:  Access to $0 by (real $< )(effective $> )\n";print MAIL shift @_; # What the Event was...print MAIL "\n";close (MAIL);}# WARNING:  Astro no longer handles aliases...#............................................................................#sub astroAlias { # Was there an error?#open (MAIL, "| /usr/lib/sendmail mailADS\@astro.fccj.cc.fl.us") || #       die ("$0:  Fatal Error!  Cannot open sendmail: $!\n");#print MAIL "Reply-to: crazyguys\@fccj.org\n"; # Who would know what to do?#print MAIL "From: 'Mail.Aliases.Server'\n";#print MAIL "To: 'Mail.Aliases.ADS.Astro.Server'\n";#print MAIL "Subject: =Informational Only=\n";#print MAIL "X-Comments: ===== A Message from the $0 application... =====\n";#print MAIL "X-Comments: us (NJE origin SERVER\@FCCJ) by FCCJVM\n";#print MAIL "SECURITY:  Access to $0 by (real $< )(effective $> )\n";#print MAIL shift @_; # What the Event was...#print MAIL "\n";#close (MAIL);#}