status.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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="statusErrmsg" class="ui red message" style="display: none;"></div>
  75. <div class="ui divider"></div>
  76. <div class="ui two column stackable grid">
  77. <div class="column">
  78. <p>Visitor Counts</p>
  79. <table class="ui basic celled table">
  80. <thead>
  81. <tr>
  82. <th>Country ISO Code</th>
  83. <th>Visitor Count</th>
  84. </tr>
  85. </thead>
  86. <tbody>
  87. <!-- insert table rows here -->
  88. </tbody>
  89. </table>
  90. </div>
  91. <div class="column">
  92. <p>Proxy Request Types</p>
  93. <table class="ui basic celled table">
  94. <thead>
  95. <tr>
  96. <th>Proxy Type</th>
  97. <th>Count</th>
  98. </tr>
  99. </thead>
  100. <tbody>
  101. <!-- insert table rows here -->
  102. </tbody>
  103. </table>
  104. </div>
  105. </div>
  106. <br>
  107. <button class="ui basic green button"><i class="refresh icon"></i> Refresh</button>
  108. <script>
  109. //Get the latest server status from proxy server
  110. function initRPStaste(){
  111. $.get("/api/proxy/status", function(data){
  112. if (data.Running == true){
  113. $("#startbtn").addClass("disabled");
  114. $("#stopbtn").removeClass("disabled");
  115. $("#serverstatus").addClass("green");
  116. $("#statusTitle").text("Online");
  117. $("#statusText").text("Serving request on port: " + data.Option.Port);
  118. }else{
  119. $("#startbtn").removeClass("disabled");
  120. $("#stopbtn").addClass("disabled");
  121. $("#statusTitle").text("Offline");
  122. $("#statusText").text("Reverse proxy server is offline");
  123. $("#serverstatus").removeClass("green");
  124. }
  125. $("#incomingPort").val(data.Option.Port);
  126. });
  127. }
  128. function abbreviateNumber(value) {
  129. var newValue = value;
  130. var suffixes = ["", "K", "M", "B", "T"];
  131. var suffixNum = 0;
  132. while (newValue >= 1000 && suffixNum < suffixes.length - 1) {
  133. newValue /= 1000;
  134. suffixNum++;
  135. }
  136. if (value > 1000){
  137. newValue = newValue.toFixed(2);
  138. }
  139. return newValue + suffixes[suffixNum];
  140. }
  141. function getDailySummary(){
  142. $.get("/api/stats/summary?fast=true", function(data){
  143. console.log(data);
  144. $("#summaryTotalCount").text(abbreviateNumber(data.TotalRequest));
  145. $("#summarySuccCount").text(abbreviateNumber(data.ValidRequest));
  146. $("#summaryErrCount").text(abbreviateNumber(data.ErrorRequest));
  147. });
  148. }
  149. setInterval(function(){
  150. getDailySummary();
  151. }, 10000);
  152. getDailySummary();
  153. //Start and stop service button
  154. function startService(){
  155. $.post("/api/proxy/enable", {enable: true}, function(data){
  156. if (data.error != undefined){
  157. statusErrmsg(data.error);
  158. }
  159. initRPStaste();
  160. });
  161. }
  162. function stopService(){
  163. $.post("/api/proxy/enable", {enable: false}, function(data){
  164. if (data.error != undefined){
  165. statusErrmsg(data.error);
  166. }
  167. initRPStaste();
  168. });
  169. }
  170. //Show error message
  171. function statusErrmsg(message){
  172. $("#statusErrmsg").html(`<i class="red remove icon"></i> ${message}`);
  173. $("#statusErrmsg").slideDown('fast').delay(5000).slideUp('fast');
  174. }
  175. function handlePortChange(){
  176. var newPortValue = $("#incomingPort").val();
  177. if (isNaN(newPortValue - 1)){
  178. alert("Invalid incoming port value");
  179. return;
  180. }
  181. $.post("/api/proxy/setIncoming", {incoming: newPortValue}, function(data){
  182. if (data.error != undefined){
  183. statusErrmsg(data.error);
  184. }
  185. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  186. initRPStaste();
  187. });
  188. }
  189. function initHTTPtoHTTPSRedirectSetting(){
  190. $.get("/api/proxy/useHttpsRedirect", function(data){
  191. if (data == true){
  192. $("#redirect").checkbox("set checked");
  193. }
  194. //Initiate the input listener on the checkbox
  195. $("#redirect").find("input").on("change", function(){
  196. let thisValue = $("#redirect").checkbox("is checked");
  197. $.ajax({
  198. url: "/api/proxy/useHttpsRedirect",
  199. data: {set: thisValue},
  200. success: function(data){
  201. if (data.error != undefined){
  202. alert(data.error);
  203. }else{
  204. //Updated
  205. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  206. initRPStaste();
  207. }
  208. }
  209. })
  210. });
  211. });
  212. }
  213. initHTTPtoHTTPSRedirectSetting();
  214. function initTlsSetting(){
  215. $.get("/api/cert/tls", function(data){
  216. if (data == true){
  217. $("#tls").checkbox("set checked");
  218. }
  219. //Initiate the input listener on the checkbox
  220. $("#tls").find("input").on("change", function(){
  221. let thisValue = $("#tls").checkbox("is checked");
  222. $.ajax({
  223. url: "/api/cert/tls",
  224. data: {set: thisValue},
  225. success: function(data){
  226. if (data.error != undefined){
  227. alert(data.error);
  228. }else{
  229. //Updated
  230. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  231. initRPStaste();
  232. }
  233. }
  234. })
  235. });
  236. })
  237. }
  238. initTlsSetting();
  239. </script>