Skip to content

Commit 6e0c5d1

Browse files
committed
Allow updating settings and show configuration for node
1 parent 69b5416 commit 6e0c5d1

File tree

5 files changed

+601
-42
lines changed

5 files changed

+601
-42
lines changed

app/Http/Controllers/Admin/NodesController.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,36 @@ public function getView(Request $request, $id)
7272
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
7373
->join('users', 'users.id', '=', 'servers.owner')
7474
->join('services', 'services.id', '=', 'servers.service')
75-
->where('node', $id)->paginate(10)
75+
->where('node', $id)->paginate(10),
76+
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
77+
'locations' => Models\Location::all(),
7678
]);
7779
}
7880

81+
public function postView(Request $request, $id)
82+
{
83+
try {
84+
$node = new NodeRepository;
85+
$node->update($id, $request->except([
86+
'_token'
87+
]));
88+
Alert::success('Successfully update this node\'s information. If you changed any daemon settings you will need to restart it now.')->flash();
89+
return redirect()->route('admin.nodes.view', [
90+
'id' => $id,
91+
'tab' => 'tab_settings'
92+
]);
93+
} catch (\Pterodactyl\Exceptions\DisplayValidationException $e) {
94+
return redirect()->route('admin.nodes.view', $id)->withErrors(json_decode($e->getMessage()))->withInput();
95+
} catch (\Pterodactyl\Exceptions\DisplayException $e) {
96+
Alert::danger($e->getMessage())->flash();
97+
} catch (\Exception $e) {
98+
Log::error($e);
99+
Alert::danger('An unhandled exception occured while attempting to edit this node. Please try again.')->flash();
100+
}
101+
return redirect()->route('admin.nodes.view', [
102+
'id' => $id,
103+
'tab' => 'tab_settings'
104+
])->withInput();
105+
}
106+
79107
}

app/Http/Routes/AdminRoutes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ public function map(Router $router) {
168168
'uses' => 'Admin\NodesController@getView'
169169
]);
170170

171+
$router->post('/view/{id}', [
172+
'uses' => 'Admin\NodesController@postView'
173+
]);
174+
171175
});
172176

173177
}

app/Repositories/NodeRepository.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function create(array $data)
3232
'disk_overallocate' => 'required|numeric|min:-1',
3333
'daemonBase' => 'required|regex:/^([\/][\d\w.\-\/]+)$/',
3434
'daemonSFTP' => 'required|numeric|between:1,65535',
35-
'daemonListen' => 'required|numeric|between:1,65535'
35+
'daemonListen' => 'required|numeric|between:1,65535',
3636
]);
3737

3838
// Run validator, throw catchable and displayable exception if it fails.
@@ -42,6 +42,9 @@ public function create(array $data)
4242
}
4343

4444
// Verify the FQDN
45+
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
46+
throw new DisplayException('The FQDN provided was an IP address. You must use a FQDN.');
47+
}
4548
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
4649
throw new DisplayException('The FQDN provided does not resolve to a valid IP address.');
4750
}
@@ -63,4 +66,61 @@ public function create(array $data)
6366

6467
}
6568

69+
public function update($id, array $data)
70+
{
71+
// Validate Fields
72+
$validator = $validator = Validator::make($data, [
73+
'name' => 'regex:/^([\w .-]{1,100})$/',
74+
'location' => 'numeric|min:1|exists:locations,id',
75+
'public' => 'numeric|between:0,1',
76+
'fqdn' => 'string|unique:nodes,fqdn,' . $id,
77+
'scheme' => 'regex:/^(http(s)?)$/',
78+
'memory' => 'numeric|min:1',
79+
'memory_overallocate' => 'numeric|min:-1',
80+
'disk' => 'numeric|min:1',
81+
'disk_overallocate' => 'numeric|min:-1',
82+
'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/',
83+
'daemonSFTP' => 'numeric|between:1,65535',
84+
'daemonListen' => 'numeric|between:1,65535',
85+
'reset_secret' => 'sometimes|accepted',
86+
]);
87+
88+
// Run validator, throw catchable and displayable exception if it fails.
89+
// Exception includes a JSON result of failed validation rules.
90+
if ($validator->fails()) {
91+
throw new DisplayValidationException($validator->errors());
92+
}
93+
94+
// Verify the FQDN
95+
if (isset($data['fqdn'])) {
96+
if (filter_var($data['fqdn'], FILTER_VALIDATE_IP)) {
97+
throw new DisplayException('The FQDN provided was an IP address. You must use a FQDN.');
98+
}
99+
if (!filter_var(gethostbyname($data['fqdn']), FILTER_VALIDATE_IP)) {
100+
throw new DisplayException('The FQDN provided does not resolve to a valid IP address.');
101+
}
102+
}
103+
104+
// Should we be nulling the overallocations?
105+
if (isset($data['memory_overallocate'])) {
106+
$data['memory_overallocate'] = ($data['memory_overallocate'] < 0) ? null : $data['memory_overallocate'];
107+
}
108+
109+
if (isset($data['disk_overallocate'])) {
110+
$data['disk_overallocate'] = ($data['disk_overallocate'] < 0) ? null : $data['disk_overallocate'];
111+
}
112+
113+
// Set the Secret
114+
if (isset($data['reset_secret'])) {
115+
$uuid = new UuidService;
116+
$data['daemonSecret'] = (string) $uuid->generate('nodes', 'daemonSecret');
117+
unset($data['reset_secret']);
118+
}
119+
120+
// Store the Data
121+
$node = Models\Node::findOrFail($id);
122+
return $node->update($data);
123+
124+
}
125+
66126
}

public/css/pterodactyl.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ form .text-muted {margin: 0 0 -5.5px}
7777
.tab-pane.active .panel.panel-default {border-top:0 !important}
7878
.tabs_with_panel > li.active > a {background-color: #f5f5f5 !important}
7979
.tabs_with_panel > li > a {background: transparent;}
80+
.label{border-radius: .25em;padding: .2em .6em .3em;}
81+
kbd{border-radius: .25em}

0 commit comments

Comments
 (0)