status.html 12 KB

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