diff --git a/.gitignore b/.gitignore index 183d197..c0947aa 100644 --- a/.gitignore +++ b/.gitignore @@ -26,11 +26,8 @@ # (license.md in the root folder of this project) If not, see . -# Configuration files -config.php - -# Docker Secrets -**/secrets/ +# Data directory of MariaDB +data/* # Include all README files !**/README.md @@ -41,7 +38,7 @@ config.php .project .pydevproject -.bak +*.bak ### WINDOWS ### desktop.ini diff --git a/data/README.md b/data/README.md new file mode 100644 index 0000000..bcea1ba --- /dev/null +++ b/data/README.md @@ -0,0 +1,32 @@ +**************************************************************************************************** +* ______ _ _ * +* | ____| /\ (_) | | * +* | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ * +* | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| * +* | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ * +* |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ * +* | | | | * +* |_| |_| * +* * +**************************************************************************************************** + +This file is part of the European Airports Project, a free, collaborative platform of airport data +extending beyond the official AIPs. + +Copyright (C) 2023 + +Florian Meissner + +This program is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software Foundation, either +version 3 of the License, or (at your option) any later version. This program is distributed in the +hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with this program. +(license.md in the root folder of this project) If not, see . + + +# MariaDB Data Directory + +This directory will be mounted to the MariaDB service and provide a persitend storage for the +database files. diff --git a/init/02-ddl/01-mysql_user.sql b/init/02-ddl/01-mysql_user.sql new file mode 100644 index 0000000..2b6435c --- /dev/null +++ b/init/02-ddl/01-mysql_user.sql @@ -0,0 +1,93 @@ +-- **************************************************************************************************** +-- * ______ _ _ * +-- * | ____| /\ (_) | | * +-- * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ * +-- * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| * +-- * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ * +-- * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ * +-- * | | | | * +-- * |_| |_| * +-- * * +-- **************************************************************************************************** + +-- This file is part of the European Airports Project, a free, collaborative platform of airport data +-- extending beyond the official AIPs. + +-- Copyright (C) 2023 + +-- Florian Meissner + +-- This program is free software: you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software Foundation, either +-- version 3 of the License, or (at your option) any later version. This program is distributed in the +-- hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +-- details. You should have received a copy of the GNU General Public License along with this program. +-- (license.md in the root folder of this project) If not, see . + + +USE mysql; + +-- Create a user and grant rights from Docker secrets + +-- The procedure expects the secrets base name. It will be expected that for each user the following +-- secrets are mounted: +-- - BASENAME_name The users username +-- - BASENAME_pw The users password +-- - BASENAME_grantTable The database table on which privileges should be granted. If missing or +-- empty, the privileges will be grated to *.* +-- - BASENAME_privileges The privileges that should be granted on the above table. If missing or +-- empty, ALL PRIVILEGES will be granted. +DELIMITER $ +CREATE OR REPLACE PROCEDURE `CREATE_USER`( + IN `secretBase` VARCHAR(128) +) +COMMENT 'Create a user from Docker secrets' +CONTAINS SQL +BEGIN + + -- Read data from secrets + SET @SECRET_PATH = '/run/secrets/'; + SET @username = LOAD_FILE(CONCAT(@SECRET_PATH, secretBase, "User")); + SET @password = LOAD_FILE(CONCAT(@SECRET_PATH, secretBase, "Pw")); + SET @grantTable = LOAD_FILE(CONCAT(@SECRET_PATH, secretBase, "GrantTable")); + SET @privileges = LOAD_FILE(CONCAT(@SECRET_PATH, secretBase, "Privs")); + + -- Set defaults for missing or empty secrets + SELECT + IF( + ISNULL(@grantTable) OR @grantTable = "", + "*.*", + CONCAT("`", @grantTable, "`.*") + ) + INTO @grantTable; + + SELECT + IF( + ISNULL(@privileges) OR @privileges = "", + "ALL PRIVILEGES", + @privileges + ) + INTO @privileges; + + -- Create user + SET @query = CONCAT( + "CREATE OR REPLACE USER `",@username,"` IDENTIFIED BY '",@password,"';" + ); + PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt; + + -- Grant privileges + SET @query = CONCAT( + "GRANT ", @privileges, " ON ", @grantTable, " TO `", @username, "`@`%`;" + ); + PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt; + + FLUSH PRIVILEGES; +END +$ +DELIMITER ; + +-- Call procedure +CALL CREATE_USER('root'); +CALL CREATE_USER('eaBackend'); +CALL CREATE_USER('checkmk'); diff --git a/init/02-ddl/02-eaMain_database.sql b/init/02-ddl/02-eaMain_database.sql new file mode 100644 index 0000000..d30b436 --- /dev/null +++ b/init/02-ddl/02-eaMain_database.sql @@ -0,0 +1,35 @@ +-- **************************************************************************************************** +-- * ______ _ _ * +-- * | ____| /\ (_) | | * +-- * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ * +-- * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| * +-- * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ * +-- * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ * +-- * | | | | * +-- * |_| |_| * +-- * * +-- **************************************************************************************************** + +-- This file is part of the European Airports Project, a free, collaborative platform of airport data +-- extending beyond the official AIPs. + +-- Copyright (C) 2023 + +-- Florian Meissner + +-- This program is free software: you can redistribute it and/or modify it under the +-- terms of the GNU General Public License as published by the Free Software Foundation, either +-- version 3 of the License, or (at your option) any later version. This program is distributed in the +-- hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +-- details. You should have received a copy of the GNU General Public License along with this program. +-- (license.md in the root folder of this project) If not, see . + + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +START TRANSACTION; +SET time_zone = "+00:00"; + + +CREATE DATABASE IF NOT EXISTS `eaMain` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; +USE `eaMain`; diff --git a/init/README.md b/init/README.md new file mode 100644 index 0000000..7c7997b --- /dev/null +++ b/init/README.md @@ -0,0 +1,36 @@ +**************************************************************************************************** +* ______ _ _ * +* | ____| /\ (_) | | * +* | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ * +* | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| * +* | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ * +* |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ * +* | | | | * +* |_| |_| * +* * +**************************************************************************************************** + +This file is part of the European Airports Project, a free, collaborative platform of airport data +extending beyond the official AIPs. + +Copyright (C) 2023 + +Florian Meissner + +This program is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software Foundation, either +version 3 of the License, or (at your option) any later version. This program is distributed in the +hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. You should have received a copy of the GNU General Public License along with this program. +(license.md in the root folder of this project) If not, see . + + +# MariaDB Init Volume + +All shell scripts (*.sh) placed here will be run when the container is built. + +Additionally all SQL files (*.sql) will automatically imported into the database specified by +MYSQL_DATABASE from the docker-compose.yml. + +This folder is linked to the container as a volume. \ No newline at end of file diff --git a/mariadb.env b/mariadb.env new file mode 100644 index 0000000..6502b59 --- /dev/null +++ b/mariadb.env @@ -0,0 +1,30 @@ +# **************************************************************************************************** +# * ______ _ _ * +# * | ____| /\ (_) | | * +# * | |__ _ _ _ __ ___ _ __ ___ __ _ _ __ / \ _ _ __ _ __ ___ _ __| |_ ___ * +# * | __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \ / /\ \ | | '__| '_ \ / _ \| '__| __/ __| * +# * | |___| |_| | | | (_) | |_) | __/ (_| | | | | / ____ \| | | | |_) | (_) | | | |_\__ \ * +# * |______\__,_|_| \___/| .__/ \___|\__,_|_| |_| /_/ \_\_|_| | .__/ \___/|_| \__|___/ * +# * | | | | * +# * |_| |_| * +# * * +# **************************************************************************************************** + +# This file is part of the European Airports Project, a free, collaborative platform of airport data +# extending beyond the official AIPs. + +# Copyright (C) 2023 + +# Florian Meissner + +# This program is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software Foundation, either +# version 3 of the License, or (at your option) any later version. This program is distributed in the +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. You should have received a copy of the GNU General Public License along with this program. +# (license.md in the root folder of this project) If not, see . + + + +