Skip to content

Commit 90cd2b6

Browse files
committed
Add version checking to daemon and panel
Also includes some buttons for users to get help from the panel.
1 parent 261535d commit 90cd2b6

File tree

6 files changed

+157
-9
lines changed

6 files changed

+157
-9
lines changed

app/Console/Commands/ShowVersion.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Pterodactyl\Console\Commands;
2525

2626
use Illuminate\Console\Command;
27+
use Version;
2728

2829
class ShowVersion extends Command
2930
{
@@ -58,6 +59,6 @@ public function __construct()
5859
*/
5960
public function handle()
6061
{
61-
$this->info('You are running Pterodactyl Panel ' . config('app.version'));
62+
$this->info('You are running Pterodactyl Panel v' . Version::getCurrentPanel() . ' (' . ((Version::isLatestPanel()) ? 'Up to Date' : 'Latest: ' . Version::getDaemon()) . ')');
6263
}
6364
}

app/Facades/Version.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
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+
namespace Pterodactyl\Facades;
25+
26+
use Illuminate\Support\Facades\Facade;
27+
28+
class Version extends Facade
29+
{
30+
31+
protected static function getFacadeAccessor()
32+
{
33+
return '\Pterodactyl\Services\VersionService';
34+
}
35+
}

app/Services/VersionService.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
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+
namespace Pterodactyl\Services;
25+
26+
use Cache;
27+
use GuzzleHttp\Client;
28+
29+
class VersionService
30+
{
31+
32+
protected static $versions;
33+
34+
/**
35+
* Constructor
36+
*/
37+
public function __construct()
38+
{
39+
self::$versions = Cache::remember('versions', env('VERSION_CACHE_TIME', 60), function () {
40+
$client = new Client();
41+
42+
try {
43+
$response = $client->request('GET', env('VERSION_CHECK_URL', 'https://cdn.pterodactyl.io/releases/latest.json'));
44+
45+
if ($response->getStatusCode() === 200) {
46+
return json_decode($response->getBody());
47+
} else {
48+
throw new \Exception('Invalid response code.');
49+
}
50+
} catch (\Exception $ex) {
51+
// Failed request, just return errored version.
52+
return (object) [
53+
'panel' => 'error',
54+
'daemon' => 'error',
55+
];
56+
}
57+
});
58+
}
59+
60+
public static function getPanel()
61+
{
62+
return self::$versions->panel;
63+
}
64+
65+
public static function getDaemon()
66+
{
67+
return self::$versions->daemon;
68+
}
69+
70+
public function getCurrentPanel()
71+
{
72+
return config('app.version');
73+
}
74+
75+
public static function isLatestPanel()
76+
{
77+
if (config('app.version') === 'canary') {
78+
return true;
79+
}
80+
81+
return (version_compare(config('app.version'), self::$versions->panel) >= 0);
82+
}
83+
84+
public static function isLatestDaemon($daemon)
85+
{
86+
if ($daemon === '0.0.0-canary') {
87+
return true;
88+
}
89+
90+
return (version_compare($daemon, self::$versions->daemon) >= 0);
91+
}
92+
93+
}

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
'URL' => Illuminate\Support\Facades\URL::class,
218218
'Uuid' => Webpatser\Uuid\Uuid::class,
219219
'Validator' => Illuminate\Support\Facades\Validator::class,
220+
'Version' => Pterodactyl\Facades\Version::class,
220221
'View' => Illuminate\Support\Facades\View::class,
221222

222223
],

resources/views/admin/index.blade.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@
2424
@endsection
2525

2626
@section('content')
27-
<div class="col-md-12">
28-
<ul class="breadcrumb">
29-
<li class="active">Admin Control</li>
30-
</ul>
31-
<h3 class="nopad">Pterodactyl Admin Control Panel</h3><hr />
32-
<p>Welcome to the most advanced, lightweight, and user-friendly open source game server control panel.</p>
33-
<p>You are running version <code>{{ config('app.version') }}</code>.</p>
27+
<div class="row">
28+
<div class="col-md-12">
29+
<ul class="breadcrumb">
30+
<li class="active">Admin Control</li>
31+
</ul>
32+
<h3 class="nopad">Pterodactyl Admin Control Panel</h3><hr />
33+
@if (Version::isLatestPanel())
34+
<div class="alert alert-success">You are running Pterodactyl Panel version <code>{{ Version::getCurrentPanel() }}</code>. Your panel is up-to-date!</div>
35+
@else
36+
<div class="alert alert-danger">
37+
Your panel is <strong>not up-to-date!</strong> The latest version is <a href="https://github.com/Pterodactyl/Panel/releases/v{{ Version::getPanel() }}" target="_blank"><code>{{ Version::getPanel() }}</code></a> and you are currently running version <code>{{ Version::getCurrentPanel() }}</code>.
38+
</div>
39+
@endif
40+
</div>
41+
</div>
42+
<div class="row">
43+
<div class="col-xs-4 text-center">
44+
<a href="https://discord.gg/0gYt8oU8QOkDhKLS"><button class="btn btn-sm btn-warning" style="width:100%;"><i class="fa fa-fw fa-support"></i> Get Help <small>(via Discord)</small></button></a>
45+
</div>
46+
<div class="col-xs-4 text-center">
47+
<a href="https://docs.pterodactyl.io"><button class="btn btn-sm btn-default" style="width:100%;"><i class="fa fa-fw fa-link"></i> Documentation</button></a>
48+
</div>
49+
<div class="col-xs-4 text-center">
50+
<a href="https://github.com/Pterodactyl/Panel"><button class="btn btn-sm btn-default" style="width:100%;"><i class="fa fa-fw fa-support"></i> Github</button></a>
51+
</div>
3452
</div>
3553
<script>
3654
$(document).ready(function () {

resources/views/admin/nodes/view.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<tbody>
7272
<tr>
7373
<td>Daemon Version</td>
74-
<td><code data-attr="info-version"><i class="fa fa-refresh fa-fw fa-spin"></i></code></td>
74+
<td><code data-attr="info-version"><i class="fa fa-refresh fa-fw fa-spin"></i></code> (Latest: <code>{{ Version::getPanel() }}</code>)</td>
7575
</tr>
7676
<tr>
7777
<td>System Information</td>

0 commit comments

Comments
 (0)