status.html 27 KB

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