Bugfix batch

This commit is contained in:
Matthew Vale
2015-12-02 14:05:21 +00:00
parent bcfd71577c
commit de2cb97113
5 changed files with 115 additions and 96 deletions

View File

@@ -295,12 +295,10 @@ 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);
if($settings = null){
throw new Exception("Error global_settings came back with null");
}
$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";
$system = new install_fusionpbx($settings);
$system = new install_fusionpbx($global_settings);
$system->admin_username = $admin_username;
$system->admin_password = $admin_password;
$system->default_country = $install_default_country;
@@ -308,7 +306,7 @@ if(!$install_step) { $install_step = 'select_language'; }
$system->template_name = $install_template_name;
require_once "resources/classes/install_switch.php";
$switch = new install_switch($settings);
$switch = new install_switch($global_settings);
//$switch->debug = true;
//$system->debug = true;
$system->install();
@@ -320,7 +318,7 @@ if(!$install_step) { $install_step = 'select_language'; }
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, $detect_switch);
$system = new install_fusionpbx($global_settings);
$system->remove_config();
}catch(Exception $e){
echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";
@@ -330,7 +328,7 @@ if(!$install_step) { $install_step = 'select_language'; }
restore_error_handler();
if($install_ok){
echo "</pre>\n";
header("Location: ".PROJECT_PATH."/logout.php");
#header("Location: ".PROJECT_PATH."/logout.php");
$_SESSION['message'] = 'Install complete';
}else{
echo "<form method='post' name='frm' action=''>\n";

View File

@@ -141,7 +141,7 @@ require_once "resources/classes/EventSocket.php";
$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->_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());
}

View File

