SIP Profiles: Database class integration.

This commit is contained in:
Nate
2019-08-13 07:32:07 -06:00
parent 1041c2a76f
commit 4002f3cd01
8 changed files with 462 additions and 502 deletions
+152 -184
View File
@@ -28,36 +28,37 @@
if ($domains_processed == 1) { if ($domains_processed == 1) {
//add the sip profiles to the database //add the sip profiles to the database
$sql = "select count(*) as num_rows from v_sip_profiles "; $sql = "select count(*) from v_sip_profiles ";
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
if ($prep_statement) { $num_rows = $database->select($sql, null, 'column');
$prep_statement->execute(); unset($sql);
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
else {
$sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload';
}
$db->beginTransaction();
$xml_files = glob($sip_profile_dir);
foreach ($xml_files as &$xml_file) {
//load the sip profile xml and save it into an array
$sip_profile_xml = file_get_contents($xml_file);
$xml = simplexml_load_string($sip_profile_xml);
$json = json_encode($xml);
$sip_profile = json_decode($json, true);
$sip_profile_name = $sip_profile['@attributes']['name'];
$sip_profile_enabled = $sip_profile['@attributes']['enabled'];
//echo "sip profile name: ".$sip_profile_name."\n";
if ($sip_profile_name != "{v_sip_profile_name}") { if ($num_rows == 0) {
//prepare the description if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) {
switch ($sip_profile_name) { $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
else {
$sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload';
}
$xml_files = glob($sip_profile_dir);
foreach ($xml_files as $x => &$xml_file) {
//load the sip profile xml and save it into an array
$sip_profile_xml = file_get_contents($xml_file);
$xml = simplexml_load_string($sip_profile_xml);
$json = json_encode($xml);
$sip_profile = json_decode($json, true);
$sip_profile_name = $sip_profile['@attributes']['name'];
$sip_profile_enabled = $sip_profile['@attributes']['enabled'];
//echo "sip profile name: ".$sip_profile_name."\n";
if ($sip_profile_name != "{v_sip_profile_name}") {
//prepare the description
switch ($sip_profile_name) {
case "internal": case "internal":
$sip_profile_description = "The Internal profile by default requires registration which is used by the endpoints. "; $sip_profile_description = "The Internal profile by default requires registration which is used by the endpoints. ";
$sip_profile_description .= "By default the Internal profile binds to port 5060. "; $sip_profile_description .= "By default the Internal profile binds to port 5060. ";
@@ -78,184 +79,151 @@
break; break;
default: default:
$sip_profile_description = ''; $sip_profile_description = '';
} }
//add the sip profile if it is not false //add the sip profile if it is not false
if ($sip_profile_enabled != "false") { if ($sip_profile_enabled != "false") {
//insert the sip profile name, description
$sip_profile_uuid = uuid();
$sql = "insert into v_sip_profiles";
$sql .= "(";
$sql .= "sip_profile_uuid, ";
$sql .= "sip_profile_name, ";
$sql .= "sip_profile_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".check_str($sip_profile_uuid)."', ";
$sql .= "'".check_str($sip_profile_name)."', ";
$sql .= "'".check_str($sip_profile_description)."' ";
$sql .= ")";
//echo $sql."\n\n";
$db->exec(check_sql($sql));
unset($sql);
//get the domain, alias and parse values and set as variables //add profile name and description
$sip_profile_domain_name = $sip_profile['domains']['domain']['@attributes']['name']; $sip_profile_uuid = uuid();
$sip_profile_domain_alias = $sip_profile['domains']['domain']['@attributes']['alias']; $array['sip_profiles'][$x]['sip_profile_uuid'] = $sip_profile_uuid;
$sip_profile_domain_parse = $sip_profile['domains']['domain']['@attributes']['parse']; $array['sip_profiles'][$x]['sip_profile_name'] = $sip_profile_name;
$array['sip_profiles'][$x]['sip_profile_description'] = $sip_profile_description;
//add the sip profile domains name, alias and parse //add the sip profile domains name, alias and parse
$sip_profile_domain_uuid = uuid(); $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid;
$sql = "insert into v_sip_profile_domains"; $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "("; $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_name'] = $sip_profile['domains']['domain']['@attributes']['name'];
$sql .= "sip_profile_domain_uuid, "; $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $sip_profile['domains']['domain']['@attributes']['alias'];
$sql .= "sip_profile_uuid, "; $array['sip_profiles'][$x]['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $sip_profile['domains']['domain']['@attributes']['parse'];
$sql .= "sip_profile_domain_name, ";
$sql .= "sip_profile_domain_alias, ";
$sql .= "sip_profile_domain_parse ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$sip_profile_domain_uuid."', ";
$sql .= "'".$sip_profile_uuid."', ";
$sql .= "'".check_str($sip_profile_domain_name)."', ";
$sql .= "'".check_str($sip_profile_domain_alias)."', ";
$sql .= "'".check_str($sip_profile_domain_parse)."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//add the sip profile settings //add the profile settings
foreach ($sip_profile['settings']['param'] as $row) { foreach ($sip_profile['settings']['param'] as $y => $row) {
//get the name and value pair $sip_profile_setting_uuid = uuid();
$sip_profile_setting_name = $row['@attributes']['name']; $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_uuid'] = $sip_profile_setting_uuid;
$sip_profile_setting_value = $row['@attributes']['value']; $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_uuid'] = $sip_profile_uuid;
$sip_profile_setting_enabled = $row['@attributes']['enabled']; $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_name'] = $row['@attributes']['name'];
if ($sip_profile_setting_enabled != "false") { $sip_profile_setting_enabled = "true"; } $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_value'] = $row['@attributes']['value'];
//echo "name: $name value: $value\n"; $array['sip_profiles'][$x]['sip_profile_settings'][$y]['sip_profile_setting_enabled'] = $row['@attributes']['enabled'] != 'false' ? 'true' : $row['@attributes']['enabled'];
//add the profile settings into the database
$sip_profile_setting_uuid = uuid();
$sql = "insert into v_sip_profile_settings ";
$sql .= "(";
$sql .= "sip_profile_setting_uuid, ";
$sql .= "sip_profile_uuid, ";
$sql .= "sip_profile_setting_name, ";
$sql .= "sip_profile_setting_value, ";
$sql .= "sip_profile_setting_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".check_str($sip_profile_setting_uuid)."', ";
$sql .= "'".check_str($sip_profile_uuid)."', ";
$sql .= "'".check_str($sip_profile_setting_name)."', ";
$sql .= "'".check_str($sip_profile_setting_value)."', ";
$sql .= "'".$sip_profile_setting_enabled."' ";
$sql .= ")";
//echo $sql."\n\n";
$db->exec(check_sql($sql));
} }
}
}
}
$db->commit();
//save the sip profile xml }
}
}
//execute inserts
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('sip_profile_add', 'temp');
$p->add('sip_profile_domain_add', 'temp');
$p->add('sip_profile_setting_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'sip_profiles';
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('sip_profile_add', 'temp');
$p->delete('sip_profile_domain_add', 'temp');
$p->delete('sip_profile_setting_add', 'temp');
}
//save the sip profile xml
save_sip_profile_xml(); save_sip_profile_xml();
//apply settings reminder //apply settings reminder
$_SESSION["reload_xml"] = true; $_SESSION["reload_xml"] = true;
}
unset($prep_statement);
} }
//upgrade - add missing sip profiles domain settings //upgrade - add missing sip profiles domain settings
$sql = "select count(*) as num_rows from v_sip_profile_domains "; $sql = "select count(*) from v_sip_profile_domains ";
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
if ($prep_statement) { $num_rows = $database->select($sql, null, 'column');
$prep_statement->execute(); unset($sql);
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
else {
$sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload';
}
$db->beginTransaction();
$xml_files = glob($sip_profile_dir);
foreach ($xml_files as &$xml_file) {
//load the sip profile xml and save it into an array
$sip_profile_xml = file_get_contents($xml_file);
$xml = simplexml_load_string($sip_profile_xml);
$json = json_encode($xml);
$sip_profile = json_decode($json, true);
$sip_profile_name = $sip_profile['@attributes']['name'];
$sip_profile_enabled = $sip_profile['@attributes']['enabled'];
//echo "sip profile name: ".$sip_profile_name."\n";
//get the domain, alias and parse values and set as variables if ($num_rows == 0) {
$sip_profile_domain_name = $sip_profile['domains']['domain']['@attributes']['name']; if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_domain_alias = $sip_profile['domains']['domain']['@attributes']['alias']; $sip_profile_dir = '/usr/share/examples/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
$sip_profile_domain_parse = $sip_profile['domains']['domain']['@attributes']['parse']; }
elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles')) {
$sip_profile_dir = '/usr/local/share/fusionpbx/resources/templates/conf/sip_profiles/*.xml.noload';
}
else {
$sip_profile_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/sip_profiles/*.xml.noload';
}
//get the sip_profile_uuid using the sip profile name $xml_files = glob($sip_profile_dir);
$sql = "select sip_profile_uuid from v_sip_profiles "; foreach ($xml_files as $x => &$xml_file) {
$sql .= "where sip_profile_name = '$sip_profile_name' "; //load the sip profile xml and save it into an array
$prep_statement = $db->prepare(check_sql($sql)); $sip_profile_xml = file_get_contents($xml_file);
$prep_statement->execute(); $xml = simplexml_load_string($sip_profile_xml);
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $json = json_encode($xml);
$sip_profile_uuid = $result[0]["sip_profile_uuid"]; $sip_profile = json_decode($json, true);
unset ($prep_statement); $sip_profile_name = $sip_profile['@attributes']['name'];
$sip_profile_enabled = $sip_profile['@attributes']['enabled'];
//add the sip profile domains name, alias and parse //get the sip_profile_uuid using the sip profile name
if ($sip_profile_uuid) { $sql = "select sip_profile_uuid from v_sip_profiles ";
$sip_profile_domain_uuid = uuid(); $sql .= "where sip_profile_name = :sip_profile_name ";
$sql = "insert into v_sip_profile_domains"; $parameters['sip_profile_name'] = $sip_profile_name;
$sql .= "("; $database = new database;
$sql .= "sip_profile_domain_uuid, "; $sip_profile_uuid = $database->select($sql, $parameters, 'column');
$sql .= "sip_profile_uuid, "; unset($sql, $parameters);
$sql .= "sip_profile_domain_name, ";
$sql .= "sip_profile_domain_alias, "; //add the sip profile domains name, alias and parse
$sql .= "sip_profile_domain_parse "; if (is_uuid($sip_profile_uuid)) {
$sql .= ") "; $sip_profile_domain_uuid = uuid();
$sql .= "values "; $array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid;
$sql .= "( "; $array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "'".$sip_profile_domain_uuid."', "; $array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $sip_profile['domains']['domain']['@attributes']['name'];
$sql .= "'".$sip_profile_uuid."', "; $array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $sip_profile['domains']['domain']['@attributes']['alias'];
$sql .= "'".check_str($sip_profile_domain_name)."', "; $array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $sip_profile['domains']['domain']['@attributes']['parse'];
$sql .= "'".check_str($sip_profile_domain_alias)."', "; }
$sql .= "'".check_str($sip_profile_domain_parse)."' ";
$sql .= ")"; //unset the sip_profile_uuid
$db->exec(check_sql($sql)); unset($sip_profile_uuid);
unset($sql); }
}
//execute inserts
//unset the sip_profile_uuid if (is_array($array) && @sizeof($array) != 0) {
unset($sip_profile_uuid); //grant temporary permissions
$p = new permissions;
$p->add('sip_profile_domain_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'sip_profiles';
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('sip_profile_domain_add', 'temp');
} }
$db->commit();
//save the sip profile xml //save the sip profile xml
save_sip_profile_xml(); save_sip_profile_xml();
//apply settings reminder //apply settings reminder
$_SESSION["reload_xml"] = true; $_SESSION["reload_xml"] = true;
}
unset($prep_statement);
} }
//if empty, set enabled to true
$sql = "update v_sip_profiles set ";
$sql .= "sip_profile_enabled = 'true' ";
$sql .= "where sip_profile_enabled is null ";
$sql .= "or sip_profile_enabled = '' ";
$database = new database;
$database->execute($sql);
unset($sql);
} }
//if empty, set sip_profile_enabled = true ?>
if ($domains_processed == 1) {
$sql = "update v_sip_profiles set ";
$sql .= "sip_profile_enabled = 'true' ";
$sql .= "where sip_profile_enabled is null ";
$sql .= "or sip_profile_enabled = '' ";
$db->exec(check_sql($sql));
unset($sql);
}
?>
+20
View File
@@ -361,6 +361,26 @@ $text['label-sip_profile_settings']['ru-ru'] = "Настройки";
$text['label-sip_profile_settings']['sv-se'] = "Inställningar"; $text['label-sip_profile_settings']['sv-se'] = "Inställningar";
$text['label-sip_profile_settings']['uk-ua'] = "Параметри"; $text['label-sip_profile_settings']['uk-ua'] = "Параметри";
$text['label-new_sip_profile_name']['en-us'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ar-eg'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-at'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-ch'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['de-de'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['es-cl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['es-mx'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['fr-ca'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['fr-fr'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['he-il'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['it-it'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['nl-nl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pl-pl'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pt-br'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['pt-pt'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ro-ro'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['ru-ru'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['sv-se'] = "Enter new SIP Profile Name";
$text['label-new_sip_profile_name']['uk-ua'] = "Enter new SIP Profile Name";
$text['header-sip_profiles']['en-us'] = "SIP Profiles"; $text['header-sip_profiles']['en-us'] = "SIP Profiles";
$text['header-sip_profiles']['ar-eg'] = ""; $text['header-sip_profiles']['ar-eg'] = "";
$text['header-sip_profiles']['de-at'] = "SIP Profile"; //copied from de-de $text['header-sip_profiles']['de-at'] = "SIP Profile"; //copied from de-de
+68 -107
View File
@@ -47,122 +47,83 @@
$text = $language->get(); $text = $language->get();
//set the http get/post variable(s) to a php variable //set the http get/post variable(s) to a php variable
if (isset($_REQUEST["id"])) { $sip_profile_uuid = $_REQUEST["id"];
$sip_profile_uuid = check_str($_REQUEST["id"]); $sip_profile_name = $_REQUEST["name"];
$sip_profile_name = check_str($_REQUEST["name"]);
}
//get the sip profile data if (is_uuid($sip_profile_uuid) && $sip_profile_name != '') {
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
$sql = "select * from v_sip_profiles "; //get the sip profile data
$sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
$prep_statement = $db->prepare(check_sql($sql)); $sql = "select sip_profile_description from v_sip_profiles ";
$prep_statement->execute(); $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$result = $prep_statement->fetchAll(); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
foreach ($result as &$row) { $database = new database;
$sip_profile_description = $row["sip_profile_description"]; $sip_profile_description = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
} }
unset ($prep_statement);
}
//copy the v_sip_profiles //copy the sip profile
$sip_profile_uuid_new = uuid(); $sip_profile_uuid_new = uuid();
$sip_profile_enabled = 'true'; $array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid_new;
$sql = "insert into v_sip_profiles "; $array['sip_profiles'][0]['sip_profile_name'] = $sip_profile_name;
$sql .= "("; $array['sip_profiles'][0]['sip_profile_enabled'] = 'true';
$sql .= "sip_profile_uuid, "; $array['sip_profiles'][0]['sip_profile_description'] = $sip_profile_description;
$sql .= "sip_profile_name, ";
$sql .= "sip_profile_enabled, ";
$sql .= "sip_profile_description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$sip_profile_uuid_new."', ";
$sql .= "'".$sip_profile_name."', ";
$sql .= "'".$sip_profile_enabled."', ";
$sql .= "'".$sip_profile_description."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//get the the sip profile settings //get the the sip profile settings
$sql = "select * from v_sip_profile_domains "; $sql = "select * from v_sip_profile_domains ";
$sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(); $result = $database->select($sql, $parameters, 'all');
foreach ($result as &$row) { if (is_array($result) && @sizeof($result) != 0) {
$sip_profile_domain_name = $row["sip_profile_domain_name"]; foreach ($result as $x => &$row) {
$sip_profile_domain_alias = $row["sip_profile_domain_alias"]; $array['sip_profile_domains'][$x]['sip_profile_domain_uuid'] = uuid();
$sip_profile_domain_parse = $row["sip_profile_domain_parse"]; $array['sip_profile_domains'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
$array['sip_profile_domains'][$x]['sip_profile_domain_name'] = $row["sip_profile_domain_name"];
$array['sip_profile_domains'][$x]['sip_profile_domain_alias'] = $row["sip_profile_domain_alias"];
$array['sip_profile_domains'][$x]['sip_profile_domain_parse'] = $row["sip_profile_domain_parse"];
}
}
unset($sql, $parameters, $result, $row);
//add the sip profile setting //get the the sip profile settings
$sql = "insert into v_sip_profile_domains "; $sql = "select * from v_sip_profile_settings ";
$sql .= "("; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$sql .= "sip_profile_domain_uuid, "; $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "sip_profile_uuid, "; $database = new database;
$sql .= "sip_profile_domain_name, "; $result = $database->select($sql, $parameters, 'all');
$sql .= "sip_profile_domain_alias, "; if (is_array($result) && @sizeof($result) != 0) {
$sql .= "sip_profile_domain_parse "; foreach ($result as $x => &$row) {
$sql .= ")"; $array['sip_profile_settings'][$x]['sip_profile_setting_uuid'] = uuid();
$sql .= "values "; $array['sip_profile_settings'][$x]['sip_profile_uuid'] = $sip_profile_uuid_new;
$sql .= "("; $array['sip_profile_settings'][$x]['sip_profile_setting_name'] = $row["sip_profile_setting_name"];
$sql .= "'".uuid()."', "; $array['sip_profile_settings'][$x]['sip_profile_setting_value'] = $row["sip_profile_setting_value"];
$sql .= "'$sip_profile_uuid_new', "; $array['sip_profile_settings'][$x]['sip_profile_setting_enabled'] = $row["sip_profile_setting_enabled"];
$sql .= "'$sip_profile_domain_name', "; $array['sip_profile_settings'][$x]['sip_profile_setting_description'] = $row["sip_profile_setting_description"];
$sql .= "'$sip_profile_domain_alias', "; }
$sql .= "'$sip_profile_domain_parse' "; }
$sql .= ")"; unset($sql, $parameters, $result, $row);
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
//get the the sip profile settings //execute insert
$sql = "select * from v_sip_profile_settings "; $database = new database;
$sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; $database->app_name = 'sip_profiles';
$prep_statement = $db->prepare(check_sql($sql)); $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$prep_statement->execute(); $database->save($array);
$result = $prep_statement->fetchAll(); unset($array);
foreach ($result as &$row) {
$sip_profile_setting_name = $row["sip_profile_setting_name"];
$sip_profile_setting_value = $row["sip_profile_setting_value"];
$sip_profile_setting_enabled = $row["sip_profile_setting_enabled"];
$sip_profile_setting_description = $row["sip_profile_setting_description"];
//add the sip profile setting //save the sip profile xml
$sql = "insert into v_sip_profile_settings "; save_sip_profile_xml();
$sql .= "(";
$sql .= "sip_profile_setting_uuid, ";
$sql .= "sip_profile_uuid, ";
$sql .= "sip_profile_setting_name, ";
$sql .= "sip_profile_setting_value, ";
$sql .= "sip_profile_setting_enabled, ";
$sql .= "sip_profile_setting_description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'$sip_profile_uuid_new', ";
$sql .= "'$sip_profile_setting_name', ";
$sql .= "'$sip_profile_setting_value', ";
$sql .= "'$sip_profile_setting_enabled', ";
$sql .= "'$sip_profile_setting_description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
//save the sip profile xml //apply settings reminder
save_sip_profile_xml(); $_SESSION["reload_xml"] = true;
//apply settings reminder //set message
$_SESSION["reload_xml"] = true; message::add($text['message-copy']);
}
//redirect the user //redirect the user
message::add($text['message-copy']); header("Location: sip_profiles.php");
header("Location: ".PROJECT_PATH."/app/sip_profiles/sip_profiles.php"); exit;
return;
?> ?>
+24 -28
View File
@@ -43,46 +43,39 @@
$text = $language->get(); $text = $language->get();
//get the id //get the id
if (count($_GET) > 0) { $sip_profile_uuid = $_GET["id"];
$id = check_str($_GET["id"]);
}
//delete the records //delete the records
if (strlen($id) > 0) { if (is_uuid($sip_profile_uuid)) {
//get the details of the sip profile //get the details of the sip profile
$sql = "select * from v_sip_profiles "; $sql = "select * from v_sip_profiles ";
$sql .= "where sip_profile_uuid = '$id' "; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$prep_statement->execute(); $database = new database;
$result = $prep_statement->fetchAll(); $row = $database->select($sql, $parameters, 'row');
foreach ($result as &$row) { if (is_array($array) && @sizeof($array) != 0) {
$sip_profile_name = $row["sip_profile_name"]; $sip_profile_name = $row["sip_profile_name"];
$sip_profile_hostname = $row["sip_profile_hostname"]; $sip_profile_hostname = $row["sip_profile_hostname"];
$sip_profile_description = $row["sip_profile_description"]; $sip_profile_description = $row["sip_profile_description"];
} }
unset ($prep_statement); unset($sql, $parameters, $row);
//delete the sip profile domains //delete the sip profile domains
$sql = "delete from v_sip_profile_domains "; $array['sip_profile_domains'][0]['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "where sip_profile_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql);
//delete the sip profile settings //delete the sip profile settings
$sql = "delete from v_sip_profile_settings "; $array['sip_profile_settings'][0]['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "where sip_profile_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql);
//delete the sip profile //delete the sip profile
$sql = "delete from v_sip_profiles "; $array['sip_profiles'][0]['sip_profile_uuid'] = $sip_profile_uuid;
$sql .= "where sip_profile_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql)); //execute delete
$prep_statement->execute(); $database = new database;
unset($sql); $database->app_name = 'sip_profiles';
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$database->delete($array);
unset($array);
//delete the xml sip profile and directory //delete the xml sip profile and directory
unlink($_SESSION['switch']['conf']['dir']."/sip_profiles/".$sip_profile_name.".xml"); unlink($_SESSION['switch']['conf']['dir']."/sip_profiles/".$sip_profile_name.".xml");
@@ -106,11 +99,14 @@
//clear the cache //clear the cache
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$sip_profile_name); $cache->delete("configuration:sofia.conf:".$sip_profile_name);
//set message
message::add($text['message-delete']);
} }
//redirect the browser //redirect the browser
message::add($text['message-delete']);
header("Location: sip_profiles.php"); header("Location: sip_profiles.php");
return; exit;
?> ?>
+30 -25
View File
@@ -42,35 +42,40 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//delete the data //get the id
if (is_uuid($_GET["id"])) { $sip_profile_domain_uuid = $_GET["id"];
//get the id //delete the data
$id = $_GET["id"]; if (is_uuid($sip_profile_domain_uuid)) {
//get the details of the sip profile //get the details of the sip profile
$sql = "select * from v_sip_profile_domains "; $sql = "select sip_profile_uuid ";
$sql .= "where sip_profile_domain_uuid = '$id' "; $sql .= "from v_sip_profile_domains ";
$prep_statement = $db->prepare(check_sql($sql)); $sql .= "where sip_profile_domain_uuid = :sip_profile_domain_uuid ";
$prep_statement->execute(); $parameters['sip_profile_domain_uuid'] = $sip_profile_domain_uuid;
$result = $prep_statement->fetchAll(); $database = new database;
if (is_array($result)) { $sip_profile_uuid = $database->select($sql, $parameters, 'column');
foreach ($result as &$row) {
$sip_profile_uuid = $row["sip_profile_uuid"];
}
}
unset ($prep_statement);
//delete sip_profile_domain //build array
$sql = "delete from v_sip_profile_domains "; $array['sip_profile_domains'][0]['sip_profile_domain_uuid'] = $sip_profile_domain_uuid;
$sql .= "where sip_profile_domain_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql)); //execute delete
$prep_statement->execute(); $database = new database;
unset($sql); $database->app_name = 'sip_profiles';
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$database->delete($array);
unset($array);
//set message
message::add($text['message-delete']);
//redirect the user
header('Location: sip_profile_edit.php?id='.$sip_profile_uuid);
exit;
} }
//redirect the user //default redirect
message::add($text['message-delete']); header('Location: sip_profiles.php');
header('Location: sip_profile_edit.php?id='.$sip_profile_uuid); exit;
?> ?>
+119 -98
View File
@@ -43,9 +43,9 @@
$text = $language->get(); $text = $language->get();
//action add or update //action add or update
if (isset($_REQUEST["id"])) { if (is_uuid($_REQUEST["id"])) {
$action = "update"; $action = "update";
$sip_profile_uuid = check_str($_REQUEST["id"]); $sip_profile_uuid = $_REQUEST["id"];
} }
else { else {
$action = "add"; $action = "add";
@@ -53,11 +53,11 @@
//get http post variables and set them to php variables //get http post variables and set them to php variables
if (is_array($_POST)) { if (is_array($_POST)) {
$sip_profile_uuid = check_str($_POST["sip_profile_uuid"]); $sip_profile_uuid = $_POST["sip_profile_uuid"];
$sip_profile_name = check_str($_POST["sip_profile_name"]); $sip_profile_name = $_POST["sip_profile_name"];
$sip_profile_hostname = check_str($_POST["sip_profile_hostname"]); $sip_profile_hostname = $_POST["sip_profile_hostname"];
$sip_profile_enabled = check_str($_POST["sip_profile_enabled"]); $sip_profile_enabled = $_POST["sip_profile_enabled"];
$sip_profile_description = check_str($_POST["sip_profile_description"]); $sip_profile_description = $_POST["sip_profile_description"];
} }
//process the user data and save it to the database //process the user data and save it to the database
@@ -65,12 +65,12 @@
//get the uuid from the POST //get the uuid from the POST
if ($action == "update") { if ($action == "update") {
$sip_profile_uuid = check_str($_POST["sip_profile_uuid"]); $sip_profile_uuid = $_POST["sip_profile_uuid"];
} }
//check for all required data //check for all required data
$msg = ''; $msg = '';
if (strlen($sip_profile_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_uuid']."<br>\n"; } //if (strlen($sip_profile_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_uuid']."<br>\n"; }
if (strlen($sip_profile_name) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_name']."<br>\n"; } if (strlen($sip_profile_name) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_name']."<br>\n"; }
//if (strlen($sip_profile_hostname) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_hostname']."<br>\n"; } //if (strlen($sip_profile_hostname) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_hostname']."<br>\n"; }
if (strlen($sip_profile_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_enabled']."<br>\n"; } if (strlen($sip_profile_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-sip_profile_enabled']."<br>\n"; }
@@ -88,72 +88,74 @@
return; return;
} }
//cleanup the array
$x = 0;
foreach ($_POST["sip_profile_domains"] as $row) {
//unset the empty row
if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_name"]) == 0) {
unset($_POST["sip_profile_domains"][$x]);
}
if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_alias"]) == 0) {
unset($_POST["sip_profile_domains"][$x]);
}
if (strlen($_POST["sip_profile_domains"][$x]["sip_profile_domain_parse"]) == 0) {
unset($_POST["sip_profile_domains"][$x]);
}
//increment the row
$x++;
}
//cleanup the array
$x = 0;
foreach ($_POST["sip_profile_settings"] as $row) {
//unset the empty row
if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_name"]) == 0) {
unset($_POST["sip_profile_settings"][$x]);
}
//if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_value"]) == 0) {
// unset($_POST["sip_profile_settings"][$x]);
//}
if (strlen($_POST["sip_profile_settings"][$x]["sip_profile_setting_enabled"]) == 0) {
unset($_POST["sip_profile_settings"][$x]);
}
//increment the row
$x++;
}
//add the sip_profile_uuid //add the sip_profile_uuid
if (strlen($_POST["sip_profile_uuid"]) == 0) { if (!is_uuid($_POST["sip_profile_uuid"])) {
$sip_profile_uuid = uuid(); $sip_profile_uuid = uuid();
$_POST["sip_profile_uuid"] = $sip_profile_uuid; $_POST["sip_profile_uuid"] = $sip_profile_uuid;
} }
//cleanup the array
foreach ($_POST["sip_profile_domains"] as $index => $row) {
//populate sip profile uuid
if (!is_uuid($row['sip_profile_uuid'])) {
$_POST["sip_profile_domains"][$index]['sip_profile_uuid'] = $sip_profile_uuid;
}
//unset the empty row
if (strlen($row["sip_profile_domain_name"]) == 0) {
unset($_POST["sip_profile_domains"][$index]);
}
if (strlen($row["sip_profile_domain_alias"]) == 0) {
unset($_POST["sip_profile_domains"][$index]);
}
if (strlen($row["sip_profile_domain_parse"]) == 0) {
unset($_POST["sip_profile_domains"][$index]);
}
}
//cleanup the array
foreach ($_POST["sip_profile_settings"] as $index => $row) {
//populate sip profile uuid
if (!is_uuid($row['sip_profile_uuid'])) {
$_POST["sip_profile_settings"][$index]['sip_profile_uuid'] = $sip_profile_uuid;
}
//unset the empty row
if (strlen($row["sip_profile_setting_name"]) == 0) {
unset($_POST["sip_profile_settings"][$index]);
}
//if (strlen($row["sip_profile_setting_value"]) == 0) {
// unset($_POST["sip_profile_settings"][$index]);
//}
if (strlen($row["sip_profile_setting_enabled"]) == 0) {
unset($_POST["sip_profile_settings"][$index]);
}
}
//prepare the array //prepare the array
$array['sip_profiles'][] = $_POST; $array['sip_profiles'][] = $_POST;
//grant temporary permissions
$p = new permissions;
$p->add('sip_profile_domain_add', 'temp');
$p->add('sip_profile_setting_add', 'temp');
//save to the data //save to the data
$database = new database; $database = new database;
$database->app_name = 'sip_profiles'; $database->app_name = 'sip_profiles';
$database->app_uuid = null; $database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
if (strlen($sip_profile_uuid) > 0) {
$database->uuid($sip_profile_uuid);
}
$database->save($array); $database->save($array);
$message = $database->message; $message = $database->message;
//debug info //get the hostname
//echo "<pre>";
//print_r($message);
//echo "</pre>";
//exit;
//get the hostname
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) { if ($fp) {
$switch_cmd = "switchname"; $switch_cmd = "switchname";
$sip_profile_hostname = event_socket_request($fp, 'api '.$switch_cmd); $sip_profile_hostname = event_socket_request($fp, 'api '.$switch_cmd);
} }
//revoke temporary permissions
$p->delete('sip_profile_domain_add', 'temp');
$p->delete('sip_profile_setting_add', 'temp');
//clear the cache //clear the cache
$cache = new cache; $cache = new cache;
$cache->delete("configuration:sofia.conf:".$sip_profile_hostname); $cache->delete("configuration:sofia.conf:".$sip_profile_hostname);
@@ -165,44 +167,41 @@
$_SESSION["reload_xml"] = true; $_SESSION["reload_xml"] = true;
//redirect the user //redirect the user
if (isset($action)) { if ($action == "add") {
if ($action == "add") { message::add($text['message-add']);
message::add($text['message-add']);
}
if ($action == "update") {
message::add($text['message-update']);
}
header('Location: sip_profile_edit.php?id='.escape($sip_profile_uuid));
return;
} }
} //(is_array($_POST) && strlen($_POST["persistformvar"]) == 0) if ($action == "update") {
message::add($text['message-update']);
}
header('Location: sip_profile_edit.php?id='.escape($sip_profile_uuid));
exit;
}
//pre-populate the form //pre-populate the form
if (is_array($_GET) && $_POST["persistformvar"] != "true") { if (is_array($_GET) && $_POST["persistformvar"] != "true") {
$sip_profile_uuid = check_str($_GET["id"]); $sip_profile_uuid = $_GET["id"];
$sql = "select * from v_sip_profiles "; $sql = "select * from v_sip_profiles ";
$sql .= "where sip_profile_uuid = '$sip_profile_uuid' "; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$prep_statement = $db->prepare(check_sql($sql)); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$prep_statement->execute(); $database = new database;
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED); $row = $database->select($sql, $parameters, 'row');
foreach ($sip_profiles as $key => $row) { $sip_profiles[$key] = array_map("escape", $row); } if (is_array($row) && @sizeof($row) != 0) {
foreach ($sip_profiles as $row) {
$sip_profile_name = $row["sip_profile_name"]; $sip_profile_name = $row["sip_profile_name"];
$sip_profile_hostname = $row["sip_profile_hostname"]; $sip_profile_hostname = $row["sip_profile_hostname"];
$sip_profile_enabled = $row["sip_profile_enabled"]; $sip_profile_enabled = $row["sip_profile_enabled"];
$sip_profile_description = $row["sip_profile_description"]; $sip_profile_description = $row["sip_profile_description"];
} }
unset ($prep_statement); unset($sql, $parameters, $row);
} }
//get the child data //get the child data
$sql = "select * from v_sip_profile_settings "; $sql = "select * from v_sip_profile_settings ";
$sql .= "where sip_profile_uuid = '".$sip_profile_uuid."' "; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$sql .= "order by sip_profile_setting_name "; $sql .= "order by sip_profile_setting_name ";
$prep_statement = $db->prepare($sql); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$prep_statement->execute(); $database = new database;
$sip_profile_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); $sip_profile_settings = $database->select($sql, $parameters, 'all');
foreach ($sip_profile_settings as $key => $row) { $sip_profile_settings[$key] = array_map("escape", $row); } unset($sql, $parameters);
//add an empty row //add an empty row
$x = count($sip_profile_settings); $x = count($sip_profile_settings);
@@ -215,11 +214,11 @@
//get the child data //get the child data
$sql = "select * from v_sip_profile_domains "; $sql = "select * from v_sip_profile_domains ";
$sql .= "where sip_profile_uuid = '".$sip_profile_uuid."' "; $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
$prep_statement = $db->prepare($sql); $parameters['sip_profile_uuid'] = $sip_profile_uuid;
$prep_statement->execute(); $database = new database;
$sip_profile_domains = $prep_statement->fetchAll(PDO::FETCH_NAMED); $sip_profile_domains = $database->select($sql, $parameters, 'all');
foreach ($sip_profile_domains as $key => $row) { $sip_profile_domains[$key] = array_map("escape", $row); } unset($sql, $parameters);
//add an empty row //add an empty row
$x = count($sip_profile_domains); $x = count($sip_profile_domains);
@@ -251,7 +250,12 @@
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-sip_profile']."</b><br><br></td>\n"; echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-sip_profile']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n"; echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='sip_profiles.php'\" value='".$text['button-back']."'>"; echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='sip_profiles.php'\" value='".$text['button-back']."'>";
echo " <input type='button' class='btn' name='' alt='".$text['button-copy']."' onclick=\"var name = prompt('".$text['confirm-copy']."'); if (name != null) { window.location='sip_profile_copy.php?id=".$sip_profile_uuid."&name=' + name; }\" value='".$text['button-copy']."'>\n"; if (permission_exists('dialplan_add')
|| permission_exists('inbound_route_add')
|| permission_exists('outbound_route_add')
|| permission_exists('time_condition_add')) {
echo " <input type='button' class='btn' name='' alt='".$text['button-copy']."' onclick=\"var name = prompt('".$text['label-new_sip_profile_name']."'); if (name != null) { window.location='sip_profile_copy.php?id=".$sip_profile_uuid."&name=' + name; }\" value='".$text['button-copy']."'>\n";
}
echo " <input type='submit' class='btn' value='".$text['button-save']."'>"; echo " <input type='submit' class='btn' value='".$text['button-save']."'>";
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
@@ -261,7 +265,7 @@
echo " ".$text['label-sip_profile_name']."\n"; echo " ".$text['label-sip_profile_name']."\n";
echo "</td>\n"; echo "</td>\n";
echo "<td class='vtable' align='left'>\n"; echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='sip_profile_name' maxlength='255' value=\"$sip_profile_name\">\n"; echo " <input class='formfld' type='text' name='sip_profile_name' maxlength='255' value=\"".escape($sip_profile_name)."\">\n";
echo "<br />\n"; echo "<br />\n";
echo $text['description-sip_profile_name']."\n"; echo $text['description-sip_profile_name']."\n";
echo "</td>\n"; echo "</td>\n";
@@ -279,16 +283,16 @@
echo " <th class='vtable' style='width:70px; text-align: left;'>".$text['label-sip_profile_domain_parse']."</th>\n"; echo " <th class='vtable' style='width:70px; text-align: left;'>".$text['label-sip_profile_domain_parse']."</th>\n";
echo " </tr>\n"; echo " </tr>\n";
$x = 0; $x = 0;
foreach($sip_profile_domains as $row) { foreach ($sip_profile_domains as $row) {
echo " <tr>\n"; echo " <tr>\n";
if (strlen($row["sip_profile_domain_uuid"]) > 0) { if (is_uuid($row["sip_profile_domain_uuid"])) {
$sip_profile_domain_uuid = $row["sip_profile_domain_uuid"]; $sip_profile_domain_uuid = $row["sip_profile_domain_uuid"];
} }
if (strlen($row["sip_profile_uuid"]) > 0) { if (is_uuid($row["sip_profile_uuid"])) {
$sip_profile_uuid = $row["sip_profile_uuid"]; $sip_profile_uuid = $row["sip_profile_uuid"];
} }
echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_domain_uuid]' value=\"".$sip_profile_domain_uuid."\">\n"; echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_domain_uuid]' value=\"".$sip_profile_domain_uuid."\">\n";
echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_uuid]' maxlength='255' value=\"".$sip_profile_uuid."\">\n"; echo " <input type='hidden' name='sip_profile_domains[$x][sip_profile_uuid]' value=\"".$sip_profile_uuid."\">\n";
echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_domain_name_$x','sip_profile_domain_name_$x');\" nowrap=\"nowrap\">\n"; echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_domain_name_$x','sip_profile_domain_name_$x');\" nowrap=\"nowrap\">\n";
echo " &nbsp; <label id='label_sip_profile_domain_name_$x'>".escape($row["sip_profile_domain_name"])."</label>\n"; echo " &nbsp; <label id='label_sip_profile_domain_name_$x'>".escape($row["sip_profile_domain_name"])."</label>\n";
echo " <input id='sip_profile_domain_name_$x' class='formfld' style='display: none;' type='text' name='sip_profile_domains[$x][sip_profile_domain_name]' maxlength='255' value=\"".escape($row["sip_profile_domain_name"])."\">\n"; echo " <input id='sip_profile_domain_name_$x' class='formfld' style='display: none;' type='text' name='sip_profile_domains[$x][sip_profile_domain_name]' maxlength='255' value=\"".escape($row["sip_profile_domain_name"])."\">\n";
@@ -332,10 +336,18 @@
echo " </td>\n"; echo " </td>\n";
echo " <td class='list_control_icons' style='width: 25px;'>\n"; echo " <td class='list_control_icons' style='width: 25px;'>\n";
if (strlen($row["sip_profile_domain_name"]) > 0) { if (strlen($row["sip_profile_domain_name"]) > 0) {
echo " <a href=\"sip_profile_domain_delete.php?id=".escape($row["sip_profile_domain_uuid"])."&amp;sip_profile_domain_uuid=".$row["sip_profile_domain_uuid"]."&amp;a=delete\" alt='delete' onclick=\"return confirm('Do you really want to delete this?')\"><button type='button' class='btn btn-default list_control_icon'><span class='glyphicon glyphicon-remove'></span></button></a>\n"; echo " <a href=\"sip_profile_domain_delete.php?id=".escape($row["sip_profile_domain_uuid"])."&amp;sip_profile_domain_uuid=".escape($row["sip_profile_domain_uuid"])."&amp;a=delete\" alt='delete' onclick=\"return confirm('Do you really want to delete this?')\"><button type='button' class='btn btn-default list_control_icon'><span class='glyphicon glyphicon-remove'></span></button></a>\n";
} }
echo " </td>\n"; echo " </td>\n";
echo " </tr>\n"; echo " </tr>\n";
//convert last empty labels to form elements
if ($row["sip_profile_domain_name"] == '' && $row["sip_profile_domain_alias"] == '' && $row["sip_profile_domain_parse"] == '') {
echo "<script>\n";
echo " label_to_form('label_sip_profile_domain_name_$x','sip_profile_domain_name_$x');\n";
echo " label_to_form('label_sip_profile_domain_alias_$x','sip_profile_domain_alias_$x');\n";
echo " label_to_form('label_sip_profile_domain_parse_$x','sip_profile_domain_parse_$x');\n";
echo "</script>\n";
}
$x++; $x++;
} }
echo " </table>\n"; echo " </table>\n";
@@ -355,18 +367,17 @@
echo " <th class='vtable' style='text-align: left;'>".$text['label-sip_profile_setting_description']."</th>\n"; echo " <th class='vtable' style='text-align: left;'>".$text['label-sip_profile_setting_description']."</th>\n";
echo " </tr>\n"; echo " </tr>\n";
$x = 0; $x = 0;
foreach($sip_profile_settings as $row) { foreach ($sip_profile_settings as $row) {
echo " <tr>\n"; echo " <tr>\n";
echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_setting_uuid]' value=\"".escape($row["sip_profile_setting_uuid"])."\">\n"; echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_setting_uuid]' value=\"".escape($row["sip_profile_setting_uuid"])."\">\n";
echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_setting_uuid]' maxlength='255' value=\"".escape($row["sip_profile_setting_uuid"])."\">\n"; echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_uuid]' value=\"".escape($row["sip_profile_uuid"])."\">\n";
echo " <input type='hidden' name='sip_profile_settings[$x][sip_profile_uuid]' maxlength='255' value=\"".escape($row["sip_profile_uuid"])."\">\n";
echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_name_$x','sip_profile_setting_name_$x');\" nowrap=\"nowrap\">\n"; echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_name_$x','sip_profile_setting_name_$x');\" nowrap=\"nowrap\">\n";
echo " &nbsp; <label id='label_sip_profile_setting_name_$x'>".escape($row["sip_profile_setting_name"])."</label>\n"; echo " &nbsp; <label id='label_sip_profile_setting_name_$x'>".escape($row["sip_profile_setting_name"])."</label>\n";
echo " <input id='sip_profile_setting_name_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_name]' maxlength='255' value=\"".$row["sip_profile_setting_name"]."\">\n"; echo " <input id='sip_profile_setting_name_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_name]' maxlength='255' value=\"".escape($row["sip_profile_setting_name"])."\">\n";
echo " </td>\n"; echo " </td>\n";
echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_value_$x','sip_profile_setting_value_$x');\" nowrap=\"nowrap\">\n"; echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_value_$x','sip_profile_setting_value_$x');\" nowrap=\"nowrap\">\n";
echo " <label id='label_sip_profile_setting_value_$x'>".substr($row["sip_profile_setting_value"],0,22)." &nbsp;</label>\n"; echo " <label id='label_sip_profile_setting_value_$x'>".escape(substr($row["sip_profile_setting_value"],0,22))." &nbsp;</label>\n";
echo " <input id='sip_profile_setting_value_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_value]' maxlength='255' value=\"".$row["sip_profile_setting_value"]."\">\n"; echo " <input id='sip_profile_setting_value_$x' class='formfld' style='display: none;' type='text' name='sip_profile_settings[$x][sip_profile_setting_value]' maxlength='255' value=\"".escape($row["sip_profile_setting_value"])."\">\n";
echo " </td>\n"; echo " </td>\n";
echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_enabled_$x','sip_profile_setting_enabled_$x');\" nowrap=\"nowrap\">\n"; echo " <td class=\"vtablerow\" style=\"\" onclick=\"label_to_form('label_sip_profile_setting_enabled_$x','sip_profile_setting_enabled_$x');\" nowrap=\"nowrap\">\n";
echo " <label id='label_sip_profile_setting_enabled_$x'>".escape($row["sip_profile_setting_enabled"])."</label>\n"; echo " <label id='label_sip_profile_setting_enabled_$x'>".escape($row["sip_profile_setting_enabled"])."</label>\n";
@@ -396,6 +407,16 @@
} }
echo " </td>\n"; echo " </td>\n";
echo " </tr>\n"; echo " </tr>\n";
//convert last empty labels to form elements
if ($row["sip_profile_setting_name"] == '' && $row["sip_profile_setting_value"] == '' && $row["sip_profile_setting_enabled"] == '' && $row["sip_profile_setting_description"] == '') {
echo "<script>\n";
echo " label_to_form('label_sip_profile_setting_name_$x','sip_profile_setting_name_$x');\n";
echo " label_to_form('label_sip_profile_setting_value_$x','sip_profile_setting_value_$x');\n";
echo " label_to_form('label_sip_profile_setting_enabled_$x','sip_profile_setting_enabled_$x');\n";
echo " label_to_form('label_sip_profile_setting_description_$x','sip_profile_setting_description_$x');\n";
echo "</script>\n";
}
$x++;
$x++; $x++;
} }
echo " </table>\n"; echo " </table>\n";
@@ -419,7 +440,6 @@
echo "</td>\n"; echo "</td>\n";
echo "<td class='vtable' align='left'>\n"; echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='sip_profile_enabled'>\n"; echo " <select class='formfld' name='sip_profile_enabled'>\n";
echo " <option value=''></option>\n";
if ($sip_profile_enabled == "true") { if ($sip_profile_enabled == "true") {
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n"; echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
} }
@@ -454,6 +474,7 @@
if ($action == "update") { if ($action == "update") {
echo " <input type='hidden' name='sip_profile_uuid' value='".escape($sip_profile_uuid)."'>\n"; echo " <input type='hidden' name='sip_profile_uuid' value='".escape($sip_profile_uuid)."'>\n";
} }
echo " <br>\n";
echo " <input type='submit' class='btn' value='".$text['button-save']."'>\n"; echo " <input type='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n"; echo " </td>\n";
echo " </tr>"; echo " </tr>";
@@ -464,4 +485,4 @@
//include the footer //include the footer
require_once "resources/footer.php"; require_once "resources/footer.php";
?> ?>
+20 -17
View File
@@ -38,29 +38,32 @@ else {
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
if (count($_GET)>0) { //get ids
$id = check_str($_GET["id"]); $sip_profile_setting_uuid = $_GET["id"];
$sip_profile_uuid = check_str($_GET["sip_profile_uuid"]); $sip_profile_uuid = $_GET["sip_profile_uuid"];
}
if (strlen($id)>0) {
//delete the sip profile setting
$sql = "delete from v_sip_profile_settings ";
$sql .= "where sip_profile_setting_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql);
if (is_uuid($sip_profile_setting_uuid) && is_uuid($sip_profile_uuid)) {
//build array
$array['sip_profile_settings'][0]['sip_profile_setting_uuid'] = $sip_profile_setting_uuid;
//execute delete
$database = new database;
$database->app_name = 'sip_profiles';
$database->app_uuid = '159a8da8-0e8c-a26b-6d5b-19c532b6d470';
$database->delete($array);
unset($array);
//save the sip profile xml //save the sip profile xml
save_sip_profile_xml(); save_sip_profile_xml();
//apply settings reminder //apply settings reminder
$_SESSION["reload_xml"] = true; $_SESSION["reload_xml"] = true;
//set message
message::add($text['message-delete']);
//redirect
header("Location: sip_profile_edit.php?id=".$sip_profile_uuid);
exit;
} }
//redirect the browser //default redirect
message::add($text['message-delete']); header("Location: sip_profiles.php");
header("Location: sip_profile_edit.php?id=".$sip_profile_uuid); exit;
return;
?> ?>
+29 -43
View File
@@ -43,16 +43,17 @@
$text = $language->get(); $text = $language->get();
//get variables used to control the order //get variables used to control the order
$order_by = check_str($_GET["order_by"]); $order_by = $_GET["order_by"];
$order = check_str($_GET["order"]); $order = $_GET["order"];
//add the search term //add the search term
$search = strtolower(check_str($_GET["search"])); $search = strtolower($_GET["search"]);
if (strlen($search) > 0) { if (strlen($search) > 0) {
$sql_search = "and ("; $sql_search = "where (";
$sql_search .= "lower(sip_profile_name) like '%".$search."%' "; $sql_search .= "lower(sip_profile_name) like :search ";
$sql_search .= "or lower(sip_profile_hostname) like '%".$search."%' "; $sql_search .= "or lower(sip_profile_hostname) like :search ";
$sql_search .= ") "; $sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
} }
//additional includes //additional includes
@@ -60,21 +61,9 @@
require_once "resources/paging.php"; require_once "resources/paging.php";
//prepare to page the results //prepare to page the results
$sql = "select count(sip_profile_uuid) as num_rows from v_sip_profiles "; $sql = "select count(*) from v_sip_profiles ";
$sql .= "where 1 = 1 "; $database = new database;
$sql .= $sql_search; $num_rows = $database->select($sql, null, 'column');
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$num_rows = $row['num_rows'];
}
else {
$num_rows = '0';
}
}
//prepare to page the results //prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
@@ -85,16 +74,13 @@
$offset = $rows_per_page * $page; $offset = $rows_per_page * $page;
//get the list //get the list
$sql = "select * from v_sip_profiles "; $sql = str_replace('count(*)', '*', $sql);
$sql .= "where 1 = 1 ";
$sql .= $sql_search; $sql .= $sql_search;
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } $sql .= order_by($order_by, $order);
$sql .= "limit $rows_per_page offset $offset "; $sql .= limit_offset($rows_per_page, $offset);
$prep_statement = $db->prepare(check_sql($sql)); $database = new database;
$prep_statement->execute(); $sip_profiles = $database->select($sql, $parameters, 'all');
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($sql, $parameters);
foreach ($sip_profiles as $key => $row) { $sip_profiles[$key] = array_map("escape", $row); }
unset ($prep_statement, $sql);
//escape the search //escape the search
$search = escape($search); $search = escape($search);
@@ -139,28 +125,28 @@
echo "<tr>\n"; echo "<tr>\n";
if (is_array($sip_profiles)) { if (is_array($sip_profiles)) {
foreach($sip_profiles as $row) { foreach ($sip_profiles as $row) {
if (permission_exists('sip_profile_edit')) { if (permission_exists('sip_profile_edit')) {
$tr_link = "href='sip_profile_edit.php?id=".$row['sip_profile_uuid']."'"; $tr_link = "href='sip_profile_edit.php?id=".escape($row['sip_profile_uuid'])."'";
} }
echo "<tr ".$tr_link.">\n"; echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['sip_profile_name']."&nbsp;</td>\n"; echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".escape($row['sip_profile_name'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['sip_profile_hostname']."&nbsp;</td>\n"; echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['sip_profile_hostname'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['sip_profile_enabled']."&nbsp;</td>\n"; echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['sip_profile_enabled'])."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg'>".$row['sip_profile_description']."&nbsp;</td>\n"; echo " <td valign='top' class='row_stylebg'>".escape($row['sip_profile_description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>"; echo " <td class='list_control_icons'>";
if (permission_exists('sip_profile_edit')) { if (permission_exists('sip_profile_edit')) {
echo "<a href='sip_profile_edit.php?id=".$row['sip_profile_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>"; echo "<a href='sip_profile_edit.php?id=".escape($row['sip_profile_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
} }
if (permission_exists('sip_profile_delete')) { if (permission_exists('sip_profile_delete')) {
echo "<a href='sip_profile_delete.php?id=".$row['sip_profile_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>"; echo "<a href='sip_profile_delete.php?id=".escape($row['sip_profile_uuid'])."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
} }
echo " </td>\n"; echo " </td>\n";
echo "</tr>\n"; echo "</tr>\n";
if ($c==0) { $c=1; } else { $c=0; } $c = $c ? 0 : 1;
} //end foreach }
unset($sql, $sip_profiles); }
} //end if results unset($sip_profiles, $row);
echo "<tr>\n"; echo "<tr>\n";
echo "<td colspan='6' align='left'>\n"; echo "<td colspan='6' align='left'>\n";
@@ -186,4 +172,4 @@
//include the footer //include the footer
require_once "resources/footer.php"; require_once "resources/footer.php";
?> ?>