|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Gameap\Http\Requests\ServerVarsRequest; |
|
6
|
|
|
use Gameap\Models\Server; |
|
7
|
|
|
use Gameap\Models\ServerSetting; |
|
8
|
|
|
use Gameap\Repositories\ServerRepository; |
|
9
|
|
|
use Illuminate\Support\Facades\Auth; |
|
10
|
|
|
|
|
11
|
|
|
class ServersController extends AuthController |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The ServerRepository instance. |
|
15
|
|
|
* |
|
16
|
|
|
* @var \Gameap\Repositories\ServerRepository |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $repository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create a new ServersController instance. |
|
22
|
|
|
* |
|
23
|
|
|
* @param ServerRepository $repository |
|
24
|
|
|
*/ |
|
25
|
27 |
|
public function __construct(ServerRepository $repository) |
|
26
|
|
|
{ |
|
27
|
27 |
|
parent::__construct(); |
|
28
|
|
|
|
|
29
|
27 |
|
$this->repository = $repository; |
|
30
|
27 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Display a listing of the resource. |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
36
|
|
|
*/ |
|
37
|
|
|
public function index() |
|
38
|
|
|
{ |
|
39
|
|
|
return view('servers.list',[ |
|
40
|
|
|
'servers' => $this->repository->getServersForAuth() |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Display the specified resource. |
|
46
|
|
|
* |
|
47
|
|
|
* @param \Gameap\Models\Server $server |
|
48
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
49
|
|
|
|
|
50
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
51
|
|
|
*/ |
|
52
|
6 |
|
public function show(Server $server) |
|
53
|
|
|
{ |
|
54
|
6 |
|
$this->authorize('server-control', $server); |
|
55
|
|
|
|
|
56
|
3 |
|
return ($server->installed === $server::INSTALLED && $server->enabled && !$server->blocked) ? |
|
57
|
3 |
|
view('servers.view', compact('server')) |
|
58
|
3 |
|
: view('servers.not_active', compact('server')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param Server $server |
|
63
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
64
|
|
|
* |
|
65
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
66
|
|
|
*/ |
|
67
|
15 |
|
public function filemanager(Server $server) |
|
68
|
|
|
{ |
|
69
|
15 |
|
$this->authorize('server-control', $server); |
|
70
|
6 |
|
$this->authorize('server-files', $server); |
|
71
|
|
|
|
|
72
|
3 |
|
return view('servers.filemanager', compact('server')); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param Server $server |
|
77
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
78
|
|
|
* |
|
79
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
80
|
|
|
*/ |
|
81
|
6 |
|
public function settings(Server $server) |
|
82
|
|
|
{ |
|
83
|
6 |
|
$this->authorize('server-settings', $server); |
|
84
|
|
|
|
|
85
|
3 |
|
$autostartSetting = $server->settings->where('name', 'autostart')->first() |
|
86
|
3 |
|
?? new ServerSetting([ |
|
87
|
3 |
|
'server_id' => $server->id, |
|
88
|
3 |
|
'name' => 'autostart', |
|
89
|
|
|
'value' => true, |
|
90
|
|
|
]); |
|
91
|
|
|
|
|
92
|
3 |
|
$autostart = $autostartSetting->value; |
|
93
|
|
|
|
|
94
|
3 |
|
return view('servers.settings', compact('server', 'autostart')); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param ServerVarsRequest $request |
|
99
|
|
|
* @param Server $server |
|
100
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
101
|
|
|
* |
|
102
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException |
|
103
|
|
|
*/ |
|
104
|
|
|
public function updateSettings(ServerVarsRequest $request, Server $server) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->authorize('server-control', $server); |
|
107
|
|
|
$this->authorize('server-settings', $server); |
|
108
|
|
|
|
|
109
|
|
|
$this->repository->updateAutostart($server, ($request->get('autostart') == true)); |
|
110
|
|
|
$this->repository->updateVars($server, $request); |
|
111
|
|
|
|
|
112
|
|
|
return redirect()->route('servers.settings', ['server' => $server->id]) |
|
113
|
|
|
->with('success', __('servers.update_success_msg')); |
|
114
|
|
|
} |
|
115
|
|
|
} |