|
@ -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\\'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |