2022-07-17 18:16:00 +00:00
|
|
|
<!--
|
2024-01-22 19:22:41 +00:00
|
|
|
Copyright (C) 2024 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
This WebUI uses the KeenThemes Mega Bundle, a proprietary theme:
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
https://keenthemes.com/products/templates-mega-bundle
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
KeenThemes HTML/CSS/JS components are allowed for use only within the
|
|
|
|
SFTPGo product and restricted to be used in a resealable HTML template
|
|
|
|
that can compete with KeenThemes products anyhow.
|
|
|
|
|
|
|
|
This WebUI is allowed for use only within the SFTPGo product and
|
|
|
|
therefore cannot be used in derivative works/products without an
|
|
|
|
explicit grant from the SFTPGo Team (support@sftpgo.com).
|
2022-07-17 18:16:00 +00:00
|
|
|
-->
|
2021-01-17 21:29:08 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
{{- define "extra_css"}}
|
|
|
|
<link href="{{.StaticURL}}/assets/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css"/>
|
|
|
|
{{- end}}
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
{{- define "page_body"}}
|
|
|
|
{{- template "errmsg" ""}}
|
|
|
|
<div class="card shadow-sm">
|
|
|
|
<div class="card-header bg-light">
|
|
|
|
<h3 data-i18n="admin.view_manage" class="card-title section-title">View and manage admins</h3>
|
|
|
|
</div>
|
|
|
|
<div id="card_body" class="card-body">
|
|
|
|
<div id="loader" class="align-items-center text-center my-10">
|
|
|
|
<span class="spinner-border w-15px h-15px text-muted align-middle me-2"></span>
|
|
|
|
<span data-i18n="general.loading" class="text-gray-700">Loading...</span>
|
|
|
|
</div>
|
|
|
|
<div id="card_content" class="d-none">
|
|
|
|
<div class="d-flex flex-stack flex-wrap mb-5">
|
|
|
|
<div class="d-flex align-items-center position-relative my-2">
|
|
|
|
<i class="ki-solid ki-magnifier fs-1 position-absolute ms-6"></i>
|
|
|
|
<input name="search" data-i18n="[placeholder]general.search" type="text" data-table-filter="search"
|
|
|
|
class="form-control rounded-1 w-250px ps-15 me-5" placeholder="Search" />
|
|
|
|
</div>
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
<div class="d-flex justify-content-end my-2" data-table-toolbar="base">
|
|
|
|
<button type="button" class="btn btn-light-primary rotate" data-kt-menu-trigger="click" data-kt-menu-placement="bottom" data-kt-menu-permanent="true">
|
|
|
|
<span data-i18n="general.colvis">Column visibility</span>
|
|
|
|
<i class="ki-duotone ki-down fs-3 rotate-180 ms-3 me-0"></i>
|
|
|
|
</button>
|
|
|
|
<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-800 menu-state-bg-light-primary fw-semibold w-auto min-w-200 mw-300px py-4" data-kt-menu="true">
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkColStatus" />
|
|
|
|
<label class="form-check-label" for="checkColStatus">
|
|
|
|
<span data-i18n="general.status" class="text-gray-800 fs-6">Status</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkColLastLogin" />
|
|
|
|
<label class="form-check-label" for="checkColLastLogin">
|
|
|
|
<span data-i18n="general.last_login" class="text-gray-800 fs-6">Last login</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkColEmail" />
|
|
|
|
<label class="form-check-label" for="checkColEmail">
|
|
|
|
<span data-i18n="general.email" class="text-gray-800 fs-6">Email</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkColRole" />
|
|
|
|
<label class="form-check-label" for="checkColRole">
|
|
|
|
<span data-i18n="general.role" class="text-gray-800 fs-6">Role</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkCol2FA" />
|
|
|
|
<label class="form-check-label" for="checkCol2FA">
|
|
|
|
<span data-i18n="title.two_factor_auth_short" class="text-gray-800 fs-6">2FA</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3 py-2 form-check form-check-sm form-check-custom form-check-solid">
|
|
|
|
<input type="checkbox" class="form-check-input" value="" id="checkColDesc" />
|
|
|
|
<label class="form-check-label" for="checkColDesc">
|
|
|
|
<span data-i18n="general.description" class="text-gray-800 fs-6">Description</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{- if .LoggedUser.HasPermission "manage_admins"}}
|
|
|
|
<a href="{{.AdminURL}}" class="btn btn-primary ms-5">
|
|
|
|
<i class="ki-duotone ki-plus fs-2"></i>
|
|
|
|
<span data-i18n="general.add">Add</span>
|
|
|
|
</a>
|
|
|
|
{{- end}}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
<table id="dataTable" class="table align-middle table-row-dashed fs-6 gy-5">
|
2021-01-17 21:29:08 +00:00
|
|
|
<thead>
|
2024-01-22 19:22:41 +00:00
|
|
|
<tr class="text-start text-muted fw-bold fs-6 gs-0">
|
|
|
|
<th data-i18n="login.username">Username</th>
|
|
|
|
<th data-i18n="general.status">Status</th>
|
|
|
|
<th data-i18n="general.last_login">Last login</th>
|
|
|
|
<th data-i18n="general.email">Email</th>
|
|
|
|
<th data-i18n="general.role">Role</th>
|
|
|
|
<th data-i18n="title.two_factor_auth_short">2FA</th>
|
|
|
|
<th data-i18n="general.description">Description</th>
|
|
|
|
<th class="min-w-100px"></th>
|
2021-01-17 21:29:08 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
2024-01-22 19:22:41 +00:00
|
|
|
<tbody id="table_body" class="text-gray-800 fw-semibold"></tbody>
|
2021-01-17 21:29:08 +00:00
|
|
|
</table>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-01-22 19:22:41 +00:00
|
|
|
{{- end}}
|
|
|
|
{{- define "extra_js"}}
|
|
|
|
<script {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}} src="{{.StaticURL}}/assets/plugins/custom/datatables/datatables.bundle.js"></script>
|
|
|
|
<script type="text/javascript" {{- if .CSPNonce}} nonce="{{.CSPNonce}}"{{- end}}>
|
|
|
|
function deleteAction(username) {
|
|
|
|
ModalAlert.fire({
|
|
|
|
text: $.t('general.delete_confirm_generic'),
|
|
|
|
icon: "warning",
|
|
|
|
confirmButtonText: $.t('general.delete_confirm_btn'),
|
|
|
|
cancelButtonText: $.t('general.cancel'),
|
|
|
|
customClass: {
|
|
|
|
confirmButton: "btn btn-danger",
|
|
|
|
cancelButton: 'btn btn-secondary'
|
|
|
|
}
|
|
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed){
|
|
|
|
$('#loading_message').text("");
|
|
|
|
KTApp.showPageLoading();
|
|
|
|
let path = '{{.AdminURL}}' + "/" + encodeURIComponent(username);
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
axios.delete(path, {
|
|
|
|
timeout: 15000,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': '{{.CSRFToken}}'
|
|
|
|
},
|
|
|
|
validateStatus: function (status) {
|
|
|
|
return status == 200;
|
|
|
|
}
|
|
|
|
}).then(function(response){
|
|
|
|
location.reload();
|
|
|
|
}).catch(function(error){
|
|
|
|
KTApp.hidePageLoading();
|
|
|
|
let errorMessage;
|
|
|
|
if (error && error.response) {
|
|
|
|
switch (error.response.status) {
|
|
|
|
case 400:
|
|
|
|
if (error.response.data && error.response.data.error){
|
|
|
|
if (error.response.data.error.includes("delete yourself")){
|
|
|
|
errorMessage = "admin.self_delete";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 403:
|
|
|
|
errorMessage = "general.delete_error_403";
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
errorMessage = "general.delete_error_404";
|
|
|
|
break;
|
2021-06-08 11:24:28 +00:00
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
2024-01-22 19:22:41 +00:00
|
|
|
if (!errorMessage){
|
|
|
|
errorMessage = "general.delete_error_generic";
|
|
|
|
}
|
|
|
|
ModalAlert.fire({
|
|
|
|
text: $.t(errorMessage),
|
|
|
|
icon: "warning",
|
|
|
|
confirmButtonText: $.t('general.ok'),
|
|
|
|
customClass: {
|
|
|
|
confirmButton: "btn btn-primary"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-01-17 21:29:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
var datatable = function(){
|
|
|
|
var dt;
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
var initDatatable = function () {
|
|
|
|
$('#errorMsg').addClass("d-none");
|
|
|
|
dt = $('#dataTable').DataTable({
|
|
|
|
ajax: {
|
|
|
|
url: "{{.AdminsURL}}/json",
|
|
|
|
dataSrc: "",
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
|
|
|
$(".dataTables_processing").hide();
|
|
|
|
let txt = "";
|
|
|
|
if ($xhr) {
|
|
|
|
let json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
|
|
|
if (json.message){
|
|
|
|
txt = json.message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!txt){
|
|
|
|
txt = "general.error500";
|
|
|
|
}
|
|
|
|
setI18NData($('#errorTxt'), txt);
|
|
|
|
$('#errorMsg').removeClass("d-none");
|
|
|
|
}
|
2022-05-22 09:45:49 +00:00
|
|
|
},
|
2024-01-22 19:22:41 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
data: "username",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
return escapeHTML(data);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "status",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
switch (data){
|
|
|
|
case 1:
|
|
|
|
return $.t('general.active');
|
|
|
|
default:
|
|
|
|
return $.t('general.inactive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "last_login",
|
|
|
|
defaultContent: "",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data > 0){
|
|
|
|
return $.t('general.datetime', {
|
|
|
|
val: parseInt(data, 10),
|
|
|
|
formatParams: {
|
|
|
|
val: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' },
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "email",
|
|
|
|
visible: false,
|
|
|
|
defaultContent: "",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data){
|
|
|
|
return escapeHTML(data);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "role",
|
|
|
|
visible: false,
|
|
|
|
defaultContent: "",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data){
|
|
|
|
return escapeHTML(data);
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "filters.totp_config.enabled",
|
|
|
|
visible: false,
|
|
|
|
defaultContent: false,
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data){
|
|
|
|
return $.t('general.active');
|
|
|
|
}
|
|
|
|
return $.t('general.inactive')
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "description",
|
|
|
|
visible: false,
|
|
|
|
defaultContent: "",
|
|
|
|
render: function(data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
if (data){
|
|
|
|
return escapeHTML(data);
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: "id",
|
|
|
|
searchable: false,
|
|
|
|
orderable: false,
|
|
|
|
className: 'text-end',
|
|
|
|
render: function (data, type, row) {
|
|
|
|
if (type === 'display') {
|
|
|
|
//{{- if .LoggedUser.HasPermission "manage_admins"}}
|
|
|
|
return `<button class="btn btn-light btn-active-light-primary btn-flex btn-center btn-sm rotate" data-kt-menu-trigger="click" data-kt-menu-placement="bottom-end">
|
|
|
|
<span data-i18n="general.actions" class="fs-6">Actions</span>
|
|
|
|
<i class="ki-duotone ki-down fs-5 ms-1 rotate-180"></i>
|
|
|
|
</button>
|
|
|
|
<div class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-700 menu-state-bg-light-primary fw-semibold fs-6 w-200px py-4" data-kt-menu="true">
|
|
|
|
<div class="menu-item px-3">
|
|
|
|
<a data-i18n="general.edit" href="#" class="menu-link px-3" data-table-action="edit_row">Edit</a>
|
|
|
|
</div>
|
|
|
|
<div class="menu-item px-3">
|
|
|
|
<a data-i18n="general.delete" href="#" class="menu-link text-danger px-3" data-table-action="delete_row">Delete</a>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
//{{- end}}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
deferRender: true,
|
|
|
|
stateSave: true,
|
|
|
|
stateDuration: 0,
|
|
|
|
colReorder: {
|
|
|
|
enable: true,
|
|
|
|
fixedColumnsLeft: 1
|
2022-05-22 09:45:49 +00:00
|
|
|
},
|
2024-01-22 19:22:41 +00:00
|
|
|
stateLoadParams: function (settings, data) {
|
|
|
|
if (data.search.search){
|
|
|
|
const filterSearch = document.querySelector('[data-table-filter="search"]');
|
|
|
|
filterSearch.value = data.search.search;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
language: {
|
|
|
|
info: $.t('datatable.info'),
|
|
|
|
infoEmpty: $.t('datatable.info_empty'),
|
|
|
|
infoFiltered: $.t('datatable.info_filtered'),
|
|
|
|
loadingRecords: "",
|
|
|
|
processing: $.t('datatable.processing'),
|
|
|
|
zeroRecords: "",
|
|
|
|
emptyTable: $.t('datatable.no_records')
|
2022-09-13 16:04:27 +00:00
|
|
|
},
|
2024-01-22 19:22:41 +00:00
|
|
|
order: [[0, 'asc']],
|
|
|
|
initComplete: function(settings, json) {
|
|
|
|
$('#loader').addClass("d-none");
|
|
|
|
$('#card_content').removeClass("d-none");
|
|
|
|
let api = $.fn.dataTable.Api(settings);
|
|
|
|
api.columns.adjust().draw("page");
|
|
|
|
drawAction();
|
2021-03-28 09:02:11 +00:00
|
|
|
}
|
2024-01-22 19:22:41 +00:00
|
|
|
});
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
dt.on('draw', drawAction);
|
|
|
|
dt.on('column-reorder', function(e, settings, details){
|
|
|
|
drawAction();
|
|
|
|
});
|
|
|
|
}
|
2021-03-28 09:02:11 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
function drawAction() {
|
|
|
|
KTMenu.createInstances();
|
|
|
|
handleRowActions();
|
|
|
|
$('#table_body').localize();
|
|
|
|
}
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
function handleColVisibilityCheckbox(el, index) {
|
|
|
|
el.off("change");
|
|
|
|
el.prop('checked', dt.column(index).visible());
|
|
|
|
el.on("change", function(e){
|
|
|
|
dt.column(index).visible($(this).is(':checked'));
|
|
|
|
dt.draw('page');
|
|
|
|
});
|
|
|
|
}
|
2021-03-28 09:02:11 +00:00
|
|
|
|
2024-01-22 19:22:41 +00:00
|
|
|
var handleDatatableActions = function () {
|
|
|
|
const filterSearch = $(document.querySelector('[data-table-filter="search"]'));
|
|
|
|
filterSearch.off("keyup");
|
|
|
|
filterSearch.on('keyup', function (e) {
|
|
|
|
dt.rows().deselect();
|
|
|
|
dt.search(e.target.value, true, false).draw();
|
|
|
|
});
|
|
|
|
handleColVisibilityCheckbox($('#checkColStatus'), 1);
|
|
|
|
handleColVisibilityCheckbox($('#checkColLastLogin'), 2);
|
|
|
|
handleColVisibilityCheckbox($('#checkColEmail'), 3);
|
|
|
|
handleColVisibilityCheckbox($('#checkColRole'), 4);
|
|
|
|
handleColVisibilityCheckbox($('#checkCol2FA'), 5);
|
|
|
|
handleColVisibilityCheckbox($('#checkColDesc'), 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleRowActions() {
|
|
|
|
const editButtons = document.querySelectorAll('[data-table-action="edit_row"]');
|
|
|
|
editButtons.forEach(d => {
|
|
|
|
let el = $(d);
|
|
|
|
el.off("click");
|
|
|
|
el.on("click", function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
let rowData = dt.row(e.target.closest('tr')).data();
|
|
|
|
window.location.replace('{{.AdminURL}}' + "/" + encodeURIComponent(rowData['username']));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const deleteButtons = document.querySelectorAll('[data-table-action="delete_row"]');
|
|
|
|
deleteButtons.forEach(d => {
|
|
|
|
let el = $(d);
|
|
|
|
el.off("click");
|
|
|
|
el.on("click", function(e){
|
|
|
|
e.preventDefault();
|
|
|
|
const parent = e.target.closest('tr');
|
|
|
|
deleteAction(dt.row(parent).data()['username']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
init: function () {
|
|
|
|
initDatatable();
|
|
|
|
handleDatatableActions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
$(document).on("i18nshow", function(){
|
|
|
|
datatable.init();
|
2021-01-17 21:29:08 +00:00
|
|
|
});
|
|
|
|
</script>
|
2024-01-22 19:22:41 +00:00
|
|
|
{{- end}}
|