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