Resolved install issues, environment now in tact enough to run app_defaults

This commit is contained in:
Matthew Vale
2015-11-18 17:30:43 +00:00
parent 192ef9fc3f
commit 75efd1bd58
5 changed files with 222 additions and 347 deletions

View File

@@ -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

View File

@@ -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');
}
}
?>

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -1,207 +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>
Copyright (C) 2010-2015
All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
include "root.php";
//define the install class
class install {
var $result;
var $domain_uuid;
var $domain;
var $switch_conf_dir;
var $switch_scripts_dir;
var $switch_sounds_dir;
//$options '-n' --no-clobber
public function recursive_copy($src, $dst, $options = '') {
if (file_exists('/bin/cp')) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
//copy -R recursive, preserve attributes for SUN
$cmd = 'cp -Rp '.$src.'/* '.$dst;
} else {
//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
$cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
}
exec ($cmd);
//echo $cmd."\n";
}
else {
$dir = opendir($src);
if (!$dir) {
if (!mkdir($src, 0755, true)) {
throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
}
}
if (!is_dir($dst)) {
if (!mkdir($dst, 0755, true)) {
throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
}
}
$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
if (
substr_count($file_path_source, '/..') == 0 &&
substr_count($file_path_source, '/.') == 0 &&
substr_count($file_path_source, '/.svn') == 0 &&
substr_count($file_path_source, '/.git') == 0
) {
if ($dst != $src.'/resources/config.lua') {
//echo $file_path_source.' ---> '.$dst.'<br>';
copy($file_path_source, $dst);
chmod($dst, 0755);
}
}
}
while(false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src.'/'.$file)) {
$this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
}
else {
//copy only missing files -n --no-clobber
if (strpos($options,'-n') !== false) {
if (!file_exists($dst.'/'.$file)) {
copy($src.'/'.$file, $dst.'/'.$file);
//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
}
}
else {
copy($src.'/'.$file, $dst.'/'.$file);
}
}
}
}
closedir($dir);
}
}
function recursive_delete($dir) {
if (file_exists('/bin/rm')) {
exec ('rm -Rf '.$dir.'/*');
}
else {
foreach (glob($dir) as $file) {
if (is_dir($file)) {
$this->recursive_delete("$file/*");
rmdir($file);
//echo "rm dir: ".$file."\n";
} else {
//echo "delete file: ".$file."\n";
unlink($file);
}
}
}
clearstatcache();
}
function copy() {
$this->copy_scripts();
//$this->copy_sounds();
}
function copy_conf() {
if (file_exists($this->switch_conf_dir)) {
//make a backup copy of the conf directory
$src_dir = $this->switch_conf_dir;
$dst_dir = $this->switch_conf_dir.'.orig';
if (is_readable($src_dir)) {
$this->recursive_copy($src_dir, $dst_dir);
$this->recursive_delete($src_dir);
}
else {
if ($src_dir != "/conf") {
mkdir($src_dir, 0774, true);
}
}
//make sure the conf directory exists
if (!is_dir($this->switch_conf_dir)) {
if (!mkdir($this->switch_conf_dir, 0774, true)) {
throw new Exception("Failed to create the switch conf directory '".$this->switch_conf_dir."'. ");
}
}
//copy resources/templates/conf to the freeswitch conf dir
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
}
else {
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
}
$dst_dir = $this->switch_conf_dir;
if (is_readable($dst_dir)) {
$this->recursive_copy($src_dir, $dst_dir);
}
//print_r($install->result);
}
}
// added /examples/ into the string
function copy_scripts() {
if (file_exists($this->switch_scripts_dir)) {
if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
}
else {
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts';
}
$dst_dir = $this->switch_scripts_dir;
if (is_readable($this->switch_scripts_dir)) {
$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
unset($src_dir, $dst_dir);
}
chmod($dst_dir, 0774);
}
}
//function copy_sounds() {
// if (file_exists($this->switch_sounds_dir)) {
// if (file_exists('/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/')){
// $src_dir = '/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/';
// changes the output dir for testing
// $dst_dir = $this->switch_sounds_dir.'/en/us/fusionpbx/custom/';
// }
// else {
// $src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sounds/en/us/callie/custom/';
// $dst_dir = $this->switch_sounds_dir.'/en/us/callie/custom/';
// }
// $this->recursive_copy($src_dir, $dst_dir, "-n");
// if (is_readable($this->switch_sounds_dir)) {
// $this->recursive_copy($src_dir, $dst_dir);
// chmod($dst_dir, 0664);
// }
// }
//}
}
//how to use the class
//$install = new install;
//$install->domain_uuid = $domain_uuid;
//$install->switch_conf_dir = $switch_conf_dir;
//$install->switch_scripts_dir = $switch_scripts_dir;
//$install->switch_sounds_dir = $switch_sounds_dir;
//$install->copy();
//print_r($install->result);
?>