forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAjaxController.php
More file actions
63 lines (46 loc) · 1.51 KB
/
AjaxController.php
File metadata and controls
63 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Pterodactyl\Http\Controllers\Admin;
use Debugbar;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Node;
use Pterodactyl\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AjaxController extends Controller
{
/**
* Controller Constructor
*/
public function __construct()
{
// All routes in this controller are protected by the authentication middleware.
$this->middleware('auth');
$this->middleware('admin');
}
public function postNewServerGetNodes(Request $request)
{
if(!$request->input('location')) {
return response()->json([
'error' => 'Missing location in request.'
], 500);
}
return response(Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()->toJson());
}
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);
}
}