Database class integration.

This commit is contained in:
Nate 2019-07-29 09:26:52 -06:00
parent ccfce8ee1f
commit 12d7ceb397
5 changed files with 269 additions and 281 deletions

View File

@ -28,112 +28,106 @@
if ($domains_processed == 1) { if ($domains_processed == 1) {
//add the access control list to the database //add the access control list to the database
$sql = "select count(*) as num_rows from v_access_controls "; $sql = "select count(*) from v_access_controls ";
$prep_statement = $db->prepare($sql); $database = new database;
if ($prep_statement) { $num_rows = $database->select($sql, null, 'column');
$prep_statement->execute(); if ($num_rows == 0) {
$row = $prep_statement->fetch(PDO::FETCH_ASSOC); //set the directory
if ($row['num_rows'] == 0) { $xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
//set the directory $xml_file = $xml_dir."/acl.conf.xml";
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs'; $xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/acl.conf';
$xml_file = $xml_dir."/acl.conf.xml"; //load the xml and save it into an array
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/acl.conf'; if (file_exists($xml_file)) {
//load the xml and save it into an array $xml_string = file_get_contents($xml_file);
if (file_exists($xml_file)) { }
$xml_string = file_get_contents($xml_file); elseif (file_exists($xml_file_alt)) {
} $xml_string = file_get_contents(xml_file_alt);
elseif (file_exists($xml_file_alt)) { }
$xml_string = file_get_contents(xml_file_alt); else {
} $xml_string = "<configuration name=\"acl.conf\" description=\"Network Lists\">\n";
else { $xml_string .= " <network-lists>\n";
$xml_string = "<configuration name=\"acl.conf\" description=\"Network Lists\">\n"; $xml_string .= " <list name=\"lan\" default=\"allow\">\n";
$xml_string .= " <network-lists>\n"; $xml_string .= " <node type=\"allow\" cidr=\"192.168.42.42/32\"/>\n";
$xml_string .= " <list name=\"lan\" default=\"allow\">\n"; $xml_string .= " </list>\n";
$xml_string .= " <node type=\"allow\" cidr=\"192.168.42.42/32\"/>\n"; $xml_string .= " <list name=\"domains\" default=\"deny\">\n";
$xml_string .= " </list>\n"; $xml_string .= " <node type=\"allow\" domain=\"".$_SESSION['domain_name']."\"/>\n";
$xml_string .= " <list name=\"domains\" default=\"deny\">\n"; $xml_string .= " </list>\n";
$xml_string .= " <node type=\"allow\" domain=\"".$_SESSION['domain_name']."\"/>\n"; $xml_string .= " </network-lists>\n";
$xml_string .= " </list>\n"; $xml_string .= "</configuration>\n";
$xml_string .= " </network-lists>\n"; }
$xml_string .= "</configuration>\n"; $xml_object = simplexml_load_string($xml_string);
} $json = json_encode($xml_object);
$xml_object = simplexml_load_string($xml_string); $conf_array = json_decode($json, true);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array //process the array
foreach($conf_array['network-lists']['list'] as $list) { foreach($conf_array['network-lists']['list'] as $list) {
//get the attributes //get the attributes
$access_control_name = $list['@attributes']['name']; $access_control_name = $list['@attributes']['name'];
$access_control_default = $list['@attributes']['default']; $access_control_default = $list['@attributes']['default'];
//insert the name, description //insert the name, description
$access_control_uuid = uuid(); $access_control_uuid = uuid();
$sql = "insert into v_access_controls "; $array['access_controls'][0]['access_control_uuid'] = $access_control_uuid;
$sql .= "("; $array['access_controls'][0]['access_control_name'] = $access_control_name;
$sql .= "access_control_uuid, "; $array['access_controls'][0]['access_control_default'] = $access_control_default;
$sql .= "access_control_name, ";
$sql .= "access_control_default ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$access_control_uuid."', ";
$sql .= "'".check_str($access_control_name)."', ";
$sql .= "'".check_str($access_control_default)."' ";
$sql .= ")";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//normalize the array - needed because the array is inconsistent when there is only one row vs multiple $p = new permissions;
if (strlen($list['node']['@attributes']['type']) > 0) { $p->add('access_control_add', 'temp');
$list['node'][]['@attributes'] = $list['node']['@attributes'];
unset($list['node']['@attributes']);
}
//add the nodes $database = new database;
foreach ($list['node'] as $row) { $database->app_name = 'access_controls';
//get the name and value pair $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
$node_type = $row['@attributes']['type']; $database->save($array);
$node_cidr = $row['@attributes']['cidr']; unset($array);
$node_domain = $row['@attributes']['domain'];
$node_description = $row['@attributes']['description']; $p->delete('access_control_add', 'temp');
//replace $${domain}
if (strlen($node_domain) > 0) { //normalize the array - needed because the array is inconsistent when there is only one row vs multiple
$node_domain = str_replace("\$\${domain}", $domain_name, $node_domain); if (strlen($list['node']['@attributes']['type']) > 0) {
} $list['node'][]['@attributes'] = $list['node']['@attributes'];
//add the profile settings into the database unset($list['node']['@attributes']);
$access_control_node_uuid = uuid();
$sql = "insert into v_access_control_nodes ";
$sql .= "(";
$sql .= "access_control_node_uuid, ";
$sql .= "access_control_uuid, ";
$sql .= "node_type, ";
$sql .= "node_cidr, ";
$sql .= "node_domain, ";
$sql .= "node_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$access_control_node_uuid."', ";
$sql .= "'".$access_control_uuid."', ";
$sql .= "'".$node_type."', ";
$sql .= "'".$node_cidr."', ";
$sql .= "'".$node_domain."', ";
$sql .= "'".$node_description."' ";
$sql .= ")";
//echo $sql."\n";
$db->exec(check_sql($sql));
}
} }
unset($prep_statement);
//rename the file //add the nodes
if (file_exists($xml_dir.'/acl.conf.xml')) { foreach ($list['node'] as $row) {
rename($xml_dir.'/acl.conf.xml', $xml_dir.'/acl.conf'); //get the name and value pair
$node_type = $row['@attributes']['type'];
$node_cidr = $row['@attributes']['cidr'];
$node_domain = $row['@attributes']['domain'];
$node_description = $row['@attributes']['description'];
//replace $${domain}
if (strlen($node_domain) > 0) {
$node_domain = str_replace("\$\${domain}", $domain_name, $node_domain);
}
//add the profile settings into the database
$access_control_node_uuid = uuid();
$array['access_control_nodes'][0]['access_control_node_uuid'] = $access_control_node_uuid;
$array['access_control_nodes'][0]['access_control_uuid'] = $access_control_uuid;
$array['access_control_nodes'][0]['node_type'] = $node_type;
$array['access_control_nodes'][0]['node_cidr'] = $node_cidr;
$array['access_control_nodes'][0]['node_domain'] = $node_domain;
$array['access_control_nodes'][0]['node_description'] = $node_description;
$p = new permissions;
$p->add('access_control_node_add', 'temp');
$database = new database;
$database->app_name = 'access_controls';
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
$database->save($array);
unset($array);
$p->delete('access_control_node_add', 'temp');
} }
} }
unset($prep_statement);
//rename the file
if (file_exists($xml_dir.'/acl.conf.xml')) {
rename($xml_dir.'/acl.conf.xml', $xml_dir.'/acl.conf');
}
} }
unset($sql, $num_rows);
} }

