2015-12-06 18:58:49 +00:00
< ? php
2016-01-20 00:10:39 +00:00
/**
2016-01-20 21:05:16 +00:00
* Pterodactyl - Panel
2017-01-24 22:57:08 +00:00
* Copyright ( c ) 2015 - 2017 Dane Everitt < dane @ daneeveritt . com >.
2016-01-20 00:10:39 +00:00
*
2016-01-20 20:56:40 +00:00
* 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 :
2016-01-20 00:10:39 +00:00
*
2016-01-20 20:56:40 +00:00
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software .
2016-01-20 00:10:39 +00:00
*
2016-01-20 20:56:40 +00:00
* 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 .
2016-01-20 00:10:39 +00:00
*/
2016-12-07 22:46:38 +00:00
2015-12-06 18:58:49 +00:00
namespace Pterodactyl\Http\Controllers\Admin ;
2017-07-15 16:52:34 +00:00
use Illuminate\Contracts\Config\Repository as ConfigRepository ;
2016-01-02 23:04:18 +00:00
use Log ;
2016-12-07 22:46:38 +00:00
use Alert ;
2017-02-24 23:19:03 +00:00
use Javascript ;
2017-07-15 16:52:34 +00:00
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface ;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface ;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface ;
use Pterodactyl\Contracts\Repository\ServiceRepositoryInterface ;
2015-12-15 20:08:41 +00:00
use Pterodactyl\Models ;
2016-12-07 22:46:38 +00:00
use Illuminate\Http\Request ;
2017-03-05 00:03:49 +00:00
use GuzzleHttp\Exception\TransferException ;
2016-12-07 22:46:38 +00:00
use Pterodactyl\Exceptions\DisplayException ;
use Pterodactyl\Http\Controllers\Controller ;
2015-12-14 03:22:16 +00:00
use Pterodactyl\Repositories\ServerRepository ;
2016-02-08 23:03:02 +00:00
use Pterodactyl\Repositories\DatabaseRepository ;
2017-05-02 02:59:56 +00:00
use Pterodactyl\Exceptions\AutoDeploymentException ;
2016-09-14 19:19:16 +00:00
use Pterodactyl\Exceptions\DisplayValidationException ;
2015-12-06 18:58:49 +00:00
class ServersController extends Controller
{
2017-07-15 16:52:34 +00:00
/**
* @ var \Illuminate\Contracts\Config\Repository
*/
protected $config ;
/**
* @ var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
*/
protected $databaseRepository ;
/**
* @ var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
*/
protected $locationRepository ;
/**
* @ var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
*/
protected $repository ;
/**
* @ var \Pterodactyl\Contracts\Repository\ServiceRepositoryInterface
*/
protected $serviceRepository ;
public function __construct (
ConfigRepository $config ,
DatabaseRepositoryInterface $databaseRepository ,
LocationRepositoryInterface $locationRepository ,
ServerRepositoryInterface $repository ,
ServiceRepositoryInterface $serviceRepository
) {
$this -> config = $config ;
$this -> databaseRepository = $databaseRepository ;
$this -> locationRepository = $locationRepository ;
$this -> repository = $repository ;
$this -> serviceRepository = $serviceRepository ;
}
2015-12-06 18:58:49 +00:00
/**
2017-03-05 00:03:49 +00:00
* Display the index page with all servers currently on the system .
*
* @ return \Illuminate\View\View
2015-12-06 18:58:49 +00:00
*/
2017-07-15 16:52:34 +00:00
public function index ()
2015-12-06 18:58:49 +00:00
{
2016-10-12 21:12:27 +00:00
return view ( 'admin.servers.index' , [
2017-07-15 16:52:34 +00:00
'servers' => $this -> repository -> getAllServers (
$this -> config -> get ( 'pterodactyl.paginate.admin.servers' )
),
2015-12-06 18:58:49 +00:00
]);
}
2017-03-05 00:03:49 +00:00
/**
* Display create new server page .
*
* @ return \Illuminate\View\View
2017-07-15 16:52:34 +00:00
*
* @ throws \Exception
2017-03-05 00:03:49 +00:00
*/
2017-07-15 16:52:34 +00:00
public function create ()
2015-12-06 18:58:49 +00:00
{
2017-07-15 16:52:34 +00:00
$services = $this -> serviceRepository -> getWithOptions ();
2017-02-24 23:19:03 +00:00
Javascript :: put ([
'services' => $services -> map ( function ( $item ) {
return array_merge ( $item -> toArray (), [
'options' => $item -> options -> keyBy ( 'id' ) -> toArray (),
]);
}) -> keyBy ( 'id' ),
]);
2015-12-07 05:47:19 +00:00
return view ( 'admin.servers.new' , [
2017-07-15 16:52:34 +00:00
'locations' => $this -> locationRepository -> all (),
2017-02-24 23:19:03 +00:00
'services' => $services ,
2015-12-07 05:47:19 +00:00
]);
2015-12-06 18:58:49 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Create server controller method .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\Response\RedirectResponse
*/
2017-04-09 23:13:22 +00:00
public function store ( Request $request )
2015-12-10 23:30:47 +00:00
{
2015-12-12 04:28:58 +00:00
try {
2017-03-05 00:03:49 +00:00
$repo = new ServerRepository ;
$server = $repo -> create ( $request -> except ( '_token' ));
2017-02-11 01:26:38 +00:00
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view' , $server -> id );
2016-09-07 20:12:06 +00:00
} catch ( DisplayValidationException $ex ) {
return redirect () -> route ( 'admin.servers.new' ) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2017-05-02 02:59:56 +00:00
} catch ( AutoDeploymentException $ex ) {
Alert :: danger ( 'Auto-Deployment Exception: ' . $ex -> getMessage ()) -> flash ();
2017-04-09 17:15:15 +00:00
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to add this server. Please try again.' ) -> flash ();
2015-12-15 20:08:41 +00:00
}
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.new' ) -> withInput ();
2015-12-10 23:30:47 +00:00
}
/**
2017-03-05 00:03:49 +00:00
* Returns a tree of all avaliable nodes in a given location .
2015-12-10 23:30:47 +00:00
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
2017-07-15 16:52:34 +00:00
* @ return \Illuminate\Support\Collection
2015-12-10 23:30:47 +00:00
*/
2017-04-09 23:13:22 +00:00
public function nodes ( Request $request )
2015-12-10 23:30:47 +00:00
{
2017-02-19 00:31:44 +00:00
$nodes = Models\Node :: with ( 'allocations' ) -> where ( 'location_id' , $request -> input ( 'location' )) -> get ();
2017-02-24 23:23:03 +00:00
2017-02-19 00:31:44 +00:00
return $nodes -> map ( function ( $item ) {
2017-02-24 23:23:03 +00:00
$filtered = $item -> allocations -> where ( 'server_id' , null ) -> map ( function ( $map ) {
2017-02-24 03:52:05 +00:00
return collect ( $map ) -> only ([ 'id' , 'ip' , 'port' ]);
2017-02-19 00:31:44 +00:00
});
2017-02-24 03:52:05 +00:00
$item -> ports = $filtered -> map ( function ( $map ) use ( $item ) {
2017-02-19 00:31:44 +00:00
return [
2017-02-24 03:52:05 +00:00
'id' => $map [ 'id' ],
'text' => $map [ 'ip' ] . ':' . $map [ 'port' ],
2017-02-19 00:31:44 +00:00
];
}) -> values ();
return [
'id' => $item -> id ,
'text' => $item -> name ,
'allocations' => $item -> ports ,
];
}) -> values ();
2015-12-10 23:30:47 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Display the index when viewing a specific server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewIndex ( Request $request , $id )
{
2017-04-01 02:12:31 +00:00
return view ( 'admin.servers.view.index' , [ 'server' => Models\Server :: findOrFail ( $id )]);
2017-03-05 00:03:49 +00:00
}
/**
* Display the details page when viewing a specific server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewDetails ( Request $request , $id )
{
$server = Models\Server :: where ( 'installed' , 1 ) -> findOrFail ( $id );
return view ( 'admin.servers.view.details' , [ 'server' => $server ]);
}
/**
* Display the build details page when viewing a specific server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewBuild ( Request $request , $id )
2016-01-02 23:04:18 +00:00
{
2017-03-05 00:03:49 +00:00
$server = Models\Server :: where ( 'installed' , 1 ) -> with ( 'node.allocations' ) -> findOrFail ( $id );
return view ( 'admin.servers.view.build' , [
'server' => $server ,
'assigned' => $server -> node -> allocations -> where ( 'server_id' , $server -> id ) -> sortBy ( 'port' ) -> sortBy ( 'ip' ),
'unassigned' => $server -> node -> allocations -> where ( 'server_id' , null ) -> sortBy ( 'port' ) -> sortBy ( 'ip' ),
]);
}
/**
* Display startup configuration page for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewStartup ( Request $request , $id )
{
$server = Models\Server :: where ( 'installed' , 1 ) -> with ( 'option.variables' , 'variables' ) -> findOrFail ( $id );
$server -> option -> variables -> transform ( function ( $item , $key ) use ( $server ) {
$item -> server_value = $server -> variables -> where ( 'variable_id' , $item -> id ) -> pluck ( 'variable_value' ) -> first ();
return $item ;
});
2017-04-21 21:52:44 +00:00
$services = Models\Service :: with ( 'options.packs' , 'options.variables' ) -> get ();
Javascript :: put ([
'services' => $services -> map ( function ( $item ) {
return array_merge ( $item -> toArray (), [
'options' => $item -> options -> keyBy ( 'id' ) -> toArray (),
]);
}) -> keyBy ( 'id' ),
'server_variables' => $server -> variables -> mapWithKeys ( function ( $item ) {
return [ 'env_' . $item -> variable_id => [
'value' => $item -> variable_value ,
]];
}) -> toArray (),
]);
return view ( 'admin.servers.view.startup' , [
'server' => $server ,
'services' => $services ,
]);
2017-03-05 00:03:49 +00:00
}
/**
* Display the database management page for a specific server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewDatabase ( Request $request , $id )
{
$server = Models\Server :: where ( 'installed' , 1 ) -> with ( 'databases.host' ) -> findOrFail ( $id );
2017-03-05 21:37:38 +00:00
return view ( 'admin.servers.view.database' , [
2017-03-16 23:35:29 +00:00
'hosts' => Models\DatabaseHost :: all (),
2017-03-06 01:28:29 +00:00
'server' => $server ,
2017-03-05 21:37:38 +00:00
]);
2017-03-05 00:03:49 +00:00
}
/**
* Display the management page when viewing a specific server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewManage ( Request $request , $id )
{
return view ( 'admin.servers.view.manage' , [ 'server' => Models\Server :: findOrFail ( $id )]);
}
/**
* Display the deletion page for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
2017-03-05 00:03:49 +00:00
* @ return \Illuminate\View\View
*/
public function viewDelete ( Request $request , $id )
{
2017-04-01 02:12:31 +00:00
return view ( 'admin.servers.view.delete' , [ 'server' => Models\Server :: findOrFail ( $id )]);
2017-03-05 00:03:49 +00:00
}
/**
* Update the details for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function setDetails ( Request $request , $id )
{
2017-03-05 00:28:23 +00:00
$repo = new ServerRepository ;
2016-01-02 23:04:18 +00:00
try {
2017-05-24 04:00:31 +00:00
$repo -> updateDetails ( $id , array_merge (
$request -> only ( 'description' ),
$request -> intersect ([
'owner_id' , 'name' , 'reset_token' ,
])
));
2016-01-02 23:04:18 +00:00
Alert :: success ( 'Server details were successfully updated.' ) -> flash ();
2016-09-18 00:14:36 +00:00
} catch ( DisplayValidationException $ex ) {
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.details' , $id ) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
2016-09-18 00:14:36 +00:00
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to update this server. This error has been logged.' ) -> flash ();
2016-09-18 00:14:36 +00:00
}
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.details' , $id ) -> withInput ();
2016-09-18 00:14:36 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Set the new docker container for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function setContainer ( Request $request , $id )
2016-12-07 22:46:38 +00:00
{
2017-03-05 00:03:49 +00:00
$repo = new ServerRepository ;
2016-09-18 00:14:36 +00:00
try {
2017-03-05 00:03:49 +00:00
$repo -> updateContainer ( $id , $request -> intersect ( 'docker_image' ));
2016-09-18 00:14:36 +00:00
Alert :: success ( 'Successfully updated this server\'s docker image.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( DisplayValidationException $ex ) {
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.details' , $id ) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
2017-04-09 17:15:15 +00:00
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException occured while attempting to update the container image. Is the daemon online? This error has been logged.' );
2016-09-07 20:12:06 +00:00
} catch ( \Exception $ex ) {
Log :: error ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to update this server\'s docker image. This error has been logged.' ) -> flash ();
2016-01-02 23:04:18 +00:00
}
2016-09-07 20:12:06 +00:00
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.details' , $id );
}
/**
* Toggles the install status for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function toggleInstall ( Request $request , $id )
{
$repo = new ServerRepository ;
try {
$repo -> toggleInstall ( $id );
Alert :: success ( 'Server install status was successfully toggled.' ) -> flash ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to toggle this servers status. This error has been logged.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view.manage' , $id );
2016-01-02 23:04:18 +00:00
}
2017-04-20 22:52:43 +00:00
/**
* Reinstalls the server with the currently assigned pack and service .
*
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
*/
public function reinstallServer ( Request $request , $id )
{
$repo = new ServerRepository ;
try {
$repo -> reinstall ( $id );
Alert :: success ( 'Server successfully marked for reinstallation.' ) -> flash ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to perform this reinstallation. This error has been logged.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view.manage' , $id );
}
2017-03-05 00:03:49 +00:00
/**
* Setup a server to have a container rebuild .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function rebuildContainer ( Request $request , $id )
2016-12-07 22:46:38 +00:00
{
2017-02-09 22:43:54 +00:00
$server = Models\Server :: with ( 'node' ) -> findOrFail ( $id );
2016-01-03 04:21:22 +00:00
try {
2017-03-05 00:03:49 +00:00
$server -> node -> guzzleClient ([
2017-02-09 22:43:54 +00:00
'X-Access-Server' => $server -> uuid ,
2017-02-19 03:33:15 +00:00
'X-Access-Token' => $server -> node -> daemonSecret ,
2017-02-09 22:43:54 +00:00
]) -> request ( 'POST' , '/server/rebuild' );
2017-03-05 00:03:49 +00:00
2016-01-03 04:21:22 +00:00
Alert :: success ( 'A rebuild has been queued successfully. It will run the next time this server is booted.' ) -> flash ();
2017-03-05 00:03:49 +00:00
} catch ( TransferException $ex ) {
2016-01-03 04:21:22 +00:00
Log :: warning ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.' ) -> flash ();
2016-01-03 04:21:22 +00:00
}
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.manage' , $id );
2016-01-03 04:21:22 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Manage the suspension status for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function manageSuspension ( Request $request , $id )
2016-01-03 04:21:22 +00:00
{
2017-03-05 00:03:49 +00:00
$repo = new ServerRepository ;
$action = $request -> input ( 'action' );
if ( ! in_array ( $action , [ 'suspend' , 'unsuspend' ])) {
Alert :: danger ( 'Invalid action was passed to function.' ) -> flash ();
return redirect () -> route ( 'admin.servers.view.manage' , $id );
}
2016-01-03 04:21:22 +00:00
try {
2017-04-18 00:16:05 +00:00
$repo -> toggleAccess ( $id , ( $action === 'unsuspend' ));
2017-03-05 00:03:49 +00:00
Alert :: success ( 'Server has been ' . $action . 'ed.' );
2017-04-09 17:15:15 +00:00
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( \Exception $ex ) {
Log :: error ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to ' . $action . ' this server. This error has been logged.' ) -> flash ();
2016-01-03 04:21:22 +00:00
}
2016-09-07 20:12:06 +00:00
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.manage' , $id );
2016-01-03 04:21:22 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Update the build configuration for a server .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function updateBuild ( Request $request , $id )
2016-01-04 04:16:03 +00:00
{
2017-03-05 00:03:49 +00:00
$repo = new ServerRepository ;
2016-01-04 04:16:03 +00:00
try {
2017-03-05 00:03:49 +00:00
$repo -> changeBuild ( $id , $request -> intersect ([
'allocation_id' , 'add_allocations' , 'remove_allocations' ,
2017-04-22 02:44:56 +00:00
'memory' , 'swap' , 'io' , 'cpu' , 'disk' ,
2017-03-05 00:03:49 +00:00
]));
2016-12-07 22:46:38 +00:00
2017-03-05 00:03:49 +00:00
Alert :: success ( 'Server details were successfully updated.' ) -> flash ();
} catch ( DisplayValidationException $ex ) {
return redirect () -> route ( 'admin.servers.view.build' , $id ) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
2016-09-07 20:12:06 +00:00
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2017-04-09 17:15:15 +00:00
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException was encountered while trying to contact the daemon, please ensure it is online and accessible. This error has been logged.' ) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $ex ) {
2016-09-07 20:12:06 +00:00
Log :: error ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to add this server. This error has been logged.' ) -> flash ();
2016-01-04 04:16:03 +00:00
}
2016-12-07 22:46:38 +00:00
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.build' , $id );
2016-01-04 04:16:03 +00:00
}
2017-03-05 00:03:49 +00:00
/**
* Start the server deletion process .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 00:03:49 +00:00
*/
public function delete ( Request $request , $id )
2016-01-04 21:09:22 +00:00
{
2017-03-05 00:03:49 +00:00
$repo = new ServerRepository ;
2016-01-04 21:09:22 +00:00
try {
2017-04-01 02:12:31 +00:00
$repo -> delete ( $id , $request -> has ( 'force_delete' ));
2017-03-05 00:03:49 +00:00
Alert :: success ( 'Server was successfully deleted from the system.' ) -> flash ();
return redirect () -> route ( 'admin.servers' );
2016-10-28 00:05:29 +00:00
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2017-03-05 00:03:49 +00:00
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException occurred while attempting to delete this server from the daemon, please ensure it is running. This error has been logged.' ) -> flash ();
2016-10-28 00:05:29 +00:00
} catch ( \Exception $ex ) {
Log :: error ( $ex );
2017-03-05 00:03:49 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to delete this server. This error has been logged.' ) -> flash ();
2016-10-28 00:05:29 +00:00
}
2017-03-05 00:03:49 +00:00
return redirect () -> route ( 'admin.servers.view.delete' , $id );
2016-10-28 00:05:29 +00:00
}
2017-03-05 00:03:49 +00:00
2017-03-05 04:45:22 +00:00
/**
* Update the startup command as well as variables .
*
2017-03-19 23:36:50 +00:00
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 04:45:22 +00:00
*/
public function saveStartup ( Request $request , $id )
{
$repo = new ServerRepository ;
try {
2017-04-21 21:52:44 +00:00
if ( $repo -> updateStartup ( $id , $request -> except ( '_token' ), true )) {
Alert :: success ( 'Service configuration successfully modfied for this server, reinstalling now.' ) -> flash ();
2017-03-05 04:45:22 +00:00
2017-04-21 21:52:44 +00:00
return redirect () -> route ( 'admin.servers.view' , $id );
} else {
Alert :: success ( 'Startup variables were successfully modified and assigned for this server.' ) -> flash ();
}
2017-03-12 23:34:06 +00:00
} catch ( DisplayValidationException $ex ) {
return redirect () -> route ( 'admin.servers.view.startup' , $id ) -> withErrors ( json_decode ( $ex -> getMessage ()));
2017-03-06 01:28:29 +00:00
} catch ( DisplayException $ex ) {
2017-03-05 04:45:22 +00:00
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( TransferException $ex ) {
Log :: warning ( $ex );
Alert :: danger ( 'A TransferException occurred while attempting to update the startup for this server, please ensure the daemon is running. This error has been logged.' ) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to update startup variables for this server. This error has been logged.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view.startup' , $id );
}
2017-03-05 21:37:38 +00:00
/**
* Creates a new database assigned to a specific server .
2017-03-19 23:36:50 +00:00
*
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 21:37:38 +00:00
*/
public function newDatabase ( Request $request , $id )
{
$repo = new DatabaseRepository ;
try {
$repo -> create ( $id , $request -> only ([ 'host' , 'database' , 'connection' ]));
Alert :: success ( 'A new database was assigned to this server successfully.' ) -> flash ();
} catch ( DisplayValidationException $ex ) {
return redirect () -> route ( 'admin.servers.view.database' , $id ) -> withInput () -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
2017-03-06 01:28:29 +00:00
} catch ( DisplayException $ex ) {
2017-03-05 21:37:38 +00:00
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An exception occured while attempting to add a new database for this server. This error has been logged.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view.database' , $id ) -> withInput ();
}
/**
* Resets the database password for a specific database on this server .
2017-03-19 23:36:50 +00:00
*
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 21:37:38 +00:00
*/
public function resetDatabasePassword ( Request $request , $id )
{
$database = Models\Database :: where ( 'server_id' , $id ) -> findOrFail ( $request -> input ( 'database' ));
$repo = new DatabaseRepository ;
try {
$repo -> password ( $database -> id , str_random ( 20 ));
return response ( '' , 204 );
} catch ( \Exception $ex ) {
Log :: error ( $ex );
return response () -> json ([ 'error' => 'A unhandled exception occurred while attempting to reset this password. This error has been logged.' ], 503 );
}
}
/**
* Deletes a database from a server .
2017-03-19 23:36:50 +00:00
*
* @ param \Illuminate\Http\Request $request
* @ param int $id
* @ param int $database
* @ return \Illuminate\Http\RedirectResponse
2017-03-05 21:37:38 +00:00
*/
public function deleteDatabase ( Request $request , $id , $database )
{
$database = Models\Database :: where ( 'server_id' , $id ) -> findOrFail ( $database );
$repo = new DatabaseRepository ;
try {
$repo -> drop ( $database -> id );
return response ( '' , 204 );
} catch ( \Exception $ex ) {
Log :: error ( $ex );
return response () -> json ([ 'error' => 'A unhandled exception occurred while attempting to drop this database. This error has been logged.' ], 503 );
}
}
2015-12-06 18:58:49 +00:00
}