basicAuthEditor.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. Basic Auth Settings
  15. <div class="sub header" id="epname"></div>
  16. </div>
  17. </div>
  18. <div class="ui divider"></div>
  19. <h3 class="ui header">Basic Auth Credential</h3>
  20. <div class="scrolling content ui form">
  21. <div id="inlineEditBasicAuthCredentials" class="field">
  22. <p>Enter the username and password for allowing them to access this proxy endpoint</p>
  23. <table class="ui very basic compacted unstackable celled table">
  24. <thead>
  25. <tr>
  26. <th>Username</th>
  27. <th>Password</th>
  28. <th>Remove</th>
  29. </tr></thead>
  30. <tbody id="inlineEditBasicAuthCredentialTable">
  31. <tr>
  32. <td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. <div class="three small fields credentialEntry">
  37. <div class="field">
  38. <input id="inlineEditBasicAuthCredUsername" type="text" placeholder="Username" autocomplete="off">
  39. </div>
  40. <div class="field">
  41. <input id="inlineEditBasicAuthCredPassword" type="password" placeholder="Password" autocomplete="off">
  42. </div>
  43. <div class="field" >
  44. <button class="ui basic button" onclick="addCredentialsToEditingList();"><i class="blue add icon"></i> Add Credential</button>
  45. </div>
  46. <div class="ui divider"></div>
  47. <div class="field" >
  48. <button class="ui basic button" style="float: right;" onclick="saveCredentials();"><i class="green save icon"></i> Save</button>
  49. <button class="ui basic button" style="float: right;" onclick="cancelCredentialEdit();"><i class="remove icon"></i> Cancel</button>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="ui divider"></div>
  55. <h3 class="ui header">No-Auth Directories</h3>
  56. <div class="scrolling content ui form">
  57. <p>Exclude specific directories / paths from the basic auth interface. Useful if you are hosting services require remote API access.</p>
  58. <table class="ui very basic compacted unstackable celled table">
  59. <thead>
  60. <tr>
  61. <th>Path Prefix</th>
  62. <th>Remove</th>
  63. </tr></thead>
  64. <tbody id="exclusionPaths">
  65. <tr>
  66. <td colspan="3"><i class="ui green circle check icon"></i> No Path Excluded</td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. <div class="field">
  71. <input id="newExclusionPath" type="text" placeholder="/public/api/" autocomplete="off">
  72. <small>Make sure you add the tailing slash for only selecting the files / folder inside that path.</small>
  73. </div>
  74. <div class="field" >
  75. <button class="ui basic button" onclick="addExceptionPath();"><i class="blue add icon"></i> Add Exception</button>
  76. </div>
  77. </div>
  78. <br><br>
  79. </div>
  80. <script>
  81. let editingCredentials = [];
  82. let editingEndpoint = {};
  83. if (window.location.hash.length > 1){
  84. let payloadHash = window.location.hash.substr(1);
  85. try{
  86. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  87. loadBasicAuthCredentials(payloadHash.ept, payloadHash.ep);
  88. $("#epname").text(payloadHash.ep);
  89. editingEndpoint = payloadHash;
  90. }catch(ex){
  91. console.log("Unable to load endpoint data from hash")
  92. }
  93. }
  94. function loadBasicAuthCredentials(endpointType, uuid){
  95. $.ajax({
  96. url: "/api/proxy/updateCredentials",
  97. method: "GET",
  98. data: {
  99. ep: uuid,
  100. ptype: endpointType
  101. },
  102. success: function(data){
  103. //Push the existing account to list
  104. for(var i = 0; i < data.length; i++){
  105. // Create a new credential object
  106. var credential = {
  107. username: data[i],
  108. password: ""
  109. };
  110. // Add the credential to the global credentials array
  111. editingCredentials.push(credential);
  112. }
  113. console.log(data);
  114. updateEditingCredentialList();
  115. }
  116. })
  117. }
  118. function addCredentialsToEditingList() {
  119. // Retrieve the username and password input values
  120. var username = $('#inlineEditBasicAuthCredUsername').val();
  121. var password = $('#inlineEditBasicAuthCredPassword').val();
  122. if(username == "" || password == ""){
  123. parent.msgbox("Username or password cannot be empty", false, 5000);
  124. return;
  125. }
  126. if (alreadyExists(username)){
  127. parent.msgbox("Credential with same username already exists", false, 5000);
  128. return;
  129. }
  130. // Create a new credential object
  131. var credential = {
  132. username: username,
  133. password: password
  134. };
  135. // Add the credential to the global credentials array
  136. editingCredentials.push(credential);
  137. // Clear the input fields
  138. $('#inlineEditBasicAuthCredUsername').val('');
  139. $('#inlineEditBasicAuthCredPassword').val('');
  140. // Update the table body with the credentials
  141. updateEditingCredentialList();
  142. }
  143. function addExceptionPath(){
  144. // Retrieve the username and password input values
  145. var exclusionPath = $('#newExclusionPath').val();
  146. }
  147. function updateEditingCredentialList() {
  148. var tableBody = $('#inlineEditBasicAuthCredentialTable');
  149. tableBody.empty();
  150. if (editingCredentials.length === 0) {
  151. tableBody.append('<tr><td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td></tr>');
  152. } else {
  153. for (var i = 0; i < editingCredentials.length; i++) {
  154. var credential = editingCredentials[i];
  155. var username = credential.username;
  156. var password = credential.password.replace(/./g, '*'); // Replace each character with '*'
  157. if (credential.password == ""){
  158. password = `<span style="color: #c9c9c9;"><i class="eye slash outline icon"></i> Hidden<span>`;
  159. }
  160. var row = '<tr>' +
  161. '<td>' + username + '</td>' +
  162. '<td>' + password + '</td>' +
  163. '<td><button class="ui basic button" onclick="removeCredentialFromEditingList(' + i + ');"><i class="red remove icon"></i> Remove</button></td>' +
  164. '</tr>';
  165. tableBody.append(row);
  166. }
  167. }
  168. }
  169. function removeCredentialFromEditingList(index) {
  170. // Remove the credential from the credentials array
  171. editingCredentials.splice(index, 1);
  172. // Update the table body
  173. updateEditingCredentialList();
  174. }
  175. function alreadyExists(username){
  176. let isExists = false;
  177. editingCredentials.forEach(function(cred){
  178. if (cred.username == username){
  179. isExists = true;
  180. }
  181. });
  182. return isExists;
  183. }
  184. function cancelCredentialEdit(){
  185. parent.hideSideWrapper(true);
  186. }
  187. function saveCredentials(){
  188. $.ajax({
  189. url: "/api/proxy/updateCredentials",
  190. method: "POST",
  191. data: {
  192. ep: editingEndpoint.ep,
  193. ptype: editingEndpoint.ept,
  194. creds: JSON.stringify(editingCredentials)
  195. },
  196. success: function(data){
  197. if (data.error != undefined){
  198. parent.msgbox(data.error, false, 6000);
  199. }else{
  200. parent.msgbox("Credentials Updated");
  201. parent.hideSideWrapper(true);
  202. }
  203. }
  204. })
  205. }
  206. </script>
  207. </body>
  208. </html>