Update xml_cdr.php

This commit is contained in:
FusionPBX 2019-09-03 14:32:33 -06:00 committed by GitHub
parent 46e9f82e7e
commit 39cf5583bb
1 changed files with 107 additions and 97 deletions

View File

@ -170,46 +170,56 @@ if (!class_exists('xml_cdr')) {
$sql = "insert into v_xml_cdr ("; $sql = "insert into v_xml_cdr (";
$f = 1; $f = 1;
if (isset($this->fields)) foreach ($this->fields as $field) { if (isset($this->fields)) {
if ($field_count == $f) { foreach ($this->fields as $field) {
$sql .= "$field "; $field = preg_replace('#[^a-zA-Z0-9_\-]#', '', $field);
if ($field_count == $f) {
$sql .= "$field ";
}
else {
$sql .= "$field, ";
}
$f++;
} }
else {
$sql .= "$field, ";
}
$f++;
} }
$sql .= ")\n"; $sql .= ")\n";
$sql .= "values \n"; $sql .= "values \n";
$row_count = sizeof($this->array); $row_count = sizeof($this->array);
//$field_count = sizeof($this->fields); //$field_count = sizeof($this->fields);
$i = 0; $i = 0;
if (isset($this->array)) foreach ($this->array as $row) { if (isset($this->array)) {
$sql .= "("; foreach ($this->array as $row) {
$f = 1; $sql .= "(";
if (isset($this->fields)) foreach ($this->fields as $field) { $f = 1;
if (isset($row[$field]) && strlen($row[$field]) > 0) { if (isset($this->fields)) {
$sql .= "'".$row[$field]."'"; foreach ($this->fields as $field) {
$field = preg_replace('#[^a-zA-Z0-9_\-]#', '', $field);
if (isset($row[$field]) && strlen($row[$field]) > 0) {
$sql .= ":".$field." \n";
$parameters[$field] = $row[$field];
}
else {
$sql .= "null";
}
if ($field_count != $f) {
$sql .= ",";
}
$f++;
}
} }
else { $sql .= ")";
$sql .= "null"; if ($row_count != $i) {
$sql .= ",\n";
} }
if ($field_count != $f) { $i++;
$sql .= ",";
}
$f++;
} }
$sql .= ")";
if ($row_count != $i) {
$sql .= ",\n";
}
$i++;
} }
if (substr($sql,-2) == ",\n") { if (substr($sql,-2) == ",\n") {
$sql = substr($sql,0,-2); $sql = substr($sql,0,-2);
} }
$this->db->exec(check_sql($sql)); $database = new database;
unset($sql); $database->execute($sql, $parameters);
unset($sql, $parameters);
} }
/** /**
@ -244,8 +254,8 @@ if (!class_exists('xml_cdr')) {
//check for duplicate call uuid's //check for duplicate call uuid's
$duplicate_uuid = false; $duplicate_uuid = false;
$uuid = check_str(urldecode($xml->variables->uuid)); $uuid = urldecode($xml->variables->uuid);
if($uuid != null) { if($uuid != null && is_uuid($uuid)) {
//Check in the database //Check in the database
$database = new database; $database = new database;
$database->table = "v_xml_cdr"; $database->table = "v_xml_cdr";
@ -311,60 +321,60 @@ if (!class_exists('xml_cdr')) {
} }
//misc //misc
$uuid = check_str(urldecode($xml->variables->uuid)); $uuid = urldecode($xml->variables->uuid);
$this->array[$key]['xml_cdr_uuid'] = $uuid; $this->array[$key]['xml_cdr_uuid'] = $uuid;
$this->array[$key]['destination_number'] = check_str($destination_number); $this->array[$key]['destination_number'] = $destination_number;
$this->array[$key]['source_number'] = check_str(urldecode($xml->variables->effective_caller_id_number)); $this->array[$key]['source_number'] = urldecode($xml->variables->effective_caller_id_number);
$this->array[$key]['user_context'] = check_str(urldecode($xml->variables->user_context)); $this->array[$key]['user_context'] = urldecode($xml->variables->user_context);
$this->array[$key]['network_addr'] = check_str(urldecode($xml->variables->sip_network_ip)); $this->array[$key]['network_addr'] = urldecode($xml->variables->sip_network_ip);
$this->array[$key]['missed_call'] = check_str($missed_call); $this->array[$key]['missed_call'] = $missed_call;
$this->array[$key]['caller_id_name'] = check_str($caller_id_name); $this->array[$key]['caller_id_name'] = $caller_id_name;
$this->array[$key]['caller_id_number'] = check_str($caller_id_number); $this->array[$key]['caller_id_number'] = $caller_id_number;
$this->array[$key]['caller_destination'] = check_str(urldecode($xml->variables->caller_destination)); $this->array[$key]['caller_destination'] = urldecode($xml->variables->caller_destination);
$this->array[$key]['accountcode'] = check_str(urldecode($xml->variables->accountcode)); $this->array[$key]['accountcode'] = urldecode($xml->variables->accountcode);
$this->array[$key]['default_language'] = check_str(urldecode($xml->variables->default_language)); $this->array[$key]['default_language'] = urldecode($xml->variables->default_language);
$this->array[$key]['bridge_uuid'] = check_str(urldecode($xml->variables->bridge_uuid)); $this->array[$key]['bridge_uuid'] = urldecode($xml->variables->bridge_uuid);
//$this->array[$key]['digits_dialed'] = check_str(urldecode($xml->variables->digits_dialed)); //$this->array[$key]['digits_dialed'] = urldecode($xml->variables->digits_dialed);
$this->array[$key]['sip_hangup_disposition'] = check_str(urldecode($xml->variables->sip_hangup_disposition)); $this->array[$key]['sip_hangup_disposition'] = urldecode($xml->variables->sip_hangup_disposition);
$this->array[$key]['pin_number'] = check_str(urldecode($xml->variables->pin_number)); $this->array[$key]['pin_number'] = urldecode($xml->variables->pin_number);
//time //time
$this->array[$key]['start_epoch'] = check_str(urldecode($xml->variables->start_epoch)); $this->array[$key]['start_epoch'] = urldecode($xml->variables->start_epoch);
$start_stamp = check_str(urldecode($xml->variables->start_stamp)); $start_stamp = urldecode($xml->variables->start_stamp);
$this->array[$key]['start_stamp'] = $start_stamp; $this->array[$key]['start_stamp'] = $start_stamp;
$this->array[$key]['answer_stamp'] = check_str(urldecode($xml->variables->answer_stamp)); $this->array[$key]['answer_stamp'] = urldecode($xml->variables->answer_stamp);
$this->array[$key]['answer_epoch'] = check_str(urldecode($xml->variables->answer_epoch)); $this->array[$key]['answer_epoch'] = urldecode($xml->variables->answer_epoch);
$this->array[$key]['end_epoch'] = check_str(urldecode($xml->variables->end_epoch)); $this->array[$key]['end_epoch'] = urldecode($xml->variables->end_epoch);
$this->array[$key]['end_stamp'] = check_str(urldecode($xml->variables->end_stamp)); $this->array[$key]['end_stamp'] = urldecode($xml->variables->end_stamp);
$this->array[$key]['duration'] = check_str(urldecode($xml->variables->duration)); $this->array[$key]['duration'] = urldecode($xml->variables->duration);
$this->array[$key]['mduration'] = check_str(urldecode($xml->variables->mduration)); $this->array[$key]['mduration'] = urldecode($xml->variables->mduration);
$this->array[$key]['billsec'] = check_str(urldecode($xml->variables->billsec)); $this->array[$key]['billsec'] = urldecode($xml->variables->billsec);
$this->array[$key]['billmsec'] = check_str(urldecode($xml->variables->billmsec)); $this->array[$key]['billmsec'] = urldecode($xml->variables->billmsec);
//codecs //codecs
$this->array[$key]['read_codec'] = check_str(urldecode($xml->variables->read_codec)); $this->array[$key]['read_codec'] = urldecode($xml->variables->read_codec);
$this->array[$key]['read_rate'] = check_str(urldecode($xml->variables->read_rate)); $this->array[$key]['read_rate'] = urldecode($xml->variables->read_rate);
$this->array[$key]['write_codec'] = check_str(urldecode($xml->variables->write_codec)); $this->array[$key]['write_codec'] = urldecode($xml->variables->write_codec);
$this->array[$key]['write_rate'] = check_str(urldecode($xml->variables->write_rate)); $this->array[$key]['write_rate'] = urldecode($xml->variables->write_rate);
$this->array[$key]['remote_media_ip'] = check_str(urldecode($xml->variables->remote_media_ip)); $this->array[$key]['remote_media_ip'] = urldecode($xml->variables->remote_media_ip);
$this->array[$key]['hangup_cause'] = check_str(urldecode($xml->variables->hangup_cause)); $this->array[$key]['hangup_cause'] = urldecode($xml->variables->hangup_cause);
$this->array[$key]['hangup_cause_q850'] = check_str(urldecode($xml->variables->hangup_cause_q850)); $this->array[$key]['hangup_cause_q850'] = urldecode($xml->variables->hangup_cause_q850);
//call center //call center
$this->array[$key]['cc_side'] = check_str(urldecode($xml->variables->cc_side)); $this->array[$key]['cc_side'] = urldecode($xml->variables->cc_side);
$this->array[$key]['cc_member_uuid'] = check_str(urldecode($xml->variables->cc_member_uuid)); $this->array[$key]['cc_member_uuid'] = urldecode($xml->variables->cc_member_uuid);
$this->array[$key]['cc_queue_joined_epoch'] = check_str(urldecode($xml->variables->cc_queue_joined_epoch)); $this->array[$key]['cc_queue_joined_epoch'] = urldecode($xml->variables->cc_queue_joined_epoch);
$this->array[$key]['cc_queue'] = check_str(urldecode($xml->variables->cc_queue)); $this->array[$key]['cc_queue'] = urldecode($xml->variables->cc_queue);
$this->array[$key]['cc_member_session_uuid'] = check_str(urldecode($xml->variables->cc_member_session_uuid)); $this->array[$key]['cc_member_session_uuid'] = urldecode($xml->variables->cc_member_session_uuid);
$this->array[$key]['cc_agent'] = check_str(urldecode($xml->variables->cc_agent)); $this->array[$key]['cc_agent'] = urldecode($xml->variables->cc_agent);
$this->array[$key]['cc_agent_type'] = check_str(urldecode($xml->variables->cc_agent_type)); $this->array[$key]['cc_agent_type'] = urldecode($xml->variables->cc_agent_type);
$this->array[$key]['waitsec'] = check_str(urldecode($xml->variables->waitsec)); $this->array[$key]['waitsec'] = urldecode($xml->variables->waitsec);
//app info //app info
$this->array[$key]['last_app'] = check_str(urldecode($xml->variables->last_app)); $this->array[$key]['last_app'] = urldecode($xml->variables->last_app);
$this->array[$key]['last_arg'] = check_str(urldecode($xml->variables->last_arg)); $this->array[$key]['last_arg'] = urldecode($xml->variables->last_arg);
//conference //conference
$this->array[$key]['conference_name'] = check_str(urldecode($xml->variables->conference_name)); $this->array[$key]['conference_name'] = urldecode($xml->variables->conference_name);
$this->array[$key]['conference_uuid'] = check_str(urldecode($xml->variables->conference_uuid)); $this->array[$key]['conference_uuid'] = urldecode($xml->variables->conference_uuid);
$this->array[$key]['conference_member_id'] = check_str(urldecode($xml->variables->conference_member_id)); $this->array[$key]['conference_member_id'] = urldecode($xml->variables->conference_member_id);
//call quality //call quality
$rtp_audio_in_mos = check_str(urldecode($xml->variables->rtp_audio_in_mos)); $rtp_audio_in_mos = urldecode($xml->variables->rtp_audio_in_mos);
if (strlen($rtp_audio_in_mos) > 0) { if (strlen($rtp_audio_in_mos) > 0) {
$this->array[$key]['rtp_audio_in_mos'] = $rtp_audio_in_mos; $this->array[$key]['rtp_audio_in_mos'] = $rtp_audio_in_mos;
} }
@ -373,10 +383,10 @@ if (!class_exists('xml_cdr')) {
$this->array[$key]['leg'] = $leg; $this->array[$key]['leg'] = $leg;
//store the call direction //store the call direction
$this->array[$key]['direction'] = check_str(urldecode($xml->variables->call_direction)); $this->array[$key]['direction'] = urldecode($xml->variables->call_direction);
//store post dial delay, in milliseconds //store post dial delay, in milliseconds
$this->array[$key]['pdd_ms'] = check_str(urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec)); $this->array[$key]['pdd_ms'] = urldecode($xml->variables->progress_mediamsec) + urldecode($xml->variables->progressmsec);
//get break down the date to year, month and day //get break down the date to year, month and day
$tmp_time = strtotime($start_stamp); $tmp_time = strtotime($start_stamp);
@ -385,15 +395,15 @@ if (!class_exists('xml_cdr')) {
$tmp_day = date("d", $tmp_time); $tmp_day = date("d", $tmp_time);
//get the domain values from the xml //get the domain values from the xml
$domain_name = check_str(urldecode($xml->variables->domain_name)); $domain_name = urldecode($xml->variables->domain_name);
$domain_uuid = check_str(urldecode($xml->variables->domain_uuid)); $domain_uuid = urldecode($xml->variables->domain_uuid);
//get the domain name //get the domain name
if (strlen($domain_name) == 0) { if (strlen($domain_name) == 0) {
$domain_name = check_str(urldecode($xml->variables->sip_req_host)); $domain_name = urldecode($xml->variables->sip_req_host);
} }
if (strlen($domain_name) == 0) { if (strlen($domain_name) == 0) {
$presence_id = check_str(urldecode($xml->variables->presence_id)); $presence_id = urldecode($xml->variables->presence_id);
if (strlen($presence_id) > 0) { if (strlen($presence_id) > 0) {
$presence_array = explode($presence_id); $presence_array = explode($presence_id);
$domain_name = $presence_array[1]; $domain_name = $presence_array[1];
@ -523,7 +533,7 @@ if (!class_exists('xml_cdr')) {
// Last check // Last check
if (!isset($record_name) || is_null ($record_name) || (strlen($record_name) == 0)) { if (!isset($record_name) || is_null ($record_name) || (strlen($record_name) == 0)) {
$bridge_uuid = check_str(urldecode($xml->variables->bridge_uuid)); $bridge_uuid = urldecode($xml->variables->bridge_uuid);
$path = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/archive/'.$start_year.'/'.$start_month.'/'.$start_day; $path = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name.'/archive/'.$start_year.'/'.$start_month.'/'.$start_day;
if (file_exists($path.'/'.$bridge_uuid.'.wav')) { if (file_exists($path.'/'.$bridge_uuid.'.wav')) {
$record_path = $path; $record_path = $path;
@ -584,17 +594,17 @@ if (!class_exists('xml_cdr')) {
//save to the database in xml format //save to the database in xml format
if ($_SESSION['cdr']['format']['text'] == "xml" && $_SESSION['cdr']['storage']['text'] == "db") { if ($_SESSION['cdr']['format']['text'] == "xml" && $_SESSION['cdr']['storage']['text'] == "db") {
$this->array[$key]['xml'] = check_str($xml_string); $this->array[$key]['xml'] = $xml_string;
} }
//save to the database in json format //save to the database in json format
if ($_SESSION['cdr']['format']['text'] == "json" && $_SESSION['cdr']['storage']['text'] == "db") { if ($_SESSION['cdr']['format']['text'] == "json" && $_SESSION['cdr']['storage']['text'] == "db") {
$this->array[$key]['json'] = check_str(json_encode($xml)); $this->array[$key]['json'] = json_encode($xml);
} }
//insert the check_str($extension_uuid) //insert the $extension_uuid
if (strlen($xml->variables->extension_uuid) > 0) { if (strlen($xml->variables->extension_uuid) > 0) {
$this->array[$key]['extension_uuid'] = check_str(urldecode($xml->variables->extension_uuid)); $this->array[$key]['extension_uuid'] = urldecode($xml->variables->extension_uuid);
} }
//insert the values //insert the values
@ -1077,22 +1087,21 @@ if (!class_exists('xml_cdr')) {
session_cache_limiter('public'); session_cache_limiter('public');
//get call recording from database //get call recording from database
$uuid = check_str($_GET['id']); $uuid = $_GET['id'];
if ($uuid != '') { if ($uuid != '') {
$sql = "select record_name, record_path from v_xml_cdr "; $sql = "select record_name, record_path from v_xml_cdr ";
$sql .= "where xml_cdr_uuid = '".$uuid."' "; $sql .= "where xml_cdr_uuid = :xml_cdr_uuid ";
//$sql .= "and domain_uuid = '".$domain_uuid."' \n"; //$sql .= "and domain_uuid = '".$domain_uuid."' \n";
$prep_statement = $this->db->prepare($sql); $parameters['xml_cdr_uuid'] = $xml_cdr_uuid;
$prep_statement->execute(); //$parameters['domain_uuid'] = $domain_uuid;
$xml_cdr = $prep_statement->fetchAll(PDO::FETCH_ASSOC); $database = new database;
if (is_array($xml_cdr)) { $row = $database->select($sql, $parameters, 'row');
foreach($xml_cdr as &$row) { unset($parameters);
$record_name = $row['record_name']; if (is_array($row)) {
$record_path = $row['record_path']; $record_name = $row['record_name'];
break; $record_path = $row['record_path'];
}
} }
unset ($sql, $prep_statement, $xml_cdr); unset ($sql, $parameters, $row);
} }
//build full path //build full path
@ -1124,6 +1133,7 @@ if (!class_exists('xml_cdr')) {
header("Content-Type: audio/ogg"); header("Content-Type: audio/ogg");
} }
} }
$record_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $record_name);
header('Content-Disposition: attachment; filename="'.$record_name.'"'); header('Content-Disposition: attachment; filename="'.$record_name.'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past