|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gameap\Http\Controllers\GdaemonAPI; |
|
4
|
|
|
|
|
5
|
|
|
use Gameap\Repositories\DedicatedServersRepository; |
|
6
|
|
|
use Gameap\Models\DedicatedServer; |
|
7
|
|
|
use Illuminate\Routing\Controller as BaseController; |
|
8
|
|
|
use Illuminate\Support\Facades\Cache; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
|
10
|
|
|
use Illuminate\Support\Str; |
|
11
|
|
|
use Gameap\Http\Requests\GdaemonAPI\DedicatedServerRequest; |
|
12
|
|
|
use Illuminate\Http\Request; |
|
13
|
|
|
use Storage; |
|
14
|
|
|
|
|
15
|
|
|
class SetupController extends BaseController |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The DedicatedServersRepository instance. |
|
19
|
|
|
* |
|
20
|
|
|
* @var \Gameap\Repositories\DedicatedServersRepository |
|
21
|
|
|
*/ |
|
22
|
|
|
public $repository; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* DedicatedServersController constructor. |
|
26
|
|
|
* @param DedicatedServersRepository $repository |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(DedicatedServersRepository $repository) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->repository = $repository; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Return path to daemon script setup |
|
35
|
|
|
*/ |
|
36
|
|
|
public function setup(string $token) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
app('debugbar')->disable(); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
Cache::forget('gdaemonAutoSetupToken'); |
|
41
|
|
|
|
|
42
|
|
|
$gdaemonCreateToken = Str::random(24); |
|
43
|
|
|
Cache::put('gdaemonCreateToken', $gdaemonCreateToken, 30); |
|
44
|
|
|
|
|
45
|
|
|
return "export createToken={$gdaemonCreateToken}; |
|
46
|
|
|
export panelHost=" . url('/') . "; |
|
47
|
|
|
curl -sL https://raw.githubusercontent.com/gameap/auto-install-scripts/master/debian/install-gdaemon-en.sh | bash --"; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Creating a new Dedicated server. Uploading certificate |
|
52
|
|
|
*/ |
|
53
|
|
|
public function create(string $token, DedicatedServerRequest $request) |
|
54
|
|
|
{ |
|
55
|
|
|
app('debugbar')->disable(); |
|
56
|
|
|
$gdaemonCreateToken = Cache::get('gdaemonCreateToken'); |
|
|
|
|
|
|
57
|
|
|
Cache::forget('gdaemonCreateToken'); |
|
58
|
|
|
|
|
59
|
|
|
$attributes = $request->all(); |
|
60
|
|
|
|
|
61
|
|
|
if ($request->hasFile('gdaemon_server_cert')) { |
|
62
|
|
|
$attributes['gdaemon_server_cert'] = $request->file('gdaemon_server_cert')->store( |
|
63
|
|
|
'gdaemon_certs', 'local' |
|
64
|
|
|
); |
|
65
|
|
|
} else { |
|
66
|
|
|
return "Error Empty GDdaemon server certificate"; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$dedicatedServer = $this->repository->store($attributes); |
|
70
|
|
|
|
|
71
|
|
|
$certificate = Storage::disk('local')->get($dedicatedServer->clientCertificate->certificate); |
|
72
|
|
|
|
|
73
|
|
|
return "Success {$dedicatedServer->id} {$dedicatedServer->gdaemon_api_key}\n{$certificate}"; |
|
74
|
|
|
} |
|
75
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.