From cc92e9de90de2b3f85a381b2ba0e57409ee3a70c Mon Sep 17 00:00:00 2001 From: azammitdcarf Date: Mon, 22 Feb 2010 23:02:24 +0000 Subject: [PATCH] Status updated to handle extension password for switching VoIP on an off VoIP Functions can properly handle IAX2 extensions --- functions/functions.voip.php | 73 ++++++++++++++++++++++++++++-------- status.php | 10 ++++- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/functions/functions.voip.php b/functions/functions.voip.php index f18105c0..d233e390 100644 --- a/functions/functions.voip.php +++ b/functions/functions.voip.php @@ -57,6 +57,33 @@ class voip { } + /** + * Return a list of IAX extensions + * as an associative array + * + * @return array Key is extension, value is status + * + */ + function getIAXStatus() + { + $ret = $this->query("Action: IAXPeerList\r\n\r\n","PeerlistComplete"); + + $c = spliti("\r\n\r\n",$ret); + $chans = array(); + foreach ($c as $s) + { + if(eregi("Event: PeerEntry.*ObjectName: ([0-9a-zA-Z-]+).*Status: ([/0-9a-zA-Z-]+)",$s,$regs)) + { + //print T_("Channel: SIP/") . $regs[1] . " BridgedChannel " . $regs[2] . "\n"; + $chan = substr($regs[1],0,4); + $chans[$chan] = $regs[2]; + } + } + return $chans; + } + + + /** * Return a list of active extensions and their corresponding * channels as an associative array @@ -72,16 +99,18 @@ class voip { $chans = array(); foreach ($c as $s) { - if(eregi("Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+).*BridgedChannel: ([/0-9a-zA-Z-]+)",$s,$regs)) + if(eregi("Event: Status.*Channel: (SIP/|IAX2/[0-9a-zA-Z-]+).*BridgedChannel: (SIP/|IAX2/[/0-9a-zA-Z-]+)",$s,$regs)) { //print T_("Channel: SIP/") . $regs[1] . " BridgedChannel " . $regs[2] . "\n"; - $chan = substr($regs[1],0,4); + $ccs = explode('-',$regs[1]); + $chan = $ccs[0]; $chans[$chan] = array($regs[1],$regs[2]); } - else if(eregi("Event: Status.*Channel: ((SIP/|IAX2/)[0-9a-zA-Z-]+).*",$s,$regs)) + else if(eregi("Event: Status.*Channel: (SIP/|IAX2/[0-9a-zA-Z-]+).*",$s,$regs)) { //print T_("Channel: ") . $regs[1] . "\n"; - $chan = substr($regs[1],0,4); + $ccs = explode('-', $regs[1]); + $chan = $ccs[0]; $chans[$chan] = array($regs[1],false); } } @@ -224,26 +253,40 @@ class voip { { if($ext) { + $type = "SIP"; $exts = explode('/', $ext, 2); + if (isset($exts[0])) + $type = $exts[0]; if (isset($exts[1])) $ext = $exts[1]; - - $ret = $this->query("Action: ExtensionState\r\nContext: default\r\nExten: $ext\r\nActionID: 1\r\n\r\n","Status:"); - if(eregi("Status: ([0-9]+)",$ret,$regs)) + + if ($type == "SIP") { - if (isset($regs[1])) + $ret = $this->query("Action: ExtensionState\r\nContext: from-internal\r\nExten: $ext\r\nActionID: \r\n\r\n","Status:"); + if(eregi("Status: ([0-9]+)",$ret,$regs)) { - // 0 appears to be online, 1 online and on a call - if ($regs[1] == 0) - return 1; - else if ($regs[1] == 1 || $regs[1] == 8) - return 2; + if (isset($regs[1])) + { + // 0 appears to be online, 1 online and on a call + if ($regs[1] == 0) + return 1; + else if ($regs[1] == 1 || $regs[1] == 8) + return 2; + } } } + else if ($type == "IAX2") + { + $exts = $this->getIAXStatus(); + if (isset($exts[$ext])) + { + $status = $exts[$ext]; + if ($status == "OK") + return 1; + } + } } - return false; - } /** diff --git a/status.php b/status.php index 2b0623ec..c0a64584 100644 --- a/status.php +++ b/status.php @@ -72,10 +72,16 @@ if (is_voip_enabled($operator_id)) $v = new voip(); $v->connect(VOIP_SERVER); $ext = get_extension($operator_id); + $exta = $ext; + //Get just the start of the extension for auto dial out + $exts = explode('/', $ext, 2); + if (isset($exts[1])) + $exta = $exts[1]; + $extp = get_extension_password($operator_id); if ($v->getExtensionStatus($ext)) - print "
" . T_("VoIP On") . "
"; + print "
" . T_("VoIP On") . "
"; else - print "
" . T_("VoIP Off") . "
"; + print "
" . T_("VoIP Off") . "
"; } else print "
" . T_("No VoIP") . "
";