2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

VoIP status is now part of VoIP monitoring so we don't query the Asterisk server often

Uses the "Register" and "Unregister" options of Asterisk to get extension status
Stores voip_status in operator table
This commit is contained in:
azammitdcarf
2010-07-30 03:18:14 +00:00
parent 864ba7968d
commit 3bbb234896
5 changed files with 89 additions and 15 deletions

View File

@@ -259,11 +259,7 @@ switch($state)
$es = 1;
if (is_voip_enabled($operator_id))
{
include("functions/functions.voip.php");
$v = new voip();
$v->connect(VOIP_SERVER);
$ext = get_extension($operator_id);
if ($v->getExtensionStatus($ext))
if (get_extension_status($operator_id))
$es = 1;
else
$es = 0;
@@ -339,11 +335,7 @@ switch($state)
$es = 1;
if (is_voip_enabled($operator_id))
{
include("functions/functions.voip.php");
$v = new voip();
$v->connect(VOIP_SERVER);
$ext = get_extension($operator_id);
if ($v->getExtensionStatus($ext))
if (get_extension_status($operator_id))
$es = 1;
else
$es = 0;

View File

@@ -306,6 +306,7 @@ CREATE TABLE `operator` (
`Time_zone_name` char(64) NOT NULL,
`enabled` tinyint(1) NOT NULL default '1',
`voip` tinyint(1) NOT NULL default '1',
`voip_status` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`operator_id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `extension` (`extension`)

View File

@@ -537,6 +537,26 @@ function get_call_number($call_id)
return false;
}
/**
* Return the extension status from the database
*
* @param int $operator_id The queXS Operator ID
* @return bool the extension status (false for offline, true for online)
*
*/
function get_extension_status($operator_id)
{
global $db;
$sql = "SELECT o.voip_status
FROM `operator` as o
WHERE o.operator_id = '$operator_id'";
$rs = $db->GetRow($sql);
if (!empty($rs) && $rs['voip_status'] == 1 ) return true;
return false;
}
/**
* Return the extension password of an operator
*

View File

@@ -433,6 +433,21 @@ class voipWatch extends voip {
}
function setExtensionStatus($ext, $online = true)
{
global $db;
$s = $online ? 1 : 0;
print(T_("Extension") . " $ext " . ($online ? T_("online") : T_("offline")) . "\n");
$sql = "UPDATE operator
SET voip_status = '$s'
WHERE extension = '$ext'";
$db->Execute($sql);
}
function setState($call_id,$state,$checkOutcome = false)
{
global $db;
@@ -447,6 +462,33 @@ class voipWatch extends voip {
$db->Execute($sql);
}
/**
* Update the extension status for all extensions
*/
function updateAllExtensionStatus()
{
global $db;
$sql = "SELECT extension,operator_id
FROM operator
WHERE voip = 1 AND enabled = 1";
$rs = $db->GetAll($sql);
foreach($rs as $r)
{
$o = $r['operator_id'];
$e = $r['extension'];
$s = $this->getExtensionStatus($e);
if ($s == false)
$this->setExtensionStatus($e,false);
else
$this->setExtensionStatus($e,true);
}
}
/**
* Watch for Asterisk events and make changes to the queXS databse if
* appropriate
@@ -460,12 +502,16 @@ class voipWatch extends voip {
*/
if ($process_id) include_once(dirname(__FILE__).'/../functions/functions.process.php');
$line = "";
if ($this->socket === false)
return false;
//Set initial extension status
$this->updateAllExtensionStatus();
//Watch for events
do
{
if (!$this->isConnected() || $this->socket === false){
@@ -522,6 +568,24 @@ class voipWatch extends voip {
}
}
/**
* The status of an extension has changed to unregistered
*/
else if (eregi("Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Unregistered",$line,$regs))
{
print T_("Unregistered") . T_(" Extension ") . $regs[1] . "\n";
$this->setExtensionStatus($regs[1],false);
}
/**
* The status of an extension has changed to registered
*/
else if (eregi("Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Registered",$line,$regs))
{
print T_("Registered") . T_(" Extension ") . $regs[1] . "\n";
$this->setExtensionStatus($regs[1],true);
}
//print $line . "\n\n";
$line = "";
}

View File

@@ -68,9 +68,6 @@ print "<div class='text'>" . get_operator_time($operator_id,"%a %d %b %h:%i%p")
if (is_voip_enabled($operator_id))
{
include("functions/functions.voip.php");
$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
@@ -78,7 +75,7 @@ if (is_voip_enabled($operator_id))
if (isset($exts[1]))
$exta = $exts[1];
$extp = get_extension_password($operator_id);
if ($v->getExtensionStatus($ext))
if (get_extension_status($operator_id))
print "<div class='online statusbutton'><a href='news://turnvoipoff'>" . T_("VoIP On") . "</a></div>";
else
print "<div class='offline statusbutton'><a href='irc://$exta:$extp@" . VOIP_SERVER . "/'>" . T_("VoIP Off") . "</a></div>";