list.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <div class="wrapper wrapper-content animated fadeInRight">
  2. <div class="row">
  3. <div class="col-lg-12">
  4. <div class="ibox float-e-margins">
  5. <div class="ibox-title">
  6. <h5>client list</h5>
  7. <div class="ibox-tools">
  8. <a class="collapse-link">
  9. <i class="fa fa-chevron-up"></i>
  10. </a>
  11. <a class="close-link">
  12. <i class="fa fa-times"></i>
  13. </a>
  14. </div>
  15. </div>
  16. <div class="content">
  17. <div class="table-responsive">
  18. <div id="toolbar">
  19. <a href="/client/add" class="btn btn-primary dim" type="button">new</i></a>
  20. </div>
  21. <table id="taskList_table" class="table-striped table-hover"
  22. data-mobile-responsive="true"></table>
  23. </div>
  24. </div>
  25. <div class="ibox-content">
  26. <table id="table"></table>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <script>
  33. function del(id) {
  34. if (confirm("Are you sure you want to delete it??")) {
  35. $.ajax({
  36. type: "POST",
  37. url: "/client/del",
  38. data: {"id": id},
  39. success: function (res) {
  40. alert(res.msg)
  41. if (res.status) {
  42. document.location.reload();
  43. }
  44. }
  45. })
  46. }
  47. }
  48. function start(id) {
  49. if (confirm("Are you sure you want to start it??")) {
  50. $.ajax({
  51. type: "POST",
  52. url: "/client/changestatus",
  53. data: {"id": id, "status": 1},
  54. success: function (res) {
  55. alert(res.msg)
  56. if (res.status) {
  57. document.location.reload();
  58. }
  59. }
  60. })
  61. }
  62. }
  63. function stop(id) {
  64. if (confirm("Are you sure you want to stop it?")) {
  65. $.ajax({
  66. type: "POST",
  67. url: "/client/changestatus",
  68. data: {
  69. "id": id, "status": 0
  70. },
  71. success:
  72. function (res) {
  73. alert(res.msg)
  74. if (res.status) {
  75. document.location.reload();
  76. }
  77. }
  78. })
  79. }
  80. }
  81. function edit(id) {
  82. window.location.href = "/client/edit?id=" + id
  83. }
  84. function add() {
  85. window.location.href = "/client/add"
  86. }
  87. function tunnel(id) {
  88. window.location.href = "/index/all?client_id=" + id
  89. }
  90. function host(id) {
  91. window.location.href = "/index/hostlist?client_id=" + id
  92. }
  93. /*bootstrap table*/
  94. $('#table').bootstrapTable({
  95. toolbar: "#toolbar",
  96. method: 'post', // 服务器数据的请求方式 get or post
  97. url: "/client/list", // 服务器数据的加载地址
  98. contentType: "application/x-www-form-urlencoded",
  99. striped: true, // 设置为true会有隔行变色效果
  100. showHeader: true,
  101. showColumns: true,
  102. showRefresh: true,
  103. pagination: true,//分页
  104. sidePagination: 'server',//服务器端分页
  105. pageNumber: 1,
  106. pageList: [5, 10, 20, 50],//分页步进值
  107. detailView: true,
  108. smartDisplay: true, // 智能显示 pagination 和 cardview 等
  109. detailFormatter: function (index, row, element) {
  110. return '<b>max connection num: </b>' + row.MaxConn + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  111. + '<b>now conn num: </b>' + row.NowConn + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  112. + '<b>rate limit: </b>' + row.Flow.FlowLimit + `m&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  113. + '<b>flow limit: </b>' + row.RateLimit + `kb/s&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  114. + '<b>export flow: </b>' + change(row.Flow.ExportFlow) + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  115. + '<b>inlet flow: </b>' + change(row.Flow.InletFlow) + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
  116. + '<b>crypt: </b>' + row.Cnf.Crypt + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  117. + '<b>compress: </b>' + row.Cnf.Compress + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  118. + '<b>username: </b>' + row.Cnf.U + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp`
  119. + '<b>password: </b>' + row.Cnf.P + `&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp` + "<br/><br>"
  120. + '<b>commond: </b>' + "<code>./npc -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + "</code>"
  121. },
  122. //表格的列
  123. columns: [
  124. {
  125. field: 'Id',//域值
  126. title: 'id',//标题
  127. visible: true,//false表示不显示
  128. sortable: true,//启用排序
  129. },
  130. {
  131. field: 'Remark',//域值
  132. title: 'remark',//标题
  133. visible: true,//false表示不显示
  134. sortable: true,//启用排序
  135. },
  136. {
  137. field: 'VerifyKey',//域值
  138. title: 'key',//标题
  139. visible: true,//false表示不显示
  140. sortable: true,//启用排序
  141. formatter: function (value, row, index) {
  142. if (!row.NoStore) {
  143. return value
  144. } else {
  145. return "public vkey"
  146. }
  147. }
  148. },
  149. {
  150. field: 'Addr',//域值
  151. title: 'client addr',//标题
  152. visible: true,//false表示不显示
  153. sortable: true,//启用排序
  154. },
  155. {
  156. field: 'Status',//域值
  157. title: 'setting status',//内容
  158. visible: true,//false表示不显示
  159. sortable: true,//启用排序
  160. formatter: function (value, row, index) {
  161. if (value) {
  162. return '<span class="badge badge-primary">open</span>'
  163. } else {
  164. return '<span class="badge badge-badge">close</span>'
  165. }
  166. }
  167. },
  168. {
  169. field: 'IsConnect',//域值
  170. title: 'client status',//内容
  171. visible: true,//false表示不显示
  172. sortable: true,//启用排序
  173. formatter: function (value, row, index) {
  174. if (value) {
  175. return '<span class="badge badge-primary">online</span>'
  176. } else {
  177. return '<span class="badge badge-badge">offline</span>'
  178. }
  179. }
  180. },
  181. {
  182. field: 'option',//域值
  183. title: 'option',//内容
  184. visible: true,//false表示不显示
  185. sortable: true,//启用排序
  186. formatter: function (value, row, index) {
  187. btn_group = '<div class="btn-group">'
  188. btn = `<button onclick="del(` + row.Id + `)" class="btn-danger"><i class="fa fa-trash"></i></button><button onclick="edit(` + row.Id + `)" class="btn-primary"><i class="fa fa-edit"></i></button></div>`
  189. if (row.Status) {
  190. return btn_group + `<button onclick="stop(` + row.Id + `)" class="btn-warning"><i class="fa fa-close"></i></button>` + btn
  191. } else {
  192. return btn_group + `<button onclick="start(` + row.Id + `)" class="btn-warning"><i class="fa fa-check"></i></button>` + btn
  193. }
  194. }
  195. },
  196. {
  197. field: 'show',//域值
  198. title: 'show',//内容
  199. visible: true,//false表示不显示
  200. sortable: true,//启用排序
  201. formatter: function (value, row, index) {
  202. return `<button onclick="tunnel(` + row.Id + `)" class="btn-info">tunnel</button><button onclick="host(` + row.Id + `)" class="btn-primary">host</button>`
  203. }
  204. }
  205. ]
  206. });
  207. </script>