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.

AjaxController::postResetDatabasePassword()   A
last analyzed

Complexity

Conditions 3
Paths 7

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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