[mythtv] Contrib: Asterisk AGI script for CID notification

Matt White whitem at arts.usask.ca
Sat Feb 21 23:26:31 EST 2004


Hi.  Attached is an AGI script for the open-source Asterisk PBX
that sends callerID information for incoming calls to your MythTV
machine's notify port.

Documentation is at the beginning of the script.

For those who aren't familiar with it, you can read about
Asterisk at http://www.asterisk.org/

-- 
Matt White                          whitem at arts.usask.ca
Arts and Science Computer Labs      University of Saskatchewan

It sure is Monday... Ain't it a sin
I've gotta work my way thru the week again.
	- Mark Chesnutt..."Sure Is Monday"
-------------- next part --------------
#!/usr/bin/perl

# Use this script along with MythNotify to display callerID information
# on your MythTV screen when a call comes into your Asterisk PBX.
#
# Here's how I have it set up in my Asterisk extensions.conf:
#
# exten => 2000,1,AGI(cid.agi)
# exten => 2000,2,Macro(stdexten,2000,SIP/2001)
#
# The only necessary configuration in this script is setting the
# netbroadcast variable below to the correct broadcast address
# for your network.
#
# This script should be installed in /var/lib/asterisk/agi-bin for
# a default Asterisk installation, and the Asterisk::AGI perl module
# must be installed.

use Asterisk::AGI;
use IO::Socket;

# Set this to the broadcast address for your network
$netbroadcast = "192.168.0.255";

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

my $callerid = $input{'callerid'};
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$date = sprintf("%02d/%02d/%4d %d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
if ($callerid =~ /<.*>/) {
  ($name,$num) = $callerid =~ /^(.*) <(.*)>/;
} else {
  $name = "Unknown";
  $num = $callerid;
}

$sock = IO::Socket::INET->new(PeerPort  => 6948,
                              PeerAddr  => $netbroadcast,
                              Proto     => udp,
                              Broadcast => 1 ) or die "Can't bind : $@\n";

print $sock <<EOT;
<?xml version="1.0"?>
<mythnotify version="1"><container name="notify_cid_info"><textarea name="notify_cid_line"><value>Unused</value></textarea><textarea name="notify_cid_name"><value>NAME: $name</value></textarea><textarea name="notify_cid_num"><value>NUM : $num</value></textarea><textarea name="notify_cid_dt"><value>$date</value></textarea></container></mythnotify>
EOT
close $sock;
exit(0);


More information about the mythtv-dev mailing list