Skip to content

Commit 378a185

Browse files
committed
Merge branch 'feature/vuejs-serverlist' into feature/vue-serverview
2 parents 5dd9ed2 + aa61afb commit 378a185

File tree

21 files changed

+497
-68
lines changed

21 files changed

+497
-68
lines changed

app/Http/Controllers/Api/Client/ClientController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function __construct(ServerRepositoryInterface $repository)
3535
*/
3636
public function index(GetServersRequest $request): array
3737
{
38-
$servers = $this->repository->filterUserAccessServers($request->user(), User::FILTER_LEVEL_SUBUSER);
38+
$servers = $this->repository
39+
->setSearchTerm($request->input('query'))
40+
->filterUserAccessServers($request->user(), User::FILTER_LEVEL_ALL);
3941

4042
return $this->fractal->collection($servers)
4143
->transformWith($this->getTransformer(ServerTransformer::class))

app/Http/Controllers/Auth/LoginController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Pterodactyl\Http\Controllers\Auth;
44

5+
use Lcobucci\JWT\Builder;
56
use Illuminate\Http\Request;
67
use Illuminate\Http\JsonResponse;
78
use Illuminate\Contracts\View\View;
9+
use Lcobucci\JWT\Signer\Hmac\Sha256;
810
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
911

1012
class LoginController extends AbstractLoginController
@@ -63,11 +65,26 @@ public function login(Request $request): JsonResponse
6365
'request_ip' => $request->ip(),
6466
], 5);
6567

66-
return response()->json(['complete' => false, 'token' => $token]);
68+
return response()->json(['complete' => false, 'login_token' => $token]);
6769
}
6870

71+
$signer = new Sha256();
72+
$token = (new Builder)->setIssuer('http://pterodactyl.local')
73+
->setAudience('http://pterodactyl.local')
74+
->setId(str_random(12), true)
75+
->setIssuedAt(time())
76+
->setNotBefore(time())
77+
->setExpiration(time() + 3600)
78+
->set('uid', $user->id)
79+
->sign($signer, env('APP_JWT_KEY'))
80+
->getToken();
81+
6982
$this->auth->guard()->login($user, true);
7083

71-
return response()->json(['complete' => true]);
84+
return response()->json([
85+
'complete' => true,
86+
'intended' => $this->redirectPath(),
87+
'token' => $token->__toString(),
88+
]);
7289
}
7390
}

app/Http/Middleware/Api/AuthenticateKey.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Http\Middleware\Api;
44

55
use Closure;
6+
use Lcobucci\JWT\Parser;
67
use Cake\Chronos\Chronos;
78
use Illuminate\Http\Request;
89
use Pterodactyl\Models\ApiKey;
@@ -63,6 +64,23 @@ public function handle(Request $request, Closure $next, int $keyType)
6364
}
6465

6566
$raw = $request->bearerToken();
67+
68+
// This is an internal JWT, treat it differently to get the correct user
69+
// before passing it along.
70+
if (strlen($raw) > ApiKey::IDENTIFIER_LENGTH + ApiKey::KEY_LENGTH) {
71+
$token = (new Parser)->parse($raw);
72+
73+
$model = (new ApiKey)->fill([
74+
'user_id' => $token->getClaim('uid'),
75+
'key_type' => ApiKey::TYPE_ACCOUNT,
76+
]);
77+
78+
$this->auth->guard()->loginUsingId($token->getClaim('uid'));
79+
$request->attributes->set('api_key', $model);
80+
81+
return $next($request);
82+
}
83+
6684
$identifier = substr($raw, 0, ApiKey::IDENTIFIER_LENGTH);
6785
$token = substr($raw, ApiKey::IDENTIFIER_LENGTH);
6886

app/Http/Middleware/Api/SetSessionDriver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7-
use Barryvdh\Debugbar\LaravelDebugbar;
87
use Illuminate\Contracts\Foundation\Application;
98
use Illuminate\Contracts\Config\Repository as ConfigRepository;
109

