|
|
@ -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); |
|
|
|