Add database host management to panel.
This commit is contained in:
parent
5bbded2c03
commit
198a021a97
12 changed files with 605 additions and 125 deletions
|
@ -13,6 +13,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
* Table seeders for services now can be run during upgrades and will attempt to locate and update, or create new if not found in the database.
|
||||
* Many structural changes to the database and `Pterodactyl\Models` classes that would flood this changelog if they were all included. All required migrations included to handle database changes.
|
||||
* `[pre.4]` — Service pack files are now stored in the database rather than on the host system to make updates easier.
|
||||
* Clarified details for database hosts to prevent users entering invalid account details, as well as renamed tables and columns relating to it to keep things clearer.
|
||||
|
||||
### Fixed
|
||||
* Fixes potential bug with invalid CIDR notation (ex: `192.168.1.1/z`) when adding allocations that could cause over 4 million records to be created at once.
|
||||
|
@ -22,6 +23,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
### Added
|
||||
* Ability to assign multiple allocations at once when creating a new server.
|
||||
* New `humanReadable` macro on `File` facade that accepts a file path and returns a human readable size. (`File::humanReadable(path, precision)`)
|
||||
* Added ability to edit database host details after creation on the system.
|
||||
|
||||
### Deprecated
|
||||
* Old API calls to `Server::create` will fail due to changed data structure.
|
||||
|
|
|
@ -26,8 +26,10 @@ namespace Pterodactyl\Http\Controllers\Admin;
|
|||
|
||||
use Log;
|
||||
use Alert;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Repositories\DatabaseRepository;
|
||||
|
@ -36,82 +38,98 @@ use Pterodactyl\Exceptions\DisplayValidationException;
|
|||
class DatabaseController extends Controller
|
||||
{
|
||||
/**
|
||||
* Controller Constructor.
|
||||
* Display database host index.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function getIndex(Request $request)
|
||||
public function index(Request $request)
|
||||
{
|
||||
return view('admin.databases.index', [
|
||||
'databases' => Models\Database::with('server')->paginate(50),
|
||||
'hosts' => Models\DatabaseServer::withCount('databases')->with('node')->paginate(20),
|
||||
'locations' => Location::with('nodes')->get(),
|
||||
'hosts' => DatabaseHost::withCount('databases')->with('node')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getNew(Request $request)
|
||||
/**
|
||||
* Display database host to user.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function view(Request $request, $id)
|
||||
{
|
||||
return view('admin.databases.new', [
|
||||
'nodes' => Models\Node::all()->load('location'),
|
||||
return view('admin.databases.view', [
|
||||
'locations' => Location::with('nodes')->get(),
|
||||
'host' => DatabaseHost::with('databases.server')->findOrFail($id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function postNew(Request $request)
|
||||
/**
|
||||
* Handle post request to create database host.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
try {
|
||||
$repo = new DatabaseRepository;
|
||||
$repo->add($request->only([
|
||||
'name',
|
||||
'host',
|
||||
'port',
|
||||
'username',
|
||||
'password',
|
||||
'linked_node',
|
||||
|
||||
try {
|
||||
$host = $repo->add($request->intersect([
|
||||
'name', 'username', 'password',
|
||||
'host', 'port', 'node_id',
|
||||
]));
|
||||
Alert::success('Successfully added a new database server to the system.')->flash();
|
||||
Alert::success('Successfully created new database host on the system.')->flash();
|
||||
|
||||
return redirect()->route('admin.databases', ['tab' => 'tab_dbservers']);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.databases.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (\Exception $ex) {
|
||||
if ($ex instanceof DisplayException || $ex instanceof \PDOException) {
|
||||
return redirect()->route('admin.databases.view', $host->id);
|
||||
} catch (\PDOException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.databases')->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error was encountered while trying to process this request. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.databases');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle post request to update a database host.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Response\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$repo = new DatabaseRepository;
|
||||
|
||||
try {
|
||||
if ($request->input('action') !== 'delete') {
|
||||
$host = $repo->update($id, $request->intersect([
|
||||
'name', 'username', 'password',
|
||||
'host', 'port', 'node_id',
|
||||
]));
|
||||
Alert::success('Database host was updated successfully.')->flash();
|
||||
} else {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occurred while attempting to delete this database server from the system.')->flash();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.databases.new')->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteDatabase(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$repo = new DatabaseRepository;
|
||||
$repo->drop($id);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return response()->json([
|
||||
'error' => ($ex instanceof DisplayException) ? $ex->getMessage() : 'An error occurred while attempting to delete this database from the system.',
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteServer(Request $request, $id)
|
||||
{
|
||||
try {
|
||||
$repo = new DatabaseRepository;
|
||||
$repo->delete($id);
|
||||
|
||||
return redirect()->route('admin.databases');
|
||||
}
|
||||
} catch (\PDOException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.databases.view', $id)->withErrors(json_decode($ex->getMessage()));
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error was encountered while trying to process this request. This error has been logged.')->flash();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => ($ex instanceof DisplayException) ? $ex->getMessage() : 'An error occurred while attempting to delete this database server from the system.',
|
||||
], 500);
|
||||
}
|
||||
return redirect()->route('admin.databases.view', $id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ class ServersController extends Controller
|
|||
$server = Models\Server::where('installed', 1)->with('databases.host')->findOrFail($id);
|
||||
|
||||
return view('admin.servers.view.database', [
|
||||
'hosts' => Models\DatabaseServer::all(),
|
||||
'hosts' => Models\DatabaseHost::all(),
|
||||
'server' => $server,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,29 @@ class AdminRoutes
|
|||
'uses' => 'Admin\BaseController@getIndex',
|
||||
]);
|
||||
|
||||
$router->group([
|
||||
'prefix' => 'admin/databases',
|
||||
'middleware' => [
|
||||
'auth',
|
||||
'admin',
|
||||
'csrf',
|
||||
],
|
||||
], function () use ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'admin.databases',
|
||||
'uses' => 'Admin\DatabaseController@index',
|
||||
]);
|
||||
|
||||
$router->post('/', 'Admin\DatabaseController@create');
|
||||
|
||||
$router->get('/view/{id}', [
|
||||
'as' => 'admin.databases.view',
|
||||
'uses' => 'Admin\DatabaseController@view',
|
||||
]);
|
||||
|
||||
$router->post('/view/{id}', 'Admin\DatabaseController@update');
|
||||
});
|
||||
|
||||
$router->group([
|
||||
'prefix' => 'admin/locations',
|
||||
'middleware' => [
|
||||
|
|
|
@ -43,11 +43,13 @@ class Database extends Model
|
|||
protected $hidden = ['password'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
protected $fillable = [
|
||||
'server_id', 'database_host_id', 'database', 'username', 'remote',
|
||||
];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
|
@ -56,7 +58,7 @@ class Database extends Model
|
|||
*/
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
'db_server' => 'integer',
|
||||
'database_host_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -66,7 +68,7 @@ class Database extends Model
|
|||
*/
|
||||
public function host()
|
||||
{
|
||||
return $this->belongsTo(DatabaseServer::class, 'db_server');
|
||||
return $this->belongsTo(DatabaseHost::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,14 +26,14 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DatabaseServer extends Model
|
||||
class DatabaseHost extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'database_servers';
|
||||
protected $table = 'database_hosts';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
|
@ -43,11 +43,13 @@ class DatabaseServer extends Model
|
|||
protected $hidden = ['password'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
protected $fillable = [
|
||||
'name', 'host', 'port', 'username', 'max_databases', 'node_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
|
@ -56,8 +58,8 @@ class DatabaseServer extends Model
|
|||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'server_id' => 'integer',
|
||||
'db_server' => 'integer',
|
||||
'max_databases' => 'integer',
|
||||
'node_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -67,7 +69,7 @@ class DatabaseServer extends Model
|
|||
*/
|
||||
public function node()
|
||||
{
|
||||
return $this->belongsTo(Node::class, 'linked_node');
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +79,6 @@ class DatabaseServer extends Model
|
|||
*/
|
||||
public function databases()
|
||||
{
|
||||
return $this->hasMany(Database::class, 'db_server');
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
}
|
|
@ -28,7 +28,9 @@ use DB;
|
|||
use Crypt;
|
||||
use Config;
|
||||
use Validator;
|
||||
use Pterodactyl\Models;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\DatabaseHost;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Exceptions\DisplayValidationException;
|
||||
|
||||
|
@ -37,17 +39,16 @@ class DatabaseRepository
|
|||
/**
|
||||
* Adds a new database to a specified database host server.
|
||||
*
|
||||
* @param int $server Id of the server to add a database for.
|
||||
* @param array $options Array of options for creating that database.
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Database
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
* @throws \Exception
|
||||
* @return void
|
||||
*/
|
||||
public function create($server, $data)
|
||||
public function create($id, array $data)
|
||||
{
|
||||
$server = Models\Server::findOrFail($server);
|
||||
$server = Server::findOrFail($server);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'host' => 'required|exists:database_servers,id',
|
||||
|
@ -56,16 +57,16 @@ class DatabaseRepository
|
|||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
$host = Models\DatabaseServer::findOrFail($data['host']);
|
||||
$host = DatabaseHost::findOrFail($data['host']);
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$database = Models\Database::firstOrNew([
|
||||
'server_id' => $server->id,
|
||||
'db_server' => $data['host'],
|
||||
'database_host_id' => $data['host'],
|
||||
'database' => sprintf('s%d_%s', $server->id, $data['database']),
|
||||
]);
|
||||
|
||||
|
@ -109,6 +110,8 @@ class DatabaseRepository
|
|||
|
||||
// Save Everything
|
||||
DB::commit();
|
||||
|
||||
return $database;
|
||||
} catch (\Exception $ex) {
|
||||
try {
|
||||
DB::connection('dynamic')->statement(sprintf('DROP DATABASE IF EXISTS `%s`', $database->database));
|
||||
|
@ -124,18 +127,17 @@ class DatabaseRepository
|
|||
|
||||
/**
|
||||
* Updates the password for a given database.
|
||||
* @param int $id The ID of the database to modify.
|
||||
* @param string $password The new password to use for the database.
|
||||
* @return bool
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $password
|
||||
* @return void
|
||||
*/
|
||||
public function password($id, $password)
|
||||
{
|
||||
$database = Models\Database::with('host')->findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
DB::transaction(function () use ($database, $password) {
|
||||
$database->password = Crypt::encrypt($password);
|
||||
$database->save();
|
||||
|
||||
Config::set('database.connections.dynamic', [
|
||||
'driver' => 'mysql',
|
||||
|
@ -153,24 +155,21 @@ class DatabaseRepository
|
|||
$database->username, $database->remote, $password
|
||||
));
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
$database->save();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a database from the associated MySQL Server.
|
||||
* @param int $id The ID of the database to drop.
|
||||
* @return bool
|
||||
* Drops a database from the associated database host.
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
public function drop($id)
|
||||
{
|
||||
$database = Models\Database::with('host')->findOrFail($id);
|
||||
$database = Database::with('host')->findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
DB::transaction(function () use ($database) {
|
||||
Config::set('database.connections.dynamic', [
|
||||
'driver' => 'mysql',
|
||||
'host' => $database->host->host,
|
||||
|
@ -187,34 +186,35 @@ class DatabaseRepository
|
|||
DB::connection('dynamic')->statement('FLUSH PRIVILEGES');
|
||||
|
||||
$database->delete();
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollback();
|
||||
throw $ex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a database server from the system if it is empty.
|
||||
* Deletes a database host from the system if it has no associated databases.
|
||||
*
|
||||
* @param int $server The ID of the Database Server.
|
||||
* @return bool
|
||||
* @param int $server
|
||||
* @return void
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
*/
|
||||
public function delete($server)
|
||||
public function delete($id)
|
||||
{
|
||||
$host = Models\DatabaseServer::withCount('databases')->findOrFail($server);
|
||||
$host = DatabaseHost::withCount('databases')->findOrFail($id);
|
||||
|
||||
if ($host->databases_count > 0) {
|
||||
throw new DisplayException('You cannot delete a database server that has active databases attached to it.');
|
||||
throw new DisplayException('You cannot delete a database host that has active databases attached to it.');
|
||||
}
|
||||
|
||||
return $host->delete();
|
||||
$host->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new Database Server to the system.
|
||||
* Adds a new Database Host to the system.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\DatabaseHost
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
|
@ -224,19 +224,18 @@ class DatabaseRepository
|
|||
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'required|string|max:255',
|
||||
'host' => 'required|ip|unique:database_servers,host',
|
||||
'host' => 'required|ip|unique:database_hosts,host',
|
||||
'port' => 'required|numeric|between:1,65535',
|
||||
'username' => 'required|string|max:32',
|
||||
'password' => 'required|string',
|
||||
'linked_node' => 'sometimes',
|
||||
'node_id' => 'sometimes|required|exists:nodes,id',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
return DB::transaction(function () use ($data) {
|
||||
Config::set('database.connections.dynamic', [
|
||||
'driver' => 'mysql',
|
||||
'host' => $data['host'],
|
||||
|
@ -251,20 +250,74 @@ class DatabaseRepository
|
|||
// Allows us to check that we can connect to things.
|
||||
DB::connection('dynamic')->select('SELECT 1 FROM dual');
|
||||
|
||||
Models\DatabaseServer::create([
|
||||
$host = new DatabaseHost;
|
||||
$host->password = Crypt::encrypt($data['password']);
|
||||
|
||||
$host->fill([
|
||||
'name' => $data['name'],
|
||||
'host' => $data['host'],
|
||||
'port' => $data['port'],
|
||||
'username' => $data['username'],
|
||||
'password' => Crypt::encrypt($data['password']),
|
||||
'max_databases' => null,
|
||||
'linked_node' => (! empty($data['linked_node']) && $data['linked_node'] > 0) ? $data['linked_node'] : null,
|
||||
'node_id' => (isset($data['node_id'])) ? $data['node_id'] : null,
|
||||
])->save();
|
||||
|
||||
return $host;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a Database Host on the system.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\DatabaseHost
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayValidationException
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$host = DatabaseHost::findOrFail($id);
|
||||
|
||||
if (isset($data['host'])) {
|
||||
$data['host'] = gethostbyname($data['host']);
|
||||
}
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'sometimes|required|string|max:255',
|
||||
'host' => 'sometimes|required|ip|unique:database_hosts,host,' . $host->id,
|
||||
'port' => 'sometimes|required|numeric|between:1,65535',
|
||||
'username' => 'sometimes|required|string|max:32',
|
||||
'password' => 'sometimes|required|string',
|
||||
'node_id' => 'sometimes|required|exists:nodes,id',
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $ex) {
|
||||
DB::rollBack();
|
||||
throw $ex;
|
||||
}
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($data, $host) {
|
||||
if (isset($data['password'])) {
|
||||
$host->password = Crypt::encrypt($data['password']);
|
||||
}
|
||||
$host->fill($data)->save();
|
||||
|
||||
// Check that we can still connect with these details.
|
||||
Config::set('database.connections.dynamic', [
|
||||
'driver' => 'mysql',
|
||||
'host' => $host->host,
|
||||
'port' => $host->port,
|
||||
'database' => 'mysql',
|
||||
'username' => $host->username,
|
||||
'password' => Crypt::decrypt($host->password),
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
]);
|
||||
|
||||
// Allows us to check that we can connect to things.
|
||||
DB::connection('dynamic')->select('SELECT 1 FROM dual');
|
||||
|
||||
return $host;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ReOrganizeDatabaseServersToDatabaseHost extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('database_servers', function (Blueprint $table) {
|
||||
$table->dropForeign(['linked_node']);
|
||||
});
|
||||
|
||||
Schema::rename('database_servers', 'database_hosts');
|
||||
|
||||
Schema::table('database_hosts', function (Blueprint $table) {
|
||||
$table->renameColumn('linked_node', 'node_id');
|
||||
|
||||
$table->foreign('node_id')->references('id')->on('nodes');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('database_hosts', function (Blueprint $table) {
|
||||
$table->dropForeign(['node_id']);
|
||||
});
|
||||
|
||||
Schema::rename('database_hosts', 'database_servers');
|
||||
|
||||
Schema::table('database_servers', function (Blueprint $table) {
|
||||
$table->renameColumn('node_id', 'linked_node');
|
||||
|
||||
$table->foreign('linked_node')->references('id')->on('nodes');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CleanupDatabasesDatabase extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('databases', function (Blueprint $table) {
|
||||
$table->dropForeign(['db_server']);
|
||||
|
||||
$table->renameColumn('db_server', 'database_host_id');
|
||||
|
||||
$table->foreign('database_host_id')->references('id')->on('database_hosts');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('databases', function (Blueprint $table) {
|
||||
$table->dropForeign(['database_host_id']);
|
||||
|
||||
$table->renameColumn('database_host_id', 'db_server');
|
||||
|
||||
$table->foreign('db_server')->references('id')->on('database_hosts');
|
||||
});
|
||||
}
|
||||
}
|
149
resources/themes/pterodactyl/admin/databases/index.blade.php
Normal file
149
resources/themes/pterodactyl/admin/databases/index.blade.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
|
||||
|
||||
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
|
||||
{{-- of this software and associated documentation files (the "Software"), to deal --}}
|
||||
{{-- in the Software without restriction, including without limitation the rights --}}
|
||||
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
|
||||
{{-- copies of the Software, and to permit persons to whom the Software is --}}
|
||||
{{-- furnished to do so, subject to the following conditions: --}}
|
||||
|
||||
{{-- The above copyright notice and this permission notice shall be included in all --}}
|
||||
{{-- copies or substantial portions of the Software. --}}
|
||||
|
||||
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
|
||||
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
|
||||
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
|
||||
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
|
||||
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
|
||||
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
|
||||
{{-- SOFTWARE. --}}
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title')
|
||||
Database Hosts
|
||||
@endsection
|
||||
|
||||
@section('content-header')
|
||||
<h1>Database Hosts<small>Database hosts that servers can have databases created on.</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ route('admin.index') }}">Admin</a></li>
|
||||
<li class="active">Database Hosts</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Host List</h3>
|
||||
</div>
|
||||
<div class="box-body table-responsive no-padding">
|
||||
<table class="table table-hover">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Host</th>
|
||||
<th>Port</th>
|
||||
<th>Username</th>
|
||||
<th class="text-center">Databases</th>
|
||||
<th class="text-center">Node</th>
|
||||
</tr>
|
||||
@foreach ($hosts as $host)
|
||||
<tr>
|
||||
<td><code>{{ $host->id }}</code></td>
|
||||
<td><a href="{{ route('admin.databases.view', $host->id) }}">{{ $host->name }}</a></td>
|
||||
<td><code>{{ $host->host }}</code></td>
|
||||
<td><code>{{ $host->port }}</code></td>
|
||||
<td>{{ $host->username }}</td>
|
||||
<td class="text-center">{{ $host->databases_count }}</td>
|
||||
<td class="text-center">
|
||||
@if(! is_null($host->node))
|
||||
<a href="{{ route('admin.nodes.view', $host->node->id) }}">{{ $host->node->name }}</a>
|
||||
@else
|
||||
<span class="label label-default">None</span>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button class="btn btn-sm btn-default pull-right" data-toggle="modal" data-target="#newHostModal">New Host</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="newHostModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<form action="{{ route('admin.databases') }}" method="POST">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Create New Database Host</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label for="pName" class="form-label">Name</label>
|
||||
<input type="text" name="name" id="pName" class="form-control" />
|
||||
<p class="text-muted small">A short identifier used to distinguish this location from others. Must be between 1 and 60 characters, for example, <code>us.nyc.lvl3</code>.</p>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<label for="pHost" class="form-label">Host</label>
|
||||
<input type="text" name="host" id="pHost" class="form-control" />
|
||||
<p class="text-muted small">The IP address or FQDN that should be used when attempting to connect to this MySQL host <em>from the panel</em> to add new databases.</p>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="pPort" class="form-label">Port</label>
|
||||
<input type="text" name="port" id="pPort" class="form-control" value="3306"/>
|
||||
<p class="text-muted small">The port that MySQL is running on for this host.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<label for="pUsername" class="form-label">Username</label>
|
||||
<input type="text" name="username" id="pUsername" class="form-control" />
|
||||
<p class="text-muted small">The username of an account that has enough permissions to create new users and databases on the system.</p>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="pPassword" class="form-label">Password</label>
|
||||
<input type="password" name="password" id="pPassword" class="form-control" />
|
||||
<p class="text-muted small">The password to the account defined.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pNodeId" class="form-label">Linked Node</label>
|
||||
<select name="node_id" id="pNodeId" class="form-control">
|
||||
<option value="0">None</option>
|
||||
@foreach($locations as $location)
|
||||
<optgroup label="{{ $location->short }}">
|
||||
@foreach($location->nodes as $node)
|
||||
<option value="{{ $node->id }}">{{ $node->name }}</option>
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endforeach
|
||||
</select>
|
||||
<p class="text-muted small">This setting does nothing other than default to this database host when adding a database to a server on the selected node.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<p class="text-danger small text-left">The account defined for this database host <strong>must</strong> have the <code>WITH GRANT OPTION</code> permission. If the defined account does not have this permission requests to create databases <em>will</em> fail. <strong>Do not use the same account details for MySQL that you have defined for this panel.</strong></p>
|
||||
{!! csrf_field() !!}
|
||||
<button type="button" class="btn btn-default btn-sm pull-left" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-success btn-sm">Create</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('footer-scripts')
|
||||
@parent
|
||||
<script>
|
||||
$('#pNodeId').select2();
|
||||
</script>
|
||||
@endsection
|
143
resources/themes/pterodactyl/admin/databases/view.blade.php
Normal file
143
resources/themes/pterodactyl/admin/databases/view.blade.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
|
||||
|
||||
{{-- Permission is hereby granted, free of charge, to any person obtaining a copy --}}
|
||||
{{-- of this software and associated documentation files (the "Software"), to deal --}}
|
||||
{{-- in the Software without restriction, including without limitation the rights --}}
|
||||
{{-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --}}
|
||||
{{-- copies of the Software, and to permit persons to whom the Software is --}}
|
||||
{{-- furnished to do so, subject to the following conditions: --}}
|
||||
|
||||
{{-- The above copyright notice and this permission notice shall be included in all --}}
|
||||
{{-- copies or substantial portions of the Software. --}}
|
||||
|
||||
{{-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --}}
|
||||
{{-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --}}
|
||||
{{-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --}}
|
||||
{{-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --}}
|
||||
{{-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --}}
|
||||
{{-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --}}
|
||||
{{-- SOFTWARE. --}}
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title')
|
||||
Database Hosts → View → {{ $host->name }}
|
||||
@endsection
|
||||
|
||||
@section('content-header')
|
||||
<h1>{{ $host->name }}<small>Viewing associated databases and details for this database host.</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ route('admin.index') }}">Admin</a></li>
|
||||
<li><a href="{{ route('admin.databases') }}">Database Hosts</a></li>
|
||||
<li class="active">{{ $host->name }}</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<form action="{{ route('admin.databases.view', $host->id) }}" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Host Details</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label for="pName" class="form-label">Name</label>
|
||||
<input type="text" id="pName" name="name" class="form-control" value="{{ $host->name }}" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pHost" class="form-label">Host</label>
|
||||
<input type="text" id="pHost" name="host" class="form-control" value="{{ $host->host }}" />
|
||||
<p class="text-muted small">The IP address or FQDN that should be used when attempting to connect to this MySQL host <em>from the panel</em> to add new databases.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pPort" class="form-label">Port</label>
|
||||
<input type="text" id="pPort" name="port" class="form-control" value="{{ $host->port }}" />
|
||||
<p class="text-muted small">The port that MySQL is running on for this host.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pNodeId" class="form-label">Linked Node</label>
|
||||
<select name="node_id" id="pNodeId" class="form-control">
|
||||
<option value="0">None</option>
|
||||
@foreach($locations as $location)
|
||||
<optgroup label="{{ $location->short }}">
|
||||
@foreach($location->nodes as $node)
|
||||
<option value="{{ $node->id }}" {{ $host->node_id !== $node->id ?: 'selected' }}>{{ $node->name }}</option>
|
||||
@endforeach
|
||||
</optgroup>
|
||||
@endforeach
|
||||
</select>
|
||||
<p class="text-muted small">This setting does nothing other than default to this database host when adding a database to a server on the selected node.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">User Details</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="form-group">
|
||||
<label for="pUsername" class="form-label">Username</label>
|
||||
<input type="text" name="username" id="pUsername" class="form-control" value="{{ $host->username }}" />
|
||||
<p class="text-muted small">The username of an account that has enough permissions to create new users and databases on the system.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="pPassword" class="form-label">Password</label>
|
||||
<input type="password" name="password" id="pPassword" class="form-control" />
|
||||
<p class="text-muted small">The password to the account defined. Leave blank to continue using the assigned password.</p>
|
||||
</div>
|
||||
<hr />
|
||||
<p class="text-danger small text-left">The account defined for this database host <strong>must</strong> have the <code>WITH GRANT OPTION</code> permission. If the defined account does not have this permission requests to create databases <em>will</em> fail. <strong>Do not use the same account details for MySQL that you have defined for this panel.</strong></p>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
{!! csrf_field() !!}
|
||||
<button name="action" value="delete" class="btn btn-sm btn-danger pull-left muted muted-hover"><i class="fa fa-trash-o"></i></button>
|
||||
<button name="action" value="edit" class="btn btn-sm btn-primary pull-right">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Databases</h3>
|
||||
</div>
|
||||
<div class="box-body table-responsive no-padding">
|
||||
<table class="table table-hover">
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th>Database Name</th>
|
||||
<th>Username</th>
|
||||
<th>Connections From</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@foreach($host->databases as $database)
|
||||
<tr>
|
||||
<td class="middle"><a href="{{ route('admin.servers.view', $database->server->id) }}">{{ $database->server->name }}</a></td>
|
||||
<td class="middle">{{ $database->database }}</td>
|
||||
<td class="middle">{{ $database->username }}</td>
|
||||
<td class="middle">{{ $database->remote }}</td>
|
||||
<td class="text-center">
|
||||
<a href="{{ route('admin.servers.view.database', $database->server->id) }}">
|
||||
<button class="btn btn-xs btn-primary">Manage</button>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('footer-scripts')
|
||||
@parent
|
||||
<script>
|
||||
$('#pNodeId').select2();
|
||||
</script>
|
||||
@endsection
|
|
@ -92,7 +92,7 @@
|
|||
</li>
|
||||
<li class="header">MANAGEMENT</li>
|
||||
<li class="{{ ! starts_with(Route::currentRouteName(), 'admin.databases') ?: 'active' }}">
|
||||
<a href="{{ route('admin.servers') }}">
|
||||
<a href="{{ route('admin.databases') }}">
|
||||
<i class="fa fa-database"></i> <span>Databases</span>
|
||||
</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in a new issue