소스 검색

restructured install to go via global_settings

added new global_settings to marshal settings used during a
install/upgrade
Matthew Vale 9 년 전
부모
커밋
6d13ed6ac0

+ 9 - 12
core/install/install_first_time.php

@@ -267,10 +267,10 @@ if(!$install_step) { $install_step = 'select_language'; }
 		//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>";
 		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;
 		try {
-			$switch_detect->detect();
+			$detect_switch->detect();
 		} catch(Exception $e){
 			echo "<p>Failed to detect configuration detect_switch reported: " . $e->getMessage() . "</p>\n";
 			$detect_ok = false;
@@ -294,34 +294,31 @@ if(!$install_step) { $install_step = 'select_language'; }
 			}
 			#set_error_handler("error_handler");
 			try {
+				require_once "resources/classes/global_settings.php";
+				$settings = new global_settings($detect_switch, $domain_name);
+
 				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($settings);
 				$system->admin_username = $admin_username;
 				$system->admin_password = $admin_password;
 				$system->default_country = $install_default_country;
 				$system->install_language = $install_language;
 				$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";
-				$switch = new install_switch($domain_name, $domain_uuid, $switch_detect);
+				$switch = new install_switch($settings);
 				//$switch->debug = true;
 				//$system->debug = true;
 				$system->install();
 				$switch->install();
 				$system->app_defaults();
-				$switch_detect->restart_switch();
+				$detect_switch->restart_switch();
 			}catch(Exception $e){
 				echo "</pre>\n";
 				echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
 				try {
 					require_once "resources/classes/install_fusionpbx.php";
-					$system = new install_fusionpbx($domain_name, $domain_uuid, $switch_detect);
+					$system = new install_fusionpbx($domain_name, $domain_uuid, $detect_switch);
 					$system->remove_config();
 				}catch(Exception $e){
 					echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";

+ 39 - 38
core/install/resources/classes/detect_switch.php

@@ -31,11 +31,19 @@ require_once "resources/classes/EventSocket.php";
 	class detect_switch {
 
 		// cached data
-		protected $_folders;
+		protected $_dirs;
+		protected $_vdirs;
+		public function get_dirs()	{ return $this->_dirs; }
+		public function get_vdirs()	{ return $this->_vdirs; }
+
 		// version information
 		protected $_major;
 		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; }
 
 		// dirs - detected by from the switch
 		protected $_base_dir = '';
@@ -55,30 +63,23 @@ require_once "resources/classes/EventSocket.php";
 		protected $_sounds_dir = '';
 		protected $_storage_dir = '';
 		protected $_temp_dir = '';
-
-		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; }
-		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_dirs() {	return $this->_dirs;	}
-		public function get_vdirs() {	return $this->_vdirs;	}
+		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 = '';
@@ -87,13 +88,12 @@ require_once "resources/classes/EventSocket.php";
 		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; }
+		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
 		public $event_host = 'localhost';
@@ -102,6 +102,7 @@ require_once "resources/classes/EventSocket.php";
 		protected $event_socket;
 
 		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_port){		$this->event_port = $event_port; }
 			if($event_password){	$this->event_password = $event_password; }
@@ -137,12 +138,12 @@ require_once "resources/classes/EventSocket.php";
 					$this->$field = normalize_path($matches[2]);
 				}
 			}
-			$this->_voicemail_vdir = normalize_path(join( DIRECTORY_SEPARATOR, array($this->_storage_dir, "voicemail")));
-			$this->_phrases_vdir = normalize_path(join( DIRECTORY_SEPARATOR, array($this->_conf_dir, "lang")));
-			$this->_extensions_vdir = normalize_path(join( DIRECTORY_SEPARATOR, array($this->_conf_dir, "directory")));
-			$this->_sip_profiles_vdir = normalize_path(join( DIRECTORY_SEPARATOR, array($this->_conf_dir, "sip_profiles")));
-			$this->_dialplan_vdir = normalize_path(join( DIRECTORY_SEPARATOR, array($this->_conf_dir, "dialplan")));
-			$this->_backup_vdir = normalize_path(sys_get_temp_dir());
+			$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(){

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

@@ -0,0 +1,192 @@
+<?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 $_dirs;
+		protected $_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_count;
+		public function domain_count()	 		{return $this->_domain_count; }
+
+		public function __construct($detect_switch, $domain_name, $domain_uuid) {
+			$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($detect_switch == null){
+				//take settings from session
+				foreach ($this->_switch_dirs as $dir){
+					$session_var;
+					preg_match( '^switch_.*_dir$', $dir, $session_var);
+					$this->$dir = $_SESSION['switch'][$session_var[0]]['dir'];
+				}
+				foreach ($this->_switch_vdirs as $vdir){
+					$session_var;
+					preg_match( '^switch_.*_vdir$', $vdir, $session_var);
+					$this->$vdir = $_SESSION['switch'][$session_var[0]]['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->switch_dirs() as $dir){
+					$t_dir = "_$dir";
+					$this->$t_dir = $detect_switch->$dir();
+				}
+				foreach($detect_switch->switch_vdirs() as $vdir){
+					$t_vdir = "_$vdir";
+					$this->$t_vdir = $detect_switch->$vdir();
+				}
+
+				//copy from _POST
+				foreach($_POST as $key=>$value){
+					if(substr($key,0,3) == "db_"){
+						$this->$key = $value;
+					}
+				}
+
+				// domain info
+				if($domain_uuid == null){ $domain_uuid = uuid(); }
+				$this->domain_name = $domain_name;
+				$this->domain_uuid = $domain_uuid;
+
+				//collect misc info
+				$this->_domain_count = 1;	//assumed to be one
+			}
+		}
+	}
+?>

+ 114 - 129
core/install/resources/classes/install_fusionpbx.php

@@ -29,9 +29,7 @@ include "root.php";
 //define the install class
 	class install_fusionpbx {
 
-		protected $_domain_uuid;
-		protected $domain_name;
-		protected $detect_switch;
+		protected $global_settings;
 		protected $config_php;
 		protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
 		protected $dbh;
@@ -47,25 +45,11 @@ include "root.php";
 	 	public $default_country = 'US';
 		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;
-		public $db_create;
-		public $db_create_username;
-		public $db_create_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_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")){
 				$this->config_php = "/etc/fusionpbx/config.php";
 			} elseif (is_dir("/usr/local/etc/fusionpbx")){
@@ -138,26 +122,26 @@ include "root.php";
 			$tmp_config .= "//-----------------------------------------------------\n";
 			$tmp_config .= "\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";
-			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 .= "		\$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 .= "	//mysql: database connection information\n";
-			if ($this->db_type == "mysql") {
-				if ($this->db_host == "localhost") {
+			if ($this->global_settings->db_type() == "mysql") {
+				if ($this->global_settings->db_host() == "localhost") {
 					//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
-					$this->db_host = "127.0.0.1";
+					$this->global_settings->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 = '".$this->global_settings->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 {
 				$tmp_config .= "		//\$db_host = '';\n";
@@ -168,19 +152,19 @@ include "root.php";
 			}
 			$tmp_config .= "\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") {
+				$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";
 			}
 			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 .= "	//show errors\n";
@@ -205,23 +189,24 @@ include "root.php";
 
 		protected function create_database() {
 			require $this->config_php;
-			$this->write_progress("\tUsing database as type " . $this->db_type);
-			if($this->db_create and strlen($this->db_create_username) == 0)
+			global $db;
+			$db = $this->dbh;
+
+			$this->write_progress("\tUsing database as type " . $this->global_settings->db_type());
+			if($this->global_settings->db_create() and strlen($this->global_settings->db_create_username()) == 0)
 			{
-				$this->db_create_username = $this->db_username;
-				$this->db_create_password = $this->db_password;
+				$this->global_settings->db_create_username() = $this->global_settings->db_username();
+				$this->global_settings->db_create_password() = $this->global_settings->db_password();
 			}
-			$function = "create_database_" . $this->db_type;
+			$function = "create_database_" . $this->global_settings->db_type();
 			$this->$function();
-			global $db;
-			$db = $this->dbh;
 
 			//sqlite is natively supported under all known OS'es
-			if($this->db_type != 'sqlite'){
+			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->db_type != 'pgsql'){
+				}elseif($this->global_settings->db_type() != 'pgsql'){
 				//switch supports postgresql natively
 					$this->create_odbc_database_connection();
 				}
@@ -236,7 +221,7 @@ include "root.php";
 		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
 			try {
-				$this->dbh = new PDO('sqlite:'.$this->db_path.'/'.$this->db_name); //sqlite 3
+				$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) {
@@ -258,7 +243,7 @@ include "root.php";
 			require_once "resources/classes/schema.php";
 			$schema = new schema;
 			$schema->db = $this->dbh;
-			$schema->db_type = $this->db_type;
+			$schema->db_type = $this->global_settings->db_type();
 			$schema->sql();
 			$schema->exec();
 
@@ -292,34 +277,34 @@ include "root.php";
 			$this->dbh->commit();
 
 		//set the file permissions
-			chmod($this->db_path.'/'.$this->db_name, 0777);
+			chmod($this->global_settings->db_path().'/'.$this->global_settings->db_name(), 0777);
 		}
 
 		protected function create_database_pgsql() {
-			if ($this->db_create) {
+			if ($this->global_settings->db_create()) {
 			//Attempt to create new PG role and database
 				$this->write_progress("\tCreating database");
 				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");
+					if (strlen($this->global_settings->db_port()) == 0) { $this->global_settings->db_port() = "5432"; }
+					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->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
+						$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());
 				}
 
 				//create the database, user, grant perms
-				if($this->dbh->exec("CREATE DATABASE {$this->db_name}") === false) {
-					throw new Exception("Failed to create database {$this->db_name}: " . join(":", $this->dbh->errorInfo()));
+				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->db_username != $this->db_create_username){
-					if($this->dbh->exec("CREATE USER {$this->db_username} WITH PASSWORD '{$this->db_password}'") === false){
-						throw new Exception("Failed to create user {$this->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()));
 					}
-					if($this->dbh->exec("GRANT ALL ON {$this->db_name} TO {$this->db_username}") === false){
-						throw new Exception("Failed to create user {$this->db_name}: " . join(":", $this->dbh->errorInfo()));
+					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()));
 					}
 				}
 
@@ -328,13 +313,13 @@ include "root.php";
 			}
 
 			$this->write_progress("\tInstalling data to database");				
-		//open database connection with $this->db_name
+		//open database connection with $this->global_settings->db_name()
 			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}");
+				if (strlen($this->global_settings->db_port()) == 0) { $this->global_settings->db_port() = "5432"; }
+				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->db_port} user={$this->db_username} password={$this->db_password} dbname={$this->db_name}");
+					$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) {
@@ -346,7 +331,7 @@ include "root.php";
 			require_once "resources/classes/schema.php";
 			$schema = new schema;
 			$schema->db = $this->dbh;
-			$schema->db_type = $this->db_type;
+			$schema->db_type = $this->global_settings->db_type();
 			$schema->sql();
 			$schema->exec();
 
@@ -382,23 +367,23 @@ include "root.php";
 		protected function create_database_mysql() {
 				//database connection
 					$connect_string;
-					if (strlen($this->db_host) == 0 && strlen($this->db_port) == 0) {
+					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->db_host;unix_socket=/var/run/mysqld/mysqld.sock;";
+						$connect_string = "mysql:host=$this->global_settings->db_host();unix_socket=/var/run/mysqld/mysqld.sock;";
 					}
-					elseif (strlen($this->db_port) == 0) {
+					elseif (strlen($this->global_settings->db_port()) == 0) {
 						//leave out port if it is empty
-						$connect_string = "mysql:host=$this->db_host;";
+						$connect_string = "mysql:host=$this->global_settings->db_host();";
 					}
 					else {
-						$connect_string = "mysql:host=$this->db_host;port=$this->db_port;";
+						$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
-					if ($this->db_create) {
+					if ($this->global_settings->db_create()) {
 						$this->write_progress("\tCreating database");				
 						try {
-							$this->dbh = new PDO($connect_string, $this->db_create_username, db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+							$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);
 						}
@@ -415,7 +400,7 @@ include "root.php";
 
 						//create user and set the permissions
 							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);
 							}
 							catch (PDOException $error) {
@@ -424,20 +409,20 @@ include "root.php";
 
 						//set account to unlimited use
 							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; ";
 									$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; ";
 									$this->dbh->query($tmp_sql);
 								}
 								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; ";
 									$this->dbh->query($tmp_sql);
 								}
@@ -448,7 +433,7 @@ include "root.php";
 
 						//create the database and set the create user with permissions
 							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);
 							}
 							catch (PDOException $error) {
@@ -457,7 +442,7 @@ include "root.php";
 
 						//set user permissions
 							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) {
 								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
@@ -472,12 +457,12 @@ include "root.php";
 								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
 							}
 							$this->dbh = null;
-					} //if (strlen($this->db_create_username) > 0)
+					} //if (strlen($this->global_settings->db_create_username()) > 0)
 
 				$this->write_progress("\tInstalling data to database");
 				//select the database
 					try {
-						$this->dbh = new PDO($connect_string, $this->db_username, db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+						$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);
 					}
@@ -485,7 +470,7 @@ include "root.php";
 						throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql );
 					}
 					try {
-						$this->dbh->query("USE ".$this->db_name.";");
+						$this->dbh->query("USE ".$this->global_settings->db_name().";");
 					}
 					catch (PDOException $error) {
 						throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
@@ -495,7 +480,7 @@ include "root.php";
 					require_once "resources/classes/schema.php";
 					$schema = new schema;
 					$schema->db = $this->dbh;
-					$schema->db_type = $this->db_type;
+					$schema->db_type = $this->global_settings->db_type();
 					$schema->sql();
 					$schema->exec();
 
@@ -534,9 +519,9 @@ include "root.php";
 		}
 
 		protected function create_domain() {
-			$this->write_progress("\tChecking if domain exists '" . $this->domain_name . "'");
+			$this->write_progress("\tChecking if domain exists '" . $this->global_settings->domain_name . "'");
 			$sql = "select * from v_domains ";
-			$sql .= "where domain_name = '".$this->domain_name."' ";
+			$sql .= "where domain_name = '".$this->global_settings->domain_name."' ";
 			$sql .= "limit 1";
 			$this->write_debug($sql);
 			$prep_statement = $this->dbh->prepare(check_sql($sql));
@@ -560,7 +545,7 @@ include "root.php";
 				$sql .= "values ";
 				$sql .= "(";
 				$sql .= "'".$this->_domain_uuid."', ";
-				$sql .= "'".$this->domain_name."', ";
+				$sql .= "'".$this->global_settings->domain_name."', ";
 				$sql .= "'' ";
 				$sql .= ");";
 
@@ -608,73 +593,73 @@ include "root.php";
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->base_dir();
+				$tmp[$x]['value'] = $this->global_settings->base_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'base';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->conf_dir();
+				$tmp[$x]['value'] = $this->global_settings->conf_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'conf';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->db_dir();
+				$tmp[$x]['value'] = $this->global_settings->db_dir()();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'db';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->log_dir();
+				$tmp[$x]['value'] = $this->global_settings->log_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'log';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->mod_dir();
+				$tmp[$x]['value'] = $this->global_settings->mod_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'mod';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->script_dir();
+				$tmp[$x]['value'] = $this->global_settings->script_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'scripts';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->grammar_dir();
+				$tmp[$x]['value'] = $this->global_settings->grammar_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'grammar';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->storage_dir();
+				$tmp[$x]['value'] = $this->global_settings->storage_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'storage';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->voicemail_vdir();
+				$tmp[$x]['value'] = $this->global_settings->voicemail_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'voicemail';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->recordings_dir();
+				$tmp[$x]['value'] = $this->global_settings->recordings_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'recordings';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->sounds_dir();
+				$tmp[$x]['value'] = $this->global_settings->sounds_dir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'sounds';
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->phrases_vdir();
+				$tmp[$x]['value'] = $this->global_settings->phrases_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'phrases';
 				$tmp[$x]['enabled'] = 'true';
@@ -686,19 +671,19 @@ include "root.php";
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->extensions_vdir();
+				$tmp[$x]['value'] = $this->global_settings->extensions_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'extensions';
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->sip_profiles_vdir();
+				$tmp[$x]['value'] = $this->global_settings->sip_profiles_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'sip_profiles';
 				$tmp[$x]['enabled'] = 'false';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->dialplan_vdir();
+				$tmp[$x]['value'] = $this->global_settings->dialplan_vdir();
 				$tmp[$x]['category'] = 'switch';
 				$tmp[$x]['subcategory'] = 'dialplan';
 				$tmp[$x]['enabled'] = 'false';
@@ -706,7 +691,7 @@ include "root.php";
 
 				//server settings
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->temp_dir();
+				$tmp[$x]['value'] = $this->global_settings->temp_dir();
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['subcategory'] = 'temp';
 				$tmp[$x]['enabled'] = 'true';
@@ -719,7 +704,7 @@ include "root.php";
 				$tmp[$x]['enabled'] = 'true';
 				$x++;
 				$tmp[$x]['name'] = 'dir';
-				$tmp[$x]['value'] = $this->detect_switch->backup_vdir();
+				$tmp[$x]['value'] = $this->global_settings->backup_vdir();
 				$tmp[$x]['category'] = 'server';
 				$tmp[$x]['subcategory'] = 'backup';
 				$tmp[$x]['enabled'] = 'true';
@@ -835,7 +820,7 @@ include "root.php";
 		}
 
 		protected function create_superuser() {
-			$this->write_progress("\tChecking if superuser exists '" . $this->domain_name . "'");
+			$this->write_progress("\tChecking if superuser exists '" . $this->global_settings->domain_name . "'");
 			$sql = "select * from v_users ";
 			$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
 			$sql .= "and username = '".$this->admin_username."' ";
@@ -1009,16 +994,16 @@ include "root.php";
 			$_SESSION["domain_uuid"] = $this->_domain_uuid;
 			require $this->config_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"]
 			$sql = "SELECT * FROM v_group_users ";
 			$sql .= "where domain_uuid=:domain_uuid ";
 			$sql .= "and user_uuid=:user_uuid ";
 			$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->execute();
 			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@@ -1031,10 +1016,10 @@ include "root.php";
 			foreach($_SESSION["groups"] as $field) {
 				if (strlen($field['group_name']) > 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 {
-						$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++;
 				}
@@ -1045,13 +1030,13 @@ include "root.php";
 			unset($sql, $prep_statement_sub);
 
 		//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
 			require_once "resources/classes/schema.php";

+ 55 - 60
core/install/resources/classes/install_switch.php

@@ -28,34 +28,25 @@ include "root.php";
 //define the install class
 	class install_switch {
 
-		protected $domain_uuid;
-		protected $domain_name;
-		protected $detect_switch;
+		protected $global_settings;
 		protected $config_lua;
+		protected $dbh;
 
 		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_a($global_settings, 'global_settings')){
+				throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
 			}
-			$this->domain_uuid = $domain_uuid;
-			$this->domain = $domain_name;
-			$this->detect_switch = $detect_switch;
+			$this->global_settings = $global_settings;
 			if (is_dir("/etc/fusionpbx")){
 				$this->config_lua = "/etc/fusionpbx/config.lua";
-			} elseif (is_dir("/usr/local/etc/fusionpbx")){
+			}elseif (is_dir("/usr/local/etc/fusionpbx")){
 				$this->config_lua = "/usr/local/etc/fusionpbx/config.lua";
-			}
-			else {
-				$this->config_lua = $this->detect_switch->script_dir."/resources/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->config_lua = normalize_path_to_os($this->config_lua);
 		}
@@ -91,6 +82,7 @@ include "root.php";
 				exec("xcopy /E /Y \"$src\" \"$dst\"");
 			}
 			else {
+				throw new Exception('Could not perform copy operation on this platform, implementation missing');
 				$dir = opendir($src);
 				if (!$dir) {
 					if (!mkdir($src, 0755, true)) {
@@ -202,14 +194,14 @@ include "root.php";
 		function copy_conf() {
 			$this->write_progress("\tCopying 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->conf_dir())) {
+					$this->backup_dir($this->global_settings->conf_dir(), 'fusionpbx_switch_config');
+					$this->recursive_delete($this->global_settings->conf_dir());
 				}
 			//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->conf_dir())) {
+					if (!mkdir($this->global_settings->conf_dir(), 0774, true)) {
+						throw new Exception("Failed to create the switch conf directory '".$this->global_settings->conf_dir()."'. ");
 					}
 				}
 			//copy resources/templates/conf to the freeswitch conf dir
@@ -219,14 +211,14 @@ include "root.php";
 				else {
 					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
 				}
-				$dst_dir = $this->detect_switch->conf_dir();
+				$dst_dir = $this->global_settings->conf_dir();
 				if (is_readable($dst_dir)) {
 					$this->recursive_copy($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->storage_dir(), 'fax'));
 				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->storage_dir(), 'voicemail'));
 				if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
 			
 			//create the dialplan/default.xml for single tenant or dialplan/domain.xml
@@ -234,7 +226,7 @@ include "root.php";
 					$dialplan = new dialplan;
 					$dialplan->domain_uuid = $this->domain_uuid;
 					$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->conf_dir(), "/dialplan"));
 					$dialplan->restore_advanced_xml();
 					if($this->_debug){
 						print_r($dialplan->result, $message);
@@ -248,7 +240,7 @@ include "root.php";
 				}
 
 			//write the switch.conf.xml file
-				if (file_exists($this->detect_switch->conf_dir())) {
+				if (file_exists($this->global_settings->conf_dir())) {
 					switch_conf_xml();
 				}
 
@@ -256,7 +248,10 @@ include "root.php";
 
 		function copy_scripts() {
 			$this->write_progress("\tCopying Scripts");
-			$script_dir = $this->detect_switch->script_dir();
+			$script_dir = $this->global_settings->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('/usr/share/examples/fusionpbx/resources/install/scripts')){
 					$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
@@ -312,30 +307,30 @@ include "root.php";
 		//config.lua
 			$fout = fopen($this->config_lua,"w");
 			if(!$fout){
-				throw new Exception("Failed to open '{$this->config_lua}' for writing");
+				throw new Exception("Failed to open '".$this->config_lua."' for writing");
 			}
 			$tmp = "\n";
 			$tmp .= "--set the variables\n";
-			if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\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($_SESSION['switch']['phrases']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	phrases_dir = [[".$_SESSION['switch']['phrases']['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($_SESSION['switch']['db']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	database_dir = [[".$_SESSION['switch']['db']['dir']."]];\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($_SESSION['switch']['recordings']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	recordings_dir = [[".$_SESSION['switch']['recordings']['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($_SESSION['switch']['storage']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	storage_dir = [[".$_SESSION['switch']['storage']['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($_SESSION['switch']['voicemail']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	voicemail_dir = [[".$_SESSION['switch']['voicemail']['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($_SESSION['switch']['scripts']['dir']) > 0) {
-				$tmp .= normalize_path_to_os("	scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n");
+			if (strlen($this->global_settings->switch_scripts_dir()) > 0) {
+				$tmp .= normalize_path_to_os("	scripts_dir = [[".$this->global_settings->switch_scripts_dir()."]];\n");
 			}
 			$tmp .= normalize_path_to_os("	php_dir = [[".PHP_BINDIR."]];\n");
 			if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
@@ -347,27 +342,27 @@ include "root.php";
 			$tmp .= normalize_path_to_os("	document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
 			$tmp .= "\n";
 
-			if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) {
+			if ((strlen($this->global_settings->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 .= normalize_path_to_os("	database[\"path\"] = [[".$db_path."]];\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 ($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 ($this->global_settings->db_type() == "pgsql") {
+					if ($this->global_settings->db_host() == "localhost") { $this->global_settings->db_host() = "127.0.0.1"; }
+					$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 ($db_type == "sqlite") {
-					$tmp .= "	database[\"system\"] = \"sqlite://".$db_path."/".$db_name."\";\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 ($db_type == "mysql") {
+				elseif ($this->global_settings->db_type() == "mysql") {
 					$tmp .= "	database[\"system\"] = \"\";\n";
 					$tmp .= "	database[\"switch\"] = \"\";\n";
 				}
@@ -393,8 +388,8 @@ include "root.php";
 			$tmp .= "	debug[\"cache\"] = false;\n";
 			$tmp .= "\n";
 			$tmp .= "--additional info\n";
-			$tmp .= "	domain_count = ".count($_SESSION["domains"]).";\n";
-			$tmp .= normalize_path_to_os("	temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\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";
 			}