customHeaders.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Notes: This should be open in its original path-->
  5. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  6. <script src="../script/jquery-3.6.0.min.js"></script>
  7. <script src="../script/semantic/semantic.min.js"></script>
  8. </head>
  9. <body>
  10. <br>
  11. <div class="ui container">
  12. <div class="ui header">
  13. <div class="content">
  14. Custom Headers
  15. <div class="sub header" id="epname"></div>
  16. </div>
  17. </div>
  18. <div class="ui divider"></div>
  19. <p>You can define custom headers to be sent
  20. together with the client request to the backend server in
  21. this reverse proxy endpoint / host.</p>
  22. <table class="ui very basic compacted unstackable celled table">
  23. <thead>
  24. <tr>
  25. <th>Name</th>
  26. <th>Value</th>
  27. <th>Remove</th>
  28. </tr></thead>
  29. <tbody id="headerTable">
  30. <tr>
  31. <td colspan="3"><i class="ui green circle check icon"></i> No Additonal Header</td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. <div class="ui divider"></div>
  36. <h4>Add Custom Header</h4>
  37. <p>Add custom header(s) into this proxy target</p>
  38. <div class="scrolling content ui form">
  39. <div class="three small fields credentialEntry">
  40. <div class="field">
  41. <input id="headerName" type="text" placeholder="X-Custom-Header" autocomplete="off">
  42. </div>
  43. <div class="field">
  44. <input id="headerValue" type="text" placeholder="value1,value2,value3" autocomplete="off">
  45. </div>
  46. <div class="field" >
  47. <button class="ui basic button" onclick="addCustomHeader();"><i class="green add icon"></i> Add Header</button>
  48. </div>
  49. <div class="ui divider"></div>
  50. </div>
  51. </div>
  52. <div class="ui divider"></div>
  53. <div class="field" >
  54. <button class="ui basic button" style="float: right;" onclick="closeThisWrapper();">Close</button>
  55. </div>
  56. </div>
  57. <br><br><br><br>
  58. <script>
  59. let editingEndpoint = {};
  60. if (window.location.hash.length > 1){
  61. let payloadHash = window.location.hash.substr(1);
  62. try{
  63. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  64. $("#epname").text(payloadHash.ep);
  65. editingEndpoint = payloadHash;
  66. }catch(ex){
  67. console.log("Unable to load endpoint data from hash")
  68. }
  69. }
  70. function closeThisWrapper(){
  71. parent.hideSideWrapper(true);
  72. }
  73. //$("#debug").text(JSON.stringify(editingEndpoint));
  74. function addCustomHeader(){
  75. let name = $("#headerName").val().trim();
  76. let value = $("#headerValue").val().trim();
  77. if (name == ""){
  78. $("#headerName").parent().addClass("error");
  79. return
  80. }else{
  81. $("#headerName").parent().removeClass("error");
  82. }
  83. if (value == ""){
  84. $("#headerValue").parent().addClass("error");
  85. return
  86. }else{
  87. $("#headerValue").parent().removeClass("error");
  88. }
  89. $.ajax({
  90. url: "/api/proxy/header/add",
  91. data: {
  92. "type": editingEndpoint.ept,
  93. "domain": editingEndpoint.ep,
  94. "name": name,
  95. "value": value
  96. },
  97. success: function(data){
  98. if (data.error != undefined){
  99. if (parent != undefined && parent.msgbox != undefined){
  100. parent.msgbox(data.error,false);
  101. }else{
  102. alert(data.error);
  103. }
  104. }else{
  105. listCustomHeaders();
  106. if (parent != undefined && parent.msgbox != undefined){
  107. parent.msgbox("Custom header added",true);
  108. }
  109. //Clear the form
  110. $("#headerName").val("");
  111. $("#headerValue").val("");
  112. }
  113. }
  114. });
  115. }
  116. function deleteCustomHeader(name){
  117. $.ajax({
  118. url: "/api/proxy/header/remove",
  119. data: {
  120. "type": editingEndpoint.ept,
  121. "domain": editingEndpoint.ep,
  122. "name": name,
  123. },
  124. success: function(data){
  125. listCustomHeaders();
  126. if (parent != undefined && parent.msgbox != undefined){
  127. parent.msgbox("Custom header removed",true);
  128. }
  129. }
  130. });
  131. }
  132. function listCustomHeaders(){
  133. $("#headerTable").html(`<tr><td colspan="3"><i class="ui loading spinner icon"></i> Loading</td></tr>`);
  134. $.ajax({
  135. url: "/api/proxy/header/list",
  136. data: {
  137. "type": editingEndpoint.ept,
  138. "domain": editingEndpoint.ep,
  139. },
  140. success: function(data){
  141. if (data.error != undefined){
  142. alert(data.error);
  143. }else{
  144. $("#headerTable").html("");
  145. data.forEach(header => {
  146. $("#headerTable").append(`
  147. <tr>
  148. <td>${header.Key}</td>
  149. <td>${header.Value}</td>
  150. <td><button class="ui basic circular mini red icon button" onclick="deleteCustomHeader('${header.Key}');"><i class="ui trash icon"></i></button></td>
  151. </tr>
  152. `);
  153. });
  154. if (data.length == 0){
  155. $("#headerTable").html(`<tr>
  156. <td colspan="3"><i class="ui green circle check icon"></i> No Additonal Header</td>
  157. </tr>`);
  158. }
  159. }
  160. },
  161. });
  162. }
  163. listCustomHeaders();
  164. </script>
  165. </body>
  166. </html>