connections.html 7.9 KB

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