status.html 27 KB

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