add initial api management page
This commit is contained in:
parent
09d9f2a064
commit
a6bc36a710
7 changed files with 169 additions and 1 deletions
32
app/Http/Controllers/Admin/APIController.php
Normal file
32
app/Http/Controllers/Admin/APIController.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Alert;
|
||||
use Log;
|
||||
use Pterodactyl\Models;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class APIController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function getIndex(Request $request)
|
||||
{
|
||||
$keys = Models\APIKey::all();
|
||||
foreach($keys as &$key) {
|
||||
$key->permissions = Models\APIPermission::where('key_id', $key->id)->get();
|
||||
}
|
||||
|
||||
return view('admin.api.index', [
|
||||
'keys' => $keys
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -203,7 +203,7 @@ class AdminRoutes {
|
|||
|
||||
});
|
||||
|
||||
// Server Routes
|
||||
// Location Routes
|
||||
$router->group([
|
||||
'prefix' => 'admin/locations',
|
||||
'middleware' => [
|
||||
|
@ -218,6 +218,29 @@ class AdminRoutes {
|
|||
]);
|
||||
});
|
||||
|
||||
// API Routes
|
||||
$router->group([
|
||||
'prefix' => 'admin/api',
|
||||
'middleware' => [
|
||||
'auth',
|
||||
'admin',
|
||||
'csrf'
|
||||
]
|
||||
], function () use ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'admin.api',
|
||||
'uses' => 'Admin\APIController@getIndex'
|
||||
]);
|
||||
$router->get('/new', [
|
||||
'as' => 'admin.api.new',
|
||||
'uses' => 'Admin\APIController@getNew'
|
||||
]);
|
||||
$router->delete('/revoke/{key?}', [
|
||||
'as' => 'admin.api.revoke',
|
||||
'uses' => 'Admin\APIController@deleteKey'
|
||||
]);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,4 +14,18 @@ class APIKey extends Model
|
|||
*/
|
||||
protected $table = 'api_keys';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['secret'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
}
|
||||
|
|
|
@ -14,4 +14,12 @@ class APIPermission extends Model
|
|||
*/
|
||||
protected $table = 'api_permissions';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
|
||||
}
|
||||
|
|
90
resources/views/admin/api/index.blade.php
Normal file
90
resources/views/admin/api/index.blade.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
@extends('layouts.admin')
|
||||
|
||||
@section('title')
|
||||
API Management
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="col-md-12">
|
||||
<ul class="breadcrumb">
|
||||
<li><a href="/admin">Admin Control</a></li>
|
||||
<li class="active">API Management</li>
|
||||
</ul>
|
||||
<h3>API Key Information</h3><hr />
|
||||
<table class="table table-bordered table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>API Public Key</th>
|
||||
<th>Allowed IPs</th>
|
||||
<th>Permissions</th>
|
||||
<th class="text-center">Created</th>
|
||||
<th class="text-center"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($keys as $key)
|
||||
<tr>
|
||||
<td><code>{{ $key->public }}</code></td>
|
||||
<td>
|
||||
@if (is_null($key->allowed_ips))
|
||||
<code>*</code>
|
||||
@else
|
||||
@foreach(json_decode($key->allowed_ips) as $ip)
|
||||
<code style="line-height:2;">{{ $ip }}</code><br />
|
||||
@endforeach
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@foreach(json_decode($key->permissions) as &$perm)
|
||||
<code style="line-height:2;">{{ $perm->permission }}</code><br />
|
||||
@endforeach
|
||||
</td>
|
||||
<td class="text-center">{{ $key->created_at }}</td>
|
||||
<td class="text-center"><a href="#delete" class="text-danger" data-action="delete" data-attr="{{ $key->public }}"><i class="fa fa-trash"></i></a></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="well">
|
||||
<a href="{{ route('admin.api.new') }}"><button class="btn btn-success btn-sm">Create New API Key</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#sidebar_links').find("a[href='/admin/api']").addClass('active');
|
||||
$('[data-action="delete"]').click(function (event) {
|
||||
var self = $(this);
|
||||
event.preventDefault();
|
||||
swal({
|
||||
type: 'error',
|
||||
title: 'Revoke API Key',
|
||||
text: 'Once this API key is revoked any applications currently using it will stop working.',
|
||||
showCancelButton: true,
|
||||
allowOutsideClick: true,
|
||||
confirmButtonText: 'Revoke',
|
||||
confirmButtonColor: '#d9534f',
|
||||
}, function () {
|
||||
$.ajax({
|
||||
method: 'DELETE',
|
||||
url: '{{ route('admin.api.revoke') }}/' + self.data('attr'),
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
}).done(function (data) {
|
||||
swal({
|
||||
type: 'success',
|
||||
});
|
||||
self.parent().parent().slideUp();
|
||||
}).fail(function (jqXHR) {
|
||||
console.error(jqXHR);
|
||||
swal({
|
||||
type: 'error',
|
||||
title: 'Whoops!',
|
||||
text: 'An error occured while attempting to revoke this key.'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endsection
|
0
resources/views/admin/api/new.blade.php
Normal file
0
resources/views/admin/api/new.blade.php
Normal file
|
@ -61,6 +61,7 @@
|
|||
<a href="#" class="list-group-item list-group-item-heading"><strong>Management</strong></a>
|
||||
<a href="/admin" id="sidenav_admin-index" class="list-group-item">Admin Index</a>
|
||||
<a href="/admin/settings" class="list-group-item">General Settings</a>
|
||||
<a href="/admin/api" class="list-group-item">API Management</a>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<a href="#" class="list-group-item list-group-item-heading"><strong>Account Management</strong></a>
|
||||
|
|
Loading…
Reference in a new issue