admins.html 9.9 KB

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