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 ( d7e524...2330c2 )
by Dane
02:52
created

ActionController::configuration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 9.2
cc 3
eloc 10
nc 3
nop 2
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 Illuminate\Http\Request;
28
use Pterodactyl\Models\Server;
29
use Pterodactyl\Models\Download;
30
use Pterodactyl\Http\Controllers\Controller;
31
use Pterodactyl\Models\NodeConfigurationToken;
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 = Download::where('token', $request->input('token'))->first();
44
        if (! $download) {
45
            return response()->json([
46
                'error' => 'An invalid request token was recieved with this request.',
47
            ], 403);
48
        }
49
50
        $download->delete();
51
52
        return response()->json([
53
            'path' => $download->path,
54
            'server' => $download->server,
55
        ]);
56
    }
57
58
    /**
59
     * Handles install toggle request from daemon.
60
     *
61
     * @param  \Illuminate\Http\Request  $request
62
     * @return \Illuminate\Http\JsonResponse
63
     */
64
    public function markInstall(Request $request)
65
    {
66
        $server = Server::where('uuid', $request->input('server'))->with('node')->first();
67
        if (! $server) {
68
            return response()->json([
69
                'error' => 'No server by that ID was found on the system.',
70
            ], 422);
71
        }
72
73
        $hmac = $request->input('signed');
74
        $status = $request->input('installed');
75
76
        if (! hash_equals(base64_decode($hmac), hash_hmac('sha256', $server->uuid, $server->node->daemonSecret, true))) {
77
            return response()->json([
78
                'error' => 'Signed HMAC was invalid.',
79
            ], 403);
80
        }
81
82
        $server->installed = ($status === 'installed') ? 1 : 2;
83
        $server->save();
84
85
        return response('', 204);
86
    }
87
88
    /**
89
     * Handles configuration data request from daemon.
90
     *
91
     * @param  \Illuminate\Http\Request  $request
92
     * @param  string                    $token
93
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
94
     */
95
    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...
96
    {
97
        // Try to query the token and the node from the database
98
        try {
99
            $model = NodeConfigurationToken::with('node')->where('token', $token)->firstOrFail();
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
100
        } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
101
            return response()->json(['error' => 'token_invalid'], 403);
102
        }
103
104
        // Check if token is expired
105
        if ($model->created_at->addMinutes(5)->lt(Carbon::now())) {
106
            $model->delete();
107
108
            return response()->json(['error' => 'token_expired'], 403);
109
        }
110
111
        // Delete the token, it's one-time use
112
        $model->delete();
113
114
        // Manually as getConfigurationAsJson() returns it in correct format already
115
        return response($model->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...
116
    }
117
}
118