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 (#259)
by Dane
08:47
created

ServerController   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 320
Duplicated Lines 27.81 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
wmc 23
lcom 1
cbo 12
dl 89
loc 320
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIndex() 0 19 1
B getFiles() 0 30 1
A getAddFile() 17 17 2
B getEditFile() 0 37 4
A getDownloadFile() 0 17 1
A getAllocation() 17 17 1
A getStartup() 0 47 3
A getDatabases() 20 20 1
A getSFTP() 16 16 1
A postSettingsSFTP() 19 20 4
A postSettingsStartup() 0 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Server;
26
27
use DB;
28
use Log;
29
use Uuid;
30
use Alert;
31
use Javascript;
32
use Pterodactyl\Models;
33
use Illuminate\Http\Request;
34
use Pterodactyl\Exceptions\DisplayException;
35
use Pterodactyl\Http\Controllers\Controller;
36
use Pterodactyl\Repositories\ServerRepository;
37
use Pterodactyl\Repositories\Daemon\FileRepository;
38
use Pterodactyl\Exceptions\DisplayValidationException;
39
40
class ServerController extends Controller
41
{
42
    /**
43
     * Controller Constructor.
44
     *
45
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
46
     */
47
    public function __construct()
48
    {
49
        //
50
    }
51
52
    /**
53
     * Renders server index page for specified server.
54
     *
55
     * @param  \Illuminate\Http\Request $request
56
     * @return \Illuminate\Contracts\View\View
57
     */
58
    public function getIndex(Request $request)
59
    {
60
        $server = Models\Server::getByUUID($request->route()->server);
61
        $node = Models\Node::find($server->node);
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...
62
63
        Javascript::put([
64
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'daemonSecret', 'username']),
65
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
66
            'meta' => [
67
                'saveFile' => route('server.files.save', $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...
68
                'csrfToken' => csrf_token(),
69
            ],
70
        ]);
71
72
        return view('server.index', [
73
            'server' => $server,
74
            'node' => $node,
75
        ]);
76
    }
77
78
    /**
79
     * Renders file overview page.
80
     *
81
     * @param  Request $request
82
     * @return \Illuminate\Contracts\View\View
83
     */
84
    public function getFiles(Request $request, $uuid)
85
    {
86
        $server = Models\Server::getByUUID($uuid);
87
        $this->authorize('list-files', $server);
88
89
        $node = Models\Node::find($server->node);
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...
90
91
        Javascript::put([
92
            'server' => collect($server->makeVisible('daemonSecret'))->only('uuid', 'uuidShort', 'daemonSecret'),
93
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
94
            'meta' => [
95
                'directoryList' => route('server.files.directory-list', $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...
96
                'csrftoken' => csrf_token(),
97
            ],
98
            'permissions' => [
99
                'moveFiles' => $request->user()->can('move-files', $server),
100
                'copyFiles' => $request->user()->can('copy-files', $server),
101
                'compressFiles' => $request->user()->can('compress-files', $server),
102
                'decompressFiles' => $request->user()->can('decompress-files', $server),
103
                'createFiles' => $request->user()->can('create-files', $server),
104
                'downloadFiles' => $request->user()->can('download-files', $server),
105
                'deleteFiles' => $request->user()->can('delete-files', $server),
106
            ],
107
        ]);
108
109
        return view('server.files.index', [
110
            'server' => $server,
111
            'node' => $node,
112
        ]);
113
    }
114
115
    /**
116
     * Renders add file page.
117
     *
118
     * @param  Request $request
119
     * @return \Illuminate\Contracts\View\View
120
     */
121 View Code Duplication
    public function getAddFile(Request $request, $uuid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
122
    {
123
        $server = Models\Server::getByUUID($uuid);
124
        $this->authorize('add-files', $server);
125
        $node = Models\Node::find($server->node);
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...
126
127
        Javascript::put([
128
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
129
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
130
        ]);
131
132
        return view('server.files.add', [
133
            'server' => $server,
134
            'node' => $node,
135
            'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
136
        ]);
137
    }
138
139
    /**
140
     * Renders edit file page for a given file.
141
     *
142
     * @param  Request $request
143
     * @param  string  $uuid
144
     * @param  string  $file
145
     * @return \Illuminate\Contracts\View\View
146
     */
147
    public function getEditFile(Request $request, $uuid, $file)
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...
148
    {
149
        $server = Models\Server::getByUUID($uuid);
150
        $this->authorize('edit-files', $server);
151
        $node = Models\Node::find($server->node);
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...
152
153
        $fileInfo = (object) pathinfo($file);
154
        $controller = new FileRepository($uuid);
155
156
        try {
157
            $fileContent = $controller->returnFileContents($file);
158
        } catch (DisplayException $ex) {
159
            Alert::danger($ex->getMessage())->flash();
160
161
            return redirect()->route('server.files.index', $uuid);
0 ignored issues
show
Documentation introduced by
$uuid is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
162
        } catch (\Exception $ex) {
163
            Log::error($ex);
164
            Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash();
165
166
            return redirect()->route('server.files.index', $uuid);
0 ignored issues
show
Documentation introduced by
$uuid is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
167
        }
168
169
        Javascript::put([
170
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
171
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
172
            'stat' => $fileContent['stat'],
173
        ]);
174
175
        return view('server.files.edit', [
176
            'server' => $server,
177
            'node' => $node,
178
            'file' => $file,
179
            'stat' => $fileContent['stat'],
180
            'contents' => $fileContent['file']->content,
181
            'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
182
        ]);
183
    }
184
185
    /**
186
     * Handles downloading a file for the user.
187
     *
188
     * @param  Request $request
189
     * @param  string  $uuid
190
     * @param  string  $file
191
     * @return \Illuminate\Contracts\View\View
192
     */
193
    public function getDownloadFile(Request $request, $uuid, $file)
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...
194
    {
195
        $server = Models\Server::getByUUID($uuid);
196
        $node = Models\Node::find($server->node);
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...
197
198
        $this->authorize('download-files', $server);
199
200
        $download = new Models\Download;
201
202
        $download->token = (string) Uuid::generate(4);
0 ignored issues
show
Documentation introduced by
The property token does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
203
        $download->server = $server->uuid;
0 ignored issues
show
Documentation introduced by
The property server does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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...
204
        $download->path = $file;
0 ignored issues
show
Documentation introduced by
The property path does not exist on object<Pterodactyl\Models\Download>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
205
206
        $download->save();
207
208
        return redirect($node->scheme . '://' . $node->fqdn . ':' . $node->daemonListen . '/server/file/download/' . $download->token);
0 ignored issues
show
Documentation introduced by
The property token does not exist on object<Pterodactyl\Models\Download>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
209
    }
210
211 View Code Duplication
    public function getAllocation(Request $request, $uuid)
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...
Duplication introduced by
This method seems to be duplicated in 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...
212
    {
213
        $server = Models\Server::getByUUID($uuid);
214
        $this->authorize('view-allocation', $server);
215
        $node = Models\Node::find($server->node);
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...
216
217
        Javascript::put([
218
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
219
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
220
        ]);
221
222
        return view('server.settings.allocation', [
223
            'server' => $server,
224
            'allocations' => Models\Allocation::where('assigned_to', $server->id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(),
0 ignored issues
show
Bug introduced by
The property id 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...
225
            'node' => $node,
226
        ]);
227
    }
228
229
    public function getStartup(Request $request, $uuid)
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...
230
    {
231
        $server = Models\Server::getByUUID($uuid);
232
        $this->authorize('view-startup', $server);
233
        $node = Models\Node::find($server->node);
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...
234
        $allocation = Models\Allocation::findOrFail($server->allocation);
0 ignored issues
show
Bug introduced by
The property allocation 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...
235
236
        Javascript::put([
237
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
238
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
239
        ]);
240
241
        $variables = Models\ServiceVariables::select(
242
                'service_variables.*',
243
                DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
244
            )->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
245
            ->where('service_variables.option_id', $server->option)
0 ignored issues
show
Bug introduced by
The property option 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...
246
            ->where('server_variables.server_id', $server->id)
0 ignored issues
show
Bug introduced by
The property id 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...
247
            ->get();
248
249
        $service = Models\Service::select(
250
                DB::raw('IFNULL(service_options.executable, services.executable) as executable')
251
            )->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
252
            ->where('service_options.id', $server->option)
253
            ->where('services.id', $server->service)
0 ignored issues
show
Bug introduced by
The property service 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...
254
            ->first();
255
256
        $serverVariables = [
257
            '{{SERVER_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...
258
            '{{SERVER_IP}}' => $allocation->ip,
259
            '{{SERVER_PORT}}' => $allocation->port,
260
        ];
261
262
        $processed = str_replace(array_keys($serverVariables), array_values($serverVariables), $server->startup);
0 ignored issues
show
Bug introduced by
The property startup 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...
263
        foreach ($variables as &$variable) {
264
            $replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '**';
265
            $processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
266
        }
267
268
        return view('server.settings.startup', [
269
            'server' => $server,
270
            'node' => Models\Node::find($server->node),
271
            'variables' => $variables->where('user_viewable', 1),
272
            'service' => $service,
273
            'processedStartup' => $processed,
274
        ]);
275
    }
276
277 View Code Duplication
    public function getDatabases(Request $request, $uuid)
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...
Duplication introduced by
This method seems to be duplicated in 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...
278
    {
279
        $server = Models\Server::getByUUID($uuid);
280
        $this->authorize('view-databases', $server);
281
        $node = Models\Node::find($server->node);
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...
282
283
        Javascript::put([
284
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
285
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
286
        ]);
287
288
        return view('server.settings.databases', [
289
            'server' => $server,
290
            'node' => $node,
291
            'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
292
                ->where('server_id', $server->id)
0 ignored issues
show
Bug introduced by
The property id 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...
293
                ->join('database_servers', 'database_servers.id', '=', 'databases.db_server')
294
                ->get(),
295
        ]);
296
    }
297
298 View Code Duplication
    public function getSFTP(Request $request, $uuid)
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...
Duplication introduced by
This method seems to be duplicated in 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...
299
    {
300
        $server = Models\Server::getByUUID($uuid);
301
        $this->authorize('view-sftp', $server);
302
        $node = Models\Node::find($server->node);
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...
303
304
        Javascript::put([
305
            'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'daemonSecret', 'username']),
306
            'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
307
        ]);
308
309
        return view('server.settings.sftp', [
310
            'server' => $server,
311
            'node' => $node,
312
        ]);
313
    }
314
315 View Code Duplication
    public function postSettingsSFTP(Request $request, $uuid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
316
    {
317
        $server = Models\Server::getByUUID($uuid);
318
        $this->authorize('reset-sftp', $server);
319
320
        try {
321
            $repo = new ServerRepository;
322
            $repo->updateSFTPPassword($server->id, $request->input('sftp_pass'));
0 ignored issues
show
Bug introduced by
The property id 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...
323
            Alert::success('Successfully updated this servers SFTP password.')->flash();
324
        } catch (DisplayValidationException $ex) {
325
            return redirect()->route('server.settings.sftp', $uuid)->withErrors(json_decode($ex->getMessage()));
326
        } catch (DisplayException $ex) {
327
            Alert::danger($ex->getMessage())->flash();
328
        } catch (\Exception $ex) {
329
            Log::error($ex);
330
            Alert::danger('An unknown error occured while attempting to update this server\'s SFTP settings.')->flash();
331
        }
332
333
        return redirect()->route('server.settings.sftp', $uuid);
334
    }
335
336
    public function postSettingsStartup(Request $request, $uuid)
337
    {
338
        $server = Models\Server::getByUUID($uuid);
339
        $this->authorize('edit-startup', $server);
340
341
        try {
342
            $repo = new ServerRepository;
343
            $repo->updateStartup($server->id, $request->except([
0 ignored issues
show
Bug introduced by
The property id 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...
344
                '_token',
345
            ]));
346
            Alert::success('Server startup variables were successfully updated.')->flash();
347
        } catch (DisplayException $ex) {
348
            Alert::danger($ex->getMessage())->flash();
349
        } catch (\Exception $ex) {
350
            Log::error($ex);
351
            Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
352
        }
353
354
        return redirect()->route('server.settings', [
355
            'uuid' => $uuid,
356
            'tab' => 'tab_startup',
357
        ]);
358
    }
359
}
360