2022-01-15 02:23:50 +02:00
{% extends ../base.html %}
{% block meta %}
{% end %}
{% block title %}Crafty Controller - Edit User API Keys{% end %}
{% block content %}
< div class = "content-wrapper" >
<!-- Page Title Header Starts -->
< div class = "row page-title-header" >
< div class = "col-12" >
< div class = "page-header" >
< h4 class = "page-title" >
2022-01-20 00:05:14 -05:00
{{ translate('apiKeys', 'pageTitle', data['lang']) }} - {{ data['user']['user_id'] }}
2022-01-15 02:23:50 +02:00
< br / >
< small > UID: {{ data['user']['user_id'] }}< / small >
< / h4 >
< / div >
< / div >
< / div >
<!-- Page Title Header Ends -->
< div class = "row" >
< div class = "col-sm-12 grid-margin" >
< div class = "card" >
< div class = "card-body pt-0" >
< ul class = "nav nav-tabs col-md-12 tab-simple-styled " role = "tablist" >
< li class = "nav-item" >
< a class = "nav-link" href = "/panel/edit_user?id={{ data['user']['user_id'] }}&subpage=config"
role="tab"
aria-selected="false">
2022-01-20 00:05:14 -05:00
< i class = "fas fa-cogs" > < / i > {{ translate('apiKeys', 'config', data['lang']) }}< / a >
2022-01-15 02:23:50 +02:00
< / li >
< li class = "nav-item" >
< a class = "nav-link active" href = "/panel/edit_user_apikeys?id={{ data['user']['user_id'] }}"
role="tab"
aria-selected="true">
2022-01-20 00:05:14 -05:00
< i class = "fas fa-key" > < / i > {{ translate('apiKeys', 'apiKeys', data['lang']) }}< / a >
2022-01-15 02:23:50 +02:00
< / li >
< / ul >
< div class = "row" >
< div class = "col-md-7 col-sm-12" >
< div class = "card" >
< div class = "card-header header-sm d-flex justify-content-between align-items-center" >
2022-01-20 00:05:14 -05:00
< h4 class = "card-title" > < i class = "fas fa-key" > < / i > {{ translate('apiKeys', 'apiKeys', data['lang']) }}< / h4 >
2022-01-15 02:23:50 +02:00
< / div >
< div class = "card-body" >
< div class = "form-group" >
< div class = "table-responsive" >
< table class = "table table-hover" >
< thead >
< tr class = "rounded" >
<!-- <th>ID</th> -->
2022-01-20 00:05:14 -05:00
< th > {{ translate('apiKeys', 'name', data['lang']) }}< / th >
< th > {{ translate('apiKeys', 'created', data['lang']) }}< / th >
< th > {{ translate('apiKeys', 'superUser', data['lang']) }}< / th >
< th > {{ translate('apiKeys', 'perms', data['lang']) }}< / th >
< th > {{ translate('apiKeys', 'buttons', data['lang']) }}< / th >
2022-01-15 02:23:50 +02:00
< / tr >
< / thead >
< tbody >
{% for apikey in data['api_keys'] %}
< tr >
<!-- <td>{ - { apikey.token_id } - }</td> -->
< td > {{ apikey.name }}< / td >
< td > {{ apikey.created.strftime('%d/%m/%Y %H:%M:%S') }}< / td >
< td >
{% if apikey.superuser %}
< span class = "text-success" >
2022-01-20 00:05:14 -05:00
< i class = "fas fa-check-square" > < / i > {{ translate('apiKeys', 'yes', data['lang']) }}
2022-01-15 02:23:50 +02:00
< / span >
{% else %}
< span class = "text-danger" >
2022-01-20 00:05:14 -05:00
< i class = "far fa-times-square" > < / i > {{ translate('apiKeys', 'no', data['lang']) }}
2022-01-15 02:23:50 +02:00
< / span >
{% end %}
< / td >
2022-01-20 00:05:14 -05:00
< td > {{ translate('apiKeys', 'server', data['lang']) }} {{ apikey.server_permissions }}
{{ translate('apiKeys', 'crafty', data['lang']) }} {{ apikey.crafty_permissions }}< / td >
2022-01-15 02:23:50 +02:00
< td >
< button
class="btn btn-danger delete-api-key"
data-key-id="{{ apikey.token_id }}"
data-key-name="{{ apikey.name }}"
>{{ translate('panelConfig', 'delete', data['lang']) }}< / button >
< button
class="btn btn-outline-primary get-a-token"
data-key-id="{{ apikey.token_id }}"
data-key-name="{{ apikey.name }}"
2022-01-20 00:05:14 -05:00
>{{ translate('apiKeys', 'getToken', data['lang']) }}
2022-01-15 02:23:50 +02:00
< / button >
< / td >
< / tr >
{% end %}
< / tbody >
< / table >
< / div >
< / div >
< / div >
< / div >
< / div >
< div class = "col-md-5 col-sm-12" >
< div class = "card" >
< div class = "card-header header-sm d-flex justify-content-between align-items-center" >
2022-01-20 00:05:14 -05:00
< h4 class = "card-title" > < i class = "fas fa-plus" > < / i > {{ translate('apiKeys', 'createNew', data['lang']) }}< / h4 >
2022-01-15 02:23:50 +02:00
< / div >
< div class = "card-body" >
< form id = "user_form" class = "forms-sample" method = "post"
action="/panel/edit_user_apikeys">
{% raw xsrf_form_html() %}
< input type = "hidden" name = "id" value = "{{ data['user']['user_id'] }}" >
< div class = "form-group" >
2022-01-20 00:05:14 -05:00
< label class = "form-label" for = "username" > {{ translate('apiKeys', 'name', data['lang']) }}< small
class="text-muted ml-1"> - {{ translate('apiKeys', 'nameDesc', data['lang']) }}< / small > < / label >
2022-01-15 02:23:50 +02:00
< input type = "text" class = "form-control" name = "name" id = "name"
placeholder="API Key">
< / div >
< table class = "table table-hover mb-3" >
< thead >
< tr class = "rounded" >
2022-01-20 00:05:14 -05:00
< th > {{ translate('apiKeys', 'permName', data['lang']) }}< / th >
< th > {{ translate('apiKeys', 'auth', data['lang']) }}< / th >
2022-01-15 02:23:50 +02:00
< / tr >
< / thead >
< tbody >
{% for permission in data['server_permissions_all'] %}
< tr >
< td > < label
for="permission_{{ permission.name }}">{{ permission.name }}< / label >
< / td >
< td >
< input type = "checkbox" class = ""
id="permission_{{ permission.name }}"
name="permission_{{ permission.name }}" value="1">
< / td >
< / tr >
{% end %}
{% for permission in data['crafty_permissions_all'] %}
< tr >
< td > < label
for="permission_{{ permission.name }}">{{ permission.name }}< / label >
< / td >
< td >
< input type = "checkbox" class = ""
id="permission_{{ permission.name }}"
name="permission_{{ permission.name }}" value="1">
< / td >
< / tr >
{% end %}
< / tbody >
< / table >
< label for = "superuser" > Superuser< / label >
< input type = "checkbox" class = "" id = "superuser"
name="superuser" value="1">
< br / >
< button type = "submit" class = "btn btn-success mr-2" > < i class = "fas fa-plus" > < / i >
Create
< / button >
< button type = "reset" class = "btn btn-light" > < i
class="fas fa-undo-alt">< / i > {{ translate('panelConfig', 'cancel', data['lang']) }}
< / button >
< / form >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
<!-- content - wrapper ends -->
{% end %}
{% block js %}
< script >
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
function getCookie(name) {
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
return r ? r[1] : undefined;
}
$(document).ready(function () {
console.log("ready!");
$('.delete-api-key').click(function () {
var keyId = $(this).data("key-id");
var keyName = $(this).data("key-name");
bootbox.confirm({
title: `Remove API key ${keyName}?`,
message: "Do you want to delete this API key? This cannot be undone.",
buttons: {
cancel: {
label: '< i class = "fas fa-times" > < / i > {{ translate("panelConfig", "cancel", data['lang']) }}'
},
confirm: {
label: '< i class = "fas fa-check" > < / i > {{ translate("serverBackups", "confirm", data['lang']) }}'
}
},
callback: function (result) {
var token = getCookie("_xsrf")
$.ajax({
type: "DELETE",
headers: {'X-XSRFToken': token},
url: '/panel/remove_apikey?id=' + keyId,
success: function (data) {
location.reload();
},
});
}
});
})
$('.get-a-token').click(function () {
var keyId = $(this).data("key-id");
var keyName = $(this).data("key-name");
var token = getCookie("_xsrf")
$.ajax({
type: "POST",
headers: {'X-XSRFToken': token},
url: '/panel/get_token?id=' + keyId,
success: function (data) {
bootbox.alert({
title: `API token for ${keyName}`,
message: `Here is an API token for ${keyName}:\n< pre style = "white-space: pre-wrap;color:white;word-break:break-all;background: grey;border-radius: 5px;" > ${data}< / pre > `
});
},
});
})
});
< / script >
{% end %}