Work on the install.

This commit is contained in:
markjcrane
2016-04-14 21:14:40 -06:00
parent 3f5f268c15
commit 5799ce6497
4 changed files with 11 additions and 438 deletions

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2010-2015
Copyright (C) 2010-2016
All Rights Reserved.
Contributor(s):
@@ -88,6 +88,7 @@ include "root.php";
$this->create_database();
$this->create_domain();
$this->create_superuser();
$this->app_defaults();
$this->write_progress("\tRunning requires");
require "resources/require.php";
$this->write_progress("Install phase 1 complete for FusionPBX");
@@ -96,14 +97,10 @@ include "root.php";
function install_phase_2() {
ini_set('max_execution_time',3600);
$this->write_progress("Install phase 2 started for FusionPBX");
$this->app_defaults();
//$this->app_defaults();
$this->write_progress("Install phase 2 complete for FusionPBX");
}
function upgrade() {
$this->app_defaults();
}
protected function create_config_php() {
$this->write_progress("\tCreating " . $this->config_php);
$tmp_config = "<?php\n";
@@ -663,111 +660,7 @@ include "root.php";
$tmp[$x]['subcategory'] = 'template';
$tmp[$x]['enabled'] = 'true';
$x++;
/*
//switch settings
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $switch_bin_dir;
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'bin';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_base_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'base';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_conf_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'conf';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_db_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'db';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_log_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'log';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_mod_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'mod';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_script_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'scripts';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_grammar_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'grammar';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_storage_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'storage';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_voicemail_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'voicemail';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_recordings_dir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'recordings';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->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'] = $this->global_settings->switch_extensions_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'extensions';
$tmp[$x]['enabled'] = 'false';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_sip_profiles_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'sip_profiles';
$tmp[$x]['enabled'] = 'false';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_dialplan_vdir();
$tmp[$x]['category'] = 'switch';
$tmp[$x]['subcategory'] = 'dialplan';
$tmp[$x]['enabled'] = 'false';
$x++;
*/
//server settings
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_temp_dir();
@@ -775,12 +668,6 @@ include "root.php";
$tmp[$x]['subcategory'] = 'temp';
$tmp[$x]['enabled'] = 'true';
$x++;
#throw new Exception("I don't know how to find /etc/init.d for server > startup_scripts");
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = '';
$tmp[$x]['category'] = 'server';
$tmp[$x]['subcategory'] = 'startup_script';
$tmp[$x]['enabled'] = 'true';
$x++;
$tmp[$x]['name'] = 'dir';
$tmp[$x]['value'] = $this->global_settings->switch_backup_vdir();
@@ -823,80 +710,6 @@ include "root.php";
include($config_path);
$x++;
}
/*
//add the groups
$x = 0;
$tmp[$x]['group_name'] = 'superadmin';
$tmp[$x]['group_description'] = 'Super Administrator Group';
$x++;
$tmp[$x]['group_name'] = 'admin';
$tmp[$x]['group_description'] = 'Administrator Group';
$x++;
$tmp[$x]['group_name'] = 'user';
$tmp[$x]['group_description'] = 'User Group';
$x++;
$tmp[$x]['group_name'] = 'public';
$tmp[$x]['group_description'] = 'Public Group';
$x++;
$tmp[$x]['group_name'] = 'agent';
$tmp[$x]['group_description'] = 'Call Center Agent Group';
$this->dbh->beginTransaction();
foreach($tmp as $row) {
$sql = "insert into v_groups ";
$sql .= "(";
$sql .= "group_uuid, ";
$sql .= "group_name, ";
$sql .= "group_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$row['group_name']."', ";
$sql .= "'".$row['group_description']."' ";
$sql .= ");";
$this->write_debug($sql);
$this->dbh->exec(check_sql($sql));
unset($sql);
}
unset($tmp);
$this->dbh->commit();
//assign the default permissions to the groups
$this->dbh->beginTransaction();
foreach($apps as $app) {
if ($app['permissions']) {
foreach ($app['permissions'] as $row) {
if ($this->debug) {
$this->write_debug( "v_group_permissions\n");
$this->write_debug( json_encode($row)."\n\n");
}
if ($row['groups']) {
foreach ($row['groups'] as $group) {
//add the record
$sql = "insert into v_group_permissions ";
$sql .= "(";
$sql .= "group_permission_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$row['name']."', ";
$sql .= "'".$group."' ";
$sql .= ");";
if ($this->debug) {
$this->write_debug( $sql."\n");
}
$this->dbh->exec(check_sql($sql));
unset($sql);
}
}
}
}
}
$this->dbh->commit();
*/
}
}
@@ -941,7 +754,8 @@ include "root.php";
$sql .= "password, ";
$sql .= "salt, ";
$sql .= "add_date, ";
$sql .= "add_user ";
$sql .= "add_user, ";
$sql .= "user_enabled ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
@@ -952,7 +766,8 @@ include "root.php";
$sql .= "'".md5($salt.$this->admin_password)."', ";
$sql .= "'$salt', ";
$sql .= "now(), ";
$sql .= "'".$this->admin_username."' ";
$sql .= "'".$this->admin_username."', ";
$sql .= "'true' ";
$sql .= ");";
$this->write_debug( $sql."\n");
$this->dbh->exec(check_sql($sql));

View File

@@ -29,7 +29,6 @@ include "root.php";
class install_switch {
protected $global_settings;
//protected $config_lua;
protected $dbh;
public $debug = false;
@@ -43,18 +42,6 @@ include "root.php";
throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
}
$this->global_settings = $global_settings;
/*
if (is_dir("/etc/fusionpbx")){
$this->config_lua = "/etc/fusionpbx/config.lua";
}elseif (is_dir("/usr/local/etc/fusionpbx")){
$this->config_lua = "/usr/local/etc/fusionpbx/config.lua";
}elseif(strlen($this->global_settings->switch_script_dir()) > 0) {
$this->config_lua = $this->global_settings->switch_script_dir()."/resources/config.lua";
}else{
throw new Exception("Could not work out where to put the config.lua");
}
$this->config_lua = normalize_path($this->config_lua);
*/
}
//utility Functions
@@ -91,27 +78,15 @@ include "root.php";
function install_phase_1() {
$this->write_progress("Install phase 1 started for switch");
$this->copy_conf();
//$this->copy_scripts();
$this->write_progress("Install phase 1 completed for switch");
}
function install_phase_2() {
$this->write_progress("Install phase 2 started for switch");
//$this->create_config_lua();
//run all app_defaults.php files
$domain = new domains;
$domain->upgrade();
$this->restart_switch();
$this->write_progress("Install phase 2 completed for switch");
}
function upgrade() {
//$this->copy_scripts();
//$this->create_config_lua();
}
protected function copy_conf() {
//send a message
$this->write_progress("\tCopying Config");
@@ -146,19 +121,6 @@ include "root.php";
$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
//create the dialplan/default.xml for single tenant or dialplan/domain.xml
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) {
$dialplan = new dialplan;
$dialplan->domain_uuid = $this->domain_uuid;
$dialplan->domain = $this->domain_name;
$dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan"));
$dialplan->restore_advanced_xml();
if($this->_debug){
print_r($dialplan->result, $message);
$this->write_debug($message);
}
}
//write the xml_cdr.conf.xml file
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/xml_cdr")) {
xml_cdr_conf_xml();
@@ -168,193 +130,8 @@ include "root.php";
if (file_exists($this->global_settings->switch_conf_dir())) {
switch_conf_xml();
}
}
protected function copy_scripts() {
$this->write_progress("\tCopying Scripts");
$script_dir = $this->global_settings->switch_script_dir();
if(strlen($script_dir) == 0) {
throw new Exception("Cannot copy scripts the 'script_dir' is empty");
}
if (file_exists($script_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 = $script_dir;
if (is_readable($script_dir)) {
recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
unset($src_dir, $dst_dir);
}else{
throw new Exception("Cannot read from '$src_dir' to get the scripts");
}
chmod($dst_dir, 0774);
}else{
$this->write_progress("\tSkipping scripts, script_dir is unset");
}
}
/*
public function create_config_lua() {
//define the database connection as global
global $db;
//send progress
$this->write_progress("\tCreating " . $this->config_lua);
//set the directories
$path = dirname($this->config_lua);
$parent_dir = basename($path);
if ($parent_dir == 'resources' and !file_exists($path)){
$this->write_progress("\t... creating missing '$path'");
if (!mkdir($path, 0755, true)) {
throw new Exception("Failed to create the missing resources directory '$path'");
}
}
//get the odbc information
$sql = "select count(*) as num_rows from v_databases ";
$sql .= "where database_driver = 'odbc' ";
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset($prep_statement);
if ($row['num_rows'] > 0) {
$odbc_num_rows = $row['num_rows'];
$sql = "select * from v_databases ";
$sql .= "where database_driver = 'odbc' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$dsn_name = $row["database_name"];
$dsn_username = $row["database_username"];
$dsn_password = $row["database_password"];
break; //limit to 1 row
}
unset ($prep_statement);
}
else {
$odbc_num_rows = '0';
}
}
//config.lua
$fout = fopen($this->config_lua,"w");
if(!$fout){
throw new Exception("Failed to open '".$this->config_lua."' for writing");
}
$tmp = "\n";
$tmp .= "--set the variables\n";
if (strlen($this->global_settings->switch_sounds_dir()) > 0) {
$tmp .= normalize_path(" sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n");
}
if (strlen($this->global_settings->switch_phrases_vdir()) > 0) {
$tmp .= normalize_path(" phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n");
}
if (strlen($this->global_settings->switch_db_dir()) > 0) {
$tmp .= normalize_path(" database_dir = [[".$this->global_settings->switch_db_dir()."]];\n");
}
if (strlen($this->global_settings->switch_recordings_dir()) > 0) {
$tmp .= normalize_path(" recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n");
}
if (strlen($this->global_settings->switch_storage_dir()) > 0) {
$tmp .= normalize_path(" storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n");
}
if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) {
$tmp .= normalize_path(" voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n");
}
if (strlen($this->global_settings->switch_script_dir()) > 0) {
$tmp .= normalize_path(" scripts_dir = [[".$this->global_settings->switch_script_dir()."]];\n");
}
$tmp .= normalize_path(" php_dir = [[".PHP_BINDIR."]];\n");
if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
$tmp .= " php_bin = \"php.exe\";\n";
}
else {
$tmp .= " php_bin = \"php\";\n";
}
$tmp .= normalize_path(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
$tmp .= "\n";
if ((strlen($this->global_settings->db_type()) > 0) || (strlen($dsn_name) > 0)) {
$tmp .= "--database information\n";
$tmp .= " database = {}\n";
$tmp .= " database.type = \"".$this->global_settings->db_type()."\";\n";
$tmp .= " database.name = \"".$this->global_settings->db_name()."\";\n";
$tmp .= normalize_path(" database.path = [[".$this->global_settings->db_path()."]];\n");
if (strlen($dsn_name) > 0) {
$tmp .= " database.system = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n";
$tmp .= " database.switch = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n";
}
elseif ($this->global_settings->db_type() == "pgsql") {
$db_host = $this->global_settings->db_host();
if($db_host == 'localhost') { $db_host = '127.0.0.1'; } // lua cannot resolve localhost
if (filter_var($db_host, FILTER_VALIDATE_IP)) {
$host_type = "hostaddr";
}
else {
$host_type = "host";
}
$tmp .= " database.system = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=".$this->global_settings->db_name()." user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='".$this->global_settings->db_name()."'\";\n";
$tmp .= " database.switch = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=freeswitch user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='freeswitch'\";\n";
}
elseif ($this->global_settings->db_type() == "sqlite") {
$tmp .= " database.system = \"sqlite://".$this->global_settings->db_path()."/".$this->global_settings->db_name()."\";\n";
$tmp .= " database.switch = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
}
elseif ($this->global_settings->db_type() == "mysql") {
$tmp .= " database.system = \"\";\n";
$tmp .= " database.switch = \"\";\n";
}
$tmp .= "\n";
}
$tmp .= "--set defaults\n";
$tmp .= " expire = {}\n";
$tmp .= " expire.directory = \"3600\";\n";
$tmp .= " expire.dialplan = \"3600\";\n";
$tmp .= " expire.languages = \"3600\";\n";
$tmp .= " expire.sofia = \"3600\";\n";
$tmp .= " expire.acl = \"3600\";\n";
$tmp .= "\n";
$tmp .= "--set xml_handler\n";
$tmp .= " xml_handler = {}\n";
$tmp .= " xml_handler.fs_path = false;\n";
$tmp .= "\n";
$tmp .= "--set the debug options\n";
$tmp .= " debug.params = false;\n";
$tmp .= " debug.sql = false;\n";
$tmp .= " debug.xml_request = false;\n";
$tmp .= " debug.xml_string = false;\n";
$tmp .= " debug.cache = false;\n";
$tmp .= "\n";
$tmp .= "--additional info\n";
$tmp .= " domain_count = ".$this->global_settings->domain_count().";\n";
$tmp .= normalize_path(" temp_dir = [[".$this->global_settings->switch_temp_dir()."]];\n");
if (isset($_SESSION['domain']['dial_string']['text'])) {
$tmp .= " dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
}
$tmp .= "\n";
$tmp .= "--include local.lua\n";
$tmp .= " require(\"resources.functions.file_exists\");\n";
$tmp .= " if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
$tmp .= " dofile(\"/etc/fusionpbx/local.lua\");\n";
$tmp .= " elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
$tmp .= " dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
$tmp .= " elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
$tmp .= " require(\"resources.local\");\n";
$tmp .= " end\n";
fwrite($fout, $tmp);
unset($tmp);
fclose($fout);
}
*/
protected function restart_switch() {
$esl = new event_socket;
if(!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) {

View File

@@ -68,20 +68,6 @@ if (sizeof($_POST) > 0) {
$_SESSION["message_mood"] = 'negative';
$response_message = $text['message-upgrade_source_failed'];
}
else {
//update scripts folder, if allowed (default)
if ($_SESSION['switch']['scripts']['dir'] != '') {
//copy the files and directories from resources/install
$obj = new install_switch;
$obj->upgrade();
//set the message
$response_message = $text['message-upgrade_source_scripts'];
}
else {
//set the message
$response_message = $text['message-upgrade_source'];
}
}
}
// load an array of the database schema and compare it with the active database
@@ -238,7 +224,6 @@ echo "<div style='text-align: right;'><input type='submit' class='btn' value='".
echo "<br><br>";
echo "</form>\n";
// output result of source update
if (sizeof($_SESSION["response_source_update"]) > 0) {
echo "<br />";
@@ -251,7 +236,6 @@ if (sizeof($_SESSION["response_source_update"]) > 0) {
unset($_SESSION["response_source_update"]);
}
// output result of upgrade schema
if ($_SESSION["schema"]["response"] != '') {
echo "<br />";

View File

@@ -48,8 +48,8 @@
$format = 'html';
}
require_once "resources/classes/text.php";
//add multi-lingual support
require_once "resources/classes/text.php";
$language = new text;
$text = $language->get();
@@ -67,10 +67,7 @@
$obj = new schema;
echo $obj->schema("text");
//request the switch to perform upgrade functions
$obj = new install_switch;
$obj->upgrade();
//run all app_defaults.php files
require_once "resources/classes/domains.php";
$domain = new domains;
$domain->upgrade();
@@ -105,4 +102,4 @@
require_once "resources/footer.php";
}
?>
?>