#!/usr/local/bin/perl # Sentry -- Email Sentry for MessageSaver # $Id: sentry.pl,v 1.0 2002/04/30 12:00:00 scovetta Exp $ # Created by Michael Scovetta (michael.scovetta@gmail.com") ######################################################################### #use strict; use lib '.'; use Net::AIM; use Mail::POP3Client; ######################################################################### ## GLOBAL DEFINES SECTION ## ######################################################################### ## User Information my $AIM_USER = "XXXXXXXXXX"; # AIM screen name my $AIM_PASS = "XXXXXXXX"; # AIM password my $CHECK_EMAIL = 1; # Enable/Disable Email checking my $EMAIL_USER = "XXXXXXXXXXXXXXXX"; # Email username my $EMAIL_PASS = "XXXXXXXXXXX"; # Email password my $EMAIL_HOST = "XXXXXXXXXXXXXX"; # Email POP3 host ## Log files my $MSG_BACKUP_FILE = "savedb.txt"; # Place to save backups of messages my $TRANSACTION_FILE = "num.txt"; # Holds number of transactions my $LOG_FILE = "aim.log"; # Main log file my $MORON_FILE = "morons.log"; # List of morons ## Program data my $PROGRAM_TITLE = "MessageSaver"; # Text of program title my $PROGRAM_VERSION = "2.22"; # Text of version my $LAST_UPDATE = "1/28/02"; # Date of last update my $FOOTER = "
Help the cause. Donate a buck to the MessageSaver fund. Click here"; # Optional footer ## Options my $LOG_ALL_MESSAGES = 1; # Log all messages received? my $LOG_NUM_TRANSACTIONS = 1; # Log number of transactions? my $LOG_MORONS = 1; # Log morons my $CHECK_MAIL = 1200; # Min seconds to wait to check mail my @ADMIN_LIST = ("your-screen-name"); # List of administrators ######################################################################### ## YOU SHOULD NOT NEED TO EDIT BELOW THIS LINE ## ######################################################################### ## Debugging information my $DEBUG_LEVEL = 2; # Debug Mode: my $DBG_NO_MSG = 0; # 0=no messages, ever. my $DBG_ERRORS = 1; # 1=only errors my $DBG_ERRWRN = 2; # 2=+warnings+connection details my $DBG_ALL = 3; # 3=everything my $DBG_DETAIL = 4; # 4=detailed $AUTOFLUSH = 1; # Flush all files automatically my $MAX_BUDDIES = 160; # Maximum set by AOL ## Global variables my %morons; my %suspects = (); # People suspected of warning me my %stats = (); # statistics (messages received, etc) my %msgs = (); my %users_online = (); my $lastTime = 0; # Internal, last time email was checked ######################################################################### ######################################## # [ BEGIN ] # # Initial execution. Checks ARGV and # # files, if necessary. # ######################################## BEGIN { print "$PROGRAM_TITLE $PROGRAM_VERSION\n"; if ($ARGV[1] =~ /-\?|--\?|-h|\/\?|\/h/i) { print "Usage:\n"; print " perl $0 [username password]\n"; exit; } if (exists $ARGV[1] && exists $ARGV[2]) { $AIM_USER = $ARGV[0]; $AIM_PASS = $ARGV[1]; } } ######################################## # Create the objects # ######################################## BEGIN(); my $aim = new Net::AIM; $aim->debug(1) if $DEBUG_LEVEL >= $DBG_DETAIL; print "MSG: Creating connection to AIM server...\n" if $DEBUG_LEVEL >= $DBG_ERRWRN; $aim->newconn( Screenname => $AIM_USER, Password => $AIM_PASS, AutoReconnect => 1 ) or die "ERR: Can't connect to AIM server.\n"; ######################################### # Grab the total number of transactions # ######################################### if ($LOG_NUM_TRANSACTIONS == 1) { open (TRN_FILE, $TRANSACTION_FILE); $stats{msgs_received} = ; $stats{email_received} = unless eof(TRN_FILE); close (TRN_FILE); } if ($LOG_MORONS == 1 && open (MORON_LOG, "$MORON_FILE")) { while (my $line = ) { $line =~ s/\s*//g; $morons{$line} = 1; } close(MORON_LOG); } ######################################### # Install Handler Routines # ######################################### print "INFO: Installing handler routines...\n" if $DEBUG_LEVEL >= $DBG_ERRWRN; my $conn = $aim->getconn(); $conn->set_handler('error', \&on_error); #$conn->set_handler('im_in', \&on_im); #$conn->set_handler('nick', \&on_nick); $conn->set_handler('eviled', \&on_eviled); $conn->set_handler('config', \&on_config); #$conn->set_handler('update_buddy', \&on_update_buddy); ######################################### # Start the Service # ######################################### $aim->start; ######################################################################### # BEGIN SUBROUTINES # ######################################################################### ######################################### # [ on_config ] # # Called upon startup. # ######################################### sub on_config { my ($self, $evt, $from, $to) = @_; my $str = shift @{$evt->args()}; print "DBG: on_config called, str=$str\n";# if $DEBUG_LEVEL >= $DBG_DETAIL; $self->set_config_str($str, 1); $self->set_info("Scovetta.Com MessageSaver

