status.html 14 KB

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