#!/usr/bin/perl -w ###################################################### # Gatekeeper.pl AIM Bot # author: Paul Ehrenreich # email paulehr@grid7.org # Version 0.1 # License: GPL, http://www.gnu.org/copyleft/gpl.html # more info @ www.grid7.org ###################################################### #Modules we are going to use use strict; use Net::OSCAR qw(:standard); use WWW::Mechanize; use MIME::Base64; #AIM bot login information, set this to what your AIM bot is going to use my $aim_host = 'login.oscar.aol.com'; my $aim_sn = 'CHANGEME'; my $aim_pw = 'CHANGEME'; # change the following to what screen names can access the bot my $allowed_usr1 = 'CHANGEME'; my $allowed_usr2 = 'CHANGEME'; #Your router information goes here, $router should be the status page that has the wan IP my $router = 'CHANGEME'; my $router_user = 'CHANGEME'; my $router_pass = 'CHANGEME'; my $oscar = Net::OSCAR->new(); $oscar->set_callback_im_in(\&im_in); $oscar->set_callback_error(\&im_error); $oscar->signon($aim_sn, $aim_pw) or die "unable to connect to the AOL network\n"; $oscar->loglevel(10); # i like to keep logging turned up, comment this out if you dont like lots of stuff on your console screen while(1) { $oscar->do_one_loop(); } #this is where all the magic happens sub im_in { my ($oscar, $sender, $message, $is_away) = @_; print "[AWAY]" if $is_away; print "$sender: $message\n"; #strip HTML $message =~ s/<(.|\n)+?>//g; if ($sender eq $allowed_usr1 || $sender eq $allowd_usr2) { if ($message eq "ip") { #this is where an instance of mech will connect to the router's web interface , extract the WAN IP from the status page, and IM it back my $mech = WWW::Mechanize->new(); my @args = (Authorization => "Basic " .MIME::Base64::encode("$router_user:$router_pass")); $mech->get($router, @args); if ($mech->content =~ /(\d+\.\d+\.\d+\.\d+)/) { my $ip = $1; $oscar->send_im($sender, "Your IP is $ip"); } } else { $oscar->send_im($sender, "sorry me no understandy :("); } } else { $oscar->send_im($sender, "I'm sorry $sender, I am afarid can't do that"); } } # this handles our error handling, if the bot loses connection to the internet, it will attempt to reconnect sub im_error { my($oscar, $connection, $errno, $error, $fatal) = @_; if($fatal) { warn "ut oh OSCAR error $errno...\n" if( $errno == 29 || $errno == 17 || $errno == 0 ); print "attempting to recover....\n"; sleep(120); #will sleep for 2 minutes before trying again system("gatekeeper.pl"); die "Fatal error $errno in ".$connection->{description}.": $error\n"; #this clears out the old connection } }