Get dashboard in a more working state

This commit is contained in:
Dane Everitt 2018-06-05 23:42:34 -07:00
parent e948d81d8a
commit 5bcabbde35
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 69 additions and 47 deletions

View file

@ -2,7 +2,6 @@
namespace Pterodactyl\Http; namespace Pterodactyl\Http;
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
use Pterodactyl\Models\ApiKey; use Pterodactyl\Models\ApiKey;
use Illuminate\Auth\Middleware\Authorize; use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\Authenticate; use Illuminate\Auth\Middleware\Authenticate;
@ -21,6 +20,7 @@ use Illuminate\Routing\Middleware\SubstituteBindings;
use Pterodactyl\Http\Middleware\AccessingValidServer; use Pterodactyl\Http\Middleware\AccessingValidServer;
use Pterodactyl\Http\Middleware\Api\SetSessionDriver; use Pterodactyl\Http\Middleware\Api\SetSessionDriver;
use Illuminate\View\Middleware\ShareErrorsFromSession; use Illuminate\View\Middleware\ShareErrorsFromSession;
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
use Pterodactyl\Http\Middleware\RedirectIfAuthenticated; use Pterodactyl\Http\Middleware\RedirectIfAuthenticated;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth; use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Pterodactyl\Http\Middleware\Api\AuthenticateIPAccess; use Pterodactyl\Http\Middleware\Api\AuthenticateIPAccess;
@ -71,7 +71,7 @@ class Kernel extends HttpKernel
RequireTwoFactorAuthentication::class, RequireTwoFactorAuthentication::class,
], ],
'api' => [ 'api' => [
'throttle:120,1', 'throttle:240,1',
ApiSubstituteBindings::class, ApiSubstituteBindings::class,
SetSessionDriver::class, SetSessionDriver::class,
'api..key:' . ApiKey::TYPE_APPLICATION, 'api..key:' . ApiKey::TYPE_APPLICATION,
@ -79,7 +79,9 @@ class Kernel extends HttpKernel
AuthenticateIPAccess::class, AuthenticateIPAccess::class,
], ],
'client-api' => [ 'client-api' => [
'throttle:60,1', 'throttle:240,1',
EncryptCookies::class,
StartSession::class,
SubstituteClientApiBindings::class, SubstituteClientApiBindings::class,
SetSessionDriver::class, SetSessionDriver::class,
'api..key:' . ApiKey::TYPE_ACCOUNT, 'api..key:' . ApiKey::TYPE_ACCOUNT,

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Middleware\Api;
use Closure; use Closure;
use Lcobucci\JWT\Parser; use Lcobucci\JWT\Parser;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use Illuminate\Support\Str;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\ApiKey; use Pterodactyl\Models\ApiKey;
use Illuminate\Auth\AuthManager; use Illuminate\Auth\AuthManager;
@ -63,19 +64,24 @@ class AuthenticateKey
public function handle(Request $request, Closure $next, int $keyType) public function handle(Request $request, Closure $next, int $keyType)
{ {
if (is_null($request->bearerToken())) { if (is_null($request->bearerToken())) {
if (! Str::startsWith($request->route()->getName(), ['api.client']) && ! $request->user()) {
throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']); throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']);
} }
$raw = $request->bearerToken();
// This is an internal JWT, treat it differently to get the correct user before passing it along.
if (strlen($raw) > ApiKey::IDENTIFIER_LENGTH + ApiKey::KEY_LENGTH) {
$model = $this->authenticateJWT($raw);
} else {
$model = $this->authenticateApiKey($raw, $keyType);
} }
if (is_null($request->bearerToken())) {
$model = (new ApiKey)->forceFill([
'user_id' => $request->user()->id,
'key_type' => ApiKey::TYPE_ACCOUNT,
]);
}
if (! isset($model)) {
$raw = $request->bearerToken();
$model = $this->authenticateApiKey($raw, $keyType);
$this->auth->guard()->loginUsingId($model->user_id); $this->auth->guard()->loginUsingId($model->user_id);
}
$request->attributes->set('api_key', $model); $request->attributes->set('api_key', $model);
return $next($request); return $next($request);

View file

@ -3,6 +3,8 @@ import Vuex from 'vuex';
import vuexI18n from 'vuex-i18n'; import vuexI18n from 'vuex-i18n';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
require('./bootstrap');
// Helpers // Helpers
import { Ziggy } from './helpers/ziggy'; import { Ziggy } from './helpers/ziggy';
import Locales from './../../../resources/lang/locales'; import Locales from './../../../resources/lang/locales';
@ -32,6 +34,4 @@ const router = new VueRouter({
mode: 'history', routes mode: 'history', routes
}); });
require('./bootstrap');
const app = new Vue({ store, router }).$mount('#pterodactyl'); const app = new Vue({ store, router }).$mount('#pterodactyl');

