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

Added process_log table to database

Log process data to a separate table for speed and better display (don't have to do too many updates)
Updated VoIP watching process to more gracefully handle socket timeouts/errors
This commit is contained in:
azammitdcarf
2011-02-17 03:36:18 +00:00
parent 614647435f
commit e1357712ce
7 changed files with 80 additions and 40 deletions

View File

@@ -188,9 +188,8 @@ function process_append_data($process_id,$data)
$data = $db->qstr($data,get_magic_quotes_gpc());
$sql = "UPDATE `process`
SET `data` = CONCAT(`data`, $data)
WHERE `process_id` = '$process_id'";
$sql = "INSERT INTO `process_log` (process_log_id,process_id,datetime,data)
VALUES (NULL,'$process_id',NOW(),$data)";
$db->Execute($sql);
@@ -208,16 +207,17 @@ function process_get_data($process_id)
{
global $db;
$sql = "SELECT `data`
FROM `process`
WHERE `process_id` = '$process_id'";
$sql = "SELECT process_log_id,datetime,data
FROM `process_log`
WHERE `process_id` = '$process_id'
ORDER BY process_log_id DESC";
$rs = $db->GetRow($sql);
$rs = $db->GetAll($sql);
if (!empty($rs))
return $rs['data'];
return $rs;
return "";
return false;
}
/**
@@ -231,7 +231,7 @@ function process_get_last_data($type = 1)
{
global $db;
$sql = "SELECT `data`
$sql = "SELECT process_id
FROM `process`
WHERE type = '$type'
ORDER BY `process_id` DESC
@@ -240,9 +240,9 @@ function process_get_last_data($type = 1)
$rs = $db->GetRow($sql);
if (!empty($rs))
return $rs['data'];
return process_get_data($rs['process_id']);
return "";
return false;
}
?>

View File

@@ -326,7 +326,7 @@ class voip {
return false;
}
stream_set_timeout($this->socket, 1);
// stream_set_timeout($this->socket, 1);
$q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: ";
@@ -395,11 +395,14 @@ class voipWatch extends voip {
function dbReconnect()
{
global $db;
//keep reconnecting to the db so it doesn't time out
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
if (!$db->IsConnected())
{
//keep reconnecting to the db so it doesn't time out
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
}
}
@@ -413,7 +416,7 @@ class voipWatch extends voip {
{
global $db;
$sql = "SELECT l.call_id
$sql = "SELECT l.call_id, c.case_id
FROM operator AS o
JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON
( c.current_operator_id = o.operator_id
@@ -426,10 +429,14 @@ class voipWatch extends voip {
$rs = $db->GetRow($sql);
$call_id =0;
$case_id =0;
if (!empty($rs))
{
$call_id =$rs['call_id'];
$case_id =$rs['case_id'];
}
return $call_id;
return array($call_id,$case_id);
}
@@ -511,10 +518,15 @@ class voipWatch extends voip {
$this->updateAllExtensionStatus();
$in = true;
$time = time();
//Watch for events
do
{
if (!$this->isConnected() || $this->socket === false){
if (!$this->isConnected() || $this->socket === false || $in === FALSE){
fclose($this->socket);
print(T_("Disconnected") . "\n");
$this->connect(VOIP_SERVER,VOIP_ADMIN_USER,VOIP_ADMIN_PASS,true);
if ($this->isConnected()) print (T_("Reconnected") . "\n");
@@ -522,6 +534,7 @@ class voipWatch extends voip {
$in = fgets($this->socket, 4096);
//print "IN: $in\n";
/**
@@ -536,10 +549,10 @@ class voipWatch extends voip {
*/
if (eregi("Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{
$call_id = $this->getCallId($regs[1]);
list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0)
{
print T_("Ringing") . T_(" Extension ") . $regs[1] . "\n";
print T_("Ringing") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,2);
}
}
@@ -548,10 +561,10 @@ class voipWatch extends voip {
*/
else if (eregi("Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{
$call_id = $this->getCallId($regs[1]);
list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0)
{
print T_("Answered") . T_(" Extension ") . $regs[1] . "\n";
print T_("Answered") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,3);
}
}
@@ -560,10 +573,10 @@ class voipWatch extends voip {
*/
else if (eregi("Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{
$call_id = $this->getCallId($regs[1]);
list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0)
{
print T_("Hangup") . T_(" Extension ") . $regs[1] . "\n";
print T_("Hangup") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,4,true);
}
}
@@ -589,7 +602,7 @@ class voipWatch extends voip {
//print $line . "\n\n";
$line = "";
}
else
else if ($in !== FALSE)
{
/**
* Append the lines to the message if we are not yet at the end of one
@@ -601,10 +614,11 @@ class voipWatch extends voip {
@flush();
if ($process_id)
if ($process_id && ((time() - $time) > 10))
{
$this->dbReconnect();
$this->keepWatching = !is_process_killed($process_id);
$time = time();
}
} while ($this->keepWatching);