connections.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. {{end}}
  22. {{define "page_body"}}
  23. <div id="errorMsg" class="alert alert-warning alert-dismissible fade show" style="display: none;" role="alert">
  24. <span id="errorTxt"></span>
  25. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  26. <span aria-hidden="true">&times;</span>
  27. </button>
  28. </div>
  29. <div class="card shadow mb-4">
  30. <div class="card-header py-3">
  31. <h6 class="m-0 font-weight-bold text-primary">View and manage connections</h6>
  32. </div>
  33. <div class="card-body">
  34. <div class="table-responsive">
  35. <table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
  36. <thead>
  37. <tr>
  38. <th>ID</th>
  39. <th>Node</th>
  40. <th>Username</th>
  41. <th>Time</th>
  42. <th>Info</th>
  43. <th>Transfers</th>
  44. </tr>
  45. </thead>
  46. <tbody>
  47. {{range .Connections}}
  48. <tr>
  49. <td>{{.ConnectionID}}</td>
  50. <td>{{.Node}}</td>
  51. <td>{{.Username}}</td>
  52. <td>{{.GetConnectionDuration}}</td>
  53. <td>{{.GetConnectionInfo}}</td>
  54. <td>{{.GetTransfersAsString}}</td>
  55. </tr>
  56. {{end}}
  57. </tbody>
  58. </table>
  59. </div>
  60. </div>
  61. </div>
  62. {{end}}
  63. {{define "dialog"}}
  64. <div class="modal fade" id="disconnectModal" tabindex="-1" role="dialog" aria-labelledby="disconnectModalLabel"
  65. aria-hidden="true">
  66. <div class="modal-dialog" role="document">
  67. <div class="modal-content">
  68. <div class="modal-header">
  69. <h5 class="modal-title" id="disconnectModalLabel">
  70. Confirmation required
  71. </h5>
  72. <button class="close" type="button" data-dismiss="modal" aria-label="Close">
  73. <span aria-hidden="true">&times;</span>
  74. </button>
  75. </div>
  76. <div class="modal-body">Do you want to close the selected connection?</div>
  77. <div class="modal-footer">
  78. <button class="btn btn-secondary" type="button" data-dismiss="modal">
  79. Cancel
  80. </button>
  81. <a class="btn btn-warning" href="#" onclick="disconnectAction()">
  82. Disconnect
  83. </a>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. {{end}}
  89. {{define "extra_js"}}
  90. <script src="{{.StaticURL}}/vendor/datatables/jquery.dataTables.min.js"></script>
  91. <script src="{{.StaticURL}}/vendor/datatables/dataTables.bootstrap4.min.js"></script>
  92. <script src="{{.StaticURL}}/vendor/datatables/dataTables.buttons.min.js"></script>
  93. <script src="{{.StaticURL}}/vendor/datatables/buttons.bootstrap4.min.js"></script>
  94. <script src="{{.StaticURL}}/vendor/datatables/buttons.colVis.min.js"></script>
  95. <script src="{{.StaticURL}}/vendor/datatables/dataTables.fixedHeader.min.js"></script>
  96. <script src="{{.StaticURL}}/vendor/datatables/dataTables.responsive.min.js"></script>
  97. <script src="{{.StaticURL}}/vendor/datatables/responsive.bootstrap4.min.js"></script>
  98. <script src="{{.StaticURL}}/vendor/datatables/dataTables.select.min.js"></script>
  99. <script type="text/javascript">
  100. function disconnectAction() {
  101. let table = $('#dataTable').DataTable();
  102. table.button('disconnect:name').enable(false);
  103. let selectedData = table.row({ selected: true }).data()
  104. let connectionID = selectedData[0];
  105. let nodeID = selectedData[1];
  106. let path = '{{.ConnectionsURL}}' + "/" + fixedEncodeURIComponent(connectionID)+"?node="+encodeURIComponent(nodeID);
  107. $('#disconnectModal').modal('hide');
  108. $('#errorMsg').hide();
  109. $.ajax({
  110. url: path,
  111. type: 'DELETE',
  112. dataType: 'json',
  113. headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
  114. timeout: 15000,
  115. success: function (result) {
  116. window.location.href = '{{.ConnectionsURL}}';
  117. },
  118. error: function ($xhr, textStatus, errorThrown) {
  119. var txt = "Failed to close the selected connection";
  120. if ($xhr) {
  121. var json = $xhr.responseJSON;
  122. if (json) {
  123. if (json.message){
  124. txt += ": " + json.message;
  125. } else {
  126. txt += ": " + json.error;
  127. }
  128. }
  129. }
  130. $('#errorTxt').text(txt);
  131. $('#errorMsg').show();
  132. }
  133. });
  134. }
  135. $(document).ready(function () {
  136. $.fn.dataTable.ext.buttons.disconnect = {
  137. text: 'Disconnect',
  138. name: 'disconnect',
  139. action: function (e, dt, node, config) {
  140. $('#disconnectModal').modal('show');
  141. },
  142. enabled: false
  143. };
  144. $.fn.dataTable.ext.buttons.refresh = {
  145. text: '<i class="fas fa-sync-alt"></i>',
  146. name: 'refresh',
  147. titleAttr: "Refresh",
  148. action: function (e, dt, node, config) {
  149. location.reload();
  150. }
  151. };
  152. var table = $('#dataTable').DataTable({
  153. "select": {
  154. "style": "single",
  155. "blurable": true
  156. },
  157. "buttons": [
  158. {
  159. "text": "Column visibility",
  160. "extend": "colvis",
  161. "columns": ":not(.noVis)"
  162. }
  163. ],
  164. "lengthChange": true,
  165. "columnDefs": [
  166. {
  167. "targets": [0, 1],
  168. "visible": false,
  169. "searchable": false,
  170. "className": "noVis"
  171. },
  172. {
  173. "targets": [2],
  174. "className": "noVis"
  175. }
  176. ],
  177. "scrollX": false,
  178. "scrollY": false,
  179. "responsive": true,
  180. "language": {
  181. "emptyTable": "No user connected"
  182. },
  183. "order": [[2, 'asc']]
  184. });
  185. new $.fn.dataTable.FixedHeader( table );
  186. table.button().add(0, 'refresh');
  187. //table.button().add(0,'pageLength');
  188. {{if .LoggedAdmin.HasPermission "close_conns"}}
  189. table.button().add(0,'disconnect');
  190. table.on('select deselect', function () {
  191. var selectedRows = table.rows({ selected: true }).count();
  192. table.button('disconnect:name').enable(selectedRows == 1);
  193. });
  194. {{end}}
  195. table.buttons().container().appendTo('.col-md-6:eq(0)', table.table().container());
  196. });
  197. </script>
  198. {{end}}