customHeaders.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. User Defined / 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. <script>
  53. let editingEndpoint = {};
  54. if (window.location.hash.length > 1){
  55. let payloadHash = window.location.hash.substr(1);
  56. try{
  57. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  58. $("#epname").text(payloadHash.ep);
  59. editingEndpoint = payloadHash;
  60. }catch(ex){
  61. console.log("Unable to load endpoint data from hash")
  62. }
  63. }
  64. //$("#debug").text(JSON.stringify(editingEndpoint));
  65. function addCustomHeader(){
  66. let name = $("#headerName").val().trim();
  67. let value = $("#headerValue").val().trim();
  68. if (name == ""){
  69. $("#headerName").parent().addClass("error");
  70. return
  71. }else{
  72. $("#headerName").parent().removeClass("error");
  73. }
  74. if (value == ""){
  75. $("#headerValue").parent().addClass("error");
  76. return
  77. }else{
  78. $("#headerValue").parent().removeClass("error");
  79. }
  80. $.ajax({
  81. url: "/api/proxy/header/add",
  82. data: {
  83. "type": editingEndpoint.ept,
  84. "domain": editingEndpoint.ep,
  85. "name": name,
  86. "value": value
  87. },
  88. success: function(data){
  89. if (data.error != undefined){
  90. if (parent != undefined && parent.msgbox != undefined){
  91. parent.msgbox(data.error,false);
  92. }else{
  93. alert(data.error);
  94. }
  95. }else{
  96. listCustomHeaders();
  97. if (parent != undefined && parent.msgbox != undefined){
  98. parent.msgbox("Custom header added",true);
  99. }
  100. //Clear the form
  101. $("#headerName").val("");
  102. $("#headerValue").val("");
  103. }
  104. }
  105. });
  106. }
  107. function deleteCustomHeader(name){
  108. $.ajax({
  109. url: "/api/proxy/header/remove",
  110. data: {
  111. "type": editingEndpoint.ept,
  112. "domain": editingEndpoint.ep,
  113. "name": name,
  114. },
  115. success: function(data){
  116. listCustomHeaders();
  117. if (parent != undefined && parent.msgbox != undefined){
  118. parent.msgbox("Custom header removed",true);
  119. }
  120. }
  121. });
  122. }
  123. function listCustomHeaders(){
  124. $("#headerTable").html(`<tr><td colspan="3"><i class="ui loading spinner icon"></i> Loading</td></tr>`);
  125. $.ajax({
  126. url: "/api/proxy/header/list",
  127. data: {
  128. "type": editingEndpoint.ept,
  129. "domain": editingEndpoint.ep,
  130. },
  131. success: function(data){
  132. if (data.error != undefined){
  133. alert(data.error);
  134. }else{
  135. $("#headerTable").html("");
  136. data.forEach(header => {
  137. $("#headerTable").append(`
  138. <tr>
  139. <td>${header.Key}</td>
  140. <td>${header.Value}</td>
  141. <td><button class="ui basic circular mini red icon button" onclick="deleteCustomHeader('${header.Key}');"><i class="ui trash icon"></i></button></td>
  142. </tr>
  143. `);
  144. });
  145. if (data.length == 0){
  146. $("#headerTable").html(`<tr>
  147. <td colspan="3"><i class="ui green circle check icon"></i> No Additonal Header</td>
  148. </tr>`);
  149. }
  150. }
  151. },
  152. });
  153. }
  154. listCustomHeaders();
  155. </script>
  156. </body>
  157. </html>