Email Sentry. This bot will not respond to commands unless issued by administrators.
."); # Deny Some Mode $self->{_config}->{mode} = 4; $self->send_config(); # Place the email check here sleep(10); &emailHandler(); sleep(1); exit(0); } ######################################### # [ on_error ] # # Called when there's an AIM error. # ######################################### sub on_error { my ($self, $evt) = @_; my ($error, @stuff) = @{$evt->args()}; my $errstr = $evt->trans($error); $errstr =~ s/\$(\d+)/$stuff[$1]/ge; print "DBG: on_error called, errstr=$errstr\n" if $DEBUG_LEVEL >= $DBG_ERRORS; } ######################################### # [ emailHandler ] # # Handles checking email and adding # # messages to the queue. # ######################################### sub emailHandler { return unless $CHECK_EMAIL; my ($self, $evt) = @_; my ($fromBuddy, $toBuddy, $msg, $msgDate, $IP, @emailBody); my $numEmailReceived = 0; print "INFO: Email Handler..." if $DEBUG_LEVEL >= $DBG_ERRWRN; $lastTime = time; print "INFO: Checking email..." if $DEBUG_LEVEL >= $DBG_ERRWRN; $pop = new Mail::POP3Client( USER => $EMAIL_USER, PASSWORD => $EMAIL_PASS, HOST => $EMAIL_HOST, AUTH_MODE => "PASS" ); for ($i=1; $i <= $pop->Count(); $i++) { sleep(5); my @emailBody = $pop->Body($i); foreach my $line (@emailBody) { if ($line =~ /^FROM:\"([^\"]*)\"$/i) { $fromBuddy = $1; } elsif ($line =~ /^TO:\"([^\"]*)\"$/i) { $toBuddy = $1; } elsif ($line =~ /^MESSAGE:\"([^\"]*)\"$/i) { $msg = $1; } elsif ($line =~ /^DATE:\"([^\"]*)\"$/i) { $msgDate = $1; } elsif ($line =~ /^IP:\"([^\"]*)\"$/i) { $IP = $1; } } # Should we log the transaction? if ($LOG_ALL_MESSAGES == 1 && open(LOG_FILE, ">>$LOG_FILE")) { print LOG_FILE "EMAIL: FROM:$fromBuddy, TO:$toBuddy, DATE:$msgDate, IP:$IP, MSG:$msg\n"; close LOG_FILE; } $aim->send_im("MessageSaver", "tellobo \"$fromBuddy\" \"$toBuddy\" $msg"); $numEmailReceived++; # Remove the email $pop->Delete($i); } $pop->Close(); print "INFO: $numEmailReceived messages received.\n" if $DEBUG_LEVEL >= $DBG_ERRWRN; }