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.
Completed
Push — develop ( 2dbaca...c09170 )
by Dane
12s
created

RemoteController::getConfiguration()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 1
b 1
f 0
cc 3
eloc 12
nc 4
nop 2
1
<?php
2
/**
3
 * Pterodactyl - Panel
4
 * Copyright (c) 2015 - 2016 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\Remote;
26
27
use Carbon\Carbon;
28
use Pterodactyl\Models;
29
use Illuminate\Http\Request;
30
use Pterodactyl\Http\Controllers\Controller;
31
use Pterodactyl\Services\NotificationService;
32
33
class RemoteController extends Controller
34
{
35
    /**
36
     * Controller Constructor.
37
     */
38
    public function __construct()
39
    {
40
        // No middleware for this route.
41
    }
42
43
    public function postDownload(Request $request)
44
    {
45
        $download = Models\Download::where('token', $request->input('token', '00'))->first();
46
        if (! $download) {
47
            return response()->json([
48
                'error' => 'An invalid request token was recieved with this request.',
49
            ], 403);
50
        }
51
52
        $download->delete();
53
54
        return response()->json([
55
            'path' => $download->path,
56
            'server' => $download->server,
57
        ]);
58
    }
59
60
    public function postInstall(Request $request)
61
    {
62
        $server = Models\Server::where('uuid', $request->input('server'))->first();
63
        if (! $server) {
64
            return response()->json([
65
                'error' => 'No server by that ID was found on the system.',
66
            ], 422);
67
        }
68
69
        $node = Models\Node::findOrFail($server->node);
70
        $hmac = $request->input('signed');
71
        $status = $request->input('installed');
72
73 View Code Duplication
        if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $node->daemonSecret, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
            return response()->json([
75
                'error' => 'Signed HMAC was invalid.',
76
            ], 403);
77
        }
78
79
        $server->installed = ($status === 'installed') ? 1 : 2;
80
        $server->save();
81
82
        return response()->json([
83
            'message' => 'Recieved!',
84
        ], 200);
85
    }
86
87
    public function event(Request $request)
88
    {
89
        $server = Models\Server::where('uuid', $request->input('server'))->first();
90
        if (! $server) {
91
            return response()->json([
92
                'error' => 'No server by that ID was found on the system.',
93
            ], 422);
94
        }
95
96
        $node = Models\Node::findOrFail($server->node);
97
98
        $hmac = $request->input('signed');
99 View Code Duplication
        if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $node->daemonSecret, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
            return response()->json([
101
                'error' => 'Signed HMAC was invalid.',
102
            ], 403);
103
        }
104
105
        // Passes Validation, Setup Notifications
106
        $notify = new NotificationService($server);
107
        $notify->pass($request->input('notification'));
0 ignored issues
show
Bug introduced by
It seems like $request->input('notification') targeting Illuminate\Http\Request::input() can also be of type string; however, Pterodactyl\Services\NotificationService::pass() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
108
109
        return response('', 201);
110
    }
111
112
    public function getConfiguration(Request $request, $tokenString)
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...
113
    {
114
        // Try to query the token and the node from the database
115
        try {
116
            $token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail();
117
            $node = Models\Node::findOrFail($token->node);
118
        } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
119
            return response()->json(['error' => 'token_invalid'], 403);
120
        }
121
122
        // Check if token is expired
123
        if ($token->expires_at->lt(Carbon::now())) {
124
            $token->delete();
125
126
            return response()->json(['error' => 'token_expired'], 403);
127
        }
128
129
        // Delete the token, it's one-time use
130
        $token->delete();
131
132
        // Manually as getConfigurationAsJson() returns it in correct format already
133
        return response($node->getConfigurationAsJson(), 200)
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...
134
            ->header('Content-Type', 'application/json');
135
    }
136
}
137