From 17af99d5e5b77ecc84fb56d60a393a97dabb3021 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Tue, 14 Aug 2012 21:59:45 +0000 Subject: [PATCH] Efficiency enhancement for upgrade and upgrade_schema by running global tasks one time rather than for each domain. --- app/dialplan_inbound/app_defaults.php | 40 +++-- app/dialplan_outbound/app_defaults.php | 18 +- app/extensions/app_defaults.php | 6 +- app/modules/app_defaults.php | 23 +-- app/php_edit/app_defaults.php | 70 ++++---- app/settings/app_defaults.php | 73 ++++++++ app/sip_profiles/app_defaults.php | 190 ++++++++++---------- app/vars/app_defaults.php | 174 +++++++++--------- app/xml_cdr/app_defaults.php | 18 +- core/databases/app_defaults.php | 238 +++++++++++++------------ core/databases/database_edit.php | 1 + core/default_settings/app_defaults.php | 1 - core/menu/app_defaults.php | 165 ++++++++--------- core/upgrade/app_defaults.php | 4 +- 14 files changed, 562 insertions(+), 459 deletions(-) create mode 100644 app/settings/app_defaults.php diff --git a/app/dialplan_inbound/app_defaults.php b/app/dialplan_inbound/app_defaults.php index 4c00f35a16..6055dd5090 100644 --- a/app/dialplan_inbound/app_defaults.php +++ b/app/dialplan_inbound/app_defaults.php @@ -25,31 +25,35 @@ */ //if there are multiple domains then update the public dir path to include the domain - if (count($_SESSION["domains"]) > 1) { - if (is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { - //clear out the old xml files - $v_needle = '_v_'; - if($dh = opendir($_SESSION['switch']['dialplan']['dir'].'/public')) { - $files = Array(); - while($file = readdir($dh)) { - if($file != "." && $file != ".." && $file[0] != '.') { - if(is_dir($dir . "/" . $file)) { - //this is a directory - } else { - if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') { - unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$file); + if ($domains_processed == 1) { + if (count($_SESSION["domains"]) > 1) { + if (is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { + //clear out the old xml files + $v_needle = '_v_'; + if($dh = opendir($_SESSION['switch']['dialplan']['dir'].'/public')) { + $files = Array(); + while($file = readdir($dh)) { + if($file != "." && $file != ".." && $file[0] != '.') { + if(is_dir($dir . "/" . $file)) { + //this is a directory + } else { + if (strpos($file, $v_needle) !== false && substr($file,-4) == '.xml') { + unlink($_SESSION['switch']['dialplan']['dir'].'/public/'.$file); + } } } } + closedir($dh); } - closedir($dh); - } + } } } //if the public directory doesn't exist then create it - if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { - if (!is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { mkdir($_SESSION['switch']['dialplan']['dir'].'/public',0777,true); } + if ($domains_processed == 1) { + if (strlen($_SESSION['switch']['dialplan']['dir']) > 0) { + if (!is_dir($_SESSION['switch']['dialplan']['dir'].'/public')) { mkdir($_SESSION['switch']['dialplan']['dir'].'/public',0777,true); } + } } //if multiple domains then make sure that the dialplan/public/domain_name.xml file exists @@ -70,6 +74,6 @@ unset($xml,$file); } } - } + } ?> \ No newline at end of file diff --git a/app/dialplan_outbound/app_defaults.php b/app/dialplan_outbound/app_defaults.php index af8bd44d63..879b292ed7 100644 --- a/app/dialplan_outbound/app_defaults.php +++ b/app/dialplan_outbound/app_defaults.php @@ -25,14 +25,16 @@ */ //make sure that enum uses sofia internal in the enum.conf.xml file - $file_contents = file_get_contents($switch_conf_dir."/autoload_configs/enum.conf.xml"); - $file_contents_new = str_replace("service=\"E2U+SIP\" regex=\"sip:(.*)\" replace=\"sofia/\${use_profile}/\$1", "service=\"E2U+SIP\" regex=\"sip:(.*)\" replace=\"sofia/internal/\$1", $file_contents); - if ($file_contents != $file_contents_new) { - $fout = fopen($switch_conf_dir."/autoload_configs/enum.conf.xml","w"); - fwrite($fout, $file_contents_new); - fclose($fout); - if ($display_type == "text") { - echo " enum.conf.xml: updated\n"; + if ($domains_processed == 1) { + $file_contents = file_get_contents($switch_conf_dir."/autoload_configs/enum.conf.xml"); + $file_contents_new = str_replace("service=\"E2U+SIP\" regex=\"sip:(.*)\" replace=\"sofia/\${use_profile}/\$1", "service=\"E2U+SIP\" regex=\"sip:(.*)\" replace=\"sofia/internal/\$1", $file_contents); + if ($file_contents != $file_contents_new) { + $fout = fopen($switch_conf_dir."/autoload_configs/enum.conf.xml","w"); + fwrite($fout, $file_contents_new); + fclose($fout); + if ($display_type == "text") { + echo " enum.conf.xml: updated\n"; + } } } diff --git a/app/extensions/app_defaults.php b/app/extensions/app_defaults.php index bced9d90e7..1f97d52bed 100644 --- a/app/extensions/app_defaults.php +++ b/app/extensions/app_defaults.php @@ -25,8 +25,10 @@ */ //if the extensions dir doesn't exist then create it - if (strlen($_SESSION['switch']['extensions']['dir']) > 0) { - if (!is_dir($_SESSION['switch']['extensions']['dir'])) { mkdir($_SESSION['switch']['extensions']['dir'],0777,true); } + if ($domains_processed == 1) { + if (strlen($_SESSION['switch']['extensions']['dir']) > 0) { + if (!is_dir($_SESSION['switch']['extensions']['dir'])) { mkdir($_SESSION['switch']['extensions']['dir'],0777,true); } + } } ?> \ No newline at end of file diff --git a/app/modules/app_defaults.php b/app/modules/app_defaults.php index e8ee87f902..23fb82654a 100644 --- a/app/modules/app_defaults.php +++ b/app/modules/app_defaults.php @@ -24,16 +24,19 @@ Mark J Crane */ -//use the module class to get the list of modules from the db and add any missing modules - require_once "includes/classes/switch_modules.php"; - $mod = new switch_modules; - $mod->db = $db; - $mod->dir = $_SESSION['switch']['mod']['dir']; - $mod->get_modules(); - $mod->synch(); - $msg = $mod->msg; -// synchronize the modules - save_module_xml(); +//use the module class to get the list of modules from the db and add any missing modules + if ($domains_processed == 1) { + require_once "includes/classes/switch_modules.php"; + $mod = new switch_modules; + $mod->db = $db; + $mod->dir = $_SESSION['switch']['mod']['dir']; + $mod->get_modules(); + $mod->synch(); + $msg = $mod->msg; + + //synchronize the modules + save_module_xml(); + } ?> \ No newline at end of file diff --git a/app/php_edit/app_defaults.php b/app/php_edit/app_defaults.php index 0fac72d90f..68b3729580 100644 --- a/app/php_edit/app_defaults.php +++ b/app/php_edit/app_defaults.php @@ -25,41 +25,43 @@ */ //if the number of rows is 0 then add example clips - $sql = "select count(*) as num_rows from v_clips "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $clip_name = "\$_POST"; - $clip_folder = "PHP"; - $clip_text_start = "\$zzz = \$_POST[\""; - $clip_text_end = "\"];"; - $clip_desc = "Set HTTP POST value as a PHP variable."; - $clip_order = 0; + if ($domains_processed == 1) { + $sql = "select count(*) as num_rows from v_clips "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + $clip_name = "\$_POST"; + $clip_folder = "PHP"; + $clip_text_start = "\$zzz = \$_POST[\""; + $clip_text_end = "\"];"; + $clip_desc = "Set HTTP POST value as a PHP variable."; + $clip_order = 0; - $sql = "insert into v_clips "; - $sql .= "("; - $sql .= "clip_uuid, "; - $sql .= "clip_name, "; - $sql .= "clip_folder, "; - $sql .= "clip_text_start, "; - $sql .= "clip_text_end, "; - $sql .= "clip_desc, "; - $sql .= "clip_order "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'$clip_name', "; - $sql .= "'$clip_folder', "; - $sql .= "'$clip_text_start', "; - $sql .= "'$clip_text_end', "; - $sql .= "'$clip_desc', "; - $sql .= "'$clip_order' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + $sql = "insert into v_clips "; + $sql .= "("; + $sql .= "clip_uuid, "; + $sql .= "clip_name, "; + $sql .= "clip_folder, "; + $sql .= "clip_text_start, "; + $sql .= "clip_text_end, "; + $sql .= "clip_desc, "; + $sql .= "clip_order "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'$clip_name', "; + $sql .= "'$clip_folder', "; + $sql .= "'$clip_text_start', "; + $sql .= "'$clip_text_end', "; + $sql .= "'$clip_desc', "; + $sql .= "'$clip_order' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + } } } diff --git a/app/settings/app_defaults.php b/app/settings/app_defaults.php new file mode 100644 index 0000000000..e730e22469 --- /dev/null +++ b/app/settings/app_defaults.php @@ -0,0 +1,73 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//move the smtp settings from v_settings to the v_default_settings table +if (count($_SESSION['email']) == 0 && $domains_processed == 1) { + //get the data from the database + $sql = "select * from v_settings "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_NAMED); + //set the variable + $smtp[]['smtp_host'] = check_str($row['smtp_host']); + $smtp[]['smtp_secure'] = check_str($row['smtp_secure']); + $smtp[]['smtp_auth'] = check_str($row['smtp_auth']); + $smtp[]['smtp_username'] = check_str($row['smtp_username']); + $smtp[]['smtp_password'] = check_str($row['smtp_password']); + $smtp[]['smtp_from'] = check_str($row['smtp_from']); + $smtp[]['smtp_from_name'] = check_str($row['smtp_from_name']); + //build the sql inserts + foreach ($smtp as $row) { + foreach ($row as $key => $value) { + //add the provision variable to the default settings table + $sql = "insert into v_default_settings "; + $sql .= "("; + $sql .= "default_setting_uuid, "; + $sql .= "default_setting_category, "; + $sql .= "default_setting_subcategory, "; + $sql .= "default_setting_name, "; + $sql .= "default_setting_value, "; + $sql .= "default_setting_enabled, "; + $sql .= "default_setting_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'email', "; + $sql .= "'".$key."', "; + $sql .= "'var', "; + $sql .= "'".check_str($value)."', "; + $sql .= "'true', "; + $sql .= "'' "; + $sql .= ")"; + //echo $sql."\n"; + $db->exec(check_sql($sql)); + unset($sql); + } + } +} + +?> \ No newline at end of file diff --git a/app/sip_profiles/app_defaults.php b/app/sip_profiles/app_defaults.php index 1d781df7eb..63c5885f4c 100644 --- a/app/sip_profiles/app_defaults.php +++ b/app/sip_profiles/app_defaults.php @@ -25,110 +25,114 @@ */ //if the number of rows is 0 then read the sip profile xml into the database - $sql = "select count(*) as num_rows from v_sip_profiles "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $xml_list = glob($_SESSION['switch']['conf']['dir']."/sip_profiles/*.xml"); - foreach ($xml_list 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']; - //echo "sip profile name: ".$sip_profile_name."\n"; + if ($domains_processed == 1) { + $sql = "select count(*) as num_rows from v_sip_profiles "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + $xml_list = glob($_SESSION['switch']['conf']['dir']."/sip_profiles/*.xml"); + foreach ($xml_list 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']; + //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": - $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. "; - break; - case "internal-ipv6": - $sip_profile_description = "The Internal IPV6 profile binds to the IP version 6 address and is similar to the Internal profile.\n"; - break; - case "external": - $sip_profile_description .= "The External profile external provides anonymous calling in the public context. "; - $sip_profile_description .= "By default the External profile binds to port 5080. "; - $sip_profile_description .= "Calls can be sent using a SIP URL \"voip.domain.com:5080\" "; - break; - case "lan": - $sip_profile_description = "The LAN profile is the same as the Internal profile except that it is bound to the LAN IP.\n"; - break; - default: - $sip_profile_description .= ''; - } + if ($sip_profile_name != "{v_sip_profile_name}") { + //prepare the description + switch ($sip_profile_name) { + case "internal": + $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. "; + break; + case "internal-ipv6": + $sip_profile_description = "The Internal IPV6 profile binds to the IP version 6 address and is similar to the Internal profile.\n"; + break; + case "external": + $sip_profile_description .= "The External profile external provides anonymous calling in the public context. "; + $sip_profile_description .= "By default the External profile binds to port 5080. "; + $sip_profile_description .= "Calls can be sent using a SIP URL \"voip.domain.com:5080\" "; + break; + case "lan": + $sip_profile_description = "The LAN profile is the same as the Internal profile except that it is bound to the LAN IP.\n"; + break; + default: + $sip_profile_description .= ''; + } - //add the sip profile - $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); + //add the sip profile + $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); - //add the sip profile settings - foreach ($sip_profile['settings']['param'] as $row) { - //get the name and value pair - $sip_profile_setting_name = $row['@attributes']['name']; - $sip_profile_setting_value = $row['@attributes']['value']; - //echo "name: $name value: $value\n"; - //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 .= "'true' "; - $sql .= ")"; - //echo $sql."\n\n"; - $db->exec(check_sql($sql)); - } + //add the sip profile settings + foreach ($sip_profile['settings']['param'] as $row) { + //get the name and value pair + $sip_profile_setting_name = $row['@attributes']['name']; + $sip_profile_setting_value = $row['@attributes']['value']; + //echo "name: $name value: $value\n"; + //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 .= "'true' "; + $sql .= ")"; + //echo $sql."\n\n"; + $db->exec(check_sql($sql)); + } + } } } } } //if there is more than one domain then disable the force domains sip profile settings - if (count($_SESSION['domains']) > 1) { - //disable force domains - $sql = "update v_sip_profile_settings set "; - $sql .= "sip_profile_setting_enabled = 'false' "; - $sql .= "where sip_profile_setting_name = 'force-register-domain'"; - $sql .= "or sip_profile_setting_name = 'force-subscription-domain'"; - $sql .= "or sip_profile_setting_name = 'force-register-db-domain'"; - $db->exec(check_sql($sql)); - unset($sql); + if ($domains_processed == 1) { + if (count($_SESSION['domains']) > 1) { + //disable force domains + $sql = "update v_sip_profile_settings set "; + $sql .= "sip_profile_setting_enabled = 'false' "; + $sql .= "where sip_profile_setting_name = 'force-register-domain'"; + $sql .= "or sip_profile_setting_name = 'force-subscription-domain'"; + $sql .= "or sip_profile_setting_name = 'force-register-db-domain'"; + $db->exec(check_sql($sql)); + unset($sql); - //save the sip profile xml - save_sip_profile_xml(); + //save the sip profile xml + save_sip_profile_xml(); - //apply settings reminder - $_SESSION["reload_xml"] = true; + //apply settings reminder + $_SESSION["reload_xml"] = true; + } } ?> \ No newline at end of file diff --git a/app/vars/app_defaults.php b/app/vars/app_defaults.php index 263433f8be..0edcb166b3 100644 --- a/app/vars/app_defaults.php +++ b/app/vars/app_defaults.php @@ -24,95 +24,99 @@ Mark J Crane */ -$vars_string = <<=2;+=.1;%(1400,0,350,440)","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"sit","var_value":"%(274,0,913.8);%(274,0,1370.6);%(380,0,1776.7)","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"sip_tls_version","var_value":"tlsv1","var_cat":"SIP","var_enabled":"true","var_description":"U0lQIGFuZCBUTFMgc2V0dGluZ3Mu"}, -{"var_name":"internal_auth_calls","var_value":"true","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, -{"var_name":"internal_sip_port","var_value":"5060","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, -{"var_name":"internal_tls_port","var_value":"5061","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, -{"var_name":"internal_ssl_enable","var_value":"false","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, -{"var_name":"internal_ssl_dir","var_value":"\$\${base_dir}/conf/ssl","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, -{"var_name":"external_auth_calls","var_value":"false","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, -{"var_name":"external_sip_port","var_value":"5080","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, -{"var_name":"external_tls_port","var_value":"5081","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, -{"var_name":"external_ssl_enable","var_value":"false","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, -{"var_name":"external_ssl_dir","var_value":"\$\${base_dir}/conf/ssl","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, -{"var_name":"use_profile","var_value":"internal","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"default_language","var_value":"en","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"default_dialect","var_value":"us","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"default_voice","var_value":"callie","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"ajax_refresh_rate","var_value":"3000","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"format_phone","var_value":"Rxxx-xxx-xxxx","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"format_phone","var_value":"xxx-xxx-xxxx","var_cat":"Defaults","var_enabled":"true","var_description":""}, -{"var_name":"xml_cdr_archive","var_value":"dir","var_cat":"Defaults","var_enabled":"true","var_description":""} -] -EOD; +if ($domains_processed == 1) { + $vars_string = <<=2;+=.1;%(1400,0,350,440)","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"sit","var_value":"%(274,0,913.8);%(274,0,1370.6);%(380,0,1776.7)","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"sip_tls_version","var_value":"tlsv1","var_cat":"SIP","var_enabled":"true","var_description":"U0lQIGFuZCBUTFMgc2V0dGluZ3Mu"}, + {"var_name":"internal_auth_calls","var_value":"true","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, + {"var_name":"internal_sip_port","var_value":"5060","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, + {"var_name":"internal_tls_port","var_value":"5061","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, + {"var_name":"internal_ssl_enable","var_value":"false","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, + {"var_name":"internal_ssl_dir","var_value":"\$\${base_dir}/conf/ssl","var_cat":"SIP Profile: Internal","var_enabled":"true","var_description":""}, + {"var_name":"external_auth_calls","var_value":"false","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, + {"var_name":"external_sip_port","var_value":"5080","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, + {"var_name":"external_tls_port","var_value":"5081","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, + {"var_name":"external_ssl_enable","var_value":"false","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, + {"var_name":"external_ssl_dir","var_value":"\$\${base_dir}/conf/ssl","var_cat":"SIP Profile: External","var_enabled":"true","var_description":""}, + {"var_name":"use_profile","var_value":"internal","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"default_language","var_value":"en","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"default_dialect","var_value":"us","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"default_voice","var_value":"callie","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"ajax_refresh_rate","var_value":"3000","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"format_phone","var_value":"Rxxx-xxx-xxxx","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"format_phone","var_value":"xxx-xxx-xxxx","var_cat":"Defaults","var_enabled":"true","var_description":""}, + {"var_name":"xml_cdr_archive","var_value":"dir","var_cat":"Defaults","var_enabled":"true","var_description":""} + ] + EOD; -//if there are no variables in the vars table then add them - $sql = " select count(*) as num_rows from v_vars "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $result = json_decode($vars_string, true); - $x = 1; - foreach($result as $row) { - $sql = "insert into v_vars "; - $sql .= "("; - $sql .= "var_uuid, "; - $sql .= "var_name, "; - $sql .= "var_value, "; - $sql .= "var_cat, "; - $sql .= "var_enabled, "; - $sql .= "var_order, "; - $sql .= "var_description "; - $sql .= ") "; - $sql .= "values "; - $sql .= "("; - $sql .= "'".uuid()."', "; - $sql .= "'".$row['var_name']."', "; - $sql .= "'".$row['var_value']."', "; - $sql .= "'".$row['var_cat']."', "; - $sql .= "'".$row['var_enabled']."', "; - $sql .= "'".$x."', "; - $sql .= "'".$row['var_description']."' "; - $sql .= ");"; - $db->exec($sql); - unset($sql); - $x++; + //if there are no variables in the vars table then add them + $sql = " select count(*) as num_rows from v_vars "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] == 0) { + $result = json_decode($vars_string, true); + $x = 1; + foreach($result as $row) { + $sql = "insert into v_vars "; + $sql .= "("; + $sql .= "var_uuid, "; + $sql .= "var_name, "; + $sql .= "var_value, "; + $sql .= "var_cat, "; + $sql .= "var_enabled, "; + $sql .= "var_order, "; + $sql .= "var_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".uuid()."', "; + $sql .= "'".$row['var_name']."', "; + $sql .= "'".$row['var_value']."', "; + $sql .= "'".$row['var_cat']."', "; + $sql .= "'".$row['var_enabled']."', "; + $sql .= "'".$x."', "; + $sql .= "'".$row['var_description']."' "; + $sql .= ");"; + $db->exec($sql); + unset($sql); + $x++; + } } } - } - unset($prep_statement, $result); + unset($prep_statement, $result); +} //if there is more than one domain then disable the domain variable - if (count($_SESSION['domains']) > 1) { - $sql = "update v_vars set "; - $sql .= "var_enabled = 'false' "; - $sql .= "where var_name = 'domain'"; - $db->exec(check_sql($sql)); - unset($sql); + if ($domains_processed == 1) { + if (count($_SESSION['domains']) > 1) { + $sql = "update v_vars set "; + $sql .= "var_enabled = 'false' "; + $sql .= "where var_name = 'domain'"; + $db->exec(check_sql($sql)); + unset($sql); + } } ?> \ No newline at end of file diff --git a/app/xml_cdr/app_defaults.php b/app/xml_cdr/app_defaults.php index 6140274772..07c82b9603 100644 --- a/app/xml_cdr/app_defaults.php +++ b/app/xml_cdr/app_defaults.php @@ -25,14 +25,16 @@ */ //make sure that prefix-a-leg is set to true in the xml_cdr.conf.xml file - $file_contents = file_get_contents($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml"); - $file_contents_new = str_replace("param name=\"prefix-a-leg\" value=\"false\"/", "param name=\"prefix-a-leg\" value=\"true\"/", $file_contents); - if ($file_contents != $file_contents_new) { - $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml","w"); - fwrite($fout, $file_contents_new); - fclose($fout); - if ($display_type == "text") { - echo " xml_cdr.conf.xml: updated\n"; + if ($domains_processed == 1) { + $file_contents = file_get_contents($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml"); + $file_contents_new = str_replace("param name=\"prefix-a-leg\" value=\"false\"/", "param name=\"prefix-a-leg\" value=\"true\"/", $file_contents); + if ($file_contents != $file_contents_new) { + $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml","w"); + fwrite($fout, $file_contents_new); + fclose($fout); + if ($display_type == "text") { + echo " xml_cdr.conf.xml: updated\n"; + } } } diff --git a/core/databases/app_defaults.php b/core/databases/app_defaults.php index 26c5c884a3..599792d39e 100644 --- a/core/databases/app_defaults.php +++ b/core/databases/app_defaults.php @@ -24,129 +24,131 @@ Mark J Crane */ -//set the database driver - $sql = "select * from v_databases "; - $sql .= "where database_driver is null "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $database_uuid = $row["database_uuid"]; - $database_type = $row["database_type"]; - $database_type_array = explode(":", $database_type); - if ($database_type_array[0] == "odbc") { - $database_driver = $database_type_array[1]; - } - else { - $database_driver = $database_type_array[0]; - } - $sql = "update v_databases set "; - $sql .= "database_driver = '$database_driver' "; - $sql .= "where database_uuid = '$database_uuid' "; - $db->exec(check_sql($sql)); - unset($sql); - } - -if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { - - //get the odbc information - $sql = "select count(*) as num_rows from v_databases "; - $sql .= "where database_driver = 'odbc' "; - 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) { - $odbc_num_rows = $row['num_rows']; - - $sql = "select * from v_databases "; - $sql .= "where database_driver = 'odbc' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $dsn_name = $row["database_name"]; - $dsn_username = $row["database_username"]; - $dsn_password = $row["database_password"]; - break; //limit to 1 row - } - unset ($prep_statement); +//proccess this only one time +if ($domains_processed == 1) { + //set the database driver + $sql = "select * from v_databases "; + $sql .= "where database_driver is null "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $database_uuid = $row["database_uuid"]; + $database_type = $row["database_type"]; + $database_type_array = explode(":", $database_type); + if ($database_type_array[0] == "odbc") { + $database_driver = $database_type_array[1]; } else { - $odbc_num_rows = '0'; + $database_driver = $database_type_array[0]; } + $sql = "update v_databases set "; + $sql .= "database_driver = '$database_driver' "; + $sql .= "where database_uuid = '$database_uuid' "; + $db->exec(check_sql($sql)); + unset($sql); } - //config.lua - $fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.lua","w"); - $tmp = "\n"; - $tmp .= "--switch directories\n"; - if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { - $tmp .= " sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n"; - } - if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { - $tmp .= " recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n"; - } - $tmp .= "\n"; - $tmp .= "--database connection info\n"; - if (strlen($db_type) > 0) { - $tmp .= " db_type = \"".$db_type."\";\n"; - } - if (strlen($db_name) > 0) { - $tmp .= " db_name = \"".$db_name."\";\n"; - } - if (strlen($db_path) > 0) { - $tmp .= " db_path = \"".$db_path."\";\n"; - } - if (strlen($dsn_name) > 0) { - $tmp .= " dsn_name = \"".$dsn_name."\";\n"; - } - if (strlen($dsn_username) > 0) { - $tmp .= " dsn_username = \"".$dsn_username."\";\n"; - } - if (strlen($dsn_password) > 0) { - $tmp .= " dsn_password = \"".$dsn_password."\";\n"; - } - $tmp .= "\n"; - $tmp .= "--additional info\n"; - $tmp .= " tmp_dir = \"".$tmp_dir."\";\n"; - fwrite($fout, $tmp); - unset($tmp); - fclose($fout); + if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { + //get the odbc information + $sql = "select count(*) as num_rows from v_databases "; + $sql .= "where database_driver = 'odbc' "; + 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) { + $odbc_num_rows = $row['num_rows']; - //config.js - $fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.js","w"); - $tmp = "\n"; - $tmp .= "//switch directories\n"; - $tmp .= " var admin_pin = \"".$row["admin_pin"]."\";\n"; - $tmp .= " var sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n"; - $tmp .= " var recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n"; - $tmp .= "\n"; - $tmp = "//database connection info\n"; - if (strlen($db_type) > 0) { - $tmp .= " var db_type = \"".$db_type."\";\n"; - } - if (strlen($db_name) > 0) { - $tmp .= " var db_name = \"".$db_name."\";\n"; - } - if (strlen($db_path) > 0) { - $tmp .= " var db_path = \"".$db_path."\";\n"; - } - if (strlen($dsn_name) > 0) { - $tmp .= " var dsn_name = \"".$dsn_name."\";\n"; - } - if (strlen($dsn_username) > 0) { - $tmp .= " var dsn_username = \"".$dsn_username."\";\n"; - } - if (strlen($dsn_password) > 0) { - $tmp .= " var dsn_password = \"".$dsn_password."\";\n"; - } - $tmp .= "\n"; - $tmp .= "//additional info\n"; - $tmp .= " var tmp_dir = \"".$tmp_dir."\";\n"; - fwrite($fout, $tmp); - unset($tmp); - fclose($fout); + $sql = "select * from v_databases "; + $sql .= "where database_driver = 'odbc' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $dsn_name = $row["database_name"]; + $dsn_username = $row["database_username"]; + $dsn_password = $row["database_password"]; + break; //limit to 1 row + } + unset ($prep_statement); + } + else { + $odbc_num_rows = '0'; + } + } + + //config.lua + $fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.lua","w"); + $tmp = "\n"; + $tmp .= "--switch directories\n"; + if (strlen($_SESSION['switch']['sounds']['dir']) > 0) { + $tmp .= " sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n"; + } + if (strlen($_SESSION['switch']['recordings']['dir']) > 0) { + $tmp .= " recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n"; + } + $tmp .= "\n"; + $tmp .= "--database connection info\n"; + if (strlen($db_type) > 0) { + $tmp .= " db_type = \"".$db_type."\";\n"; + } + if (strlen($db_name) > 0) { + $tmp .= " db_name = \"".$db_name."\";\n"; + } + if (strlen($db_path) > 0) { + $tmp .= " db_path = \"".$db_path."\";\n"; + } + if (strlen($dsn_name) > 0) { + $tmp .= " dsn_name = \"".$dsn_name."\";\n"; + } + if (strlen($dsn_username) > 0) { + $tmp .= " dsn_username = \"".$dsn_username."\";\n"; + } + if (strlen($dsn_password) > 0) { + $tmp .= " dsn_password = \"".$dsn_password."\";\n"; + } + $tmp .= "\n"; + $tmp .= "--additional info\n"; + $tmp .= " tmp_dir = \"".$tmp_dir."\";\n"; + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + + //config.js + $fout = fopen($_SESSION['switch']['scripts']['dir']."/resources/config.js","w"); + $tmp = "\n"; + $tmp .= "//switch directories\n"; + $tmp .= " var admin_pin = \"".$row["admin_pin"]."\";\n"; + $tmp .= " var sounds_dir = \"".$_SESSION['switch']['sounds']['dir']."\";\n"; + $tmp .= " var recordings_dir = \"".$_SESSION['switch']['recordings']['dir']."\";\n"; + $tmp .= "\n"; + $tmp = "//database connection info\n"; + if (strlen($db_type) > 0) { + $tmp .= " var db_type = \"".$db_type."\";\n"; + } + if (strlen($db_name) > 0) { + $tmp .= " var db_name = \"".$db_name."\";\n"; + } + if (strlen($db_path) > 0) { + $tmp .= " var db_path = \"".$db_path."\";\n"; + } + if (strlen($dsn_name) > 0) { + $tmp .= " var dsn_name = \"".$dsn_name."\";\n"; + } + if (strlen($dsn_username) > 0) { + $tmp .= " var dsn_username = \"".$dsn_username."\";\n"; + } + if (strlen($dsn_password) > 0) { + $tmp .= " var dsn_password = \"".$dsn_password."\";\n"; + } + $tmp .= "\n"; + $tmp .= "//additional info\n"; + $tmp .= " var tmp_dir = \"".$tmp_dir."\";\n"; + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + } } ?> \ No newline at end of file diff --git a/core/databases/database_edit.php b/core/databases/database_edit.php index 7b20d0323e..7e8c2779cd 100644 --- a/core/databases/database_edit.php +++ b/core/databases/database_edit.php @@ -163,6 +163,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { unset($sql); //set the defaults + $domains_processed = 1; require_once "app_defaults.php"; //redirect the browser diff --git a/core/default_settings/app_defaults.php b/core/default_settings/app_defaults.php index a05620f994..5ab85de6a6 100644 --- a/core/default_settings/app_defaults.php +++ b/core/default_settings/app_defaults.php @@ -25,5 +25,4 @@ */ - ?> \ No newline at end of file diff --git a/core/menu/app_defaults.php b/core/menu/app_defaults.php index 57a9ad23ec..42b164c110 100644 --- a/core/menu/app_defaults.php +++ b/core/menu/app_defaults.php @@ -25,94 +25,97 @@ */ //if there are no items in the menu then add the default menu - $sql = "SELECT count(*) as count FROM v_menus "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset ($prep_statement); - if ($sub_result['count'] > 0) { - if ($display_type == "text") { - echo " Menu: no change\n"; - } - } - else { - //create the uuid - $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286'; - //set the defaults - $menu_name = 'default'; - $menu_language = 'en'; - $menu_description = ''; - //add the menu - $sql = "insert into v_menus "; - $sql .= "("; - $sql .= "menu_uuid, "; - $sql .= "menu_name, "; - $sql .= "menu_language, "; - $sql .= "menu_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'".$menu_uuid."', "; - $sql .= "'$menu_name', "; - $sql .= "'$menu_language', "; - $sql .= "'$menu_description' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - //add the menu items - require_once "includes/classes/menu.php"; - $menu = new menu; - $menu->db = $db; - $menu->menu_uuid = $menu_uuid; - $menu->restore(); - unset($menu); + if ($domains_processed == 1) { + $sql = "SELECT count(*) as count FROM v_menus "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset ($prep_statement); + if ($sub_result['count'] > 0) { if ($display_type == "text") { - echo " Menu: added\n"; + echo " Menu: no change\n"; } + } + else { + //create the uuid + $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286'; + //set the defaults + $menu_name = 'default'; + $menu_language = 'en'; + $menu_description = ''; + //add the menu + $sql = "insert into v_menus "; + $sql .= "("; + $sql .= "menu_uuid, "; + $sql .= "menu_name, "; + $sql .= "menu_language, "; + $sql .= "menu_description "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$menu_uuid."', "; + $sql .= "'$menu_name', "; + $sql .= "'$menu_language', "; + $sql .= "'$menu_description' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + //add the menu items + require_once "includes/classes/menu.php"; + $menu = new menu; + $menu->db = $db; + $menu->menu_uuid = $menu_uuid; + $menu->restore(); + unset($menu); + if ($display_type == "text") { + echo " Menu: added\n"; + } + } + unset($prep_statement, $sub_result); } - unset($prep_statement, $sub_result); //if there are no groups listed in v_menu_item_groups then add the default groups - $sql = "SELECT * FROM v_menus "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($result); - foreach($result as $field) { - //get the menu_uuid - $menu_uuid = $field['menu_uuid']; - //check each menu to see if there are items in the menu assigned to it - $sql = ""; - $sql .= "select count(*) as count from v_menu_item_groups "; - $sql .= "where menu_uuid = '$menu_uuid' "; - $prep_statement = $db->prepare($sql); - $prep_statement->execute(); - $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); - unset ($prep_statement); - if ($sub_result['count'] == 0) { - //no menu item groups found add the defaults - foreach($apps as $app) { - foreach ($app['menu'] as $sub_row) { - foreach ($sub_row['groups'] as $group) { - //add the record - $sql = "insert into v_menu_item_groups "; - $sql .= "("; - $sql .= "menu_uuid, "; - $sql .= "menu_item_uuid, "; - $sql .= "group_name "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'$menu_uuid', "; - $sql .= "'".$sub_row['uuid']."', "; - $sql .= "'".$group."' "; - $sql .= ")"; - $db->exec($sql); - unset($sql); + if ($domains_processed == 1) { + $sql = "SELECT * FROM v_menus "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + foreach($result as $field) { + //get the menu_uuid + $menu_uuid = $field['menu_uuid']; + //check each menu to see if there are items in the menu assigned to it + $sql .= "select count(*) as count from v_menu_item_groups "; + $sql .= "where menu_uuid = '$menu_uuid' "; + $prep_statement = $db->prepare($sql); + $prep_statement->execute(); + $sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset ($prep_statement); + if ($sub_result['count'] == 0) { + //no menu item groups found add the defaults + foreach($apps as $app) { + foreach ($app['menu'] as $sub_row) { + foreach ($sub_row['groups'] as $group) { + //add the record + $sql = "insert into v_menu_item_groups "; + $sql .= "("; + $sql .= "menu_uuid, "; + $sql .= "menu_item_uuid, "; + $sql .= "group_name "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'$menu_uuid', "; + $sql .= "'".$sub_row['uuid']."', "; + $sql .= "'".$group."' "; + $sql .= ")"; + $db->exec($sql); + unset($sql); + } } } - } - } + } + } } ?> \ No newline at end of file diff --git a/core/upgrade/app_defaults.php b/core/upgrade/app_defaults.php index a2d6f2cd6f..e8a67c5c6e 100644 --- a/core/upgrade/app_defaults.php +++ b/core/upgrade/app_defaults.php @@ -27,7 +27,9 @@ if (strlen($_SESSION['switch']['scripts']['dir']) > 0) { //if the resource scripts resource directory does not exist then create it - if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) { mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true); } + if ($domains_processed == 1) { + if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) { mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true); } + } } ?> \ No newline at end of file