@@ -30,8 +30,8 @@ require_once "root.php";
class global_settings {
// cached data
protected $_dirs;
protected $_vdirs;
protected $_switch_dirs;
protected $_switch_vdirs;
public function get_switch_dirs() { return $this->_switch_dirs; }
public function get_switch_vdirs() { return $this->_switch_vdirs; }
@@ -116,25 +116,39 @@ require_once "root.php";
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, $domain_name, $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($detect_switch == null){
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);
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);
preg_match( '/^switch_.*_vdir$/', $vdir, $session_var);
$this->$vdir = $_SESSION['switch'][$session_var[0]]['dir'];
}
$this->switch_event_host = $_SESSION['event_socket_ip_address'];
@@ -142,8 +156,8 @@ require_once "root.php";
$this->switch_event_password = $_SESSION['event_socket_password'];
// domain info
$this->domain_name = $_SESSION['domain_name'];
$this->domain_uuid = $_SESSION['domain_uuid'];
$this->_domain_name = $_SESSION['domain_name'];
$this->_domain_uuid = $_SESSION['domain_uuid'];
// collect misc info
$this->domain_count = count($_SESSION["domains"]);
@@ -163,26 +177,33 @@ require_once "root.php";
}else{
//copy from detect_switch
foreach($detect_switch->switch_dirs() as $dir){
$t_dir = "_$dir";
foreach($detect_switch->get_dirs() as $dir){
$t_dir = "_switch_$dir";
$this->$t_dir = $detect_switch->$dir();
}
foreach($detect_switch->switch_vdirs() as $vdir){
$t_vdir = "_$vdir";
foreach($detect_switch->get_vdirs() as $vdir){
$t_vdir = "_switch_$vdir";
$this->$t_vdir = $detect_switch->$vdir();
}
//copy from _POST
foreach($_POST as $key=>$value){
if(substr($key,0,3) == "db_"){
$this->$key = $value;
$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($domain_uuid == null){ $domain_uuid = uuid(); }
$this->domain_name = $domain_name;
$this->domain_uuid = $domain_uuid;
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

View File

@@ -34,7 +34,7 @@ include "root.php";
protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
protected $dbh;
public function domain_uuid() { return $this->_domain_uuid; }
public function domain_uuid() { return $this->global_settings->domain_uuid(); }
public $debug = false;
@@ -46,10 +46,10 @@ include "root.php";
public $template_name = 'enhanced';
function __construct($global_settings) {
if($global_settings == null){
if(is_null($global_settings)){
require_once "resources/classes/global_settings.php";
$global_settings = new global_settings();
elseif(!is_a($global_settings, '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;
@@ -81,9 +81,14 @@ include "root.php";
ini_set('max_execution_time',3600);
$this->write_progress("Install started for FusionPBX");
$this->create_config_php();
$this->write_progress("\tExecuting config.php");
require $this->config_php;
global $db;
$db = $this->dbh;
$this->create_database();
$this->create_domain();
$this->create_superuser();
$this->write_progress("\tRunning requires");
require "resources/require.php";
$this->create_menus();
$this->write_progress("Install complete for FusionPBX");
@@ -135,12 +140,13 @@ include "root.php";
$tmp_config .= "\n";
$tmp_config .= " //mysql: database connection information\n";
if ($this->global_settings->db_type() == "mysql") {
if ($this->global_settings->db_host() == "localhost") {
$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.
//replace localhost with 127.0.0.1 so that it will connect using TCP
$this->global_settings->db_host() = "127.0.0.1";
$db_host = "127.0.0.1";
}
$tmp_config .= " \$db_host = '".$this->global_settings->db_host()."';\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";
@@ -156,7 +162,9 @@ include "root.php";
$tmp_config .= "\n";
$tmp_config .= " //pgsql: database connection information\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";
$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";
@@ -191,16 +199,7 @@ include "root.php";
}
protected function create_database() {
require $this->config_php;
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->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->global_settings->db_type();
$this->$function();
@@ -288,7 +287,6 @@ include "root.php";
//Attempt to create new PG role and database
$this->write_progress("\tCreating database");
try {
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 {
@@ -318,7 +316,6 @@ include "root.php";
$this->write_progress("\tInstalling data to database");
//open database connection with $this->global_settings->db_name()
try {
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 {
@@ -528,12 +525,14 @@ include "root.php";
$sql .= "limit 1";
$this->write_debug($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);
unset($sql, $prep_statement);
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'){
throw new Exception("Domain already exists but is disabled, this is unexpected");
}
@@ -547,13 +546,15 @@ include "root.php";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->_domain_uuid."', ";
$sql .= "'".$this->global_settings->domain_name."', ";
$sql .= "'' ";
$sql .= "'".$this->global_settings->domain_uuid()."', ";
$sql .= "'".$this->global_settings->domain_name()."', ";
$sql .= "'Default Domain' ";
$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);
//domain settings
@@ -596,73 +597,73 @@ include "root.php";
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->base_dir();
$tmp[$x]['value'] = $this->global_settings->switch_base_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'base';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->conf_dir();
$tmp[$x]['value'] = $this->global_settings->switch_conf_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'conf';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->db_dir()();
$tmp[$x]['value'] = $this->global_settings->switch_db_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'db';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->log_dir();
$tmp[$x]['value'] = $this->global_settings->switch_log_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'log';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->mod_dir();
$tmp[$x]['value'] = $this->global_settings->switch_mod_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'mod';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->script_dir();
$tmp[$x]['value'] = $this->global_settings->switch_script_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'scripts';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->grammar_dir();
$tmp[$x]['value'] = $this->global_settings->switch_grammar_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'grammar';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->storage_dir();
$tmp[$x]['value'] = $this->global_settings->switch_storage_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'storage';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->voicemail_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_voicemail_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'voicemail';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->recordings_dir();
$tmp[$x]['value'] = $this->global_settings->switch_recordings_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'recordings';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->sounds_dir();
$tmp[$x]['value'] = $this->global_settings->switch_sounds_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'sounds';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->phrases_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_phrases_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'phrases';
$tmp[$x]['enabled'] = 'true';
@@ -674,19 +675,19 @@ include "root.php";
$tmp[$x]['enabled'] = 'false';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->extensions_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_extensions_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'extensions';
$tmp[$x]['enabled'] = 'false';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->sip_profiles_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_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->global_settings->dialplan_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_dialplan_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'dialplan';
$tmp[$x]['enabled'] = 'false';
@@ -694,7 +695,7 @@ include "root.php";
//server settings
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->temp_dir();
$tmp[$x]['value'] = $this->global_settings->switch_temp_dir();
$tmp[$x]['category'] = 'server';
$tmp[$x]['subcategory'] = 'temp';
$tmp[$x]['enabled'] = 'true';
@@ -707,7 +708,7 @@ include "root.php";
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->backup_vdir();
$tmp[$x]['value'] = $this->global_settings->switch_backup_vdir();
$tmp[$x]['category'] = 'server';
$tmp[$x]['subcategory'] = 'backup';
$tmp[$x]['enabled'] = 'true';
@@ -825,7 +826,7 @@ include "root.php";
protected function create_superuser() {
$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 .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
$sql .= "and username = '".$this->admin_username."' ";
$sql .= "limit 1 ";
$this->write_debug($sql);
@@ -866,7 +867,7 @@ include "root.php";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->_domain_uuid."', ";
$sql .= "'".$this->global_settings->domain_uuid()."', ";
$sql .= "'".$this->admin_uuid."', ";
$sql .= "'$contact_uuid', ";
$sql .= "'".$this->admin_username."', ";
@@ -881,7 +882,7 @@ include "root.php";
}
$this->write_progress("\tChecking if superuser contact exists");
$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_nickname = '".$this->admin_username."' ";
$sql .= "limit 1 ";
@@ -900,7 +901,7 @@ include "root.php";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->_domain_uuid."', ";
$sql .= "'".$this->global_settings->domain_uuid()."', ";
$sql .= "'$contact_uuid', ";
$sql .= "'user', ";
$sql .= "'".$this->admin_username."', ";
@@ -911,7 +912,7 @@ include "root.php";
}
$this->write_progress("\tChecking if superuser is in the correct group");
$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 group_name = 'superadmin' ";
$sql .= "limit 1 ";
@@ -931,7 +932,7 @@ include "root.php";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$this->_domain_uuid."', ";
$sql .= "'".$this->global_settings->domain_uuid()."', ";
$sql .= "'".$this->admin_uuid."', ";
$sql .= "'superadmin' ";
$sql .= ");";
@@ -994,7 +995,7 @@ include "root.php";
//set needed session settings
$_SESSION["username"] = $this->admin_username;
$_SESSION["domain_uuid"] = $this->_domain_uuid;
$_SESSION["domain_uuid"] = $this->global_settings->domain_uuid();
require $this->config_php;
require "resources/require.php";
$_SESSION['event_socket_ip_address'] = $this->global_settings->event_host;

View File

@@ -35,10 +35,10 @@ include "root.php";
public $debug = false;
function __construct($global_settings) {
if($global_settings == null){
if(is_null($global_settings)){
require_once "resources/classes/global_settings.php";
$global_settings = new global_settings();
elseif(!is_a($global_settings, '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;
@@ -98,8 +98,8 @@ include "root.php";
}
}
//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) {
if (
substr_count($file_path_source, '/..') == 0 &&
@@ -197,14 +197,14 @@ include "root.php";
function copy_conf() {
$this->write_progress("\tCopying Config");
//make a backup of the config
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());
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
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()."'. ");
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
@@ -214,14 +214,14 @@ include "root.php";
else {
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
}
$dst_dir = $this->global_settings->conf_dir();
$dst_dir = $this->global_settings->switch_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->global_settings->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); }
$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->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); }
//create the dialplan/default.xml for single tenant or dialplan/domain.xml
@@ -229,7 +229,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->global_settings->conf_dir(), "/dialplan"));
$dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan"));
$dialplan->restore_advanced_xml();
if($this->_debug){
print_r($dialplan->result, $message);
@@ -243,7 +243,7 @@ include "root.php";
}
//write the switch.conf.xml file
if (file_exists($this->global_settings->conf_dir())) {
if (file_exists($this->global_settings->switch_conf_dir())) {
switch_conf_xml();
}
@@ -251,7 +251,7 @@ include "root.php";
function copy_scripts() {
$this->write_progress("\tCopying Scripts");
$script_dir = $this->global_settings->script_dir();
$script_dir = $this->global_settings->switch_script_dir();
if(strlen($script_dir) == 0) {
throw new Exception("Cannot copy scripts the 'script_dir' is empty");
}
@@ -271,7 +271,7 @@ include "root.php";
}
chmod($dst_dir, 0774);
}else{
$this->write_progress("\tSkipping scripts, scripts_dir is unset");
$this->write_progress("\tSkipping scripts, script_dir is unset");
}
}
@@ -332,8 +332,8 @@ include "root.php";
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_scripts_dir()) > 0) {
$tmp .= normalize_path_to_os(" scripts_dir = [[".$this->global_settings->switch_scripts_dir()."]];\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") {
@@ -357,7 +357,6 @@ include "root.php";
$tmp .= " database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\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";
}
@@ -403,7 +402,7 @@ include "root.php";
$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 .= " elseif (file_exists(script_dir..\"/resources/local.lua\")) then\n";
$tmp .= " require(\"resources.local\");\n";
$tmp .= " end\n";
fwrite($fout, $tmp);