update
This commit is contained in:
parent
f6e8cfb489
commit
9373b21241
3 changed files with 120 additions and 4 deletions
22
bin/mysql-create-db-and-user.sh
Normal file
22
bin/mysql-create-db-and-user.sh
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Creating MySQL user and database"
|
||||
|
||||
PASS=$3
|
||||
if [ -z "$3" ]; then
|
||||
PASS=`openssl rand -base64 8`
|
||||
fi
|
||||
|
||||
mysql -u root <<MYSQL_SCRIPT
|
||||
CREATE DATABASE $1;
|
||||
CREATE USER '$2'@'localhost' IDENTIFIED BY '$PASS';
|
||||
GRANT ALL PRIVILEGES ON $1.* TO '$2'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
MYSQL_SCRIPT
|
||||
|
||||
echo "MySQL user and database created."
|
||||
echo "Database: $1"
|
||||
echo "Username: $2"
|
||||
echo "Password: $PASS"
|
||||
echo "Success!"
|
||||
|
|
@ -23,7 +23,31 @@ class HostingDatabaseResource extends Resource
|
|||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
|
||||
Forms\Components\TextInput::make('database_name')
|
||||
->required()
|
||||
->disabled(function ($record) {
|
||||
if (isset($record->exists)) {
|
||||
return $record->exists;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
|
||||
Forms\Components\TextInput::make('database_username')
|
||||
->required()
|
||||
->disabled(function ($record) {
|
||||
if (isset($record->exists)) {
|
||||
return $record->exists;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
|
||||
Forms\Components\TextInput::make('database_password')
|
||||
->required(),
|
||||
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -31,7 +55,12 @@ class HostingDatabaseResource extends Resource
|
|||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
Tables\Columns\TextColumn::make('database_name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('database_username')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
|
|
@ -2,10 +2,75 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use App\ShellApi;
|
||||
use Sushi\Sushi;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class HostingDatabase extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Sushi;
|
||||
|
||||
protected $fillable = [
|
||||
'database_name',
|
||||
'database_username',
|
||||
'database_password'
|
||||
];
|
||||
|
||||
protected $schema = [
|
||||
'database_name' => 'string',
|
||||
'database_username' => 'string',
|
||||
'database_password' => 'string'
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
|
||||
$createDbAndUser = ShellApi::callBin('mysql-create-db-and-user', [
|
||||
$model->database_name,
|
||||
$model->database_username,
|
||||
$model->database_password
|
||||
]);
|
||||
|
||||
if (empty($createDbAndUser)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected function sushiShouldCache()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRows()
|
||||
{
|
||||
// $websitesList = ShellApi::callBin('nginx-websites-list');
|
||||
//
|
||||
// $rows = [];
|
||||
// if (!empty($websitesList)) {
|
||||
// $websitesList = json_decode($websitesList, true);
|
||||
// if (!empty($websitesList)) {
|
||||
// foreach ($websitesList as $website) {
|
||||
// if (isset($website['file'])) {
|
||||
// $rows[] = [
|
||||
// 'file' => $website['file'],
|
||||
// 'domain' => $website['server_name'],
|
||||
// 'root' => $website['root']
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue