admins.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!--
  2. Copyright (C) 2019-2023 Nicola Murino
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as published
  5. by the Free Software Foundation, version 3.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Affero General Public License for more details.
  10. You should have received a copy of the GNU Affero General Public License
  11. along with this program. If not, see <https://www.gnu.org/licenses/>.
  12. -->
  13. {{template "base" .}}
  14. {{define "title"}}{{.Title}}{{end}}
  15. {{define "extra_css"}}
  16. <link href="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
  17. <link href="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
  18. <link href="{{.StaticURL}}/vendor/datatables/fixedHeader.bootstrap4.min.css" rel="stylesheet">
  19. <link href="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.css" rel="stylesheet">
  20. <link href="{{.StaticURL}}/vendor/datatables/select.bootstrap4.min.css" rel="stylesheet">
  21. <link href="{{.StaticURL}}/vendor/datatables/colReorder.bootstrap4.min.css" rel="stylesheet">
  22. {{end}}
  23. {{define "page_body"}}
  24. <div id="errorMsg" class="alert alert-warning fade show" style="display: none;" role="alert">
  25. <span id="errorTxt"></span>
  26. <button type="button" class="close" aria-label="Close" onclick="dismissErrorMsg();">
  27. <span aria-hidden="true">&times;</span>
  28. </button>
  29. </div>
  30. <script type="text/javascript">
  31. function dismissErrorMsg(){
  32. $('#errorMsg').hide();
  33. }
  34. </script>
  35. <div class="card shadow mb-4">
  36. <div class="card-header py-3">
  37. <h6 class="m-0 font-weight-bold text-primary">View and manage admins</h6>
  38. </div>
  39. <div class="card-body">
  40. <div class="table-responsive">
  41. <table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
  42. <thead>
  43. <tr>
  44. <th>ID</th>
  45. <th>Username</th>
  46. <th>Status</th>
  47. <th>Permissions</th>
  48. <th>Last login</th>
  49. <th>MFA</th>
  50. <th>Allow list</th>
  51. <th>Email</th>
  52. <th>Description</th>
  53. <th>Groups for users</th>
  54. <th>Role</th>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. {{range .Admins}}
  59. <tr>
  60. <td>{{.ID}}</td>
  61. <td>{{.Username}}</td>
  62. <td>{{if eq .Status 1 }}Active{{else}}Inactive{{end}}</td>
  63. <td>{{.GetPermissionsAsString}}</td>
  64. <td>{{.GetLastLoginAsString}}</td>
  65. <td>{{if .Filters.TOTPConfig.Enabled }}Enabled{{else}}Disabled{{end}}</td>
  66. <td>{{.GetAllowedIPAsString}}</td>
  67. <td>{{.Email}}</td>
  68. <td>{{.Description}}</td>
  69. <td>{{.GetGroupsAsString}}</td>
  70. <td>{{.Role}}</td>
  71. </tr>
  72. {{end}}
  73. </tbody>
  74. </table>
  75. </div>
  76. </div>
  77. </div>
  78. {{end}}
  79. {{define "dialog"}}
  80. <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
  81. aria-hidden="true">
  82. <div class="modal-dialog" role="document">
  83. <div class="modal-content">
  84. <div class="modal-header">
  85. <h5 class="modal-title" id="deleteModalLabel">
  86. Confirmation required
  87. </h5>
  88. <button class="close" type="button" data-dismiss="modal" aria-label="Close">
  89. <span aria-hidden="true">&times;</span>
  90. </button>
  91. </div>
  92. <div class="modal-body">Do you want to delete the selected admin?</div>
  93. <div class="modal-footer">
  94. <button class="btn btn-secondary" type="button" data-dismiss="modal">
  95. Cancel
  96. </button>
  97. <a class="btn btn-warning" href="#" onclick="deleteAction()">
  98. Delete
  99. </a>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. {{end}}
  105. {{define "extra_js"}}
  106. <script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
  107. <script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
  108. <script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
  109. <script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
  110. <script src="{{.StaticURL}}/vendor/datatables/buttons.colVis.min.js"></script>
  111. <script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
  112. <script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
  113. <script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
  114. <script src="{{.StaticURL}}/vendor/datatables/dataTables.select.min.js"></script>
  115. <script src="{{.StaticURL}}/vendor/datatables/ellipsis.js"></script>
  116. <script src="{{.StaticURL}}/vendor/datatables/dataTables.colReorder.min.js"></script>
  117. <script type="text/javascript">
  118. function deleteAction() {
  119. var table = $('#dataTable').DataTable();
  120. table.button('delete:name').enable(false);
  121. var username = table.row({ selected: true }).data()[1];
  122. var path = '{{.AdminURL}}' + "/" + fixedEncodeURIComponent(username);
  123. $('#deleteModal').modal('hide');
  124. $('#errorMsg').hide();
  125. $.ajax({
  126. url: path,
  127. type: 'DELETE',
  128. dataType: 'json',
  129. headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
  130. timeout: 15000,
  131. success: function (result) {
  132. window.location.href = '{{.AdminsURL}}';
  133. },
  134. error: function ($xhr, textStatus, errorThrown) {
  135. var txt = "Unable to delete the selected admin";
  136. if ($xhr) {
  137. var json = $xhr.responseJSON;
  138. if (json) {
  139. if (json.message){
  140. txt += ": " + json.message;
  141. } else {
  142. txt += ": " + json.error;
  143. }
  144. }
  145. }
  146. $('#errorTxt').text(txt);
  147. $('#errorMsg').show();
  148. }
  149. });
  150. }
  151. $(document).ready(function () {
  152. $.fn.dataTable.ext.buttons.add = {
  153. text: '<i class="fas fa-plus"></i>',
  154. name: 'add',
  155. titleAttr: "Add",
  156. action: function (e, dt, node, config) {
  157. window.location.href = '{{.AdminURL}}';
  158. }
  159. };
  160. $.fn.dataTable.ext.buttons.edit = {
  161. text: '<i class="fas fa-pen"></i>',
  162. name: 'edit',
  163. titleAttr: "Edit",
  164. action: function (e, dt, node, config) {
  165. var username = dt.row({ selected: true }).data()[1];
  166. var path = '{{.AdminURL}}' + "/" + fixedEncodeURIComponent(username);
  167. window.location.href = path;
  168. },
  169. enabled: false
  170. };
  171. $.fn.dataTable.ext.buttons.delete = {
  172. text: '<i class="fas fa-trash"></i>',
  173. name: 'delete',
  174. titleAttr: "Delete",
  175. action: function (e, dt, node, config) {
  176. $('#deleteModal').modal('show');
  177. },
  178. enabled: false
  179. };
  180. var table = $('#dataTable').DataTable({
  181. "select": {
  182. "style": "single",
  183. "blurable": true
  184. },
  185. "colReorder": {
  186. "enable": true,
  187. "fixedColumnsLeft": 2
  188. },
  189. "stateSave": true,
  190. "stateDuration": 0,
  191. "buttons": [
  192. {
  193. "text": "Column visibility",
  194. "extend": "colvis",
  195. "columns": ":not(.noVis)"
  196. }
  197. ],
  198. "columnDefs": [
  199. {
  200. "targets": [0],
  201. "visible": false,
  202. "searchable": false,
  203. "className": "noVis"
  204. },
  205. {
  206. "targets": [1],
  207. "className": "noVis"
  208. },
  209. {
  210. "targets": [3],
  211. "render": $.fn.dataTable.render.ellipsis(70, true)
  212. },
  213. {
  214. "targets": [4],
  215. "render": $.fn.dataTable.render.datetime()
  216. },
  217. {
  218. "targets": [6],
  219. "render": $.fn.dataTable.render.ellipsis(60, true),
  220. "visible": false,
  221. },
  222. {
  223. "targets": [5,7,8,10],
  224. "visible": false,
  225. },
  226. {
  227. "targets": [9],
  228. "render": $.fn.dataTable.render.ellipsis(50, true),
  229. "visible": false,
  230. }
  231. ],
  232. "scrollX": false,
  233. "scrollY": false,
  234. "responsive": true,
  235. "order": [[1, 'asc']]
  236. });
  237. new $.fn.dataTable.FixedHeader( table );
  238. {{if .LoggedAdmin.HasPermission "manage_admins"}}
  239. table.button().add(0,'delete');
  240. table.button().add(0,'edit');
  241. table.button().add(0,'add');
  242. table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
  243. table.on('select deselect', function () {
  244. var selectedRows = table.rows({ selected: true }).count();
  245. table.button('edit:name').enable(selectedRows == 1);
  246. table.button('delete:name').enable(selectedRows == 1);
  247. });
  248. {{end}}
  249. });
  250. </script>
  251. {{end}}