Browse Source

adding #34

master
Björn 4 years ago
parent
commit
8349a397aa
3 changed files with 63 additions and 21 deletions
  1. +54
    -0
      app/Commands/AdminerInstallCommand.php
  2. +6
    -19
      app/Commands/MariadbAddCommand.php
  3. +3
    -2
      app/Commands/MariadbClientInstallCommand.php

+ 54
- 0
app/Commands/AdminerInstallCommand.php View File

@ -0,0 +1,54 @@
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use App\Facades\Install;
/**
* Install php-fpm
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/mcp
*
*/
class AdminerInstallCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'adminer:install {destination}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Install Adminer.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->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!');
}
}
}

+ 6
- 19
app/Commands/MariadbAddCommand.php View File

@ -21,21 +21,15 @@ use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator;
*/ */
class MariadbAddCommand extends Command class MariadbAddCommand extends Command
{ {
// destination for username and password
const MCP_LOG_FILE = '/root/mcp.log';
// length for password // length for password
const NAME_LENGTH = 15; const NAME_LENGTH = 15;
// length for password
const PASSWORD_LENGTH = 40;
/** /**
* The signature of the command. * The signature of the command.
* *
* @var string * @var string
*/ */
protected $signature = 'mariadb:add {--ssl}';
protected $signature = 'mariadb:add';
/** /**
* The description of the command. * The description of the command.
@ -97,17 +91,12 @@ class MariadbAddCommand extends Command
$this->info('Database: '.$database); $this->info('Database: '.$database);
$this->info('Username: '.$username); $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"); $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) { if ($mysqli->error) {
$this->error('Failed! '.$mysqli->error); $this->error('Failed! '.$mysqli->error);
@ -118,11 +107,9 @@ class MariadbAddCommand extends Command
exit(); exit();
} }
// grant privleges, for remote acces require ssl
$mysqli->query("GRANT ALL PRIVILEGES ON $database.* TO $username@localhost"); $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) { if ($mysqli->error) {
$this->error('Failed! '.$mysqli->error); $this->error('Failed! '.$mysqli->error);


+ 3
- 2
app/Commands/MariadbClientInstallCommand.php View File

@ -79,7 +79,7 @@ class MariadbClientInstallCommand extends Command
} }
// getting // 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 // 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')) { 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] [client]
ssl-ca=/etc/mysql/ssl/ca-cert.pem ssl-ca=/etc/mysql/ssl/ca-cert.pem
ssl-cert=/etc/mysql/ssl/client-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('chown -R mysql:mysql /etc/mysql/ssl');
system('chmod 644 /etc/mysql/ssl/*cert*'); system('chmod 644 /etc/mysql/ssl/*cert*');


Loading…
Cancel
Save