connections.html 8.0 KB

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