1
0

status.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 greybackground 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">
  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">
  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. </div>
  47. </div>
  48. </h5>
  49. </div>
  50. </div>
  51. </div>
  52. <div id="networkActWrapper" class="standardContainer" style="position: relative; margin-top: 1em;">
  53. <canvas id="networkActivity"></canvas>
  54. </div>
  55. <div id="networkActivityPlaceHolder">
  56. <p style="opacity: 0.5;"><i class="ui pause icon"></i> Graph Render Paused</p>
  57. </div>
  58. <br>
  59. <div class="standardContainer">
  60. <h4>Basic Settings</h4>
  61. <p>Inbound Port (Port to be proxied)</p>
  62. <div class="ui action fluid notloopbackOnly input">
  63. <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
  64. <button class="ui basic green notloopbackOnly button" onclick="handlePortChange();">Apply</button>
  65. </div>
  66. <br>
  67. <div id="tls" class="ui toggle notloopbackOnly checkbox">
  68. <input type="checkbox">
  69. <label>Use TLS to serve proxy request</label>
  70. </div>
  71. <br>
  72. <div id="tlsMinVer" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.6em;">
  73. <input type="checkbox">
  74. <label>Force TLS v1.2 or above<br>
  75. <small>(Not compatible with legacy browsers)</small></label>
  76. </div>
  77. <br>
  78. <div id="redirect" class="ui toggle notloopbackOnly tlsEnabledOnly checkbox" style="margin-top: 0.6em;">
  79. <input type="checkbox">
  80. <label>Force redirect HTTP request to HTTPS<br>
  81. <small>(Only apply when listening port is not 80)</small></label>
  82. </div>
  83. <br><br>
  84. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  85. <button id="stopbtn" class="ui red notloopbackOnly disabled button" onclick="stopService();">Stop Service</button>
  86. <div id="rploopbackWarning" class="ui segment" style="display:none;">
  87. <b><i class="yellow warning icon"></i> Loopback Routing Warning</b><br>
  88. <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>
  89. </div>
  90. <div class="ui divider"></div>
  91. <div class="">
  92. <h4>Statistic Overview</h4>
  93. <div class="ui two column stackable grid">
  94. <div class="column">
  95. <p>Visitor Counts</p>
  96. <table class="ui unstackable inverted celled table">
  97. <thead>
  98. <tr>
  99. <th>Country ISO Code</th>
  100. <th>Unique Visitors</th>
  101. </tr>
  102. </thead>
  103. <tbody id="countryCodetable">
  104. <tr>
  105. <td colspan="2">No Data</td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. </div>
  110. <div class="column">
  111. <p>Proxy Request Types</p>
  112. <table class="ui unstackable inverted celled table">
  113. <thead>
  114. <tr>
  115. <th>Proxy Type</th>
  116. <th>Count</th>
  117. </tr>
  118. </thead>
  119. <tbody id="forwardTypeTable">
  120. <tr>
  121. <td colspan="2">No Data</td>
  122. </tr>
  123. </tbody>
  124. </table>
  125. </div>
  126. </div>
  127. </div>
  128. <br>
  129. <button class="ui right floated basic button" onclick="getDailySummaryDetails();"><i class="green refresh icon"></i> Refresh</button>
  130. <br><br>
  131. </div>
  132. <script>
  133. let loopbackProxiedInterface = false;
  134. //Initial the start stop button if this is reverse proxied
  135. $.get("/api/proxy/requestIsProxied", function(data){
  136. if (data == true){
  137. //This management interface is reverse proxied by itself
  138. //do not allow turning off the proxy
  139. $(".notloopbackOnly").addClass("disabled");
  140. loopbackProxiedInterface = true;
  141. $("#rploopbackWarning").show();
  142. }
  143. });
  144. //Get the latest server status from proxy server
  145. function initRPStaste(){
  146. $.get("/api/proxy/status", function(data){
  147. if (data.Running == true){
  148. $("#startbtn").addClass("disabled");
  149. if (!loopbackProxiedInterface){
  150. $("#stopbtn").removeClass("disabled");
  151. }
  152. $("#serverstatus").addClass("green");
  153. $("#statusTitle").text("Online");
  154. $("#rpStatusIcon").attr("class", "green circle check icon");
  155. $("#statusText").text("Serving request on port: " + data.Option.Port);
  156. }else{
  157. $("#startbtn").removeClass("disabled");
  158. $("#stopbtn").addClass("disabled");
  159. $("#statusTitle").text("Offline");
  160. $("#rpStatusIcon").attr("class", "black circle times icon")
  161. $("#statusText").text("Reverse proxy server is offline");
  162. $("#serverstatus").removeClass("green");
  163. }
  164. $("#incomingPort").val(data.Option.Port);
  165. });
  166. }
  167. function getDailySummaryDetails(){
  168. function sortObjectByValue(obj) {
  169. // Convert object to array of [key, value] pairs
  170. const entries = Object.entries(obj);
  171. // Sort array based on value of each pair
  172. entries.sort((a, b) => {
  173. return b[1] - a[1];
  174. });
  175. // Convert sorted array back to object
  176. const sortedObj = {};
  177. for (const [key, value] of entries) {
  178. sortedObj[key] = value;
  179. }
  180. return sortedObj;
  181. }
  182. $.get("/api/stats/countries", function(data){
  183. data = sortObjectByValue(data);
  184. $("#country").html((Object.keys(data)[0])?Object.keys(data)[0]:"No Data");
  185. $("#countryList").html(`
  186. <div>
  187. ${(Object.keys(data)[1])?Object.keys(data)[1]:"-"}<br>
  188. ${(Object.keys(data)[2])?Object.keys(data)[2]:"-"}
  189. </div>
  190. `);
  191. //populate the table
  192. $("#countryCodetable").html("");
  193. for (const [key, value] of Object.entries(data)) {
  194. var countryName = getCountryName(key);
  195. if (countryName == ""){
  196. countryName = "LAN"
  197. }
  198. $("#countryCodetable").append(`<tr>
  199. <td>${key} (${countryName})</td>
  200. <td>${value}</td>
  201. </tr>`);
  202. }
  203. if (Object.keys(data).length == 0){
  204. $("#countryCodetable").append(`<tr>
  205. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  206. </tr>`);
  207. }
  208. });
  209. //Filter forward type
  210. function fft(ft){
  211. if (ft.indexOf("-") >= 0){
  212. ft = ft.replace("-", " (");
  213. ft = ft + ")";
  214. }
  215. ft = ft.charAt(0).toUpperCase() + ft.slice(1);
  216. return ft;
  217. }
  218. $.get("/api/stats/summary", function(data){
  219. data = sortObjectByValue(data.ForwardTypes);
  220. $("#forwardtype").html((Object.keys(data)[0])?fft(Object.keys(data)[0]) + ": " + abbreviateNumber(data[Object.keys(data)[0]]):"No Data");
  221. $("#forwardtypeList").html(`
  222. <div>
  223. ${(Object.keys(data)[1])?fft(Object.keys(data)[1]) + ": " + abbreviateNumber(data[Object.keys(data)[1]]):"-"}<br>
  224. ${(Object.keys(data)[2])?fft(Object.keys(data)[2]) + ": " + abbreviateNumber(data[Object.keys(data)[2]]):"-"}
  225. </div>
  226. `);
  227. $("#forwardTypeTable").html("");
  228. for (const [key, value] of Object.entries(data)) {
  229. $("#forwardTypeTable").append(`<tr>
  230. <td>${key}</td>
  231. <td>${value}</td>
  232. </tr>`);
  233. }
  234. if (Object.keys(data).length == 0){
  235. $("#forwardTypeTable").append(`<tr>
  236. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  237. </tr>`);
  238. }
  239. });
  240. }
  241. getDailySummaryDetails();
  242. function getDailySummary(){
  243. $.get("/api/stats/summary?fast=true", function(data){
  244. $("#summaryTotalCount").text(abbreviateNumber(data.TotalRequest));
  245. $("#summarySuccCount").text(abbreviateNumber(data.ValidRequest));
  246. $("#summaryErrCount").text(abbreviateNumber(data.ErrorRequest));
  247. });
  248. }
  249. setInterval(function(){
  250. getDailySummary();
  251. }, 10000);
  252. getDailySummary();
  253. //Start and stop service button
  254. function startService(){
  255. $.post("/api/proxy/enable", {enable: true}, function(data){
  256. if (data.error != undefined){
  257. msgbox(data.error, false, 5000);
  258. }
  259. initRPStaste();
  260. });
  261. }
  262. function stopService(){
  263. $.post("/api/proxy/enable", {enable: false}, function(data){
  264. if (data.error != undefined){
  265. msgbox(data.error, false, 5000);
  266. }
  267. initRPStaste();
  268. });
  269. }
  270. function handlePortChange(){
  271. var newPortValue = $("#incomingPort").val();
  272. if (isNaN(newPortValue - 1) || newPortValue < 1 || newPortValue > 65535){
  273. msgbox("Invalid incoming port value", false, 5000);
  274. return;
  275. }
  276. $.post("/api/proxy/setIncoming", {incoming: newPortValue}, function(data){
  277. if (data.error != undefined){
  278. msgbox(data.error, false, 5000);
  279. return;
  280. }
  281. msgbox("Setting Updated");
  282. initRPStaste();
  283. });
  284. }
  285. function initHTTPtoHTTPSRedirectSetting(){
  286. $.get("/api/proxy/useHttpsRedirect", function(data){
  287. if (data == true){
  288. $("#redirect").checkbox("set checked");
  289. }
  290. //Initiate the input listener on the checkbox
  291. $("#redirect").find("input").on("change", function(){
  292. let thisValue = $("#redirect").checkbox("is checked");
  293. $.ajax({
  294. url: "/api/proxy/useHttpsRedirect",
  295. data: {set: thisValue},
  296. success: function(data){
  297. if (data.error != undefined){
  298. msgbox(data.error, false, 8000);
  299. //Restore backend value to make sure the UI is always in sync
  300. $.get("/api/proxy/useHttpsRedirect", function(data){
  301. if (data == true){
  302. $("#redirect").checkbox("set checked");
  303. }else{
  304. $("#redirect").checkbox("set unchecked");
  305. }
  306. });
  307. }else{
  308. //Updated
  309. msgbox("Setting Updated");
  310. initRPStaste();
  311. }
  312. }
  313. })
  314. });
  315. });
  316. }
  317. initHTTPtoHTTPSRedirectSetting();
  318. function initTlsVersionSetting(){
  319. $.get("/api/cert/tlsRequireLatest", function(data){
  320. if (data == true){
  321. $("#tlsMinVer").checkbox("set checked");
  322. }else{
  323. $("#tlsMinVer").checkbox("set unchecked");
  324. }
  325. //Bind events to the checkbox
  326. $("#tlsMinVer").find("input").on("change", function(){
  327. let thisValue = $("#tlsMinVer").checkbox("is checked");
  328. $.ajax({
  329. url: "/api/cert/tlsRequireLatest",
  330. data: {"set": thisValue},
  331. success: function(data){
  332. if (data.error != undefined){
  333. msgbox(data.error, false, 5000);
  334. }else{
  335. msgbox("TLS Version Setting Updated");
  336. }
  337. }
  338. })
  339. });
  340. });
  341. }
  342. initTlsVersionSetting();
  343. function initTlsSetting(){
  344. $.get("/api/cert/tls", function(data){
  345. if (data == true){
  346. $("#tls").checkbox("set checked");
  347. }else{
  348. $(".tlsEnabledOnly").addClass('disabled');
  349. $(".tlsEnabledOnly").addClass('disabled');
  350. }
  351. //Initiate the input listener on the checkbox
  352. $("#tls").find("input").on("change", function(){
  353. let thisValue = $("#tls").checkbox("is checked");
  354. if (thisValue){
  355. $(".tlsEnabledOnly").removeClass('disabled');
  356. }else{
  357. $(".tlsEnabledOnly").addClass('disabled');
  358. }
  359. $.ajax({
  360. url: "/api/cert/tls",
  361. data: {set: thisValue},
  362. success: function(data){
  363. if (data.error != undefined){
  364. alert(data.error);
  365. }else{
  366. //Updated
  367. msgbox("Setting Updated");
  368. initRPStaste();
  369. }
  370. }
  371. })
  372. });
  373. })
  374. }
  375. initTlsSetting();
  376. </script>
  377. <script>
  378. /*
  379. Render Network Activity Graph
  380. */
  381. /*
  382. Setup Graph
  383. */
  384. let rxValues = [];
  385. let txValues = [];
  386. let dataCount = 300;
  387. let timestamps = [];
  388. for(var i = 0; i < dataCount; i++){
  389. timestamps.push(parseInt(Date.now() / 1000) + i);
  390. }
  391. function fetchData() {
  392. $.ajax({
  393. url: '/api/stats/netstatgraph?array=true',
  394. success: function(data){
  395. if (rxValues.length == 0){
  396. rxValues = JSON.parse(JSON.stringify(data.Rx));
  397. }else{
  398. rxValues.push(data.Rx[dataCount-1]);
  399. rxValues.shift();
  400. }
  401. if (txValues.length == 0){
  402. txValues = JSON.parse(JSON.stringify(data.Tx));
  403. }else{
  404. txValues.push(data.Tx[dataCount-1]);
  405. txValues.shift();
  406. }
  407. timestamps.push(parseInt(Date.now() / 1000));
  408. timestamps.shift();
  409. updateChart();
  410. }
  411. })
  412. }
  413. function formatBandwidth(bps) {
  414. const KBPS = 1000;
  415. const MBPS = 1000 * KBPS;
  416. const GBPS = 1000 * MBPS;
  417. if (bps >= GBPS) {
  418. return (bps / GBPS).toFixed(2) + " Gbps";
  419. } else if (bps >= MBPS) {
  420. return (bps / MBPS).toFixed(2) + " Mbps";
  421. } else if (bps >= KBPS) {
  422. return (bps / KBPS).toFixed(2) + " Kbps";
  423. } else {
  424. return bps.toFixed(2) + " bps";
  425. }
  426. }
  427. var networkStatisticChart;
  428. function initChart(){
  429. $.get("/api/stats/netstat", function(data){
  430. networkStatisticChart = new Chart(
  431. document.getElementById('networkActivity'),
  432. {
  433. type: 'line',
  434. responsive: true,
  435. resizeDelay: 100,
  436. options: {
  437. animation: false,
  438. maintainAspectRatio: false,
  439. tooltips: {enabled: false},
  440. hover: {mode: null},
  441. //stepped: 'middle',
  442. plugins: {
  443. legend: {
  444. display: true,
  445. position: "right",
  446. },
  447. title: {
  448. display: false,
  449. text: 'Network Statistic'
  450. },
  451. },
  452. scales: {
  453. x: {
  454. display: false,
  455. },
  456. y: {
  457. display: true,
  458. scaleLabel: {
  459. display: true,
  460. labelString: 'Value'
  461. },
  462. ticks: {
  463. stepSize: 10000000,
  464. callback: function(label, index, labels) {
  465. return formatBandwidth(parseInt(label));
  466. }
  467. },
  468. gridLines: {
  469. display: true
  470. }
  471. }
  472. }
  473. },
  474. data: {
  475. labels: timestamps,
  476. datasets: [
  477. {
  478. label: 'Inbound',
  479. data: rxValues,
  480. borderColor: "#4d9dd9",
  481. borderWidth: 2,
  482. backgroundColor: 'rgba(77, 157, 217, 0.2)',
  483. fill: true,
  484. pointStyle: false,
  485. },
  486. {
  487. label: 'Outbound',
  488. data: txValues,
  489. borderColor: '#ffe32b',
  490. borderWidth: 2,
  491. backgroundColor: 'rgba(255, 227, 43, 0.2)',
  492. fill: true,
  493. pointStyle: false,
  494. }
  495. ]
  496. }
  497. }
  498. );
  499. });
  500. }
  501. function updateChart() {
  502. //networkStatisticChart.data.datasets[0].data = rxValues;
  503. //networkStatisticChart.data.datasets[1].data = txValues;
  504. if (networkStatisticChart != undefined){
  505. networkStatisticChart.update();
  506. }
  507. }
  508. function updateChartSize(){
  509. let newSize = $("#networkActWrapper").width() - 300;
  510. if (window.innerWidth > 750){
  511. newSize = window.innerWidth - $(".toolbar").width() - 500;
  512. }else{
  513. newSize = $("#networkActWrapper").width() - 500;
  514. }
  515. if (networkStatisticChart != undefined){
  516. networkStatisticChart.resize(newSize, 200);
  517. }
  518. }
  519. function handleChartAccumulateResize(){
  520. $("#networkActivity").hide();
  521. $("#networkActivityPlaceHolder").show();
  522. if (chartResizeTimeout != undefined){
  523. clearTimeout(chartResizeTimeout);
  524. }
  525. chartResizeTimeout = setTimeout(function(){
  526. chartResizeTimeout = undefined;
  527. $("#networkActivityPlaceHolder").hide();
  528. $("#networkActivity").show();
  529. updateChartSize();
  530. }, 300);
  531. }
  532. var chartResizeTimeout;
  533. window.addEventListener('resize', () => {
  534. handleChartAccumulateResize();
  535. });
  536. //Bind event to tab switch
  537. tabSwitchEventBind["status"] = function(){
  538. //On switch over to this page, resize the chart
  539. handleChartAccumulateResize();
  540. }
  541. window.addEventListener("focus", function(event){
  542. handleChartAccumulateResize();
  543. });
  544. //Initialize chart data
  545. initChart();
  546. fetchData();
  547. setInterval(fetchData, 1000);
  548. </script>