From 03ae41b78d490e360cafd4531573c0943a3f2834 Mon Sep 17 00:00:00 2001 From: "alvarenga.milton" Date: Sun, 3 Mar 2019 16:13:26 -0300 Subject: [PATCH 1/3] Improved install process removing SQL code from process.php file and creating one file per database type --- components/install/process.php | 135 +++----------------------- components/install/sql/mysql.sql | 57 +++++++++++ components/install/sql/postgresql.sql | 53 ++++++++++ 3 files changed, 121 insertions(+), 124 deletions(-) create mode 100644 components/install/sql/mysql.sql create mode 100644 components/install/sql/postgresql.sql diff --git a/components/install/process.php b/components/install/process.php index 7777822..5cccdbd 100755 --- a/components/install/process.php +++ b/components/install/process.php @@ -98,11 +98,12 @@ if ( ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && de $aValidDBType = [ 'mysql' ,'postgresql' + //,'sqlite' ]; //Is selected database type valid? if(!in_array($dbtype,$aValidDBType)){ - die( "Invalid database. Please select one of ".implode(", "$aValidDBType)."." ); + die( "Invalid database. Please select one of ".implode(", ",$aValidDBType)."." ); } try { @@ -115,130 +116,16 @@ if ( ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && de } $bind_vars = array(); $bind = ""; - $sql = []; - $sql['mysql'] = " - --- --- Table structure for table options --- - -CREATE TABLE IF NOT EXISTS options ( - id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - name varchar(255) NOT NULL, - value text NOT NULL, - CONSTRAINT option_name UNIQUE (name) -); - --- -------------------------------------------------------- - --- --- Table structure for table projects --- - -CREATE TABLE IF NOT EXISTS projects ( - id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - name varchar(255) NOT NULL, - path varchar(255) NOT NULL, - owner varchar(255) NOT NULL, - access text, - CONSTRAINT project UNIQUE (path, owner) -); - --- -------------------------------------------------------- - --- --- Table structure for table users --- - -CREATE TABLE IF NOT EXISTS users ( - id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - first_name varchar(255) DEFAULT NULL, - last_name varchar(255) DEFAULT NULL, - username varchar(255) NOT NULL, - password text NOT NULL, - email varchar(255) DEFAULT NULL, - project varchar(255) DEFAULT NULL, - access varchar(255) NOT NULL, - groups text, - token text, - CONSTRAINT username UNIQUE (username) -); - --- --- Table structure for table user_options --- - -CREATE TABLE IF NOT EXISTS user_options ( - id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - name varchar(255) NOT NULL, - username varchar(255) NOT NULL, - value text NOT NULL, - CONSTRAINT option_name UNIQUE (name,username) -); - -"; - - $sql['postgresql'] = " - --- --- Table structure for table options --- - -CREATE TABLE IF NOT EXISTS options ( - id SERIAL PRIMARY KEY, - name varchar(255) NOT NULL UNIQUE, - value TEXT NOT NULL -); - --- -------------------------------------------------------- - --- --- Table structure for table projects --- - -CREATE TABLE IF NOT EXISTS projects ( - id SERIAL PRIMARY KEY, - name varchar(255) NOT NULL, - path varchar(255) NOT NULL UNIQUE, - owner varchar(255) NOT NULL UNIQUE, - access text -); - --- -------------------------------------------------------- - --- --- Table structure for table users --- - -CREATE TABLE IF NOT EXISTS users ( - id SERIAL PRIMARY KEY, - first_name varchar(255) DEFAULT NULL, - last_name varchar(255) DEFAULT NULL, - username varchar(255) NOT NULL UNIQUE, - password text NOT NULL, - email varchar(255) DEFAULT NULL, - project varchar(255) DEFAULT NULL, - access varchar(255) NOT NULL, - groups text, - token text -); - --- --- Table structure for table user_options --- - -CREATE TABLE IF NOT EXISTS user_options ( - id SERIAL PRIMARY KEY, - name varchar(255) NOT NULL UNIQUE, - username varchar(255) NOT NULL UNIQUE, - value text NOT NULL -); - -"; + $database_sql_fullpath = $path.'/components/install/sql/'.$dbtype.".sql"; + if(!is_file($database_sql_fullpath)){ + die("Could not find the sql of the database ".$dbtype." to execute"); + } + $sql = file_get_contents($database_sql_fullpath); + try { - - $result = $connection->exec($sql[$dbtype]); + //Create the database + $result = $connection->exec($sql); } catch( PDOException $e ) { die($e->getMessage()); @@ -405,4 +292,4 @@ define("WSURL", BASE_URL . "/workspace"); saveFile( $config, $config_data ); echo( "success" ); -} \ No newline at end of file +} diff --git a/components/install/sql/mysql.sql b/components/install/sql/mysql.sql new file mode 100644 index 0000000..332b413 --- /dev/null +++ b/components/install/sql/mysql.sql @@ -0,0 +1,57 @@ +-- +-- Table structure for table options +-- + +CREATE TABLE IF NOT EXISTS options ( + id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + name varchar(255) NOT NULL, + value text NOT NULL, + CONSTRAINT option_name UNIQUE (name) +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table projects +-- + +CREATE TABLE IF NOT EXISTS projects ( + id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + name varchar(255) NOT NULL, + path varchar(255) NOT NULL, + owner varchar(255) NOT NULL, + access text, + CONSTRAINT project UNIQUE (path, owner) +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table users +-- + +CREATE TABLE IF NOT EXISTS users ( + id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + first_name varchar(255) DEFAULT NULL, + last_name varchar(255) DEFAULT NULL, + username varchar(255) NOT NULL, + password text NOT NULL, + email varchar(255) DEFAULT NULL, + project varchar(255) DEFAULT NULL, + access varchar(255) NOT NULL, + groups text, + token text, + CONSTRAINT username UNIQUE (username) +); + +-- +-- Table structure for table user_options +-- + +CREATE TABLE IF NOT EXISTS user_options ( + id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + name varchar(255) NOT NULL, + username varchar(255) NOT NULL, + value text NOT NULL, + CONSTRAINT option_name UNIQUE (name,username) +); diff --git a/components/install/sql/postgresql.sql b/components/install/sql/postgresql.sql new file mode 100644 index 0000000..3147dde --- /dev/null +++ b/components/install/sql/postgresql.sql @@ -0,0 +1,53 @@ +-- +-- Table structure for table options +-- + +CREATE TABLE IF NOT EXISTS options ( + id SERIAL PRIMARY KEY, + name varchar(255) NOT NULL UNIQUE, + value TEXT NOT NULL +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table projects +-- + +CREATE TABLE IF NOT EXISTS projects ( + id SERIAL PRIMARY KEY, + name varchar(255) NOT NULL, + path varchar(255) NOT NULL UNIQUE, + owner varchar(255) NOT NULL UNIQUE, + access text +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table users +-- + +CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + first_name varchar(255) DEFAULT NULL, + last_name varchar(255) DEFAULT NULL, + username varchar(255) NOT NULL UNIQUE, + password text NOT NULL, + email varchar(255) DEFAULT NULL, + project varchar(255) DEFAULT NULL, + access varchar(255) NOT NULL, + groups text, + token text +); + +-- +-- Table structure for table user_options +-- + +CREATE TABLE IF NOT EXISTS user_options ( + id SERIAL PRIMARY KEY, + name varchar(255) NOT NULL UNIQUE, + username varchar(255) NOT NULL UNIQUE, + value text NOT NULL +); From 6ab45f07ab066cd595701a85c87c7ae7f19cd733 Mon Sep 17 00:00:00 2001 From: "alvarenga.milton" Date: Sun, 3 Mar 2019 16:27:59 -0300 Subject: [PATCH 2/3] Added SQL install file compatible with SQLite for future use, when all queries and PDO connections has been adapted to support this new database --- components/install/sql/sqlite.sql | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 components/install/sql/sqlite.sql diff --git a/components/install/sql/sqlite.sql b/components/install/sql/sqlite.sql new file mode 100644 index 0000000..4eec35e --- /dev/null +++ b/components/install/sql/sqlite.sql @@ -0,0 +1,53 @@ +-- +-- Table structure for table options +-- + +CREATE TABLE IF NOT EXISTS options ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name CHAR(255) NOT NULL UNIQUE, + value TEXT NOT NULL +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table projects +-- + +CREATE TABLE IF NOT EXISTS projects ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name CHAR(255) NOT NULL, + path CHAR(255) NOT NULL UNIQUE, + owner CHAR(255) NOT NULL UNIQUE, + access text +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table users +-- + +CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + first_name CHAR(255) DEFAULT NULL, + last_name CHAR(255) DEFAULT NULL, + username CHAR(255) NOT NULL UNIQUE, + password text NOT NULL, + email CHAR(255) DEFAULT NULL, + project CHAR(255) DEFAULT NULL, + access CHAR(255) NOT NULL, + groups text, + token text +); + +-- +-- Table structure for table user_options +-- + +CREATE TABLE IF NOT EXISTS user_options ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name CHAR(255) NOT NULL UNIQUE, + username CHAR(255) NOT NULL UNIQUE, + value text NOT NULL +); From 38e402a4b82777a30623167932e8c1c2306e7dc0 Mon Sep 17 00:00:00 2001 From: "alvarenga.milton" Date: Sun, 3 Mar 2019 17:04:50 -0300 Subject: [PATCH 3/3] Added htmlentities for filename and folders with special character --- components/filemanager/class.filemanager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index b33cd6a..8128af3 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -709,7 +709,7 @@ class Filemanager extends Common { "url"=>$add, "thumbnail_url"=>$add, "delete_url"=>$add, - "delete_type"=>"DELETE" + "delete_type"=>'DELETE' ); } } @@ -785,4 +785,4 @@ class Filemanager extends Common { return $path; } -} \ No newline at end of file +}