Fix for QM live monitoring

Fix for Issue #1102

git-svn-id: svn://192.168.202.10@2993 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2018-05-29 15:05:33 +00:00
parent 118b64d732
commit 0c20dc8cb5
6 changed files with 139 additions and 49 deletions
@@ -1,7 +1,7 @@
<?php
# SCRIPT_multirecording.php - script page that stops/starts recordings being made over a forced-recording (ALLFORCE) call
#
# Copyright (C) 2017 Joe Johnson <joej@vicidial.com> LICENSE: AGPLv2
# Copyright (C) 2018 Joe Johnson <joej@vicidial.com> LICENSE: AGPLv2
# - works in conjunction with SCRIPT_multirecording_AJAX.php to allow reps the ability to make their own recordings over the course of a call while the entire call is being recorded into its own file, as in ALLFORCE recording.
#
# Implementation is done by creating a script in the Scripts section that calls this page within an <iframe> tag which passes several essential dialer variables to the page
@@ -16,9 +16,10 @@
# 120227-1512 - First Build
# 160401-0026 - HTML formatting fixes
# 170526-2158 - Added variable filtering
# 180514-2230 - Switched to mysqli
#
require("dbconnect.php");
require("dbconnect_mysqli.php");
if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];}
elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];}
if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
@@ -1,7 +1,7 @@
<?php
# SCRIPT_multirecording_AJAX.php - script that stops/starts recordings being made over a forced-recording (ALLFORCE) call
#
# Copyright (C) 2017 Joe Johnson, Matt Florell <mattf@vicidial.com> LICENSE: AGPLv2
# Copyright (C) 2018 Joe Johnson, Matt Florell <mattf@vicidial.com> LICENSE: AGPLv2
#
# Other scripts that this application depends on:
# - SCRIPT_multirecording.php: Gives agents ability to stop and start recordings over a forced-recording (ALLFORCE) call
@@ -11,9 +11,10 @@
# 130328-0009 - Converted ereg to preg functions
# 160401-0026 - Fix for Asterisk 1.8
# 170526-2157 - Added variable filtering
# 180514-2230 - Switched to mysqli, fixed variable filtering bug
#
require("dbconnect.php");
require("dbconnect_mysqli.php");
if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];}
elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];}
if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
@@ -53,11 +54,11 @@ $user = preg_replace("/\||`|&|\'|\"|\\\\|;| /","",$user);
$server_ip = preg_replace('/[^\.0-9]/','',$server_ip);
$uniqueid = preg_replace('/[^-_\.0-9a-zA-Z]/','',$uniqueid);
$rec_action = preg_replace('/[^0-9a-zA-Z]/','',$rec_action);
$recording_channel = preg_replace("/\||`|&|\'|\"|\\\\|;| /","",$recording_channel);
$recording_channel = preg_replace("/\||`|&|\'|\"|\\\\| /","",$recording_channel);
$stmt="select campaign_rec_filename from vicidial_campaigns where campaign_id='$campaign'";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_array($rslt);
$rslt=mysqli_query($link, $stmt);
$row=mysqli_fetch_array($rslt);
$filename=$row["campaign_rec_filename"];
$filename=preg_replace("/CAMPAIGN/i", $campaign, $filename);
$filename=preg_replace("/INGROUP/i", $campaign, $filename);
@@ -85,9 +86,9 @@ if ($rec_action=="START")
######################## START RECORDING ##########################
$stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$channel%\" and (channel LIKE \"%,1\" or channel LIKE \"%;1\");";
$rslt=mysql_query($stmt, $link);
$rslt=mysqli_query($link, $stmt);
$channel_SQL=" and channel not in (";
while($row=mysql_fetch_array($rslt))
while($row=mysqli_fetch_array($rslt))
{
$channel_SQL.="'$row[channel]',";
}
@@ -98,25 +99,25 @@ if ($rec_action=="START")
$VDvicidial_id='';
$stmt="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Originate','$filename','Channel: $channel','Context: $ext_context','Exten: $exten','Priority: $ext_priority','Callerid: $filename','','','','','');";
$rslt=mysql_query($stmt, $link);
$rslt=mysqli_query($link, $stmt);
$stmt = "INSERT INTO recording_log (channel,server_ip,extension,start_time,start_epoch,filename,lead_id,user) values('$channel','$server_ip','$exten','$NOW_TIME','$StarTtime','$filename','$lead_id','$user')";
$rslt=mysql_query($stmt, $link);
$RLaffected_rows = mysql_affected_rows($link);
$rslt=mysqli_query($link, $stmt);
$RLaffected_rows = mysqli_affected_rows($link);
if ($RLaffected_rows > 0) {
usleep(2000000);
$recording_id = mysql_insert_id($link);
$recording_id = mysqli_insert_id($link);
$current_rec_filename=$filename;
$channel_stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$channel%\" and (channel LIKE \"%,1\" or channel LIKE \"%;1\") $channel_SQL;";
$channel_rslt=mysql_query($channel_stmt, $link);
if (mysql_num_rows($channel_rslt)==1)
$channel_rslt=mysqli_query($link, $channel_stmt);
if (mysqli_num_rows($channel_rslt)==1)
{
$channel_row=mysql_fetch_row($channel_rslt);
$channel_row=mysqli_fetch_row($channel_rslt);
echo "$recording_id|$channel_row[0]";
}
else
{
echo "Error 2\n$channel_stmt\n".mysql_num_rows($channel_rslt);
echo "Error 2\n$channel_stmt\n".mysqli_num_rows($channel_rslt);
}
} else {
echo "Error 3";
@@ -125,10 +126,10 @@ if ($rec_action=="START")
##### get call type from vicidial_live_agents table
$VLA_inOUT='NONE';
$stmt="SELECT comments FROM vicidial_live_agents where user='$user' order by last_update_time desc limit 1;";
$rslt=mysql_query($stmt, $link);
$VLA_inOUT_ct = mysql_num_rows($rslt);
$rslt=mysqli_query($link, $stmt);
$VLA_inOUT_ct = mysqli_num_rows($rslt);
if ($VLA_inOUT_ct > 0) {
$row=mysql_fetch_row($rslt);
$row=mysqli_fetch_row($rslt);
$VLA_inOUT = $row[0];
}
if ($VLA_inOUT == 'INBOUND') {
@@ -141,13 +142,13 @@ if ($rec_action=="START")
$stmt="SELECT uniqueid FROM vicidial_log where uniqueid='$uniqueid' and lead_id='$lead_id';";
}
/*
$rslt=mysql_query($stmt, $link);
$VM_mancall_ct = mysql_num_rows($rslt);
$rslt=mysqli_query($link, $stmt);
$VM_mancall_ct = mysqli_num_rows($rslt);
if ($VM_mancall_ct > 0) {
$row=mysql_fetch_row($rslt);
$row=mysqli_fetch_row($rslt);
$VDvicidial_id = $row[0];
$stmt = "UPDATE recording_log SET vicidial_id='$VDvicidial_id' where recording_id='$recording_id';";
$rslt=mysql_query($stmt, $link);
$rslt=mysqli_query($link, $stmt);
}
*/
}
@@ -157,10 +158,10 @@ else
{
############### STOP RECORDING ########
$stmt="SELECT recording_id,start_epoch FROM recording_log where recording_id='$rec_action' and end_epoch is null";
$rslt=mysql_query($stmt, $link);
$rec_count = mysql_num_rows($rslt);
$rslt=mysqli_query($link, $stmt);
$rec_count = mysqli_num_rows($rslt);
if ($rec_count>0) {
$row=mysql_fetch_row($rslt);
$row=mysqli_fetch_row($rslt);
$recording_id = $row[0];
$start_time = $row[1];
$length_in_sec = ($StarTtime - $start_time);
@@ -168,23 +169,24 @@ else
$length_in_min = sprintf("%8.2f", $length_in_min);
$stmt = "UPDATE recording_log set end_time='$NOW_TIME',end_epoch='$StarTtime',length_in_sec=$length_in_sec,length_in_min='$length_in_min' where recording_id='$rec_action'";
$rslt=mysql_query($stmt, $link);
$rslt=mysqli_query($link, $stmt);
}
# find and hang up the recording
$stmt="SELECT channel FROM live_sip_channels where server_ip = '$server_ip' and channel LIKE \"$recording_channel%\" and (channel LIKE \"%,1\" or channel LIKE \"%;1\");";
$rslt=mysql_query($stmt, $link);
$rec_count = mysql_num_rows($rslt);
$rslt=mysqli_query($link, $stmt);
$rec_count = mysqli_num_rows($rslt);
$h=0;
while ($rec_count>$h) {
$rowx=mysql_fetch_row($rslt);
$rowx=mysqli_fetch_row($rslt);
$HUchannel[$h] = $rowx[0];
$h++;
}
$i=0;
while ($h>$i) {
$stmt="INSERT INTO vicidial_manager values('','','$NOW_TIME','NEW','N','$server_ip','','Hangup','RH12345$StarTtime$i','Channel: $HUchannel[$i]','','','','','','','','','');";
$rslt=mysql_query($stmt, $link);
$rslt=mysqli_query($link, $stmt);
$i++;
echo "HANGUP SUCCESSFUL";
}
+22 -5
View File
@@ -1,7 +1,7 @@
<?php
# QM_live_monitor.php
#
# Copyright (C) 2013 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# Script to initiate live monitoring from QueueMetrics link
#
@@ -10,10 +10,13 @@
# 130610-1130 - Finalized changing of all ereg instances to preg
# 130617-2128 - Added filtering of input to prevent SQL injection attacks
# 130901-0859 - Changed to mysqli PHP functions
# 180529-1005 - Added debug logging
#
$version = '2.8-4';
$build = '130901-0859';
$version = '2.14-5';
$build = '180529-1005';
$DBlogfile=0; # set to 1 for logfile writing
header ("Content-type: text/html; charset=utf-8");
@@ -53,6 +56,12 @@ $phone = preg_replace("/'|\"|\\\\|;/", '', $phone);
$type = preg_replace("/'|\"|\\\\|;/", '', $type);
$QMuser = preg_replace("/'|\"|\\\\|;/", '', $QMuser);
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, "QM Live-Monitor: " . date("U") . ' - ' . date("Y-m-d H:i:s") . " $version $build\nParameters: |$call|$user|$extension|$server_ip|$stage|$campaign|$phone|$type|$QMuser|\n");
fclose($logfile);
}
$ERR=0;
$ERRstring='';
@@ -105,12 +114,18 @@ if ($enable_queuemetrics_logging > 0)
$admDIR = preg_replace('/QM_live_monitor\.php/i', '',$admDIR);
$monitor_script = 'non_agent_api.php';
$monitorURL = "$admDIR$monitor_script?source=queuemetrics&function=blind_monitor&user=$user&pass=$call&phone_login=$extension&session_id=$session&server_ip=$server_ip&stage=$stage";
$monitorURL = "$admDIR$monitor_script?source=queuemetrics&function=blind_monitor&user=$user&pass=$call&phone_login=$extension&session_id=$session&server_ip=$server_ip&stage=$stage&value=$stage&agent_user=$user";
$monitorCONTENTS = file("$monitorURL");
if (preg_match('/SUCCESS/i',$monitorCONTENTS[0]))
{
echo "<HTML><BODY BGCOLOR=\"E6E6E6\" onLoad=\"javascript:window.close();\">\n";
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, "QM Live-Monitor Closing: $monitorCONTENTS[0]\n");
fclose($logfile);
}
}
else
{
@@ -149,8 +164,10 @@ if ($enable_queuemetrics_logging > 0)
echo "<TR><TD ALIGN=RIGHT>Queue: </TD><TD>$campaign</TD></TR>";
echo "<TR><TD ALIGN=RIGHT>Extension: </TD>";
echo "<TD><INPUT TYPE=TEXT NAME=extension SIZE=20 MAXLENGTH=20></TD></TR>\n";
echo "<TR><TD ALIGN=CENTER COLSPAN=2><INPUT TYPE=BUTTON VALUE=\"Close Window\" onClick=\"javascript:window.close();\">";
echo "<TR><TD ALIGN=CENTER COLSPAN=2>";
# echo "<INPUT TYPE=BUTTON VALUE=\"Close Window\" onClick=\"javascript:window.close();\">";
echo "<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT></TD></TR>\n";
echo "</TD></TR>\n";
echo "</FORM>";
echo "</BODY></HTML>";
exit;
+2 -2
View File
@@ -5761,7 +5761,7 @@ if ( ( (strlen($ADD)>4) and ($ADD < 99998) ) or ($ADD==3) or (($ADD>20) and ($AD
$XFERgroups_list .= "<input type=\"checkbox\" name=\"XFERgroups[]\" value=\"$group_id_values[$o]\"";
$RANKgroups_list .= "<tr $bgcolor><td><input type=\"checkbox\" name=\"groups[]\" value=\"$group_id_values[$o]\"";
$p=0;
$group_ct = count($groups);
if (is_array($groups)) {$group_ct = count($groups);} else {$group_ct=0;}
while ($p < $group_ct)
{
if ($group_id_values[$o] == $groups[$p])
@@ -5773,7 +5773,7 @@ if ( ( (strlen($ADD)>4) and ($ADD < 99998) ) or ($ADD==3) or (($ADD>20) and ($AD
$p++;
}
$p=0;
$XFERgroup_ct = count($XFERgroups);
if (is_array($XFERgroups)) {$XFERgroup_ct = count($XFERgroups);} else {$XFERgroup_ct=0;}
while ($p < $XFERgroup_ct)
{
if ($group_id_values[$o] == $XFERgroups[$p])
+19 -3
View File
@@ -131,10 +131,11 @@
# 180208-1655 - Added call_dispo_report function
# 180301-2301 - Added GET-AND-POST URL logging
# 180331-1716 - Added options to update_campaign, add_user, update_phone. Added function update_did
# 180529-1102 - Fix for QM live monitoring
#
$version = '2.14-108';
$build = '180331-1716';
$version = '2.14-109';
$build = '180529-1102';
$api_url_log = 0;
$startMS = microtime();
@@ -833,6 +834,21 @@ $auth_message = user_authorization($user,$pass,'REPORTS',1,1);
if ($auth_message == 'GOOD')
{$auth=1;}
if ($auth < 1)
{
if ( ($function == 'blind_monitor') and ($source == 'queuemetrics') and ($stage == 'MONITOR') )
{
$stmt="SELECT count(*) from vicidial_auto_calls where callerid='$pass';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$monauth_to_check = mysqli_num_rows($rslt);
if ($monauth_to_check > 0)
{
$rowvac=mysqli_fetch_row($rslt);
$auth = $rowvac[0];
}
}
}
if ($auth < 1)
{
$VDdisplayMESSAGE = "ERROR: Login incorrect, please try again";
@@ -6162,7 +6178,7 @@ if ($function == 'user_group_status')
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$mandial_to_check = mysqli_num_rows($rslt);
if ($mandial_to_check > 0)
if ($mandial_to_check > 0)
{
$rowvac=mysqli_fetch_row($rslt);
if ( (strlen($rowvac[0])<5) and (strlen($rowvac[1])<5) )
@@ -3,7 +3,7 @@
#
# Used for integration with QueueMetrics of audio recordings
#
# Copyright (C) 2013 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2018 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2007 Lenz Emilitri <lenz.loway@gmail.com> LICENSE: ????
#
# CHANGES
@@ -16,6 +16,7 @@
# 130610-1100 - Finalized changing of all ereg instances to preg
# 130615-2324 - Added filtering of input to prevent SQL injection attacks
# 130901-0829 - Changed to mysqli PHP functions
# 180529-1016 - Added debug logging
#
// $Id: xmlrpc_audio_server.php,v 1.3 2007/11/12 17:53:09 lenz Exp $
@@ -42,6 +43,14 @@
// "pear install XML_RPC-1.5.1"
//
$DBlogfile=0; # set to 1 for logfile writing
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, "Starting QM XML/RPC query: " . date("U") . ' - ' . date("Y-m-d H:i:s") . "\n");
fclose($logfile);
}
require_once 'XML/RPC/Server.php';
@@ -72,11 +81,14 @@ function find_file( $ServerID, $AsteriskID, $QMUserID, $QMUserName )
global $FILE_LENGTH;
global $FILE_ENCODING;
global $FILE_DURATION;
global $DBlogfile;
# uncomment below to enable basic logging of requests
# $fp = fopen ("./qm_rpc_debug.txt", "a");
# fwrite ($fp, date("U") . "|$ServerID|$AsteriskID|$QMUserID|$QMUserName|\n");
# fclose($fp);
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|$ServerID|$AsteriskID|$QMUserID|$QMUserName|\n");
fclose($logfile);
}
require("dbconnect_mysqli.php");
require("functions.php");
@@ -194,6 +206,13 @@ function find_file( $ServerID, $AsteriskID, $QMUserID, $QMUserName )
mysqli_close($linkB);
}
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|find_file|$FILE_FOUND|$FILE_LISTEN_URL|$FILE_LENGTH|$FILE_ENCODING|$FILE_DURATION|\n");
fclose($logfile);
}
# $FILE_FOUND = true;
# $FILE_LISTEN_URL = "http://listennow.server/$ServerID/$AsteriskID/$QMUserID/$QMUserName";
# $FILE_LENGTH = "125000";
@@ -207,6 +226,7 @@ function listen_call( $ServerID, $AsteriskID, $Agent, $QMUserID, $QMUserName )
global $CALL_LISTEN_URL;
global $CALL_POPUP_WIDTH;
global $CALL_POPUP_HEIGHT;
global $DBlogfile;
require("dbconnect_mysqli.php");
require("functions.php");
@@ -278,6 +298,13 @@ function listen_call( $ServerID, $AsteriskID, $Agent, $QMUserID, $QMUserName )
}
}
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|listen_call|$CALL_FOUND|$CALL_LISTEN_URL|\n");
fclose($logfile);
}
# $CALL_FOUND = true;
# $CALL_LISTEN_URL = "http://listennow.server/$ServerID/$AsteriskID/$QMUserID/$QMUserName/$Agent";
}
@@ -293,12 +320,20 @@ function xmlrpc_find_file( $params ) {
global $FILE_LENGTH;
global $FILE_ENCODING;
global $FILE_DURATION;
global $DBlogfile;
$p0 = $params->getParam(0)->scalarval(); // server ID
$p1 = $params->getParam(1)->scalarval(); // Asterisk call ID
$p2 = $params->getParam(2)->scalarval(); // QM User ID
$p3 = $params->getParam(3)->scalarval(); // Qm user name
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|TRIGGER_find_file|$p0|$p1|$p2|$p3|\n");
fclose($logfile);
}
find_file( $p0, $p1, $p2, $p3 );
$response = new XML_RPC_Value(array(
@@ -319,13 +354,21 @@ function xmlrpc_listen_call( $params ) {
global $CALL_LISTEN_URL;
global $CALL_POPUP_WIDTH;
global $CALL_POPUP_HEIGHT;
global $DBlogfile;
$p0 = $params->getParam(0)->scalarval(); // server ID
$p1 = $params->getParam(1)->scalarval(); // asterisk call ID
$p2 = $params->getParam(2)->scalarval(); // agent code
$p3 = $params->getParam(3)->scalarval(); // QM user ID
$p4 = $params->getParam(3)->scalarval(); // QM user name
if ($DBlogfile > 0)
{
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|TRIGGER_listen_call|$p0|$p1|$p2|$p3|$p4|\n");
fclose($logfile);
}
listen_call( $p0, $p1, $p2, $p3, $p4 );
$response = new XML_RPC_Value(array(
@@ -340,6 +383,17 @@ function xmlrpc_listen_call( $params ) {
if ($DBlogfile > 0)
{
if (getenv('REQUEST_METHOD') == 'POST')
{
$client_data = file_get_contents("php://input");
}
$logfile=fopen('qm_rpc_debug.txt', "a");
fwrite($logfile, date("U") . "|START_request|\n$client_data\nEND_request|\n");
fclose($logfile);
}
//
// Instantiates a very simple XML-RPC audio server for QueueMetrics
//