Rename install_first_time variable and file name. Remove the install/upgrade_switch.php which isn't being used anymore. Update the indentation and remove inconsistent white spaces.
This commit is contained in:
parent
f32d99377f
commit
03897edf95
|
|
@ -207,7 +207,7 @@ else {
|
||||||
$label = $text['label-11d'];
|
$label = $text['label-11d'];
|
||||||
$abbrv = "11d";
|
$abbrv = "11d";
|
||||||
break;
|
break;
|
||||||
case "^(?:\+1|1)?([2-9]\d\d[2-9]\d{6})$":
|
case "^(?:\+?1)?(\d{10})$":
|
||||||
$label = $text['label-north-america'];
|
$label = $text['label-north-america'];
|
||||||
$abbrv = "10-11d";
|
$abbrv = "10-11d";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -29,19 +29,18 @@ require_once "resources/require.php";
|
||||||
require_once "resources/check_auth.php";
|
require_once "resources/check_auth.php";
|
||||||
|
|
||||||
//detect install state
|
//detect install state
|
||||||
|
$install_enabled = true;
|
||||||
$first_time_install = true;
|
|
||||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
||||||
//linux
|
//linux
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($first_time_install) {
|
if($install_enabled) {
|
||||||
header("Location: ".PROJECT_PATH."/core/install/install_first_time.php");
|
header("Location: ".PROJECT_PATH."/core/install/install.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
require_once "resources/check_auth.php";
|
require_once "resources/check_auth.php";
|
||||||
|
|
|
||||||
|
|
@ -77,16 +77,16 @@ if (is_link('/etc/localtime')) {
|
||||||
date_default_timezone_set($timezone);
|
date_default_timezone_set($timezone);
|
||||||
|
|
||||||
//detect install state
|
//detect install state
|
||||||
$first_time_install = true;
|
$install_enabled = true;
|
||||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
} elseif (file_exists("/etc/fusionpbx/config.php")) {
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
|
||||||
$first_time_install = false;
|
$install_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$first_time_install) {
|
if(!$install_enabled) {
|
||||||
require_once "resources/require.php";
|
require_once "resources/require.php";
|
||||||
require_once "resources/check_auth.php";
|
require_once "resources/check_auth.php";
|
||||||
if (!if_group("superadmin")) {
|
if (!if_group("superadmin")) {
|
||||||
|
|
@ -132,7 +132,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//set a default enviroment if first_time
|
//set a default enviroment if first_time
|
||||||
if($first_time_install){
|
if($install_enabled){
|
||||||
//initialize some varibles to cut down on warnings
|
//initialize some varibles to cut down on warnings
|
||||||
$_SESSION['message'] = '';
|
$_SESSION['message'] = '';
|
||||||
$v_link_label_play = '';
|
$v_link_label_play = '';
|
||||||
|
|
@ -183,10 +183,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
if ( count($messages) > $existing_errors) { $install_step = 'config_detail'; }
|
if ( count($messages) > $existing_errors) { $install_step = 'config_detail'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if($install_step =='execute')
|
if($install_step =='execute') {
|
||||||
{
|
|
||||||
//start the rocket launch!
|
|
||||||
|
|
||||||
//set the max execution time to 1 hour
|
//set the max execution time to 1 hour
|
||||||
ini_set('max_execution_time',3600);
|
ini_set('max_execution_time',3600);
|
||||||
}
|
}
|
||||||
|
|
@ -224,7 +221,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n";
|
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n";
|
||||||
echo " </div>\n";
|
echo " </div>\n";
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
}elseif($install_step == 'detect_config'){
|
} elseif($install_step == 'detect_config'){
|
||||||
if(!($event_host == '' || $event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1' )){
|
if(!($event_host == '' || $event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1' )){
|
||||||
echo "<p><b>Warning</b> you have choosen a value other than localhost for event_host, this is unsoported at present</p>\n";
|
echo "<p><b>Warning</b> you have choosen a value other than localhost for event_host, this is unsoported at present</p>\n";
|
||||||
}
|
}
|
||||||
|
|
@ -242,7 +239,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n";
|
echo " <button type='submit' id='next'>".$text['button-next']."</button>\n";
|
||||||
echo " </div>\n";
|
echo " </div>\n";
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
}else{
|
} else {
|
||||||
echo "<form method='post' name='frm' action=''>\n";
|
echo "<form method='post' name='frm' action=''>\n";
|
||||||
echo " <div style='text-align:right'>\n";
|
echo " <div style='text-align:right'>\n";
|
||||||
echo " <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
|
echo " <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
|
||||||
|
|
@ -315,14 +312,14 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
$switch->install_phase_1();
|
$switch->install_phase_1();
|
||||||
$system->install_phase_2();
|
$system->install_phase_2();
|
||||||
$switch->install_phase_2();
|
$switch->install_phase_2();
|
||||||
}catch(Exception $e){
|
} catch(Exception $e){
|
||||||
echo "</pre>\n";
|
echo "</pre>\n";
|
||||||
echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
|
echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
|
||||||
try {
|
try {
|
||||||
require_once "resources/classes/install_fusionpbx.php";
|
require_once "resources/classes/install_fusionpbx.php";
|
||||||
$system = new install_fusionpbx($global_settings);
|
$system = new install_fusionpbx($global_settings);
|
||||||
$system->remove_config();
|
$system->remove_config();
|
||||||
}catch(Exception $e){
|
} catch(Exception $e){
|
||||||
echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";
|
echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";
|
||||||
}
|
}
|
||||||
$install_ok = false;
|
$install_ok = false;
|
||||||
|
|
@ -345,14 +342,14 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||||
echo "<p>Unkown install_step '$install_step'</p>\n";
|
echo "<p>Unkown install_step '$install_step'</p>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($first_time_install){
|
if($install_enabled){
|
||||||
//grab the default theme
|
//grab the default theme
|
||||||
$set_session_theme = 1;
|
$set_session_theme = 1;
|
||||||
$domains_processed = 1;
|
$domains_processed = 1;
|
||||||
include "themes/enhanced/app_defaults.php";
|
include "themes/enhanced/app_defaults.php";
|
||||||
unset($set_session_theme, $domains_processed);
|
unset($set_session_theme, $domains_processed);
|
||||||
//initialize some defaults so we can be 'logged in'
|
//initialize some defaults so we can be 'logged in'
|
||||||
$_SESSION['username'] = 'first_time_install';
|
$_SESSION['username'] = 'install_enabled';
|
||||||
$_SESSION['permissions'][]['permission_name'] = 'superadmin';
|
$_SESSION['permissions'][]['permission_name'] = 'superadmin';
|
||||||
$_SESSION['menu'] = '';
|
$_SESSION['menu'] = '';
|
||||||
}
|
}
|
||||||
|
|
@ -37,13 +37,13 @@ include "root.php";
|
||||||
public $debug = false;
|
public $debug = false;
|
||||||
public $echo_progress = false;
|
public $echo_progress = false;
|
||||||
|
|
||||||
public $install_language = 'en-us';
|
public $install_language = 'en-us';
|
||||||
public $admin_username;
|
public $admin_username;
|
||||||
public $admin_password;
|
public $admin_password;
|
||||||
public $default_country = 'US';
|
public $default_country = 'US';
|
||||||
public $template_name = 'enhanced';
|
public $template_name = 'enhanced';
|
||||||
|
|
||||||
function __construct($global_settings) {
|
function __construct($global_settings) {
|
||||||
if(is_null($global_settings)){
|
if(is_null($global_settings)){
|
||||||
require_once "resources/classes/global_settings.php";
|
require_once "resources/classes/global_settings.php";
|
||||||
$global_settings = new global_settings();
|
$global_settings = new global_settings();
|
||||||
|
|
@ -70,7 +70,7 @@ include "root.php";
|
||||||
echo "$message\n";
|
echo "$message\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function write_progress($message) {
|
function write_progress($message) {
|
||||||
if($this->echo_progress){
|
if($this->echo_progress){
|
||||||
echo "$message\n";
|
echo "$message\n";
|
||||||
|
|
@ -93,14 +93,14 @@ include "root.php";
|
||||||
$this->create_menus();
|
$this->create_menus();
|
||||||
$this->write_progress("Install phase 1 complete for FusionPBX");
|
$this->write_progress("Install phase 1 complete for FusionPBX");
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_phase_2() {
|
function install_phase_2() {
|
||||||
ini_set('max_execution_time',3600);
|
ini_set('max_execution_time',3600);
|
||||||
$this->write_progress("Install phase 2 started for FusionPBX");
|
$this->write_progress("Install phase 2 started for FusionPBX");
|
||||||
$this->app_defaults();
|
$this->app_defaults();
|
||||||
$this->write_progress("Install phase 2 complete for FusionPBX");
|
$this->write_progress("Install phase 2 complete for FusionPBX");
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgrade() {
|
function upgrade() {
|
||||||
$this->app_defaults();
|
$this->app_defaults();
|
||||||
}
|
}
|
||||||
|
|
@ -230,9 +230,9 @@ include "root.php";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_odbc_database_connection() {
|
protected function create_odbc_database_connection() {
|
||||||
//needed for non native database support
|
//needed for non native database support
|
||||||
$database_uuid = uuid();
|
$database_uuid = uuid();
|
||||||
$sql = "insert into v_databases ";
|
$sql = "insert into v_databases ";
|
||||||
$sql .= "(";
|
$sql .= "(";
|
||||||
|
|
@ -267,147 +267,147 @@ include "root.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_database_sqlite() {
|
protected function create_database_sqlite() {
|
||||||
//sqlite database will be created when the config.php is loaded and only if the database file does not exist
|
//sqlite database will be created when the config.php is loaded and only if the database file does not exist
|
||||||
try {
|
|
||||||
$this->dbh = new PDO('sqlite:'.$this->global_settings->db_path().'/'.$this->global_settings->db_name()); //sqlite 3
|
|
||||||
//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
|
|
||||||
}
|
|
||||||
catch (PDOException $error) {
|
|
||||||
throw new Exception("Failed to create database: " . $error->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
|
|
||||||
if (!function_exists('php_now')) {
|
|
||||||
function php_now() {
|
|
||||||
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
|
|
||||||
@date_default_timezone_set(@date_default_timezone_get());
|
|
||||||
}
|
|
||||||
return date("Y-m-d H:i:s");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
|
|
||||||
|
|
||||||
//add the database structure
|
|
||||||
require_once "resources/classes/schema.php";
|
|
||||||
$schema = new schema;
|
|
||||||
$schema->db = $this->dbh;
|
|
||||||
$schema->db_type = $this->global_settings->db_type();
|
|
||||||
$schema->sql();
|
|
||||||
$schema->exec();
|
|
||||||
|
|
||||||
//get the contents of the sql file
|
|
||||||
if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
|
|
||||||
$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
|
|
||||||
}
|
|
||||||
$file_contents = file_get_contents($filename);
|
|
||||||
unset($filename);
|
|
||||||
|
|
||||||
//replace \r\n with \n then explode on \n
|
|
||||||
$file_contents = str_replace("\r\n", "\n", $file_contents);
|
|
||||||
|
|
||||||
//loop line by line through all the lines of sql code
|
|
||||||
$this->dbh->beginTransaction();
|
|
||||||
$string_array = explode("\n", $file_contents);
|
|
||||||
$x = 0;
|
|
||||||
foreach($string_array as $sql) {
|
|
||||||
try {
|
try {
|
||||||
$this->dbh->query($sql);
|
$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) {
|
catch (PDOException $error) {
|
||||||
throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
|
throw new Exception("Failed to create database: " . $error->getMessage());
|
||||||
}
|
|
||||||
$x++;
|
|
||||||
}
|
|
||||||
unset ($file_contents, $sql);
|
|
||||||
$this->dbh->commit();
|
|
||||||
|
|
||||||
//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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the database, user, grant perms
|
//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
|
||||||
if($this->dbh->exec("CREATE DATABASE {$this->global_settings->db_name()}") === false) {
|
if (!function_exists('php_now')) {
|
||||||
throw new Exception("Failed to create database {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
|
function php_now() {
|
||||||
}
|
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
|
||||||
if($this->global_settings->db_username() != $this->global_settings->db_create_username()){
|
@date_default_timezone_set(@date_default_timezone_get());
|
||||||
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()));
|
return date("Y-m-d H:i:s");
|
||||||
}
|
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
|
||||||
|
|
||||||
//close database connection_aborted
|
//add the database structure
|
||||||
$this->dbh = null;
|
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();
|
||||||
|
|
||||||
$this->write_progress("\tInstalling data to database");
|
//get the contents of the sql file
|
||||||
//open database connection with $this->global_settings->db_name()
|
if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
|
||||||
try {
|
$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
|
||||||
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()}");
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
catch (PDOException $error) {
|
$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
|
||||||
throw new Exception("error connecting to database: " . $error->getMessage());
|
}
|
||||||
}
|
$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);
|
||||||
|
|
||||||
//add the database structure
|
//loop line by line through all the lines of sql code
|
||||||
require_once "resources/classes/schema.php";
|
$this->dbh->beginTransaction();
|
||||||
$schema = new schema;
|
$string_array = explode("\n", $file_contents);
|
||||||
$schema->db = $this->dbh;
|
$x = 0;
|
||||||
$schema->db_type = $this->global_settings->db_type();
|
foreach($string_array as $sql) {
|
||||||
$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);
|
|
||||||
|
|
||||||
//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 {
|
try {
|
||||||
$this->dbh->query($sql);
|
$this->dbh->query($sql);
|
||||||
}
|
}
|
||||||
catch (PDOException $error) {
|
catch (PDOException $error) {
|
||||||
throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
|
throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
|
||||||
}
|
}
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
$x++;
|
unset ($file_contents, $sql);
|
||||||
}
|
$this->dbh->commit();
|
||||||
unset ($file_contents, $sql);
|
|
||||||
|
//set the file permissions
|
||||||
|
chmod($this->global_settings->db_path().'/'.$this->global_settings->db_name(), 0777);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function create_database_pgsql() {
|
||||||
|
//create the database
|
||||||
|
if ($this->global_settings->db_create()) {
|
||||||
|
//attempt to create new Postgres 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
//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()));
|
||||||
|
}
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//close database connection_aborted
|
||||||
|
$this->dbh = null;
|
||||||
|
}
|
||||||
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//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);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_database_mysql() {
|
protected function create_database_mysql() {
|
||||||
|
|
@ -505,7 +505,8 @@ include "root.php";
|
||||||
$this->dbh = null;
|
$this->dbh = null;
|
||||||
} //if (strlen($this->global_settings->db_create_username()) > 0)
|
} //if (strlen($this->global_settings->db_create_username()) > 0)
|
||||||
|
|
||||||
$this->write_progress("\tInstalling data to database");
|
$this->write_progress("\tInstalling data to database");
|
||||||
|
|
||||||
//select the database
|
//select the database
|
||||||
try {
|
try {
|
||||||
$this->dbh = new PDO($connect_string, $this->global_settings->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'));
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ include "root.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
//utility Functions
|
//utility Functions
|
||||||
|
|
||||||
function write_debug($message) {
|
function write_debug($message) {
|
||||||
if($this->debug){
|
if($this->debug){
|
||||||
echo "$message\n";
|
echo "$message\n";
|
||||||
|
|
@ -135,7 +134,7 @@ include "root.php";
|
||||||
if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); }
|
if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); }
|
||||||
$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
|
$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
|
||||||
if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
|
if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
|
||||||
|
|
||||||
//create the dialplan/default.xml for single tenant or dialplan/domain.xml
|
//create the dialplan/default.xml for single tenant or dialplan/domain.xml
|
||||||
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) {
|
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) {
|
||||||
$dialplan = new dialplan;
|
$dialplan = new dialplan;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$iso_countries = array
|
$iso_countries = array
|
||||||
(
|
(
|
||||||
'AF' => 'Afghanistan',
|
'AF' => 'Afghanistan',
|
||||||
|
|
@ -247,4 +248,5 @@ $iso_countries = array
|
||||||
'ZM' => 'Zambia',
|
'ZM' => 'Zambia',
|
||||||
'ZW' => 'Zimbabwe',
|
'ZW' => 'Zimbabwe',
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
<?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 <markjcrane@fusionpbx.com>
|
|
||||||
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
|
||||||
the Initial Developer. All Rights Reserved.
|
|
||||||
|
|
||||||
Contributor(s):
|
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
// set included, if not
|
|
||||||
if (!isset($included)) { $included = false; }
|
|
||||||
|
|
||||||
//check the permission
|
|
||||||
if(defined('STDIN')) {
|
|
||||||
$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
|
|
||||||
preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
|
|
||||||
$document_root = $matches[1];
|
|
||||||
set_include_path($document_root);
|
|
||||||
require_once "resources/require.php";
|
|
||||||
$_SERVER["DOCUMENT_ROOT"] = $document_root;
|
|
||||||
$format = 'text'; //html, text
|
|
||||||
}
|
|
||||||
else if (!$included) {
|
|
||||||
include "root.php";
|
|
||||||
require_once "resources/require.php";
|
|
||||||
require_once "resources/check_auth.php";
|
|
||||||
if (permission_exists('upgrade_switch') || if_group("superadmin")) {
|
|
||||||
//echo "access granted";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
echo "access denied";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
$format = 'html'; //html, text
|
|
||||||
}
|
|
||||||
|
|
||||||
//run switch upgrade
|
|
||||||
require_once "resources/classes/install_switch.php";
|
|
||||||
$switch = new install_switch();
|
|
||||||
$switch->upgrade();
|
|
||||||
|
|
||||||
?>
|
|
||||||
Loading…
Reference in New Issue