Merge branch 'develop' into feature/service-changes

This commit is contained in:
Dane Everitt 2016-11-27 14:01:13 -05:00
commit 9eb14614c2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
20 changed files with 345 additions and 70 deletions

View file

@ -24,6 +24,7 @@
namespace Pterodactyl\Console\Commands;
use Illuminate\Console\Command;
use Version;
class ShowVersion extends Command
{
@ -58,6 +59,6 @@ class ShowVersion extends Command
*/
public function handle()
{
$this->info('You are running Pterodactyl Panel ' . config('app.version'));
$this->info('You are running Pterodactyl Panel v' . Version::getCurrentPanel() . ' (' . ((Version::isLatestPanel()) ? 'Up to Date' : 'Latest: ' . Version::getDaemon()) . ')');
}
}

35
app/Facades/Version.php Normal file
View file

@ -0,0 +1,35 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 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.
*/
namespace Pterodactyl\Facades;
use Illuminate\Support\Facades\Facade;
class Version extends Facade
{
protected static function getFacadeAccessor()
{
return '\Pterodactyl\Services\VersionService';
}
}

View file

@ -253,20 +253,22 @@ class NodesController extends Controller
public function deleteNode(Request $request, $id)
{
$node = Models\Node::findOrFail($id);
$servers = Models\Server::where('node', $id)->count();
if ($servers > 0) {
Alert::danger('You cannot delete a node with servers currently attached to it.')->flash();
return redirect()->route('admin.nodes.view', [
'id' => $id,
'tab' => 'tab_delete'
]);
try {
$repo = new NodeRepository;
$repo->delete($id);
Alert::success('Successfully deleted the requested node from the panel.')->flash();
return redirect()->route('admin.nodes');
} catch (DisplayException $e) {
Alert::danger($e->getMessage())->flash();
} catch (\Exception $e) {
Log::error($e);
Alert::danger('An unhandled exception occured while attempting to delete this node. Please try again.')->flash();
}
$node->delete();
Alert::success('Node successfully deleted.')->flash();
return redirect()->route('admin.nodes');
return redirect()->route('admin.nodes.view', [
'id' => $id,
'tab' => 'tab_delete'
]);
}
}

View file

@ -68,14 +68,23 @@ class ServersController extends Controller
$match = str_replace('"', '', $match);
if (strpos($match, ':')) {
list($field, $term) = explode(':', $match);
$field = (strpos($field, '.')) ? $field : 'servers.' . $field;
if ($field === 'node') {
$field = 'nodes.name';
} else if ($field === 'owner') {
$field = 'users.email';
} else if (!strpos($field, '.')) {
$field = 'servers.' . $field;
}
$query->orWhere($field, 'LIKE', '%' . $term . '%');
} else {
$query->where('servers.name', 'LIKE', '%' . $match . '%');
$query->orWhere('servers.username', 'LIKE', '%' . $match . '%');
$query->orWhere('users.email', 'LIKE', '%' . $match . '%');
$query->orWhere('allocations.port', 'LIKE', '%' . $match . '%');
$query->orWhere('allocations.ip', 'LIKE', '%' . $match . '%');
$query->orWhere([
['servers.username', 'LIKE', '%' . $match . '%'],
['users.email', 'LIKE', '%' . $match . '%'],
['allocations.port', 'LIKE', '%' . $match . '%'],
['allocations.ip', 'LIKE', '%' . $match . '%'],
]);
}
}
}

View file

