1
0

status.html 5.3 KB

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