Super Technologies

Asterisk Call Back

Phone Home. Inspired by ET and the Coors reminder (see inset), we wanted a way to have our Asterisk system call us while we were on the road and provide dialtone to make international calls … to hail a cab. Remember, it’s free with BroadVoice’s $19.99 World Plan. So we put together a little web application (actually a PHP script) so that, using a web browser on the road, you could tell your Asterisk server to call you and provide dialtone to any number you specify. The only prerequisite here was that we didn’t want to sell the farm, i.e. provide free dialtone service and unlimited international calling for all the world’s hackers and crackers. We also didn’t want to have to go through a bunch of authentication steps to access the web site and put the call in motion. So here’s the design. We have a PHP script which you can download here. It needs to be renamed to callme.php. Then copy it into the /var/www/html directory on your Asterisk server. You’ll also need to tell your firewall/router to route HTTP or port 80 traffic to the internal IP address of your Asterisk server. This is usually done under the Services or Rules menus on most routers. You’ll want to specify that all port 80 traffic be allowed through the firewall all of the time. Be sure you’ve changed ALL of your Asterisk passwords before you do this!

To use this script from the Internet, you’ll probably want to have to have a more permanent fully-qualified domain name associated with your Asterisk server. We explained here how to do this using dyndns.org. The syntax is as follows: http://asterisk.dyndns.org/callme.php?number=sip/bv/4045551212 where asterisk.dyndns.org is the fully-qualified domain name for your Asterisk server and 4045551212 is the area code and number where you wish to accept a call with dialtone. Nothing else needs to be changed. To dial a local extension, use this syntax: http://asterisk.dyndns.org/callme.php?number=sip/204 where asterisk.dyndns.org is the fully-qualified domain name for your Asterisk server and 204 is the local number to ring. Beginning on the first ring, Asterisk will start prompting for a password. It doesn’t care whether the call is answered or not, and it times out after 10 seconds. After three unsuccessful password attempts (each timeout counts as 1), Asterisk hangs up. Stated another way, you have about 30 seconds to enter your password after the phone first rings. Then Asterisk disconnects the call. To enter your password, key in the touchtone numbers which match the numerical password code you specified in your [callout] context (see below). Then press the pound (#) key. Note that a web page will not display at this web address unless you enter the portion of the address following the question mark. Nor will a call be placed unless the sip/bv/ syntax precedes a phone number. We did this for security reasons.

Before the above script will work, you also need to add the following context to the bottom of the extensions_custom.conf configuration file discussed above. Make sure you change the password 24681234 to something very secure. After all, it’s your phone bill! Once you make this change, it won’t take effect until you restart Asterisk. The easiest way to do that is to access setup within AMP, click Incoming Calls, then click the Submit Changes button, then click on the red bar which appears. Count to 10 and your changes should be operational.

[callout]
exten => s,1,Authenticate(24681234)
exten => s,2,DISA(no-password|from-internal)

Update. The Phone Home article has been updated since this was published. The updated article provides setup instructions for three DISA alternatives. You can read all about it here.

Unlimited Calls For Free With Nextel. If you’re one of the lucky ones that subscribes to Nextel’s “free incoming calls” plan with web Internet service, then you obviously can use the Phone Home trick above to never again pay for an outgoing call. Just use the web browser on your Nextel phone to connect to the link shown above, and your Asterisk server will immediately call you back with outgoing dial tone.

<?php
// (c) Copyright Ward Mundy, 2005. All rights reserved.
// This script will only work with Asterisk@Home ver. 1.3 or higher
// Syntax: http://asterisk.dyndns.org/callme.php?number=sip/bv/4045551212
// where asterisk.dyndns.org is the fully-qualified domain name of your Asterisk server
// and 4045551212 is the number to be called immediately to provide dialtone

// This script will not work without adding [callout] context to extensions_custom.conf. See below.
// Change 24681234 below to a very secure PIN number that the user will be prompted for when call is made.

// [callout]
// exten => s,1,Authenticate(24681234)
// exten => s,2,DISA(no-password|from-internal)

// For additional documentation, visit Nerd Vittles blog at
// http://mundy.org/blog/index.php?p=63

// No changes should be made below this line
// For BroadVoice, dial strings should look like this: SIP/bv/14045551212
// To call a local extension with SIP, use the syntax: SIP/200 where 200 is the extension number
// MAKE ALL EXISTING ACCOUNTS SECURE BEFORE OPENING ASTERISK WEB SERVER TO BIG, BAD INTERNET!!!
$number=strtolower($_REQUEST[‘number’]);
$pos=strpos ($number,"local");
if ($number == null) :
exit() ;
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
$fp = fsockopen ("localhost", 5038, &$errno, &$errstr, 20);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "Action: login\r\n");
fputs ($fp, "Username: phpagi\r\n");
fputs ($fp, "Secret: phpagi\r\n");
fputs ($fp, "Events: off\r\n\r\n");
sleep(1) ;
fputs ($fp, "Action: Originate\r\n");
fputs ($fp, "Channel: $number\r\n");
fputs ($fp, "Context: callout\r\n");
fputs ($fp, "Extension: s\r\n");
fputs ($fp, "Priority: 1\r\n\r\n");
sleep(2) ;
fclose ($fp);
}
echo "Extension $number should be ringing now." ;
else :
exit() ;
endif ;
?>