View File

@ -33,24 +33,36 @@ if ($domains_processed == 1) {
$sql .= "from v_call_center_tiers as t, v_domains as d "; $sql .= "from v_call_center_tiers as t, v_domains as d ";
$sql .= "where t.domain_uuid = d.domain_uuid "; $sql .= "where t.domain_uuid = d.domain_uuid ";
$sql .= "and (t.call_center_queue_uuid is null or t.call_center_agent_uuid is null) "; $sql .= "and (t.call_center_queue_uuid is null or t.call_center_agent_uuid is null) ";
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
$prep_statement->execute(); $tiers = $database->select($sql, null, 'all');
$tiers = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (is_array($tiers) && @sizeof($tiers) != 0) {
foreach ($tiers as &$row) { foreach ($tiers as $index => &$row) {
if ($row['call_center_queue_uuid'] == null && $row['queue_uuid'] != null) { if ($row['call_center_queue_uuid'] == null && $row['queue_uuid'] != null) {
$sql = "update v_call_center_tiers set call_center_queue_uuid = '".$row['queue_uuid']."' "; $array['call_center_tiers'][$index]['call_center_queue_uuid'] = $row['queue_uuid'];
$sql .= "where call_center_tier_uuid = '".$row['call_center_tier_uuid']."' "; }
$db->exec(check_sql($sql)); if ($row['call_center_agent_uuid'] == null && $row['agent_uuid'] != null) {
unset($sql); $array['call_center_tiers'][$index]['call_center_agent_uuid'] = $row['agent_uuid'];
}
if (is_array($array['call_center_tiers'][$index]) && @sizeof($array['call_center_tiers'][$index]) != 0) {
$array['call_center_tiers'][$index]['call_center_tier_uuid'] = $row['call_center_tier_uuid'];
}
} }
if ($row['call_center_agent_uuid'] == null && $row['agent_uuid'] != null) { if (is_array($array) && @sizeof($array) != 0) {
$sql = "update v_call_center_tiers set call_center_agent_uuid = '".$row['agent_uuid']."' "; $p = new permissions;
$sql .= "where call_center_tier_uuid = '".$row['call_center_tier_uuid']."' "; $p->add('call_center_tier_edit', 'temp');
$db->exec(check_sql($sql));
unset($sql); $database = new database;
$database->app_name = 'call_centers';
$database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
$database->save($array);
$response = $database->message;
unset($array);
$p->delete('call_center_tier_edit', 'temp');
} }
} }
unset($sql);
} }

