Skip to content

Commit 5bcabbd

Browse files
committed
Get dashboard in a more working state
1 parent e948d81 commit 5bcabbd

File tree

10 files changed

+69
-47
lines changed

10 files changed

+69
-47
lines changed

app/Http/Kernel.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pterodactyl\Http;
44

5-
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
65
use Pterodactyl\Models\ApiKey;
76
use Illuminate\Auth\Middleware\Authorize;
87
use Illuminate\Auth\Middleware\Authenticate;
@@ -21,6 +20,7 @@
2120
use Pterodactyl\Http\Middleware\AccessingValidServer;
2221
use Pterodactyl\Http\Middleware\Api\SetSessionDriver;
2322
use Illuminate\View\Middleware\ShareErrorsFromSession;
23+
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
2424
use Pterodactyl\Http\Middleware\RedirectIfAuthenticated;
2525
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
2626
use Pterodactyl\Http\Middleware\Api\AuthenticateIPAccess;
@@ -71,15 +71,17 @@ class Kernel extends HttpKernel
7171
RequireTwoFactorAuthentication::class,
7272
],
7373
'api' => [
74-
'throttle:120,1',
74+
'throttle:240,1',
7575
ApiSubstituteBindings::class,
7676
SetSessionDriver::class,
7777
'api..key:' . ApiKey::TYPE_APPLICATION,
7878
AuthenticateApplicationUser::class,
7979
AuthenticateIPAccess::class,
8080
],
8181
'client-api' => [
82-
'throttle:60,1',
82+
'throttle:240,1',
83+
EncryptCookies::class,
84+
StartSession::class,
8385
SubstituteClientApiBindings::class,
8486
SetSessionDriver::class,
8587
'api..key:' . ApiKey::TYPE_ACCOUNT,

app/Http/Middleware/Api/AuthenticateKey.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use Lcobucci\JWT\Parser;
77
use Cake\Chronos\Chronos;
8+
use Illuminate\Support\Str;
89
use Illuminate\Http\Request;
910
use Pterodactyl\Models\ApiKey;
1011
use Illuminate\Auth\AuthManager;
@@ -63,19 +64,24 @@ public function __construct(ApiKeyRepositoryInterface $repository, AuthManager $
6364
public function handle(Request $request, Closure $next, int $keyType)
6465
{
6566
if (is_null($request->bearerToken())) {
66-
throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']);
67+
if (! Str::startsWith($request->route()->getName(), ['api.client']) && ! $request->user()) {
68+
throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']);
69+
}
6770
}
6871

69-
$raw = $request->bearerToken();
72+
if (is_null($request->bearerToken())) {
73+
$model = (new ApiKey)->forceFill([
74+
'user_id' => $request->user()->id,
75+
'key_type' => ApiKey::TYPE_ACCOUNT,
76+
]);
77+
}
7078

71-
// This is an internal JWT, treat it differently to get the correct user before passing it along.
72-
if (strlen($raw) > ApiKey::IDENTIFIER_LENGTH + ApiKey::KEY_LENGTH) {
73-
$model = $this->authenticateJWT($raw);
74-
} else {
79+
if (! isset($model)) {
80+
$raw = $request->bearerToken();
7581
$model = $this->authenticateApiKey($raw, $keyType);
82+
$this->auth->guard()->loginUsingId($model->user_id);
7683
}
7784

78-
$this->auth->guard()->loginUsingId($model->user_id);
7985
$request->attributes->set('api_key', $model);
8086

8187
return $next($request);

resources/assets/scripts/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Vuex from 'vuex';
33
import vuexI18n from 'vuex-i18n';
44
import VueRouter from 'vue-router';
55

6+
require('./bootstrap');
7+
68
// Helpers
79
import { Ziggy } from './helpers/ziggy';
810
import Locales from './../../../resources/lang/locales';
@@ -32,6 +34,4 @@ const router = new VueRouter({
3234
mode: 'history', routes
3335
});
3436

35-
require('./bootstrap');
36-
3737
const app = new Vue({ store, router }).$mount('#pterodactyl');

resources/assets/scripts/bootstrap.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import axios from './helpers/axios';
2+
13
window._ = require('lodash');
24

35
/**
@@ -10,24 +12,7 @@ try {
1012
window.$ = window.jQuery = require('jquery');
1113
} catch (e) {}
1214

13-
/**
14-
* We'll load the axios HTTP library which allows us to easily issue requests
15-
* to our Laravel back-end. This library automatically handles sending the
16-
* CSRF token as a header based on the value of the "XSRF" token cookie.
17-
*/
18-
19-
window.axios = require('axios');
20-
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
21-
window.axios.defaults.headers.common['Accept'] = 'application/json';
22-
window.axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token || '';
23-
24-
if (typeof phpdebugbar !== 'undefined') {
25-
window.axios.interceptors.response.use(function (response) {
26-
phpdebugbar.ajaxHandler.handle(response.request);
27-
28-
return response;
29-
});
30-
}
15+
window.axios = axios;
3116

3217
/**
3318
* Next we will register the CSRF Token as a common header with Axios so that

resources/assets/scripts/components/dashboard/Dashboard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</div>
1919
<transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start" v-else>
2020
<server-box
21-
v-for="(server, index) in servers.models"
21+
v-for="(server, index) in servers"
2222
v-bind:key="index"
2323
v-bind:server="server"
2424
/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* We'll load the axios HTTP library which allows us to easily issue requests
3+
* to our Laravel back-end. This library automatically handles sending the
4+
* CSRF token as a header based on the value of the "XSRF" token cookie.
5+
*/
6+
7+
let axios = require('axios');
8+
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
9+
axios.defaults.headers.common['Accept'] = 'application/json';
10+
11+
if (typeof phpdebugbar !== 'undefined') {
12+
axios.interceptors.response.use(function (response) {
13+
phpdebugbar.ajaxHandler.handle(response.request);
14+
15+
return response;
16+
});
17+
}
18+
19+
export default axios;
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
export default class Server {
2-
2+
constructor({
3+
identifier,
4+
uuid,
5+
name,
6+
node,
7+
description,
8+
allocation,
9+
limits,
10+
feature_limits
11+
}) {
12+
this.identifier = identifier;
13+
this.uuid = uuid;
14+
this.name = name;
15+
this.node = node;
16+
this.description = description;
17+
this.allocation = allocation;
18+
this.limits = limits;
19+
this.feature_limits = feature_limits;
20+
}
321
}

resources/assets/scripts/models/user.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1+
import axios from './../helpers/axios';
2+
13
export default class User {
24
/**
35
* Get a new user model by hitting the Panel API using the authentication token
46
* provided. If no user can be retrieved null will be returned.
57
*
6-
* @param {string} token
7-
* @param {string} cookie
88
* @return {User|null}
99
*/
10-
static fromCookie(token, cookie = 'pterodactyl_session') {
11-
window.axios.get('/api/client/account', {
12-
headers: {
13-
Cookie: `${cookie}=${token}`,
14-
}
15-
})
10+
static fromCookie() {
11+
axios.get('/api/client/account')
1612
.then(response => {
1713
return new User(response.data.attributes);
1814
})
1915
.catch(err => {
2016
console.error(err);
2117
return null;
22-
})
18+
});
2319
}
2420

2521
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import auth from './modules/auth';
22

33
export default {
4-
// strict: process.env.NODE_ENV !== 'production',
4+
strict: process.env.NODE_ENV !== 'production',
55
modules: { auth },
66
};

resources/assets/scripts/store/modules/auth.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').de
44
export default {
55
namespaced: true,
66
state: {
7-
user: () => {
8-
const data = JSON.parse(localStorage.getItem('token'));
9-
10-
return User.fromCookie(data.value, data.name);
11-
}
7+
user: null,
128
},
139
getters: {
1410
/**

0 commit comments

Comments
 (0)