forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionController.php
More file actions
84 lines (71 loc) · 2.5 KB
/
ActionController.php
File metadata and controls
84 lines (71 loc) · 2.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Pterodactyl\Http\Controllers\Daemon;
use Cache;
use Illuminate\Http\Request;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
use Pterodactyl\Http\Controllers\Controller;
class ActionController extends Controller
{
/**
* Handles download request from daemon.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function authenticateDownload(Request $request)
{
$download = Cache::pull('Server:Downloads:' . $request->input('token'));
if (is_null($download)) {
return response()->json([
'error' => 'An invalid request token was recieved with this request.',
], 403);
}
return response()->json([
'path' => $download['path'],
'server' => $download['server'],
]);
}
/**
* Handles install toggle request from daemon.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function markInstall(Request $request)
{
$server = Server::where('uuid', $request->input('server'))->with('node')->first();
if (! $server) {
return response()->json([
'error' => 'No server by that ID was found on the system.',
], 422);
}
$hmac = $request->input('signed');
$status = $request->input('installed');
if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) {
return response()->json([
'error' => 'Signed HMAC was invalid.',
], 403);
}
$server->installed = ($status === 'installed') ? 1 : 2;
$server->save();
return response()->json([]);
}
/**
* Handles configuration data request from daemon.
*
* @param \Illuminate\Http\Request $request
* @param string $token
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function configuration(Request $request, $token)
{
$nodeId = Cache::pull('Node:Configuration:' . $token);
if (is_null($nodeId)) {
return response()->json(['error' => 'token_invalid'], 403);
}
$node = Node::findOrFail($nodeId);
// Manually as getConfigurationAsJson() returns it in correct format already
return response($node->getConfigurationAsJson())->header('Content-Type', 'text/json');
}
}