Explorar o código

Merge pull request #1271 from mafoo/Enhance_Install

Enhance install based on feedback
FusionPBX %!s(int64=9) %!d(string=hai) anos
pai
achega
eed6ebebe0

+ 0 - 177
core/databases/app_defaults.php

@@ -24,22 +24,6 @@
 	Mark J Crane <[email protected]>
 	Mark J Crane <[email protected]>
 */
 */
 
 
-global $IS_WINDOWS;
-
-if ($IS_WINDOWS == null) {
-	if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; }
-}
-
-if (!function_exists('correct_path')) {
-	function correct_path($p) {
-		global $IS_WINDOWS;
-		if ($IS_WINDOWS) {
-			return str_replace('/', '\\', $p);
-		}
-		return $p;
-	}
-}
-
 //proccess this only one time
 //proccess this only one time
 if ($domains_processed == 1) {
 if ($domains_processed == 1) {
 
 
@@ -66,166 +50,5 @@ if ($domains_processed == 1) {
 			unset($sql);
 			unset($sql);
 		}
 		}
 		unset($prep_statement, $result);
 		unset($prep_statement, $result);
-
-	//replace the backslash with a forward slash
-		$db_path = str_replace("\\", "/", $db_path);
-
-	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);
-				unset($prep_statement);
-				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);
-				}
-				else {
-					$odbc_num_rows = '0';
-				}
-			}
-
-		//get the recordings directory
-			if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
-				$sql = "select * from v_default_settings ";
-				$sql .= "where default_setting_category = 'switch' ";
-				$sql .= "and default_setting_subcategory = 'recordings' ";
-				$sql .= "and default_setting_name = 'dir' ";
-				$prep_statement = $db->prepare(check_sql($sql));
-				$prep_statement->execute();
-				$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-				foreach ($result as &$row) {
-					$recordings_dir = $row["default_setting_value"];
-				}
-				unset($prep_statement, $result);
-			}
-
-		//config.lua
-			if (is_dir("/etc/fusionpbx")){
-				$config = "/etc/fusionpbx/config.lua";
-			} elseif (is_dir("/usr/local/etc/fusionpbx")){
-				$config = "/usr/local/etc/fusionpbx/config.lua";
-			}
-			else {
-				$config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua";
-			}
-			$fout = fopen($config,"w");
-			if(!$fout){
-				throw new Exception("Failed to open '$config' for writing");
-			}
-			$tmp = "\n";
-			$tmp .= "--set the variables\n";
-			if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
-				$tmp .= correct_path("	sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['phrases']['dir']) > 0) {
-				$tmp .= correct_path("	phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['db']['dir']) > 0) {
-				$tmp .= correct_path("	database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
-				$tmp .= correct_path("	recordings_dir = [[".$recordings_dir."]];\n");
-			}
-			if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
-				$tmp .= correct_path("	storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
-				$tmp .= correct_path("	voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
-				$tmp .= correct_path("	scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n");
-			}
-			$tmp .= correct_path("	php_dir = [[".PHP_BINDIR."]];\n");
-			if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
-				$tmp .= "	php_bin = \"php.exe\";\n";
-			}
-			else {
-				$tmp .= "	php_bin = \"php\";\n";
-			}
-			$tmp .= correct_path("	document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
-			$tmp .= "\n";
-
-			if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) {
-				$tmp .= "--database information\n";
-				$tmp .= "	database = {}\n";
-				$tmp .= "	database[\"type\"] = \"".$db_type."\";\n";
-				$tmp .= "	database[\"name\"] = \"".$db_name."\";\n";
-				$tmp .= correct_path("	database[\"path\"] = [[".$db_path."]];\n");
-
-				if (strlen($dsn_name) > 0) {
-					$tmp .= "	database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n";
-					$tmp .= "	database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n";
-				}
-				elseif ($db_type == "pgsql") {
-					if ($db_host == "localhost") { $db_host = "127.0.0.1"; }
-					$tmp .= "	database[\"system\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=".$db_name." user=".$db_username." password=".$db_password." options='' application_name='".$db_name."'\";\n";
-					$tmp .= "	database[\"switch\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=freeswitch user=".$db_username." password=".$db_password." options='' application_name='freeswitch'\";\n";
-				}
-				elseif ($db_type == "sqlite") {
-					$tmp .= "	database[\"system\"] = \"sqlite://".$db_path."/".$db_name."\";\n";
-					$tmp .= "	database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
-				}
-				elseif ($db_type == "mysql") {
-					$tmp .= "	database[\"system\"] = \"\";\n";
-					$tmp .= "	database[\"switch\"] = \"\";\n";
-				}
-				$tmp .= "\n";
-			}
-			$tmp .= "--set defaults\n";
-			$tmp .= "	expire = {}\n";
-			$tmp .= "	expire[\"directory\"] = \"3600\";\n";
-			$tmp .= "	expire[\"dialplan\"] = \"3600\";\n";
-			$tmp .= "	expire[\"languages\"] = \"3600\";\n";
-			$tmp .= "	expire[\"sofia.conf\"] = \"3600\";\n";
-			$tmp .= "	expire[\"acl.conf\"] = \"3600\";\n";
-			$tmp .= "\n";
-			$tmp .= "--set xml_handler\n";
-			$tmp .= "	xml_handler = {}\n";
-			$tmp .= "	xml_handler[\"fs_path\"] = false;\n";
-			$tmp .= "\n";
-			$tmp .= "--set the debug options\n";
-			$tmp .= "	debug[\"params\"] = false;\n";
-			$tmp .= "	debug[\"sql\"] = false;\n";
-			$tmp .= "	debug[\"xml_request\"] = false;\n";
-			$tmp .= "	debug[\"xml_string\"] = false;\n";
-			$tmp .= "	debug[\"cache\"] = false;\n";
-			$tmp .= "\n";
-			$tmp .= "--additional info\n";
-			$tmp .= "	domain_count = ".count($_SESSION["domains"]).";\n";
-			$tmp .= correct_path("	temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n");
-			if (isset($_SESSION['domain']['dial_string']['text'])) {
-				$tmp .= "	dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
-			}
-			$tmp .= "\n";
-			$tmp .= "--include local.lua\n";
-			$tmp .= "	require(\"resources.functions.file_exists\");\n";
-			$tmp .= "	if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
-			$tmp .= "		dofile(\"/etc/fusionpbx/local.lua\");\n";
-			$tmp .= "	elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
-			$tmp .= "		dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
-			$tmp .= "	elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
-			$tmp .= "		require(\"resources.local\");\n";
-			$tmp .= "	end\n";
-			fwrite($fout, $tmp);
-			unset($tmp);
-			fclose($fout);
-	}
 }
 }
 ?>
 ?>

+ 11 - 0
core/install/app_languages.php

@@ -22,6 +22,17 @@ $text['title-detected_configuration']['uk'] = "";
 $text['title-detected_configuration']['de-at'] = "";
 $text['title-detected_configuration']['de-at'] = "";
 $text['title-detected_configuration']['ar-eg'] = "";
 $text['title-detected_configuration']['ar-eg'] = "";
 
 
+$text['title-assumed_configuration']['en-us'] = "Assumed Configuration";
+$text['title-assumed_configuration']['es-cl'] = "";
+$text['title-assumed_configuration']['pt-pt'] = "";
+$text['title-assumed_configuration']['fr-fr'] = "";
+$text['title-assumed_configuration']['pt-br'] = "";
+$text['title-assumed_configuration']['pl'] = "";
+$text['title-assumed_configuration']['sv-se'] = "";
+$text['title-assumed_configuration']['uk'] = "";
+$text['title-assumed_configuration']['de-at'] = "";
+$text['title-assumed_configuration']['ar-eg'] = "";
+
 $text['message-update']['en-us'] = "Update Completed";
 $text['message-update']['en-us'] = "Update Completed";
 $text['message-update']['es-cl'] = "Actualización Completada";
 $text['message-update']['es-cl'] = "Actualización Completada";
 $text['message-update']['pt-pt'] = "Actualização Efectuada";
 $text['message-update']['pt-pt'] = "Actualização Efectuada";

+ 13 - 13
core/install/install_first_time.php

@@ -45,6 +45,7 @@ require_once "resources/classes/text.php";
 	$db_name = '';
 	$db_name = '';
 	$db_username = '';
 	$db_username = '';
 	$db_password = '';
 	$db_password = '';
+	$db_create = '';
 	$db_create_username = '';
 	$db_create_username = '';
 	$db_create_password = '';
 	$db_create_password = '';
 
 
@@ -167,6 +168,10 @@ if(!$install_step) { $install_step = 'select_language'; }
 				"<sm>You can use the following to find what ports are allowed<pre>semanage port -l | grep '^http_port_t'</pre></sm>";
 				"<sm>You can use the following to find what ports are allowed<pre>semanage port -l | grep '^http_port_t'</pre></sm>";
 			}
 			}
 		}
 		}
