#!/usr/bin/perl # You may need to change this path to /usr/local/bin/perl $mailprog = "/usr/sbin/sendmail"; #************************************************************** # # Script to notify you of new POP accounts: PWSmonitorPOPs V1.0 # # Written by: # Premier Website Solutions - http://www.premierwebsitesolutions.com # Created - March 15, 2006 (V1.0) # # # Set a few variables below and upload this script to anywhere on your server, # then set a cron job to run the script at whatever frequency you want the checks done. # I put mine in a subfolder of the servers scripts folder. (/scripts/custom) # # To set the cronjob, in shell, type crontab -e, then enter what's between the quotes # on the following line as a new line in your cron listings: # "5 * * * * perl /scripts/custom/PWSmonitorPOPs.cgi >/dev/null 2>&1" # checks every hour at 5 minutes after the hour # "*/15 * * * * perl /scripts/custom/PWSmonitorPOPs.cgi >/dev/null 2>&1" # checks every 15 minutes # # Ownership and permissions of the script should be root:root, and 0700, unless you # want to enable wheel users to use it, then it would be root:wheel 0770. # # # Registered users of this script will be notified of any future updates. # If you registered this copy with me, put your email here for future reference. # This copy is registered to: # #************************************************************** # This is where the email will be sent when a change is detected. # This script is useless until you put your email address here. # If you use spamassassin, you should include a name, like this: # $sendto_email = 'me '; $sendto_email = ''; # This is the sender for the email message. # Change it if you wish. $sender_email = 'Mike '; # This is the path to where you put this script. $path = "/scripts/custom"; # The script will create a POPs.txt file here as well which will be a list of current # POP accounts. Each time it runs, it checks to see if the current list has anything # not in this one, then updates this one and emails you if there are new ones. #------------------------------------------------------------------- #------------------------------------------------------------------- # UNLESS YOU KNOW CGI, DO NOT EDIT ANYTHING BELOW HERE # Feel free to study the code, but alterations are at your own risk #------------------------------------------------------------------- #------------------------------------------------------------------- unless (-f "$path/POPs.txt") { system ("touch $path/POPs.txt;chmod 0600 $path/POPs.txt"); } open(datafile,"$path/POPs.txt") or &ohdear("Cannot open $path/POPs.txt"); { local $/; $POPs = } close(datafile); @currPOPs = `ls -A1 /home*/*/mail/*/* | grep "/"`; open(datafile,">$path/POPs.txt"); print datafile @currPOPs; close(datafile); foreach $currPOP (@currPOPs) { chomp($currPOP); if ($POPs !~ /$currPOP/) { $currPOP =~ s/:$//; (undef,undef,undef,undef,$domain,$username) = split(/\//,$currPOP); $email .= "New POP Account: $username\@$domain\nFolder Path: $currPOP\n\n"; } } if ($email) { # Open The Mail Program open(MAIL,"|$mailprog -t"); print MAIL "To: $sendto_email\n"; print MAIL "From: $sender_email\n"; print MAIL "Subject: New POP accounts added\n"; print MAIL "The following new POP accounts have been added:\n\n"; print MAIL "$email\n"; print MAIL "\n\n"; close (MAIL); } exit;