use POE;
use POE::Component::IRC;
use Net::Telnet; # Used for connecting to the asterisk manager port.
use DBI;
use warnings;
use strict;
my $count;
my $dbh;
my $outpt;
my $name = "Telephreak PBX"; # Your PBX's named
############################################################################
## IRC server/nick/port information ##
############################################################################
my $ircserver = "irc.telephreak.org";
my $nickname = "AstBot";
my $channel = "#testing";
my $port = "6667";
my $debug = "1"; # Set to 0 for no debug output
############################################################################
## Asterisk manager port authentication information ##
############################################################################
my $username = "myusername";
my $secret = "mypassword";
my $serverip = "127.0.0.1";
############################################################################
## Asterisk MySQL information (used to retreive # of VMBs ##
############################################################################
my $myusername = "asterisk";
my $mysecret = "mysecret";
my $myhost = "127.0.0.1";
my $myvm = "asterisk_vm"; # Asterisk Voicemail DB
############################################################################
## Where to look for help ##
############################################################################
# The bot has received a public message. Parse it for commands, and
# respond to interesting things.
sub on_public {
my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 ];
my $nick = &remove_unwanted(( split /!/, $who )[0]);
my $channel = $where->[0];
my $ts = scalar localtime; # Time for output
############################################################################
## Get the number of active channels ##
############################################################################
if ( $msg eq ".channels" )
{
print " [$ts] <$nick:$channel> $msg\n";
&connect_manager();
$tn->print("Action: Status\n\n");
@dataout = $tn->waitfor('/Event: StatusComplete/');
$tn->print("Action: Logoff\n\n");
$_ = $dataout[0];
$count=s/($channelpattern)/$1/g;
if ( $count eq "" )
{
$count="0";
}
$outmsg="There are currently $count active channels up and operational on the $name";
$kernel->post( astbot => 'privmsg', $channel , $outmsg );
}
############################################################################
## Get total number of voice mail boxes ##
############################################################################
if ( $msg eq ".voicemail" )
{
print " [$ts] <$nick:$channel> $msg\n";
$dbase = "DBI:mysql:database=$myvm;host=$myhost";
$dbh = DBI->connect($dbase, $myusername, $mysecret) || die "Can't connect to asterisk_vm";
$outpt = $dbh->prepare("select count(mailbox) from users");
$outpt->execute || die "Can do query";
$count=$outpt->fetchrow_array;
$outmsg="There are currently $count voicemail boxes on the $name.";
$kernel->post( astbot => 'privmsg', $channel, $outmsg);
print "$outmsg \n";
}
###########################################################################
## Get information about conferences ##
###########################################################################
###########################################################################
## Get system uptime (last reload, etc) ##
###########################################################################
############################################################################
## Get version of Asterisk thats running ##
############################################################################
sub remove_unwanted
{
our $s;
local($s) = @_;
$s =~ s/[^A-Za-z0-9]//g if defined $s;
$s =~ tr/A-Z/a-z/;
return $s;
}
############################################################################
## Connect to the manager port, and log in please..... ##
############################################################################
sub connect_manager
{
$tn->open("$serverip");
$tn->waitfor('/0\n$/');
$tn->print("Action: Login\nUsername: $username\nSecret: $secret\n\n");
$tn->waitfor('/Authentication accept*/') || die "Can't login in";
}