Skip to content

Commit 2fc852c

Browse files
committed
Push 'Account' and 'Security' pages as well as 'My Servers'
1 parent 1c85b1f commit 2fc852c

File tree

19 files changed

+1068
-3
lines changed

19 files changed

+1068
-3
lines changed

app/Http/Controllers/Base/SecurityController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function generateTotp(Request $request)
7979
public function setTotp(Request $request)
8080
{
8181
if (! $request->has('token')) {
82-
return response(null, 500);
82+
return response()->json([
83+
'error' => 'Request is missing token parameter.'
84+
], 500);
8385
}
8486

8587
$user = $request->user();
@@ -101,7 +103,7 @@ public function disableTotp(Request $request)
101103
if (! $request->has('token')) {
102104
Alert::danger('Missing required `token` field in request.')->flash();
103105

104-
return redirect()->route('account.totp');
106+
return redirect()->route('account.security');
105107
}
106108

107109
$user = $request->user();

app/Http/Routes/BaseRoutes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ public function map(Router $router)
6464
'uses' => 'Base\AccountController@index',
6565
]);
6666
$router->post('/password', [
67+
'as' => 'account.password',
6768
'uses' => 'Base\AccountController@password',
6869
]);
6970
$router->post('/email', [
71+
'as' => 'account.email',
7072
'uses' => 'Base\AccountController@email',
7173
]);
7274
});
@@ -113,6 +115,7 @@ public function map(Router $router)
113115
'uses' => 'Base\SecurityController@revoke',
114116
]);
115117
$router->put('/totp', [
118+
'as' => 'account.security.totp',
116119
'uses' => 'Base\SecurityController@generateTotp',
117120
]);
118121
$router->post('/totp', [

app/Http/Routes/ServerRoutes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function map(Router $router)
153153
$router->group(['prefix' => 'ajax'], function ($server) use ($router) {
154154
// Returns Server Status
155155
$router->get('status', [
156+
'as' => 'server.ajax.status',
156157
'uses' => 'Server\AjaxController@getStatus',
157158
]);
158159

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"dingo/api": "1.0.0-beta6",
2828
"aws/aws-sdk-php": "3.19.20",
2929
"predis/predis": "1.1.1",
30-
"laracasts/utilities": "2.1.0"
30+
"laracasts/utilities": "2.1.0",
31+
"lord/laroute": "^2.3"
3132
},
3233
"require-dev": {
3334
"fzaninotto/faker": "~1.4",

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
Prologue\Alerts\AlertsServiceProvider::class,
160160
Krucas\Settings\Providers\SettingsServiceProvider::class,
161161
Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class,
162+
Lord\Laroute\LarouteServiceProvider::class,
162163

163164
],
164165

config/laroute.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
* The destination path for the javascript file.
7+
*/
8+
'path' => 'public/js',
9+
10+
/*
11+
* The destination filename for the javascript file.
12+
*/
13+
'filename' => 'laroute',
14+
15+
/*
16+
* The namespace for the helper functions. By default this will bind them to
17+
* `window.laroute`.
18+
*/
19+
'namespace' => 'Router',
20+
21+
/*
22+
* Generate absolute URLs
23+
*
24+
* Set the Application URL in config/app.php
25+
*/
26+
'absolute' => false,
27+
28+
/*
29+
* The Filter Method
30+
*
31+
* 'all' => All routes except "'laroute' => false"
32+
* 'only' => Only "'laroute' => true" routes
33+
* 'force' => All routes, ignored "laroute" route parameter
34+
*/
35+
'filter' => 'all',
36+
37+
/*
38+
* Controller Namespace
39+
*
40+
* Set here your controller namespace (see RouteServiceProvider -> $namespace) for cleaner action calls
41+
* e.g. 'App\Http\Controllers'
42+
*/
43+
'action_namespace' => '',
44+
45+
/*
46+
* The path to the template `laroute.js` file. This is the file that contains
47+
* the ported helper Laravel url/route functions and the route data to go
48+
* with them.
49+
*/
50+
'template' => 'vendor/lord/laroute/src/templates/laroute.js',
51+
52+
/*
53+
* Appends a prefix to URLs. By default the prefix is an empty string.
54+
*
55+
*/
56+
'prefix' => '',
57+
58+
];

public/js/laroute.js

Lines changed: 186 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/themes/pterodactyl/css/pterodactyl.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@
3636
.btn-clear {
3737
background: transparent;
3838
}
39+
40+
.user-panel > .info {
41+
position: relative;
42+
left: 0;
43+
}
44+
45+
code {
46+
font-size: 85%;
47+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
$(document).ready(function () {
21+
$('#close_reload').click(function () {
22+
location.reload();
23+
});
24+
$('#do_2fa').submit(function (event) {
25+
event.preventDefault();
26+
27+
$.ajax({
28+
type: 'PUT',
29+
url: Router.route('account.security.totp'),
30+
headers: {
31+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
32+
}
33+
}).done(function (data) {
34+
var image = new Image();
35+
image.src = data.qrImage;
36+
$(image).load(function () {
37+
$('#hide_img_load').slideUp(function () {
38+
$('#qr_image_insert').attr('src', image.src).slideDown();
39+
});
40+
});
41+
$('#2fa_secret_insert').html(data.secret);
42+
$('#open2fa').modal('show');
43+
}).fail(function (jqXHR) {
44+
alert('An error occured while attempting to load the 2FA setup modal. Please try again.');
45+
console.error(jqXHR);
46+
});
47+
48+
});
49+
$('#2fa_token_verify').submit(function (event) {
50+
event.preventDefault();
51+
$('#submit_action').html('<i class="fa fa-spinner fa-spin"></i> Submit').addClass('disabled');
52+
53+
$.ajax({
54+
type: 'POST',
55+
url: Router.route('account.security.totp'),
56+
headers: {
57+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
58+
},
59+
data: {
60+
token: $('#2fa_token').val()
61+
}
62+
}).done(function (data) {
63+
$('#notice_box_2fa').hide();
64+
if (data === 'true') {
65+
$('#notice_box_2fa').html('<div class="alert alert-success">2-Factor Authentication has been enabled on your account. Press \'Close\' below to reload the page.</div>').slideDown();
66+
} else {
67+
$('#notice_box_2fa').html('<div class="alert alert-danger">The token provided was invalid.</div>').slideDown();
68+
}
69+
}).fail(function (jqXHR) {
70+
$('#notice_box_2fa').html('<div class="alert alert-danger">There was an error while attempting to enable 2-Factor Authentication on this account.</div>').slideDown();
71+
console.error(jqXHR);
72+
}).always(function () {
73+
$('#submit_action').html('Submit').removeClass('disabled');
74+
});
75+
});
76+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
var Status = {
21+
0: 'Offline',
22+
1: 'Online',
23+
2: 'Starting',
24+
3: 'Stopping'
25+
};
26+
27+
(function updateServerStatus () {
28+
$('.dynamic-update').each(function (index, data) {
29+
var element = $(this);
30+
var serverShortUUID = $(this).data('server');
31+
$.ajax({
32+
type: 'GET',
33+
url: Router.route('server.ajax.status', { server: serverShortUUID }),
34+
timeout: 5000,
35+
headers: {
36+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content'),
37+
}
38+
}).done(function (data) {
39+
if (typeof data.status === 'undefined') {
40+
element.find('[data-action="status"]').html('<span class="label label-default">Error</span>');
41+
return;
42+
}
43+
switch (data.status) {
44+
case 0:
45+
element.find('[data-action="status"]').html('<span class="label label-danger">Offline</span>');
46+
break;
47+
case 1:
48+
element.find('[data-action="status"]').html('<span class="label label-success">Online</span>');
49+
break;
50+
case 2:
51+
element.find('[data-action="status"]').html('<span class="label label-info">Starting</span>');
52+
break;
53+
case 3:
54+
element.find('[data-action="status"]').html('<span class="label label-info">Stopping</span>');
55+
break;
56+
}
57+
if (data.status !== 0) {
58+
var cpuMax = element.find('[data-action="cpu"]').data('cpumax');
59+
var currentCpu = data.proc.cpu.total;
60+
if (cpuMax !== 0) {
61+
currentCpu = parseFloat(((data.proc.cpu.total / cpuMax) * 100).toFixed(2).toString());
62+
}
63+
element.find('[data-action="memory"]').html(parseInt(data.proc.memory.total / (1024 * 1024)));
64+
element.find('[data-action="cpu"]').html(currentCpu);
65+
} else {
66+
element.find('[data-action="memory"]').html('--');
67+
element.find('[data-action="cpu"]').html('--');
68+
}
69+
}).fail(function (jqXHR) {
70+
console.error(jqXHR);
71+
element.find('[data-action="status"]').html('<span class="label label-default">Error</span>');
72+
});
73+
});
74+
setTimeout(updateServerStatus, 10000);
75+
})();

0 commit comments

Comments
 (0)