diff --git a/app/dialplan_outbound/dialplan_outbound_add.php b/app/dialplan_outbound/dialplan_outbound_add.php index 46f1796d30..34261db7c3 100644 --- a/app/dialplan_outbound/dialplan_outbound_add.php +++ b/app/dialplan_outbound/dialplan_outbound_add.php @@ -207,7 +207,7 @@ else { $label = $text['label-11d']; $abbrv = "11d"; break; - case "^(?:\+1|1)?([2-9]\d\d[2-9]\d{6})$": + case "^(?:\+?1)?(\d{10})$": $label = $text['label-north-america']; $abbrv = "10-11d"; break; diff --git a/core/install/index.php b/core/install/index.php index 34faefef83..05f1611d17 100644 --- a/core/install/index.php +++ b/core/install/index.php @@ -29,19 +29,18 @@ require_once "resources/require.php"; require_once "resources/check_auth.php"; //detect install state - -$first_time_install = true; +$install_enabled = true; if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) { - $first_time_install = false; + $install_enabled = false; } elseif (file_exists("/etc/fusionpbx/config.php")) { //linux - $first_time_install = false; + $install_enabled = false; } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) { - $first_time_install = false; + $install_enabled = false; } -if($first_time_install) { - header("Location: ".PROJECT_PATH."/core/install/install_first_time.php"); +if($install_enabled) { + header("Location: ".PROJECT_PATH."/core/install/install.php"); exit; } require_once "resources/check_auth.php"; diff --git a/core/install/install_first_time.php b/core/install/install similarity index 94% rename from core/install/install_first_time.php rename to core/install/install index 7a60766b93..a3e1189695 100644 --- a/core/install/install_first_time.php +++ b/core/install/install @@ -77,16 +77,16 @@ if (is_link('/etc/localtime')) { date_default_timezone_set($timezone); //detect install state -$first_time_install = true; +$install_enabled = true; if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) { - $first_time_install = false; + $install_enabled = false; } elseif (file_exists("/etc/fusionpbx/config.php")) { - $first_time_install = false; + $install_enabled = false; } 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/check_auth.php"; if (!if_group("superadmin")) { @@ -132,7 +132,7 @@ if(!$install_step) { $install_step = 'select_language'; } } //set a default enviroment if first_time - if($first_time_install){ + if($install_enabled){ //initialize some varibles to cut down on warnings $_SESSION['message'] = ''; $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($install_step =='execute') - { - //start the rocket launch! - + if($install_step =='execute') { //set the max execution time to 1 hour ini_set('max_execution_time',3600); } @@ -224,7 +221,7 @@ if(!$install_step) { $install_step = 'select_language'; } echo " \n"; echo " \n"; echo "\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' )){ echo "

Warning you have choosen a value other than localhost for event_host, this is unsoported at present

\n"; } @@ -242,7 +239,7 @@ if(!$install_step) { $install_step = 'select_language'; } echo " \n"; echo " \n"; echo "\n"; - }else{ + } else { echo "
\n"; echo "
\n"; echo " \n"; @@ -315,14 +312,14 @@ if(!$install_step) { $install_step = 'select_language'; } $switch->install_phase_1(); $system->install_phase_2(); $switch->install_phase_2(); - }catch(Exception $e){ + } catch(Exception $e){ echo "\n"; echo "

Failed to install
" . $e->getMessage() . "

\n"; try { require_once "resources/classes/install_fusionpbx.php"; $system = new install_fusionpbx($global_settings); $system->remove_config(); - }catch(Exception $e){ + } catch(Exception $e){ echo "

Failed to remove config: " . $e->getMessage() . "

\n"; } $install_ok = false; @@ -345,14 +342,14 @@ if(!$install_step) { $install_step = 'select_language'; } echo "

Unkown install_step '$install_step'

\n"; } -if($first_time_install){ +if($install_enabled){ //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['username'] = 'install_enabled'; $_SESSION['permissions'][]['permission_name'] = 'superadmin'; $_SESSION['menu'] = ''; } diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index 45508ab28e..263d796241 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -37,13 +37,13 @@ include "root.php"; public $debug = false; public $echo_progress = false; - public $install_language = 'en-us'; - public $admin_username; - public $admin_password; - public $default_country = 'US'; + public $install_language = 'en-us'; + public $admin_username; + public $admin_password; + public $default_country = 'US'; public $template_name = 'enhanced'; - function __construct($global_settings) { + function __construct($global_settings) { if(is_null($global_settings)){ require_once "resources/classes/global_settings.php"; $global_settings = new global_settings(); @@ -70,7 +70,7 @@ include "root.php"; echo "$message\n"; } } - + function write_progress($message) { if($this->echo_progress){ echo "$message\n"; @@ -93,14 +93,14 @@ include "root.php"; $this->create_menus(); $this->write_progress("Install phase 1 complete for FusionPBX"); } - + function install_phase_2() { ini_set('max_execution_time',3600); $this->write_progress("Install phase 2 started for FusionPBX"); $this->app_defaults(); $this->write_progress("Install phase 2 complete for FusionPBX"); } - + function upgrade() { $this->app_defaults(); } @@ -230,9 +230,9 @@ include "root.php"; } } } - + protected function create_odbc_database_connection() { - //needed for non native database support + //needed for non native database support $database_uuid = uuid(); $sql = "insert into v_databases "; $sql .= "("; @@ -267,147 +267,147 @@ include "root.php"; } 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 - 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) { + //sqlite database will be created when the config.php is loaded and only if the database file does not exist 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) { - throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql ); - } - $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()); + throw new Exception("Failed to create database: " . $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())); + //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); - //close database connection_aborted - $this->dbh = null; - } + //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(); - $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()}"); + //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"; } - } - catch (PDOException $error) { - throw new Exception("error connecting to database: " . $error->getMessage()); - } + 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); - //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) { + //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); } catch (PDOException $error) { throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql ); } + $x++; } - $x++; - } - unset ($file_contents, $sql); + 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() { + //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() { @@ -505,7 +505,8 @@ include "root.php"; $this->dbh = null; } //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 try { $this->dbh = new PDO($connect_string, $this->global_settings->db_username(), db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); diff --git a/core/install/resources/classes/install_switch.php b/core/install/resources/classes/install_switch.php index cecfaf04df..2f2b5925ae 100644 --- a/core/install/resources/classes/install_switch.php +++ b/core/install/resources/classes/install_switch.php @@ -56,7 +56,6 @@ include "root.php"; } //utility Functions - function write_debug($message) { if($this->debug){ echo "$message\n"; @@ -135,7 +134,7 @@ include "root.php"; if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); } $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; diff --git a/core/install/resources/classes/iso_countries.php b/core/install/resources/classes/iso_countries.php index 3609754ab7..ea03a6b5c1 100644 --- a/core/install/resources/classes/iso_countries.php +++ b/core/install/resources/classes/iso_countries.php @@ -1,4 +1,5 @@ 'Afghanistan', @@ -247,4 +248,5 @@ $iso_countries = array 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe', ); + ?> \ No newline at end of file diff --git a/core/install/upgrade_switch.php b/core/install/upgrade_switch.php deleted file mode 100644 index fd34d3c806..0000000000 --- a/core/install/upgrade_switch.php +++ /dev/null @@ -1,59 +0,0 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2012 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -// 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(); - -?> \ No newline at end of file