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