+	//test for windows and non sqlite
+		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' and strlen($db_type) > 0 and $db_type !='sqlite') {
+			$messages[] = "<b>Windows requires a system DSN ODBC connection</b> this must be configured after installing then restart freeswitch.";
+		}
 
 
 	//action code
 	//action code
 	if($return_install_step == 'config_detail'){
 	if($return_install_step == 'config_detail'){
@@ -262,10 +267,10 @@ if(!$install_step) { $install_step = 'select_language'; }
 		//if($_SERVER['HTTPS']) { $protocol = 'https'; }
 		//if($_SERVER['HTTPS']) { $protocol = 'https'; }
 		//echo "<iframe src='$protocol://$domain_name/core/install/install_first_time.php' style='border:solid 1px #000;width:100%;height:auto'></iframe>";
 		//echo "<iframe src='$protocol://$domain_name/core/install/install_first_time.php' style='border:solid 1px #000;width:100%;height:auto'></iframe>";
 		require_once "core/install/resources/classes/detect_switch.php";
 		require_once "core/install/resources/classes/detect_switch.php";
-		$switch_detect = new detect_switch($event_host, $event_port, $event_password);
+		$detect_switch = new detect_switch($event_host, $event_port, $event_password);
 		$detect_ok = true;
 		$detect_ok = true;
 		try {
 		try {
-			$switch_detect->detect();
+			$detect_switch->detect();
 		} catch(Exception $e){
 		} catch(Exception $e){
 			echo "<p>Failed to detect configuration detect_switch reported: " . $e->getMessage() . "</p>\n";
 			echo "<p>Failed to detect configuration detect_switch reported: " . $e->getMessage() . "</p>\n";
 			$detect_ok = false;
 			$detect_ok = false;
@@ -289,34 +294,29 @@ if(!$install_step) { $install_step = 'select_language'; }
 			}
 			}
 			#set_error_handler("error_handler");
 			#set_error_handler("error_handler");
 			try {
 			try {
+				require_once "resources/classes/global_settings.php";
+				$global_settings = new global_settings($detect_switch, $domain_name);
+				if(is_null($global_settings)){ throw new Exception("Error global_settings came back with null");	}
 				require_once "resources/classes/install_fusionpbx.php";
 				require_once "resources/classes/install_fusionpbx.php";
-				$system = new install_fusionpbx($domain_name, null, $switch_detect);
-				$domain_uuid = $system->domain_uuid();
+				$system = new install_fusionpbx($global_settings);
 				$system->admin_username = $admin_username;
 				$system->admin_username = $admin_username;
 				$system->admin_password = $admin_password;
 				$system->admin_password = $admin_password;
 				$system->default_country = $install_default_country;
 				$system->default_country = $install_default_country;
 				$system->install_language = $install_language;
 				$system->install_language = $install_language;
 				$system->template_name = $install_template_name;
 				$system->template_name = $install_template_name;
-				foreach($_POST as $key=>$value){
-					if(substr($key,0,3) == "db_"){
-						$system->$key = $value;
-					}
-				}
 
 
 				require_once "resources/classes/install_switch.php";
 				require_once "resources/classes/install_switch.php";
-				$switch = new install_switch($domain_name, $domain_uuid, $switch_detect);
+				$switch = new install_switch($global_settings);
 				//$switch->debug = true;
 				//$switch->debug = true;
 				//$system->debug = true;
 				//$system->debug = true;
 				$system->install();
 				$system->install();
 				$switch->install();
 				$switch->install();
-				$system->app_defaults();
-				$switch_detect->restart_switch();
 			}catch(Exception $e){
 			}catch(Exception $e){
 				echo "</pre>\n";
 				echo "</pre>\n";
 				echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
 				echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
 				try {
 				try {
 					require_once "resources/classes/install_fusionpbx.php";
 					require_once "resources/classes/install_fusionpbx.php";
-					$system = new install_fusionpbx($domain_name, $domain_uuid, $switch_detect);
+					$system = new install_fusionpbx($global_settings);
 					$system->remove_config();
 					$system->remove_config();
 				}catch(Exception $e){
 				}catch(Exception $e){
 					echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";
 					echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";

+ 59 - 32
core/install/resources/classes/detect_switch.php

@@ -31,12 +31,21 @@ require_once "resources/classes/EventSocket.php";
 	class detect_switch {
 	class detect_switch {
 
 
 		// cached data
 		// cached data
-		protected $_folders;
+		protected $_dirs;
+		protected $_vdirs;
+		public function get_dirs()	{ return $this->_dirs; }
+		public function get_vdirs()	{ return $this->_vdirs; }
+
 		// version information
 		// version information
 		protected $_major;
 		protected $_major;
 		protected $_minor;
 		protected $_minor;
+		protected $_build;
+		public function major()		{ return $this->_major; }
+		public function minor()		{ return $this->_minor; }
+		public function build()		{ return $this->_build; }
+		public function version()	{ return $this->_major.".".$this->_minor.".".$this->_build; }
 
 
-		// folders
+		// dirs - detected by from the switch
 		protected $_base_dir = '';
 		protected $_base_dir = '';
 		protected $_cache_dir = '';
 		protected $_cache_dir = '';
 		protected $_certs_dir = '';
 		protected $_certs_dir = '';
@@ -54,28 +63,37 @@ require_once "resources/classes/EventSocket.php";
 		protected $_sounds_dir = '';
 		protected $_sounds_dir = '';
 		protected $_storage_dir = '';
 		protected $_storage_dir = '';
 		protected $_temp_dir = '';
 		protected $_temp_dir = '';
-		
-		public function major() { return $this->_major; }
-		public function minor() { return $this->_minor; }
-		public function version() { return $this->_major.".".$this->_minor; }
-		public function base_dir() { return $this->_base_dir; }
-		public function cache_dir() { return $this->_cache_dir; }
-		public function certs_dir() { return $this->_certs_dir; }
-		public function conf_dir() { return $this->_conf_dir; }
-		public function db_dir() { return $this->_db_dir; }
-		public function external_ssl_dir() { return $this->_external_ssl_dir; }
-		public function grammar_dir() { return $this->_grammar_dir; }
-		public function htdocs_dir() { return $this->_htdocs_dir; }
-		public function internal_ssl_dir() { return $this->_internal_ssl_dir; }
-		public function log_dir() { return $this->_log_dir; }
-		public function mod_dir() { return $this->_mod_dir; }
-		public function recordings_dir() { return $this->_recordings_dir; }
-		public function run_dir() { return $this->_run_dir; }
-		public function script_dir() { return $this->_script_dir; }
-		public function sounds_dir() { return $this->_sounds_dir; }
-		public function storage_dir() { return $this->_storage_dir; }
-		public function temp_dir() { return $this->_temp_dir; }
-		public function get_folders() {	return $this->_folders;	}
+		public function base_dir()			{ return $this->_base_dir; }
+		public function cache_dir()			{ return $this->_cache_dir; }
+		public function certs_dir()			{ return $this->_certs_dir; }
+		public function conf_dir()			{ return $this->_conf_dir; }
+		public function db_dir()			{ return $this->_db_dir; }
+		public function external_ssl_dir()	{ return $this->_external_ssl_dir; }
+		public function grammar_dir()		{ return $this->_grammar_dir; }
+		public function htdocs_dir()		{ return $this->_htdocs_dir; }
+		public function internal_ssl_dir()	{ return $this->_internal_ssl_dir; }
+		public function log_dir()			{ return $this->_log_dir; }
+		public function mod_dir()			{ return $this->_mod_dir; }
+		public function recordings_dir()	{ return $this->_recordings_dir; }
+		public function run_dir()			{ return $this->_run_dir; }
+		public function script_dir()		{ return $this->_script_dir; }
+		public function sounds_dir()		{ return $this->_sounds_dir; }
+		public function storage_dir()		{ return $this->_storage_dir; }
+		public function temp_dir()			{ return $this->_temp_dir; }
+
+		// virtual dirs - assumed based on the detected dirs
+		protected $_voicemail_vdir = '';
+		protected $_phrases_vdir = '';
+		protected $_extensions_vdir = '';
+		protected $_sip_profiles_vdir = '';
+		protected $_dialplan_vdir = '';
+		protected $_backup_vdir = '';
+		public function voicemail_vdir()	{ return $this->_voicemail_vdir; }
+		public function phrases_vdir()		{ return $this->_phrases_vdir; }
+		public function extensions_vdir()	{ return $this->_extensions_vdir; }
+		public function sip_profiles_vdir()	{ return $this->_sip_profiles_vdir; }
+		public function dialplan_vdir()		{ return $this->_dialplan_vdir; }
+		public function backup_vdir()		{ return $this->_backup_vdir; }
 
 
 		// event socket
 		// event socket
 		public $event_host = 'localhost';
 		public $event_host = 'localhost';
@@ -84,6 +102,7 @@ require_once "resources/classes/EventSocket.php";
 		protected $event_socket;
 		protected $event_socket;
 
 
 		public function __construct($event_host, $event_port, $event_password) {
 		public function __construct($event_host, $event_port, $event_password) {
+			//do not take these settings from session as they be detecting a new switch
 			if($event_host){		$this->event_host = $event_host; }
 			if($event_host){		$this->event_host = $event_host; }
 			if($event_port){		$this->event_port = $event_port; }
 			if($event_port){		$this->event_port = $event_port; }
 			if($event_password){	$this->event_password = $event_password; }
 			if($event_password){	$this->event_password = $event_password; }
@@ -91,33 +110,41 @@ require_once "resources/classes/EventSocket.php";
 			if(!$this->event_socket){
 			if(!$this->event_socket){
 				$this->detect_event_socket();
 				$this->detect_event_socket();
 			}
 			}
-			$this->_folders = preg_grep ('/.*_dir$/', get_class_methods('detect_switch') );
-			sort( $this->_folders );
+			$this->_dirs = preg_grep ('/.*_dir$/', get_class_methods('detect_switch') );
+			sort( $this->_dirs );
+			$this->_vdirs = preg_grep ('/.*_vdir$/', get_class_methods('detect_switch') );
+			sort( $this->_vdirs );
 		}
 		}
-		
+
 		protected function detect_event_socket() {
 		protected function detect_event_socket() {
 			//perform searches for user's config here
 			//perform searches for user's config here
 		}
 		}
-		
+
 		public function detect() {
 		public function detect() {
 			$this->connect_event_socket();
 			$this->connect_event_socket();
 			if(!$this->event_socket){
 			if(!$this->event_socket){
 				throw new Exception('Failed to use event socket');
 				throw new Exception('Failed to use event socket');
 			}
 			}
 			$FS_Version = $this->event_socket_request('api version');
 			$FS_Version = $this->event_socket_request('api version');
-			preg_match("/FreeSWITCH Version (\d+)\.(\d(?:\.\d+)?)/", $FS_Version, $matches);
+			preg_match("/FreeSWITCH Version (\d+)\.(\d+)\.(\d+(?:\.\d+)?)/", $FS_Version, $matches);
 			$this->_major = $matches[1];
 			$this->_major = $matches[1];
 			$this->_minor = $matches[2];
 			$this->_minor = $matches[2];
+			$this->_build = $matches[3];
 			$FS_Vars = $this->event_socket_request('api global_getvar');
 			$FS_Vars = $this->event_socket_request('api global_getvar');
 			foreach (explode("\n",$FS_Vars) as $FS_Var){
 			foreach (explode("\n",$FS_Vars) as $FS_Var){
 				preg_match("/(\w+_dir)=(.*)/", $FS_Var, $matches);
 				preg_match("/(\w+_dir)=(.*)/", $FS_Var, $matches);
 				if(count($matches) > 0 and property_exists($this, "_" . $matches[1])){
 				if(count($matches) > 0 and property_exists($this, "_" . $matches[1])){
 					$field = "_" . $matches[1];
 					$field = "_" . $matches[1];
-					$this->$field = $matches[2];
+					$this->$field = normalize_path($matches[2]);
 				}
 				}
 			}
 			}
-		}
-		
+			$this->_voicemail_vdir = 	normalize_path($this->_storage_dir . DIRECTORY_SEPARATOR . "voicemail");
+			$this->_phrases_vdir = 		normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "lang");
+			$this->_extensions_vdir = 	normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "directory");
+			$this->_sip_profiles_vdir =	normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "sip_profiles");
+			$this->_dialplan_vdir =		normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "dialplan");
+			$this->_backup_vdir =		normalize_path(sys_get_temp_dir());
+		}	
 	
 	
 		protected function connect_event_socket(){
 		protected function connect_event_socket(){
 			$esl = new EventSocket;
 			$esl = new EventSocket;

+ 219 - 0
core/install/resources/classes/global_settings.php

@@ -0,0 +1,219 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2010-2015
+	All Rights Reserved.
+
+	Contributor(s):
+	Matthew Vale <[email protected]>
+	
+*/
+require_once "root.php";
+
+//define the install class
+	class global_settings {
+
+		// cached data
+		protected $_switch_dirs;
+		protected $_switch_vdirs;
+		public function get_switch_dirs()	{ return $this->_switch_dirs; }
+		public function get_switch_vdirs()	{ return $this->_switch_vdirs; }
+
+		// dirs - detected by from the switch
+		protected $_switch_base_dir = '';
+		protected $_switch_cache_dir = '';
+		protected $_switch_certs_dir = '';
+		protected $_switch_conf_dir = '';
+		protected $_switch_db_dir = '';
+		protected $_switch_external_ssl_dir = '';
+		protected $_switch_grammar_dir = '';
+		protected $_switch_htdocs_dir = '';
+		protected $_switch_internal_ssl_dir = '';
+		protected $_switch_log_dir = '';
+		protected $_switch_mod_dir = '';
+		protected $_switch_recordings_dir = '';
+		protected $_switch_run_dir = '';
+		protected $_switch_script_dir = '';
+		protected $_switch_sounds_dir = '';
+		protected $_switch_storage_dir = '';
+		protected $_switch_temp_dir = '';
+		public function switch_base_dir()			{ return $this->_switch_base_dir; }
+		public function switch_cache_dir()			{ return $this->_switch_cache_dir; }
+		public function switch_certs_dir()			{ return $this->_switch_certs_dir; }
+		public function switch_conf_dir()			{ return $this->_switch_conf_dir; }
+		public function switch_db_dir()				{ return $this->_switch_db_dir; }
+		public function switch_external_ssl_dir()	{ return $this->_switch_external_ssl_dir; }
+		public function switch_grammar_dir()		{ return $this->_switch_grammar_dir; }
+		public function switch_htdocs_dir()			{ return $this->_switch_htdocs_dir; }
+		public function switch_internal_ssl_dir()	{ return $this->_switch_internal_ssl_dir; }
+		public function switch_log_dir()			{ return $this->_switch_log_dir; }
+		public function switch_mod_dir()			{ return $this->_switch_mod_dir; }
+		public function switch_recordings_dir()		{ return $this->_switch_recordings_dir; }
+		public function switch_run_dir()			{ return $this->_switch_run_dir; }
+		public function switch_script_dir()			{ return $this->_switch_script_dir; }
+		public function switch_sounds_dir()			{ return $this->_switch_sounds_dir; }
+		public function switch_storage_dir()		{ return $this->_switch_storage_dir; }
+		public function switch_temp_dir()			{ return $this->_switch_temp_dir; }
+
+		// virtual dirs - assumed based on the detected dirs
+		protected $_switch_voicemail_vdir = '';
+		protected $_switch_phrases_vdir = '';
+		protected $_switch_extensions_vdir = '';
+		protected $_switch_sip_profiles_vdir = '';
+		protected $_switch_dialplan_vdir = '';
+		protected $_switch_backup_vdir = '';
+		public function switch_voicemail_vdir()		{ return $this->_switch_voicemail_vdir; }
+		public function switch_phrases_vdir()		{ return $this->_switch_phrases_vdir; }
+		public function switch_extensions_vdir()	{ return $this->_switch_extensions_vdir; }
+		public function switch_sip_profiles_vdir()	{ return $this->_switch_sip_profiles_vdir; }
+		public function switch_dialplan_vdir()		{ return $this->_switch_dialplan_vdir; }
+		public function switch_backup_vdir()		{ return $this->_switch_backup_vdir; }
+
+		// event socket
+		protected $_switch_event_host;
+		protected $_switch_event_port;
+		protected $_switch_event_password;
+		public function switch_event_host()		{ return $this->_switch_event_host; }
+		public function switch_event_port()		{ return $this->_switch_event_port; }
+		public function switch_event_password()	{ return $this->_switch_event_password; }
+
+		// database information
+		protected $_db_type;
+		protected $_db_path;
+		protected $_db_host;
+		protected $_db_port;
+		protected $_db_name;
+		protected $_db_username;
+		protected $_db_password;
+		protected $_db_create;
+		protected $_db_create_username;
+		protected $_db_create_password;
+		public function db_type()	 			{ return $this->_db_type; }
+		public function db_path()	 			{ return $this->_db_path; }
+		public function db_host()	 			{ return $this->_db_host; }
+		public function db_port()	 			{ return $this->_db_port; }
+		public function db_name()	 			{ return $this->_db_name; }
+		public function db_username()	 		{ return $this->_db_username; }
+		public function db_password()	 		{ return $this->_db_password; }
+		public function db_create()	 			{ return $this->_db_create; }
+		public function db_create_username()	{ return $this->_db_create_username; }
+		public function db_create_password()	{ return $this->_db_create_password; }
+
+		//misc information
+		protected $_domain_uuid;
+		protected $_domain_name;
+		protected $_domain_count;
+		public function domain_uuid()	 		{ return $this->_domain_uuid; }
+		public function domain_name()	 		{ return $this->_domain_name; }
+		public function domain_count()	 		{ return $this->_domain_count; }
+		public function set_domain_uuid($domain_uuid) {
+			$e = new Exception();
+			$trace = $e->getTrace();
+			if($trace[1]['function'] != 'create_domain'){
+				throw new Exception('Only create_domain is allowed to update the domain_uuid');
+			}
+			$this->_domain_uuid = $domain_uuid;
+		}
+
+		public function __construct($detect_switch = null, $domain_name = null, $domain_uuid = null) {
+			$this->_switch_dirs = preg_grep ('/^switch_.*_dir$/', get_class_methods('global_settings') );
+			sort( $this->_switch_dirs );
+			$this->_switch_vdirs = preg_grep ('/^switch_.*_vdir$/', get_class_methods('global_settings') );
+			sort( $this->_switch_vdirs );
+			if(is_null($detect_switch)){
+				//take settings from session
+				if(!isset($_SESSION['switch'])){
+					throw new Exception("No detect_switch was passed to me but \$_SESSION['switch'] is empty!");
+				}
+				foreach ($this->_switch_dirs as $dir){
+					$session_var;
+					preg_match( '/^switch_(.*)_dir$/', $dir, $session_var);
+					$dir = "_$dir";
+					if($session_var[1] == 'script'){ $session_var[1] = 'scripts'; }
+					$this->$dir = $_SESSION['switch'][$session_var[1]]['dir'];
+				}
+				foreach ($this->_switch_vdirs as $vdir){
+					$session_var;
+					preg_match( '/^switch_(.*)_vdir$/', $vdir, $session_var);
+					$vdir = "_$vdir";
+					$this->$vdir = $_SESSION['switch'][$session_var[1]]['dir'];
+				}
+				$this->_switch_event_host		= $_SESSION['event_socket_ip_address'];
+				$this->_switch_event_port		= $_SESSION['event_socket_port'];
+				$this->_switch_event_password	= $_SESSION['event_socket_password'];
+				
+				// domain info
+				$this->_domain_name = $_SESSION['domain_name'];
+				$this->_domain_uuid = $_SESSION['domain_uuid'];
+
+				// collect misc info
+				$this->domain_count = count($_SESSION["domains"]);
+
+				// collect db_info
+				global $db_type, $db_path, $db_host, $db_port, $db_name, $db_username, $db_password;
+				$this->_db_type = $db_type;
+				$this->_db_path = $db_path;
+				$this->_db_host = $db_host;
+				$this->_db_port = $db_port;
+				$this->_db_name = $db_name;
+				$this->_db_username = $db_username;
+				$this->_db_password = $db_password;
+
+			}elseif(!is_a($detect_switch, 'detect_switch')){
+				throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
+
+			}else{
+				//copy from detect_switch
+				foreach($detect_switch->get_dirs() as $dir){
+					$t_dir = "_switch_$dir";
+					$this->$t_dir = $detect_switch->$dir();
+				}
+				foreach($detect_switch->get_vdirs() as $vdir){
+					$t_vdir = "_switch_$vdir";
+					$this->$t_vdir = $detect_switch->$vdir();
+				}
+				$this->_switch_event_host		= $detect_switch->event_host;
+				$this->_switch_event_port		= $detect_switch->event_port;
+				$this->_switch_event_password	= $detect_switch->event_password;
+
+				//copy from _POST
+				foreach($_POST as $key=>$value){
+					if(substr($key,0,3) == "db_"){
+						$o_key = "_$key";
+						$this->$o_key = $value;
+					}
+				}
+				if($this->_db_create and strlen($this->_db_create_username) == 0)
+				{
+					$this->_db_create_username = $this->_db_username;
+					$this->_db_create_password = $this->_db_password;
+				}
+				if (strlen($this->_db_port) == 0) { $this->_db_port = "5432"; }
+
+				// domain info
+				if(strlen($domain_uuid) == 0){ $domain_uuid = uuid(); }
+				$this->_domain_name = $domain_name;
+				$this->_domain_uuid = $domain_uuid;
+
+				//collect misc info
+				$this->_domain_count = 1;	//assumed to be one
+			}
+		}
+	}
+?>

+ 331 - 285
core/install/resources/classes/install_fusionpbx.php

@@ -29,40 +29,27 @@ include "root.php";
 //define the install class
 //define the install class
 	class install_fusionpbx {
 	class install_fusionpbx {
 
 
-		protected $_domain_uuid;
-		protected $domain_name;
-		protected $detect_switch;
+		protected $global_settings;
 		protected $config_php;
 		protected $config_php;
 		protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
 		protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
 		protected $dbh;
 		protected $dbh;
 
 
-		public function domain_uuid() { return $this->_domain_uuid; }
-
 		public $debug = false;
 		public $debug = false;
 
 
-	 	public $install_msg;
 	 	public $install_language = 'en-us';
 	 	public $install_language = 'en-us';
 	 	public $admin_username;
 	 	public $admin_username;
 	 	public $admin_password;
 	 	public $admin_password;
 	 	public $default_country = 'US';
 	 	public $default_country = 'US';
 		public $template_name = 'enhanced';
 		public $template_name = 'enhanced';
 
 
-	 	public $db_type;
-		public $db_path;
-		public $db_host;
-		public $db_port;
-		public $db_name;
-		public $db_username;
-		public $db_password;
-
-	 	function __construct($domain_name, $domain_uuid, $detect_switch) {
-			if(!is_a($detect_switch, 'detect_switch')){
-				throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
+	 	function __construct($global_settings) {
+			if(is_null($global_settings)){
+				require_once "resources/classes/global_settings.php";
+				$global_settings = new global_settings();
+			}elseif(!is_a($global_settings, 'global_settings')){
+				throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
 			}
 			}
-			if($domain_uuid == null){ $domain_uuid = uuid(); }
-			$this->_domain_uuid = $domain_uuid;
-			$this->domain_name = $domain_name;
-			$this->detect_switch = $detect_switch;
+			$this->global_settings = $global_settings;
 			if (is_dir("/etc/fusionpbx")){
 			if (is_dir("/etc/fusionpbx")){
 				$this->config_php = "/etc/fusionpbx/config.php";
 				$this->config_php = "/etc/fusionpbx/config.php";
 			} elseif (is_dir("/usr/local/etc/fusionpbx")){
 			} elseif (is_dir("/usr/local/etc/fusionpbx")){
@@ -74,6 +61,7 @@ include "root.php";
 			else {
 			else {
 				$this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
 				$this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
 			}
 			}
+			$this->config_php = normalize_path_to_os($this->config_php);
 		}
 		}
 
 
 		function write_debug($message) {
 		function write_debug($message) {
@@ -88,15 +76,28 @@ include "root.php";
 
 
 		function install() {
 		function install() {
 			ini_set('max_execution_time',3600);
 			ini_set('max_execution_time',3600);
+			$this->write_progress("Install started for FusionPBX");
 			$this->create_config_php();
 			$this->create_config_php();
+			$this->write_progress("\tExecuting config.php");
+			require $this->config_php;
+			global $db;
+			$db = $this->dbh;
 			$this->create_database();
 			$this->create_database();
 			$this->create_domain();
 			$this->create_domain();
 			$this->create_superuser();
 			$this->create_superuser();
+			$this->write_progress("\tRunning requires");
 			require "resources/require.php";
 			require "resources/require.php";
 			$this->create_menus();
 			$this->create_menus();
+			$this->app_defaults();
+			$this->write_progress("Install complete for FusionPBX");
+		}
+		
+		function upgrade() {
+			$this->app_defaults();
 		}
 		}
 
 
 		protected function create_config_php() {
 		protected function create_config_php() {
+			$this->write_progress("\tCreating " . $this->config_php);
 			$tmp_config = "<?php\n";
 			$tmp_config = "<?php\n";
 			$tmp_config .= "/* \$Id\$ */\n";
 			$tmp_config .= "/* \$Id\$ */\n";
 			$tmp_config .= "/*\n";
 			$tmp_config .= "/*\n";
@@ -131,26 +132,27 @@ include "root.php";
 			$tmp_config .= "//-----------------------------------------------------\n";
 			$tmp_config .= "//-----------------------------------------------------\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "	//set the database type\n";
 			$tmp_config .= "	//set the database type\n";
-			$tmp_config .= "		\$db_type = '".$this->db_type."'; //sqlite, mysql, pgsql, others with a manually created PDO connection\n";
+			$tmp_config .= "		\$db_type = '".$this->global_settings->db_type()."'; //sqlite, mysql, pgsql, others with a manually created PDO connection\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "\n";
-			if ($this->db_type == "sqlite") {
+			if ($this->global_settings->db_type() == "sqlite") {
 				$tmp_config .= "	//sqlite: the db_name and db_path are automatically assigned however the values can be overidden by setting the values here.\n";
 				$tmp_config .= "	//sqlite: the db_name and db_path are automatically assigned however the values can be overidden by setting the values here.\n";
-				$tmp_config .= "		\$db_name = '".$this->db_name."'; //host name/ip address + '.db' is the default database filename\n";
-				$tmp_config .= "		\$db_path = '".$this->db_path."'; //the path is determined by a php variable\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."'; //host name/ip address + '.db' is the default database filename\n";
+				$tmp_config .= "		\$db_path = '".$this->global_settings->db_path()."'; //the path is determined by a php variable\n";
 			}
 			}
 			$tmp_config .= "\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "	//mysql: database connection information\n";
 			$tmp_config .= "	//mysql: database connection information\n";
-			if ($this->db_type == "mysql") {
-				if ($this->db_host == "localhost") {
+			if ($this->global_settings->db_type() == "mysql") {
+				$db_host = $this->global_settings->db_host();
+				if ( $db_host == "localhost") {
 					//if localhost is used it defaults to a Unix Socket which doesn't seem to work.
 					//if localhost is used it defaults to a Unix Socket which doesn't seem to work.
 					//replace localhost with 127.0.0.1 so that it will connect using TCP
 					//replace localhost with 127.0.0.1 so that it will connect using TCP
-					$this->db_host = "127.0.0.1";
+					$db_host = "127.0.0.1";
 				}
 				}
-				$tmp_config .= "		\$db_host = '".$this->db_host."';\n";
-				$tmp_config .= "		\$db_port = '".$this->db_port."';\n";
-				$tmp_config .= "		\$db_name = '".$this->db_name."';\n";
-				$tmp_config .= "		\$db_username = '".$this->db_username."';\n";
-				$tmp_config .= "		\$db_password = '".$this->db_password."';\n";
+				$tmp_config .= "		\$db_host = '".$db_host."';\n";
+				$tmp_config .= "		\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		\$db_password = '".$this->global_settings->db_password()."';\n";
 			}
 			}
 			else {
 			else {
 				$tmp_config .= "		//\$db_host = '';\n";
 				$tmp_config .= "		//\$db_host = '';\n";
@@ -161,19 +163,21 @@ include "root.php";
 			}
 			}
 			$tmp_config .= "\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "	//pgsql: database connection information\n";
 			$tmp_config .= "	//pgsql: database connection information\n";
-			if ($this->db_type == "pgsql") {
-				$tmp_config .= "		\$db_host = '".$this->db_host."'; //set the host only if the database is not local\n";
-				$tmp_config .= "		\$db_port = '".$this->db_port."';\n";
-				$tmp_config .= "		\$db_name = '".$this->db_name."';\n";
-				$tmp_config .= "		\$db_username = '".$this->db_username."';\n";
-				$tmp_config .= "		\$db_password = '".$this->db_password."';\n";
+			if ($this->global_settings->db_type() == "pgsql") {
+				$cmt_out = '';
+				if($this->global_settings->db_host() != 'localhost') { $cmt_out = "//"; }
+				$tmp_config .= "		$cmt_out\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n";
+				$tmp_config .= "		\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		\$db_password = '".$this->global_settings->db_password()."';\n";
 			}
 			}
 			else {
 			else {
-				$tmp_config .= "		//\$db_host = '".$this->db_host."'; //set the host only if the database is not local\n";
-				$tmp_config .= "		//\$db_port = '".$this->db_port."';\n";
-				$tmp_config .= "		//\$db_name = '".$this->db_name."';\n";
-				$tmp_config .= "		//\$db_username = '".$this->db_username."';\n";
-				$tmp_config .= "		//\$db_password = '".$this->db_password."';\n";
+				$tmp_config .= "		//\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n";
+				$tmp_config .= "		//\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		//\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		//\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		//\$db_password = '".$this->global_settings->db_password()."';\n";
 			}
 			}
 			$tmp_config .= "\n";
 			$tmp_config .= "\n";
 			$tmp_config .= "	//show errors\n";
 			$tmp_config .= "	//show errors\n";
@@ -190,7 +194,6 @@ include "root.php";
 				) {
 				) {
 				throw new Exception("cannot write to '" . $this->config_php . "'" );
 				throw new Exception("cannot write to '" . $this->config_php . "'" );
 			}
 			}
-			$this->write_progress("Creating " . $this->config_php);
 			$fout = fopen($this->config_php,"w");
 			$fout = fopen($this->config_php,"w");
 			fwrite($fout, $tmp_config);
 			fwrite($fout, $tmp_config);
 			unset($tmp_config);
 			unset($tmp_config);
@@ -198,255 +201,283 @@ include "root.php";
 		}
 		}
 
 
 		protected function create_database() {
 		protected function create_database() {
-			require $this->config_php;
-			$this->write_progress("Creating database as " . $this->db_type);
-			$function = "create_database_" . $this->db_type;
+			$this->write_progress("\tUsing database as type " . $this->global_settings->db_type());
+			$function = "create_database_" . $this->global_settings->db_type();
 			$this->$function();
 			$this->$function();
-			global $db;
-			$db = $this->dbh;
+
+			//sqlite is natively supported under all known OS'es
+			if($this->global_settings->db_type() != 'sqlite'){
+				if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
+				//non sqlite database support only uses ODBC under windows
+					$this->create_odbc_database_connection();
+				}elseif($this->global_settings->db_type() != 'pgsql'){
+				//switch supports postgresql natively
+					$this->create_odbc_database_connection();
+				}
+			}
+		}
+		
+		protected function create_odbc_database_connection() {
+		//needed for non native database support
+				$database_uuid = uuid();
+				$sql = "insert into v_databases ";
+				$sql .= "(";
+				$sql .= "database_uuid, ";
+				$sql .= "database_driver, ";
+				$sql .= "database_type, ";
+				$sql .= "database_host, ";
+				$sql .= "database_port, ";
+				$sql .= "database_name, ";
+				$sql .= "database_username, ";
+				$sql .= "database_password, ";
+				$sql .= "database_path, ";
+				$sql .= "database_description ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'$database_uuid', ";
+				$sql .= "'odbc', ";
+				$sql .= "'".$this->global_settings->db_type()."', ";
+				$sql .= "'".$this->global_settings->db_host()."', ";
+				$sql .= "'".$this->global_settings->db_port()."', ";
+				$sql .= "'".$this->global_settings->db_name()."', ";
+				$sql .= "'".$this->global_settings->db_username()."', ";
+				$sql .= "'".$this->global_settings->db_password()."', ";
+				$sql .= "'".$this->global_settings->db_path()."', ";
+				$sql .= "'Created by installer' ";
+				$sql .= ")";
+				if($this->dbh->exec(check_sql($sql)) === false){
+					throw new Exception("Failed to create odbc_database entery: " . join(":", $this->dbh->errorInfo()));
+				}
+				unset($sql);
 		}
 		}
 
 
 		protected function create_database_sqlite() {
 		protected function create_database_sqlite() {
-			//sqlite database will be created when the config.php is loaded and only if the database file does not exist
+		//sqlite database will be created when the config.php is loaded and only if the database file does not exist
+			try {
+				$this->dbh = new PDO('sqlite:'.$this->global_settings->db_path().'/'.$this->global_settings->db_name()); //sqlite 3
+				//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
+			}
+			catch (PDOException $error) {
+				throw Exception("Failed to create database: " . $error->getMessage());
+			}
+
+		//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
+			if (!function_exists('php_now')) {
+				function php_now() {
+					if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
+						@date_default_timezone_set(@date_default_timezone_get());
+					}
+					return date("Y-m-d H:i:s");
+				}
+			}
+			$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
+
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->global_settings->db_type();
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
+			}
+			else {
+				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
+			}
+			$file_contents = file_get_contents($filename);
+			unset($filename);
+
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
+
+		//loop line by line through all the lines of sql code
+			$this->dbh->beginTransaction();
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
 				try {
 				try {
-					$this->dbh = new PDO('sqlite:'.$this->db_path.'/'.$this->db_name); //sqlite 3
-					//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
+					$this->dbh->query($sql);
 				}
 				}
 				catch (PDOException $error) {
 				catch (PDOException $error) {
-					throw Exception("Failed to create database: " . $error->getMessage());
+							throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
 				}
 				}
+				$x++;
+			}
+			unset ($file_contents, $sql);
+			$this->dbh->commit();
 
 
-			//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
-				if (!function_exists('php_now')) {
-					function php_now() {
-						if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
-							@date_default_timezone_set(@date_default_timezone_get());
-						}
-						return date("Y-m-d H:i:s");
+		//set the file permissions
+			chmod($this->global_settings->db_path().'/'.$this->global_settings->db_name(), 0777);
+		}
+
+		protected function create_database_pgsql() {
+			if ($this->global_settings->db_create()) {
+			//Attempt to create new PG role and database
+				$this->write_progress("\tCreating database");
+				try {
+					if (strlen($this->global_settings->db_host()) > 0) {
+						$this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1");
+					} else {
+						$this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1");
 					}
 					}
+				} catch (PDOException $error) {
+					throw new Exception("error connecting to database in order to create: " . $error->getMessage());
 				}
 				}
-				$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
-
-			//add the database structure
-				require_once "resources/classes/schema.php";
-				$schema = new schema;
-				$schema->db = $this->dbh;
-				$schema->db_type = $this->db_type;
-				$schema->sql();
-				$schema->exec();
-
-			//get the contents of the sql file
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
-					$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
-				}
-				else {
-					$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
-				}
-				$file_contents = file_get_contents($filename);
-				unset($filename);
-
-			//replace \r\n with \n then explode on \n
-				$file_contents = str_replace("\r\n", "\n", $file_contents);
 
 
-			//loop line by line through all the lines of sql code
-				$this->dbh->beginTransaction();
-				$string_array = explode("\n", $file_contents);
-				$x = 0;
-				foreach($string_array as $sql) {
-					try {
-						$this->dbh->query($sql);
+				//create the database, user, grant perms
+				if($this->dbh->exec("CREATE DATABASE {$this->global_settings->db_name()}") === false) {
+					throw new Exception("Failed to create database {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
+				}
+				if($this->global_settings->db_username() != $this->global_settings->db_create_username()){
+					if($this->dbh->exec("CREATE USER {$this->global_settings->db_username()} WITH PASSWORD '{$this->global_settings->db_password()}'") === false){
+						throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
 					}
 					}
-					catch (PDOException $error) {
-								throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
+					if($this->dbh->exec("GRANT ALL ON {$this->global_settings->db_name()} TO {$this->global_settings->db_username()}") === false){
+						throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
 					}
 					}
-					$x++;
 				}
 				}
-				unset ($file_contents, $sql);
-				$this->dbh->commit();
 
 
-			//set the file permissions
-				chmod($this->db_path.'/'.$this->db_name, 0777);
-		}
+				//close database connection_aborted
+				$this->dbh = null;
+			}
 
 
-		protected function create_database_pgsql() {
+			$this->write_progress("\tInstalling data to database");				
+		//open database connection with $this->global_settings->db_name()
+			try {
+				if (strlen($this->global_settings->db_host()) > 0) {
+					$this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} dbname={$this->global_settings->db_name()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()}");
+				} else {
+					$this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()} dbname={$this->global_settings->db_name()}");
+				}
+			}
+			catch (PDOException $error) {
+				throw new Exception("error connecting to database: " . $error->getMessage());
+			}
 
 
-				//if $this->db_create_username provided, attempt to create new PG role and database
-					if (strlen($this->db_create_username) > 0) {
-						try {
-							if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
-							if (strlen($this->db_host) > 0) {
-								$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
-							} else {
-								$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
-							}
-						} catch (PDOException $error) {
-							throw new Exception("error connecting to database: " . $error->getMessage());
-						}
 
 
-						//create the database, user, grant perms
-						$this->dbh->exec("CREATE DATABASE {$this->db_name}");
-						$this->dbh->exec("CREATE USER {$this->db_username} WITH PASSWORD '{$this->db_password}'");
-						$this->dbh->exec("GRANT ALL ON {$this->db_name} TO {$this->db_username}");
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->global_settings->db_type();
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
+			}
+			else {
+			$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
+			}
+			$file_contents = file_get_contents($filename);
 
 
-						//close database connection_aborted
-						$this->dbh = null;
-					}
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
 
 
-				//open database connection with $this->db_name
+		//loop line by line through all the lines of sql code
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
+				if (strlen($sql) > 3) {
 					try {
 					try {
-						if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
-						if (strlen($this->db_host) > 0) {
-							$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} dbname={$this->db_name} user={$this->db_username} password={$this->db_password}");
-						} else {
-							$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_username} password={$this->db_password} dbname={$this->db_name}");
-						}
+						$this->dbh->query($sql);
 					}
 					}
 					catch (PDOException $error) {
 					catch (PDOException $error) {
-						throw new Exception("error connecting to database: " . $error->getMessage());
-					}
-
-				//add the database structure
-					require_once "resources/classes/schema.php";
-					$schema = new schema;
-					$schema->db = $this->dbh;
-					$schema->db_type = $this->db_type;
-					$schema->sql();
-					$schema->exec();
-
-				//get the contents of the sql file
-					if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
-						$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
+						throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
 					}
 					}
-					else {
-					$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
-					}
-					$file_contents = file_get_contents($filename);
-
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$string_array = explode("\n", $file_contents);
-					$x = 0;
-					foreach($string_array as $sql) {
-						if (strlen($sql) > 3) {
-							try {
-								$this->dbh->query($sql);
-							}
-							catch (PDOException $error) {
-								throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
-							}
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
+				}
+				$x++;
 			}
 			}
+			unset ($file_contents, $sql);
+		}
 
 
 		protected function create_database_mysql() {
 		protected function create_database_mysql() {
 				//database connection
 				//database connection
-					try {
-						if (strlen($this->db_host) == 0 && strlen($this->db_port) == 0) {
-							//if both host and port are empty use the unix socket
-							if (strlen($this->db_create_username) == 0) {
-								$this->dbh = new PDO("mysql:host=$this->db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $this->db_username, $this->db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-							}
-							else {
-								$this->dbh = new PDO("mysql:host=$this->db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $this->db_create_username, $this->db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-							}
-						}
-						else {
-							if (strlen($this->db_port) == 0) {
-								//leave out port if it is empty
-								if (strlen($this->db_create_username) == 0) {
-									$this->dbh = new PDO("mysql:host=$this->db_host;", $this->db_username, $this->db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-								}
-								else {
-									$this->dbh = new PDO("mysql:host=$this->db_host;", $this->db_create_username, $this->db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));							}
-							}
-							else {
-								if (strlen($this->db_create_username) == 0) {
-									$this->dbh = new PDO("mysql:host=$this->db_host;port=$this->db_port;", $this->db_username, $this->db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-								}
-								else {
-									$this->dbh = new PDO("mysql:host=$this->db_host;port=$this->db_port;", $this->db_create_username, $this->db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-								}
-							}
-						}
-						$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-						$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+					$connect_string;
+					if (strlen($this->global_settings->db_host()) == 0 && strlen($this->global_settings->db_port()) == 0) {
+						//if both host and port are empty use the unix socket
+						$connect_string = "mysql:host=$this->global_settings->db_host();unix_socket=/var/run/mysqld/mysqld.sock;";
 					}
 					}
-					catch (PDOException $error) {
-								throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
+					elseif (strlen($this->global_settings->db_port()) == 0) {
+						//leave out port if it is empty
+						$connect_string = "mysql:host=$this->global_settings->db_host();";
+					}
+					else {
+						$connect_string = "mysql:host=$this->global_settings->db_host();port=$this->global_settings->db_port();";
 					}
 					}
 
 
 				//create the table, user and set the permissions only if the db_create_username was provided
 				//create the table, user and set the permissions only if the db_create_username was provided
-					if (strlen($this->db_create_username) > 0) {
+					if ($this->global_settings->db_create()) {
+						$this->write_progress("\tCreating database");				
+						try {
+							$this->dbh = new PDO($connect_string, $this->global_settings->db_create_username(), db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+							$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+							$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+						}
+						catch (PDOException $error) {
+							throw new Exception("error connecting to database for ccreate: " . $error->getMessage() . "\n" . $sql );
+						}
 						//select the mysql database
 						//select the mysql database
 							try {
 							try {
 								$this->dbh->query("USE mysql;");
 								$this->dbh->query("USE mysql;");
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									throw new Exception("error conencting to database: " . $error->getMessage());
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
 
 
 						//create user and set the permissions
 						//create user and set the permissions
 							try {
 							try {
-								$tmp_sql = "CREATE USER '".$this->db_username."'@'%' IDENTIFIED BY '".$this->db_password."'; ";
+								$tmp_sql = "CREATE USER '".$this->global_settings->db_username()."'@'%' IDENTIFIED BY '".$this->global_settings->db_password()."'; ";
 								$this->dbh->query($tmp_sql);
 								$this->dbh->query($tmp_sql);
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									print "error: " . $error->getMessage() . "<br/>";
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
 
 
 						//set account to unlimited use
 						//set account to unlimited use
 							try {
 							try {
-								if ($this->db_host == "localhost" || $this->db_host == "127.0.0.1") {
-									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->db_username."'@'localhost' ";
-									$tmp_sql .= "IDENTIFIED BY '".$this->db_password."' ";
+								if ($this->global_settings->db_host() == "localhost" || $this->global_settings->db_host() == "127.0.0.1") {
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'localhost' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$this->dbh->query($tmp_sql);
 									$this->dbh->query($tmp_sql);
 
 
-									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->db_username."'@'127.0.0.1' ";
-									$tmp_sql .= "IDENTIFIED BY '".$this->db_password."' ";
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'127.0.0.1' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$this->dbh->query($tmp_sql);
 									$this->dbh->query($tmp_sql);
 								}
 								}
 								else {
 								else {
-									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->db_username."'@'".$this->db_host."' ";
-									$tmp_sql .= "IDENTIFIED BY '".$this->db_password."' ";
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'".$this->global_settings->db_host()."' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
 									$this->dbh->query($tmp_sql);
 									$this->dbh->query($tmp_sql);
 								}
 								}
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									print "error: " . $error->getMessage() . "<br/>";
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
 
 
 						//create the database and set the create user with permissions
 						//create the database and set the create user with permissions
 							try {
 							try {
-								$tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->db_name."; ";
+								$tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->global_settings->db_name()."; ";
 								$this->dbh->query($tmp_sql);
 								$this->dbh->query($tmp_sql);
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									print "error: " . $error->getMessage() . "<br/>";
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
 
 
 						//set user permissions
 						//set user permissions
 							try {
 							try {
-								$this->dbh->query("GRANT ALL PRIVILEGES ON ".$this->db_name.".* TO '".$this->db_username."'@'%'; ");
+								$this->dbh->query("GRANT ALL PRIVILEGES ON ".$this->global_settings->db_name().".* TO '".$this->global_settings->db_username()."'@'%'; ");
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									print "error: " . $error->getMessage() . "<br/>";
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
 
 
 						//make the changes active
 						//make the changes active
@@ -455,28 +486,33 @@ include "root.php";
 								$this->dbh->query($tmp_sql);
 								$this->dbh->query($tmp_sql);
 							}
 							}
 							catch (PDOException $error) {
 							catch (PDOException $error) {
-								if ($this->debug) {
-									print "error: " . $error->getMessage() . "<br/>";
-								}
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							}
+							$this->dbh = null;
+					} //if (strlen($this->global_settings->db_create_username()) > 0)
 
 
-					} //if (strlen($this->db_create_username) > 0)
-
+				$this->write_progress("\tInstalling data to database");
 				//select the database
 				//select the database
 					try {
 					try {
-						$this->dbh->query("USE ".$this->db_name.";");
+						$this->dbh = new PDO($connect_string, $this->global_settings->db_username(), db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+						$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+						$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
 					}
 					}
 					catch (PDOException $error) {
 					catch (PDOException $error) {
-						if ($this->debug) {
-							print "error: " . $error->getMessage() . "<br/>";
-						}
+						throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql );
+					}
+					try {
+						$this->dbh->query("USE ".$this->global_settings->db_name().";");
+					}
+					catch (PDOException $error) {
+						throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 					}
 					}
 
 
 				//add the database structure
 				//add the database structure
 					require_once "resources/classes/schema.php";
 					require_once "resources/classes/schema.php";
 					$schema = new schema;
 					$schema = new schema;
 					$schema->db = $this->dbh;
 					$schema->db = $this->dbh;
-					$schema->db_type = $this->db_type;
+					$schema->db_type = $this->global_settings->db_type();
 					$schema->sql();
 					$schema->sql();
 					$schema->exec();
 					$schema->exec();
 
 
@@ -515,23 +551,25 @@ include "root.php";
 		}
 		}
 
 
 		protected function create_domain() {
 		protected function create_domain() {
-			$this->write_progress("Checking if domain exists '" . $this->domain_name . "'");
+			$this->write_progress("\tChecking if domain exists '" . $this->global_settings->domain_name . "'");
 			$sql = "select * from v_domains ";
 			$sql = "select * from v_domains ";
-			$sql .= "where domain_name = '".$this->domain_name."' ";
+			$sql .= "where domain_name = '".$this->global_settings->domain_name."' ";
 			$sql .= "limit 1";
 			$sql .= "limit 1";
 			$this->write_debug($sql);
 			$this->write_debug($sql);
 			$prep_statement = $this->dbh->prepare(check_sql($sql));
 			$prep_statement = $this->dbh->prepare(check_sql($sql));
-			$prep_statement->execute();
+			if($prep_statement->execute() === false){
+				throw new Exception("Failed to search for domain: " . join(":", $this->dbh->errorInfo()));
+			}
 			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
 			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
 			unset($sql, $prep_statement);
 			unset($sql, $prep_statement);
 			if ($result) {
 			if ($result) {
-				$this->_domain_uuid = $result['domain_uuid'];
-				$this->write_progress("... domain exists as '" . $this->_domain_uuid . "'");
+				$this->global_settings->set_domain_uuid($result['domain_uuid']);
+				$this->write_progress("... domain exists as '" . $this->global_settings->domain_uuid() . "'");
 				if($result['domain_enabled'] != 'true'){
 				if($result['domain_enabled'] != 'true'){
 					throw new Exception("Domain already exists but is disabled, this is unexpected");
 					throw new Exception("Domain already exists but is disabled, this is unexpected");
 				}
 				}
 			} else {
 			} else {
-				$this->write_progress("... creating domain");
+				$this->write_progress("\t... creating domain");
 				$sql = "insert into v_domains ";
 				$sql = "insert into v_domains ";
 				$sql .= "(";
 				$sql .= "(";
 				$sql .= "domain_uuid, ";
 				$sql .= "domain_uuid, ";
@@ -540,13 +578,15 @@ include "root.php";
 				$sql .= ") ";
 				$sql .= ") ";
 				$sql .= "values ";
 				$sql .= "values ";
 				$sql .= "(";
 				$sql .= "(";
-				$sql .= "'".$this->_domain_uuid."', ";
-				$sql .= "'".$this->domain_name."', ";
-				$sql .= "'' ";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
+				$sql .= "'".$this->global_settings->domain_name()."', ";
+				$sql .= "'Default Domain' ";
 				$sql .= ");";
 				$sql .= ");";
 
 
 				$this->write_debug($sql);
 				$this->write_debug($sql);
-				$this->dbh->exec(check_sql($sql));
+				if($this->dbh->exec(check_sql($sql)) === false){
+					throw new Exception("Failed to execute sql statement: " . join(":", $this->dbh->errorInfo()));
+				}
 				unset($sql);
 				unset($sql);
 
 
 				//domain settings
 				//domain settings
@@ -589,91 +629,97 @@ include "root.php";
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->base_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_base_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'base';
 				$tmp[$x]['subcategory'] = 'base';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->conf_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_conf_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'conf';
 				$tmp[$x]['subcategory'] = 'conf';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->db_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_db_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'db';
 				$tmp[$x]['subcategory'] = 'db';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->log_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_log_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'log';
 				$tmp[$x]['subcategory'] = 'log';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->mod_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_mod_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'mod';
 				$tmp[$x]['subcategory'] = 'mod';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->script_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_script_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'scripts';
 				$tmp[$x]['subcategory'] = 'scripts';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->grammar_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_grammar_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'grammar';
 				$tmp[$x]['subcategory'] = 'grammar';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->storage_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_storage_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'storage';
 				$tmp[$x]['subcategory'] = 'storage';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = join( DIRECTORY_SEPARATOR, $this->detect_switch->storage_dir(), 'voicemail');
+				$tmp[$x]['value'] = $this->global_settings->switch_voicemail_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'voicemail';
 				$tmp[$x]['subcategory'] = 'voicemail';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->recordings_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_recordings_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'recordings';
 				$tmp[$x]['subcategory'] = 'recordings';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->sounds_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_sounds_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'sounds';
 				$tmp[$x]['subcategory'] = 'sounds';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_phrases_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'phrases';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['value'] = '';
 				$tmp[$x]['value'] = '';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'provision';
 				$tmp[$x]['subcategory'] = 'provision';
 				$tmp[$x]['enabled'] = 'false';
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = join( DIRECTORY_SEPARATOR, $this->detect_switch->conf_dir(), "/directory");
+				$tmp[$x]['value'] = $this->global_settings->switch_extensions_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'extensions';
 				$tmp[$x]['subcategory'] = 'extensions';
 				$tmp[$x]['enabled'] = 'false';
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = join( DIRECTORY_SEPARATOR, $this->detect_switch->conf_dir(), "/sip_profiles");
+				$tmp[$x]['value'] = $this->global_settings->switch_sip_profiles_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'sip_profiles';
 				$tmp[$x]['subcategory'] = 'sip_profiles';
 				$tmp[$x]['enabled'] = 'false';
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = join( DIRECTORY_SEPARATOR, $this->detect_switch->conf_dir(), "/dialplan");
+				$tmp[$x]['value'] = $this->global_settings->switch_dialplan_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'dialplan';
 				$tmp[$x]['subcategory'] = 'dialplan';
 				$tmp[$x]['enabled'] = 'false';
 				$tmp[$x]['enabled'] = 'false';
@@ -681,7 +727,7 @@ include "root.php";
 
 
 				//server settings
 				//server settings
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->temp_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_temp_dir();
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['subcategory'] = 'temp';
 				$tmp[$x]['subcategory'] = 'temp';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
@@ -694,7 +740,7 @@ include "root.php";
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$x++;
 				$tmp[$x]['name'] = 'dir';
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = sys_get_temp_dir();
+				$tmp[$x]['value'] = $this->global_settings->switch_backup_vdir();
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['subcategory'] = 'backup';
 				$tmp[$x]['subcategory'] = 'backup';
 				$tmp[$x]['enabled'] = 'true';
 				$tmp[$x]['enabled'] = 'true';
@@ -810,9 +856,9 @@ include "root.php";
 		}
 		}
 
 
 		protected function create_superuser() {
 		protected function create_superuser() {
-			$this->write_progress("Checking if superuser exists '" . $this->domain_name . "'");
+			$this->write_progress("\tChecking if superuser exists '" . $this->global_settings->domain_name . "'");
 			$sql = "select * from v_users ";
 			$sql = "select * from v_users ";
-			$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
 			$sql .= "and username = '".$this->admin_username."' ";
 			$sql .= "and username = '".$this->admin_username."' ";
 			$sql .= "limit 1 ";
 			$sql .= "limit 1 ";
 			$this->write_debug($sql);
 			$this->write_debug($sql);
@@ -831,7 +877,7 @@ include "root.php";
 				$this->write_debug($sql);
 				$this->write_debug($sql);
 				$this->dbh->exec(check_sql($sql));
 				$this->dbh->exec(check_sql($sql));
 			}else{
 			}else{
-				$this->write_progress("... creating super user '" . $this->admin_username . "'");
+				$this->write_progress("\t... creating super user '" . $this->admin_username . "'");
 			//add a user and then add the user to the superadmin group
 			//add a user and then add the user to the superadmin group
 			//prepare the values
 			//prepare the values
 				$this->admin_uuid = uuid();
 				$this->admin_uuid = uuid();
@@ -853,7 +899,7 @@ include "root.php";
 				$sql .= ") ";
 				$sql .= ") ";
 				$sql .= "values ";
 				$sql .= "values ";
 				$sql .= "(";
 				$sql .= "(";
-				$sql .= "'".$this->_domain_uuid."', ";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
 				$sql .= "'".$this->admin_uuid."', ";
 				$sql .= "'".$this->admin_uuid."', ";
 				$sql .= "'$contact_uuid', ";
 				$sql .= "'$contact_uuid', ";
 				$sql .= "'".$this->admin_username."', ";
 				$sql .= "'".$this->admin_username."', ";
@@ -866,9 +912,9 @@ include "root.php";
 				$this->dbh->exec(check_sql($sql));
 				$this->dbh->exec(check_sql($sql));
 				unset($sql);
 				unset($sql);
 			}
 			}
-			$this->write_progress("Checking if superuser contact exists");
+			$this->write_progress("\tChecking if superuser contact exists");
 			$sql = "select count(*) from v_contacts ";
 			$sql = "select count(*) from v_contacts ";
-			$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
 			$sql .= "and contact_name_given = '".$this->admin_username."' ";
 			$sql .= "and contact_name_given = '".$this->admin_username."' ";
 			$sql .= "and contact_nickname = '".$this->admin_username."' ";
 			$sql .= "and contact_nickname = '".$this->admin_username."' ";
 			$sql .= "limit 1 ";
 			$sql .= "limit 1 ";
@@ -887,7 +933,7 @@ include "root.php";
 				$sql .= ") ";
 				$sql .= ") ";
 				$sql .= "values ";
 				$sql .= "values ";
 				$sql .= "(";
 				$sql .= "(";
-				$sql .= "'".$this->_domain_uuid."', ";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
 				$sql .= "'$contact_uuid', ";
 				$sql .= "'$contact_uuid', ";
 				$sql .= "'user', ";
 				$sql .= "'user', ";
 				$sql .= "'".$this->admin_username."', ";
 				$sql .= "'".$this->admin_username."', ";
@@ -896,9 +942,9 @@ include "root.php";
 				$this->dbh->exec(check_sql($sql));
 				$this->dbh->exec(check_sql($sql));
 				unset($sql);
 				unset($sql);
 			}
 			}
-			$this->write_progress("Checking if superuser is in the correct group");
+			$this->write_progress("\tChecking if superuser is in the correct group");
 			$sql = "select count(*) from v_group_users ";
 			$sql = "select count(*) from v_group_users ";
-			$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
 			$sql .= "and user_uuid = '".$this->admin_uuid."' ";
 			$sql .= "and user_uuid = '".$this->admin_uuid."' ";
 			$sql .= "and group_name = 'superadmin' ";
 			$sql .= "and group_name = 'superadmin' ";
 			$sql .= "limit 1 ";
 			$sql .= "limit 1 ";
@@ -918,7 +964,7 @@ include "root.php";
 				$sql .= "values ";
 				$sql .= "values ";
 				$sql .= "(";
 				$sql .= "(";
 				$sql .= "'".uuid()."', ";
 				$sql .= "'".uuid()."', ";
-				$sql .= "'".$this->_domain_uuid."', ";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
 				$sql .= "'".$this->admin_uuid."', ";
 				$sql .= "'".$this->admin_uuid."', ";
 				$sql .= "'superadmin' ";
 				$sql .= "'superadmin' ";
 				$sql .= ");";
 				$sql .= ");";
@@ -929,13 +975,13 @@ include "root.php";
 		}
 		}
 
 
 		protected function create_menus() {
 		protected function create_menus() {
-			$this->write_progress("Creating menus");
+			$this->write_progress("\tCreating menus");
 		//set the defaults
 		//set the defaults
 			$menu_name = 'default';
 			$menu_name = 'default';
 			$menu_language = 'en-us';
 			$menu_language = 'en-us';
 			$menu_description = 'Default Menu Set';
 			$menu_description = 'Default Menu Set';
 
 
-			$this->write_progress("Checking if menu exists");
+			$this->write_progress("\tChecking if menu exists");
 			$sql = "select count(*) from v_menus ";
 			$sql = "select count(*) from v_menus ";
 			$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
 			$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
 			$sql .= "limit 1 ";
 			$sql .= "limit 1 ";
@@ -945,7 +991,7 @@ include "root.php";
 			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
 			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
 			unset($sql, $prep_statement);
 			unset($sql, $prep_statement);
 			if ($result['count'] == 0) {
 			if ($result['count'] == 0) {
-				$this->write_progress("... creating menu '" . $menu_name. "'");
+				$this->write_progress("\t... creating menu '" . $menu_name. "'");
 				$sql = "insert into v_menus ";
 				$sql = "insert into v_menus ";
 				$sql .= "(";
 				$sql .= "(";
 				$sql .= "menu_uuid, ";
 				$sql .= "menu_uuid, ";
@@ -976,24 +1022,24 @@ include "root.php";
 			}
 			}
 		}
 		}
 
 
-		public function app_defaults() {
-			$this->write_progress("Running app_defaults");
+		protected function app_defaults() {
+			$this->write_progress("\tRunning app_defaults");
 
 
 		//set needed session settings
 		//set needed session settings
 			$_SESSION["username"] = $this->admin_username;
 			$_SESSION["username"] = $this->admin_username;
-			$_SESSION["domain_uuid"] = $this->_domain_uuid;
+			$_SESSION["domain_uuid"] = $this->global_settings->domain_uuid();
 			require $this->config_php;
 			require $this->config_php;
 			require "resources/require.php";
 			require "resources/require.php";
-			$_SESSION['event_socket_ip_address'] = $this->detect_switch->event_host;
-			$_SESSION['event_socket_port'] = $this->detect_switch->event_port;
-			$_SESSION['event_socket_password'] = $this->detect_switch->event_password;
+			$_SESSION['event_socket_ip_address'] = $this->global_settings->event_host;
+			$_SESSION['event_socket_port'] = $this->global_settings->event_port;
+			$_SESSION['event_socket_password'] = $this->global_settings->event_password;
 
 
 		//get the groups assigned to the user and then set the groups in $_SESSION["groups"]
 		//get the groups assigned to the user and then set the groups in $_SESSION["groups"]
 			$sql = "SELECT * FROM v_group_users ";
 			$sql = "SELECT * FROM v_group_users ";
 			$sql .= "where domain_uuid=:domain_uuid ";
 			$sql .= "where domain_uuid=:domain_uuid ";
 			$sql .= "and user_uuid=:user_uuid ";
 			$sql .= "and user_uuid=:user_uuid ";
 			$prep_statement = $this->dbh->prepare(check_sql($sql));
 			$prep_statement = $this->dbh->prepare(check_sql($sql));
-			$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
+			$prep_statement->bindParam(':domain_uuid', $this->global_settings->domain_uuid);
 			$prep_statement->bindParam(':user_uuid', $this->admin_uuid);
 			$prep_statement->bindParam(':user_uuid', $this->admin_uuid);
 			$prep_statement->execute();
 			$prep_statement->execute();
 			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
 			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@@ -1006,10 +1052,10 @@ include "root.php";
 			foreach($_SESSION["groups"] as $field) {
 			foreach($_SESSION["groups"] as $field) {
 				if (strlen($field['group_name']) > 0) {
 				if (strlen($field['group_name']) > 0) {
 					if ($x == 0) {
 					if ($x == 0) {
-						$sql .= "where (domain_uuid = '".$this->domain_uuid."' and group_name = '".$field['group_name']."') ";
+						$sql .= "where (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') ";
 					}
 					}
 					else {
 					else {
-						$sql .= "or (domain_uuid = '".$this->domain_uuid."' and group_name = '".$field['group_name']."') ";
+						$sql .= "or (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') ";
 					}
 					}
 					$x++;
 					$x++;
 				}
 				}
@@ -1020,13 +1066,13 @@ include "root.php";
 			unset($sql, $prep_statement_sub);
 			unset($sql, $prep_statement_sub);
 
 
 		//include the config.php
 		//include the config.php
-			$db_type = $this->db_type;
-			$db_path = $this->db_path;
-			$db_host = $this->db_host;
-			$db_port = $this->db_port;
-			$db_name = $this->db_name;
-			$db_username = $this->db_username;
-			$db_password = $this->db_password;
+			$db_type = $this->global_settings->db_type();
+			$db_path = $this->global_settings->db_path();
+			$db_host = $this->global_settings->db_host();
+			$db_port = $this->global_settings->db_port();
+			$db_name = $this->global_settings->db_name();
+			$db_username = $this->global_settings->db_username();
+			$db_password = $this->global_settings->db_password();
 
 
 		//add the database structure
 		//add the database structure
 			require_once "resources/classes/schema.php";
 			require_once "resources/classes/schema.php";

+ 203 - 42
core/install/resources/classes/install_switch.php

@@ -28,26 +28,30 @@ include "root.php";
 //define the install class
 //define the install class
 	class install_switch {
 	class install_switch {
 
 
-		protected $domain_uuid;
-		protected $domain_name;
-		protected $detect_switch;
+		protected $global_settings;
+		protected $config_lua;
+		protected $dbh;
 
 
 		public $debug = false;
 		public $debug = false;
 
 
-		function __construct($domain_name, $domain_uuid, $detect_switch) {
-			if($detect_switch == null){
-				if(strlen($_SESSION['event_socket_ip_address']) == 0 or strlen($_SESSION['event_socket_port']) == 0 or strlen($_SESSION['event_socket_password']) == 0 ){
-					throw new Exception('The parameter $detect_switch was empty and i could not find the event socket details from the session');
-				}
-				$detect_switch = new detect_switch($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
-				$domain_name = $_SESSION['domain_name'];
-				$domain_uuid = $_SESSION['domain_uuid'];
-			}elseif(!is_a($detect_switch, 'detect_switch')){
-				throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
+		function __construct($global_settings) {
+			if(is_null($global_settings)){
+				require_once "core/install/resources/classes/global_settings.php";
+				$global_settings = new global_settings();
+			}elseif(!is_a($global_settings, 'global_settings')){
+				throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
+			}
+			$this->global_settings = $global_settings;
+			if (is_dir("/etc/fusionpbx")){
+				$this->config_lua = "/etc/fusionpbx/config.lua";
+			}elseif (is_dir("/usr/local/etc/fusionpbx")){
+				$this->config_lua = "/usr/local/etc/fusionpbx/config.lua";
+			}elseif(strlen($this->global_settings->script_dir) > 0) {
+				$this->config_lua = $this->global_settings->script_dir."/resources/config.lua";
+			}else{
+				throw new Exception("Could not work out where to put the config.lua");
 			}
 			}
-			$this->domain_uuid = $domain_uuid;
-			$this->domain = $domain_name;
-			$this->detect_switch = $detect_switch;
+			$this->config_lua = normalize_path_to_os($this->config_lua);
 		}
 		}
 
 
 		//utility Functions
 		//utility Functions
@@ -76,9 +80,12 @@ include "root.php";
 				exec ($cmd);
 				exec ($cmd);
 			}
 			}
 			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
 			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
-				exec("copy /L '$src' '$dst'");
+				$src = normalize_path_to_os($src);
+				$dst = normalize_path_to_os($dst);
+				exec("xcopy /E /Y \"$src\" \"$dst\"");
 			}
 			}
 			else {
 			else {
+				throw new Exception('Could not perform copy operation on this platform, implementation missing');
 				$dir = opendir($src);
 				$dir = opendir($src);
 				if (!$dir) {
 				if (!$dir) {
 					if (!mkdir($src, 0755, true)) {
 					if (!mkdir($src, 0755, true)) {
@@ -91,8 +98,8 @@ include "root.php";
 					}
 					}
 				}
 				}
 				//This looks wrong, essentially if we can't use /bin/cp it manually fils dirs, not correct
 				//This looks wrong, essentially if we can't use /bin/cp it manually fils dirs, not correct
-				$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
-				$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
+				$script_dir_target = $_SESSION['switch']['scripts']['dir'];
+				$script_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
 				foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
 				foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
 					if (
 					if (
 					substr_count($file_path_source, '/..') == 0 &&
 					substr_count($file_path_source, '/..') == 0 &&
@@ -137,8 +144,9 @@ include "root.php";
 				exec ('rm -Rf '.$dir.'/*');
 				exec ('rm -Rf '.$dir.'/*');
 			}
 			}
 			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
 			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
-				$this->write_debug("del /S /F /Q '$dir'");
-				exec("del /S /F /Q '$dir'");
+				$dst = normalize_path_to_os($dst);
+				$this->write_debug("del /S /F /Q \"$dir\"");
+				exec("del /S /F /Q \"$dir\"");
 			}
 			}
 			else {
 			else {
 				foreach (glob($dir) as $file) {
 				foreach (glob($dir) as $file) {
@@ -174,25 +182,31 @@ include "root.php";
 		}
 		}
 
 
 		function install() {
 		function install() {
+			$this->write_progress("Install started for switch");
 			$this->copy_conf();
 			$this->copy_conf();
 			$this->copy_scripts();
 			$this->copy_scripts();
+			$this->create_config_lua();
+			$this->restart_switch();
+			$this->write_progress("Install completed for switch");
 		}
 		}
 
 
 		function upgrade() {
 		function upgrade() {
 			$this->copy_scripts();
 			$this->copy_scripts();
+			$this->create_config_lua();
+			$this->restart_switch();
 		}
 		}
 
 
-		function copy_conf() {
-			$this->write_progress("Copying Config");
+		protected function copy_conf() {
+			$this->write_progress("\tCopying Config");
 			//make a backup of the config
 			//make a backup of the config
-				if (file_exists($this->detect_switch->conf_dir())) {
-					$this->backup_dir($this->detect_switch->conf_dir(), 'fusionpbx_switch_config');
-					$this->recursive_delete($this->detect_switch->conf_dir());
+				if (file_exists($this->global_settings->switch_conf_dir())) {
+					$this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config');
+					$this->recursive_delete($this->global_settings->switch_conf_dir());
 				}
 				}
 			//make sure the conf directory exists
 			//make sure the conf directory exists
-				if (!is_dir($this->detect_switch->conf_dir())) {
-					if (!mkdir($this->detect_switch->conf_dir(), 0774, true)) {
-						throw new Exception("Failed to create the switch conf directory '".$this->detect_switch->conf_dir()."'. ");
+				if (!is_dir($this->global_settings->switch_conf_dir())) {
+					if (!mkdir($this->global_settings->switch_conf_dir(), 0774, true)) {
+						throw new Exception("Failed to create the switch conf directory '".$this->global_settings->switch_conf_dir()."'. ");
 					}
 					}
 				}
 				}
 			//copy resources/templates/conf to the freeswitch conf dir
 			//copy resources/templates/conf to the freeswitch conf dir
@@ -202,14 +216,14 @@ include "root.php";
 				else {
 				else {
 					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
 					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
 				}
 				}
-				$dst_dir = $this->detect_switch->conf_dir();
+				$dst_dir = $this->global_settings->switch_conf_dir();
 				if (is_readable($dst_dir)) {
 				if (is_readable($dst_dir)) {
 					$this->recursive_copy($src_dir, $dst_dir);
 					$this->recursive_copy($src_dir, $dst_dir);
 					unset($src_dir, $dst_dir);
 					unset($src_dir, $dst_dir);
 				}
 				}
-				$fax_dir = join( DIRECTORY_SEPARATOR, array($this->detect_switch->storage_dir(), 'fax'));
+				$fax_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax'));
 				if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); }
 				if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); }
-				$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->detect_switch->storage_dir(), 'voicemail'));
+				$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
 				if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
 				if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
 			
 			
 			//create the dialplan/default.xml for single tenant or dialplan/domain.xml
 			//create the dialplan/default.xml for single tenant or dialplan/domain.xml
@@ -217,7 +231,7 @@ include "root.php";
 					$dialplan = new dialplan;
 					$dialplan = new dialplan;
 					$dialplan->domain_uuid = $this->domain_uuid;
 					$dialplan->domain_uuid = $this->domain_uuid;
 					$dialplan->domain = $this->domain_name;
 					$dialplan->domain = $this->domain_name;
-					$dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->detect_switch->conf_dir(), "/dialplan"));
+					$dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan"));
 					$dialplan->restore_advanced_xml();
 					$dialplan->restore_advanced_xml();
 					if($this->_debug){
 					if($this->_debug){
 						print_r($dialplan->result, $message);
 						print_r($dialplan->result, $message);
@@ -231,19 +245,17 @@ include "root.php";
 				}
 				}
 
 
 			//write the switch.conf.xml file
 			//write the switch.conf.xml file
-				if (file_exists($this->detect_switch->conf_dir())) {
+				if (file_exists($this->global_settings->switch_conf_dir())) {
 					switch_conf_xml();
 					switch_conf_xml();
 				}
 				}
 
 
 		}
 		}
 
 
-		function copy_scripts() {
-			$this->write_progress("Copying Scripts");
-			if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
-				$script_dir = $_SESSION['switch']['scripts']['dir'];
-			}
-			else {
-				$script_dir = $this->detect_switch->script_dir();
+		protected function copy_scripts() {
+			$this->write_progress("\tCopying Scripts");
+			$script_dir = $this->global_settings->switch_script_dir();
+			if(strlen($script_dir) == 0) {
+				throw new Exception("Cannot copy scripts the 'script_dir' is empty");
 			}
 			}
 			if (file_exists($script_dir)) {
 			if (file_exists($script_dir)) {
 				if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
 				if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
@@ -256,10 +268,159 @@ include "root.php";
 				if (is_readable($script_dir)) {
 				if (is_readable($script_dir)) {
 					$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
 					$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
 					unset($src_dir, $dst_dir);
 					unset($src_dir, $dst_dir);
+				}else{
+					throw new Exception("Cannot read from '$src_dir' to get the scripts");
 				}
 				}
 				chmod($dst_dir, 0774);
 				chmod($dst_dir, 0774);
+			}else{
+				$this->write_progress("\tSkipping scripts, script_dir is unset");
 			}
 			}
 		}
 		}
-		
+
+		public function create_config_lua() {
+			$this->write_progress("\tCreating " . $this->config_lua);
+			global $db;
+		//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);
+				unset($prep_statement);
+				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);
+				}
+				else {
+					$odbc_num_rows = '0';
+				}
+			}
+
+		//config.lua
+			$fout = fopen($this->config_lua,"w");
+			if(!$fout){
+				throw new Exception("Failed to open '".$this->config_lua."' for writing");
+			}
+			$tmp = "\n";
+			$tmp .= "--set the variables\n";
+			if (strlen($this->global_settings->switch_sounds_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_phrases_vdir()) > 0) {
+				$tmp .= normalize_path_to_os("	phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_db_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	database_dir = [[".$this->global_settings->switch_db_dir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_recordings_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_storage_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) {
+				$tmp .= normalize_path_to_os("	voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n");
+			}
+			if (strlen($this->global_settings->switch_script_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	script_dir = [[".$this->global_settings->switch_script_dir()."]];\n");
+			}
+			$tmp .= normalize_path_to_os("	php_dir = [[".PHP_BINDIR."]];\n");
+			if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
+				$tmp .= "	php_bin = \"php.exe\";\n";
+			}
+			else {
+				$tmp .= "	php_bin = \"php\";\n";
+			}
+			$tmp .= normalize_path_to_os("	document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
+			$tmp .= "\n";
+
+			if ((strlen($this->global_settings->db_type()) > 0) || (strlen($dsn_name) > 0)) {
+				$tmp .= "--database information\n";
+				$tmp .= "	database = {}\n";
+				$tmp .= "	database[\"type\"] = \"".$this->global_settings->db_type()."\";\n";
+				$tmp .= "	database[\"name\"] = \"".$this->global_settings->db_name()."\";\n";
+				$tmp .= normalize_path_to_os("	database[\"path\"] = [[".$this->global_settings->db_path()."]];\n");
+
+				if (strlen($dsn_name) > 0) {
+					$tmp .= "	database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n";
+					$tmp .= "	database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n";
+				}
+				elseif ($this->global_settings->db_type() == "pgsql") {
+					$tmp .= "	database[\"system\"] = \"pgsql://hostaddr=".$this->global_settings->db_host()." port=".$this->global_settings->db_port()." dbname=".$this->global_settings->db_name()." user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='".$this->global_settings->db_name()."'\";\n";
+					$tmp .= "	database[\"switch\"] = \"pgsql://hostaddr=".$this->global_settings->db_host()." port=".$this->global_settings->db_port()." dbname=freeswitch user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='freeswitch'\";\n";
+				}
+				elseif ($this->global_settings->db_type() == "sqlite") {
+					$tmp .= "	database[\"system\"] = \"sqlite://".$this->global_settings->db_path()."/".$this->global_settings->db_name()."\";\n";
+					$tmp .= "	database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
+				}
+				elseif ($this->global_settings->db_type() == "mysql") {
+					$tmp .= "	database[\"system\"] = \"\";\n";
+					$tmp .= "	database[\"switch\"] = \"\";\n";
+				}
+				$tmp .= "\n";
+			}
+			$tmp .= "--set defaults\n";
+			$tmp .= "	expire = {}\n";
+			$tmp .= "	expire[\"directory\"] = \"3600\";\n";
+			$tmp .= "	expire[\"dialplan\"] = \"3600\";\n";
+			$tmp .= "	expire[\"languages\"] = \"3600\";\n";
+			$tmp .= "	expire[\"sofia.conf\"] = \"3600\";\n";
+			$tmp .= "	expire[\"acl.conf\"] = \"3600\";\n";
+			$tmp .= "\n";
+			$tmp .= "--set xml_handler\n";
+			$tmp .= "	xml_handler = {}\n";
+			$tmp .= "	xml_handler[\"fs_path\"] = false;\n";
+			$tmp .= "\n";
+			$tmp .= "--set the debug options\n";
+			$tmp .= "	debug[\"params\"] = false;\n";
+			$tmp .= "	debug[\"sql\"] = false;\n";
+			$tmp .= "	debug[\"xml_request\"] = false;\n";
+			$tmp .= "	debug[\"xml_string\"] = false;\n";
+			$tmp .= "	debug[\"cache\"] = false;\n";
+			$tmp .= "\n";
+			$tmp .= "--additional info\n";
+			$tmp .= "	domain_count = ".$this->global_settings->domain_count().";\n";
+			$tmp .= normalize_path_to_os("	temp_dir = [[".$this->global_settings->switch_temp_dir()."]];\n");
+			if (isset($_SESSION['domain']['dial_string']['text'])) {
+				$tmp .= "	dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
+			}
+			$tmp .= "\n";
+			$tmp .= "--include local.lua\n";
+			$tmp .= "	require(\"resources.functions.file_exists\");\n";
+			$tmp .= "	if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
+			$tmp .= "		dofile(\"/etc/fusionpbx/local.lua\");\n";
+			$tmp .= "	elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
+			$tmp .= "		dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
+			$tmp .= "	elseif (file_exists(script_dir..\"/resources/local.lua\")) then\n";
+			$tmp .= "		require(\"resources.local\");\n";
+			$tmp .= "	end\n";
+			fwrite($fout, $tmp);
+			unset($tmp);
+			fclose($fout);	
+		}
+
+		protected function restart_switch() {
+			$esl = new EventSocket;
+			if(!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) {
+				throw new Exception("Failed to connect to switch");
+			}
+			if (!$esl->request('api fsctl shutdown restart elegant')){
+				throw new Exception("Failed to send switch restart");
+			}
+			$esl->reset_fp();
+		}
 	}
 	}
 ?>
 ?>

+ 31 - 1
core/install/resources/page_parts/install_config_database.php

@@ -134,6 +134,25 @@
 		echo "</td>\n";
 		echo "</td>\n";
 		echo "</tr>\n";
 		echo "</tr>\n";
 
 
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Options\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='none'";
+		if($db_create_option=='none') { echo " checked='checked'"; }
+		echo "/>Do not create database</label>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='same'";
+		if($db_create_option=='same') { echo " checked='checked'"; }
+		echo "/>Create database using above username/password</label>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='user'";
+		if($db_create_option=='user') { echo " checked='checked'"; }
+		echo "/>Create database using below username/password</label>\n";
+		echo "<br />\n";
+		echo "Choose whether to create the database\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
 		echo "<tr>\n";
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
 		echo "		Create Database Username\n";
 		echo "		Create Database Username\n";
@@ -218,6 +237,17 @@
 		echo "</td>\n";
 		echo "</td>\n";
 		echo "</tr>\n";
 		echo "</tr>\n";
 
 
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Options\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<label class='radio'><input type='checkbox' name='db_create' value='1'";
+		if($db_create=='1') { echo " checked='checked'"; }
+		echo "/>Create the database</label>\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
 		echo "<tr>\n";
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
 		echo "		Create Database Username\n";
 		echo "		Create Database Username\n";
@@ -226,7 +256,7 @@
 		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
 		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
 		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
 		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
 		echo "		By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n";
 		echo "		By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n";
-		echo "		Leave blank if the user and empty database already exist and you do not want them created. \n";
+		echo "		Leave blank to use the details above. \n";
 		echo "</td>\n";
 		echo "</td>\n";
 		echo "</tr>\n";
 		echo "</tr>\n";
 
 

+ 19 - 4
core/install/resources/page_parts/install_event_socket.php

@@ -91,10 +91,10 @@
 		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	
 	
 		echo "<tr>\n";
 		echo "<tr>\n";
-		echo "<td colspan='4' align='left' nowrap><b>".$text['title-detected_configuration']."</b><br><br></td>\n";
+		echo "<td colspan='4' align='left' nowrap><b>".$text['title-detected_configuration']."</b></td>\n";
 		echo "</tr>\n";
 		echo "</tr>\n";
 
 
-		$id = 0;
+		$id = 1;
 		echo "<tr>\n";
 		echo "<tr>\n";
 		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
 		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
 		echo "Switch version\n";
 		echo "Switch version\n";
@@ -102,9 +102,8 @@
 		echo "<td class='vtable' width='35%' align='left'>\n";
 		echo "<td class='vtable' width='35%' align='left'>\n";
 		echo "    ".$switch_detect->version()."\n";
 		echo "    ".$switch_detect->version()."\n";
 		echo "</td>\n";
 		echo "</td>\n";
-		echo "</tr>\n";
 		
 		
-		foreach ($switch_detect->get_folders() as $folder)
+		foreach ($switch_detect->get_dirs() as $folder)
 		{
 		{
 			if($id % 2 == 0){ echo "<tr>\n"; }
 			if($id % 2 == 0){ echo "<tr>\n"; }
 			echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
 			echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
@@ -117,6 +116,22 @@
 			$id++;
 			$id++;
 		}
 		}
 		if($id % 2 == 1){ echo "</tr>\n"; }
 		if($id % 2 == 1){ echo "</tr>\n"; }
+		echo "<tr>\n";
+		echo "<td colspan='4' align='left' nowrap><br/><b>".$text['title-assumed_configuration']."</b></td>\n";
+		echo "</tr>\n";
+		$id=0;
+		foreach ($switch_detect->get_vdirs() as $folder)
+		{
+			if($id % 2 == 0){ echo "<tr>\n"; }
+			echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
+			echo $folder."\n";
+			echo "</td>\n";
+			echo "<td class='vtable' width='35%' align='left'>\n";
+			echo "    ".$switch_detect->$folder()."\n";
+			echo "</td>\n";
+			if($id % 2 == 1){ echo "</tr>\n"; }
+			$id++;
+		}
 			
 			
 		echo "</table>";
 		echo "</table>";
 	}
 	}

+ 59 - 0
core/install/upgrade_switch.php

@@ -0,0 +1,59 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+
+// set included, if not
+	if (!isset($included)) { $included = false; }
+
+//check the permission
+	if(defined('STDIN')) {
+		$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
+		preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
+		$document_root = $matches[1];
+		set_include_path($document_root);
+		require_once "resources/require.php";
+		$_SERVER["DOCUMENT_ROOT"] = $document_root;
+		$format = 'text'; //html, text
+	}
+	else if (!$included) {
+		include "root.php";
+		require_once "resources/require.php";
+		require_once "resources/check_auth.php";
+		if (permission_exists('upgrade_switch') || if_group("superadmin")) {
+			//echo "access granted";
+		}
+		else {
+			echo "access denied";
+			exit;
+		}
+		$format = 'html'; //html, text
+	}
+
+//run switch upgrade
+	require_once "resources/classes/install_switch.php";
+	$switch = new install_switch();
+	$switch->upgrade();
+
+?>

+ 3 - 0
core/upgrade/app_config.php

@@ -32,6 +32,9 @@
 		$apps[$x]['permissions'][$y]['menu']['uuid'] = "e7bb1296-3141-48c9-a95a-82d2768d0ae4";
 		$apps[$x]['permissions'][$y]['menu']['uuid'] = "e7bb1296-3141-48c9-a95a-82d2768d0ae4";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
 		$y++;
+		$apps[$x]['permissions'][$y]['name'] = "upgrade_switch";
+		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
+		$y++;
 
 
 	//schema details
 	//schema details
 		$y = 0; //table array index
 		$y = 0; //table array index

+ 20 - 0
core/upgrade/app_languages.php

@@ -180,6 +180,16 @@ $text['label-upgrade_apps']['sv-se'] = "App Standard";
 $text['label-upgrade_apps']['uk'] = "Типові значення додатків";
 $text['label-upgrade_apps']['uk'] = "Типові значення додатків";
 $text['label-upgrade_apps']['de-at'] = "Applikationen zurücksetzen";
 $text['label-upgrade_apps']['de-at'] = "Applikationen zurücksetzen";
 
 
+$text['label-upgrade_switch']['en-us'] = "Switch Upgrade";
+$text['label-upgrade_switch']['es-cl'] = "";
+$text['label-upgrade_switch']['pt-pt'] = "";
+$text['label-upgrade_switch']['fr-fr'] = "";
+$text['label-upgrade_switch']['pt-br'] = "";
+$text['label-upgrade_switch']['pl'] = "";
+$text['label-upgrade_switch']['sv-se'] = "";
+$text['label-upgrade_switch']['uk'] = "";
+$text['label-upgrade_switch']['de-at'] = "";
+
 $text['label-upgrade']['en-us'] = "Upgrade";
 $text['label-upgrade']['en-us'] = "Upgrade";
 $text['label-upgrade']['es-cl'] = "Actualizar";
 $text['label-upgrade']['es-cl'] = "Actualizar";
 $text['label-upgrade']['pt-pt'] = "Actualizar";
 $text['label-upgrade']['pt-pt'] = "Actualizar";
@@ -390,6 +400,16 @@ $text['description-upgrade_apps']['sv-se'] = "Återställer standardinställning
 $text['description-upgrade_apps']['uk'] = "Встановлює типові значення для додатків";
 $text['description-upgrade_apps']['uk'] = "Встановлює типові значення для додатків";
 $text['description-upgrade_apps']['de-at'] = "Setzt alle Applikationen auf die Standardeinstellungen zurück.";
 $text['description-upgrade_apps']['de-at'] = "Setzt alle Applikationen auf die Standardeinstellungen zurück.";
 
 
+$text['description-upgrade_switch']['en-us'] = "Runs the upgrade switch routine.";
+$text['description-upgrade_switch']['es-cl'] = "";
+$text['description-upgrade_switch']['pt-pt'] = "";
+$text['description-upgrade_switch']['fr-fr'] = "";
+$text['description-upgrade_switch']['pt-br'] = "";
+$text['description-upgrade_switch']['pl'] = "";
+$text['description-upgrade_switch']['sv-se'] = "";
+$text['description-upgrade_switch']['uk'] = "";
+$text['description-upgrade_switch']['de-at'] = "";
+
 $text['description-upgrade']['en-us'] = "Select the actions below you wish to perform.";
 $text['description-upgrade']['en-us'] = "Select the actions below you wish to perform.";
 $text['description-upgrade']['es-cl'] = "Seleccione las acciones a continuación que desea realizar.";
 $text['description-upgrade']['es-cl'] = "Seleccione las acciones a continuación que desea realizar.";
 $text['description-upgrade']['pt-pt'] = "Selecione as ações abaixo você deseja executar.";
 $text['description-upgrade']['pt-pt'] = "Selecione as ações abaixo você deseja executar.";

+ 24 - 0
core/upgrade/index.php

@@ -35,6 +35,7 @@ if (
 	!permission_exists('upgrade_source') &&
 	!permission_exists('upgrade_source') &&
 	!permission_exists('upgrade_schema') &&
 	!permission_exists('upgrade_schema') &&
 	!permission_exists('upgrade_apps') &&
 	!permission_exists('upgrade_apps') &&
+	!permission_exists('upgrade_switch') &&
 	!permission_exists('menu_restore') &&
 	!permission_exists('menu_restore') &&
 	!permission_exists('group_edit')
 	!permission_exists('group_edit')
 	) {
 	) {
@@ -121,6 +122,13 @@ if (sizeof($_POST) > 0) {
 		$response_message = "Permission Defaults Restored";
 		$response_message = "Permission Defaults Restored";
 	}
 	}
 
 
+	// upgrade switch
+	if ($do["switch"] && permission_exists("upgrade_switch")) {
+		$included = true;
+		require_once("core/install/upgrade_switch.php");
+		$response_message = "Switch Upgraded";
+	}
+
 	if (sizeof($_POST['do']) > 1) {
 	if (sizeof($_POST['do']) > 1) {
 		$response_message = $text['message-upgrade'];
 		$response_message = $text['message-upgrade'];
 	}
 	}
@@ -250,6 +258,22 @@ if (permission_exists("group_edit")) {
 	echo "</table>\n";
 	echo "</table>\n";
 }
 }
 
 
+if (permission_exists("upgrade_switch")) {
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "	<td width='30%' class='vncell'>\n";
+	echo "		".$text['label-upgrade_switch'];
+	echo "	</td>\n";
+	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
+	echo "		<label for='do_switch'>";
+	echo "			<input type='checkbox' class='formfld' name='do[switch]' id='do_switch' value='1'>";
+	echo "			".$text['description-upgrade_switch'];
+	echo "		</label>\n";
+	echo "	</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+}
+
 echo "<br>";
 echo "<br>";
 echo "<div style='text-align: right;'><input type='submit' class='btn' value='".$text['button-upgrade_execute']."'></div>";
 echo "<div style='text-align: right;'><input type='submit' class='btn' value='".$text['button-upgrade_execute']."'></div>";
 echo "<br><br>";
 echo "<br><br>";

+ 4 - 0
resources/classes/domains.php

@@ -369,6 +369,10 @@
 				if (function_exists('save_dialplan_xml')) {
 				if (function_exists('save_dialplan_xml')) {
 					save_dialplan_xml();
 					save_dialplan_xml();
 				}
 				}
+			//update config.lua
+				require_once "core/install/resources/classes/install_switch.php";
+				$switch = new install_switch;
+				$switch->create_config_lua();
 
 
 			//clear the session variables
 			//clear the session variables
 				unset($_SESSION['domain']);
 				unset($_SESSION['domain']);

+ 13 - 0
resources/functions.php

@@ -600,6 +600,19 @@
 	}
 	}
 	//echo realpath(sys_get_temp_dir());
 	//echo realpath(sys_get_temp_dir());
 
 
+	if ( !function_exists('normalize_path')) {
+		//don't use DIRECTORY_SEPARATOR as it will change on a per platform basis and we need consistency
+		function normalize_path($path) {
+			return str_replace(array('/','\\'), '/', $path);
+		}
+	}
+	
+	if ( !function_exists('normalize_path_to_os')) {
+		function normalize_path_to_os($path) {
+			return str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $path);
+		}
+	}
+
 	if (!function_exists('username_exists')) {
 	if (!function_exists('username_exists')) {
 		function username_exists($username) {
 		function username_exists($username) {
 			global $db, $domain_uuid;
 			global $db, $domain_uuid;