index.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>frp</title>
  5. <link href="static/bootstrap.min.css" rel="stylesheet">
  6. <script src="static/jquery.min.js"></script>
  7. <script src="static/bootstrap.min.js"></script>
  8. <link href="static/iconfont.css" rel="stylesheet">
  9. </head>
  10. <body>
  11. <div class="container-fluid">
  12. <!--div class="row">
  13. <div class="col-sm-12 text-center">
  14. <h1 class="logo">frp</h1>
  15. </div>
  16. </div-->
  17. <div class="row">
  18. <div class="col-md-5 col-sm-offset-1">
  19. <div class="panel panel-default">
  20. <div ng-app="myTable" class="panel-body">
  21. <table class="table table-bordered" ng-app="myTable" ng-controller="myCtrl">
  22. <thead>
  23. <tr>
  24. <th class="tab_info" ng-click="col='name';desc=!desc">Server<i class="iconfont pull-right">&#xe66d;</i></th>
  25. <th class="tab_info" ng-click="col='type';desc=!desc">Type<i class="iconfont pull-right">&#xe66d;</i></th>
  26. <th class="tab_info" ng-click="col='bind_addr';desc=!desc">Ip<i class="iconfont pull-right">&#xe66d;</i></th>
  27. <th class="tab_info" ng-click="col='listen_port';desc=!desc">Port<i class="iconfont pull-right">&#xe66d;</i></th>
  28. <th class="tab_info" ng-click="col='status';desc=!desc">Status<i class="iconfont pull-right">&#xe66d;</i></th>
  29. <th class="tab_info" ng-click="col='current_conns';desc=!desc">CurCon<i class="iconfont pull-right">&#xe66d;</i></th>
  30. <th class="tab_info" ng-click="col='daily[0].flow_out';desc=!desc">FlowOut<i class="iconfont pull-right">&#xe66d;</i></th>
  31. <th class="tab_info" ng-click="col='daily[0].flow_in';desc=!desc">FlowIn<i class="iconfont pull-right">&#xe66d;</i></th>
  32. </tr>
  33. </thead>
  34. <tbody id="tab_body">
  35. <tr ng-repeat="x in proxies|orderBy:col:desc">
  36. <td>
  37. <button class="btn btn-xs btn-block btn-success center-block" onclick="changeit(this)"><span ng-bind="x.name"></span></button>
  38. </td>
  39. <td><span ng-bind="x.type"></span></td>
  40. <td><span ng-bind="x.bind_addr"></span></td>
  41. <td><span ng-bind="x.listen_port"></span></td>
  42. <td><span ng-bind="x.status"></span></td>
  43. <td><span ng-bind="x.current_conns"></span></td>
  44. <td><span ng-bind="x.daily[0].flow_out"></span></td>
  45. <td><span ng-bind="x.daily[0].flow_in"></span></td>
  46. </tr>
  47. </tbody>
  48. </table>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="col-md-5">
  53. <div id="view1" style="height: 300pt"></div>
  54. <div id="view2" style="height: 300pt"></div>
  55. </div>
  56. </div>
  57. </div>
  58. <script src="static/angular.min.js"></script>
  59. <script type="text/javascript" src="static/echarts.min.js"></script>
  60. <script>
  61. var alldata = new Array();
  62. var index = null;
  63. <<< range .proxies >>>
  64. alldata["<<< .name >>>"] = {
  65. name: "<<< .name >>>",
  66. type: "<<< .type >>>",
  67. bind_addr: "<<< .bind_addr >>>",
  68. listen_port: "<<< .listen_port >>>",
  69. current_conns: <<< .current_conns >>> ,
  70. domains: [ <<< range.custom_domains >>> "<<< . >>>", <<< end >>> ],
  71. stat: "<<< .status >>>",
  72. use_encryption: "<<< .use_encryption >>>",
  73. use_gzip: "<<< .use_gzip >>>",
  74. privilege_mode: "<<< .privilege_mode >>>",
  75. times: [],
  76. ins: [],
  77. outs: [],
  78. conns: [],
  79. };
  80. <<< end >>>
  81. var newproxies = <<< . >>>;
  82. var dom1 = document.getElementById("view1");
  83. var dom2 = document.getElementById("view2");
  84. var myChart1 = echarts.init(dom1);
  85. var myChart2 = echarts.init(dom2);
  86. var option1 = null;
  87. var option2 = null;
  88. var maxval = 0;
  89. var dw = " B";
  90. var step = 1;
  91. function reloadview() {
  92. console.log("in reloadview index:", index);
  93. window.maxval = 0;
  94. window.dw = " B";
  95. window.step = 1;
  96. for (var val1 in alldata[index].ins) {
  97. if (maxval < alldata[index].ins[val1]) {
  98. window.maxval = alldata[index].outs[val1];
  99. }
  100. }
  101. for (var val2 in alldata[index].outs) {
  102. if (maxval < alldata[index].outs[val2]) {
  103. window.maxval = alldata[index].outs[val2]
  104. }
  105. }
  106. if (maxval > 1024 * 1024) {
  107. window.dw = " MB";
  108. window.step = 1024 * 1024;
  109. } else if (maxval > 1024) {
  110. window.dw = " KB";
  111. window.step = 1024;
  112. }
  113. window.option1 = {
  114. title: {
  115. text: alldata[index].name
  116. },
  117. tooltip: {
  118. trigger: 'axis'
  119. },
  120. legend: {
  121. data: ['flow_in', 'flow_out']
  122. },
  123. grid: {
  124. left: '3%',
  125. right: '6%',
  126. bottom: '3%',
  127. containLabel: true
  128. },
  129. toolbox: {
  130. feature: {
  131. saveAsImage: {}
  132. }
  133. },
  134. xAxis: {
  135. type: 'category',
  136. boundaryGap: false,
  137. data: alldata[index].times
  138. },
  139. yAxis: {
  140. type: 'value',
  141. axisLabel: {
  142. formatter: function(value) {
  143. var data = (value / step).toFixed(2);
  144. return data + dw;
  145. }
  146. }
  147. },
  148. series: [{
  149. name: 'flow_in',
  150. type: 'line',
  151. stack: '总量',
  152. data: alldata[index].ins
  153. }, {
  154. name: 'flow_out',
  155. type: 'line',
  156. stack: '总量',
  157. data: alldata[index].outs
  158. }]
  159. };
  160. window.option2 = {
  161. title: {
  162. text: ""
  163. },
  164. tooltip: {
  165. trigger: 'axis'
  166. },
  167. legend: {
  168. data: ['total_accept_conns']
  169. },
  170. grid: {
  171. left: '3%',
  172. right: '6%',
  173. bottom: '3%',
  174. containLabel: true
  175. },
  176. toolbox: {
  177. feature: {
  178. saveAsImage: {}
  179. }
  180. },
  181. xAxis: {
  182. type: 'category',
  183. boundaryGap: false,
  184. data: alldata[index].times
  185. },
  186. yAxis: {
  187. type: 'value'
  188. },
  189. series: [{
  190. name: 'total_accept_conns',
  191. type: 'line',
  192. stack: '总量',
  193. data: alldata[index].conns
  194. }]
  195. };
  196. myChart1.setOption(option1, true);
  197. myChart2.setOption(option2, true);
  198. };;
  199. var showdetail = false;
  200. var newindex = 0;
  201. function cleandetail() {
  202. $(".info_detail").remove();
  203. showdetail = false;
  204. };
  205. function changeit(id) {
  206. newindex = id.firstElementChild.innerHTML;
  207. if (index == newindex) {
  208. if (showdetail) {
  209. cleandetail();
  210. return;
  211. }
  212. }
  213. index = newindex;
  214. cleandetail();
  215. window.showdetail = true;
  216. var newrow = "<tr class='info_detail'><th colspan='4'>Key</th><th colspan='4'>Val</th><tr>";
  217. newrow += "<tr class='info_detail'><td colspan='4'>Domains</td><td colspan='4'>" + alldata[index].domains + "</td><tr>";
  218. newrow += "<tr class='info_detail'><td colspan='4'>Status</td><td colspan='4'>" + alldata[index].stat + "</td><tr>";
  219. newrow += "<tr class='info_detail'><td colspan='4'>Encryption</td><td colspan='4'>" + alldata[index].use_encryption + "</td><tr>";
  220. newrow += "<tr class='info_detail'><td colspan='4'>Gzip</td><td colspan='4'>" + alldata[index].use_gzip + "</td><tr>";
  221. newrow += "<tr class='info_detail'><td colspan='4'>Privilege</td><td colspan='4'>" + alldata[index].privilege_mode + "</td><tr>";
  222. var hehe = $(id.parentNode.parentNode);
  223. $(hehe).after(newrow);
  224. reloadview();
  225. };
  226. // add somedata
  227. {
  228. var ttdy = new Date();
  229. var today = ttdy.getFullYear() * 10000 + (1 + ttdy.getMonth()) * 100 + ttdy.getDate();
  230. for (var inx in newproxies.proxies) {
  231. console.log("now inx is ", inx);
  232. if (newproxies.proxies[inx].current_conns == undefined) {
  233. newproxies.proxies[inx].current_conns = 0;
  234. alldata[newproxies.proxies[inx].name].current_conns = 0;
  235. }
  236. if (newproxies.proxies[inx].daily == undefined ) {
  237. newproxies.proxies[inx].daily = [];
  238. }
  239. newproxies.proxies[inx].daily.sort(function (a, b) {
  240. return a.time > b.time;
  241. });
  242. for (var iinnx in newproxies.proxies[inx].daily) {
  243. alldata[newproxies.proxies[inx].name].times.push(newproxies.proxies[inx].daily[iinnx].time);
  244. alldata[newproxies.proxies[inx].name].ins.push(newproxies.proxies[inx].daily[iinnx].flow_in);
  245. alldata[newproxies.proxies[inx].name].outs.push(newproxies.proxies[inx].daily[iinnx].flow_out);
  246. alldata[newproxies.proxies[inx].name].conns.push(newproxies.proxies[inx].daily[iinnx].total_accept_conns);
  247. }
  248. if (newproxies.proxies[inx].daily.length == 0 || newproxies.proxies[inx].daily[0].time != today) {
  249. alldata[newproxies.proxies[inx].name].times.push(today);
  250. alldata[newproxies.proxies[inx].name].ins.push(0);
  251. alldata[newproxies.proxies[inx].name].outs.push(0);
  252. alldata[newproxies.proxies[inx].name].conns.push(0);
  253. newproxies.proxies[inx].daily.push({
  254. time: today,
  255. flow_in: 0,
  256. flow_out: 0,
  257. total_accept_conns: 0
  258. });
  259. }
  260. }
  261. }
  262. var app = angular.module('myTable', []);
  263. app.controller('myCtrl', function($scope) {
  264. $scope.col = 'name';
  265. $scope.desc = 0;
  266. $scope.proxies = newproxies.proxies;
  267. });
  268. $(".tab_info").hover(
  269. function() {
  270. $(this).css("color", "orange");
  271. },
  272. function() {
  273. $(this).css("color", "black");
  274. });
  275. // set default index
  276. for (var inx in alldata) {
  277. if (window.index == null || window.index > inx) {
  278. window.index = inx;
  279. }
  280. }
  281. reloadview();
  282. </script>
  283. </body>
  284. </html>