2022-07-18 11:43:25 +00:00
|
|
|
<!--
|
|
|
|
Copyright (C) 2019-2022 Nicola Murino
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, version 3.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
-->
|
2019-10-07 16:19:01 +00:00
|
|
|
{{template "base" .}}
|
|
|
|
|
|
|
|
{{define "title"}}{{.Title}}{{end}}
|
|
|
|
|
|
|
|
{{define "extra_css"}}
|
2021-04-09 20:02:48 +00:00
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/fixedHeader.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.css" rel="stylesheet">
|
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/select.bootstrap4.min.css" rel="stylesheet">
|
2022-05-22 09:45:49 +00:00
|
|
|
<link href="{{.StaticURL}}/vendor/datatables/colReorder.bootstrap4.min.css" rel="stylesheet">
|
2019-10-07 16:19:01 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "page_body"}}
|
|
|
|
|
|
|
|
<div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
|
|
|
|
<div id="errorTxt" class="card-body text-form-error"></div>
|
|
|
|
</div>
|
|
|
|
|
2019-10-13 10:07:22 +00:00
|
|
|
<div id="successMsg" class="card mb-4 border-left-success" style="display: none;">
|
|
|
|
<div id="successTxt" class="card-body"></div>
|
|
|
|
</div>
|
|
|
|
|
2019-10-07 16:19:01 +00:00
|
|
|
<div class="card shadow mb-4">
|
|
|
|
<div class="card-header py-3">
|
|
|
|
<h6 class="m-0 font-weight-bold text-primary">View and manage users</h6>
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
|
|
<div class="table-responsive">
|
2021-05-06 19:35:43 +00:00
|
|
|
<table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
|
2019-10-07 16:19:01 +00:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>ID</th>
|
|
|
|
<th>Username</th>
|
2019-11-13 10:36:21 +00:00
|
|
|
<th>Status</th>
|
2022-05-22 09:45:49 +00:00
|
|
|
<th>Last login</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Email</th>
|
|
|
|
<th>Storage</th>
|
|
|
|
<th>Groups</th>
|
|
|
|
<th>MFA</th>
|
2019-10-07 16:19:01 +00:00
|
|
|
<th>Bandwidth</th>
|
|
|
|
<th>Quota</th>
|
|
|
|
<th>Other</th>
|
2022-05-22 09:45:49 +00:00
|
|
|
<th></th>
|
2019-10-07 16:19:01 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{{range .Users}}
|
|
|
|
<tr>
|
|
|
|
<td>{{.ID}}</td>
|
|
|
|
<td>{{.Username}}</td>
|
2021-03-28 09:02:11 +00:00
|
|
|
<td>{{.GetStatusAsString}}</td>
|
2022-05-22 09:45:49 +00:00
|
|
|
<td>{{.GetLastLoginAsString}}</td>
|
|
|
|
<td>{{.Description}}</td>
|
|
|
|
<td>{{.Email}}</td>
|
|
|
|
<td>{{.GetStorageDescrition}}</td>
|
|
|
|
<td>{{.GetGroupsAsString}}</td>
|
|
|
|
<td>{{.GetMFAStatusAsString}}</td>
|
2019-10-07 16:19:01 +00:00
|
|
|
<td>{{.GetBandwidthAsString}}</td>
|
|
|
|
<td>{{.GetQuotaSummary}}</td>
|
|
|
|
<td>{{.GetInfoString}}</td>
|
2022-05-22 09:45:49 +00:00
|
|
|
<td>{{.GetLastQuotaUpdateAsString}}</td>
|
2019-10-07 16:19:01 +00:00
|
|
|
</tr>
|
|
|
|
{{end}}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "dialog"}}
|
|
|
|
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
|
|
|
|
aria-hidden="true">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title" id="deleteModalLabel">
|
|
|
|
Confirmation required
|
|
|
|
</h5>
|
|
|
|
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
|
2021-07-26 18:55:49 +00:00
|
|
|
<span aria-hidden="true">×</span>
|
2019-10-07 16:19:01 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">Do you want to delete the selected user?</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" type="button" data-dismiss="modal">
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
<a class="btn btn-warning" href="#" onclick="deleteAction()">
|
|
|
|
Delete
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{define "extra_js"}}
|
2021-04-09 20:02:48 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
|
2022-05-22 09:45:49 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/buttons.colVis.min.js"></script>
|
2021-04-09 20:02:48 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.select.min.js"></script>
|
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/ellipsis.js"></script>
|
2022-05-22 09:45:49 +00:00
|
|
|
<script src="{{.StaticURL}}/vendor/datatables/dataTables.colReorder.min.js"></script>
|
2019-10-07 16:19:01 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
function deleteAction() {
|
|
|
|
var table = $('#dataTable').DataTable();
|
2021-01-17 21:29:08 +00:00
|
|
|
table.button('delete:name').enable(false);
|
|
|
|
var username = table.row({ selected: true }).data()[1];
|
2021-03-04 08:48:53 +00:00
|
|
|
var path = '{{.UserURL}}' + "/" + fixedEncodeURIComponent(username);
|
2019-10-07 16:19:01 +00:00
|
|
|
$('#deleteModal').modal('hide');
|
|
|
|
$.ajax({
|
2021-03-04 08:48:53 +00:00
|
|
|
url: path,
|
2019-10-07 16:19:01 +00:00
|
|
|
type: 'DELETE',
|
|
|
|
dataType: 'json',
|
2021-02-03 07:55:28 +00:00
|
|
|
headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
|
2019-10-07 16:19:01 +00:00
|
|
|
timeout: 15000,
|
|
|
|
success: function (result) {
|
|
|
|
window.location.href = '{{.UsersURL}}';
|
|
|
|
},
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
|
|
|
var txt = "Unable to delete the selected user";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
2021-06-08 11:24:28 +00:00
|
|
|
if (json.message){
|
|
|
|
txt += ": " + json.message;
|
|
|
|
} else {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
2019-10-07 16:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
$.fn.dataTable.ext.buttons.add = {
|
2021-03-27 21:23:01 +00:00
|
|
|
text: '<i class="fas fa-plus"></i>',
|
2021-01-17 21:29:08 +00:00
|
|
|
name: 'add',
|
2021-03-27 21:23:01 +00:00
|
|
|
titleAttr: "Add",
|
2019-10-07 16:19:01 +00:00
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
window.location.href = '{{.UserURL}}';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.dataTable.ext.buttons.edit = {
|
2021-03-27 21:23:01 +00:00
|
|
|
text: '<i class="fas fa-pen"></i>',
|
2021-01-17 21:29:08 +00:00
|
|
|
name: 'edit',
|
2021-03-27 21:23:01 +00:00
|
|
|
titleAttr: "Edit",
|
2019-10-07 16:19:01 +00:00
|
|
|
action: function (e, dt, node, config) {
|
2021-01-17 21:29:08 +00:00
|
|
|
var username = dt.row({ selected: true }).data()[1];
|
2021-03-04 08:48:53 +00:00
|
|
|
var path = '{{.UserURL}}' + "/" + fixedEncodeURIComponent(username);
|
|
|
|
window.location.href = path;
|
2019-10-07 16:19:01 +00:00
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2021-01-25 20:31:33 +00:00
|
|
|
$.fn.dataTable.ext.buttons.template = {
|
2022-01-12 18:01:19 +00:00
|
|
|
text: '<i class="fas fa-clone"></i>',
|
2021-01-25 20:31:33 +00:00
|
|
|
name: 'template',
|
2022-01-12 18:01:19 +00:00
|
|
|
titleAttr: "Template",
|
2021-01-25 20:31:33 +00:00
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
var selectedRows = table.rows({ selected: true }).count();
|
|
|
|
if (selectedRows == 1){
|
|
|
|
var username = dt.row({ selected: true }).data()[1];
|
2021-12-08 18:25:22 +00:00
|
|
|
var path = '{{.UserTemplateURL}}' + "?from=" + encodeURIComponent(username);
|
2021-01-25 20:31:33 +00:00
|
|
|
window.location.href = path;
|
|
|
|
} else {
|
|
|
|
window.location.href = '{{.UserTemplateURL}}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-07 16:19:01 +00:00
|
|
|
$.fn.dataTable.ext.buttons.delete = {
|
2021-03-27 21:23:01 +00:00
|
|
|
text: '<i class="fas fa-trash"></i>',
|
2021-01-17 21:29:08 +00:00
|
|
|
name: 'delete',
|
2021-03-27 21:23:01 +00:00
|
|
|
titleAttr: "Delete",
|
2019-10-07 16:19:01 +00:00
|
|
|
action: function (e, dt, node, config) {
|
|
|
|
/*console.log("delete clicked, num row selected: " + dt.rows({ selected: true }).count());
|
|
|
|
var data = dt.rows({ selected: true }).data();
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
console.log("selected row data: " + JSON.stringify(data[i]));
|
|
|
|
}*/
|
|
|
|
$('#deleteModal').modal('show');
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2019-10-13 10:07:22 +00:00
|
|
|
$.fn.dataTable.ext.buttons.quota_scan = {
|
2022-05-22 09:45:49 +00:00
|
|
|
text: '<i class="fas fa-redo-alt"></i>',
|
2021-01-17 21:29:08 +00:00
|
|
|
name: 'quota_scan',
|
2022-05-22 09:45:49 +00:00
|
|
|
titleAttr: 'Quota Scan',
|
2019-10-13 10:07:22 +00:00
|
|
|
action: function (e, dt, node, config) {
|
2021-01-17 21:29:08 +00:00
|
|
|
dt.button('quota_scan:name').enable(false);
|
2019-10-13 10:07:22 +00:00
|
|
|
var username = dt.row({ selected: true }).data()[1];
|
2021-06-07 19:52:43 +00:00
|
|
|
var path = '{{.QuotaScanURL}}'+ "/" + fixedEncodeURIComponent(username);
|
2019-10-13 10:07:22 +00:00
|
|
|
$.ajax({
|
|
|
|
url: path,
|
|
|
|
type: 'POST',
|
2021-02-03 07:55:28 +00:00
|
|
|
headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
|
2019-10-13 10:07:22 +00:00
|
|
|
timeout: 15000,
|
|
|
|
success: function (result) {
|
2021-01-17 21:29:08 +00:00
|
|
|
dt.button('quota_scan:name').enable(true);
|
2019-10-13 10:07:22 +00:00
|
|
|
$('#successTxt').text("Quota scan started for the selected user. Please reload the user's page to check when the scan ends");
|
|
|
|
$('#successMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#successMsg').hide();
|
|
|
|
}, 5000);
|
|
|
|
},
|
|
|
|
error: function ($xhr, textStatus, errorThrown) {
|
2021-01-17 21:29:08 +00:00
|
|
|
dt.button('quota_scan:name').enable(true);
|
2019-10-13 10:07:22 +00:00
|
|
|
var txt = "Unable to update quota for the selected user";
|
|
|
|
if ($xhr) {
|
|
|
|
var json = $xhr.responseJSON;
|
|
|
|
if (json) {
|
2019-10-13 11:08:19 +00:00
|
|
|
if (json.message) {
|
|
|
|
txt += ": " + json.message;
|
|
|
|
} else if (json.error) {
|
|
|
|
txt += ": " + json.error;
|
|
|
|
}
|
2019-10-13 10:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#errorTxt').text(txt);
|
|
|
|
$('#errorMsg').show();
|
|
|
|
setTimeout(function () {
|
|
|
|
$('#errorMsg').hide();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
|
2019-10-07 16:19:01 +00:00
|
|
|
var table = $('#dataTable').DataTable({
|
2021-05-06 19:35:43 +00:00
|
|
|
"select": {
|
|
|
|
"style": "single",
|
|
|
|
"blurable": true
|
|
|
|
},
|
2022-05-22 09:45:49 +00:00
|
|
|
"colReorder": {
|
|
|
|
"enable": true,
|
|
|
|
"fixedColumnsLeft": 2
|
|
|
|
},
|
2021-03-28 09:02:11 +00:00
|
|
|
"stateSave": true,
|
2021-12-04 06:58:49 +00:00
|
|
|
"stateDuration": 0,
|
2022-05-22 09:45:49 +00:00
|
|
|
"buttons": [
|
|
|
|
{
|
|
|
|
"text": "Column visibility",
|
|
|
|
"extend": "colvis",
|
|
|
|
"columns": ":not(.noVis)"
|
|
|
|
}
|
|
|
|
],
|
2019-10-07 16:19:01 +00:00
|
|
|
"columnDefs": [
|
|
|
|
{
|
2022-05-22 09:45:49 +00:00
|
|
|
"targets": [0,12],
|
2019-10-07 16:19:01 +00:00
|
|
|
"visible": false,
|
2022-05-22 09:45:49 +00:00
|
|
|
"searchable": false,
|
|
|
|
"className": "noVis"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [1],
|
|
|
|
"className": "noVis"
|
2019-10-07 16:19:01 +00:00
|
|
|
},
|
2021-03-28 09:02:11 +00:00
|
|
|
{
|
|
|
|
"targets": [3],
|
2022-05-22 09:45:49 +00:00
|
|
|
"render": $.fn.dataTable.render.datetime()
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [4,5,8],
|
|
|
|
"visible": false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [6,7],
|
|
|
|
"visible": false,
|
|
|
|
"render": $.fn.dataTable.render.ellipsis(50, true)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [9],
|
|
|
|
"visible": false,
|
2021-12-10 17:43:26 +00:00
|
|
|
"render": $.fn.dataTable.render.ellipsis(40, true)
|
2021-03-28 09:02:11 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-22 09:45:49 +00:00
|
|
|
"targets": [10],
|
|
|
|
"visible": false,
|
|
|
|
"render": function ( data, type, row, meta ) {
|
|
|
|
if (type !== 'display') {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
if (row[12] !== ""){
|
|
|
|
var dateFn = $.fn.dataTable.render.datetime();
|
|
|
|
var formattedDate = dateFn(row[12], type);
|
|
|
|
data = `${data}. Updated at: ${formattedDate}`;
|
|
|
|
}
|
|
|
|
var ellipsisFn = $.fn.dataTable.render.ellipsis(70, true);
|
|
|
|
return ellipsisFn(data, type);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"targets": [11],
|
|
|
|
"visible": false,
|
|
|
|
"render": $.fn.dataTable.render.ellipsis(100, true)
|
2021-03-28 09:02:11 +00:00
|
|
|
}
|
2019-10-07 16:19:01 +00:00
|
|
|
],
|
|
|
|
"scrollX": false,
|
2021-04-03 14:00:55 +00:00
|
|
|
"scrollY": false,
|
2021-03-28 09:02:11 +00:00
|
|
|
"responsive": true,
|
2021-04-09 20:02:48 +00:00
|
|
|
"language": {
|
|
|
|
"emptyTable": "No user defined"
|
|
|
|
},
|
2019-10-07 16:19:01 +00:00
|
|
|
"order": [[1, 'asc']]
|
|
|
|
});
|
|
|
|
|
2021-03-28 09:02:11 +00:00
|
|
|
new $.fn.dataTable.FixedHeader( table );
|
|
|
|
|
2021-01-17 21:29:08 +00:00
|
|
|
{{if .LoggedAdmin.HasPermission "quota_scans"}}
|
|
|
|
table.button().add(0,'quota_scan');
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if .LoggedAdmin.HasPermission "del_users"}}
|
|
|
|
table.button().add(0,'delete');
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if .LoggedAdmin.HasPermission "add_users"}}
|
2022-01-12 18:01:19 +00:00
|
|
|
table.button().add(0,'template');
|
2021-01-17 21:29:08 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if .LoggedAdmin.HasPermission "edit_users"}}
|
|
|
|
table.button().add(0,'edit');
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{if .LoggedAdmin.HasPermission "add_users"}}
|
|
|
|
table.button().add(0,'add');
|
|
|
|
{{end}}
|
|
|
|
|
2021-10-09 12:17:28 +00:00
|
|
|
table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
|
2021-01-17 21:29:08 +00:00
|
|
|
|
2019-10-07 16:19:01 +00:00
|
|
|
table.on('select deselect', function () {
|
|
|
|
var selectedRows = table.rows({ selected: true }).count();
|
2021-01-17 21:29:08 +00:00
|
|
|
{{if .LoggedAdmin.HasPermission "edit_users"}}
|
|
|
|
table.button('edit:name').enable(selectedRows == 1);
|
|
|
|
{{end}}
|
|
|
|
{{if .LoggedAdmin.HasPermission "del_users"}}
|
|
|
|
table.button('delete:name').enable(selectedRows == 1);
|
|
|
|
{{end}}
|
|
|
|
{{if .LoggedAdmin.HasPermission "quota_scans"}}
|
|
|
|
table.button('quota_scan:name').enable(selectedRows == 1);
|
|
|
|
{{end}}
|
2019-10-07 16:19:01 +00:00
|
|
|
});
|
2019-11-13 10:36:21 +00:00
|
|
|
});
|
2019-10-07 16:19:01 +00:00
|
|
|
</script>
|
|
|
|
{{end}}
|