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
02:28
created

ServerController::getFiles()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
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 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, $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...
59
    {
60
        $server = Models\Server::byUuid($uuid);
61
62
        $server->js([
63
            'meta' => [
64
                '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...
65
                'csrfToken' => csrf_token(),
66
            ],
67
        ]);
68
69
        return view('server.index', [
70
            'server' => $server,
71
            'node' => $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...
72
        ]);
73
    }
74
75
    /**
76
     * Renders file overview page.
77
     *
78
     * @param  Request $request
79
     * @return \Illuminate\Contracts\View\View
80
     */
81
    public function getFiles(Request $request, $uuid)
82
    {
83
        $server = Models\Server::byUuid($uuid);
84
        $this->authorize('list-files', $server);
85
86
        $server->js([
87
            'meta' => [
88
                '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...
89
                'csrftoken' => csrf_token(),
90
            ],
91
            'permissions' => [
92
                'moveFiles' => $request->user()->can('move-files', $server),
93
                'copyFiles' => $request->user()->can('copy-files', $server),
94
                'compressFiles' => $request->user()->can('compress-files', $server),
95
                'decompressFiles' => $request->user()->can('decompress-files', $server),
96
                'createFiles' => $request->user()->can('create-files', $server),
97
                'downloadFiles' => $request->user()->can('download-files', $server),
98
                'deleteFiles' => $request->user()->can('delete-files', $server),
99
            ],
100
        ]);
101
102
        return view('server.files.index', [
103
            'server' => $server,
104
            'node' => $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...
105
        ]);
106
    }
107
108
    /**
109
     * Renders add file page.
110
     *
111
     * @param  Request $request
112
     * @return \Illuminate\Contracts\View\View
113
     */
114 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...
115
    {
116
        $server = Models\Server::byUuid($uuid);
117
        $this->authorize('add-files', $server);
118
119
        $server->js();
120
121
        return view('server.files.add', [
122
            'server' => $server,
123
            'node' => $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...
124
            'directory' => (in_array($request->get('dir'), [null, '/', ''])) ? '' : trim($request->get('dir'), '/') . '/',
125
        ]);
126
    }
127
128
    /**
129
     * Renders edit file page for a given file.
130
     *
131
     * @param  Request $request
132
     * @param  string  $uuid
133
     * @param  string  $file
134
     * @return \Illuminate\Contracts\View\View
135
     */
136
    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...
137
    {
138
        $server = Models\Server::byUuid($uuid);
139
        $this->authorize('edit-files', $server);
140
141
        $fileInfo = (object) pathinfo($file);
142
        $controller = new FileRepository($uuid);
143
144
        try {
145
            $fileContent = $controller->returnFileContents($file);
146
        } catch (DisplayException $ex) {
147
            Alert::danger($ex->getMessage())->flash();
148
149
            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...
150
        } catch (\Exception $ex) {
151
            Log::error($ex);
152
            Alert::danger('An error occured while attempting to load the requested file for editing, please try again.')->flash();
153
154
            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...
155
        }
156
157
        $server->js([
158
            'stat' => $fileContent['stat'],
159
        ]);
160
161
        return view('server.files.edit', [
162
            'server' => $server,
163
            'node' => $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...
164
            'file' => $file,
165
            'stat' => $fileContent['stat'],
166
            'contents' => $fileContent['file']->content,
167
            'directory' => (in_array($fileInfo->dirname, ['.', './', '/'])) ? '/' : trim($fileInfo->dirname, '/') . '/',
168
        ]);
169
    }
170
171
    /**
172
     * Handles downloading a file for the user.
173
     *
174
     * @param  Request $request
175
     * @param  string  $uuid
176
     * @param  string  $file
177
     * @return \Illuminate\Contracts\View\View
178
     */
179
    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...
