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
Pull Request — develop (#286)
by Dane
08:45 queued 05:44
created

ServerController::info()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 48
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 9.125
c 0
b 0
f 0
cc 3
eloc 34
nc 6
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\API\User;
26
27
use Log;
28
use Pterodactyl\Models;
29
use Illuminate\Http\Request;
30
use Pterodactyl\Http\Controllers\API\BaseController;
31
32
class ServerController extends BaseController
33
{
34
    public function info(Request $request, $uuid)
35
    {
36
        $server = Models\Server::byUuid($uuid)->load('allocations');
37
38
        try {
39
            $response = $server->guzzleClient()->request('GET', '/server');
40
41
            $json = json_decode($response->getBody());
42
            $daemon = [
43
                'status' => $json->status,
44
                'stats' => $json->proc,
45
            ];
46
        } catch (\Exception $ex) {
47
            $daemon = [
48
                'error' => 'An error was encountered while trying to connect to the daemon to collect information. It might be offline.',
49
            ];
50
            Log::error($ex);
51
        }
52
53
        return [
54
            'uuidShort' => $server->uuidShort,
0 ignored issues
show
Bug introduced by
The property uuidShort does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
55
            'uuid' => $server->uuid,
0 ignored issues
show
Bug introduced by
The property uuid does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
56
            'name' => $server->name,
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
57
            'node' => $server->node->name,
0 ignored issues
show
Bug introduced by
The property node does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
58
            'limits' => [
59
                'memory' => $server->memory,
0 ignored issues
show
Bug introduced by
The property memory does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
60
                'swap' => $server->swap,
0 ignored issues
show
Bug introduced by
The property swap does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
61
                'disk' => $server->disk,
0 ignored issues
show
Bug introduced by
The property disk does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
62
                'io' => $server->io,
0 ignored issues
show
Bug introduced by
The property io does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
63
                'cpu' => $server->cpu,
0 ignored issues
show
Bug introduced by
The property cpu does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
64
                'oom_disabled' => (bool) $server->oom_disabled,
0 ignored issues
show
Bug introduced by
The property oom_disabled does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
65
            ],
66
            'allocations' => $server->allocations->map(function ($item) use ($server) {
0 ignored issues
show
Bug introduced by
The property allocations does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
67
                return [
68
                    'ip' => $item->alias,
69
                    'port' => $item->port,
70
                    'default' => ($item->id === $server->allocation_id),
71
                ];
72
            }),
73
            'sftp' => [
74
                'username' => ($request->user()->can('view-sftp', $server)) ? $server->username : null,
0 ignored issues
show
Bug introduced by
The property username does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
75
            ],
76
            'daemon' => [
77
                'token' => $server->daemonSecret,
0 ignored issues
show
Bug introduced by
The property daemonSecret does not seem to exist in Illuminate\Database\Eloquent\Collection.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
78
                'response' => $daemon,
79
            ],
80
        ];
81
    }
82
83
    public function power(Request $request, $uuid)
84
    {
85
        $server = Models\Server::byUuid($uuid);
86
        Auth::user()->can('power-' . $request->input('action'), $server);
87
88
        $res = $server->guzzleClient()->request('PUT', '/server/power', [
89
            'exceptions' => false,
90
            'json' => [
91
                'action' => $request->input('action'),
92
            ],
93
        ]);
94
95
        if ($res->getStatusCode() !== 204) {
96
            return $this->response->error(json_decode($res->getBody())->error, $res->getStatusCode());
97
        }
98
99
        return $this->response->noContent();
100
    }
101
}
102