View File

@ -27,104 +27,94 @@
if ($domains_processed == 1) { if ($domains_processed == 1) {
//add the conference controls list to the database //add the conference controls list to the database
$sql = "select count(*) as num_rows from v_conference_controls; "; $sql = "select count(*) from v_conference_controls; ";
$prep_statement = $db->prepare($sql); $database = new database;
if ($prep_statement) { $num_rows = $database->select($sql, null, 'column');
$prep_statement->execute(); if ($num_rows == 0) {
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
//set the directory //set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs'; $xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf"; $xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf'; $xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//rename the file //rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) { if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf'); rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
} }
//load the xml and save it into an array //load the xml and save it into an array
if (file_exists($xml_file)) { if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file); $xml_string = file_get_contents($xml_file);
} }
elseif (file_exists($xml_file_alt)) { elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt); $xml_string = file_get_contents($xml_file_alt);
} }
$xml_object = simplexml_load_string($xml_string); $xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object); $json = json_encode($xml_object);
$conf_array = json_decode($json, true); $conf_array = json_decode($json, true);
//process the array //process the array
foreach ($conf_array['caller-controls']['group'] as $row) { foreach ($conf_array['caller-controls']['group'] as $row) {
//get the data from the array //get the data from the array
$control_name = $row['@attributes']['name']; $control_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n"; //echo $profile_name."<br />\n";
//insert the data into the database //insert the data into the database
$conference_control_uuid = uuid(); $conference_control_uuid = uuid();
$sql = "insert into v_conference_controls "; $array['conference_controls'][0]['conference_control_uuid'] = $conference_control_uuid;
$sql .= "("; $array['conference_controls'][0]['control_name'] = $control_name;
//$sql .= "domain_uuid, "; $array['conference_controls'][0]['control_enabled'] = 'true';
$sql .= "conference_control_uuid, ";
$sql .= "control_name, ";
$sql .= "control_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
//$sql .= "'".$domain_uuid."', ";
$sql .= "'".$conference_control_uuid."', ";
$sql .= "'".check_str($control_name)."', ";
$sql .= "'true' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//insert the profile params $p = new permissions;
foreach ($row['control'] as $p) { $p->add('conference_control_add', 'temp');
//get the name $database = new database;
//print_r($p); $database->app_name = 'conference_controls';
$control_action = $p['@attributes']['action']; $database->app_uuid = 'e1ad84a2-79e1-450c-a5b1-7507a043e048';
$control_digits = $p['@attributes']['digits']; $database->save($array);
$control_data = $p['@attributes']['data']; unset($array);
$control_enabled = 'true';
//add the coference profile params $p->delete('conference_control_add', 'temp');
$conference_control_detail_uuid = uuid();
$sql = "insert into v_conference_control_details ";
$sql .= "(";
$sql .= "conference_control_uuid, ";
$sql .= "conference_control_detail_uuid, ";
$sql .= "control_digits, ";
$sql .= "control_action, ";
if (strlen($control_data) > 0) {
$sql .= "control_data, ";
}
$sql .= "control_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$conference_control_uuid."', ";
$sql .= "'".$conference_control_detail_uuid."', ";
$sql .= "'".$control_digits."', ";
$sql .= "'".$control_action."', ";
if (strlen($control_data) > 0) {
$sql .= "'".$control_data."', ";
}
$sql .= "'".$control_enabled."' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
}
} //insert the profile params
foreach ($row['control'] as $p) {
} //if num_rows //get the name
} //if prep_statement //print_r($p);
$control_action = $p['@attributes']['action'];
$control_digits = $p['@attributes']['digits'];
$control_data = $p['@attributes']['data'];
$control_enabled = 'true';
//add the coference profile params
$conference_control_detail_uuid = uuid();
$array['conference_contro_details'][0]['conference_control_uuid'] = $conference_control_uuid;
$array['conference_contro_details'][0]['conference_control_detail_uuid'] = $conference_control_detail_uuid;
$array['conference_contro_details'][0]['control_digits'] = $control_digits;
$array['conference_contro_details'][0]['control_action'] = $control_action;
if (strlen($control_data) > 0) {
$array['conference_contro_details'][0]['control_data'] = $control_data;
}
$array['conference_contro_details'][0]['control_enabled'] = $control_enabled;
$p = new permissions;
$p->add('conference_contro_detail_add', 'temp');
$database = new database;
$database->app_name = 'conference_controls';
$database->app_uuid = 'e1ad84a2-79e1-450c-a5b1-7507a043e048';
$database->save($array);
unset($array);
$p->delete('conference_contro_detail_add', 'temp');
}
}
}
unset($sql, $num_rows);
} }

