From 4dd7f9ab251ea8e92a063953a3ecd4a48ef1bdbe Mon Sep 17 00:00:00 2001 From: Giandonato Inverso <70962472+giandonatoinverso@users.noreply.github.com> Date: Sun, 28 Aug 2022 11:24:32 +0200 Subject: [PATCH 1/4] configuration file modification, docker environment variable support --- docker/docker-compose.yml | 17 ++++++++++------- qrcode/config/config.php | 35 +++++++++++++++++++++++++++++++++++ qrcode/config/environment.php | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100755 qrcode/config/config.php create mode 100644 qrcode/config/environment.php diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ebfa217..a9c1932 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -15,13 +15,16 @@ services: ports: - "8080:80" user: "${PUID}:${PGID}" - #environment: - #ADMIN_USER: "superadmin" # not supported yet please see road map - #ADMIN_PASSWORD: "superadmin" # not supported yet please see road map - #DATABASE_HOST: "mariadb" # not supported yet please see road map - #DATABASE_NAME: "qrcode" # not supported yet please see road map - #DATABASE_USER: "qrcode" # not supported yet please see road map - #DATABASE_PASSWORD: "changeme" # not supported yet please see road map + environment: + ADMIN_USER: "superadmin" + ADMIN_PASSWORD: "superadmin" + DATABASE_HOST: "mariadb" + DATABASE_PORT: "3306" + DATABASE_NAME: "qrcode" + DATABASE_USER: "qrcode" + DATABASE_PASSWORD: "changeme" + DATABASE_PREFIX: "" + DATABASE_CHARSET: "utf8" volumes: - ./data/app/config:/var/www/html/config - ./data/app/saved_qrcode:/var/www/html/saved_qrcode diff --git a/qrcode/config/config.php b/qrcode/config/config.php new file mode 100755 index 0000000..cea86f7 --- /dev/null +++ b/qrcode/config/config.php @@ -0,0 +1,35 @@ + DATABASE_HOST, + 'username' => DATABASE_USER, + 'password' => DATABASE_PASSWORD, + 'db'=> DATABASE_NAME, + 'port' => DATABASE_PORT, + 'prefix' => DATABASE_PREFIX, + 'charset' => DATABASE_CHARSET)); +} diff --git a/qrcode/config/environment.php b/qrcode/config/environment.php new file mode 100644 index 0000000..4dcf888 --- /dev/null +++ b/qrcode/config/environment.php @@ -0,0 +1,32 @@ + \ No newline at end of file From c3e04a4357a62280803a6e03e11d4c139a507a59 Mon Sep 17 00:00:00 2001 From: Giandonato Inverso <70962472+giandonatoinverso@users.noreply.github.com> Date: Sun, 28 Aug 2022 11:57:31 +0200 Subject: [PATCH 2/4] new installation process via script, elimination of data entry form for installation Signed-off-by: giandonato.inverso@edempg.it --- qrcode/install/config/database.php | 36 ----- qrcode/install/database.php | 163 --------------------- qrcode/install/finish.php | 63 ++------ qrcode/install/folder-permissions.php | 91 ------------ qrcode/install/includes/core_class.php | 61 -------- qrcode/install/includes/database_class.php | 28 ++-- qrcode/install/index.php | 122 --------------- qrcode/install/setup.php | 62 ++++++++ 8 files changed, 89 insertions(+), 537 deletions(-) delete mode 100644 qrcode/install/config/database.php delete mode 100644 qrcode/install/database.php delete mode 100644 qrcode/install/folder-permissions.php delete mode 100644 qrcode/install/includes/core_class.php delete mode 100644 qrcode/install/index.php create mode 100644 qrcode/install/setup.php diff --git a/qrcode/install/config/database.php b/qrcode/install/config/database.php deleted file mode 100644 index 2c48784..0000000 --- a/qrcode/install/config/database.php +++ /dev/null @@ -1,36 +0,0 @@ -validate_post($_POST) == true) { - // First create the database, then create tables, then write config file - if ($database->create_database($_POST) == false) { - $message = $core->show_message('error', "The database could not be created, please check your database credentials!"); - } else if ($database->create_tables($_POST) == false) { - $message = $core->show_message('error', "The database tables could not be created, please check your database credentials!"); - } else if ($core->write_config($_POST) == false) { - $message = $core->show_message('error', "The database configuration file could not be written, please chmod application/config/database.php file to 777"); - } - - // If no errors, redirect to index - if (!isset($message)) { - header("Refresh: 10; finish.php"); - $installing = 1; - } - } else { - $message = $core->show_message('error', 'Not all fields have been filled in correctly. The host, username, password, and database name are required.'); - } -} - -?> - - - - - - - - - PHP Dynamic Qr code - Installer - - - - - - - - - -
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
-
-
-

Start

-
-
-
-

Folder Permissions

-
-
-
-

Database

-
-
-
-

Finish

-
-
- -
- -
- -
- - -
- The database is being created. Please wait! -
- -
- -
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-

