mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Resolved install issues, environment now in tact enough to run app_defaults
This commit is contained in:
@@ -133,15 +133,6 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||
|
||||
//set a default enviroment if first_time
|
||||
if($first_time_install){
|
||||
//grab the default theme
|
||||
$set_session_theme = 1;
|
||||
$domains_processed = 1;
|
||||
include "themes/enhanced/app_defaults.php";
|
||||
unset($set_session_theme, $domains_processed);
|
||||
//initialize some defaults so we can be 'logged in'
|
||||
$_SESSION['username'] = 'first_time_install';
|
||||
$_SESSION['permissions'][]['permission_name'] = 'superadmin';
|
||||
$_SESSION['menu'] = '';
|
||||
//initialize some varibles to cut down on warnings
|
||||
$_SESSION['message'] = '';
|
||||
$v_link_label_play = '';
|
||||
@@ -277,7 +268,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||
}
|
||||
if($detect_ok){
|
||||
$install_ok = true;
|
||||
echo "<pre>\n";
|
||||
echo "<pre style='text-align:left;'>\n";
|
||||
function error_handler($err_severity, $errstr, $errfile, $errline ) {
|
||||
if (0 === error_reporting()) { return false;}
|
||||
switch($err_severity)
|
||||
@@ -292,12 +283,12 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
set_error_handler("error_handler");
|
||||
#set_error_handler("error_handler");
|
||||
try {
|
||||
$domain_uuid = uuid();
|
||||
require_once "resources/classes/install_fusionpbx.php";
|
||||
$fusionPBX = new install_fusionpbx($domain_name, $domain_uuid, $switch_detect);
|
||||
$fusionPBX->debug = true;
|
||||
$fusionPBX = new install_fusionpbx($domain_name, null, $switch_detect);
|
||||
$domain_uuid = $fusionPBX->domain_uuid();
|
||||
//$fusionPBX->debug = true;
|
||||
$fusionPBX->admin_username = $admin_username;
|
||||
$fusionPBX->admin_password = $admin_password;
|
||||
$fusionPBX->default_country = $install_default_country;
|
||||
@@ -312,7 +303,7 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||
|
||||
require_once "resources/classes/install_switch.php";
|
||||
$switch = new install_switch($domain_name, $domain_uuid, $switch_detect);
|
||||
$switch->debug = true;
|
||||
//$switch->debug = true;
|
||||
$switch->install();
|
||||
}catch(Exception $e){
|
||||
echo "</pre>\n";
|
||||
@@ -344,6 +335,17 @@ if(!$install_step) { $install_step = 'select_language'; }
|
||||
echo "<p>Unkown install_step '$install_step'</p>\n";
|
||||
}
|
||||
|
||||
if($first_time_install){
|
||||
//grab the default theme
|
||||
$set_session_theme = 1;
|
||||
$domains_processed = 1;
|
||||
include "themes/enhanced/app_defaults.php";
|
||||
unset($set_session_theme, $domains_processed);
|
||||
//initialize some defaults so we can be 'logged in'
|
||||
$_SESSION['username'] = 'first_time_install';
|
||||
$_SESSION['permissions'][]['permission_name'] = 'superadmin';
|
||||
$_SESSION['menu'] = '';
|
||||
}
|
||||
// add the content to the template and then send output
|
||||
$body = ob_get_contents(); //get the output from the buffer
|
||||
ob_end_clean(); //clean the buffer
|
||||
|
||||
@@ -150,6 +150,13 @@ require_once "resources/classes/EventSocket.php";
|
||||
$esl->reset_fp();
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function restart_switch() {
|
||||
$this->connect_event_socket();
|
||||
if(!$this->event_socket){
|
||||
throw new Exception('Failed to use event socket');
|
||||
}
|
||||
$this->event_socket_request('api fsctl shutdown restart elegant');
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -29,12 +29,14 @@ include "root.php";
|
||||
//define the install class
|
||||
class install_fusionpbx {
|
||||
|
||||
protected $domain_uuid;
|
||||
protected $_domain_uuid;
|
||||
protected $domain_name;
|
||||
protected $detect_switch;
|
||||
protected $config_php;
|
||||
protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
|
||||
protected $dbh;
|
||||
|
||||
public function domain_uuid() { return $this->_domain_uuid; }
|
||||
|
||||
public $debug = false;
|
||||
|
||||
@@ -57,7 +59,8 @@ include "root.php";
|
||||
if(!is_a($detect_switch, 'detect_switch')){
|
||||
throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
|
||||
}
|
||||
$this->domain_uuid = $domain_uuid;
|
||||
if($domain_uuid == null){ $domain_uuid = uuid(); }
|
||||
$this->_domain_uuid = $domain_uuid;
|
||||
$this->domain_name = $domain_name;
|
||||
$this->detect_switch = $detect_switch;
|
||||
if (is_dir("/etc/fusionpbx")){
|
||||
@@ -91,7 +94,7 @@ include "root.php";
|
||||
$this->create_superuser();
|
||||
require "resources/require.php";
|
||||
$this->create_menus();
|
||||
$this->post_create();
|
||||
$this->app_defaults();
|
||||
}
|
||||
|
||||
protected function create_config_php() {
|
||||
@@ -196,7 +199,7 @@ include "root.php";
|
||||
|
||||
protected function create_database() {
|
||||
require $this->config_php;
|
||||
$this->write_progress("creating database as " . $this->db_type);
|
||||
$this->write_progress("Creating database as " . $this->db_type);
|
||||
$function = "create_database_" . $this->db_type;
|
||||
$this->$function();
|
||||
global $db;
|
||||
@@ -512,17 +515,23 @@ include "root.php";
|
||||
|
||||
|
||||
protected function create_domain() {
|
||||
$this->write_progress("checking if domain exists '" . $this->domain_name . "'");
|
||||
$sql = "select count(*) from v_domains ";
|
||||
$this->write_progress("Checking if domain exists '" . $this->domain_name . "'");
|
||||
$sql = "select * from v_domains ";
|
||||
$sql .= "where domain_name = '".$this->domain_name."' ";
|
||||
|
||||
$sql .= "limit 1";
|
||||
$this->write_debug($sql);
|
||||
$prep_statement = $this->dbh->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
$result = $prep_statement->fetch(PDO::FETCH_NAMED);
|
||||
unset($sql, $prep_statement);
|
||||
if ($row['num_rows'] == 0) {
|
||||
$this->write_progress("creating domain '" . $this->domain_name . "'");
|
||||
if ($result) {
|
||||
$this->_domain_uuid = $result['domain_uuid'];
|
||||
$this->write_progress("... domain exists as '" . $this->_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");
|
||||
$sql = "insert into v_domains ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
@@ -531,7 +540,7 @@ include "root.php";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".$this->_domain_uuid."', ";
|
||||
$sql .= "'".$this->domain_name."', ";
|
||||
$sql .= "'' ";
|
||||
$sql .= ");";
|
||||
@@ -801,123 +810,180 @@ include "root.php";
|
||||
}
|
||||
|
||||
protected function create_superuser() {
|
||||
//check if it exists first?
|
||||
$this->write_progress("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();
|
||||
$contact_uuid = uuid();
|
||||
//set a sessiong variable
|
||||
$_SESSION["user_uuid"] = $user_uuid;
|
||||
//salt used with the password to create a one way hash
|
||||
$this->write_progress("Checking if superuser exists '" . $this->domain_name . "'");
|
||||
$sql = "select * from v_users ";
|
||||
$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
|
||||
$sql .= "and username = '".$this->admin_username."' ";
|
||||
$sql .= "limit 1 ";
|
||||
$this->write_debug($sql);
|
||||
$prep_statement = $this->dbh->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetch(PDO::FETCH_NAMED);
|
||||
unset($sql, $prep_statement);
|
||||
$salt = generate_password('20', '4');
|
||||
//add the user account
|
||||
$sql = "insert into v_users ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "user_uuid, ";
|
||||
$sql .= "contact_uuid, ";
|
||||
$sql .= "username, ";
|
||||
$sql .= "password, ";
|
||||
$sql .= "salt, ";
|
||||
$sql .= "add_date, ";
|
||||
$sql .= "add_user ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".$this->admin_uuid."', ";
|
||||
$sql .= "'$contact_uuid', ";
|
||||
$sql .= "'".$this->admin_username."', ";
|
||||
$sql .= "'".md5($salt.$this->admin_password)."', ";
|
||||
$sql .= "'$salt', ";
|
||||
$sql .= "now(), ";
|
||||
$sql .= "'".$this->admin_username."' ";
|
||||
$sql .= ");";
|
||||
$this->write_debug( $sql."\n");
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
//add to contacts
|
||||
$sql = "insert into v_contacts ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "contact_uuid, ";
|
||||
$sql .= "contact_type, ";
|
||||
$sql .= "contact_name_given, ";
|
||||
$sql .= "contact_nickname ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'$contact_uuid', ";
|
||||
$sql .= "'user', ";
|
||||
$sql .= "'".$this->admin_username."', ";
|
||||
$sql .= "'".$this->admin_username."' ";
|
||||
$sql .= ")";
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
//add the user to the superadmin group
|
||||
$sql = "insert into v_group_users ";
|
||||
$sql .= "(";
|
||||
$sql .= "group_user_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "user_uuid, ";
|
||||
$sql .= "group_name ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".$this->admin_uuid."', ";
|
||||
$sql .= "'superadmin' ";
|
||||
$sql .= ");";
|
||||
$this->write_debug( $sql."\n");
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
if ($result) {
|
||||
$this->admin_uuid = $result['user_uuid'];
|
||||
$this->write_progress("... superuser exists as '" . $this->admin_uuid . "', updating password");
|
||||
$sql = "update v_users ";
|
||||
$sql .= "set password = '".md5($salt.$this->admin_password)."' ";
|
||||
$sql .= "set salt = '$salt' ";
|
||||
$sql .= "where USER_uuid = '".$this->admin_uuid."' ";
|
||||
$this->write_debug($sql);
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
}else{
|
||||
$this->write_progress("... 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();
|
||||
$contact_uuid = uuid();
|
||||
//set a sessiong variable
|
||||
$_SESSION["user_uuid"] = $user_uuid;
|
||||
//salt used with the password to create a one way hash
|
||||
//add the user account
|
||||
$sql = "insert into v_users ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "user_uuid, ";
|
||||
$sql .= "contact_uuid, ";
|
||||
$sql .= "username, ";
|
||||
$sql .= "password, ";
|
||||
$sql .= "salt, ";
|
||||
$sql .= "add_date, ";
|
||||
$sql .= "add_user ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->_domain_uuid."', ";
|
||||
$sql .= "'".$this->admin_uuid."', ";
|
||||
$sql .= "'$contact_uuid', ";
|
||||
$sql .= "'".$this->admin_username."', ";
|
||||
$sql .= "'".md5($salt.$this->admin_password)."', ";
|
||||
$sql .= "'$salt', ";
|
||||
$sql .= "now(), ";
|
||||
$sql .= "'".$this->admin_username."' ";
|
||||
$sql .= ");";
|
||||
$this->write_debug( $sql."\n");
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
$this->write_progress("Checking if superuser contact exists");
|
||||
$sql = "select count(*) from v_contacts ";
|
||||
$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
|
||||
$sql .= "and contact_name_given = '".$this->admin_username."' ";
|
||||
$sql .= "and contact_nickname = '".$this->admin_username."' ";
|
||||
$sql .= "limit 1 ";
|
||||
$this->write_debug($sql);
|
||||
$prep_statement = $this->dbh->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['count'] == 0) {
|
||||
$sql = "insert into v_contacts ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "contact_uuid, ";
|
||||
$sql .= "contact_type, ";
|
||||
$sql .= "contact_name_given, ";
|
||||
$sql .= "contact_nickname ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->_domain_uuid."', ";
|
||||
$sql .= "'$contact_uuid', ";
|
||||
$sql .= "'user', ";
|
||||
$sql .= "'".$this->admin_username."', ";
|
||||
$sql .= "'".$this->admin_username."' ";
|
||||
$sql .= ")";
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
$this->write_progress("Checking if superuser is in the correct group");
|
||||
$sql = "select count(*) from v_group_users ";
|
||||
$sql .= "where domain_uuid = '".$this->_domain_uuid."' ";
|
||||
$sql .= "and user_uuid = '".$this->admin_uuid."' ";
|
||||
$sql .= "and group_name = 'superadmin' ";
|
||||
$sql .= "limit 1 ";
|
||||
$this->write_debug($sql);
|
||||
$prep_statement = $this->dbh->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['count'] == 0) {
|
||||
//add the user to the superadmin group
|
||||
$sql = "insert into v_group_users ";
|
||||
$sql .= "(";
|
||||
$sql .= "group_user_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "user_uuid, ";
|
||||
$sql .= "group_name ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$this->_domain_uuid."', ";
|
||||
$sql .= "'".$this->admin_uuid."', ";
|
||||
$sql .= "'superadmin' ";
|
||||
$sql .= ");";
|
||||
$this->write_debug( $sql."\n");
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
}
|
||||
}
|
||||
|
||||
protected function create_menus() {
|
||||
$this->write_progress("creating menus");
|
||||
$this->write_progress("Creating menus");
|
||||
//set the defaults
|
||||
$menu_name = 'default';
|
||||
$menu_language = 'en-us';
|
||||
$menu_description = 'Default Menu Set';
|
||||
//add the parent menu
|
||||
$sql = "insert into v_menus ";
|
||||
$sql .= "(";
|
||||
$sql .= "menu_uuid, ";
|
||||
$sql .= "menu_name, ";
|
||||
$sql .= "menu_language, ";
|
||||
$sql .= "menu_description ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->menu_uuid."', ";
|
||||
$sql .= "'$menu_name', ";
|
||||
$sql .= "'$menu_language', ";
|
||||
$sql .= "'$menu_description' ";
|
||||
$sql .= ");";
|
||||
if ($this->debug) {
|
||||
$this->write_debug( $sql."\n");
|
||||
|
||||
$this->write_progress("Checking if menu exists");
|
||||
$sql = "select count(*) from v_menus ";
|
||||
$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
|
||||
$sql .= "limit 1 ";
|
||||
$this->write_debug($sql);
|
||||
$prep_statement = $this->dbh->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetch(PDO::FETCH_NAMED);
|
||||
unset($sql, $prep_statement);
|
||||
if ($result['count'] == 0) {
|
||||
$this->write_progress("... creating menu '" . $menu_name. "'");
|
||||
$sql = "insert into v_menus ";
|
||||
$sql .= "(";
|
||||
$sql .= "menu_uuid, ";
|
||||
$sql .= "menu_name, ";
|
||||
$sql .= "menu_language, ";
|
||||
$sql .= "menu_description ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->menu_uuid."', ";
|
||||
$sql .= "'$menu_name', ";
|
||||
$sql .= "'$menu_language', ";
|
||||
$sql .= "'$menu_description' ";
|
||||
$sql .= ");";
|
||||
if ($this->debug) {
|
||||
$this->write_debug( $sql."\n");
|
||||
}
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
//add the menu items
|
||||
require_once "resources/classes/menu.php";
|
||||
$menu = new menu;
|
||||
$menu->db = $this->dbh;
|
||||
$menu->menu_uuid = $this->menu_uuid;
|
||||
$menu->restore();
|
||||
unset($menu);
|
||||
}
|
||||
$this->dbh->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
//add the menu items
|
||||
require_once "resources/classes/menu.php";
|
||||
$menu = new menu;
|
||||
$menu->db = $this->dbh;
|
||||
$menu->menu_uuid = $this->menu_uuid;
|
||||
$menu->restore();
|
||||
unset($menu);
|
||||
}
|
||||
|
||||
protected function post_create() {
|
||||
$this->write_progress("running post steps");
|
||||
//login the user account
|
||||
protected function app_defaults() {
|
||||
$this->write_progress("Running app_defaults");
|
||||
|
||||
//set needed session settings
|
||||
$_SESSION["username"] = $this->admin_username;
|
||||
$_SESSION["domain_uuid"] = $this->_domain_uuid;
|
||||
require $this->config_php;
|
||||
require "resources/require.php";
|
||||
|
||||
//get the groups assigned to the user and then set the groups in $_SESSION["groups"]
|
||||
$sql = "SELECT * FROM v_group_users ";
|
||||
@@ -949,17 +1015,19 @@ include "root.php";
|
||||
$prep_statementsub->execute();
|
||||
$_SESSION['permissions'] = $prep_statementsub->fetchAll(PDO::FETCH_NAMED);
|
||||
unset($sql, $prep_statementsub);
|
||||
|
||||
//make sure the database schema and installation have performed all necessary tasks
|
||||
$display_results = false;
|
||||
$display_type = 'none';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once "resources/classes/schema.php";
|
||||
$obj = new schema;
|
||||
$obj->schema($this->dbh, $this->db_type, $this->db_name, $display_type);
|
||||
global $db, $db_type, $db_name, $db_username, $db_password, $db_host, $db_path, $db_port;
|
||||
|
||||
$schema = new schema;
|
||||
echo $schema->schema();
|
||||
|
||||
//run all app_defaults.php files
|
||||
$default_language = $this->install_language;
|
||||
require_once "resources/classes/domains.php";
|
||||
$domain = new domains;
|
||||
$domain->upgrade();
|
||||
|
||||
@@ -971,6 +1039,7 @@ include "root.php";
|
||||
|
||||
//clear the menu
|
||||
$_SESSION["menu"] = "";
|
||||
|
||||
}
|
||||
|
||||
public function remove_config() {
|
||||
|
||||
@@ -156,7 +156,7 @@ include "root.php";
|
||||
//pharData is the correct ay to do it, but it keeps creating incomplete archives
|
||||
//$tar = new PharData($dst_tar);
|
||||
//$tar->buildFromDirectory($dir);
|
||||
$this->write_debug("backingup to $dst_tar");
|
||||
$this->write_debug("backing up to $dst_tar");
|
||||
if (file_exists('/bin/tar')) {
|
||||
exec('tar -cvf ' .$dst_tar. ' -C '.$dir .' .');
|
||||
}else{
|
||||
@@ -166,9 +166,13 @@ include "root.php";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function install() {
|
||||
$this->copy_conf();
|
||||
$this->copy_scripts();
|
||||
//tell freeswitch to restart
|
||||
$this->write_progress("Restarting switch");
|
||||
$this->detect_switch->restart_switch();
|
||||
}
|
||||
|
||||
function upgrade() {
|
||||
|
||||
Reference in New Issue
Block a user