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.

Node::getConfigurationAsJson()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 39
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 39
rs 8.8571
cc 3
eloc 28
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
use Nicolaslopezj\Searchable\SearchableTrait;
31
32
class Node extends Model
33
{
34
    use Notifiable, SearchableTrait;
35
36
    /**
37
     * The table associated with the model.
38
     *
39
     * @var string
40
     */
41
    protected $table = 'nodes';
42
43
    /**
44
     * The attributes excluded from the model's JSON form.
45
     *
46
     * @var array
47
     */
48
    protected $hidden = ['daemonSecret'];
49
50
     /**
51
      * Cast values to correct type.
52
      *
53
      * @var array
54
      */
55
     protected $casts = [
56
         'public' => 'integer',
57
         'location_id' => 'integer',
58
         'memory' => 'integer',
59
         'disk' => 'integer',
60
         'daemonListen' => 'integer',
61
         'daemonSFTP' => 'integer',
62
         'behind_proxy' => 'boolean',
63
     ];
64
65
    /**
66
     * Fields that are mass assignable.
67
     *
68
     * @var array
69
     */
70
    protected $fillable = [
71
        'public', 'name', 'location_id',
72
        'fqdn', 'scheme', 'behind_proxy',
73
        'memory', 'memory_overallocate', 'disk',
74
        'disk_overallocate', 'upload_size',
75
        'daemonSecret', 'daemonBase',
76
        'daemonSFTP', 'daemonListen',
77
    ];
78
79
    /**
80
     * Fields that are searchable.
81
     *
82
     * @var array
83
     */
84
    protected $searchable = [
85
         'columns' => [
86
             'nodes.name' => 10,
87
             'nodes.fqdn' => 8,
88
             'locations.short' => 4,
89
             'locations.long' => 4,
90
         ],
91
         'joins' => [
92
            'locations' => ['locations.id', 'nodes.location_id'],
93
         ],
94
     ];
95
96
    /**
97
     * Return an instance of the Guzzle client for this specific node.
98
     *
99
     * @param  array  $headers
100
     * @return \GuzzleHttp\Client
101
     */
102
    public function guzzleClient($headers = [])
103
    {
104
        return new Client([
105
            'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
106
            'timeout' => config('pterodactyl.guzzle.timeout'),
107
            'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
108
            'headers' => $headers,
109
        ]);
110
    }
111
112
    /**
113
     * Returns the configuration in JSON format.
114
     *
115
     * @param  bool  $pretty
116
     * @return string
117
     */
118
    public function getConfigurationAsJson($pretty = false)
119
    {
120
        $config = [
121
            'web' => [
122
                'host' => '0.0.0.0',
123
                'listen' => $this->daemonListen,
124
                'ssl' => [
125
                    'enabled' => (! $this->behind_proxy && $this->scheme === 'https'),
126
                    'certificate' => '/etc/letsencrypt/live/' . $this->fqdn . '/fullchain.pem',
127
                    'key' => '/etc/letsencrypt/live/' . $this->fqdn . '/privkey.pem',
128
                ],
129
            ],
130
            'docker' => [
131
                'socket' => '/var/run/docker.sock',
132
                'autoupdate_images' => true,
133
            ],
134
            'sftp' => [
135
                'path' => $this->daemonBase,
136
                'port' => $this->daemonSFTP,
137
                'container' => 'ptdl-sftp',
138
            ],
139
            'logger' => [
140
                'path' => 'logs/',
141
                'src' => false,
142
                'level' => 'info',
143
                'period' => '1d',
144
                'count' => 3,
145
            ],
146
            'remote' => [
147
                'base' => route('index'),
148
            ],
149
            'uploads' => [
150
                'size_limit' => $this->upload_size,
151
            ],
152
            'keys' => [$this->daemonSecret],
153
        ];
154
155
        return json_encode($config, ($pretty) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES);
156
    }
157
158
    /**
159
     * Gets the location associated with a node.
160
     *
161
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
162
     */
163
    public function location()
164
    {
165
        return $this->belongsTo(Location::class);
166
    }
167
168
    /**
169
     * Gets the servers associated with a node.
170
     *
171
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
172
     */
173
    public function servers()
174
    {
175
        return $this->hasMany(Server::class);
176
    }
177
178
    /**
179
     * Gets the allocations associated with a node.
180
     *
181
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
182
     */
183
    public function allocations()
184
    {
185
        return $this->hasMany(Allocation::class);
186
    }
187
}
188