View File

@ -27,96 +27,88 @@
if ($domains_processed == 1) { if ($domains_processed == 1) {
//add the music_on_hold list to the database //add the music_on_hold list to the database
$sql = "select count(*) as num_rows from v_conference_profiles; "; $sql = "select count(*) from v_conference_profiles; ";
$prep_statement = $db->prepare($sql); $database = new database;
if ($prep_statement) { $num_rows = $database->select($sql, null, 'column');
$prep_statement->execute(); if ($num_rows == 0) {
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
//set the directory //set the directory
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs'; $xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/conference.conf"; $xml_file = $xml_dir."/conference.conf";
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf'; $xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/conference.conf';
//rename the file //rename the file
if (file_exists($xml_dir.'/conference.conf.xml.noload')) { if (file_exists($xml_dir.'/conference.conf.xml.noload')) {
rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf'); rename($xml_dir.'/conference.conf.xml.noload', $xml_dir.'/conference.conf');
} }
//load the xml and save it into an array //load the xml and save it into an array
if (file_exists($xml_file)) { if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file); $xml_string = file_get_contents($xml_file);
} }
elseif (file_exists($xml_file_alt)) { elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt); $xml_string = file_get_contents($xml_file_alt);
} }
$xml_object = simplexml_load_string($xml_string); $xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object); $json = json_encode($xml_object);
$conf_array = json_decode($json, true); $conf_array = json_decode($json, true);
//process the array //process the array
foreach ($conf_array['profiles']['profile'] as $row) { foreach ($conf_array['profiles']['profile'] as $row) {
//get the data from the array //get the data from the array
$profile_name = $row['@attributes']['name']; $profile_name = $row['@attributes']['name'];
//echo $profile_name."<br />\n"; //echo $profile_name."<br />\n";
//insert the data into the database //insert the data into the database
$conference_profile_uuid = uuid(); $conference_profile_uuid = uuid();
$sql = "insert into v_conference_profiles "; $array['conference_profiles'][0]['conference_profile_uuid'] = $conference_profile_uuid;
$sql .= "("; $array['conference_profiles'][0]['profile_name'] = $profile_name;
//$sql .= "domain_uuid, "; $array['conference_profiles'][0]['profile_enabled'] = 'true';
$sql .= "conference_profile_uuid, ";
$sql .= "profile_name, ";
$sql .= "profile_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
//$sql .= "'".$domain_uuid."', ";
$sql .= "'".$conference_profile_uuid."', ";
$sql .= "'".check_str($profile_name)."', ";
$sql .= "'true' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//insert the profile params $p = new permissions;
foreach ($row['param'] as $p) { $p->add('conference_profile_add', 'temp');
//get the name
//print_r($p);
$profile_param_name = $p['@attributes']['name'];
$profile_param_value = $p['@attributes']['value'];
$profile_param_enabled = 'true';
//add the coference profile params $database = new database;
$conference_profile_param_uuid = uuid(); $database->app_name = 'conference_profiles';
$sql = "insert into v_conference_profile_params "; $database->app_uuid = 'c33e2c2a-847f-44c1-8c0d-310df5d65ba9';
$sql .= "("; $database->save($array);
$sql .= "conference_profile_uuid, "; unset($array);
$sql .= "conference_profile_param_uuid, ";
$sql .= "profile_param_name, ";
$sql .= "profile_param_value, ";
$sql .= "profile_param_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$conference_profile_uuid."', ";
$sql .= "'".$conference_profile_param_uuid."', ";
$sql .= "'".$profile_param_name."', ";
$sql .= "'".$profile_param_value."', ";
$sql .= "'".$profile_param_enabled."' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
}
} $p->delete('conference_profile_add', 'temp');
} //if num_rows //insert the profile params
} //if prep_statement foreach ($row['param'] as $p) {
//get the name
//print_r($p);
$profile_param_name = $p['@attributes']['name'];
$profile_param_value = $p['@attributes']['value'];
$profile_param_enabled = 'true';
//add the coference profile params
$conference_profile_param_uuid = uuid();
$array['conference_profile_params'][0]['conference_profile_uuid'] = $conference_profile_uuid;
$array['conference_profile_params'][0]['conference_profile_param_uuid'] = $conference_profile_param_uuid;
$array['conference_profile_params'][0]['profile_param_name'] = $profile_param_name;
$array['conference_profile_params'][0]['profile_param_value'] = $profile_param_value;
$array['conference_profile_params'][0]['profile_param_enabled'] = $profile_param_enabled;
$p = new permissions;
$p->add('conference_profile_param_add', 'temp');
$database = new database;
$database->app_name = 'conference_profiles';
$database->app_uuid = 'c33e2c2a-847f-44c1-8c0d-310df5d65ba9';
$database->save($array);
unset($array);
$p->delete('conference_profile_param_add', 'temp');
}
}
}
unset($sql, $num_rows);
} }

View File

@ -5,8 +5,8 @@ if ($domains_processed == 1) {
$sql = "update v_dialplan_details "; $sql = "update v_dialplan_details ";
$sql .= "set dialplan_detail_data = replace(dialplan_detail_data, '-','@') "; $sql .= "set dialplan_detail_data = replace(dialplan_detail_data, '-','@') ";
$sql .= "where dialplan_detail_type = 'conference' and dialplan_detail_data like '%-%';"; $sql .= "where dialplan_detail_type = 'conference' and dialplan_detail_data like '%-%';";
//echo $sql."\n"; $database = new database;
$db->exec($sql); $database->execute($sql);
unset($sql); unset($sql);
} }