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 ( 4f127b...a52d9e )
by Dane
02:59
created

AjaxController::getStatus()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.439
c 0
b 0
f 0
cc 6
eloc 14
nc 8
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\Server;
26
27
use Log;
28
use Pterodactyl\Models;
29
use Illuminate\Http\Request;
30
use Pterodactyl\Repositories;
31
use GuzzleHttp\Exception\RequestException;
32
use Pterodactyl\Exceptions\DisplayException;
33
use Pterodactyl\Http\Controllers\Controller;
34
use Pterodactyl\Exceptions\DisplayValidationException;
35
36
class AjaxController extends Controller
37
{
38
    /**
39
     * @var array
40
     */
41
    protected $files = [];
42
43
    /**
44
     * @var array
45
     */
46
    protected $folders = [];
47
48
    /**
49
     * @var string
50
     */
51
    protected $directory;
52
53
    /**
54
     * Returns a listing of files in a given directory for a server.
55
     *
56
     * @param  \Illuminate\Http\Request  $request
57
     * @param  string                    $uuid
58
     * @return \Illuminate\View\View|\Illuminate\Http\Response
59
     */
60
    public function postDirectoryList(Request $request, $uuid)
61
    {
62
        $server = Models\Server::byUuid($uuid);
63
        $this->authorize('list-files', $server);
64
65
        $this->directory = '/' . trim(urldecode($request->input('directory', '/')), '/');
66
        $prevDir = [
67
            'header' => ($this->directory !== '/') ? $this->directory : '',
68
        ];
69
        if ($this->directory !== '/') {
70
            $prevDir['first'] = true;
71
        }
72
73
        // Determine if we should show back links in the file browser.
74
        // This code is strange, and could probably be rewritten much better.
75
        $goBack = explode('/', trim($this->directory, '/'));
76
        if (! empty(array_filter($goBack)) && count($goBack) >= 2) {
77
            $prevDir['show'] = true;
78
            array_pop($goBack);
79
            $prevDir['link'] = '/' . implode('/', $goBack);
80
            $prevDir['link_show'] = implode('/', $goBack) . '/';
81
        }
82
83
        $controller = new Repositories\Daemon\FileRepository($uuid);
84
85
        try {
86
            $directoryContents = $controller->returnDirectoryListing($this->directory);
87
        } catch (DisplayException $ex) {
88
            return response($ex->getMessage(), 500);
89
        } catch (\Exception $ex) {
90
            Log::error($ex);
91
92
            return response('An error occured while attempting to load the requested directory, please try again.', 500);
93
        }
94
95
        return view('server.files.list', [
96
            'server' => $server,
97
            'files' => $directoryContents->files,
98
            'folders' => $directoryContents->folders,
99
            'editableMime' => Repositories\HelperRepository::editableFiles(),
100
            'directory' => $prevDir,
101
        ]);
102
    }
103
104
    /**
105
     * Handles a POST request to save a file.
106
     *
107
     * @param  \Illuminate\Http\Request  $request
108
     * @param  string                    $uuid
109
     * @return \Illuminate\Http\Response
110
     */
111
    public function postSaveFile(Request $request, $uuid)
112
    {
113
        $server = Models\Server::byUuid($uuid);
114
        $this->authorize('save-files', $server);
115
116
        $controller = new Repositories\Daemon\FileRepository($uuid);
117
118
        try {
119
            $controller->saveFileContents($request->input('file'), $request->input('contents'));
0 ignored issues
show
Bug introduced by
It seems like $request->input('file') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Pterodactyl\Repositories...ory::saveFileContents() does only seem to accept string, 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...
Bug introduced by
It seems like $request->input('contents') targeting Illuminate\Http\Concerns...ractsWithInput::input() can also be of type array; however, Pterodactyl\Repositories...ory::saveFileContents() does only seem to accept string, 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...
120
121
            return response(null, 204);
122
        } catch (DisplayException $ex) {
123
            return response($ex->getMessage(), 500);
124
        } catch (\Exception $ex) {
125
            Log::error($ex);
126
127
            return response('An error occured while attempting to save this file, please try again.', 500);
128
        }
129
    }
130
131
    /**
132
     * Sets the primary allocation for a server.
133
     *
134
     * @param  \Illuminate\Http\Request  $request
135
     * @param  string                    $uuid
136
     * @return \Illuminate\Http\JsonResponse
137
     * @deprecated
138
     */
139
    public function postSetPrimary(Request $request, $uuid)
140
    {
141
        $server = Models\Server::byUuid($uuid)->load('allocations');
142
        $this->authorize('set-connection', $server);
143
144
        if ((int) $request->input('allocation') === $server->allocation_id) {
145
            return response()->json([
146
                'error' => 'You are already using this as your default connection.',
147
            ], 409);
148
        }
149
150
        try {
151
            $allocation = $server->allocations->where('id', $request->input('allocation'))->where('server_id', $server->id)->first();
152
            if (! $allocation) {
153
                return response()->json([
154
                    'error' => 'No allocation matching your request was found in the system.',
155
                ], 422);
156
            }
157
158
            $repo = new Repositories\ServerRepository;
159
            $repo->changeBuild($server->id, [
160
                'default' => $allocation->ip . ':' . $allocation->port,
161
            ]);
162
163
            return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.');
164
        } catch (DisplayValidationException $ex) {
165
            return response()->json([
166
                'error' => json_decode($ex->getMessage(), true),
167
            ], 422);
168
        } catch (DisplayException $ex) {
169
            return response()->json([
170
                'error' => $ex->getMessage(),
171
            ], 503);
172
        } catch (\Exception $ex) {
173
            Log::error($ex);
174
175
            return response()->json([
176
                'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.',
177
            ], 503);
178
        }
179
    }
180
181
    /**
182
     * Resets a database password for a server.
183
     *
184
     * @param  \Illuminate\Http\Request  $request
185
     * @param  string                    $uuid
186
     * @return \Illuminate\Http\JsonResponse
187
     * @deprecated
188
     */
189
    public function postResetDatabasePassword(Request $request, $uuid)
190
    {
191
        $server = Models\Server::byUuid($uuid);
192
        $this->authorize('reset-db-password', $server);
193
194
        $database = Models\Database::where('server_id', $server->id)->findOrFail($request->input('database'));
195
        $repo = new Repositories\DatabaseRepository;
196
197
        try {
198
            $password = str_random(20);
199
            $repo->password($database->id, $password);
200
201
            return response($password);
202
        } catch (DisplayException $ex) {
203
            return response()->json(['error' => $ex->getMessage()], 503);
204
        } catch (\Exception $ex) {
205
            Log::error($ex);
206
207
            return response()->json([
208
                'error' => 'An unhandled error occured while attempting to modify this database\'s password.',
209
            ], 503);
210
        }
211
    }
212
}
213