status.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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="portUpdateSucc" class="ui green message" style="display:none;">
  23. <i class="ui green checkmark icon"></i> Setting Updated
  24. </div>
  25. <Br>
  26. <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
  27. <button id="stopbtn" class="ui red disabled button" onclick="stopService();">Stop Service</button>
  28. <script>
  29. //Get the latest server status from proxy server
  30. function initRPStaste(){
  31. $.get("status", function(data){
  32. if (data.Running == true){
  33. $("#startbtn").addClass("disabled");
  34. $("#stopbtn").removeClass("disabled");
  35. $("#serverstatus").addClass("green");
  36. $("#statusTitle").text("Online");
  37. $("#statusText").text("Reverse proxying request on port: " + data.ListenPort);
  38. }else{
  39. $("#startbtn").removeClass("disabled");
  40. $("#stopbtn").addClass("disabled");
  41. $("#statusTitle").text("Offline");
  42. $("#statusText").text("Reverse proxy server is offline");
  43. $("#serverstatus").removeClass("green");
  44. }
  45. $("#incomingPort").val(data.ListenPort);
  46. });
  47. }
  48. //Start and stop service button
  49. function startService(){
  50. $.post("enable", {enable: true}, function(data){
  51. if (data.error != undefined){
  52. errmsg(data.error);
  53. }
  54. initRPStaste();
  55. });
  56. }
  57. function stopService(){
  58. $.post("enable", {enable: false}, function(data){
  59. if (data.error != undefined){
  60. errmsg(data.error);
  61. }
  62. initRPStaste();
  63. });
  64. }
  65. function handlePortChange(){
  66. var newPortValue = $("#incomingPort").val();
  67. if (isNaN(newPortValue - 1)){
  68. alert("Invalid incoming port value");
  69. return;
  70. }
  71. $.post("setIncoming", {incoming: newPortValue}, function(data){
  72. if (data.error != undefined){
  73. errmsg(data.error);
  74. }
  75. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  76. initRPStaste();
  77. });
  78. }
  79. function initTlsSetting(){
  80. $.get("/cert/tls", function(data){
  81. if (data == true){
  82. $("#tls").checkbox("set checked");
  83. }
  84. //Initiate the input listener on the checkbox
  85. $("#tls").find("input").on("change", function(){
  86. let thisValue = $("#tls").checkbox("is checked");
  87. $.ajax({
  88. url: "/cert/tls",
  89. data: {set: thisValue},
  90. success: function(data){
  91. if (data.error != undefined){
  92. alert(data.error);
  93. }else{
  94. //Updated
  95. $("#portUpdateSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
  96. initRPStaste();
  97. }
  98. }
  99. })
  100. });
  101. })
  102. }
  103. initTlsSetting();
  104. </script>