Agi + PHP: "Making Phones Jump Through Fiery Hoops of Death." Rob Peck PHP Appalachia 2008
Agi + PHP: "Making Phones Jump Through Fiery Hoops of Death." Rob Peck PHP Appalachia 2008
Rob Peck
dealnews.com
PHP Appalachia 2008
Introduction to VoIP
• At its simplest, sending telephone calls over
an IP network.
• No magic. “It’s just software.”
• Voice packets are treated just like any other
packet on a network. Broken down,
transmitted, and reassembled.
Do It Open Source!
• Asterisk is an open-source (GPL) software
PBX (Private Branch Exchange) that was
created by Mark Spencer.
• Basic Asterisk software includes many
features available in proprietary PBX
systems.
• Runs on ordinary PC hardware.
How Asterisk Works
• extensions.conf is the config file that
controls how Asterisk handles calls. It is
called the “dialplan.”
• Commands are sequentially executed based
on the status from the previous command.
1. #!/usr/bin/php
2. <?php
3. include "agi.php";
4.
5. execute("SAY DATETIME #");
6.
7. ?>
More Complex
1. #!/usr/bin/php
2. <?php
3.
4. include "agi.php" ;
5.
6. $db=mysql_connect(’redacted’, ‘redacted’, ‘redacted’);
7.
8. if(!$db) {
9. verbose("Could not connect to DB!");
10. exit(1);
11. }
12.
13. if(!mysql_select_db(’redacted’, $db)) {
14. verbose("Could not use DB!");
15. exit(1);
16. }
17.
18. $res=mysql_query(sprintf("select substitution_name from cid_substitution where
from_number=’%s’",mysql_escape_string($_AGI['callerid'])));
19.
20. $result=mysql_fetch_row($res);
21.
22. if(!empty($result)) {
23. execute(sprintf("SET CALLERID \"%s <%s>\"",$result[0],$_AGI['callerid']));
24. }
25.
26. mysql_close($db);
27.
28. ?>
“Calling” your AGI