Update dialplan.php

This commit is contained in:
FusionPBX
2019-10-19 19:07:47 -06:00
committed by GitHub
parent f34ced6927
commit 7070cccb16
+143 -85
View File
@@ -228,15 +228,30 @@ include "root.php";
unset($sql, $parameters); unset($sql, $parameters);
} }
public function import() { public function import($domains) {
if (strlen($this->xml) > 0) { //set the row id
$x = 0;
//check if the dialplan app uuid exists
foreach ($domains as $domain) {
//get the array of xml files
$xml_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/resources/switch/conf/dialplan/*.xml");
//process the dialplan xml files
foreach ($xml_list as $xml_file) {
//get the xml string
$xml_string = file_get_contents($xml_file);
//prepare the xml
if (strlen($xml_string) > 0) {
//replace the variables //replace the variables
$length = (is_numeric($_SESSION["security"]["pin_length"]["var"])) ? $_SESSION["security"]["pin_length"]["var"] : 8; $length = (is_numeric($_SESSION["security"]["pin_length"]["var"])) ? $_SESSION["security"]["pin_length"]["var"] : 8;
//$this->xml = str_replace("{v_context}", $this->default_context, $this->xml); //$this->xml = str_replace("{v_context}", $this->default_context, $xml_string);
$this->xml = str_replace("{v_pin_number}", generate_password($length, 1), $this->xml); $this->xml = str_replace("{v_pin_number}", generate_password($length, 1), $xml_string);
$this->xml = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $this->xml); $this->xml = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $xml_string);
//convert the xml string to an xml object //convert the xml string to an xml object
$xml = simplexml_load_string($this->xml); $xml = simplexml_load_string($xml_string);
//convert to json //convert to json
$json = json_encode($xml); $json = json_encode($xml);
//convert to an array //convert to an array
@@ -256,69 +271,85 @@ include "root.php";
} }
} }
//get the app_uuid //determine if the dialplan already exists
$this->app_uuid = $dialplan['extension']['@attributes']['app_uuid']; $sql = "select count(*) from v_dialplans ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
//get the list of domains $sql .= "and app_uuid = :app_uuid ";
if (!isset($_SESSION['domains'])) { $parameters['domain_uuid'] = $domain['domain_uuid'];
$sql = "select * from v_domains "; $parameters['app_uuid'] = $dialplan['extension']['@attributes']['app_uuid'];
$database = new database; $database = new database;
$_SESSION['domains'] = $database->select($sql, null, 'all'); $app_uuid_exists = $database->select($sql, $parameters, 'column') > 0 ? true : false;
unset($sql); unset($parameters);
//check if the dialplan exists
if (!$app_uuid_exists) {
//set the dialplan_context
$dialplan_context = $dialplan['@attributes']['name'];
if ($dialplan_context == "{v_context}") {
$dialplan_context = $domain['domain_name'];
} }
//check if the dialplan app uuid exists //dialplan global
foreach ($_SESSION['domains'] as $domain) { if (isset($dialplan['extension']['@attributes']['global']) && $dialplan['extension']['@attributes']['global'] == "true") {
//get the domain_uuid $dialplan_global = true;
$this->domain_uuid = $domain['domain_uuid'];
//set the dialplan_context
$this->dialplan_context = $dialplan['@attributes']['name'];
if ($this->dialplan_context == "{v_context}") {
$this->dialplan_context = $domain['domain_name'];
}
//check if the dialplan exists
if (!$this->app_uuid_exists()) {
//get the attributes
$this->dialplan_uuid = uuid();
$this->dialplan_name = $dialplan['extension']['@attributes']['name'];
$this->dialplan_number = $dialplan['extension']['@attributes']['number'];
if (strlen($dialplan['extension']['@attributes']['destination']) > 0) {
$this->dialplan_destination = $dialplan['extension']['@attributes']['destination'];
}
$this->dialplan_global = false;
if (strlen($dialplan['extension']['@attributes']['global']) > 0) {
if ($dialplan['extension']['@attributes']['global'] == "true") {
$this->dialplan_global = true;
}
}
if (strlen($dialplan['extension']['@attributes']['continue']) > 0) {
$this->dialplan_continue = $dialplan['extension']['@attributes']['continue'];
}
if (strlen($dialplan['extension']['@attributes']['enabled']) > 0) {
$this->dialplan_enabled = $dialplan['extension']['@attributes']['enabled'];
} }
else { else {
$this->dialplan_enabled = "true"; $dialplan_global = false;
} }
$this->dialplan_description = $dialplan['extension']['@attributes']['description'];
$this->dialplan_add(); //set the domain_uuid
if ($dialplan_global) {
$domain_uuid = null;
}
else {
$domain_uuid = $domain['domain_uuid'];
}
//get the attributes
$dialplan_uuid = uuid();
$array['dialplans'][$x]['dialplan_uuid'] = $dialplan_uuid;
$array['dialplans'][$x]['domain_uuid'] = $domain_uuid;
$array['dialplans'][$x]['app_uuid'] = $dialplan['extension']['@attributes']['app_uuid'];
$array['dialplans'][$x]['dialplan_name'] = $dialplan['extension']['@attributes']['name'];
$array['dialplans'][$x]['dialplan_number'] = $dialplan['extension']['@attributes']['number'];
$array['dialplans'][$x]['dialplan_context'] = $dialplan_context;
if (strlen($dialplan['extension']['@attributes']['destination']) > 0) {
$array['dialplans'][$x]['dialplan_destination'] = $dialplan['extension']['@attributes']['destination'];
}
if (strlen($dialplan['extension']['@attributes']['continue']) > 0) {
$array['dialplans'][$x]['dialplan_continue'] = $dialplan['extension']['@attributes']['continue'];
}
$array['dialplans'][$x]['dialplan_order'] = $dialplan['extension']['@attributes']['order'];
if (strlen($dialplan['extension']['@attributes']['enabled']) > 0) {
$array['dialplans'][$x]['dialplan_enabled'] = $dialplan['extension']['@attributes']['enabled'];
}
else {
$array['dialplans'][$x]['dialplan_enabled'] = "true";
}
$array['dialplans'][$x]['dialplan_description'] = $dialplan['extension']['@attributes']['description'];
//loop through the condition array //loop through the condition array
$x = 0; $y = 0;
$group = 0; $group = 0;
$order = 5; $order = 5;
if (isset($dialplan['extension']['condition'])) { if (isset($dialplan['extension']['condition'])) {
foreach ($dialplan['extension']['condition'] as &$row) { foreach ($dialplan['extension']['condition'] as &$row) {
unset($this->dialplan_detail_break);
unset($this->dialplan_detail_inline); $array['dialplans'][$x]['dialplan_details'][$y]['domain_uuid'] = $domain_uuid;
$this->dialplan_detail_tag = 'condition'; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_uuid'] = $dialplan_uuid;
$this->dialplan_detail_type = $row['@attributes']['field']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_tag'] = 'condition';
$this->dialplan_detail_data = $row['@attributes']['expression']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_order'] = $order;
$this->dialplan_detail_group = $group; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row['@attributes']['field'];
$this->dialplan_detail_order = $order; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row['@attributes']['expression'];
if (strlen($row['@attributes']['break']) > 0) { if (strlen($row['@attributes']['break']) > 0) {
$this->dialplan_detail_break = $row['@attributes']['break']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_break'] = $row['@attributes']['break'];
} }
$this->dialplan_detail_add(); //$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] =
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
$y++;
if (is_array($row['action']) || is_array($row['anti-action'])) { if (is_array($row['action']) || is_array($row['anti-action'])) {
$condition_self_closing_tag = false; $condition_self_closing_tag = false;
if (!is_array($row['action'][0])) { if (!is_array($row['action'][0])) {
@@ -336,59 +367,86 @@ include "root.php";
} }
} }
$order = $order + 5; $order = $order + 5;
unset($this->dialplan_detail_break);
unset($this->dialplan_detail_inline);
if (isset($row['action'])) { if (isset($row['action'])) {
foreach ($row['action'] as &$row2) { foreach ($row['action'] as &$row2) {
$this->dialplan_detail_tag = 'action'; $array['dialplans'][$x]['dialplan_details'][$y]['domain_uuid'] = $domain_uuid;
$this->dialplan_detail_type = $row2['@attributes']['application']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_uuid'] = $dialplan_uuid;
$this->dialplan_detail_data = $row2['@attributes']['data']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_tag'] = 'action';
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_order'] = $order;
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row2['@attributes']['application'];
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'];
if (strlen($row2['@attributes']['inline']) > 0) { if (strlen($row2['@attributes']['inline']) > 0) {
$this->dialplan_detail_inline = $row2['@attributes']['inline']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
} }
else { else {
$this->dialplan_detail_inline = null; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
} }
$this->dialplan_detail_group = $group; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
$this->dialplan_detail_order = $order; $y++;
$this->dialplan_detail_add();
//increase the order number
$order = $order + 5; $order = $order + 5;
} }
} }
if (isset($row['anti-action'])) { if (isset($row['anti-action'])) {
foreach ($row['anti-action'] as &$row2) { foreach ($row['anti-action'] as &$row2) {
$this->dialplan_detail_tag = 'anti-action'; $array['dialplans'][$x]['dialplan_details'][$y]['domain_uuid'] = $domain_uuid;
$this->dialplan_detail_type = $row2['@attributes']['application']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_uuid'] = $dialplan_uuid;
$this->dialplan_detail_data = $row2['@attributes']['data']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_tag'] = 'anti-action';
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_order'] = $order;
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row2['@attributes']['application'];
$array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row2['@attributes']['data'];
if (strlen($row2['@attributes']['inline']) > 0) { if (strlen($row2['@attributes']['inline']) > 0) {
$this->dialplan_detail_inline = $row2['@attributes']['inline']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row2['@attributes']['inline'];
} }
else { else {
$this->dialplan_detail_inline = null; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = null;
} }
$this->dialplan_detail_group = $group; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = $group;
$this->dialplan_detail_order = $order; $y++;
$this->dialplan_detail_add();
//increase the order number
$order = $order + 5; $order = $order + 5;
} }
} }
} }
else {
$condition_self_closing_tag = true; //increase the order number
}
//if not a self closing tag then increment the group
if (!$condition_self_closing_tag) {
$group++;
}
$row['group'] = $group;
$order = $order + 5; $order = $order + 5;
$x++;
} }
} }
//update the session array //update the session array
$_SESSION['upgrade']['app_defaults']['dialplans'][$domain['domain_name']][]['dialplan_name'] = $this->dialplan_name; $_SESSION['upgrade']['app_defaults']['dialplans'][$domain['domain_name']][]['dialplan_name'] = $dialplan_name;
}
//increase the row number
$x++;
} //app_uuid exists
} //end foreach $xml_list
//grant temporary permissions
$p = new permissions;
$p->add('dialplan_add', 'temp');
$p->add('dialplan_edit', 'temp');
$p->add('dialplan_detail_add', 'temp');
$p->add('dialplan_detail_edit', 'temp');
//save the data
if (is_array($array)) {
$database = new database;
$database->app_name = 'dialplans';
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
$database->save($array);
unset($array);
} }
//revoke temporary permissions
$p->delete('dialplan_add', 'temp');
$p->delete('dialplan_edit', 'temp');
$p->delete('dialplan_detail_add', 'temp');
$p->delete('dialplan_detail_edit', 'temp');
} //foreach domains
} }
public function outbound_routes($destination_number) { public function outbound_routes($destination_number) {