1
0

status.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. <br>
  53. <div class="standardContainer">
  54. <h4>Basic Settings</h4>
  55. <p>Inbound Port (Port to be proxied)</p>
  56. <div class="ui action fluid notloopbackOnly input">
  57. <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
  58. <button class="ui basic green notloopbackOnly button" onclick="handlePortChange();">Apply</button>
  59. </div>
  60. <br>
  61. <div id="tls" class="ui toggle notloopbackOnly checkbox">
  62. <input type="checkbox">
  63. <label>Use TLS to serve proxy request</label>
  64. </div>
  65. <br>
  66. <div id="redirect" class="ui toggle notloopbackOnly checkbox" style="margin-top: 0.6em;">
  67. <input type="checkbox">
  68. <label>Force redirect HTTP request to HTTPS<br>
  69. <small>(Only apply when listening port is not 80)</small></label>
  70. </div>
  71. <br><br>
  72. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  73. <button id="stopbtn" class="ui red notloopbackOnly disabled button" onclick="stopService();">Stop Service</button>
  74. <div id="rploopbackWarning" class="ui segment" style="display:none;">
  75. <b><i class="yellow warning icon"></i> Loopback Routing Warning</b><br>
  76. <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>
  77. </div>
  78. <div class="ui divider"></div>
  79. <div class="">
  80. <h4>Statistic Overview</h4>
  81. <div class="ui two column stackable grid">
  82. <div class="column">
  83. <p>Visitor Counts</p>
  84. <table class="ui unstackable inverted celled table">
  85. <thead>
  86. <tr>
  87. <th>Country ISO Code</th>
  88. <th>Unique Visitors</th>
  89. </tr>
  90. </thead>
  91. <tbody id="countryCodetable">
  92. <tr>
  93. <td colspan="2">No Data</td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. </div>
  98. <div class="column">
  99. <p>Proxy Request Types</p>
  100. <table class="ui unstackable inverted celled table">
  101. <thead>
  102. <tr>
  103. <th>Proxy Type</th>
  104. <th>Count</th>
  105. </tr>
  106. </thead>
  107. <tbody id="forwardTypeTable">
  108. <tr>
  109. <td colspan="2">No Data</td>
  110. </tr>
  111. </tbody>
  112. </table>
  113. </div>
  114. </div>
  115. </div>
  116. <br>
  117. <button class="ui right floated basic button" onclick="getDailySummaryDetails();"><i class="green refresh icon"></i> Refresh</button>
  118. <br><br>
  119. </div>
  120. <script>
  121. let loopbackProxiedInterface = false;
  122. //Initial the start stop button if this is reverse proxied
  123. $.get("/api/proxy/requestIsProxied", function(data){
  124. if (data == true){
  125. //This management interface is reverse proxied by itself
  126. //do not allow turning off the proxy
  127. $(".notloopbackOnly").addClass("disabled");
  128. loopbackProxiedInterface = true;
  129. $("#rploopbackWarning").show();
  130. }
  131. });
  132. //Get the latest server status from proxy server
  133. function initRPStaste(){
  134. $.get("/api/proxy/status", function(data){
  135. if (data.Running == true){
  136. $("#startbtn").addClass("disabled");
  137. if (!loopbackProxiedInterface){
  138. $("#stopbtn").removeClass("disabled");
  139. }
  140. $("#serverstatus").addClass("green");
  141. $("#statusTitle").text("Online");
  142. $("#rpStatusIcon").attr("class", "green circle check icon");
  143. $("#statusText").text("Serving request on port: " + data.Option.Port);
  144. }else{
  145. $("#startbtn").removeClass("disabled");
  146. $("#stopbtn").addClass("disabled");
  147. $("#statusTitle").text("Offline");
  148. $("#rpStatusIcon").attr("class", "black circle times icon")
  149. $("#statusText").text("Reverse proxy server is offline");
  150. $("#serverstatus").removeClass("green");
  151. }
  152. $("#incomingPort").val(data.Option.Port);
  153. });
  154. }
  155. function abbreviateNumber(value) {
  156. var newValue = value;
  157. var suffixes = ["", "k", "m", "b", "t"];
  158. var suffixNum = 0;
  159. while (newValue >= 1000 && suffixNum < suffixes.length - 1) {
  160. newValue /= 1000;
  161. suffixNum++;
  162. }
  163. if (value > 1000){
  164. newValue = newValue.toFixed(2);
  165. }
  166. return newValue + suffixes[suffixNum];
  167. }
  168. function getDailySummaryDetails(){
  169. function sortObjectByValue(obj) {
  170. // Convert object to array of [key, value] pairs
  171. const entries = Object.entries(obj);
  172. // Sort array based on value of each pair
  173. entries.sort((a, b) => {
  174. return b[1] - a[1];
  175. });
  176. // Convert sorted array back to object
  177. const sortedObj = {};
  178. for (const [key, value] of entries) {
  179. sortedObj[key] = value;
  180. }
  181. return sortedObj;
  182. }
  183. $.get("/api/stats/countries", function(data){
  184. data = sortObjectByValue(data);
  185. $("#country").html((Object.keys(data)[0])?Object.keys(data)[0]:"No Data");
  186. $("#countryList").html(`
  187. <div>
  188. ${(Object.keys(data)[1])?Object.keys(data)[1]:"-"}<br>
  189. ${(Object.keys(data)[2])?Object.keys(data)[2]:"-"}
  190. </div>
  191. `);
  192. //populate the table
  193. $("#countryCodetable").html("");
  194. for (const [key, value] of Object.entries(data)) {
  195. $("#countryCodetable").append(`<tr>
  196. <td>${key}</td>
  197. <td>${value}</td>
  198. </tr>`);
  199. }
  200. if (Object.keys(data).length == 0){
  201. $("#countryCodetable").append(`<tr>
  202. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  203. </tr>`);
  204. }
  205. });
  206. //Filter forward type
  207. function fft(ft){
  208. if (ft.indexOf("-") >= 0){
  209. ft = ft.replace("-", " (");
  210. ft = ft + ")";
  211. }
  212. ft = ft.charAt(0).toUpperCase() + ft.slice(1);
  213. return ft;
  214. }
  215. $.get("/api/stats/summary", function(data){
  216. data = sortObjectByValue(data.ForwardTypes);
  217. $("#forwardtype").html((Object.keys(data)[0])?fft(Object.keys(data)[0]) + ": " + abbreviateNumber(data[Object.keys(data)[0]]):"No Data");
  218. $("#forwardtypeList").html(`
  219. <div>
  220. ${(Object.keys(data)[1])?fft(Object.keys(data)[1]) + ": " + abbreviateNumber(data[Object.keys(data)[1]]):"-"}<br>
  221. ${(Object.keys(data)[2])?fft(Object.keys(data)[2]) + ": " + abbreviateNumber(data[Object.keys(data)[2]]):"-"}
  222. </div>
  223. `);
  224. $("#forwardTypeTable").html("");
  225. for (const [key, value] of Object.entries(data)) {
  226. $("#forwardTypeTable").append(`<tr>
  227. <td>${key}</td>
  228. <td>${value}</td>
  229. </tr>`);
  230. }
  231. if (Object.keys(data).length == 0){
  232. $("#forwardTypeTable").append(`<tr>
  233. <td colspan="2"><i class="ui green circle check icon"></i> No Data</td>
  234. </tr>`);
  235. }
  236. });
  237. }
  238. getDailySummaryDetails();
  239. function getDailySummary(){
  240. $.get("/api/stats/summary?fast=true", function(data){
  241. console.log(data);
  242. $("#summaryTotalCount").text(abbreviateNumber(data.TotalRequest));
  243. $("#summarySuccCount").text(abbreviateNumber(data.ValidRequest));
  244. $("#summaryErrCount").text(abbreviateNumber(data.ErrorRequest));
  245. });
  246. }
  247. setInterval(function(){
  248. getDailySummary();
  249. }, 10000);
  250. getDailySummary();
  251. //Start and stop service button
  252. function startService(){
  253. $.post("/api/proxy/enable", {enable: true}, function(data){
  254. if (data.error != undefined){
  255. msgbox(data.error, false, 5000);
  256. }
  257. initRPStaste();
  258. });
  259. }
  260. function stopService(){
  261. $.post("/api/proxy/enable", {enable: false}, function(data){
  262. if (data.error != undefined){
  263. msgbox(data.error, false, 5000);
  264. }
  265. initRPStaste();
  266. });
  267. }
  268. function handlePortChange(){
  269. var newPortValue = $("#incomingPort").val();
  270. if (isNaN(newPortValue - 1) || newPortValue < 1 || newPortValue > 65535){
  271. msgbox("Invalid incoming port value", false, 5000);
  272. return;
  273. }
  274. $.post("/api/proxy/setIncoming", {incoming: newPortValue}, function(data){
  275. if (data.error != undefined){
  276. msgbox(data.error, false, 5000);
  277. }
  278. msgbox("Setting Updated");
  279. initRPStaste();
  280. });
  281. }
  282. function initHTTPtoHTTPSRedirectSetting(){
  283. $.get("/api/proxy/useHttpsRedirect", function(data){
  284. if (data == true){
  285. $("#redirect").checkbox("set checked");
  286. }
  287. //Initiate the input listener on the checkbox
  288. $("#redirect").find("input").on("change", function(){
  289. let thisValue = $("#redirect").checkbox("is checked");
  290. $.ajax({
  291. url: "/api/proxy/useHttpsRedirect",
  292. data: {set: thisValue},
  293. success: function(data){
  294. if (data.error != undefined){
  295. alert(data.error);
  296. }else{
  297. //Updated
  298. msgbox("Setting Updated");
  299. initRPStaste();
  300. }
  301. }
  302. })
  303. });
  304. });
  305. }
  306. initHTTPtoHTTPSRedirectSetting();
  307. function initTlsSetting(){
  308. $.get("/api/cert/tls", function(data){
  309. if (data == true){
  310. $("#tls").checkbox("set checked");
  311. }else{
  312. $("#redirect").addClass('disabled');
  313. }
  314. //Initiate the input listener on the checkbox
  315. $("#tls").find("input").on("change", function(){
  316. let thisValue = $("#tls").checkbox("is checked");
  317. if (thisValue){
  318. $("#redirect").removeClass('disabled');
  319. }else{
  320. $("#redirect").addClass('disabled');
  321. }
  322. $.ajax({
  323. url: "/api/cert/tls",
  324. data: {set: thisValue},
  325. success: function(data){
  326. if (data.error != undefined){
  327. alert(data.error);
  328. }else{
  329. //Updated
  330. msgbox("Setting Updated");
  331. initRPStaste();
  332. }
  333. }
  334. })
  335. });
  336. })
  337. }
  338. initTlsSetting();
  339. </script>