@ -56,13 +56,12 @@ class DatabaseRepository {
}
DB::beginTransaction();
try {
$db = new Models\Database;
$db->fill([
'server_id' => $server->id,
'db_server' => $options['db_server'],
'database' => $server->uuidShort . '_' . $options['database'],
'database' => "s{$server->id}_{$options['database']}",
'username' => $server->uuidShort . '_' . str_random(7),
'remote' => $options['remote'],
'password' => Crypt::encrypt(str_random(20))
@ -90,16 +89,29 @@ class DatabaseRepository {
$capsule->setAsGlobal();
Capsule::statement('CREATE DATABASE ' . $db->database);
Capsule::statement('CREATE USER \'' . $db->username . '\'@\'' . $db->remote . '\' IDENTIFIED BY \'' . Crypt::decrypt($db->password) . '\'');
Capsule::statement('GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON ' . $db->database . '.* TO \'' . $db->username . '\'@\'' . $db->remote . '\'');
Capsule::statement('FLUSH PRIVILEGES');
DB::commit();
return true;
} catch (\Exception $ex) {
DB::rollback();
throw $ex;
DB::rollBack();
throw new DisplayException('There was an error while connecting to the Database Host Server. Please check the error logs.', $ex);
}
try {
Capsule::statement('CREATE DATABASE `' . $db->database . '`');
Capsule::statement('CREATE USER `' . $db->username . '`@`' . $db->remote . '` IDENTIFIED BY \'' . Crypt::decrypt($db->password) . '\'');
Capsule::statement('GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON `' . $db->database . '`.* TO `' . $db->username . '`@`' . $db->remote . '`');
Capsule::statement('FLUSH PRIVILEGES');
DB::commit();
} catch (\Exception $ex) {
try {
Capsule::statement('DROP DATABASE `' . $db->database . '`');
Capsule::statement('DROP USER `' . $db->username . '`@`' . $db->remote . '`');
} catch (\Exception $exi) {
// ignore it, if it fails its probably
// because we failed to ever make the DB
// or the user on the system.
} finally {
DB::rollBack();
throw $ex;
}
}
}
@ -138,7 +150,7 @@ class DatabaseRepository {
$capsule->setAsGlobal();
Capsule::statement(sprintf(
'SET PASSWORD FOR \'%s\'@\'%s\' = PASSWORD(\'%s\')',
'SET PASSWORD FOR `%s`@`%s` = PASSWORD(\'%s\')',
$db->username,
$db->remote,
$password
@ -182,8 +194,8 @@ class DatabaseRepository {
$capsule->setAsGlobal();
Capsule::statement('DROP USER \'' . $db->username . '\'@\'' . $db->remote . '\'');
Capsule::statement('DROP DATABASE ' . $db->database);
Capsule::statement('DROP USER `' . $db->username . '`@`' . $db->remote . '`');
Capsule::statement('DROP DATABASE `' . $db->database . '`');
$db->delete();
@ -219,6 +231,11 @@ class DatabaseRepository {
*/
public function add(array $data)
{
if (isset($data['host'])) {
$data['host'] = gethostbyname($data['host']);
}
$validator = Validator::make($data, [
'name' => 'required|string|max:255',
'host' => 'required|ip|unique:database_servers,host',

View file

@ -229,8 +229,30 @@ class NodeRepository {
public function delete($id)
{
// @TODO: add logic;
return true;
$node = Models\Node::findOrFail($id);
if (Models\Server::where('node', $id)->count() > 0) {
throw new DisplayException('You cannot delete a node with servers currently attached to it.');
}
DB::beginTransaction();
try {
// Unlink Database Servers
Models\DatabaseServer::where('linked_node', $node->id)->update([
'linked_node' => null,
]);
// Delete Allocations
Models\Allocation::where('node', $node->id)->delete();
// Delete Node
$node->delete();
DB::commit();
} catch (\Exception $ex) {
DB::rollback();
throw $ex;
}
}
}

View file

@ -0,0 +1,93 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 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.
*/
namespace Pterodactyl\Services;
use Cache;
use GuzzleHttp\Client;
class VersionService
{
protected static $versions;
/**
* Constructor
*/
public function __construct()
{
self::$versions = Cache::remember('versions', env('VERSION_CACHE_TIME', 60), function () {
$client = new Client();
try {
$response = $client->request('GET', env('VERSION_CHECK_URL', 'https://cdn.pterodactyl.io/releases/latest.json'));
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody());
} else {
throw new \Exception('Invalid response code.');
}
} catch (\Exception $ex) {
// Failed request, just return errored version.
return (object) [
'panel' => 'error',
'daemon' => 'error',
];
}
});
}
public static function getPanel()
{
return self::$versions->panel;
}
public static function getDaemon()
{
return self::$versions->daemon;
}
public function getCurrentPanel()
{
return config('app.version');
}
public static function isLatestPanel()
{
if (config('app.version') === 'canary') {
return true;
}
return (version_compare(config('app.version'), self::$versions->panel) >= 0);
}
public static function isLatestDaemon($daemon)
{
if ($daemon === '0.0.0-canary') {
return true;
}
return (version_compare($daemon, self::$versions->daemon) >= 0);
}
}