From 26b376cad88472e4e01ce6162103c5025626782d Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Tue, 29 Mar 2016 14:43:58 +0300 Subject: [PATCH 1/3] Fix. Generate same `config.lua` on install as on Upgrade. --- .../resources/classes/install_switch.php | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/core/install/resources/classes/install_switch.php b/core/install/resources/classes/install_switch.php index 3467d00507..1255488575 100644 --- a/core/install/resources/classes/install_switch.php +++ b/core/install/resources/classes/install_switch.php @@ -52,7 +52,7 @@ include "root.php"; }else{ throw new Exception("Could not work out where to put the config.lua"); } - $this->config_lua = normalize_path_to_os($this->config_lua); + $this->config_lua = normalize_path($this->config_lua); } //utility Functions @@ -244,46 +244,46 @@ include "root.php"; $tmp = "\n"; $tmp .= "--set the variables\n"; if (strlen($this->global_settings->switch_sounds_dir()) > 0) { - $tmp .= normalize_path_to_os(" sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n"); + $tmp .= normalize_path(" sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n"); } if (strlen($this->global_settings->switch_phrases_vdir()) > 0) { - $tmp .= normalize_path_to_os(" phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n"); + $tmp .= normalize_path(" phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n"); } if (strlen($this->global_settings->switch_db_dir()) > 0) { - $tmp .= normalize_path_to_os(" database_dir = [[".$this->global_settings->switch_db_dir()."]];\n"); + $tmp .= normalize_path(" database_dir = [[".$this->global_settings->switch_db_dir()."]];\n"); } if (strlen($this->global_settings->switch_recordings_dir()) > 0) { - $tmp .= normalize_path_to_os(" recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n"); + $tmp .= normalize_path(" recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n"); } if (strlen($this->global_settings->switch_storage_dir()) > 0) { - $tmp .= normalize_path_to_os(" storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n"); + $tmp .= normalize_path(" storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n"); } if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) { - $tmp .= normalize_path_to_os(" voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n"); + $tmp .= normalize_path(" voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n"); } if (strlen($this->global_settings->switch_script_dir()) > 0) { - $tmp .= normalize_path_to_os(" scripts_dir = [[".$this->global_settings->switch_script_dir()."]];\n"); + $tmp .= normalize_path(" scripts_dir = [[".$this->global_settings->switch_script_dir()."]];\n"); } - $tmp .= normalize_path_to_os(" php_dir = [[".PHP_BINDIR."]];\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_to_os(" document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\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_to_os(" database[\"path\"] = [[".$this->global_settings->db_path()."]];\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"; + $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(); @@ -294,41 +294,41 @@ include "root.php"; 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"; + $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"; + $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 .= " 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.conf\"] = \"3600\";\n"; - $tmp .= " expire[\"acl.conf\"] = \"3600\";\n"; + $tmp .= " expire.directory = \"3600\";\n"; + $tmp .= " expire.dialplan = \"3600\";\n"; + $tmp .= " expire.languages = \"3600\";\n"; + $tmp .= " expire.sofia_conf = \"3600\";\n"; + $tmp .= " expire.acl_conf = \"3600\";\n"; $tmp .= "\n"; $tmp .= "--set xml_handler\n"; $tmp .= " xml_handler = {}\n"; - $tmp .= " xml_handler[\"fs_path\"] = false;\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 .= " 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_to_os(" temp_dir = [[".$this->global_settings->switch_temp_dir()."]];\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"; } From 9657d3ef0472a2c4791e28d4da53ff1d438ca2f2 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 30 Mar 2016 15:05:25 +0300 Subject: [PATCH 2/3] Fix. Install with create new database for PgSQL/MySQL * MySQL/PgSQL ignore error while create new user because user may already exists. * MySQL on database page use same checkbox like one for PgSQL * MySQL/PgSQL if create user empty try use db user.(may be better use root/postgres without pass) * PgSQL fix `GRANT ALL ON DATABASE dbname` instead of `GRANT ALL ON dbname` * MySQL fix connect string build * MySQL fix use correct password to connect --- .../resources/classes/install_fusionpbx.php | 289 ++++++++++-------- .../page_parts/install_config_database.php | 12 +- 2 files changed, 162 insertions(+), 139 deletions(-) diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index 57bc4981a7..663e38c93d 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -332,12 +332,20 @@ include "root.php"; if ($this->global_settings->db_create()) { //attempt to create new Postgres role and database $this->write_progress("\tCreating database"); + $db_create_username = $this->global_settings->db_create_username(); + $db_create_password = $this->global_settings->db_create_password(); + $db_host = $this->global_settings->db_host(); + $db_port = $this->global_settings->db_port(); + if(strlen($db_create_username) == 0){ + $db_create_username = $this->global_settings->db_username(); + $db_create_password = $this->global_settings->db_password(); + } + if (strlen($db_host) == 0) { + $db_host = 'localhost'; + } + 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"); - } + $this->dbh = new PDO("pgsql:host=$db_host port=$db_port user=$db_create_username password=$db_create_password dbname=template1"); } catch (PDOException $error) { throw new Exception("error connecting to database in order to create: " . $error->getMessage()); } @@ -346,11 +354,12 @@ include "root.php"; 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->global_settings->db_username() != $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())); + // user may be already exists + // 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){ + if($this->dbh->exec("GRANT ALL ON DATABASE {$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())); } } @@ -410,128 +419,148 @@ include "root.php"; } protected function create_database_mysql() { - //database connection - $connect_string; - if (strlen($this->global_settings->db_host()) == 0 && strlen($this->global_settings->db_port()) == 0) { - //if both host and port are empty use the unix socket - $connect_string = "mysql:host=$this->global_settings->db_host();unix_socket=/var/run/mysqld/mysqld.sock;"; - } - elseif (strlen($this->global_settings->db_port()) == 0) { - //leave out port if it is empty - $connect_string = "mysql:host=$this->global_settings->db_host();"; - } - else { - $connect_string = "mysql:host=$this->global_settings->db_host();port=$this->global_settings->db_port();"; - } + //database connection + $connect_string; + if (strlen($this->global_settings->db_host()) == 0 && strlen($this->global_settings->db_port()) == 0) { + //if both host and port are empty use the unix socket + $connect_string = "mysql:host={$this->global_settings->db_host()};unix_socket=/var/run/mysqld/mysqld.sock;"; + } + elseif (strlen($this->global_settings->db_port()) == 0) { + //leave out port if it is empty + $connect_string = "mysql:host={$this->global_settings->db_host()};"; + } + else { + $connect_string = "mysql:host={$this->global_settings->db_host()};port={$this->global_settings->db_port()};"; + } - //create the table, user and set the permissions only if the db_create_username was provided - if ($this->global_settings->db_create_username()) { + //if we need create new database + if ($this->global_settings->db_create()) { + //attempt to create new user and database $this->write_progress("\tCreating database"); + $db_create_username = $this->global_settings->db_create_username(); + $db_create_password = $this->global_settings->db_create_password(); + + if(strlen($db_create_username) == 0){ + $db_create_username = $this->global_settings->db_username(); + $db_create_password = $this->global_settings->db_password(); + } + + //connect to MySQL try { - $this->dbh = new PDO($connect_string, $this->global_settings->db_create_username(), $this->global_settings->db_create_password(), array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); + $this->dbh = new PDO($connect_string, $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); } catch (PDOException $error) { - throw new Exception("error connecting to database for ccreate: " . $error->getMessage() . "\n" . $sql ); + throw new Exception("error connecting to database for create: " . $error->getMessage() . "\n" . $sql ); } - //select the mysql database - try { - $this->dbh->query("USE mysql;"); - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } - //create user and set the permissions - try { - $tmp_sql = "CREATE USER '".$this->global_settings->db_username()."'@'%' IDENTIFIED BY '".$this->global_settings->db_password()."'; "; - $this->dbh->query($tmp_sql); - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } + //select the mysql database + try { + $this->dbh->query("USE mysql;"); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } - //set account to unlimited use - try { - if ($this->global_settings->db_host() == "localhost" || $this->global_settings->db_host() == "127.0.0.1") { - $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'localhost' "; - $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $this->dbh->query($tmp_sql); - - $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'127.0.0.1' "; - $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + //create user if we use separeate user to access and create + if($this->global_settings->db_username() != $db_create_username) { + //create user and set the permissions + try { + $tmp_sql = "CREATE USER '".$this->global_settings->db_username()."'@'%' IDENTIFIED BY '".$this->global_settings->db_password()."'; "; $this->dbh->query($tmp_sql); } - else { - $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'".$this->global_settings->db_host()."' "; - $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; - $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; - $this->dbh->query($tmp_sql); + catch (PDOException $error) { + // ignore error here because user may already exists + // (e.g. reinstall can be done via remove db) + // throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); } - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } - //create the database and set the create user with permissions - try { - $tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->global_settings->db_name()."; "; - $this->dbh->query($tmp_sql); - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } + //set account to unlimited use + try { + if ($this->global_settings->db_host() == "localhost" || $this->global_settings->db_host() == "127.0.0.1") { + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'localhost' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); - //set user permissions + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'127.0.0.1' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); + } + else { + $tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'".$this->global_settings->db_host()."' "; + $tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' "; + $tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; "; + $this->dbh->query($tmp_sql); + } + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + } + + //create the database and set the create user with permissions + try { + $tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->global_settings->db_name()."; "; + $this->dbh->query($tmp_sql); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + + //set user permissions + if($this->global_settings->db_username() != $db_create_username) { try { $this->dbh->query("GRANT ALL PRIVILEGES ON ".$this->global_settings->db_name().".* TO '".$this->global_settings->db_username()."'@'%'; "); } catch (PDOException $error) { throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); } + } - //make the changes active - try { - $tmp_sql = "FLUSH PRIVILEGES; "; - $this->dbh->query($tmp_sql); - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } - $this->dbh = null; - } //if (strlen($this->global_settings->db_create_username()) > 0) + //make the changes active + try { + $tmp_sql = "FLUSH PRIVILEGES; "; + $this->dbh->query($tmp_sql); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } + $this->dbh = null; + } - $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')); - $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - } - catch (PDOException $error) { - throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql ); - } - try { - $this->dbh->query("USE ".$this->global_settings->db_name().";"); - } - catch (PDOException $error) { - throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); - } + //connect to the database + try { + $this->dbh = new PDO($connect_string, $this->global_settings->db_username(), $this->global_settings->db_password(), array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); + $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + } + catch (PDOException $error) { + throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql ); + } - //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(); + //select the database + try { + $this->dbh->query("USE ".$this->global_settings->db_name().";"); + } + catch (PDOException $error) { + throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql ); + } - //add the defaults data into the database - //get the contents of the sql file + //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(); + + //add the defaults data into the database + //get the contents of the sql file if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql')){ $filename = "/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql"; } @@ -540,28 +569,28 @@ include "root.php"; } $file_contents = file_get_contents($filename); - //replace \r\n with \n then explode on \n - $file_contents = str_replace("\r\n", "\n", $file_contents); + //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 { - if ($this->debug) { - $this->write_debug( $sql."\n"); - } - $this->dbh->query($sql); - } - catch (PDOException $error) { - //echo "error on line $x: " . $error->getMessage() . " sql: $sql
"; - //die(); + //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 { + if ($this->debug) { + $this->write_debug( $sql."\n"); } + $this->dbh->query($sql); + } + catch (PDOException $error) { + //echo "error on line $x: " . $error->getMessage() . " sql: $sql
"; + //die(); } - $x++; } - unset ($file_contents, $sql); + $x++; + } + unset ($file_contents, $sql); } protected function create_domain() { @@ -1000,7 +1029,7 @@ include "root.php"; $_SESSION['event_socket_ip_address'] = $this->global_settings->event_host; $_SESSION['event_socket_port'] = $this->global_settings->event_port; $_SESSION['event_socket_password'] = $this->global_settings->event_password; - + //get the groups assigned to the user and then set the groups in $_SESSION["groups"] $sql = "SELECT * FROM v_group_users "; $sql .= "where domain_uuid=:domain_uuid "; @@ -1012,7 +1041,7 @@ include "root.php"; $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $_SESSION["groups"] = $result; unset($sql, $row_count, $prep_statement); - + //get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions'] $x = 0; $sql = "select distinct(permission_name) from v_group_permissions "; @@ -1031,7 +1060,7 @@ include "root.php"; $prep_statement_sub->execute(); $_SESSION['permissions'] = $prep_statement_sub->fetchAll(PDO::FETCH_NAMED); unset($sql, $prep_statement_sub); - + //include the config.php $db_type = $this->global_settings->db_type(); $db_path = $this->global_settings->db_path(); @@ -1040,23 +1069,23 @@ include "root.php"; $db_name = $this->global_settings->db_name(); $db_username = $this->global_settings->db_username(); $db_password = $this->global_settings->db_password(); - + //add the database structure require_once "resources/classes/schema.php"; $schema = new schema; echo $schema->schema(); - + //run all app_defaults.php files $default_language = $this->install_language; $domain = new domains; $domain->upgrade(); - + //synchronize the config with the saved settings save_switch_xml(); - + //do not show the apply settings reminder on the login page $_SESSION["reload_xml"] = false; - + //clear the menu $_SESSION["menu"] = ""; diff --git a/core/install/resources/page_parts/install_config_database.php b/core/install/resources/page_parts/install_config_database.php index 9abde70626..1c89150c95 100644 --- a/core/install/resources/page_parts/install_config_database.php +++ b/core/install/resources/page_parts/install_config_database.php @@ -142,15 +142,9 @@ echo " Create Database Options\n"; echo "\n"; echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; + if($db_create=='1') { $checked = "checked='checked'"; } else { $checked = ''; } + echo "  "; + echo "Create the database\n"; echo "
\n"; echo "Choose whether to create the database\n"; echo "\n"; From 14973b5c972ac27ec3ebe2e6f0719e746b5f59aa Mon Sep 17 00:00:00 2001 From: reliberate Date: Fri, 1 Apr 2016 19:44:26 -0600 Subject: [PATCH 3/3] Functions: Enhance img_spacer() function. Dialplan Edit: Integrate img_spacer() to fix row divider. Default/Domain/User Settings: Use img_spacer() function for color swatches. Contact Times: Adjust for recent changes on img_spacer() function. --- app/contacts/contact_times.php | 6 +++--- app/dialplan/dialplan_edit.php | 2 +- core/default_settings/default_settings.php | 2 +- core/domain_settings/domain_settings.php | 21 +++++++++------------ core/users/user_settings.php | 17 +++++++---------- resources/functions.php | 4 ++-- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/app/contacts/contact_times.php b/app/contacts/contact_times.php index 619cfc454c..d3336cdb3e 100644 --- a/app/contacts/contact_times.php +++ b/app/contacts/contact_times.php @@ -61,18 +61,18 @@ else { echo "\n"; echo "\n"; - echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; diff --git a/app/dialplan/dialplan_edit.php b/app/dialplan/dialplan_edit.php index eb0a117c9a..25b3b7082a 100644 --- a/app/dialplan/dialplan_edit.php +++ b/app/dialplan/dialplan_edit.php @@ -760,7 +760,7 @@ else { //end the row echo "\n"; if ($index != 999) { - echo ""; + echo ""; } //increment the value $x++; diff --git a/core/default_settings/default_settings.php b/core/default_settings/default_settings.php index d1a1b75a54..3a29169321 100644 --- a/core/default_settings/default_settings.php +++ b/core/default_settings/default_settings.php @@ -427,7 +427,7 @@ else { } else { if ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) { - echo " "; + echo " ".(img_spacer('15px', '15px', 'background: '.$row['default_setting_value'].'; margin-right: 4px; vertical-align: middle; border: 1px solid '.(color_adjust($row['default_setting_value'], -0.18)).'; padding: -1px;')); echo "".htmlspecialchars($row['default_setting_value'])."\n"; } else { diff --git a/core/domain_settings/domain_settings.php b/core/domain_settings/domain_settings.php index 1a3cb87425..1765018fdb 100644 --- a/core/domain_settings/domain_settings.php +++ b/core/domain_settings/domain_settings.php @@ -224,13 +224,13 @@ if (sizeof($_REQUEST) > 1) { echo $sub_row["menu_language"]." - ".$sub_row["menu_name"]."\n"; } } - elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) { + else if ($category == "domain" && $subcategory == "template" && $name == "name" ) { echo " ".ucwords($row['domain_setting_value']); } else if ($category == "domain" && $subcategory == "time_format" && $name == "text" ) { - switch ($row['domain_setting_value'] == '12h') { - case '12h': echo " ".$text['label-12-hour']; break; - case '24h': echo " ".$text['label-24-hour']; break; + switch ($row['domain_setting_value']) { + case '12h': echo $text['label-12-hour']; break; + case '24h': echo $text['label-24-hour']; break; } } else if ( @@ -247,16 +247,13 @@ if (sizeof($_REQUEST) > 1) { } else { if ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) { - $border = ( - substr_count(strtolower($row['domain_setting_value']), '#fff') > 0 || - substr_count(strtolower($row['domain_setting_value']), '#ffffff') > 0 || - substr_count(str_replace(' ','',strtolower($row['domain_setting_value'])), '255,255,255,') > 0 - ) ? "border: 1px solid #ccc; padding: -1px;" : null; - echo " "; + echo " ".(img_spacer('15px', '15px', 'background: '.$row['domain_setting_value'].'; margin-right: 4px; vertical-align: middle; border: 1px solid '.(color_adjust($row['domain_setting_value'], -0.18)).'; padding: -1px;')); + echo "".htmlspecialchars($row['domain_setting_value'])."\n"; + } + else { + echo " ".htmlspecialchars($row['domain_setting_value'])."\n"; } - echo " ".htmlspecialchars($row['domain_setting_value']); } - echo "  \n"; echo " \n"; echo " \n"; echo "
".$text['label-time_user']."".$text['label-time_start']."".$text['label-time_duration']."".$text['label-time_description'].""; - echo img_spacer('25px', '1px', 'none'); + echo img_spacer('25px', '1px'); if (permission_exists('contact_time_add')) { echo "$v_link_label_add"; } else { - echo img_spacer('25px', '1px', 'none'); + echo img_spacer('25px', '1px'); } echo "
".(img_spacer('100%', '1px', 'border-bottom: 1px solid #e5e9f0; margin: 0; padding: 0; display: block;'))."