GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#286)
by Dane
02:56
created

Node::getByID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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_id' => 'integer',
57
         'memory' => 'integer',
58
         'disk' => 'integer',
59
         'daemonListen' => 'integer',
60
         'daemonSFTP' => 'integer',
61
     ];
62
63
    /**
64
     * Fields that are mass assignable.
65
     *
66
     * @var array
67
     */
68
    protected $fillable = [
69
        'uuid',
70
        'uuidShort',
71
        'node_id',
72
        'name',
73
        'suspended',
74
        'owner_id',
75
        'memory',
76
        'swap',
77
        'disk',
78
        'io',
79
        'cpu',
80
        'oom_disabled',
81
        'allocation_id',
82
        'service_id',
83
        'option_id',
84
        'pack_id',
85
        'startup',
86
        'daemonSecret',
87
        'image',
88
        'username',
89
        'sftp_password',
90
        'installed',
91
    ];
92
93
    /**
94
     * @var array
95
     */
96
    protected static $guzzle = [];
97
98
    /**
99
     * @var array
100
     */
101
    protected static $nodes = [];
102
103
    /**
104
     * Returns an instance of the database object for the requested node ID.
105
     *
106
     * @param  int $id
107
     * @return \Illuminate\Database\Eloquent\Model
108
     */
109
    public static function getByID($id)
110
    {
111
112
        // The Node is already cached.
113
        if (array_key_exists($id, self::$nodes)) {
114
            return self::$nodes[$id];
115
        }
116
117
        self::$nodes[$id] = self::where('id', $id)->first();
118
119
        return self::$nodes[$id];
120
    }
121
122
    /**
123
     * Return an instance of the Guzzle client for this specific node.
124
     *
125
     * @param array $headers
126
     * @return \GuzzleHttp\Client
127
     */
128
    public function guzzleClient($headers = [])
129
    {
130
        return new Client([
131
            'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
0 ignored issues
show
Documentation introduced by
The property scheme does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
Documentation introduced by
The property daemonListen does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
132
            'timeout' => env('GUZZLE_TIMEOUT', 5.0),
133
            'connect_timeout' => env('GUZZLE_CONNECT_TIMEOUT', 3.0),
134
            'headers' => $headers,
135
        ]);
136
    }
137
138
    /**
139
     * Returns a Guzzle Client for the node in question.
140
     *
141
     * @param  int $node
142
     * @return \GuzzleHttp\Client
143
     * @deprecated
144
     */
145
    public static function guzzleRequest($node)
146
    {
147
148
        // The Guzzle Client is cached already.
149
        if (array_key_exists($node, self::$guzzle)) {
150
            return self::$guzzle[$node];
151
        }
152
153
        $nodeData = self::getByID($node);
154
155
        self::$guzzle[$node] = new Client([
156
            'base_uri' => sprintf('%s://%s:%s/', $nodeData->scheme, $nodeData->fqdn, $nodeData->daemonListen),
157
            'timeout' => 5.0,
158
            'connect_timeout' => 3.0,
159
        ]);
160
161
        return self::$guzzle[$node];
162
    }
163
164
    /**
165
     * Returns the configuration in JSON format.
166
     *
167
     * @param bool $pretty Wether to pretty print the JSON or not
168
     * @return string The configration in JSON format
169
     */
170
    public function getConfigurationAsJson($pretty = false)
171
    {
172
        $config = [
173
            'web' => [
174
                'host' => '0.0.0.0',
175
                'listen' => $this->daemonListen,
0 ignored issues
show
Documentation introduced by
The property daemonListen does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
176
                'ssl' => [
177
                    'enabled' => $this->scheme === 'https',
0 ignored issues
show
Documentation introduced by
The property scheme does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
178
                    'certificate' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem',
0 ignored issues
show
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
179
                    'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem',
0 ignored issues
show
Documentation introduced by
The property fqdn does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
180
                ],
181
            ],
182
            'docker' => [
183
                'socket' => '/var/run/docker.sock',
184
                'autoupdate_images' => true,
185
            ],
186
            'sftp' => [
187
                'path' => $this->daemonBase,
0 ignored issues
show
Documentation introduced by
The property daemonBase does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
188
                'port' => $this->daemonSFTP,
0 ignored issues
show
Documentation introduced by
The property daemonSFTP does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
189
                'container' => 'ptdl-sftp',
190
            ],
191
            'query' => [
192
                'kill_on_fail' => true,
193
                'fail_limit' => 5,
194
            ],
195
            'logger' => [
196
                'path' => 'logs/',
197
                'src' => false,
198
                'level' => 'info',
199
                'period' => '1d',
200
                'count' => 3,
201
            ],
202
            'remote' => [
203
                'base' => config('app.url'),
204
                'download' => route('remote.download'),
205
                'installed' => route('remote.install'),
206
            ],
207
            'uploads' => [
208
                'size_limit' => $this->upload_size,
0 ignored issues
show
Documentation introduced by
The property upload_size does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
209
            ],
210
            'keys' => [$this->daemonSecret],
0 ignored issues
show
Documentation introduced by
The property daemonSecret does not exist on object<Pterodactyl\Models\Node>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
211
        ];
212
213
        $json_options = JSON_UNESCAPED_SLASHES;
214
        if ($pretty) {
215
            $json_options |= JSON_PRETTY_PRINT;
216
        }
217
218
        return json_encode($config, $json_options);
219
    }
220
221
    /**
222
     * Gets the location associated with a node.
223
     *
224
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
225
     */
226
    public function location()
227
    {
228
        return $this->belongsTo(Location::class);
229
    }
230
231
    /**
232
     * Gets the servers associated with a node.
233
     *
234
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
235
     */
236
    public function servers()
237
    {
238
        return $this->hasMany(Server::class);
239
    }
240
241
    /**
242
     * Gets the allocations associated with a node.
243
     *
244
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
245
     */
246
    public function allocations()
247
    {
248
        return $this->hasMany(Allocation::class);
249
    }
250
}
251