Database

-
- - -
-
- - -
-
- - -
-
- - -
- -
-
-
- Prev - -
-
-
-
-
-
-
-
-
-
- - - diff --git a/qrcode/install/finish.php b/qrcode/install/finish.php index 2abb5e7..da5ddd8 100644 --- a/qrcode/install/finish.php +++ b/qrcode/install/finish.php @@ -1,12 +1,3 @@ - - @@ -14,7 +5,7 @@ if (!file_exists('../config/config.php')) { - PHP Dynamic Qr code - Installer + PHP Dynamic Qr code - Setup @@ -36,52 +27,25 @@ if (!file_exists('../config/config.php')) {
-
- - -
-
-
-
-
-
-

Start

-
-
-
-

Folder Permissions

-
-
-
-

Database

-
-
-
-

Finish

-
-
-
-

Finish

- -

The installation was successful.
Keep the documentation handy and log in to the control panel by entering the default credentials:

+

+ The installation was successful. +
+ Keep the documentation handy and log in to the control panel by entering the default credentials: +

+ superadmin
+ superadmin

+ We recommend that you create a new superadmin user and to delete the default one mentioned above.

-superadmin
-superadmin

- -We recommend that you create a new superadmin user and to delete the default one mentioned above.

- -N.B. Remember to delete the "install" folder otherwise you could accidentally start the installation procedure again, deleting all the saves in the database

-
- -
- - Log in + N.B. Remember to delete the "install" folder otherwise you could accidentally start the installation procedure again, deleting all the saves in the database

+
+ Log in +
@@ -91,6 +55,5 @@ We recommend that you create a new superadmin user and to delete the default one
- diff --git a/qrcode/install/folder-permissions.php b/qrcode/install/folder-permissions.php deleted file mode 100644 index 2c743d6..0000000 --- a/qrcode/install/folder-permissions.php +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - PHP Dynamic Qr code - Installer - - - - - - - - - -
-
-
- -
-
- -
-
- -
-
- -
- - -
-
-
-
-
-
-

Start

-
-
-
-

Folder Permissions

-
-
-
-

Database

-
-
-
-

Finish

-
-
- -
-
-

Folder Permissions

-
-
-

/config

-

/saved_qrcode

-
-
-

-

-
-
-
- Prev - - Next -
-
-
- -
-
-
-
-
-
- - - - diff --git a/qrcode/install/includes/core_class.php b/qrcode/install/includes/core_class.php deleted file mode 100644 index 3716125..0000000 --- a/qrcode/install/includes/core_class.php +++ /dev/null @@ -1,61 +0,0 @@ -/** -* PHP Dynamic Qr code -* -* @author Giandonato Inverso -* @copyright Copyright (c) 2020-2021 -* @license https://opensource.org/licenses/MIT MIT License -* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code -* @version 1.0 -*/ - -* @copyright Copyright (c) 2020-2021 -* @license https://opensource.org/licenses/MIT MIT License -* @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code -* @version 1.0 -*/ + * @copyright Copyright (c) 2020-2021 + * @license https://opensource.org/licenses/MIT MIT License + * @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code + * @version 1.0 + */ class Database { // Function to the database and tables and fill them with the default data - function create_database($data) + function create_database($db_host, $db_user, $db_password, $db_name, $db_port) { // Connect to the database - $mysqli = new mysqli($data['db_host'],$data['db_user'],$data['db_password'],''); + $mysqli = new mysqli($db_host,$db_user,$db_password,'', $db_port); // Check for errors if(mysqli_connect_errno()) return false; // Create the prepared statement - $mysqli->query("CREATE DATABASE IF NOT EXISTS ".$data['db_name']); + $mysqli->query("CREATE DATABASE IF NOT EXISTS ".$db_name); // Close the connection $mysqli->close(); @@ -31,10 +31,10 @@ class Database { } // Function to create the tables and fill them with the default data - function create_tables($data) + function create_tables($db_host, $db_user, $db_password, $db_name, $db_port) { // Connect to the database - $mysqli = new mysqli($data['db_host'],$data['db_user'],$data['db_password'],$data['db_name']); + $mysqli = new mysqli($db_host,$db_user,$db_password,$db_name, $db_port); // Check for errors if(mysqli_connect_errno()) diff --git a/qrcode/install/index.php b/qrcode/install/index.php deleted file mode 100644 index 5c915ee..0000000 --- a/qrcode/install/index.php +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - - - PHP Dynamic Qr code - Installer - - - - - - - - - -
-
-
- -
-
- - - -
-
- -
-
- -
- - -
-
-
-
-
-
-

Start

-
-
-
-

Folder Permissions

-
-
-
-

Database

-
-
-
-

Finish

-
-
- -
-
-

System Requirements

-
-
-

-    PHP Version: - = 5.6): ?> - - -  (Your PHP version must be 5.6 or greater) - - -

-

-    cURL PHP Extension: - - Enabled - - Disabled (You should enable "cURL" in your server) - - -

- -
-
-

- = 5.6): ?> - - - - -

