Skip to content

Commit d4bcf0b

Browse files
committed
Initial implementation of improved sever model and logic
1 parent fb589a7 commit d4bcf0b

31 files changed

+223
-158
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
2121
* User model now defines mass assignment fields using `$fillable` rather than `$guarded`.
2222
* 2FA checkpoint on login is now its own page, and not an AJAX based call. Improves security on that front.
2323

24+
### Removed
25+
* `Server::getUserDaemonSecret(Server $server)` was removed and replaced with `User::daemonSecret(Server $server)` in order to clean up models.
26+
2427
## v0.5.6 (Bodacious Boreopterus)
2528
### Added
2629
* Added the following languages: Estonian `et`, Dutch `nl`, Norwegian `nb` (partial), Romanian `ro`, and Russian `ru`. Interested in helping us translate the panel into more languages, or improving existing translations? Contact us on Discord and let us know.

app/Http/Controllers/API/ServerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function view(Request $request, $id)
122122
'pack'
123123
)->first();
124124
if ($request->input('daemon') === 'true') {
125-
$node = Models\Node::findOrFail($server->node);
125+
$node = Models\Node::findOrFail($server->node_id);
126126
$client = Models\Node::guzzleRequest($node->id);
127127

128128
$response = $client->request('GET', '/servers', [

app/Http/Controllers/API/User/InfoController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function me(Request $request)
3737
'id' => $server->uuidShort,
3838
'uuid' => $server->uuid,
3939
'name' => $server->name,
40-
'node' => $server->nodeName,
40+
'node' => $server->node_idName,
4141
'ip' => [
4242
'set' => $server->ip,
4343
'alias' => $server->ip_alias,

app/Http/Controllers/API/User/ServerController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ServerController extends BaseController
3535
public function info(Request $request, $uuid)
3636
{
3737
$server = Models\Server::getByUUID($uuid);
38-
$node = Models\Node::findOrFail($server->node);
38+
$node = Models\Node::findOrFail($server->node_id);
3939
$client = Models\Node::guzzleRequest($node->id);
4040

4141
try {
@@ -61,7 +61,7 @@ public function info(Request $request, $uuid)
6161

6262
$allocations = Models\Allocation::select('id', 'ip', 'port', 'ip_alias as alias')->where('assigned_to', $server->id)->get();
6363
foreach ($allocations as &$allocation) {
64-
$allocation->default = ($allocation->id === $server->allocation);
64+
$allocation->default = ($allocation->id === $server->allocation_id);
6565
unset($allocation->id);
6666
}
6767

@@ -92,7 +92,7 @@ public function info(Request $request, $uuid)
9292
public function power(Request $request, $uuid)
9393
{
9494
$server = Models\Server::getByUUID($uuid);
95-
$client = Models\Node::guzzleRequest($server->node);
95+
$client = Models\Node::guzzleRequest($server->node_id);
9696

9797
Auth::user()->can('power-' . $request->input('action'), $server);
9898

app/Http/Controllers/Admin/NodesController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public function getView(Request $request, $id)
108108
return view('admin.nodes.view', [
109109
'node' => $node,
110110
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
111-
->join('users', 'users.id', '=', 'servers.owner')
112-
->join('services', 'services.id', '=', 'servers.service')
111+
->join('users', 'users.id', '=', 'servers.owner_id')
112+
->join('services', 'services.id', '=', 'servers.service_id')
113113
->where('node', $id)->paginate(10, ['*'], 'servers'),
114114
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
115115
'locations' => Models\Location::all(),

app/Http/Controllers/Admin/ServersController.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function getIndex(Request $request)
5454
'allocations.ip',
5555
'allocations.port',
5656
'allocations.ip_alias'
57-
)->join('nodes', 'servers.node', '=', 'nodes.id')
58-
->join('users', 'servers.owner', '=', 'users.id')
59-
->join('allocations', 'servers.allocation', '=', 'allocations.id');
57+
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
58+
->join('users', 'servers.owner_id', '=', 'users.id')
59+
->join('allocations', 'servers.allocation_id', '=', 'allocations.id');
6060

6161
if ($request->input('filter') && ! is_null($request->input('filter'))) {
6262
preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches);
@@ -96,9 +96,9 @@ public function getIndex(Request $request)
9696
'allocations.ip',
9797
'allocations.port',
9898
'allocations.ip_alias'
99-
)->join('nodes', 'servers.node', '=', 'nodes.id')
100-
->join('users', 'servers.owner', '=', 'users.id')
101-
->join('allocations', 'servers.allocation', '=', 'allocations.id')
99+
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
100+
->join('users', 'servers.owner_id', '=', 'users.id')
101+
->join('allocations', 'servers.allocation_id', '=', 'allocations.id')
102102
->paginate(20);
103103
}
104104

@@ -127,11 +127,11 @@ public function getView(Request $request, $id)
127127
'allocations.ip',
128128
'allocations.port',
129129
'allocations.ip_alias'
130-
)->join('nodes', 'servers.node', '=', 'nodes.id')
131-
->join('users', 'servers.owner', '=', 'users.id')
132-
->join('services', 'servers.service', '=', 'services.id')
133-
->join('service_options', 'servers.option', '=', 'service_options.id')
134-
->join('allocations', 'servers.allocation', '=', 'allocations.id')
130+
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
131+
->join('users', 'servers.owner_id', '=', 'users.id')
132+
->join('services', 'servers.service_id', '=', 'services.id')
133+
->join('service_options', 'servers.option_id', '=', 'service_options.id')
134+
->join('allocations', 'servers.allocation_id', '=', 'allocations.id')
135135
->where('servers.id', $id)
136136
->first();
137137

@@ -145,13 +145,13 @@ public function getView(Request $request, $id)
145145
'nodes.*',
146146
'locations.long as a_locationName'
147147
)->join('locations', 'nodes.location', '=', 'locations.id')
148-
->where('nodes.id', $server->node)
148+
->where('nodes.id', $server->node_id)
149149
->first(),
150150
'assigned' => Models\Allocation::where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
151-
'unassigned' => Models\Allocation::where('node', $server->node)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
151+
'unassigned' => Models\Allocation::where('node', $server->node_id)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
152152
'startup' => Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue')
153153
->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
154-
->where('service_variables.option_id', $server->option)
154+
->where('service_variables.option_id', $server->option_id)
155155
->where('server_variables.server_id', $server->id)
156156
->get(),
157157
'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
@@ -334,8 +334,8 @@ public function postUpdateContainerDetails(Request $request, $id)
334334
public function postUpdateServerToggleBuild(Request $request, $id)
335335
{
336336
$server = Models\Server::findOrFail($id);
337-
$node = Models\Node::findOrFail($server->node);
338-
$client = Models\Node::guzzleRequest($server->node);
337+
$node = Models\Node::findOrFail($server->node_id);
338+
$client = Models\Node::guzzleRequest($server->node_id);
339339

340340
try {
341341
$res = $client->request('POST', '/server/rebuild', [

app/Http/Controllers/Admin/ServiceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getOption(Request $request, $service, $option)
137137
'option' => $opt,
138138
'variables' => Models\ServiceVariables::where('option_id', $option)->get(),
139139
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail')
140-
->join('users', 'users.id', '=', 'servers.owner')
140+
->join('users', 'users.id', '=', 'servers.owner_id')
141141
->where('option', $option)
142142
->paginate(10),
143143
]);

app/Http/Controllers/Admin/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getView(Request $request, $id)
8787
return view('admin.users.view', [
8888
'user' => User::findOrFail($id),
8989
'servers' => Server::select('servers.*', 'nodes.name as nodeName', 'locations.long as location')
90-
->join('nodes', 'servers.node', '=', 'nodes.id')
90+
->join('nodes', 'servers.node_id', '=', 'nodes.id')
9191
->join('locations', 'nodes.location', '=', 'locations.id')
9292
->where('owner', $id)
9393
->get(),

app/Http/Controllers/Remote/RemoteController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function postInstall(Request $request)
6666
], 422);
6767
}
6868

69-
$node = Models\Node::findOrFail($server->node);
69+
$node = Models\Node::findOrFail($server->node_id);
7070
$hmac = $request->input('signed');
7171
$status = $request->input('installed');
7272

@@ -93,7 +93,7 @@ public function event(Request $request)
9393
], 422);
9494
}
9595

96-
$node = Models\Node::findOrFail($server->node);
96+
$node = Models\Node::findOrFail($server->node_id);
9797

9898
$hmac = $request->input('signed');
9999
if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $node->daemonSecret, true)) {

app/Http/Controllers/Server/AjaxController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getStatus(Request $request, $uuid)
7373
return response()->json([], 404);
7474
}
7575

76-
$client = Models\Node::guzzleRequest($server->node);
76+
$client = Models\Node::guzzleRequest($server->node_id);
7777

7878
try {
7979
$res = $client->request('GET', '/server', [
@@ -178,7 +178,7 @@ public function postSetPrimary(Request $request, $uuid)
178178
$server = Models\Server::getByUUID($uuid);
179179
$this->authorize('set-connection', $server);
180180

181-
if ((int) $request->input('allocation') === $server->allocation) {
181+
if ((int) $request->input('allocation') === $server->allocation_id) {
182182
return response()->json([
183183
'error' => 'You are already using this as your default connection.',
184184
], 409);

0 commit comments

Comments
 (0)