I use Trixbox (
trixbox, an Asterisk-based PBX Phone System (formerly Asterisk@Home) | trixbox) version of Asterisk. It has PHPAGI interface which can be used to originate calls. I have prepared a php script that originates call. To make a call from Zimbra zimlet just need to connect via http to Asterisk with a special url.
The example of the originating url is:
Code:
http://asteriskip/makecall.php?local=207&dest=*43&passwd=ZimbraCallMaker
This url makes Asterisk to call extension 207, when 207 answers Asterisk connects it with number *43 (echo test).
Php script:
PHP Code:
<?php
$local=$_REQUEST['local'];
$dest=$_REQUEST['dest'];
$passwd=$_REQUEST['passwd'];
$remoteaddr=getenv(REMOTE_ADDR);
$res=0;
if ($remoteaddr == 'XXX.XXX.XXX.XXX') {
if ($passwd == 'ZimbraCallMaker') {
$errno=0;
$errstr=0;
$fp = fsockopen ("localhost", 5038, &$errno, &$errstr, 20);
if (!$fp) {
$res=3;
$resstr="PHPAGI error $errstr ($errno)";
}
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, "MaxRetries: 2\r\n");
fputs ($fp, "RetryTime: 10\r\n");
fputs ($fp, "WaitTime: 30\r\n");
fputs ($fp, "Action: Originate\r\n");
fputs ($fp, "Channel: SIP/$local\r\n");
fputs ($fp, "Callerid: $local\r\n");
fputs ($fp, "Context: custom-cb-dial\r\n");
sleep(1) ;
fputs ($fp, "Exten: $dest\r\n");
fputs ($fp, "Priority: 1\r\n\r\n");
sleep(1) ;
fclose ($fp);
$res=0;
$resstr='OK';
}
}
else { $res=2; $resstr='invalid password'; }
}
else {
$res=1;
$resstr='invalid IP';
}
echo "$res: $resstr";
?>
1. This script checks remote IP address to allow make calls via it only from Zimbra IP. Replace XXX.XXX.XXX.XXX with valid IP.
2. Put the password you like instead "ZimbraCallMaker".
3. Replace PHPAGI username and secret with valid ones for your Asterisk.
4. Create "custom-cb-dial" context or replace it with the name of context you are using to make calls from extensions (perhaps from-internal)
In my case "custom-cb-dial" is:
Code:
[custom-cb-dial]
exten => _X.,1,Wait(1)
exten => _X.,n,NoOp(Callback from:${CALLERID(num)} to:${EXTEN})
exten => _X.,n,Playback(number)
exten => _X.,n,SayDigits(${EXTEN})
exten => _X.,n,NoOp(goto internal)
exten => _X.,n,goto(from-internal,${EXTEN},1)
exten => _*X.,1,Wait(1)
exten => _*X.,n,NoOp(Callback from:${CALLERID(num)} to:${EXTEN})
exten => _*X.,n,Playback(number)
exten => _*X.,n,SayDigits(${EXTEN})
exten => _*X.,n,NoOp(goto internal)
exten => _*X.,n,goto(from-internal,${EXTEN},1) It says to caller "number" then pronounces destination number digits and after that call is originated according rules for internal extensions.