status.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <div class="ui stackable four column grid">
  2. <div class="column">
  3. <div id="serverstatus" class="ui green inverted segment">
  4. <h4 class="ui header">
  5. <i class="exchange 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 blue inverted segment">
  15. <h4 class="ui header">
  16. <i class="exchange icon"></i>
  17. <div class="content">
  18. <span></span>
  19. <div class="sub header"></div>
  20. </div>
  21. </h4>
  22. </div>
  23. </div>
  24. <div class="column">
  25. <div id="connections" class="ui yellow inverted segment">
  26. <h4 class="ui header">
  27. <i class="exchange icon"></i>
  28. <div class="content">
  29. <span></span>
  30. <div class="sub header"></div>
  31. </div>
  32. </h4>
  33. </div>
  34. </div>
  35. <div class="column">
  36. <div id="connections" class="ui pink inverted segment">
  37. <h4 class="ui header">
  38. <i class="exchange icon"></i>
  39. <div class="content">
  40. <span></span>
  41. <div class="sub header"></div>
  42. </div>
  43. </h4>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="ui divider"></div>
  48. <p>Inbound Port (Port to be proxied)</p>
  49. <div class="ui action fluid input">
  50. <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
  51. <button class="ui button" onclick="handlePortChange();">Apply</button>
  52. </div>
  53. <br>
  54. <div id="tls" class="ui toggle checkbox">
  55. <input type="checkbox">
  56. <label>Use TLS to serve proxy request</label>
  57. </div>
  58. <br>
  59. <div id="redirect" class="ui toggle checkbox" style="margin-top: 0.6em;">
  60. <input type="checkbox">
  61. <label>Force redirect HTTP request to HTTPS<br>
  62. <small>(Only apply when listening port is 443)</small></label>
  63. </div>
  64. <br>
  65. <div id="portUpdateSucc" class="ui green message" style="display:none;">
  66. <i class="ui green checkmark icon"></i> Setting Updated
  67. </div>
  68. <Br>
  69. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  70. <button id="stopbtn" class="ui red disabled button" onclick="stopService();">Stop Service</button>
  71. <script>
  72. //Get the latest server status from proxy server
  73. function initRPStaste(){
  74. $.get("/api/proxy/status", function(data){
  75. if (data.Running == true){
  76. $("#startbtn").addClass("disabled");
  77. $("#stopbtn").removeClass("disabled");
  78. $("#serverstatus").addClass("green");
  79. $("#statusTitle").text("Online");
  80. $("#statusText").text("Reverse proxying request on port: " + data.Option.Port);
  81. }else{
  82. $("#startbtn").removeClass("disabled");
  83. $("#stopbtn").addClass("disabled");
  84. $("#statusTitle").text("Offline");
  85. $("#statusText").text("Reverse proxy server is offline");
  86. $("#serverstatus").removeClass("green");
  87. }
  88. $("#incomingPort").val(data.Option.Port);
  89. });
  90. }
  91. //Start and stop service button
  92. function startService(){
  93. $.post("/api/proxy/enable", {enable: true}, function(data){
  94. if (data.error != undefined){
  95. errmsg(data.error);
  96. }
  97. initRPStaste();
  98. });
  99. }
  100. function stopService(){
  101. $.post("/api/proxy/enable", {enable: false}, function(data){
  102. if (data.error != undefined){
  103. errmsg(data.error);
  104. }
  105. initRPStaste();
  106. });
  107. }
  108. function handlePortChange(){
  109. var newPortValue = $("#incomingPort").val();
  110. if (isNaN(newPortValue - 1)){
  111. alert("Invalid incoming port value");
  112. return;
  113. }
  114. $.post("/api/proxy/setIncoming", {incoming: newPortValue}, function(data){
  115. if (data.error != undefined){
  116. errmsg(data.error);
  117. }
  118. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  119. initRPStaste();
  120. });
  121. }
  122. function initHTTPtoHTTPSRedirectSetting(){
  123. $.get("/api/proxy/useHttpsRedirect", function(data){
  124. if (data == true){
  125. $("#redirect").checkbox("set checked");
  126. }
  127. //Initiate the input listener on the checkbox
  128. $("#redirect").find("input").on("change", function(){
  129. let thisValue = $("#redirect").checkbox("is checked");
  130. $.ajax({
  131. url: "/api/proxy/useHttpsRedirect",
  132. data: {set: thisValue},
  133. success: function(data){
  134. if (data.error != undefined){
  135. alert(data.error);
  136. }else{
  137. //Updated
  138. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  139. initRPStaste();
  140. }
  141. }
  142. })
  143. });
  144. });
  145. }
  146. initHTTPtoHTTPSRedirectSetting();
  147. function initTlsSetting(){
  148. $.get("/api/cert/tls", function(data){
  149. if (data == true){
  150. $("#tls").checkbox("set checked");
  151. }
  152. //Initiate the input listener on the checkbox
  153. $("#tls").find("input").on("change", function(){
  154. let thisValue = $("#tls").checkbox("is checked");
  155. $.ajax({
  156. url: "/api/cert/tls",
  157. data: {set: thisValue},
  158. success: function(data){
  159. if (data.error != undefined){
  160. alert(data.error);
  161. }else{
  162. //Updated
  163. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  164. initRPStaste();
  165. }
  166. }
  167. })
  168. });
  169. })
  170. }
  171. initTlsSetting();
  172. </script>