From 8349a397aa1bc3602817498713e6ce097d407045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 15 Sep 2020 11:49:09 +0200 Subject: [PATCH] adding #34 --- app/Commands/AdminerInstallCommand.php | 54 ++++++++++++++++++++ app/Commands/MariadbAddCommand.php | 25 +++------ app/Commands/MariadbClientInstallCommand.php | 5 +- 3 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 app/Commands/AdminerInstallCommand.php diff --git a/app/Commands/AdminerInstallCommand.php b/app/Commands/AdminerInstallCommand.php new file mode 100644 index 0000000..6f807eb --- /dev/null +++ b/app/Commands/AdminerInstallCommand.php @@ -0,0 +1,54 @@ +info('Adminer installing...'); + + // download adminer + system('wget "http://www.adminer.org/latest.php" -O '.$this->argument('destination').'/index.php'); + + // check if nginx is ready and installed + if (file_exists($this->argument('destination').'/index.php')) { + $this->info('Adminer installing...Success! \o/'); + } else { + $this->error('Failed! Please check log-file!'); + } + } +} diff --git a/app/Commands/MariadbAddCommand.php b/app/Commands/MariadbAddCommand.php index 50cfbac..a1cbacf 100644 --- a/app/Commands/MariadbAddCommand.php +++ b/app/Commands/MariadbAddCommand.php @@ -21,21 +21,15 @@ use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator; */ class MariadbAddCommand extends Command { - // destination for username and password - const MCP_LOG_FILE = '/root/mcp.log'; - // length for password const NAME_LENGTH = 15; - // length for password - const PASSWORD_LENGTH = 40; - /** * The signature of the command. * * @var string */ - protected $signature = 'mariadb:add {--ssl}'; + protected $signature = 'mariadb:add'; /** * The description of the command. @@ -97,17 +91,12 @@ class MariadbAddCommand extends Command $this->info('Database: '.$database); $this->info('Username: '.$username); - // getting option for ssl - $ssl = $this->option('ssl'); $mysqli->query("CREATE DATABASE $database DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); - - if ($ssl === false) { - $mysqli->query("CREATE USER $username@localhost IDENTIFIED BY '$password'"); - } else { - $mysqli->query("CREATE USER $username@'%' IDENTIFIED BY '$password'"); - } + // create user for remote and local access + $mysqli->query("CREATE USER $username@'localhost' IDENTIFIED BY '$password'"); + $mysqli->query("CREATE USER $username@'%' IDENTIFIED BY '$password'"); if ($mysqli->error) { $this->error('Failed! '.$mysqli->error); @@ -118,11 +107,9 @@ class MariadbAddCommand extends Command exit(); } + // grant privleges, for remote acces require ssl $mysqli->query("GRANT ALL PRIVILEGES ON $database.* TO $username@localhost"); - - if ($ssl === true) { - $mysqli->query("GRANT ALL PRIVILEGES ON $database.* TO $username@'%' require ssl"); - } + $mysqli->query("GRANT ALL PRIVILEGES ON $database.* TO $username@'%' require SSL"); if ($mysqli->error) { $this->error('Failed! '.$mysqli->error); diff --git a/app/Commands/MariadbClientInstallCommand.php b/app/Commands/MariadbClientInstallCommand.php index 0c59258..019cb63 100644 --- a/app/Commands/MariadbClientInstallCommand.php +++ b/app/Commands/MariadbClientInstallCommand.php @@ -79,7 +79,7 @@ class MariadbClientInstallCommand extends Command } // getting - system('rsync -rv --include="ca-cert.pem" --include="client-cert.pem" --include="client-key.pem" --exclude="*" '.$this->argument('remove_user').'@'.$this->argument('remove_host').':/etc/mysql/ssl/ /etc/mysql/ssl/'); + system('rsync -rv --include="ca-cert.pem" --include="client-cert.pem" --include="client-key.pem" --exclude="*" '.$this->argument('remote_user').'@'.$this->argument('remote_host').':/etc/mysql/ssl/ /etc/mysql/ssl/'); // checking if certificates are exists from remote server if (!file_exists('/etc/mysql/ssl/ca-cert.pem') || !file_exists('/etc/mysql/ssl/client-cert.pem') || !file_exists('/etc/mysql/ssl/client-key.pem')) { @@ -91,7 +91,8 @@ class MariadbClientInstallCommand extends Command [client] ssl-ca=/etc/mysql/ssl/ca-cert.pem ssl-cert=/etc/mysql/ssl/client-cert.pem -ssl-key=/etc/mysql/ssl/client-key.pem'); +ssl-key=/etc/mysql/ssl/client-key.pem +ssl'); system('chown -R mysql:mysql /etc/mysql/ssl'); system('chmod 644 /etc/mysql/ssl/*cert*');