fusionpbx/app/xml_cdr/v_xml_cdr_import.php

714 lines
26 KiB
PHP
Raw Normal View History

<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2018-04-18 19:52:45 +02:00
Portions created by the Initial Developer are Copyright (C) 2008-2018
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
2014-06-22 00:08:11 +02:00
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
2014-06-22 00:08:11 +02:00
//check the permission
2018-10-24 18:51:56 +02:00
if (defined('STDIN')) {
$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
preg_match("/^(.*)\/app\/.*$/", $document_root, $matches);
$document_root = $matches[1];
set_include_path($document_root);
$_SERVER["DOCUMENT_ROOT"] = $document_root;
require_once "resources/require.php";
}
else {
include "root.php";
require_once "resources/require.php";
require_once "resources/pdo.php";
}
//set debug
2015-03-07 11:59:00 +01:00
$debug = false; //true //false
2019-10-07 22:55:20 +02:00
if ($debug) {
$time5 = microtime(true);
$insert_time=$insert_count=0;
}
function xml_cdr_log($msg) {
global $debug;
if (!$debug) {
return;
}
$fp = fopen($_SESSION['server']['temp']['dir'].'/xml_cdr.log', 'a+');
if (!$fp) {
return;
}
fwrite($fp, $msg);
fclose($fp);
}
//increase limits
set_time_limit(3600);
ini_set('memory_limit', '256M');
2014-06-22 00:08:11 +02:00
ini_set("precision", 6);
//set pdo attribute that enables exception handling
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//define accept_b_leg function
function accept_b_leg($xml){
// if no filter set allow all for backward compatibility
2019-10-07 22:55:20 +02:00
if(empty($_SESSION['cdr']['b_leg'])) {
return true;
}
// filter out by call direction
2019-10-07 22:55:20 +02:00
if(in_array(@$xml->variables->call_direction, $_SESSION['cdr']['b_leg'])) {
return true;
}
// Disable cdr write
return false;
}
//define the process_xml_cdr function
function process_xml_cdr($db, $leg, $xml_string) {
//set global variable
global $debug;
//fix the xml by escaping the contents of <sip_full_XXX>
$xml_string = preg_replace_callback("/<([^><]+)>(.*?[><].*?)<\/\g1>/",
function ($matches) {
return '<' . $matches[1] . '>' .
str_replace(">", "&gt;",
str_replace("<", "&lt;", $matches[2])
) .
'</' . $matches[1] . '>';
},
$xml_string
);
//parse the xml to get the call detail record info
try {
2019-12-23 19:17:34 +01:00
//send info to lthe log
xml_cdr_log($xml_string);
2019-12-23 19:17:34 +01:00
//disable xml entities
libxml_disable_entity_loader(true);
//load the string into an xml object
$xml = simplexml_load_string($xml_string, 'SimpleXMLElement', LIBXML_NOCDATA);
//send info to the log
xml_cdr_log("\nxml load done\n");
}
catch(Exception $e) {
echo $e->getMessage();
xml_cdr_log("\nfail loadxml: " . $e->getMessage() . "\n");
}
2018-04-19 00:29:57 +02:00
//convert the xml object to json
2019-09-03 21:21:06 +02:00
$json = json_encode($xml);
2018-04-19 00:29:57 +02:00
//convert json to an array
$array = json_decode($json, true);
//filter out b-legs
if($leg == 'b'){
if(!accept_b_leg($xml)){
return;
}
}
//prepare the database object
require_once "resources/classes/database.php";
$database = new database;
$database->table = "v_xml_cdr";
2019-09-03 21:21:06 +02:00
2017-05-29 23:14:38 +02:00
//caller info
2019-09-03 21:21:06 +02:00
$database->fields['caller_destination'] = urldecode($xml->variables->caller_destination);
2020-04-17 20:33:57 +02:00
//misc
2019-09-03 21:21:06 +02:00
$uuid = urldecode($xml->variables->uuid);
2018-10-18 06:03:31 +02:00
$database->fields['xml_cdr_uuid'] = $uuid;
2019-09-03 21:21:06 +02:00
$database->fields['accountcode'] = urldecode($xml->variables->accountcode);
$database->fields['default_language'] = urldecode($xml->variables->default_language);
$database->fields['bridge_uuid'] = urldecode($xml->variables->bridge_uuid);
//$database->fields['digits_dialed'] = urldecode($xml->variables->digits_dialed);
$database->fields['sip_hangup_disposition'] = urldecode($xml->variables->sip_hangup_disposition);
$database->fields['pin_number'] = urldecode($xml->variables->pin_number);
2020-04-17 20:33:57 +02:00
//time
2019-09-03 21:21:06 +02:00
$database->fields['start_epoch'] = urldecode($xml->variables->start_epoch);
$start_stamp = urldecode($xml->variables->start_stamp);
$database->fields['start_stamp'] = $start_stamp;
2019-09-03 21:21:06 +02:00
$database->fields['answer_stamp'] = urldecode($xml->variables->answer_stamp);
$database->fields['answer_epoch'] = urldecode($xml->variables->answer_epoch);
$database->fields['end_epoch'] = urldecode($xml->variables->end_epoch);
$database->fields['end_stamp'] = urldecode($xml->variables->end_stamp);
$database->fields['duration'] = urldecode($xml->variables->duration);
$database->fields['mduration'] = urldecode($xml->variables->mduration);
$database->fields['billsec'] = urldecode($xml->variables->billsec);
$database->fields['billmsec'] = urldecode($xml->variables->billmsec);
2020-04-17 20:33:57 +02:00
//codecs
2019-09-03 21:21:06 +02:00
$database->fields['read_codec'] = urldecode($xml->variables->read_codec);
$database->fields['read_rate'] = urldecode($xml->variables->read_rate);
$database->fields['write_codec'] = urldecode($xml->variables->write_codec);
$database->fields['write_rate'] = urldecode($xml->variables->write_rate);
$database->fields['remote_media_ip'] = urldecode($xml->variables->remote_media_ip);
$database->fields['hangup_cause'] = urldecode($xml->variables->hangup_cause);
$database->fields['hangup_cause_q850'] = urldecode($xml->variables->hangup_cause_q850);
2020-04-17 20:33:57 +02:00
//store the call direction
$database->fields['direction'] = urldecode($xml->variables->call_direction);
//call center
2019-09-03 21:21:06 +02:00
$database->fields['cc_side'] = urldecode($xml->variables->cc_side);
$database->fields['cc_member_uuid'] = urldecode($xml->variables->cc_member_uuid);
$database->fields['cc_queue_joined_epoch'] = urldecode($xml->variables->cc_queue_joined_epoch);
$database->fields['cc_queue'] = urldecode($xml->variables->cc_queue);
$database->fields['cc_member_session_uuid'] = urldecode($xml->variables->cc_member_session_uuid);
$database->fields['cc_agent_uuid'] = urldecode($xml->variables->cc_agent_uuid);
$database->fields['cc_agent'] = urldecode($xml->variables->cc_agent);
$database->fields['cc_agent_type'] = urldecode($xml->variables->cc_agent_type);
$database->fields['cc_agent_bridged'] = urldecode($xml->variables->cc_agent_bridged);
$database->fields['cc_queue_answered_epoch'] = urldecode($xml->variables->cc_queue_answered_epoch);
$database->fields['cc_queue_terminated_epoch'] = urldecode($xml->variables->cc_queue_terminated_epoch);
$database->fields['cc_queue_canceled_epoch'] = urldecode($xml->variables->cc_queue_canceled_epoch);
$database->fields['cc_cancel_reason'] = urldecode($xml->variables->cc_cancel_reason);
$database->fields['cc_cause'] = urldecode($xml->variables->cc_cause);
$database->fields['waitsec'] = urldecode($xml->variables->waitsec);
if (urldecode($xml->variables->cc_side) == 'agent') {
$database->fields['direction'] = 'inbound';
}
2020-04-17 20:33:57 +02:00
//app info
2019-09-03 21:21:06 +02:00
$database->fields['last_app'] = urldecode($xml->variables->last_app);
$database->fields['last_arg'] = urldecode($xml->variables->last_arg);
2020-04-17 20:33:57 +02:00
//conference
2019-09-03 21:21:06 +02:00
$database->fields['conference_name'] = urldecode($xml->variables->conference_name);
$database->fields['conference_uuid'] = urldecode($xml->variables->conference_uuid);
$database->fields['conference_member_id'] = urldecode($xml->variables->conference_member_id);
2020-04-17 20:33:57 +02:00
//call quality
2019-09-03 21:21:06 +02:00
$rtp_audio_in_mos = urldecode($xml->variables->rtp_audio_in_mos);
if (strlen($rtp_audio_in_mos) > 0) {
$database->fields['rtp_audio_in_mos'] = $rtp_audio_in_mos;
}
2019-03-16 11:17:01 +01:00
//set missed calls
$database->fields['missed_call'] = 'false';
if (strlen($xml->variables->answer_stamp) == 0) {
$database->fields['missed_call'] = 'true';
2019-03-16 11:17:01 +01:00
}
2019-03-17 07:49:43 +01:00
if ($xml->variables->missed_call == 'true') {
$database->fields['missed_call'] = 'true';
}
2019-03-16 11:17:01 +01:00
2019-03-17 07:51:06 +01:00
//get the caller details
2020-02-01 00:36:03 +01:00
$database->fields['caller_id_name'] = urldecode($xml->variables->caller_id_name);
$database->fields['caller_id_number'] = urldecode($xml->variables->caller_id_number);
if (isset($xml->variables->effective_caller_id_name)) {
$database->fields['caller_id_name'] = urldecode($xml->variables->effective_caller_id_name);
}
if (isset($xml->variables->effective_caller_id_number)) {
$database->fields['caller_id_number'] = urldecode($xml->variables->effective_caller_id_number);
}
2019-03-17 07:51:06 +01:00
//get the values from the callflow.
2019-09-03 21:21:06 +02:00
$i = 0;
foreach ($xml->callflow as $row) {
2019-09-03 21:21:06 +02:00
if ($i == 0) {
$context = urldecode($row->caller_profile->context);
2020-04-17 20:33:57 +02:00
$destination_number = urldecode($row->caller_profile->destination_number);
$database->fields['context'] = $context;
2019-09-03 21:21:06 +02:00
$database->fields['network_addr'] = urldecode($row->caller_profile->network_addr);
}
2018-10-17 23:45:23 +02:00
if (strlen($database->fields['caller_id_name']) == 0) {
2019-09-03 21:21:06 +02:00
$database->fields['caller_id_name'] = urldecode($row->caller_profile->caller_id_name);
2018-10-17 23:41:14 +02:00
}
2018-10-17 23:45:23 +02:00
if (strlen($database->fields['caller_id_number']) == 0) {
2019-09-03 21:21:06 +02:00
$database->fields['caller_id_number'] = urldecode($row->caller_profile->caller_id_number);
2018-10-17 23:41:14 +02:00
}
2019-09-03 21:21:06 +02:00
$i++;
}
2019-09-03 21:21:06 +02:00
unset($i);
//if last_sent_callee_id_number is set use it for the destination_number
if (($leg == 'a') && (strlen($xml->variables->last_sent_callee_id_number) > 0)) {
2020-04-17 20:33:57 +02:00
$destination_number = urldecode($xml->variables->last_sent_callee_id_number);
2020-04-17 20:51:49 +02:00
}
//remove the provider prefix
if (isset($xml->variables->provider_prefix) && isset($destination_number)) {
$provider_prefix = $xml->variables->provider_prefix;
if ($provider_prefix == substr($destination_number, 0, strlen($provider_prefix))) {
2020-04-17 20:33:57 +02:00
$destination_number = substr($destination_number, strlen($provider_prefix), strlen($destination_number));
}
}
2020-04-17 20:51:49 +02:00
//store the destination_number
$database->fields['destination_number'] = $destination_number;
//store the call leg
$database->fields['leg'] = $leg;
//store post dial delay, in milliseconds
2019-09-03 21:21:06 +02:00
$database->fields['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec);
//get break down the date to year, month and day
2018-04-18 19:52:45 +02:00
$start_time = strtotime($start_stamp);
$start_year = date("Y", $start_time);
$start_month = date("M", $start_time);
$start_day = date("d", $start_time);
//get the domain values from the xml
2019-09-03 21:21:06 +02:00
$domain_name = urldecode($xml->variables->domain_name);
$domain_uuid = urldecode($xml->variables->domain_uuid);
2020-05-06 22:23:17 +02:00
//get the domain name
2020-05-06 22:19:28 +02:00
if (strlen($domain_name) == 0) {
$domain_name = urldecode($xml->variables->dialed_domain);
}
2020-05-06 22:23:17 +02:00
if (strlen($domain_name) == 0) {
$domain_name = urldecode($xml->variables->sip_invite_domain);
}
if (strlen($domain_name) == 0) {
2019-09-03 21:21:06 +02:00
$domain_name = urldecode($xml->variables->sip_req_host);
}
2020-05-06 22:23:17 +02:00
if (strlen($domain_name) == 0) {
$presence_id = urldecode($xml->variables->presence_id);
if (strlen($presence_id) > 0) {
$presence_array = explode($presence_id);
$domain_name = $presence_array[1];
}
}
//send the domain name to the cdr log
xml_cdr_log("\ndomain_name is `$domain_name`; domain_uuid is '$domain_uuid'\n");
//get the domain_uuid with the domain_name
if (strlen($domain_uuid) == 0) {
$sql = "select domain_uuid from v_domains ";
if (strlen($domain_name) == 0 && $context != 'public' && $context != 'default') {
2019-09-03 21:21:06 +02:00
$sql .= "where domain_name = :context ";
$parameters['context'] = $context;
}
else {
2019-09-03 21:21:06 +02:00
$sql .= "where domain_name = :domain_name ";
$parameters['domain_name'] = $domain_name;
}
2019-09-03 21:21:06 +02:00
$domain_uuid = $database->select($sql, $parameters, 'column');
unset($parameters);
}
//set values in the database
if (strlen($domain_uuid) > 0) {
$database->domain_uuid = $domain_uuid;
$database->fields['domain_uuid'] = $domain_uuid;
}
if (strlen($domain_name) > 0) {
$database->fields['domain_name'] = $domain_name;
}
2018-04-19 00:29:57 +02:00
//save to the database in json format
if ($_SESSION['cdr']['format']['text'] == "json" && $_SESSION['cdr']['storage']['text'] == "db") {
$database->fields['json'] = $json;
}
2016-12-21 22:14:45 +01:00
//dynamic cdr fields
if (is_array($_SESSION['cdr']['field'])) {
foreach ($_SESSION['cdr']['field'] as $field) {
2016-12-23 04:50:09 +01:00
$fields = explode(",", $field);
2016-12-23 05:10:22 +01:00
$field_name = end($fields);
if (count($fields) == 1) {
2018-04-19 00:29:57 +02:00
$database->fields[$field_name] = urldecode($array['variables'][$fields[0]]);
2016-12-23 04:50:09 +01:00
}
if (count($fields) == 2) {
2018-04-19 00:29:57 +02:00
$database->fields[$field_name] = urldecode($array[$fields[0]][$fields[1]]);
2016-12-23 04:50:09 +01:00
}
if (count($fields) == 3) {
2018-05-10 00:48:20 +02:00
$database->fields[$field_name] = urldecode($array[$fields[0]][0][$fields[1]][$fields[2]]);
}
if (count($fields) == 4) {
$database->fields[$field_name] = urldecode($array[$fields[0]][$fields[1]][$fields[2]][$fields[3]]);
}
if (count($fields) == 5) {
$database->fields[$field_name] = urldecode($array[$fields[0]][$fields[1]][$fields[2]][$fields[3]][$fields[4]]);
2016-12-23 04:50:09 +01:00
}
2016-12-21 22:14:45 +01:00
}
}
//save to the database in xml format
if ($_SESSION['cdr']['format']['text'] == "xml" && $_SESSION['cdr']['storage']['text'] == "db") {
2019-09-03 21:21:06 +02:00
$database->fields['xml'] = $xml_string;
}
2019-10-07 22:55:20 +02:00
//get the extension_uuid and then add it to the database fields array
if (strlen($xml->variables->extension_uuid) > 0) {
2019-09-03 21:21:06 +02:00
$database->fields['extension_uuid'] = urldecode($xml->variables->extension_uuid);
}
2019-10-07 21:17:21 +02:00
else {
2019-10-07 22:55:20 +02:00
if (strlen($xml->variables->dialed_user) > 0) {
2019-10-07 21:17:21 +02:00
$sql = "select extension_uuid from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and (extension = :dialed_user or number_alias = :dialed_user) ";
$parameters['domain_uuid'] = $domain_uuid;
2019-10-07 22:55:20 +02:00
$parameters['dialed_user'] = $xml->variables->dialed_user;
2019-10-07 21:17:21 +02:00
$extension_uuid = $database->select($sql, $parameters, 'column');
2019-10-07 22:55:20 +02:00
$database->fields['extension_uuid'] = $extension_uuid;
2019-10-07 21:17:21 +02:00
unset($parameters);
}
2019-10-08 07:37:53 +02:00
if (strlen($xml->variables->referred_by_user) > 0) {
$sql = "select extension_uuid from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and (extension = :referred_by_user or number_alias = :referred_by_user) ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['referred_by_user'] = $xml->variables->referred_by_user;
$extension_uuid = $database->select($sql, $parameters, 'column');
$database->fields['extension_uuid'] = $extension_uuid;
unset($parameters);
}
2019-10-08 07:43:02 +02:00
if (strlen($xml->variables->last_sent_callee_id_number) > 0) {
2019-10-08 07:37:53 +02:00
$sql = "select extension_uuid from v_extensions ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and (extension = :callee_id_number or number_alias = :callee_id_number) ";
$parameters['domain_uuid'] = $domain_uuid;
2019-10-08 07:43:02 +02:00
$parameters['callee_id_number'] = $xml->variables->last_sent_callee_id_number;
2019-10-08 07:37:53 +02:00
$extension_uuid = $database->select($sql, $parameters, 'column');
$database->fields['extension_uuid'] = $extension_uuid;
unset($parameters);
}
2019-10-07 21:17:21 +02:00
}
2017-10-15 19:38:49 +02:00
//get the recording details
2018-03-16 06:21:56 +01:00
if (strlen($xml->variables->record_session) > 0) {
2017-10-15 19:38:49 +02:00
$record_path = urldecode($xml->variables->record_path);
$record_name = urldecode($xml->variables->record_name);
2020-03-10 17:41:38 +01:00
if (isset($xml->variables->record_seconds)) {
$record_length = urldecode($xml->variables->record_seconds);
}
else {
$record_length = urldecode($xml->variables->duration);
}
2017-10-15 19:38:49 +02:00
}
2018-10-24 18:51:56 +02:00
elseif (!isset($record_path) && urldecode($xml->variables->last_app) == "record_session") {
2018-04-22 19:51:36 +02:00
$record_path = dirname(urldecode($xml->variables->last_arg));
$record_name = basename(urldecode($xml->variables->last_arg));
$record_length = urldecode($xml->variables->record_seconds);
}
2018-03-16 06:21:56 +01:00
elseif (strlen($xml->variables->record_name) > 0) {
$record_path = urldecode($xml->variables->record_path);
$record_name = urldecode($xml->variables->record_name);
$record_length = urldecode($xml->variables->duration);
}
2017-10-15 19:38:49 +02:00
elseif (strlen($xml->variables->sofia_record_file) > 0) {
$record_path = dirname(urldecode($xml->variables->sofia_record_file));
$record_name = basename(urldecode($xml->variables->sofia_record_file));
$record_length = urldecode($xml->variables->record_seconds);
}
2018-02-05 21:26:30 +01:00
elseif (strlen($xml->variables->cc_record_filename) > 0) {
$record_path = dirname(urldecode($xml->variables->cc_record_filename));
$record_name = basename(urldecode($xml->variables->cc_record_filename));
$record_length = urldecode($xml->variables->record_seconds);
}
2017-10-21 00:46:29 +02:00
elseif (strlen($xml->variables->api_on_answer) > 0) {
$command = str_replace("\n", " ", urldecode($xml->variables->api_on_answer));
$parts = explode(" ", $command);
if ($parts[0] == "uuid_record") {
$recording = $parts[3];
$record_path = dirname($recording);
$record_name = basename($recording);
2017-10-21 01:57:57 +02:00
$record_length = urldecode($xml->variables->duration);
}
}
2017-10-21 02:02:58 +02:00
elseif (strlen($xml->variables->current_application_data) > 0) {
$commands = explode(",", urldecode($xml->variables->current_application_data));
2017-10-21 01:57:57 +02:00
foreach ($commands as $command) {
$cmd = explode("=", $command);
if ($cmd[0] == "api_on_answer") {
$a = explode("]", $cmd[1]);
$command = str_replace("'", "", $a[0]);
$parts = explode(" ", $command);
if ($parts[0] == "uuid_record") {
$recording = $parts[3];
$record_path = dirname($recording);
$record_name = basename($recording);
$record_length = urldecode($xml->variables->duration);
}
}
2017-10-21 00:46:29 +02:00
}
}
if (!isset($record_name) || is_null ($record_name) || (strlen($record_name) == 0)) {
2018-04-18 19:52:45 +02:00
$bridge_uuid = urldecode($xml->variables->bridge_uuid);
2018-05-20 00:59:24 +02:00
$path = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/archive/'.$start_year.'/'.$start_month.'/'.$start_day;
if (file_exists($path.'/'.$bridge_uuid.'.wav')) {
$record_path = $path;
2018-04-18 19:52:45 +02:00
$record_name = $bridge_uuid.'.wav';
2018-05-20 00:59:24 +02:00
$record_length = urldecode($xml->variables->duration);
2019-10-07 22:55:20 +02:00
}
elseif (file_exists($path.'/'.$bridge_uuid.'.mp3')) {
2018-05-20 00:59:24 +02:00
$record_path = $path;
2018-04-18 19:52:45 +02:00
$record_name = $bridge_uuid.'.mp3';
2018-05-20 00:59:24 +02:00
$record_length = urldecode($xml->variables->duration);
}
}
if (!isset($record_name) || is_null ($record_name) || (strlen($record_name) == 0)) {
2018-05-20 00:59:24 +02:00
$path = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/archive/'.$start_year.'/'.$start_month.'/'.$start_day;
if (file_exists($path.'/'.$uuid.'.wav')) {
$record_path = $path;
$record_name = $uuid.'.wav';
$record_length = urldecode($xml->variables->duration);
2019-10-07 22:55:20 +02:00
}
elseif (file_exists($path.'/'.$uuid.'.mp3')) {
2018-05-20 00:59:24 +02:00
$record_path = $path;
$record_name = $uuid.'.mp3';
$record_length = urldecode($xml->variables->duration);
2018-04-18 19:52:45 +02:00
}
}
2017-10-15 19:38:49 +02:00
//add the call recording
2017-10-15 19:50:09 +02:00
if (isset($record_path) && isset($record_name) && file_exists($record_path.'/'.$record_name) && $record_length > 0) {
2017-10-15 19:38:49 +02:00
//add to the xml cdr table
2017-10-15 19:50:09 +02:00
$database->fields['record_path'] = $record_path;
2017-10-15 19:38:49 +02:00
$database->fields['record_name'] = $record_name;
2019-03-14 21:57:46 +01:00
if (isset($xml->variables->record_description)) {
$record_description = urldecode($xml->variables->record_description);
}
2017-10-15 19:38:49 +02:00
//add to the call recordings table
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_recordings/app_config.php")) {
//build the array
2019-09-03 21:21:06 +02:00
$i = 0;
$recordings['call_recordings'][$i]['call_recording_uuid'] = $uuid;
$recordings['call_recordings'][$i]['domain_uuid'] = $domain_uuid;
$recordings['call_recordings'][$i]['call_recording_name'] = $record_name;
$recordings['call_recordings'][$i]['call_recording_path'] = $record_path;
$recordings['call_recordings'][$i]['call_recording_length'] = $record_length;
$recordings['call_recordings'][$i]['call_recording_description'] = $record_description;
$recordings['call_recordings'][$i]['call_recording_date'] = urldecode($xml->variables->start_stamp);
$recordings['call_recordings'][$i]['call_direction'] = urldecode($xml->variables->call_direction);
//$recordings['call_recordings'][$i]['call_recording_description']= $row['zzz'];
//$recordings['call_recordings'][$i]['call_recording_base64']= $row['zzz'];
2017-10-15 19:38:49 +02:00
//add the temporary permission
$p = new permissions;
$p->add("call_recording_add", "temp");
$p->add("call_recording_edit", "temp");
$recording_database = new database;
$recording_database->app_name = 'call_recordings';
$recording_database->app_uuid = '56165644-598d-4ed8-be01-d960bcb8ffed';
$recording_database->domain_uuid = $domain_uuid;
$recording_database->save($recordings);
2019-09-03 21:21:06 +02:00
//$message = $recording_database->message;
unset($recordings, $i);
2017-10-15 19:38:49 +02:00
//remove the temporary permission
$p->delete("call_recording_add", "temp");
$p->delete("call_recording_edit", "temp");
}
}
//insert xml_cdr into the db
if (strlen($start_stamp) > 0) {
$database->add();
if ($debug) {
echo $database->sql."\n";
}
}
//insert the values
if (strlen($uuid) > 0) {
if ($debug) {
$time5_insert = microtime(true);
//echo $sql."<br />\n";
}
try {
$error = "false";
2019-09-03 21:21:06 +02:00
//$db->exec($sql);
}
catch(PDOException $e) {
$tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/failed/';
2019-10-07 22:55:20 +02:00
if (!file_exists($tmp_dir)) {
event_socket_mkdir($tmp_dir);
}
if ($_SESSION['cdr']['format']['text'] == "xml") {
$tmp_file = $uuid.'.xml';
$fh = fopen($tmp_dir.'/'.$tmp_file, 'w');
fwrite($fh, $xml_string);
}
else {
$tmp_file = $uuid.'.json';
$fh = fopen($tmp_dir.'/'.$tmp_file, 'w');
fwrite($fh, json_encode($xml));
}
fclose($fh);
if ($debug) {
echo $e->getMessage();
}
$error = "true";
}
if ($_SESSION['cdr']['storage']['text'] == "dir" && $error != "true") {
if (strlen($uuid) > 0) {
2018-04-18 19:52:45 +02:00
$tmp_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr/archive/'.$start_year.'/'.$start_month.'/'.$start_day;
2019-10-07 22:55:20 +02:00
if (!file_exists($tmp_dir)) {
event_socket_mkdir($tmp_dir);
}
if ($_SESSION['cdr']['format']['text'] == "xml") {
$tmp_file = $uuid.'.xml';
$fh = fopen($tmp_dir.'/'.$tmp_file, 'w');
fwrite($fh, $xml_string);
}
else {
$tmp_file = $uuid.'.json';
$fh = fopen($tmp_dir.'/'.$tmp_file, 'w');
fwrite($fh, json_encode($xml));
}
fclose($fh);
}
}
unset($error);
if ($debug) {
GLOBAL $insert_time,$insert_count;
2014-06-14 09:19:56 +02:00
$insert_time+=microtime(true)-$time5_insert; //add this current query.
$insert_count++;
}
}
unset($sql);
2017-09-11 09:46:50 +02:00
}
//get cdr details from the http post
if (strlen($_POST["cdr"]) > 0) {
2014-06-18 03:40:17 +02:00
if ($debug){
print_r ($_POST["cdr"]);
}
//authentication for xml cdr http post
if ($_SESSION["cdr"]["http_enabled"]["boolean"] == "true" && strlen($_SESSION["xml_cdr"]["username"]) == 0) {
//get the contents of xml_cdr.conf.xml
$conf_xml_string = file_get_contents($_SESSION['switch']['conf']['dir'].'/autoload_configs/xml_cdr.conf.xml');
//parse the xml to get the call detail record info
try {
2019-12-23 19:23:53 +01:00
//disable xml entities
libxml_disable_entity_loader(true);
//load the string into an xml object
$conf_xml = simplexml_load_string($conf_xml_string, 'SimpleXMLElement', LIBXML_NOCDATA);
}
catch(Exception $e) {
echo $e->getMessage();
}
foreach ($conf_xml->settings->param as $row) {
if ($row->attributes()->name == "cred") {
$auth_array = explode(":", $row->attributes()->value);
//echo "username: ".$auth_array[0]."<br />\n";
//echo "password: ".$auth_array[1]."<br />\n";
}
if ($row->attributes()->name == "url") {
//check name is equal to url
}
}
}
//if http enabled is set to false then deny access
if ($_SESSION["cdr"]["http_enabled"]["boolean"] == "false") {
echo "access denied<br />\n";
return;
}
//check for the correct username and password
if ($_SESSION["cdr"]["http_enabled"]["boolean"] == "true") {
if ($auth_array[0] == $_SERVER["PHP_AUTH_USER"] && $auth_array[1] == $_SERVER["PHP_AUTH_PW"]) {
//echo "access granted<br />\n";
$_SESSION["xml_cdr"]["username"] = $auth_array[0];
$_SESSION["xml_cdr"]["password"] = $auth_array[1];
}
else {
echo "access denied<br />\n";
return;
}
}
2020-04-17 20:33:57 +02:00
//loop through all attribues
//foreach($xml->settings->param[1]->attributes() as $a => $b) {
// echo $a,'="',$b,"\"<br />\n";
//}
//get the http post variable
$xml_string = trim($_POST["cdr"]);
//get the leg of the call
if (substr($_REQUEST['uuid'], 0, 2) == "a_") {
$leg = "a";
}
else {
$leg = "b";
}
xml_cdr_log("process cdr via post\n");
2020-04-17 20:33:57 +02:00
//parse the xml and insert the data into the db
process_xml_cdr($db, $leg, $xml_string);
}
//check the filesystem for xml cdr records that were missed
$xml_cdr_dir = $_SESSION['switch']['log']['dir'].'/xml_cdr';
$dir_handle = opendir($xml_cdr_dir);
$x = 0;
while($file = readdir($dir_handle)) {
if ($file != '.' && $file != '..') {
2020-04-29 00:15:18 +02:00
//import the call detail files are less than 3 mb - 3 million bytes
if (!is_dir($xml_cdr_dir . '/' . $file) && filesize($xml_cdr_dir.'/'.$file) < 3000000) {
//get the leg of the call
if (substr($file, 0, 2) == "a_") {
$leg = "a";
}
else {
$leg = "b";
}
//get the xml cdr string
$xml_string = file_get_contents($xml_cdr_dir.'/'.$file);
//parse the xml and insert the data into the db
process_xml_cdr($db, $leg, $xml_string);
//delete the file after it has been imported
unlink($xml_cdr_dir.'/'.$file);
2017-09-11 09:46:50 +02:00
//increment the variable
$x++;
}
}
}
closedir($dir_handle);
//debug true
if ($debug) {
$content = ob_get_contents(); //get the output from the buffer
ob_end_clean(); //clean the buffer
$time = "\n\n$insert_count inserts in: ".number_format($insert_time,5). " seconds.\n";
$time .= "Other processing time: ".number_format((microtime(true)-$time5-$insert_time),5). " seconds.\n";
xml_cdr_log($content.$time);
}
2015-05-01 19:39:13 +02:00
?>