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:
12
call.php
12
call.php
@@ -259,11 +259,7 @@ switch($state)
|
|||||||
$es = 1;
|
$es = 1;
|
||||||
if (is_voip_enabled($operator_id))
|
if (is_voip_enabled($operator_id))
|
||||||
{
|
{
|
||||||
include("functions/functions.voip.php");
|
if (get_extension_status($operator_id))
|
||||||
$v = new voip();
|
|
||||||
$v->connect(VOIP_SERVER);
|
|
||||||
$ext = get_extension($operator_id);
|
|
||||||
if ($v->getExtensionStatus($ext))
|
|
||||||
$es = 1;
|
$es = 1;
|
||||||
else
|
else
|
||||||
$es = 0;
|
$es = 0;
|
||||||
@@ -339,11 +335,7 @@ switch($state)
|
|||||||
$es = 1;
|
$es = 1;
|
||||||
if (is_voip_enabled($operator_id))
|
if (is_voip_enabled($operator_id))
|
||||||
{
|
{
|
||||||
include("functions/functions.voip.php");
|
if (get_extension_status($operator_id))
|
||||||
$v = new voip();
|
|
||||||
$v->connect(VOIP_SERVER);
|
|
||||||
$ext = get_extension($operator_id);
|
|
||||||
if ($v->getExtensionStatus($ext))
|
|
||||||
$es = 1;
|
$es = 1;
|
||||||
else
|
else
|
||||||
$es = 0;
|
$es = 0;
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ CREATE TABLE `operator` (
|
|||||||
`Time_zone_name` char(64) NOT NULL,
|
`Time_zone_name` char(64) NOT NULL,
|
||||||
`enabled` tinyint(1) NOT NULL default '1',
|
`enabled` tinyint(1) NOT NULL default '1',
|
||||||
`voip` 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`),
|
PRIMARY KEY (`operator_id`),
|
||||||
UNIQUE KEY `username` (`username`),
|
UNIQUE KEY `username` (`username`),
|
||||||
UNIQUE KEY `extension` (`extension`)
|
UNIQUE KEY `extension` (`extension`)
|
||||||
|
|||||||
@@ -537,6 +537,26 @@ function get_call_number($call_id)
|
|||||||
return false;
|
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
|
* Return the extension password of an operator
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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)
|
function setState($call_id,$state,$checkOutcome = false)
|
||||||
{
|
{
|
||||||
global $db;
|
global $db;
|
||||||
@@ -447,6 +462,33 @@ class voipWatch extends voip {
|
|||||||
$db->Execute($sql);
|
$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
|
* Watch for Asterisk events and make changes to the queXS databse if
|
||||||
* appropriate
|
* appropriate
|
||||||
@@ -460,12 +502,16 @@ class voipWatch extends voip {
|
|||||||
*/
|
*/
|
||||||
if ($process_id) include_once(dirname(__FILE__).'/../functions/functions.process.php');
|
if ($process_id) include_once(dirname(__FILE__).'/../functions/functions.process.php');
|
||||||
|
|
||||||
|
|
||||||
$line = "";
|
$line = "";
|
||||||
|
|
||||||
if ($this->socket === false)
|
if ($this->socket === false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Set initial extension status
|
||||||
|
$this->updateAllExtensionStatus();
|
||||||
|
|
||||||
|
|
||||||
|
//Watch for events
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!$this->isConnected() || $this->socket === false){
|
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";
|
//print $line . "\n\n";
|
||||||
$line = "";
|
$line = "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
if (is_voip_enabled($operator_id))
|
||||||
{
|
{
|
||||||
include("functions/functions.voip.php");
|
|
||||||
$v = new voip();
|
|
||||||
$v->connect(VOIP_SERVER);
|
|
||||||
$ext = get_extension($operator_id);
|
$ext = get_extension($operator_id);
|
||||||
$exta = $ext;
|
$exta = $ext;
|
||||||
//Get just the start of the extension for auto dial out
|
//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]))
|
if (isset($exts[1]))
|
||||||
$exta = $exts[1];
|
$exta = $exts[1];
|
||||||
$extp = get_extension_password($operator_id);
|
$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>";
|
print "<div class='online statusbutton'><a href='news://turnvoipoff'>" . T_("VoIP On") . "</a></div>";
|
||||||
else
|
else
|
||||||
print "<div class='offline statusbutton'><a href='irc://$exta:$extp@" . VOIP_SERVER . "/'>" . T_("VoIP Off") . "</a></div>";
|
print "<div class='offline statusbutton'><a href='irc://$exta:$extp@" . VOIP_SERVER . "/'>" . T_("VoIP Off") . "</a></div>";
|
||||||
|
|||||||
Reference in New Issue
Block a user