|
@@ -29,40 +29,27 @@ 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;
|
|
|
|
|
|
- public function domain_uuid() { return $this->_domain_uuid; }
|
|
|
-
|
|
|
public $debug = false;
|
|
|
|
|
|
- public $install_msg;
|
|
|
public $install_language = 'en-us';
|
|
|
public $admin_username;
|
|
|
public $admin_password;
|
|
|
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;
|
|
|
-
|
|
|
- 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")){
|
|
|
$this->config_php = "/etc/fusionpbx/config.php";
|
|
|
} elseif (is_dir("/usr/local/etc/fusionpbx")){
|
|
@@ -74,6 +61,7 @@ include "root.php";
|
|
|
else {
|
|
|
$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) {
|
|
@@ -88,15 +76,28 @@ include "root.php";
|
|
|
|
|
|
function install() {
|
|
|
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->app_defaults();
|
|
|
+ $this->write_progress("Install complete for FusionPBX");
|
|
|
+ }
|
|
|
+
|
|
|
+ function upgrade() {
|
|
|
+ $this->app_defaults();
|
|
|
}
|
|
|
|
|
|
protected function create_config_php() {
|
|
|
+ $this->write_progress("\tCreating " . $this->config_php);
|
|
|
$tmp_config = "<?php\n";
|
|
|
$tmp_config .= "/* \$Id\$ */\n";
|
|
|
$tmp_config .= "/*\n";
|
|
@@ -131,26 +132,27 @@ 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") {
|
|
|
+ $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->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 {
|
|
|
$tmp_config .= " //\$db_host = '';\n";
|
|
@@ -161,19 +163,21 @@ 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") {
|
|
|
+ $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 {
|
|
|
- $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";
|
|
@@ -190,7 +194,6 @@ include "root.php";
|
|
|
) {
|
|
|
throw new Exception("cannot write to '" . $this->config_php . "'" );
|
|
|
}
|
|
|
- $this->write_progress("Creating " . $this->config_php);
|
|
|
$fout = fopen($this->config_php,"w");
|
|
|
fwrite($fout, $tmp_config);
|
|
|
unset($tmp_config);
|
|
@@ -198,255 +201,283 @@ include "root.php";
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
- 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() {
|
|
|
- //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 {
|
|
|
- $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) {
|
|
|
- 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 {
|
|
|
- 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) {
|
|
|
- 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() {
|
|
|
//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
|
|
|
- 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
|
|
|
try {
|
|
|
$this->dbh->query("USE mysql;");
|
|
|
}
|
|
|
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
|
|
|
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) {
|
|
|
- if ($this->debug) {
|
|
|
- print "error: " . $error->getMessage() . "<br/>";
|
|
|
- }
|
|
|
+ throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
|
|
|
}
|
|
|
|
|
|
//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);
|
|
|
}
|
|
|
}
|
|
|
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
|
|
|
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) {
|
|
|
- if ($this->debug) {
|
|
|
- print "error: " . $error->getMessage() . "<br/>";
|
|
|
- }
|
|
|
+ throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
|
|
|
}
|
|
|
|
|
|
//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) {
|
|
|
- if ($this->debug) {
|
|
|
- print "error: " . $error->getMessage() . "<br/>";
|
|
|
- }
|
|
|
+ throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
|
|
|
}
|
|
|
|
|
|
//make the changes active
|
|
@@ -455,28 +486,33 @@ include "root.php";
|
|
|
$this->dbh->query($tmp_sql);
|
|
|
}
|
|
|
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
|
|
|
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) {
|
|
|
- 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
|
|
|
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();
|
|
|
|
|
@@ -515,23 +551,25 @@ include "root.php";
|
|
|
}
|
|
|
|
|
|
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 .= "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));
|
|
|
- $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");
|
|
|
}
|
|
|
} else {
|
|
|
- $this->write_progress("... creating domain");
|
|
|
+ $this->write_progress("\t... creating domain");
|
|
|
$sql = "insert into v_domains ";
|
|
|
$sql .= "(";
|
|
|
$sql .= "domain_uuid, ";
|
|
@@ -540,13 +578,15 @@ include "root.php";
|
|
|
$sql .= ") ";
|
|
|
$sql .= "values ";
|
|
|
$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 .= ");";
|
|
|
|
|
|
$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
|
|
@@ -589,91 +629,97 @@ 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->switch_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->switch_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->switch_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->switch_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->switch_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->switch_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->switch_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->switch_storage_dir();
|
|
|
$tmp[$x]['category'] = 'switch';
|
|
|
$tmp[$x]['subcategory'] = 'storage';
|
|
|
$tmp[$x]['enabled'] = 'true';
|
|
|
$x++;
|
|
|
$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]['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->switch_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->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->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]['category'] = 'switch';
|
|
|
$tmp[$x]['subcategory'] = 'provision';
|
|
|
$tmp[$x]['enabled'] = 'false';
|
|
|
$x++;
|
|
|
$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]['subcategory'] = 'extensions';
|
|
|
$tmp[$x]['enabled'] = 'false';
|
|
|
$x++;
|
|
|
$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]['subcategory'] = 'sip_profiles';
|
|
|
$tmp[$x]['enabled'] = 'false';
|
|
|
$x++;
|
|
|
$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]['subcategory'] = 'dialplan';
|
|
|
$tmp[$x]['enabled'] = 'false';
|
|
@@ -681,7 +727,7 @@ include "root.php";
|
|
|
|
|
|
//server settings
|
|
|
$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]['subcategory'] = 'temp';
|
|
|
$tmp[$x]['enabled'] = 'true';
|
|
@@ -694,7 +740,7 @@ include "root.php";
|
|
|
$tmp[$x]['enabled'] = 'true';
|
|
|
$x++;
|
|
|
$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]['subcategory'] = 'backup';
|
|
|
$tmp[$x]['enabled'] = 'true';
|
|
@@ -810,9 +856,9 @@ include "root.php";
|
|
|
}
|
|
|
|
|
|
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 .= "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);
|
|
@@ -831,7 +877,7 @@ include "root.php";
|
|
|
$this->write_debug($sql);
|
|
|
$this->dbh->exec(check_sql($sql));
|
|
|
}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
|
|
|
//prepare the values
|
|
|
$this->admin_uuid = uuid();
|
|
@@ -853,7 +899,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."', ";
|
|
@@ -866,9 +912,9 @@ include "root.php";
|
|
|
$this->dbh->exec(check_sql($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 .= "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 ";
|
|
@@ -887,7 +933,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."', ";
|
|
@@ -896,9 +942,9 @@ include "root.php";
|
|
|
$this->dbh->exec(check_sql($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 .= "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 ";
|
|
@@ -918,7 +964,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 .= ");";
|
|
@@ -929,13 +975,13 @@ include "root.php";
|
|
|
}
|
|
|
|
|
|
protected function create_menus() {
|
|
|
- $this->write_progress("Creating menus");
|
|
|
+ $this->write_progress("\tCreating menus");
|
|
|
//set the defaults
|
|
|
$menu_name = 'default';
|
|
|
$menu_language = 'en-us';
|
|
|
$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 .= "where menu_uuid = '".$this->menu_uuid."' ";
|
|
|
$sql .= "limit 1 ";
|
|
@@ -945,7 +991,7 @@ include "root.php";
|
|
|
$result = $prep_statement->fetch(PDO::FETCH_NAMED);
|
|
|
unset($sql, $prep_statement);
|
|
|
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 .= "(";
|
|
|
$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
|
|
|
$_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->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);
|
|
@@ -1006,10 +1052,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++;
|
|
|
}
|
|
@@ -1020,13 +1066,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";
|