View file

@ -1,3 +1,5 @@
import axios from './helpers/axios';
window._ = require('lodash'); window._ = require('lodash');
/** /**
@ -10,24 +12,7 @@ try {
window.$ = window.jQuery = require('jquery'); window.$ = window.jQuery = require('jquery');
} catch (e) {} } catch (e) {}
/** window.axios = axios;
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['Accept'] = 'application/json';
window.axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token || '';
if (typeof phpdebugbar !== 'undefined') {
window.axios.interceptors.response.use(function (response) {
phpdebugbar.ajaxHandler.handle(response.request);
return response;
});
}
/** /**
* Next we will register the CSRF Token as a common header with Axios so that * Next we will register the CSRF Token as a common header with Axios so that

View file

@ -18,7 +18,7 @@
</div> </div>
<transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start" v-else> <transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start" v-else>
<server-box <server-box
v-for="(server, index) in servers.models" v-for="(server, index) in servers"
v-bind:key="index" v-bind:key="index"
v-bind:server="server" v-bind:server="server"
/> />

View file

@ -0,0 +1,19 @@
/**
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
let axios = require('axios');
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
axios.defaults.headers.common['Accept'] = 'application/json';
if (typeof phpdebugbar !== 'undefined') {
axios.interceptors.response.use(function (response) {
phpdebugbar.ajaxHandler.handle(response.request);
return response;
});
}
export default axios;

View file

@ -1,3 +1,21 @@
export default class Server { export default class Server {
constructor({
identifier,
uuid,
name,
node,
description,
allocation,
limits,
feature_limits
}) {
this.identifier = identifier;
this.uuid = uuid;
this.name = name;
this.node = node;
this.description = description;
this.allocation = allocation;
this.limits = limits;
this.feature_limits = feature_limits;
}
} }

View file

@ -1,25 +1,21 @@
import axios from './../helpers/axios';
export default class User { export default class User {
/** /**
* Get a new user model by hitting the Panel API using the authentication token * Get a new user model by hitting the Panel API using the authentication token
* provided. If no user can be retrieved null will be returned. * provided. If no user can be retrieved null will be returned.
* *
* @param {string} token
* @param {string} cookie
* @return {User|null} * @return {User|null}
*/ */
static fromCookie(token, cookie = 'pterodactyl_session') { static fromCookie() {
window.axios.get('/api/client/account', { axios.get('/api/client/account')
headers: {
Cookie: `${cookie}=${token}`,
}
})
.then(response => { .then(response => {
return new User(response.data.attributes); return new User(response.data.attributes);
}) })
.catch(err => { .catch(err => {
console.error(err); console.error(err);
return null; return null;
}) });
} }
/** /**

View file

@ -1,6 +1,6 @@
import auth from './modules/auth'; import auth from './modules/auth';
export default { export default {
// strict: process.env.NODE_ENV !== 'production', strict: process.env.NODE_ENV !== 'production',
modules: { auth }, modules: { auth },
}; };

View file

@ -4,11 +4,7 @@ const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').de
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
user: () => { user: null,
const data = JSON.parse(localStorage.getItem('token'));
return User.fromCookie(data.value, data.name);
}
}, },
getters: { getters: {
/** /**