status.html 27 KB

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