180
    {
181
        $server = Models\Server::byUuid($uuid);
182
        $this->authorize('download-files', $server);
183
184
        $download = new Models\Download;
185
186
        $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...
187
        $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...
188
        $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...
189
190
        $download->save();
191
192
        return redirect($server->node->scheme . '://' . $server->node->fqdn . ':' . $server->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...
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...
193
    }
194
195
    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...
196
    {
197
        $server = Models\Server::byUuid($uuid);
198
        $this->authorize('view-allocation', $server);
199
        $server->js();
200
201
        return view('server.settings.allocation', [
202
            'server' => $server->load(['allocations' => function ($query) {
203
                $query->orderBy('ip', 'asc');
204
                $query->orderBy('port', 'asc');
205
            }]),
206
            'node' => $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...
207
        ]);
208
    }
209
210
    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...
211
    {
212
        $server = Models\Server::byUuid($uuid);
213
        $server->load(['allocations' => function ($query) use ($server) {
214
            $query->where('id', $server->allocation_id);
215
        }]);
216
        $this->authorize('view-startup', $server);
217
218
        $variables = Models\ServiceVariables::select(
219
                'service_variables.*',
220
                DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
221
            )->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
222
            ->where('service_variables.option_id', $server->option_id)
0 ignored issues
show
Bug introduced by
The property option_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...
223
            ->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...
224
            ->get();
225
226
        $service = Models\Service::select(
227
                DB::raw('IFNULL(service_options.executable, services.executable) as executable')
228
            )->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
229
            ->where('service_options.id', $server->option_id)
230
            ->where('services.id', $server->service_id)
0 ignored issues
show
Bug introduced by
The property service_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...
231
            ->first();
232
233
        $allocation = $server->allocations->pop();
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...
234
        $serverVariables = [
235
            '{{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...
236
            '{{SERVER_IP}}' => $allocation->ip,
237
            '{{SERVER_PORT}}' => $allocation->port,
238
        ];
239
240
        $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...
241
        foreach ($variables as &$variable) {
242
            $replace = ($variable->user_viewable === 1) ? $variable->a_serverValue : '[hidden]';
243
            $processed = str_replace('{{' . $variable->env_variable . '}}', $replace, $processed);
244
        }
245
246
        $server->js();
247
248
        return view('server.settings.startup', [
249
            'server' => $server,
250
            'node' => $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...
251
            'variables' => $variables->where('user_viewable', 1),
252
            'service' => $service,
253
            'processedStartup' => $processed,
254
        ]);
255
    }
256
257 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...
258
    {
259
        $server = Models\Server::byUuid($uuid);
260
        $this->authorize('view-databases', $server);
261
        $server->js();
262
263
        return view('server.settings.databases', [
264
            'server' => $server,
265
            'node' => $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...
266
            'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port')
267
                ->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...
268
                ->join('database_servers', 'database_servers.id', '=', 'databases.db_server')
269
                ->get(),
270
        ]);
271
    }
272
273 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...
274
    {
275
        $server = Models\Server::byUuid($uuid);
276
        $this->authorize('view-sftp', $server);
277
        $server->js();
278
279
        return view('server.settings.sftp', [
280
            'server' => $server,
281
            'node' => $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
    }
284
285 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...
286
    {
287
        $server = Models\Server::byUuid($uuid);
288
        $this->authorize('reset-sftp', $server);
289
290
        try {
291
            $repo = new ServerRepository;
292
            $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...
293
            Alert::success('Successfully updated this servers SFTP password.')->flash();
294
        } catch (DisplayValidationException $ex) {
295
            return redirect()->route('server.settings.sftp', $uuid)->withErrors(json_decode($ex->getMessage()));
296
        } catch (DisplayException $ex) {
297
            Alert::danger($ex->getMessage())->flash();
298
        } catch (\Exception $ex) {
299
            Log::error($ex);
300
            Alert::danger('An unknown error occured while attempting to update this server\'s SFTP settings.')->flash();
301
        }
302
303
        return redirect()->route('server.settings.sftp', $uuid);
304
    }
305
306
    public function postSettingsStartup(Request $request, $uuid)
307
    {
308
        $server = Models\Server::byUuid($uuid);
309
        $this->authorize('edit-startup', $server);
310
311
        try {
312
            $repo = new ServerRepository;
313
            $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...
314
                '_token',
315
            ]));
316
            Alert::success('Server startup variables were successfully updated.')->flash();
317
        } catch (DisplayException $ex) {
318
            Alert::danger($ex->getMessage())->flash();
319
        } catch (\Exception $ex) {
320
            Log::error($ex);
321
            Alert::danger('An unhandled exception occured while attemping to update startup variables for this server. Please try again.')->flash();
322
        }
323
324
        return redirect()->route('server.settings', [
325
            'uuid' => $uuid,
326
            'tab' => 'tab_startup',
327
        ]);
328
    }
329
}
330