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\Models; |
26
|
|
|
|
27
|
|
|
use GuzzleHttp\Client; |
28
|
|
|
use Illuminate\Database\Eloquent\Model; |
29
|
|
|
use Illuminate\Notifications\Notifiable; |
30
|
|
|
|
31
|
|
|
class Node extends Model |
32
|
|
|
{ |
33
|
|
|
use Notifiable; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The table associated with the model. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $table = 'nodes'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The attributes excluded from the model's JSON form. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $hidden = ['daemonSecret']; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Cast values to correct type. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected $casts = [ |
55
|
|
|
'public' => 'integer', |
56
|
|
|
'location' => 'integer', |
57
|
|
|
'memory' => 'integer', |
58
|
|
|
'disk' => 'integer', |
59
|
|
|
'daemonListen' => 'integer', |
60
|
|
|
'daemonSFTP' => 'integer', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Fields that are not mass assignable. |
65
|
|
|
* |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at']; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
protected static $guzzle = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
protected static $nodes = []; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns an instance of the database object for the requested node ID. |
82
|
|
|
* |
83
|
|
|
* @param int $id |
84
|
|
|
* @return \Illuminate\Database\Eloquent\Model |
85
|
|
|
*/ |
86
|
|
|
public static function getByID($id) |
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
// The Node is already cached. |
90
|
|
|
if (array_key_exists($id, self::$nodes)) { |
91
|
|
|
return self::$nodes[$id]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
self::$nodes[$id] = self::where('id', $id)->first(); |
95
|
|
|
|
96
|
|
|
return self::$nodes[$id]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Return an instance of the Guzzle client for this specific node. |
101
|
|
|
* |
102
|
|
|
* @return \GuzzleHttp\Client |
103
|
|
|
*/ |
104
|
|
|
public function guzzleClient($headers = []) |
105
|
|
|
{ |
106
|
|
|
return new Client([ |
107
|
|
|
'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen), |
|
|
|
|
108
|
|
|
'timeout' => env('GUZZLE_TIMEOUT', 5.0), |
109
|
|
|
'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3.0), |
110
|
|
|
'headers' => $headers, |
111
|
|
|
]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns a Guzzle Client for the node in question. |
116
|
|
|
* |
117
|
|
|
* @param int $node |
118
|
|
|
* @return \GuzzleHttp\Client |
119
|
|
|
* @deprecated |
120
|
|
|
*/ |
121
|
|
|
public static function guzzleRequest($node) |
122
|
|
|
{ |
123
|
|
|
|
124
|
|
|
// The Guzzle Client is cached already. |
125
|
|
|
if (array_key_exists($node, self::$guzzle)) { |
126
|
|
|
return self::$guzzle[$node]; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$nodeData = self::getByID($node); |
130
|
|
|
|
131
|
|
|
self::$guzzle[$node] = new Client([ |
132
|
|
|
'base_uri' => sprintf('%s://%s:%s/', $nodeData->scheme, $nodeData->fqdn, $nodeData->daemonListen), |
133
|
|
|
'timeout' => 5.0, |
134
|
|
|
'connect_timeout' => 3.0, |
135
|
|
|
]); |
136
|
|
|
|
137
|
|
|
return self::$guzzle[$node]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns the configuration in JSON format. |
142
|
|
|
* |
143
|
|
|
* @param bool $pretty Wether to pretty print the JSON or not |
144
|
|
|
* @return string The configration in JSON format |
145
|
|
|
*/ |
146
|
|
|
public function getConfigurationAsJson($pretty = false) |
147
|
|
|
{ |
148
|
|
|
$config = [ |
149
|
|
|
'web' => [ |
150
|
|
|
'host' => '0.0.0.0', |
151
|
|
|
'listen' => $this->daemonListen, |
|
|
|
|
152
|
|
|
'ssl' => [ |
153
|
|
|
'enabled' => $this->scheme === 'https', |
|
|
|
|
154
|
|
|
'certificate' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem', |
|
|
|
|
155
|
|
|
'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem', |
|
|
|
|
156
|
|
|
], |
157
|
|
|
], |
158
|
|
|
'docker' => [ |
159
|
|
|
'socket' => '/var/run/docker.sock', |
160
|
|
|
'autoupdate_images' => true, |
161
|
|
|
], |
162
|
|
|
'sftp' => [ |
163
|
|
|
'path' => $this->daemonBase, |
|
|
|
|
164
|
|
|
'port' => $this->daemonSFTP, |
|
|
|
|
165
|
|
|
'container' => 'ptdl-sftp', |
166
|
|
|
], |
167
|
|
|
'query' => [ |
168
|
|
|
'kill_on_fail' => true, |
169
|
|
|
'fail_limit' => 5, |
170
|
|
|
], |
171
|
|
|
'logger' => [ |
172
|
|
|
'path' => 'logs/', |
173
|
|
|
'src' => false, |
174
|
|
|
'level' => 'info', |
175
|
|
|
'period' => '1d', |
176
|
|
|
'count' => 3, |
177
|
|
|
], |
178
|
|
|
'remote' => [ |
179
|
|
|
'base' => config('app.url'), |
180
|
|
|
'download' => route('remote.download'), |
181
|
|
|
'installed' => route('remote.install'), |
182
|
|
|
], |
183
|
|
|
'uploads' => [ |
184
|
|
|
'size_limit' => $this->upload_size, |
|
|
|
|
185
|
|
|
], |
186
|
|
|
'keys' => [$this->daemonSecret], |
|
|
|
|
187
|
|
|
]; |
188
|
|
|
|
189
|
|
|
$json_options = JSON_UNESCAPED_SLASHES; |
190
|
|
|
if ($pretty) { |
191
|
|
|
$json_options |= JSON_PRETTY_PRINT; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
return json_encode($config, $json_options); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
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.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.