status.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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="exchange icon"></i>
  31. <div class="content">
  32. <span></span>
  33. <div class="sub header"></div>
  34. </div>
  35. </h4>
  36. </div>
  37. </div>
  38. <div class="column">
  39. <div id="connections" class="ui pink statustab inverted segment">
  40. <h4 class="ui header">
  41. <i class="exchange icon"></i>
  42. <div class="content">
  43. <span></span>
  44. <div class="sub header"></div>
  45. </div>
  46. </h4>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="ui divider"></div>
  51. <p>Inbound Port (Port to be proxied)</p>
  52. <div class="ui action fluid input">
  53. <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
  54. <button class="ui button" onclick="handlePortChange();">Apply</button>
  55. </div>
  56. <br>
  57. <div id="tls" class="ui toggle checkbox">
  58. <input type="checkbox">
  59. <label>Use TLS to serve proxy request</label>
  60. </div>
  61. <br>
  62. <div id="redirect" class="ui toggle checkbox" style="margin-top: 0.6em;">
  63. <input type="checkbox">
  64. <label>Force redirect HTTP request to HTTPS<br>
  65. <small>(Only apply when listening port is 443)</small></label>
  66. </div>
  67. <br>
  68. <div id="portUpdateSucc" class="ui green message" style="display:none;">
  69. <i class="ui green checkmark icon"></i> Setting Updated
  70. </div>
  71. <Br>
  72. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  73. <button id="stopbtn" class="ui red 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 id="statusErrmsg" class="ui red message" style="display: none;"></div>
  79. <div class="ui divider"></div>
  80. <div class="ui two column stackable grid">
  81. <div class="column">
  82. <p>Visitor Counts</p>
  83. <table class="ui basic celled table">
  84. <thead>
  85. <tr>
  86. <th>Country ISO Code</th>
  87. <th>Visitor Count</th>
  88. </tr>
  89. </thead>
  90. <tbody>
  91. <!-- insert table rows here -->
  92. </tbody>
  93. </table>
  94. </div>
  95. <div class="column">
  96. <p>Proxy Request Types</p>
  97. <table class="ui basic celled table">
  98. <thead>
  99. <tr>
  100. <th>Proxy Type</th>
  101. <th>Count</th>
  102. </tr>
  103. </thead>
  104. <tbody>
  105. <!-- insert table rows here -->
  106. </tbody>
  107. </table>
  108. </div>
  109. </div>
  110. <br>
  111. <button class="ui basic green button"><i class="refresh icon"></i> Refresh</button>
  112. <script>
  113. let loopbackProxiedInterface = false;
  114. //Initial the start stop button if this is reverse proxied
  115. $.get("/api/proxy/requestIsProxied", function(data){
  116. if (data == true){
  117. //This management interface is reverse proxied by itself
  118. //do not allow turning off the proxy
  119. $("#stopbtn").addClass("disabled");
  120. loopbackProxiedInterface = true;
  121. $("#rploopbackWarning").show();
  122. }
  123. });
  124. //Get the latest server status from proxy server
  125. function initRPStaste(){
  126. $.get("/api/proxy/status", function(data){
  127. if (data.Running == true){
  128. $("#startbtn").addClass("disabled");
  129. if (!loopbackProxiedInterface){
  130. $("#stopbtn").removeClass("disabled");
  131. }
  132. $("#serverstatus").addClass("green");
  133. $("#statusTitle").text("Online");
  134. $("#statusText").text("Serving request on port: " + data.Option.Port);
  135. }else{
  136. $("#startbtn").removeClass("disabled");
  137. $("#stopbtn").addClass("disabled");
  138. $("#statusTitle").text("Offline");
  139. $("#statusText").text("Reverse proxy server is offline");
  140. $("#serverstatus").removeClass("green");
  141. }
  142. $("#incomingPort").val(data.Option.Port);
  143. });
  144. }
  145. function abbreviateNumber(value) {
  146. var newValue = value;
  147. var suffixes = ["", "K", "M", "B", "T"];
  148. var suffixNum = 0;
  149. while (newValue >= 1000 && suffixNum < suffixes.length - 1) {
  150. newValue /= 1000;
  151. suffixNum++;
  152. }
  153. if (value > 1000){
  154. newValue = newValue.toFixed(2);
  155. }
  156. return newValue + suffixes[suffixNum];
  157. }
  158. function getDailySummary(){
  159. $.get("/api/stats/summary?fast=true", function(data){
  160. console.log(data);
  161. $("#summaryTotalCount").text(abbreviateNumber(data.TotalRequest));
  162. $("#summarySuccCount").text(abbreviateNumber(data.ValidRequest));
  163. $("#summaryErrCount").text(abbreviateNumber(data.ErrorRequest));
  164. });
  165. }
  166. setInterval(function(){
  167. getDailySummary();
  168. }, 10000);
  169. getDailySummary();
  170. //Start and stop service button
  171. function startService(){
  172. $.post("/api/proxy/enable", {enable: true}, function(data){
  173. if (data.error != undefined){
  174. statusErrmsg(data.error);
  175. }
  176. initRPStaste();
  177. });
  178. }
  179. function stopService(){
  180. $.post("/api/proxy/enable", {enable: false}, function(data){
  181. if (data.error != undefined){
  182. statusErrmsg(data.error);
  183. }
  184. initRPStaste();
  185. });
  186. }
  187. //Show error message
  188. function statusErrmsg(message){
  189. $("#statusErrmsg").html(`<i class="red remove icon"></i> ${message}`);
  190. $("#statusErrmsg").slideDown('fast').delay(5000).slideUp('fast');
  191. }
  192. function handlePortChange(){
  193. var newPortValue = $("#incomingPort").val();
  194. if (isNaN(newPortValue - 1)){
  195. alert("Invalid incoming port value");
  196. return;
  197. }
  198. $.post("/api/proxy/setIncoming", {incoming: newPortValue}, function(data){
  199. if (data.error != undefined){
  200. statusErrmsg(data.error);
  201. }
  202. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  203. initRPStaste();
  204. });
  205. }
  206. function initHTTPtoHTTPSRedirectSetting(){
  207. $.get("/api/proxy/useHttpsRedirect", function(data){
  208. if (data == true){
  209. $("#redirect").checkbox("set checked");
  210. }
  211. //Initiate the input listener on the checkbox
  212. $("#redirect").find("input").on("change", function(){
  213. let thisValue = $("#redirect").checkbox("is checked");
  214. $.ajax({
  215. url: "/api/proxy/useHttpsRedirect",
  216. data: {set: thisValue},
  217. success: function(data){
  218. if (data.error != undefined){
  219. alert(data.error);
  220. }else{
  221. //Updated
  222. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  223. initRPStaste();
  224. }
  225. }
  226. })
  227. });
  228. });
  229. }
  230. initHTTPtoHTTPSRedirectSetting();
  231. function initTlsSetting(){
  232. $.get("/api/cert/tls", function(data){
  233. if (data == true){
  234. $("#tls").checkbox("set checked");
  235. }
  236. //Initiate the input listener on the checkbox
  237. $("#tls").find("input").on("change", function(){
  238. let thisValue = $("#tls").checkbox("is checked");
  239. $.ajax({
  240. url: "/api/cert/tls",
  241. data: {set: thisValue},
  242. success: function(data){
  243. if (data.error != undefined){
  244. alert(data.error);
  245. }else{
  246. //Updated
  247. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  248. initRPStaste();
  249. }
  250. }
  251. })
  252. });
  253. })
  254. }
  255. initTlsSetting();
  256. </script>