status.html 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. <style>
  2. #redirect.disabled{
  3. opacity: 0.7;
  4. pointer-events: none;
  5. user-select: none;
  6. }
  7. </style>
  8. <div class="ui stackable grid">
  9. <div class="ten wide column serverstatusWrapper">
  10. <div id="serverstatus" class="ui statustab inverted segment">
  11. <h1 class="ui header" style="margin-top: 1em; margin-left: 0.4em; padding-bottom: 1em;">
  12. <i id="rpStatusIcon" class="loading spinner icon"></i>
  13. <div class="content">
  14. <span id="statusTitle">Loading</span>
  15. <div class="sub header" id="statusText">Checking server status</div>
  16. </div>
  17. </h1>
  18. <div class="dot-container">
  19. <div class="dot"></div>
  20. <div class="dot"></div>
  21. <div class="dot"></div>
  22. <div class="dot"></div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="six wide column statisticWrapper">
  27. <div class="ui statustab segment">
  28. <h5 class="ui header">
  29. <i class="exchange icon"></i>
  30. <div class="content">
  31. <span id="summaryTotalCount"></span> <small>Req. Today</small>
  32. <div class="sub header" style="margin-top: 0.4em;">
  33. <i class="green circle check icon"></i> <span id="summarySuccCount"></span>
  34. / <i class="red red exclamation circle icon"></i> <span id="summaryErrCount"></span>
  35. </div>
  36. </div>
  37. </h5>
  38. <div class="ui divider"></div>
  39. <h5 class="ui header" style="margin-top: 0px;">
  40. <i class="arrows alternate horizontal icon"></i>
  41. <div class="content">
  42. <span id="forwardtype"></span>
  43. <div class="sub header" id="forwardtypeList">
  44. </div>
  45. </div>
  46. </h5>
  47. <div class="ui divider"></div>
  48. <h5 class="ui header" style="margin-top: 0px;">
  49. <i class="map marker alternate icon"></i>
  50. <div class="content">
  51. <span id="country"></span>
  52. <div class="sub header" id="countryList">
  53. <i class="ui loading circle notch icon"></i> Resolving GeoIP
  54. </div>
  55. </div>
  56. </h5>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="standardContainer" style="padding-bottom: 0 !important;">
  61. <!-- Power Buttons-->
  62. <div class="poweroptions" style="display:inline-block;">
  63. <button id="startbtn" class="ui basic button" onclick="startService();"><i class="ui green arrow alternate circle up icon"></i> Start Service</button>
  64. <button id="stopbtn" class="ui basic notloopbackOnly disabled button" onclick="stopService();"><i class="ui red minus circle icon"></i> Stop Service</button>
  65. </div>
  66. <div class="ui divider"></div>
  67. <h4>Network Status</h4>
  68. <p>Overall Network I/O in Current Host Server</p>
  69. </div>
  70. <div id="networkActWrapper" class="standardContainer" style="position: relative;">
  71. <canvas id="networkActivity"></canvas>
  72. </div>
  73. <div id="networkActivityPlaceHolder">
  74. <p style="opacity: 0.5;"> Graph Render Paused</p>
  75. </div>
  76. <div class="standardContainer">
  77. <div class="ui divider"></div>
  78. <h4>Global Settings</h4>
  79. <p>Inbound Port (Reverse Proxy Listening Port)</p>
  80. <div class="ui action fluid notloopbackOnly input" tourstep="incomingPort">
  81. <small id="applyButtonReminder">Click "Apply" button to confirm listening port changes</small>
  82. <input type="text" id="incomingPort" placeholder="Incoming Port" value="443">
  83. <button class="ui green notloopbackOnly button" style="background: linear-gradient(60deg, #27e7ff, #00ca52);" onclick="handlePortChange();"><i class="ui checkmark icon"></i> Apply</button>
  84. </div>
  85. <br>
  86. <div id="tls" class="ui toggle notloopbackOnly checkbox">
  87. <input type="checkbox">
  88. <label>Use TLS to serve proxy request<br>
  89. <small>Also known as HTTPS mode</small></label>
  90. </div>
  91. <br>
  92. <div id="listenP80" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.4em;" >
  93. <input type="checkbox">
  94. <label>Enable HTTP server on port 80<br>
  95. <small>Accept HTTP requests even if you are using HTTPS mode</small></label>
  96. </div>
  97. <br>
  98. <div tourstep="forceHttpsRedirect" style="display: inline-block;">
  99. <div id="redirect" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.4em;">
  100. <input type="checkbox">
  101. <label>Force redirect HTTP request to HTTPS<br>
  102. <small>Redirect web traffic from port 80 to 443, require enabling HTTP server on port 80</small></label>
  103. </div>
  104. </div>
  105. <div class="ui basic segment advanceoptions">
  106. <div class="ui accordion advanceSettings">
  107. <div class="title">
  108. <i class="dropdown icon"></i>
  109. Advance Settings
  110. </div>
  111. <div class="content">
  112. <div id="tlsMinVer" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.6em;">
  113. <input type="checkbox">
  114. <label>Force TLS v1.2 or above<br>
  115. <small>(Enhance security, but not compatible with legacy browsers)</small></label>
  116. </div>
  117. <br>
  118. <div id="developmentMode" class="ui toggle checkbox" style="margin-top: 0.6em;">
  119. <input type="checkbox">
  120. <label>Development Mode<br>
  121. <small>(Set Cache-Control to no-store so browser will always fetch new contents from your sites)</small></label>
  122. </div>
  123. <br>
  124. </div>
  125. </div>
  126. </div>
  127. <div id="rploopbackWarning" class="ui segment" style="display:none;">
  128. <b><i class="yellow warning icon"></i> Loopback Routing Warning</b><br>
  129. <small>This management interface is a loopback proxied service. <br>If you want to shutdown the reverse proxy server, please remove the proxy rule for the management interface and refresh.</small>
  130. </div>
  131. <div class="ui divider"></div>
  132. <div class="">
  133. <h4>Statistic Overview</h4>
  134. <div class="ui two column stackable grid">
  135. <div class="column">
  136. <p>Visitor Counts</p>
  137. <table class="ui unstackable very basic celled table">
  138. <thead>
  139. <tr>
  140. <th>Country ISO Code</th>
  141. <th>Unique Visitors</th>
  142. </tr>
  143. </thead>
  144. <tbody id="countryCodetable">
  145. <tr>
  146. <td colspan="2">No Data</td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. </div>
  151. <div class="column">
  152. <p>Proxy Request Types</p>
  153. <table class="ui unstackable very basic celled table">
  154. <thead>
  155. <tr>
  156. <th>Proxy Type</th>
  157. <th>Count</th>
  158. </tr>
  159. </thead>
  160. <tbody id="forwardTypeTable">
  161. <tr>
  162. <td colspan="2">No Data</td>
  163. </tr>
  164. </tbody>
  165. </table>
  166. </div>
  167. </div>
  168. </div>
  169. <br>
  170. <button class="ui right floated basic button" onclick="getDailySummaryDetails();"><i class="green refresh icon"></i> Refresh</button>
  171. <br><br>
  172. </div>
  173. <script>
  174. let loopbackProxiedInterface = false;
  175. let currentListeningPort = 80;
  176. $(".advanceSettings").accordion();
  177. //Initial the start stop button if this is reverse proxied
  178. $.get("/api/proxy/requestIsProxied", function(data){
  179. if (data == true){
  180. //This management interface is reverse proxied by itself
  181. //do not allow turning off the proxy
  182. $(".notloopbackOnly").addClass("disabled");
  183. loopbackProxiedInterface = true;
  184. $("#rploopbackWarning").show();
  185. }
  186. });
  187. //Get the latest server status from proxy server
  188. function initRPStaste(){
  189. $.get("/api/proxy/status", function(data){
  190. $("#incomingPort").off("change");
  191. if (data.Running == true){
  192. $("#startbtn").addClass("disabled");
  193. if (!loopbackProxiedInterface){
  194. $("#stopbtn").removeClass("disabled");
  195. }
  196. $("#serverstatus").addClass("green");
  197. $("#statusTitle").text("Online");
  198. $("#rpStatusIcon").attr("class", "white circle check icon");
  199. $("#statusText").text("Serving request on port: " + data.Option.Port);
  200. }else{
  201. $("#startbtn").removeClass("disabled");
  202. $("#stopbtn").addClass("disabled");
  203. $("#statusTitle").text("Offline");
  204. $("#rpStatusIcon").attr("class", "yellow moon icon")
  205. $("#statusText").text("Reverse proxy server is offline");
  206. $("#serverstatus").removeClass("green");
  207. }
  208. $("#incomingPort").val(data.Option.Port);
  209. currentListeningPort = data.Option.Port;
  210. $("#incomingPort").on("change", function(){
  211. let newPortValue = $("#incomingPort").val().trim();
  212. if (currentListeningPort != newPortValue){
  213. $("#applyButtonReminder").show();
  214. }else{
  215. $("#applyButtonReminder").hide();
  216. }
  217. });
  218. });
  219. }
  220. function getDailySummaryDetails(){
  221. function sortObjectByValue(obj) {
  222. // Convert object to array of [key, value] pairs
  223. const entries = Object.entries(obj);
  224. // Sort array based on value of each pair
  225. entries.sort((a, b) => {
  226. return b[1] - a[1];
  227. });
  228. // Convert sorted array back to object
  229. const sortedObj = {};
  230. for (const [key, value] of entries) {
  231. sortedObj[key] = value;
  232. }
  233. return sortedObj;
  234. }
  235. $.get("/api/stats/countries", function(data){
  236. data = sortObjectByValue(data);
  237. $("#country").html((Object.keys(data)[0])?Object.keys(data)[0]:"No Data");
  238. $("#countryList").html(`
  239. <div>
  240. ${(Object.keys(data)[1])?Object.keys(data)[1]:"-"}<br>
  241. ${(Object.keys(data)[2])?Object.keys(data)[2]:"-"}
  242. </div>
  243. `);
  244. //populate the table
  245. $("#countryCodetable").html("");
  246. for (const [key, value] of Object.entries(data)) {
  247. var countryName = getCountryName(key);
  248. if (countryName == ""){
  249. countryName = "LAN"
  250. }
  251. $("#countryCodetable").append(`<tr>
  252. <td>${key} (${countryName})</td>
  253. <td>${value}</td>
  254. </tr>`);
  255. }
  256. if (Object.keys(data).length == 0){
  257. $("#countryCodetable").append(`<tr>
  258. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  259. </tr>`);
  260. }
  261. });
  262. //Filter forward type
  263. function fft(ft){
  264. if (ft.indexOf("-") >= 0){
  265. ft = ft.replace("-", " (");
  266. ft = ft + ")";
  267. }
  268. ft = ft.charAt(0).toUpperCase() + ft.slice(1);
  269. return ft;
  270. }
  271. $.get("/api/stats/summary", function(data){
  272. data = sortObjectByValue(data.ForwardTypes);
  273. $("#forwardtype").html((Object.keys(data)[0])?fft(Object.keys(data)[0]) + ": " + abbreviateNumber(data[Object.keys(data)[0]]):"No Data");
  274. $("#forwardtypeList").html(`
  275. <div>
  276. ${(Object.keys(data)[1])?fft(Object.keys(data)[1]) + ": " + abbreviateNumber(data[Object.keys(data)[1]]):"-"}<br>
  277. ${(Object.keys(data)[2])?fft(Object.keys(data)[2]) + ": " + abbreviateNumber(data[Object.keys(data)[2]]):"-"}
  278. </div>
  279. `);
  280. $("#forwardTypeTable").html("");
  281. for (const [key, value] of Object.entries(data)) {
  282. $("#forwardTypeTable").append(`<tr>
  283. <td>${key}</td>
  284. <td>${value}</td>
  285. </tr>`);
  286. }
  287. if (Object.keys(data).length == 0){
  288. $("#forwardTypeTable").append(`<tr>
  289. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  290. </tr>`);
  291. }
  292. });
  293. }
  294. getDailySummaryDetails();
  295. function getDailySummary(){
  296. $.get("/api/stats/summary?fast=true", function(data){
  297. $("#summaryTotalCount").text(abbreviateNumber(data.TotalRequest));
  298. $("#summarySuccCount").text(abbreviateNumber(data.ValidRequest));
  299. $("#summaryErrCount").text(abbreviateNumber(data.ErrorRequest));
  300. });
  301. }
  302. setInterval(function(){
  303. getDailySummary();
  304. }, 10000);
  305. getDailySummary();
  306. //Start and stop service button
  307. function startService(){
  308. $.cjax({
  309. url: "/api/proxy/enable",
  310. method: "POST",
  311. data: {enable: true},
  312. success: function(data){
  313. if (data.error != undefined){
  314. msgbox(data.error, false, 5000);
  315. }
  316. initRPStaste();
  317. }
  318. });
  319. }
  320. function stopService(){
  321. $.cjax({
  322. url: "/api/proxy/enable",
  323. method: "POST",
  324. data: {enable: false},
  325. success: function(data){
  326. if (data.error != undefined){
  327. msgbox(data.error, false, 5000);
  328. }
  329. initRPStaste();
  330. }
  331. });
  332. }
  333. function handleP80ListenerStateChange(enabled){
  334. $.cjax({
  335. url: "/api/proxy/listenPort80",
  336. method: "POST",
  337. data: {"enable": enabled},
  338. success: function(data){
  339. if (data.error != undefined){
  340. console.log(data.error);
  341. return;
  342. }
  343. if (enabled){
  344. //$("#redirect").show();
  345. $("#redirect").removeClass("disabled");
  346. msgbox("Port 80 listener enabled");
  347. }else{
  348. //$("#redirect").hide();
  349. $("#redirect").addClass("disabled");
  350. msgbox("Port 80 listener disabled");
  351. }
  352. }
  353. });
  354. }
  355. function handlePortChange(){
  356. var newPortValue = $("#incomingPort").val();
  357. if (isNaN(newPortValue - 1) || newPortValue < 1 || newPortValue > 65535){
  358. msgbox("Invalid incoming port value", false, 5000);
  359. return;
  360. }
  361. $.cjax({
  362. url: "/api/proxy/setIncoming",
  363. method: "POST",
  364. data: {incoming: newPortValue},
  365. success: function(data){
  366. if (data.error != undefined){
  367. msgbox(data.error, false, 5000);
  368. return;
  369. }
  370. msgbox("Listening Port Updated");
  371. initRPStaste();
  372. //Hide the reminder text
  373. $("#applyButtonReminder").hide();
  374. }
  375. });
  376. }
  377. function initPort80ListenerSetting(){
  378. $.get("/api/proxy/listenPort80", function(data){
  379. if (data){
  380. $("#listenP80").checkbox("set checked");
  381. $("#redirect").removeClass("disabled");
  382. //$("#redirect").show();
  383. }else{
  384. $("#listenP80").checkbox("set unchecked");
  385. $("#redirect").addClass("disabled");
  386. //$("#redirect").hide();
  387. }
  388. $("#listenP80").find("input").on("change", function(){
  389. let enabled = $(this)[0].checked;
  390. handleP80ListenerStateChange(enabled);
  391. })
  392. });
  393. }
  394. initPort80ListenerSetting();
  395. function initHTTPtoHTTPSRedirectSetting(){
  396. $.get("/api/proxy/useHttpsRedirect", function(data){
  397. if (data == true){
  398. $("#redirect").checkbox("set checked");
  399. }
  400. //Initiate the input listener on the checkbox
  401. $("#redirect").find("input").on("change", function(){
  402. let thisValue = $("#redirect").checkbox("is checked");
  403. $.cjax({
  404. url: "/api/proxy/useHttpsRedirect",
  405. method: "POST",
  406. data: {set: thisValue},
  407. success: function(data){
  408. if (data.error != undefined){
  409. msgbox(data.error, false, 8000);
  410. //Restore backend value to make sure the UI is always in sync
  411. $.get("/api/proxy/useHttpsRedirect", function(data){
  412. if (data == true){
  413. $("#redirect").checkbox("set checked");
  414. }else{
  415. $("#redirect").checkbox("set unchecked");
  416. }
  417. });
  418. }else{
  419. //Updated
  420. msgbox("Setting Updated");
  421. initRPStaste();
  422. }
  423. }
  424. })
  425. });
  426. });
  427. }
  428. initHTTPtoHTTPSRedirectSetting();
  429. function initTlsVersionSetting(){
  430. $.get("/api/cert/tlsRequireLatest", function(data){
  431. if (data == true){
  432. $("#tlsMinVer").checkbox("set checked");
  433. }else{
  434. $("#tlsMinVer").checkbox("set unchecked");
  435. }
  436. //Bind events to the checkbox
  437. $("#tlsMinVer").find("input").on("change", function(){
  438. let thisValue = $("#tlsMinVer").checkbox("is checked");
  439. $.cjax({
  440. url: "/api/cert/tlsRequireLatest",
  441. data: {"set": thisValue},
  442. method: "POST",
  443. success: function(data){
  444. if (data.error != undefined){
  445. msgbox(data.error, false, 5000);
  446. }else{
  447. msgbox("TLS Version Setting Updated");
  448. }
  449. }
  450. })
  451. });
  452. });
  453. }
  454. initTlsVersionSetting();
  455. function initDevelopmentMode(){
  456. $.get("/api/proxy/developmentMode", function(data){
  457. if (data === true){
  458. $("#developmentMode").checkbox("set checked")
  459. }else{
  460. $("#developmentMode").checkbox("set unchecked")
  461. }
  462. //Bind change events
  463. $("#developmentMode").off("change").on("change", function(data){
  464. let enableDevMode = ($(this).find("input[type='checkbox']")[0].checked);
  465. $.get("/api/proxy/developmentMode?enable=" + enableDevMode, function(data){
  466. if (enableDevMode){
  467. msgbox("Development mode enabled");
  468. }else{
  469. msgbox("Development mode disabled");
  470. }
  471. });
  472. });
  473. });
  474. }
  475. initDevelopmentMode();
  476. function initTlsSetting(){
  477. $.get("/api/cert/tls", function(data){
  478. if (data == true){
  479. $("#tls").checkbox("set checked");
  480. }else{
  481. $(".tlsEnabledOnly").addClass('disabled');
  482. $(".tlsEnabledOnly").addClass('disabled');
  483. }
  484. //Initiate the input listener on the checkbox
  485. $("#tls").find("input").on("change", function(){
  486. let thisValue = $("#tls").checkbox("is checked");
  487. if (thisValue){
  488. $(".tlsEnabledOnly").removeClass('disabled');
  489. }else{
  490. $(".tlsEnabledOnly").addClass('disabled');
  491. }
  492. $.cjax({
  493. url: "/api/cert/tls",
  494. method: "POST",
  495. data: {set: thisValue},
  496. success: function(data){
  497. if (data.error != undefined){
  498. msgbox(data.error, false);
  499. }else{
  500. //Updated
  501. //Check for case if the port is invalid default ports
  502. if ($("#incomingPort").val() == "80" && thisValue == true){
  503. confirmBox("Change listen port to :443?", function(choice){
  504. if (choice == true){
  505. $("#incomingPort").val("443");
  506. handlePortChange();
  507. }
  508. });
  509. }else if ($("#incomingPort").val() == "443" && thisValue == false){
  510. confirmBox("Change listen port to :80?", function(choice){
  511. if (choice == true){
  512. $("#incomingPort").val("80");
  513. handlePortChange();
  514. }
  515. });
  516. }else{
  517. msgbox("Setting Updated");
  518. }
  519. initRPStaste();
  520. }
  521. }
  522. })
  523. });
  524. })
  525. }
  526. initTlsSetting();
  527. </script>
  528. <script>
  529. /*
  530. Render Network Activity Graph
  531. */
  532. /*
  533. Setup Graph
  534. */
  535. let rxValues = [];
  536. let txValues = [];
  537. let dataCount = 300;
  538. let timestamps = [];
  539. for(var i = 0; i < dataCount; i++){
  540. timestamps.push(new Date(Date.now() + i * 1000).toLocaleString().replace(',', ''));
  541. }
  542. function fetchData() {
  543. $.ajax({
  544. url: '/api/stats/netstatgraph?array=true',
  545. success: function(data){
  546. if (rxValues.length == 0){
  547. rxValues.push(...data.Rx);
  548. }else{
  549. rxValues.push(data.Rx[dataCount-1]);
  550. rxValues.shift();
  551. }
  552. if (txValues.length == 0){
  553. txValues.push(...data.Tx);
  554. }else{
  555. txValues.push(data.Tx[dataCount-1]);
  556. txValues.shift();
  557. }
  558. timestamps.push(new Date(Date.now()).toLocaleString().replace(',', ''));
  559. timestamps.shift();
  560. updateChart();
  561. }
  562. })
  563. }
  564. function formatBandwidth(bps) {
  565. const KBPS = 1000;
  566. const MBPS = 1000 * KBPS;
  567. const GBPS = 1000 * MBPS;
  568. if (bps >= GBPS) {
  569. return (bps / GBPS).toFixed(2) + " Gbps";
  570. } else if (bps >= MBPS) {
  571. return (bps / MBPS).toFixed(2) + " Mbps";
  572. } else if (bps >= KBPS) {
  573. return (bps / KBPS).toFixed(2) + " Kbps";
  574. } else {
  575. return bps.toFixed(2) + " bps";
  576. }
  577. }
  578. var networkStatisticChart;
  579. function initChart(){
  580. $.get("/api/stats/netstat", function(data){
  581. networkStatisticChart = new Chart(
  582. document.getElementById('networkActivity'),
  583. {
  584. type: 'line',
  585. responsive: true,
  586. resizeDelay: 300,
  587. options: {
  588. animation: false,
  589. maintainAspectRatio: false,
  590. bezierCurve: true,
  591. tooltips: {enabled: false},
  592. hover: {mode: null},
  593. //stepped: 'middle',
  594. plugins: {
  595. legend: {
  596. display: true,
  597. position: "right",
  598. },
  599. title: {
  600. display: false,
  601. text: 'Network Statistic'
  602. },
  603. },
  604. scales: {
  605. x: {
  606. display: false,
  607. },
  608. y: {
  609. display: true,
  610. scaleLabel: {
  611. display: true,
  612. labelString: 'Value'
  613. },
  614. ticks: {
  615. stepSize: 10000000,
  616. callback: function(label, index, labels) {
  617. return formatBandwidth(parseInt(label));
  618. }
  619. },
  620. gridLines: {
  621. display: true
  622. }
  623. }
  624. }
  625. },
  626. data: {
  627. labels: timestamps,
  628. datasets: [
  629. {
  630. label: 'Inbound',
  631. data: rxValues,
  632. borderColor: "#484bb8",
  633. borderWidth: 1,
  634. backgroundColor: 'rgba(72, 75, 184, 0.2)',
  635. fill: true,
  636. pointStyle: false,
  637. },
  638. {
  639. label: 'Outbound',
  640. data: txValues,
  641. borderColor: '#02a9c1',
  642. borderWidth: 1,
  643. backgroundColor: 'rgba(2, 169, 193, 0.2)',
  644. fill: true,
  645. pointStyle: false,
  646. }
  647. ]
  648. }
  649. }
  650. );
  651. });
  652. }
  653. function updateChart() {
  654. //networkStatisticChart.data.datasets[0].data = rxValues;
  655. //networkStatisticChart.data.datasets[1].data = txValues;
  656. if (networkStatisticChart != undefined){
  657. networkStatisticChart.update();
  658. }
  659. }
  660. function updateChartSize(){
  661. let newSize = $("#networkActWrapper").width() - 300;
  662. if (window.innerWidth > 750){
  663. newSize = window.innerWidth - $(".toolbar").width() - 500;
  664. }else{
  665. newSize = $("#networkActWrapper").width() - 500;
  666. }
  667. if (networkStatisticChart != undefined){
  668. networkStatisticChart.resize(newSize, 200);
  669. }
  670. }
  671. function handleChartAccumulateResize(){
  672. $("#networkActivity").hide();
  673. $("#networkActivityPlaceHolder").show();
  674. if (chartResizeTimeout != undefined){
  675. clearTimeout(chartResizeTimeout);
  676. }
  677. chartResizeTimeout = setTimeout(function(){
  678. chartResizeTimeout = undefined;
  679. $("#networkActivityPlaceHolder").hide();
  680. $("#networkActivity").show();
  681. updateChartSize();
  682. }, 300);
  683. }
  684. var chartResizeTimeout;
  685. window.addEventListener('resize', () => {
  686. handleChartAccumulateResize();
  687. });
  688. //Bind event to tab switch
  689. tabSwitchEventBind["status"] = function(){
  690. //On switch over to this page, resize the chart
  691. handleChartAccumulateResize();
  692. }
  693. window.addEventListener("focus", function(event){
  694. handleChartAccumulateResize();
  695. });
  696. //Initialize chart data
  697. initChart();
  698. fetchData();
  699. setInterval(fetchData, 1000);
  700. </script>