Browse Source

adding #18

release/0.1
Björn 4 years ago
parent
commit
710362478e
4 changed files with 87 additions and 14 deletions
  1. +44
    -12
      app/Commands/MariadbInstallCommand.php
  2. +1
    -0
      composer.json
  3. +41
    -1
      composer.lock
  4. +1
    -1
      install.sh

+ 44
- 12
app/Commands/MariadbInstallCommand.php View File

@ -8,10 +8,19 @@ use Illuminate\Support\Facades\File;
use App\Facades\Install; use App\Facades\Install;
use Log;
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator;
/**
*
*
*
*/
class MariadbInstallCommand extends Command class MariadbInstallCommand extends Command
{ {
const MCP_LOG_FILE = '/root/mcp.log';
const PASSWORD_LENGTH = 40;
/** /**
* The signature of the command. * The signature of the command.
* *
@ -38,22 +47,45 @@ class MariadbInstallCommand extends Command
exec('apt update 2>&1'); exec('apt update 2>&1');
exec('apt install -y mariadb-server mariadb-client 2>&1'); exec('apt install -y mariadb-server mariadb-client 2>&1');
$link = mysqli_connect('127.0.0.1', 'root', $password);
if (Install::isReady('mariadb-server mariadb-client')) {
$this->info('Mariadb setup...');
//exec('UPDATE mysql.user SET Password=PASSWORD('${install_mysql_password}') WHERE User='root';');
//mysql_query("UPDATE mysql.user SET Password=PASSWORD('$password') WHERE User='root';");
//
// generate password
$generator = new ComputerPasswordGenerator();
$generator->setRandomGenerator(new Php7RandomGenerator())
->setUppercase()
->setLowercase()
->setUppercase()
->setNumbers()
->setSymbols(false)
->setLength(self::PASSWORD_LENGTH);
//mysqli_close($link);
// getting password for root
$password = $generator->generatePasswords()[0];
if (Install::isReady('mariadb-server mariadb-client')) {
// remove plugin for root and set password
exec('sudo mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD(\''.$password.'\') WHERE User=\'root\';"');
exec('sudo mysql -u root -e "UPDATE mysql.user SET plugin=\'\' where User=\'root\';"');
// delete anonymous user
exec('sudo mysql -u root -e "DELETE FROM mysql.user WHERE User=\'\';"');
// make sure root can only access from local
exec('sudo mysql -u root -e "DELETE FROM mysql.user WHERE User=\'root\' AND Host NOT IN (\'localhost\', \'127.0.0.1\', \'::1\');"');
// drop test database and anthing familiar
exec('sudo mysql -u root -e "DROP DATABASE IF EXISTS test;"');
exec('sudo mysql -u root -e "DELETE FROM mysql.db WHERE Db=\'test\' OR Db=\'test_%\';"');
// update privileges
exec('sudo mysql -u root -e "FLUSH PRIVILEGES;"');
// get status of nginx
exec('nginx -v 2>&1', $output);
$status = "$output[0] installed";
$this->info('Success! \o/ Check /root/mcp.log');
file_put_contents(self::MCP_LOG_FILE, "Mariadb installed\nuser:root\npassword:".$password."\n--\n", FILE_APPEND);
$this->info($status);
Log::info($status);
} else {
$this->error('Failed! /o\\');
} }
} }
} }

+ 1
- 0
composer.json View File

@ -17,6 +17,7 @@
], ],
"require": { "require": {
"php": "^7.2.5", "php": "^7.2.5",
"hackzilla/password-generator": "^1.5",
"illuminate/log": "^7.0", "illuminate/log": "^7.0",
"jenssegers/blade": "^1.3", "jenssegers/blade": "^1.3",
"laminas/laminas-text": "^2.7", "laminas/laminas-text": "^2.7",


+ 41
- 1
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "0e8b08aebfaf581a3ebfba5152ff8a4c",
"content-hash": "a22606a0d481725bb8b9a8595631a8b8",
"packages": [ "packages": [
{ {
"name": "beberlei/assert", "name": "beberlei/assert",
@ -336,6 +336,46 @@
], ],
"time": "2020-06-14T09:00:00+00:00" "time": "2020-06-14T09:00:00+00:00"
}, },
{
"name": "hackzilla/password-generator",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/hackzilla/password-generator.git",
"reference": "22c7af49ef46d349d60af0fa30f61dd4dec53330"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hackzilla/password-generator/zipball/22c7af49ef46d349d60af0fa30f61dd4dec53330",
"reference": "22c7af49ef46d349d60af0fa30f61dd4dec53330",
"shasum": ""
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Hackzilla\\PasswordGenerator\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel Platt",
"email": "github@ofdan.co.uk",
"homepage": "http://www.hackzilla.org"
}
],
"description": "Password Generator Library",
"time": "2020-04-06T15:47:25+00:00"
},
{ {
"name": "illuminate/cache", "name": "illuminate/cache",
"version": "v7.18.0", "version": "v7.18.0",


+ 1
- 1
install.sh View File

@ -9,7 +9,7 @@ set -o pipefail
set -o nounset set -o nounset
# installing dependencies # installing dependencies
apt install -y php-cli php-mbstring php-dom git unzip curl composer ufw fail2ban
apt install -y php-cli php-mbstring php-dom php-mysql git unzip curl composer ufw fail2ban
# #
# configure ufw and start # configure ufw and start


Loading…
Cancel
Save