forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerRepository.php
More file actions
146 lines (127 loc) · 4.14 KB
/
ServerRepository.php
File metadata and controls
146 lines (127 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use Webmozart\Assert\Assert;
use Pterodactyl\Services\Servers\EnvironmentService;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface as DatabaseServerRepositoryInterface;
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function create($id, array $overrides = [], $start = false)
{
Assert::numeric($id, 'First argument passed to create must be numeric, received %s.');
Assert::boolean($start, 'Third argument passed to create must be boolean, received %s.');
$repository = $this->app->make(DatabaseServerRepositoryInterface::class);
$environment = $this->app->make(EnvironmentService::class);
$server = $repository->getDataForCreation($id);
$data = [
'uuid' => (string) $server->uuid,
'user' => $server->username,
'build' => [
'default' => [
'ip' => $server->allocation->ip,
'port' => $server->allocation->port,
],
'ports' => $server->allocations->groupBy('ip')->map(function ($item) {
return $item->pluck('port');
})->toArray(),
'env' => $environment->process($server),
'memory' => (int) $server->memory,
'swap' => (int) $server->swap,
'io' => (int) $server->io,
'cpu' => (int) $server->cpu,
'disk' => (int) $server->disk,
'image' => $server->image,
],
'service' => [
'type' => $server->option->service->folder,
'option' => $server->option->tag,
'pack' => object_get($server, 'pack.uuid'),
'skip_scripts' => $server->skip_scripts,
],
'rebuild' => false,
'start_on_completion' => $start,
];
// Loop through overrides.
foreach ($overrides as $key => $value) {
array_set($data, $key, $value);
}
return $this->getHttpClient()->request('POST', '/servers', [
'json' => $data,
]);
}
/**
* {@inheritdoc}
*/
public function update(array $data)
{
return $this->getHttpClient()->request('PATCH', '/server', [
'json' => $data,
]);
}
/**
* {@inheritdoc}
*/
public function reinstall($data = null)
{
Assert::nullOrIsArray($data, 'First argument passed to reinstall must be null or an array, received %s.');
if (is_null($data)) {
return $this->getHttpClient()->request('POST', '/server/reinstall');
}
return $this->getHttpClient()->request('POST', '/server/reinstall', [
'json' => $data,
]);
}
/**
* {@inheritdoc}
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', '/server/rebuild');
}
/**
* {@inheritdoc}
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', '/server/suspend');
}
/**
* {@inheritdoc}
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', '/server/unsuspend');
}
/**
* {@inheritdoc}
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', '/servers');
}
/**
* {@inheritdoc}
*/
public function details()
{
return $this->getHttpClient()->request('GET', '/server');
}
/**
* {@inheritdoc}
*/
public function revokeAccessKey($key)
{
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string, received %s.');
return $this->getHttpClient()->request('DELETE', '/keys/' . $key);
}
}