From fb0f9240f59f870534484564894a371566b9a736 Mon Sep 17 00:00:00 2001 From: Adam Zammit Date: Wed, 17 Sep 2014 15:25:22 +1000 Subject: [PATCH] Fixes lp:1362418 - Cannot originate calls on Asterisk 11 Adds ORIGINATE_CONTEXT as a configuration default and sets it to 'from-internal' --- config.default.php | 6 ++++++ functions/functions.voip.php | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/config.default.php b/config.default.php index c6f0166b..9bae7b71 100644 --- a/config.default.php +++ b/config.default.php @@ -94,6 +94,12 @@ if (!defined('VOIP_ADMIN_PASS')) define('VOIP_ADMIN_PASS','amp111'); */ if (!defined('VOIP_PORT')) define('VOIP_PORT','5038'); +/** + * The Asterisk context to originate calls from (in FreePBX this should be + * 'from-internal' otherwise try 'default' + */ +if (!defined('ORIGINATE_CONTEXT')) define('ORIGINATE_CONTEXT','from-internal'); + /** * The freepbx root path (if installed) otherwise false to disable freepbx integration */ diff --git a/functions/functions.voip.php b/functions/functions.voip.php index 0cbdd604..afebb301 100644 --- a/functions/functions.voip.php +++ b/functions/functions.voip.php @@ -75,7 +75,7 @@ class voip { $chans = array(); foreach ($c as $s) { - if(preg_match("{Event: PeerEntry.*ObjectName: ([0-9a-zA-Z-]+).*Status: ([/0-9a-zA-Z-]+)}i",$s,$regs)) + if(preg_match("{Event: PeerEntry.*ObjectName: ([0-9a-zA-Z-]+).*Status: ([/0-9a-zA-Z-]+)}is",$s,$regs)) { //print T_("Channel: SIP/") . $regs[1] . " BridgedChannel " . $regs[2] . "\n"; $chan = substr($regs[1],0,4); @@ -102,14 +102,14 @@ class voip { $chans = array(); foreach ($c as $s) { - if(preg_match("{Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+).*BridgedChannel: ((SIP/|IAX2/)[/0-9a-zA-Z-]+)}i",$s,$regs)) + if(preg_match("{Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+).*BridgedChannel: ((SIP/|IAX2/)[/0-9a-zA-Z-]+)}is",$s,$regs)) { //print T_("Channel: SIP/") . $regs[1] . " BridgedChannel " . $regs[2] . "\n"; $ccs = explode('-',$regs[1]); $chan = $ccs[0]; $chans[$chan] = array($regs[1],$regs[3]); } - else if(preg_match("{Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+)}i",$s,$regs)) + else if(preg_match("{Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+)}is",$s,$regs)) { //print T_("Channel: ") . $regs[1] . "\n"; $ccs = explode('-', $regs[1]); @@ -187,7 +187,7 @@ class voip { */ function dial($ext,$number) { - $r = $this->query("Action: Originate\r\nChannel: $ext\r\nExten: $number\r\nPriority: 1\r\nCallerid: $ext\r\n\r\n","Response"); + $r = $this->query("Action: Originate\r\nChannel: $ext\r\nExten: $number\r\nContext: " . ORIGINATE_CONTEXT . "\r\nPriority: 1\r\nCallerid: $ext\r\n\r\n","Response"); } @@ -266,7 +266,7 @@ class voip { if ($type == "SIP") { $ret = $this->query("Action: ExtensionState\r\nContext: from-internal\r\nExten: $ext\r\nActionID: \r\n\r\n","Status:"); - if(preg_match("{Status: ([0-9]+)}i",$ret,$regs)) + if(preg_match("{Status: ([0-9]+)}is",$ret,$regs)) { if (isset($regs[1])) { @@ -540,14 +540,14 @@ class voipWatch extends voip { * */ if ($in == "\r\n") - { + { //print "PROCESS: "; /** * The call is ringing */ - if (preg_match("{Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)}i",$line,$regs)) - { - list($call_id,$case_id) = $this->getCallId($regs[1]); + if (preg_match("{Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)}is",$line,$regs)) + { + list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { print T_("Ringing") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": $case_id\n"; @@ -557,8 +557,8 @@ class voipWatch extends voip { /** * The call has been answered */ - else if (preg_match("{Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)}i",$line,$regs)) - { + else if (preg_match("{Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)}is",$line,$regs)) + { list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { @@ -569,8 +569,8 @@ class voipWatch extends voip { /** * The call has been hung up */ - else if (preg_match("{Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)}i",$line,$regs)) - { + else if (preg_match("{Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)}is",$line,$regs)) + { list($call_id,$case_id) = $this->getCallId($regs[1]); if ($call_id != 0) { @@ -582,7 +582,7 @@ class voipWatch extends voip { /** * The status of an extension has changed to unregistered */ - else if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Unregistered}i",$line,$regs)) + else if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Unregistered}is",$line,$regs)) { print T_("Unregistered") . T_(" Extension ") . $regs[1] . "\n"; $this->setExtensionStatus($regs[1],false); @@ -591,7 +591,7 @@ class voipWatch extends voip { /** * The status of an extension has changed to registered */ - else if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Registered}i",$line,$regs)) + else if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Registered}is",$line,$regs)) { print T_("Registered") . T_(" Extension ") . $regs[1] . "\n"; $this->setExtensionStatus($regs[1],true);