@@ -41,10 +40,6 @@ public function __construct(Application $app, ConfigRepository $config)
4140
*/
4241
public function handle(Request $request, Closure $next)
4342
{
44-
if ($this->config->get('app.debug')) {
45-
$this->app->make(LaravelDebugbar::class)->disable();
46-
}
47-
4843
$this->config->set('session.driver', 'array');
4944

5045
return $next($request);

app/Transformers/Api/Client/ServerTransformer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public function transform(Server $server): array
2828
'identifier' => $server->uuidShort,
2929
'uuid' => $server->uuid,
3030
'name' => $server->name,
31+
'node' => $server->node->name,
3132
'description' => $server->description,
33+
'allocation' => [
34+
'ip' => $server->allocation->alias,
35+
'port' => $server->allocation->port,
36+
],
3237
'limits' => [
3338
'memory' => $server->memory,
3439
'swap' => $server->swap,

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"laracasts/utilities": "^3.0",
2727
"laravel/framework": "5.6.*",
2828
"laravel/tinker": "^1.0",
29+
"lcobucci/jwt": "^3.2",
2930
"lord/laroute": "^2.4",
3031
"matriphe/iso-639": "^1.2",
3132
"nesbot/carbon": "^1.22",

composer.lock

Lines changed: 59 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
"gulp-rev": "^8.1.1",
2525
"gulp-uglify-es": "^1.0.1",
2626
"jquery": "^3.3.1",
27+
"jwt-decode": "^2.2.0",
2728
"lodash": "^4.17.5",
2829
"postcss": "^6.0.21",
2930
"postcss-import": "^11.1.0",
3031
"postcss-preset-env": "^3.4.0",
3132
"postcss-scss": "^1.0.4",
3233
"tailwindcss": "^0.5.1",
34+
"vee-validate": "^2.0.9",
3335
"vue": "^2.5.7",
3436
"vue-axios": "^2.1.1",
3537
"vue-devtools": "^3.1.9",
3638
"vue-loader": "^14.2.2",
39+
"vue-mc": "^0.2.4",
3740
"vue-router": "^3.0.1",
3841
"vue-template-compiler": "^2.5.16",
3942
"vueify-insert-css": "^1.0.0",

resources/assets/scripts/app.js

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@ import faSolid from '@fortawesome/fontawesome-free-solid';
1313
import FontAwesomeIcon from '@fortawesome/vue-fontawesome';
1414
fontawesome.library.add(faSolid);
1515

16-
// Base Vuejs Templates
17-
import Login from './components/auth/Login';
18-
import Dashboard from './components/dashboard/Dashboard';
19-
import Account from './components/dashboard/Account';
20-
import ResetPassword from './components/auth/ResetPassword';
21-
import { Server, ServerConsole, ServerAllocations, ServerDatabases, ServerFiles, ServerSchedules, ServerSettings, ServerSubusers } from './components/server';
16+
import { routes } from './routes';
17+
import { storeData } from './store';
2218

2319
window.events = new Vue;
2420
window.Ziggy = Ziggy;
2521

2622
Vue.use(Vuex);
27-
28-
const store = new Vuex.Store();
23+
const store = new Vuex.Store(storeData);
2924
const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default;
3025

3126
Vue.config.productionTip = false;
@@ -41,35 +36,7 @@ Vue.i18n.set('en');
4136
Vue.component('font-awesome-icon', FontAwesomeIcon);
4237

4338
const router = new VueRouter({
44-
mode: 'history',
45-
routes: [
46-
{ name: 'login', path: '/auth/login', component: Login },
47-
{ name: 'forgot-password', path: '/auth/password', component: Login },
48-
{ name: 'checkpoint', path: '/checkpoint', component: Login },
49-
{
50-
name: 'reset-password',
51-
path: '/auth/password/reset/:token',
52-
component: ResetPassword,
53-
props: function (route) {
54-
return { token: route.params.token, email: route.query.email || '' };
55-
}
56-
},
57-
{ name : 'index', path: '/', component: Dashboard },
58-
{ name : 'account', path: '/account', component: Account },
59-
{ name : 'account-api', path: '/account/api', component: Account },
60-
{ name : 'account-security', path: '/account/security', component: Account },
61-
{ path: '/server/:id', component: Server,
62-
children: [
63-
{ name: 'server', path: '', component: ServerConsole },
64-
{ name: 'server-files', path: 'files', component: ServerFiles },
65-
{ name: 'server-subusers', path: 'subusers', component: ServerSubusers },
66-
{ name: 'server-schedules', path: 'schedules', component: ServerSchedules },
67-
{ name: 'server-databases', path: 'databases', component: ServerDatabases },
68-
{ name: 'server-allocations', path: 'allocations', component: ServerAllocations },
69-
{ name: 'server-settings', path: 'settings', component: ServerSettings },
70-
]
71-
}
72-
]
39+
mode: 'history', routes
7340
});
7441

7542
require('./bootstrap');

0 commit comments

Comments
 (0)