diff --git a/app/Http/Controllers/Admin/AjaxController.php b/app/Http/Controllers/Admin/AjaxController.php deleted file mode 100644 index 20f4317c5..000000000 --- a/app/Http/Controllers/Admin/AjaxController.php +++ /dev/null @@ -1,95 +0,0 @@ -middleware('auth'); - $this->middleware('admin'); - - } - - /** - * 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) - { - - if(!$request->input('location')) { - return response()->json([ - 'error' => 'Missing location in request.' - ], 500); - } - - return response()->json(Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()); - - } - - /** - * 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) - { - - if(!$request->input('node')) { - return response()->json([ - 'error' => 'Missing node in request.' - ], 500); - } - - $ips = Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get(); - $listing = []; - - foreach($ips as &$ip) { - if (array_key_exists($ip->ip, $listing)) { - $listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]); - } else { - $listing[$ip->ip] = [$ip->port]; - } - } - return response()->json($listing); - - } - - /** - * 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) - { - - if(!$request->input('service')) { - return response()->json([ - 'error' => 'Missing service in request.' - ], 500); - } - - return response()->json(ServiceOptions::select('id', 'name')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get()); - - } - -} diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index ce520564e..dafab153e 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -4,8 +4,12 @@ namespace Pterodactyl\Http\Controllers\Admin; use Debugbar; use Pterodactyl\Models\Server; +use Pterodactyl\Models\Node; use Pterodactyl\Models\Location; +use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Service; +use Pterodactyl\Models\ServiceOptions; +use Pterodactyl\Models\ServiceVariables; use Pterodactyl\Http\Controllers\Controller; use Illuminate\Http\Request; @@ -48,4 +52,95 @@ class ServersController extends Controller // } + public function postNewServer(Request $request) + { + return json_encode($request->all()); + } + + /** + * 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) + { + + if(!$request->input('location')) { + return response()->json([ + 'error' => 'Missing location in request.' + ], 500); + } + + return response()->json(Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()); + + } + + /** + * 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) + { + + if(!$request->input('node')) { + return response()->json([ + 'error' => 'Missing node in request.' + ], 500); + } + + $ips = Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get(); + $listing = []; + + foreach($ips as &$ip) { + if (array_key_exists($ip->ip, $listing)) { + $listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]); + } else { + $listing[$ip->ip] = [$ip->port]; + } + } + return response()->json($listing); + + } + + /** + * 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) + { + + if(!$request->input('service')) { + return response()->json([ + 'error' => 'Missing service in request.' + ], 500); + } + + return response()->json(ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get()); + + } + + /** + * 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) + { + + if(!$request->input('option')) { + return response()->json([ + 'error' => 'Missing option in request.' + ], 500); + } + + return response()->json(ServiceVariables::where('option_id', $request->input('option'))->get()); + + } + } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index 582a788c8..058d3c786 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -19,16 +19,17 @@ class AdminRoutes { // Server Routes $router->group(['prefix' => 'servers'], function ($server) use ($router) { + $router->get('/', [ 'as' => 'admin.servers', 'uses' => 'Admin\ServersController@getIndex' ]); $router->get('/new', [ 'as' => 'admin.servers.new', 'uses' => 'Admin\ServersController@getNew' ]); $router->get('/view/{id}', [ 'as' => 'admin.servers.view', 'uses' => 'Admin\ServersController@getView' ]); - }); - // AJAX Routes - $router->group(['prefix' => 'ajax'], function ($server) use ($router) { - $router->post('/new/server/get-nodes', [ 'uses' => 'Admin\AjaxController@postNewServerGetNodes' ]); - $router->post('/new/server/get-ips', [ 'uses' => 'Admin\AjaxController@postNewServerGetIps' ]); - $router->post('/new/server/service-options', [ 'uses' => 'Admin\AjaxController@postNewServerServiceOptions' ]); + $router->post('/new', [ 'uses' => 'Admin\ServersController@postNewServer']); + $router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]); + $router->post('/new/get-ips', [ 'uses' => 'Admin\ServersController@postNewServerGetIps' ]); + $router->post('/new/service-options', [ 'uses' => 'Admin\ServersController@postNewServerServiceOptions' ]); + $router->post('/new/service-variables', [ 'uses' => 'Admin\ServersController@postNewServerServiceVariables' ]); + }); }); diff --git a/database/migrations/2015_12_10_214921_modify_services_images.php b/database/migrations/2015_12_10_214921_modify_services_images.php new file mode 100644 index 000000000..0e2d35d20 --- /dev/null +++ b/database/migrations/2015_12_10_214921_modify_services_images.php @@ -0,0 +1,31 @@ +dropColumn('docker_image'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('services', function (Blueprint $table) { + $table->string('docker_image')->after('description'); + }); + } +} diff --git a/database/migrations/2015_12_10_215116_add_docker_image_to_service_options.php b/database/migrations/2015_12_10_215116_add_docker_image_to_service_options.php new file mode 100644 index 000000000..ca2197987 --- /dev/null +++ b/database/migrations/2015_12_10_215116_add_docker_image_to_service_options.php @@ -0,0 +1,43 @@ +renameColumn('docker_tag', 'docker_image'); + }); + + Schema::table('service_options', function (Blueprint $table) { + $table->text('docker_image')->change(); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + Schema::table('service_options', function (Blueprint $table) { + $table->renameColumn('docker_image', 'docker_tag'); + }); + + Schema::table('service_options', function (Blueprint $table) { + $table->string('docker_tag')->change(); + }); + + } +} diff --git a/database/migrations/2015_12_10_223449_allow_null_regex.php b/database/migrations/2015_12_10_223449_allow_null_regex.php new file mode 100644 index 000000000..fd720d40c --- /dev/null +++ b/database/migrations/2015_12_10_223449_allow_null_regex.php @@ -0,0 +1,29 @@ +string('regex')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::statement('ALTER TABLE `service_variables` MODIFY `regex` VARCHAR(255) NOT NULL'); + } +} diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 18a2bc8e5..0669364b3 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -11,8 +11,16 @@