-

- - - - - -

- -
-
- -
- - Next -
- -
-
-
-
-
-
-
-
- - - - diff --git a/qrcode/install/setup.php b/qrcode/install/setup.php new file mode 100644 index 0000000..f16f6ee --- /dev/null +++ b/qrcode/install/setup.php @@ -0,0 +1,62 @@ + + * @copyright Copyright (c) 2020-2021 + * @license https://opensource.org/licenses/MIT MIT License + * @link https://github.com/giandonatoinverso/PHP-Dynamic-Qr-code + * @version 1.0 + */ + +require_once ('../config/environment.php'); +require_once('includes/database_class.php'); + +/* +|-------------------------------------------------------------------------- +| CHECK REQUIREMENTS +|-------------------------------------------------------------------------- + */ + +if (!(phpversion() >= 5.6)) { + echo "Installation failed. A php version> = 5.6 is required"; + die(); +} + +if (!extension_loaded('curl')) { + echo "Installation failed. The curl extension is required"; + die(); +} + +/* +|-------------------------------------------------------------------------- +| CHECK FOLDER PERMISSION +|-------------------------------------------------------------------------- + */ + +if (!is_writable('../saved_qrcode')) { + echo "Installation failed. The folder where you save the qrcodes must have write permissions"; + die(); +} + +/* +|-------------------------------------------------------------------------- +| DATABASE CREATION +|-------------------------------------------------------------------------- + */ + +$database = new Database(); + +if (!$database->create_database(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)) { + echo "The database could not be created, please check your database credentials!"; + die(); +} +else if (!$database->create_tables(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)) { + echo "The database tables could not be created, please check your database credentials!"; + die(); +} + +// If no errors, redirect to index +header("Refresh: 1; finish.php"); + +?> \ No newline at end of file From 59c6dc92336cbc5641f77490107dabf5a5d3b478 Mon Sep 17 00:00:00 2001 From: Giandonato Inverso <70962472+giandonatoinverso@users.noreply.github.com> Date: Sun, 28 Aug 2022 12:04:48 +0200 Subject: [PATCH 3/4] doc update Signed-off-by: giandonato.inverso@edempg.it --- documentation/index.html | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/documentation/index.html b/documentation/index.html index 635ea65..b8eb1d2 100644 --- a/documentation/index.html +++ b/documentation/index.html @@ -67,7 +67,7 @@
@@ -86,18 +86,12 @@

Installation

Follow these steps to install the script:

    -
  1. Extract the zip archive to your server
  2. -
  3. Open the /install/ folder in the browser
  4. -

    Check system requirements. If one of these extensions is not enabled, you must enable it from your server settings. If all requirements are provided, click Next.

    - -
  5. Check folder permissions
  6. -

    If a folder doesn't have read and write permissions you need to change the settings on your server. If all requirements are provided, click Next.

    - -
  7. Enter your database credentials. Click next.
  8. -

    - +
  9. Clone the project from github
  10. +
  11. Edit the yaml file for docker or manually enter the credentials you want in the /config/environment.php file
  12. +
  13. Launch the setup file in your browser /install/setup.php
  14. +

    The script checks the requirements, write permissions on the generated folders and creates a database with sample data

  15. Finish
  16. -

    The installation is finished and you can access the control panel.

    +

    If all went well you will see a summary screen with a login button. Alternatively, you will get an error message

From dfaee77d861b33769a6814314fff7a7973710972 Mon Sep 17 00:00:00 2001 From: Giandonato Inverso <70962472+giandonatoinverso@users.noreply.github.com> Date: Sun, 28 Aug 2022 12:33:14 +0200 Subject: [PATCH 4/4] Update README.md --- docker/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docker/README.md b/docker/README.md index ceb831a..0c6e838 100644 --- a/docker/README.md +++ b/docker/README.md @@ -6,8 +6,7 @@ - `PUID="$(id -u)" PGID="$(id -g)" docker-compose up --build -d` - Run and build this image as specific user - `PUID="1000" PGID="1000" docker-compose up --build -d` -- Run app installation :8080/install - - Provide Database credentials +- Run app installation :8080/install/setup.php - Default login: :8080 - user: superadmin - password: superadmin @@ -15,7 +14,6 @@ ### Roadmap - Make install process run via docker-compose. - Work is partially done. docker-entrypoint.sh is created.(currently disabled due to next steps are pending) - - qrcode/install/database.php should be adjusted to create database without form submission. - Make it possible to set PUID and GUID, from environment variable in docker-compose.yml . - Reduce image size by removing unnecessary dependencies. - Automate Build image and push to docker hub. @@ -24,4 +22,4 @@ ### some debug commands - `docker-compose logs` - `PUID="$(id -u)" PGID="$(id -g)" docker-compose config` -- `ps -aef | grep apache2` \ No newline at end of file +- `ps -aef | grep apache2`