GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ActionController::authenticateDownload()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2017 Dane Everitt <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace Pterodactyl\Http\Controllers\Daemon;
26
27
use Cache;
28
use Illuminate\Http\Request;
29
use Pterodactyl\Models\Node;
30
use Pterodactyl\Models\Server;
31
use Pterodactyl\Http\Controllers\Controller;
32
33
class ActionController extends Controller
34
{
35
    /**
36
     * Handles download request from daemon.
37
     *
38
     * @param  \Illuminate\Http\Request  $request
39
     * @return \Illuminate\Http\JsonResponse
40
     */
41
    public function authenticateDownload(Request $request)
42
    {
43
        $download = Cache::tags(['Server:Downloads'])->pull($request->input('token'));
44
45
        if (is_null($download)) {
46
            return response()->json([
47
                'error' => 'An invalid request token was recieved with this request.',
48
            ], 403);
49
        }
50
51
        return response()->json([
52
            'path' => $download['path'],
53
            'server' => $download['server'],
54
        ]);
55
    }
56
57
    /**
58
     * Handles install toggle request from daemon.
59
     *
60
     * @param  \Illuminate\Http\Request  $request
61
     * @return \Illuminate\Http\JsonResponse
62
     */
63
    public function markInstall(Request $request)
64
    {
65
        $server = Server::where('uuid', $request->input('server'))->with('node')->first();
66
        if (! $server) {
67
            return response()->json([
68
                'error' => 'No server by that ID was found on the system.',
69
            ], 422);
70
        }
71
72
        $hmac = $request->input('signed');
73
        $status = $request->input('installed');
74
75
        if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) {
76
            return response()->json([
77
                'error' => 'Signed HMAC was invalid.',
78
            ], 403);
79
        }
80
81
        $server->installed = ($status === 'installed') ? 1 : 2;
82
        $server->save();
83
84
        return response()->json([]);
85
    }
86
87
    /**
88
     * Handles configuration data request from daemon.
89
     *
90
     * @param  \Illuminate\Http\Request  $request
91
     * @param  string                    $token
92
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
93
     */
94
    public function configuration(Request $request, $token)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        $nodeId = Cache::tags(['Node:Configuration'])->pull($token);
97
        if (is_null($nodeId)) {
98
            return response()->json(['error' => 'token_invalid'], 403);
99
        }
100
101
        $node = Node::findOrFail($nodeId);
102
103
        // Manually as getConfigurationAsJson() returns it in correct format already
104
        return response($node->getConfigurationAsJson())->header('Content-Type', 'text/json');
0 ignored issues
show
Bug introduced by
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
105
    }
106
}
107