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
2016-12-07 22:46:38 +00:00
* Copyright ( c ) 2015 - 2016 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 ;
2016-02-13 22:29:52 +00:00
use DB ;
2016-01-02 23:04:18 +00:00
use Log ;
2016-12-07 22:46:38 +00:00
use Alert ;
2015-12-15 20:08:41 +00:00
use Pterodactyl\Models ;
2016-12-07 22:46:38 +00:00
use Illuminate\Http\Request ;
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 ;
2016-09-14 19:19:16 +00:00
use Pterodactyl\Exceptions\DisplayValidationException ;
2015-12-06 18:58:49 +00:00
class ServersController extends Controller
{
/**
2016-12-07 22:46:38 +00:00
* Controller Constructor .
2015-12-06 18:58:49 +00:00
*/
public function __construct ()
{
2016-01-04 21:09:39 +00:00
//
2015-12-06 18:58:49 +00:00
}
public function getIndex ( Request $request )
{
2016-10-28 00:05:29 +00:00
$query = Models\Server :: withTrashed () -> select (
2016-10-12 21:12:27 +00:00
'servers.*' ,
'nodes.name as a_nodeName' ,
'users.email as a_ownerEmail' ,
'allocations.ip' ,
'allocations.port' ,
'allocations.ip_alias'
) -> join ( 'nodes' , 'servers.node' , '=' , 'nodes.id' )
-> join ( 'users' , 'servers.owner' , '=' , 'users.id' )
-> join ( 'allocations' , 'servers.allocation' , '=' , 'allocations.id' );
2016-12-07 22:46:38 +00:00
if ( $request -> input ( 'filter' ) && ! is_null ( $request -> input ( 'filter' ))) {
2016-10-12 21:12:27 +00:00
preg_match_all ( '/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/' , urldecode ( $request -> input ( 'filter' )), $matches );
2016-12-07 22:46:38 +00:00
foreach ( $matches [ 0 ] as $match ) {
2016-10-12 21:12:27 +00:00
$match = str_replace ( '"' , '' , $match );
if ( strpos ( $match , ':' )) {
list ( $field , $term ) = explode ( ':' , $match );
2016-11-26 21:19:25 +00:00
if ( $field === 'node' ) {
$field = 'nodes.name' ;
2016-12-07 22:46:38 +00:00
} elseif ( $field === 'owner' ) {
2016-11-27 01:18:46 +00:00
$field = 'users.email' ;
2016-12-07 22:46:38 +00:00
} elseif ( ! strpos ( $field , '.' )) {
2016-11-26 21:19:25 +00:00
$field = 'servers.' . $field ;
}
2016-10-12 21:12:27 +00:00
$query -> orWhere ( $field , 'LIKE' , '%' . $term . '%' );
} else {
$query -> where ( 'servers.name' , 'LIKE' , '%' . $match . '%' );
2016-11-26 21:19:25 +00:00
$query -> orWhere ([
[ 'servers.username' , 'LIKE' , '%' . $match . '%' ],
[ 'users.email' , 'LIKE' , '%' . $match . '%' ],
[ 'allocations.port' , 'LIKE' , '%' . $match . '%' ],
[ 'allocations.ip' , 'LIKE' , '%' . $match . '%' ],
]);
2016-10-12 21:12:27 +00:00
}
}
}
try {
$servers = $query -> paginate ( 20 );
} catch ( \Exception $ex ) {
Alert :: warning ( 'There was an error with the search parameters provided.' );
2016-10-28 00:05:29 +00:00
$servers = Models\Server :: withTrashed () -> select (
2016-08-31 20:03:37 +00:00
'servers.*' ,
'nodes.name as a_nodeName' ,
'users.email as a_ownerEmail' ,
'allocations.ip' ,
'allocations.port' ,
'allocations.ip_alias'
) -> join ( 'nodes' , 'servers.node' , '=' , 'nodes.id' )
-> join ( 'users' , 'servers.owner' , '=' , 'users.id' )
-> join ( 'allocations' , 'servers.allocation' , '=' , 'allocations.id' )
2016-10-12 21:12:27 +00:00
-> paginate ( 20 );
}
return view ( 'admin.servers.index' , [
2016-12-07 22:46:38 +00:00
'servers' => $servers ,
2015-12-06 18:58:49 +00:00
]);
}
public function getNew ( Request $request )
{
2015-12-07 05:47:19 +00:00
return view ( 'admin.servers.new' , [
2015-12-15 20:08:41 +00:00
'locations' => Models\Location :: all (),
2016-12-07 22:46:38 +00:00
'services' => Models\Service :: all (),
2015-12-07 05:47:19 +00:00
]);
2015-12-06 18:58:49 +00:00
}
public function getView ( Request $request , $id )
{
2016-10-28 00:05:29 +00:00
$server = Models\Server :: withTrashed () -> select (
2016-01-03 04:21:22 +00:00
'servers.*' ,
'users.email as a_ownerEmail' ,
'services.name as a_serviceName' ,
2016-09-16 22:39:36 +00:00
DB :: raw ( 'IFNULL(service_options.executable, services.executable) as a_serviceExecutable' ),
2016-09-18 00:14:36 +00:00
'service_options.docker_image' ,
2016-08-31 20:03:37 +00:00
'service_options.name as a_servceOptionName' ,
'allocations.ip' ,
'allocations.port' ,
'allocations.ip_alias'
2016-01-03 04:21:22 +00:00
) -> join ( 'nodes' , 'servers.node' , '=' , 'nodes.id' )
-> join ( 'users' , 'servers.owner' , '=' , 'users.id' )
-> join ( 'services' , 'servers.service' , '=' , 'services.id' )
-> join ( 'service_options' , 'servers.option' , '=' , 'service_options.id' )
2016-08-31 20:03:37 +00:00
-> join ( 'allocations' , 'servers.allocation' , '=' , 'allocations.id' )
2016-01-03 23:10:28 +00:00
-> where ( 'servers.id' , $id )
2016-01-03 04:21:22 +00:00
-> first ();
2016-12-07 22:46:38 +00:00
if ( ! $server ) {
2016-01-04 04:16:03 +00:00
return abort ( 404 );
}
2016-01-02 23:04:18 +00:00
return view ( 'admin.servers.view' , [
2016-01-03 04:21:22 +00:00
'server' => $server ,
2016-12-03 00:35:08 +00:00
'node' => Models\Node :: select (
'nodes.*' ,
'locations.long as a_locationName'
) -> join ( 'locations' , 'nodes.location' , '=' , 'locations.id' )
-> where ( 'nodes.id' , $server -> node )
-> first (),
2016-08-31 20:03:37 +00:00
'assigned' => Models\Allocation :: where ( 'assigned_to' , $id ) -> orderBy ( 'ip' , 'asc' ) -> orderBy ( 'port' , 'asc' ) -> get (),
'unassigned' => Models\Allocation :: where ( 'node' , $server -> node ) -> whereNull ( 'assigned_to' ) -> orderBy ( 'ip' , 'asc' ) -> orderBy ( 'port' , 'asc' ) -> get (),
2016-01-10 23:57:22 +00:00
'startup' => Models\ServiceVariables :: select ( 'service_variables.*' , 'server_variables.variable_value as a_serverValue' )
-> join ( 'server_variables' , 'server_variables.variable_id' , '=' , 'service_variables.id' )
-> where ( 'service_variables.option_id' , $server -> option )
-> where ( 'server_variables.server_id' , $server -> id )
2016-02-08 23:03:02 +00:00
-> get (),
'databases' => Models\Database :: select ( 'databases.*' , 'database_servers.host as a_host' , 'database_servers.port as a_port' )
2016-08-16 04:07:10 +00:00
-> where ( 'server_id' , $server -> id )
2016-02-08 23:03:02 +00:00
-> join ( 'database_servers' , 'database_servers.id' , '=' , 'databases.db_server' )
-> get (),
2016-12-07 22:46:38 +00:00
'db_servers' => Models\DatabaseServer :: all (),
2016-01-02 23:04:18 +00:00
]);
2015-12-06 18:58:49 +00:00
}
2015-12-10 23:30:47 +00:00
public function postNewServer ( Request $request )
{
2015-12-12 04:28:58 +00:00
try {
2015-12-14 03:22:16 +00:00
$server = new ServerRepository ;
2015-12-15 20:08:41 +00:00
$response = $server -> create ( $request -> all ());
2016-12-07 22:46:38 +00:00
return redirect () -> route ( 'admin.servers.view' , [ 'id' => $response ]);
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 ();
2016-12-07 22:46:38 +00:00
2016-09-07 20:12:06 +00:00
return redirect () -> route ( 'admin.servers.new' ) -> withInput ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to add this server. Please try again.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2015-12-15 20:08:41 +00:00
return redirect () -> route ( 'admin.servers.new' ) -> withInput ();
}
2015-12-10 23:30:47 +00:00
}
/**
* Returns a JSON tree of all avaliable nodes in a given location .
*
* @ param \Illuminate\Http\Request $request
* @ return \Illuminate\Contracts\View\View
*/
public function postNewServerGetNodes ( Request $request )
{
2016-12-07 22:46:38 +00:00
if ( ! $request -> input ( 'location' )) {
2015-12-10 23:30:47 +00:00
return response () -> json ([
2016-12-07 22:46:38 +00:00
'error' => 'Missing location in request.' ,
2015-12-10 23:30:47 +00:00
], 500 );
}
2015-12-15 20:08:41 +00:00
return response () -> json ( Models\Node :: select ( 'id' , 'name' , 'public' ) -> where ( 'location' , $request -> input ( 'location' )) -> get ());
2015-12-10 23:30:47 +00:00
}
/**
* Returns a JSON tree of all avaliable IPs and Ports on a given node .
*
* @ param \Illuminate\Http\Request $request
* @ return \Illuminate\Contracts\View\View
*/
public function postNewServerGetIps ( Request $request )
{
2016-12-07 22:46:38 +00:00
if ( ! $request -> input ( 'node' )) {
2015-12-10 23:30:47 +00:00
return response () -> json ([
2016-12-07 22:46:38 +00:00
'error' => 'Missing node in request.' ,
2015-12-10 23:30:47 +00:00
], 500 );
}
2015-12-15 20:08:41 +00:00
$ips = Models\Allocation :: where ( 'node' , $request -> input ( 'node' )) -> whereNull ( 'assigned_to' ) -> get ();
2015-12-10 23:30:47 +00:00
$listing = [];
2016-12-07 22:46:38 +00:00
foreach ( $ips as & $ip ) {
2015-12-10 23:30:47 +00:00
if ( array_key_exists ( $ip -> ip , $listing )) {
$listing [ $ip -> ip ] = array_merge ( $listing [ $ip -> ip ], [ $ip -> port ]);
} else {
$listing [ $ip -> ip ] = [ $ip -> port ];
}
}
2016-12-07 22:46:38 +00:00
return response () -> json ( $listing );
2015-12-10 23:30:47 +00:00
}
/**
* Returns a JSON tree of all avaliable options for a given service .
*
* @ param \Illuminate\Http\Request $request
* @ return \Illuminate\Contracts\View\View
*/
public function postNewServerServiceOptions ( Request $request )
{
2016-12-07 22:46:38 +00:00
if ( ! $request -> input ( 'service' )) {
2015-12-10 23:30:47 +00:00
return response () -> json ([
2016-12-07 22:46:38 +00:00
'error' => 'Missing service in request.' ,
2015-12-10 23:30:47 +00:00
], 500 );
}
2016-01-02 03:53:43 +00:00
$service = Models\Service :: select ( 'executable' , 'startup' ) -> where ( 'id' , $request -> input ( 'service' )) -> first ();
2015-12-10 23:30:47 +00:00
2016-12-07 22:46:38 +00:00
return response () -> json ( Models\ServiceOptions :: select ( 'id' , 'name' , 'docker_image' ) -> where ( 'parent_service' , $request -> input ( 'service' )) -> orderBy ( 'name' , 'asc' ) -> get ());
2015-12-10 23:30:47 +00:00
}
/**
* Returns a JSON tree of all avaliable variables for a given service option .
*
* @ param \Illuminate\Http\Request $request
* @ return \Illuminate\Contracts\View\View
*/
public function postNewServerServiceVariables ( Request $request )
{
2016-12-07 22:46:38 +00:00
if ( ! $request -> input ( 'option' )) {
2015-12-10 23:30:47 +00:00
return response () -> json ([
2016-12-07 22:46:38 +00:00
'error' => 'Missing option in request.' ,
2015-12-10 23:30:47 +00:00
], 500 );
}
2016-02-13 22:29:52 +00:00
$option = Models\ServiceOptions :: select (
DB :: raw ( 'COALESCE(service_options.executable, services.executable) as executable' ),
DB :: raw ( 'COALESCE(service_options.startup, services.startup) as startup' )
) -> leftJoin ( 'services' , 'services.id' , '=' , 'service_options.parent_service' )
-> where ( 'service_options.id' , $request -> input ( 'option' ))
-> first ();
return response () -> json ([
'variables' => Models\ServiceVariables :: where ( 'option_id' , $request -> input ( 'option' )) -> get (),
'exec' => $option -> executable ,
2016-12-07 22:46:38 +00:00
'startup' => $option -> startup ,
2016-02-13 22:29:52 +00:00
]);
2015-12-10 23:30:47 +00:00
}
2016-01-02 23:04:18 +00:00
public function postUpdateServerDetails ( Request $request , $id )
{
try {
$server = new ServerRepository ;
$server -> updateDetails ( $id , [
'owner' => $request -> input ( 'owner' ),
'name' => $request -> input ( 'name' ),
2016-12-07 22:46:38 +00:00
'reset_token' => ( $request -> input ( 'reset_token' , false ) === 'on' ) ? true : false ,
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 ) {
2016-01-02 23:04:18 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_details' ,
2016-09-18 00:14:36 +00:00
]) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to update this server. Please try again.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_details' ,
2016-09-18 00:14:36 +00:00
]) -> withInput ();
}
2016-12-07 22:46:38 +00:00
public function postUpdateContainerDetails ( Request $request , $id )
{
2016-09-18 00:14:36 +00:00
try {
$server = new ServerRepository ;
$server -> updateContainer ( $id , [
2016-12-07 22:46:38 +00:00
'image' => $request -> input ( 'docker_image' ),
2016-01-02 23:04:18 +00:00
]);
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 ) {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_details' ,
2016-09-07 20:12:06 +00:00
]) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
2016-09-18 00:14:36 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to update this server\'s docker image. Please try again.' ) -> flash ();
2016-01-02 23:04:18 +00:00
}
2016-09-07 20:12:06 +00:00
2016-09-18 00:14:36 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_details' ,
2016-09-18 00:14:36 +00:00
]);
2016-01-02 23:04:18 +00:00
}
2016-12-07 22:46:38 +00:00
public function postUpdateServerToggleBuild ( Request $request , $id )
{
2016-01-03 04:21:22 +00:00
$server = Models\Server :: findOrFail ( $id );
$node = Models\Node :: findOrFail ( $server -> node );
$client = Models\Node :: guzzleRequest ( $server -> node );
try {
$res = $client -> request ( 'POST' , '/server/rebuild' , [
'headers' => [
'X-Access-Server' => $server -> uuid ,
2016-12-07 22:46:38 +00:00
'X-Access-Token' => $node -> daemonSecret ,
],
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 ();
} catch ( \GuzzleHttp\Exception\TransferException $ex ) {
Log :: warning ( $ex );
2016-08-16 23:20:58 +00:00
Alert :: danger ( 'An error occured while attempting to toggle a rebuild.' ) -> flash ();
2016-01-03 04:21:22 +00:00
}
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_manage' ,
2016-01-03 04:21:22 +00:00
]);
}
public function postUpdateServerUpdateBuild ( Request $request , $id )
{
try {
$server = new ServerRepository ;
$server -> changeBuild ( $id , [
'default' => $request -> input ( 'default' ),
'add_additional' => $request -> input ( 'add_additional' ),
'remove_additional' => $request -> input ( 'remove_additional' ),
'memory' => $request -> input ( 'memory' ),
'swap' => $request -> input ( 'swap' ),
'io' => $request -> input ( 'io' ),
'cpu' => $request -> input ( 'cpu' ),
]);
Alert :: success ( 'Server details were successfully updated.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( DisplayValidationException $ex ) {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_build' ,
2016-09-07 20:12:06 +00:00
]) -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
2016-09-07 20:12:06 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_build' ,
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 ();
2016-01-03 04:21:22 +00:00
}
2016-09-07 20:12:06 +00:00
2016-01-03 04:21:22 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_build' ,
2016-01-03 04:21:22 +00:00
]);
}
2016-01-04 04:16:03 +00:00
public function deleteServer ( Request $request , $id , $force = null )
{
try {
$server = new ServerRepository ;
$server -> deleteServer ( $id , $force );
2016-10-28 00:05:29 +00:00
Alert :: success ( 'Server has been marked for deletion on the system.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2016-01-04 04:16:03 +00:00
return redirect () -> route ( 'admin.servers' );
2016-09-07 20:12:06 +00:00
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $ex ) {
2016-09-07 20:12:06 +00:00
Log :: error ( $ex );
Alert :: danger ( 'An unhandled exception occured while attemping to delete this server. Please try again.' ) -> flash ();
2016-01-04 04:16:03 +00:00
}
2016-12-07 22:46:38 +00:00
2016-09-14 22:35:33 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_delete' ,
2016-09-14 22:35:33 +00:00
]);
2016-01-04 04:16:03 +00:00
}
2016-01-04 21:09:22 +00:00
public function postToggleInstall ( Request $request , $id )
{
try {
$server = new ServerRepository ;
$server -> toggleInstall ( $id );
Alert :: success ( 'Server status was successfully toggled.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( DisplayException $ex ) {
2016-01-23 01:39:16 +00:00
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $ex ) {
2016-01-23 01:39:16 +00:00
Log :: error ( $ex );
2016-01-04 21:09:22 +00:00
Alert :: danger ( 'An unhandled exception occured while attemping to toggle this servers status.' ) -> flash ();
} finally {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_manage' ,
2016-01-04 21:09:22 +00:00
]);
}
}
2016-01-10 23:57:22 +00:00
public function postUpdateServerStartup ( Request $request , $id )
{
try {
$server = new ServerRepository ;
$server -> updateStartup ( $id , $request -> except ([
2016-12-07 22:46:38 +00:00
'_token' ,
2016-02-13 22:36:03 +00:00
]), true );
2016-01-10 23:57:22 +00:00
Alert :: success ( 'Server startup variables were successfully updated.' ) -> flash ();
} catch ( \Pterodactyl\Exceptions\DisplayException $e ) {
Alert :: danger ( $e -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $e ) {
2016-01-10 23:57:22 +00:00
Log :: error ( $e );
Alert :: danger ( 'An unhandled exception occured while attemping to update startup variables for this server. Please try again.' ) -> flash ();
} finally {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_startup' ,
2016-01-10 23:57:22 +00:00
]) -> withInput ();
}
}
2016-02-08 23:03:02 +00:00
public function postDatabase ( Request $request , $id )
{
try {
$repo = new DatabaseRepository ;
$repo -> create ( $id , $request -> except ([
2016-12-07 22:46:38 +00:00
'_token' ,
2016-02-08 23:03:02 +00:00
]));
Alert :: success ( 'Added new database to this server.' ) -> flash ();
2016-09-07 20:12:06 +00:00
} catch ( DisplayValidationException $ex ) {
2016-02-08 23:03:02 +00:00
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_database' ,
2016-02-08 23:03:02 +00:00
]) -> withInput () -> withErrors ( json_decode ( $ex -> getMessage ())) -> withInput ();
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An exception occured while attempting to add a new database for this server.' ) -> flash ();
}
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_database' ,
2016-02-08 23:03:02 +00:00
]) -> withInput ();
}
2016-09-02 01:16:38 +00:00
public function postSuspendServer ( Request $request , $id )
{
try {
$repo = new ServerRepository ;
$repo -> suspend ( $id );
Alert :: success ( 'Server has been suspended on the system. All running processes have been stopped and will not be startable until it is un-suspended.' );
2016-09-07 20:12:06 +00:00
} catch ( DisplayException $e ) {
2016-09-02 01:16:38 +00:00
Alert :: danger ( $e -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $e ) {
2016-09-02 01:16:38 +00:00
Log :: error ( $e );
Alert :: danger ( 'An unhandled exception occured while attemping to suspend this server. Please try again.' ) -> flash ();
} finally {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_manage' ,
2016-09-02 01:16:38 +00:00
]);
}
}
public function postUnsuspendServer ( Request $request , $id )
{
try {
$repo = new ServerRepository ;
$repo -> unsuspend ( $id );
Alert :: success ( 'Server has been unsuspended on the system. Access has been re-enabled.' );
2016-09-07 20:12:06 +00:00
} catch ( DisplayException $e ) {
2016-09-02 01:16:38 +00:00
Alert :: danger ( $e -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
} catch ( \Exception $e ) {
2016-09-02 01:16:38 +00:00
Log :: error ( $e );
Alert :: danger ( 'An unhandled exception occured while attemping to unsuspend this server. Please try again.' ) -> flash ();
} finally {
return redirect () -> route ( 'admin.servers.view' , [
'id' => $id ,
2016-12-07 22:46:38 +00:00
'tab' => 'tab_manage' ,
2016-09-02 01:16:38 +00:00
]);
}
}
2016-10-28 00:05:29 +00:00
public function postQueuedDeletionHandler ( Request $request , $id )
{
try {
$repo = new ServerRepository ;
2016-12-07 22:46:38 +00:00
if ( ! is_null ( $request -> input ( 'cancel' ))) {
2016-10-28 00:05:29 +00:00
$repo -> cancelDeletion ( $id );
Alert :: success ( 'Server deletion has been cancelled. This server will remain suspended until you unsuspend it.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2016-10-28 00:05:29 +00:00
return redirect () -> route ( 'admin.servers.view' , $id );
2016-12-07 22:46:38 +00:00
} elseif ( ! is_null ( $request -> input ( 'delete' ))) {
2016-10-28 00:05:29 +00:00
$repo -> deleteNow ( $id );
Alert :: success ( 'Server was successfully deleted from the system.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2016-10-28 00:05:29 +00:00
return redirect () -> route ( 'admin.servers' );
2016-12-07 22:46:38 +00:00
} elseif ( ! is_null ( $request -> input ( 'force_delete' ))) {
2016-10-28 00:05:29 +00:00
$repo -> deleteNow ( $id , true );
Alert :: success ( 'Server was successfully force deleted from the system.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2016-10-28 00:05:29 +00:00
return redirect () -> route ( 'admin.servers' );
}
} catch ( DisplayException $ex ) {
Alert :: danger ( $ex -> getMessage ()) -> flash ();
2016-12-07 22:46:38 +00:00
2016-10-28 00:05:29 +00:00
return redirect () -> route ( 'admin.servers.view' , $id );
} catch ( \Exception $ex ) {
Log :: error ( $ex );
Alert :: danger ( 'An unhandled error occured while attempting to perform this action.' ) -> flash ();
2016-12-07 22:46:38 +00:00
2016-10-28 00:05:29 +00:00
return redirect () -> route ( 'admin.servers.view' , $id );
}
}
2015-12-06 18:58:49 +00:00
}