Skip to content

Commit 59ff1eb

Browse files
committed
Finish front-end server creation page.
1 parent c7b76ae commit 59ff1eb

File tree

7 files changed

+284
-114
lines changed

7 files changed

+284
-114
lines changed

app/Http/Controllers/Admin/AjaxController.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

app/Http/Controllers/Admin/ServersController.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
use Debugbar;
66
use Pterodactyl\Models\Server;
7+
use Pterodactyl\Models\Node;
78
use Pterodactyl\Models\Location;
9+
use Pterodactyl\Models\Allocation;
810
use Pterodactyl\Models\Service;
11+
use Pterodactyl\Models\ServiceOptions;
12+
use Pterodactyl\Models\ServiceVariables;
913

1014
use Pterodactyl\Http\Controllers\Controller;
1115
use Illuminate\Http\Request;
@@ -48,4 +52,95 @@ public function getView(Request $request, $id)
4852
//
4953
}
5054

55+
public function postNewServer(Request $request)
56+
{
57+
return json_encode($request->all());
58+
}
59+
60+
/**
61+
* Returns a JSON tree of all avaliable nodes in a given location.
62+
*
63+
* @param \Illuminate\Http\Request $request
64+
* @return \Illuminate\Contracts\View\View
65+
*/
66+
public function postNewServerGetNodes(Request $request)
67+
{
68+
69+
if(!$request->input('location')) {
70+
return response()->json([
71+
'error' => 'Missing location in request.'
72+
], 500);
73+
}
74+
75+
return response()->json(Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get());
76+
77+
}
78+
79+
/**
80+
* Returns a JSON tree of all avaliable IPs and Ports on a given node.
81+
*
82+
* @param \Illuminate\Http\Request $request
83+
* @return \Illuminate\Contracts\View\View
84+
*/
85+
public function postNewServerGetIps(Request $request)
86+
{
87+
88+
if(!$request->input('node')) {
89+
return response()->json([
90+
'error' => 'Missing node in request.'
91+
], 500);
92+
}
93+
94+
$ips = Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get();
95+
$listing = [];
96+
97+
foreach($ips as &$ip) {
98+
if (array_key_exists($ip->ip, $listing)) {
99+
$listing[$ip->ip] = array_merge($listing[$ip->ip], [$ip->port]);
100+
} else {
101+
$listing[$ip->ip] = [$ip->port];
102+
}
103+
}
104+
return response()->json($listing);
105+
106+
}
107+
108+
/**
109+
* Returns a JSON tree of all avaliable options for a given service.
110+
*
111+
* @param \Illuminate\Http\Request $request
112+
* @return \Illuminate\Contracts\View\View
113+
*/
114+
public function postNewServerServiceOptions(Request $request)
115+
{
116+
117+
if(!$request->input('service')) {
118+
return response()->json([
119+
'error' => 'Missing service in request.'
120+
], 500);
121+
}
122+
123+
return response()->json(ServiceOptions::select('id', 'name', 'docker_image')->where('parent_service', $request->input('service'))->orderBy('name', 'asc')->get());
124+
125+
}
126+
127+
/**
128+
* Returns a JSON tree of all avaliable variables for a given service option.
129+
*
130+
* @param \Illuminate\Http\Request $request
131+
* @return \Illuminate\Contracts\View\View
132+
*/
133+
public function postNewServerServiceVariables(Request $request)
134+
{
135+
136+
if(!$request->input('option')) {
137+
return response()->json([
138+
'error' => 'Missing option in request.'
139+
], 500);
140+
}
141+
142+
return response()->json(ServiceVariables::where('option_id', $request->input('option'))->get());
143+
144+
}
145+
51146
}

app/Http/Routes/AdminRoutes.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ public function map(Router $router) {
1919

2020
// Server Routes
2121
$router->group(['prefix' => 'servers'], function ($server) use ($router) {
22+
2223
$router->get('/', [ 'as' => 'admin.servers', 'uses' => 'Admin\ServersController@getIndex' ]);
2324
$router->get('/new', [ 'as' => 'admin.servers.new', 'uses' => 'Admin\ServersController@getNew' ]);
2425
$router->get('/view/{id}', [ 'as' => 'admin.servers.view', 'uses' => 'Admin\ServersController@getView' ]);
25-
});
2626

27-
// AJAX Routes
28-
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
29-
$router->post('/new/server/get-nodes', [ 'uses' => 'Admin\AjaxController@postNewServerGetNodes' ]);
30-
$router->post('/new/server/get-ips', [ 'uses' => 'Admin\AjaxController@postNewServerGetIps' ]);
31-
$router->post('/new/server/service-options', [ 'uses' => 'Admin\AjaxController@postNewServerServiceOptions' ]);
27+
$router->post('/new', [ 'uses' => 'Admin\ServersController@postNewServer']);
28+
$router->post('/new/get-nodes', [ 'uses' => 'Admin\ServersController@postNewServerGetNodes' ]);
29+
$router->post('/new/get-ips', [ 'uses' => 'Admin\ServersController@postNewServerGetIps' ]);
30+
$router->post('/new/service-options', [ 'uses' => 'Admin\ServersController@postNewServerServiceOptions' ]);
31+
$router->post('/new/service-variables', [ 'uses' => 'Admin\ServersController@postNewServerServiceVariables' ]);
32+
3233
});
3334

3435
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class ModifyServicesImages extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('services', function (Blueprint $table) {
16+
$table->dropColumn('docker_image');
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
Schema::table('services', function (Blueprint $table) {
28+
$table->string('docker_image')->after('description');
29+
});
30+
}
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddDockerImageToServiceOptions extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
16+
Schema::table('service_options', function (Blueprint $table) {
17+
$table->renameColumn('docker_tag', 'docker_image');
18+
});
19+
20+
Schema::table('service_options', function (Blueprint $table) {
21+
$table->text('docker_image')->change();
22+
});
23+
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*
29+
* @return void
30+
*/
31+
public function down()
32+
{
33+
34+
Schema::table('service_options', function (Blueprint $table) {
35+
$table->renameColumn('docker_image', 'docker_tag');
36+
});
37+
38+
Schema::table('service_options', function (Blueprint $table) {
39+
$table->string('docker_tag')->change();
40+
});
41+
42+
}
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AllowNullRegex extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('service_variables', function (Blueprint $table) {
16+
$table->string('regex')->nullable()->change();
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
DB::statement('ALTER TABLE `service_variables` MODIFY `regex` VARCHAR(255) NOT NULL');
28+
}
29+
}

0 commit comments

Comments
 (0)