basicAuthEditor.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. <i class="lock icon"></i>
  14. <div class="content">
  15. Basic Auth Credential
  16. <div class="sub header"></div>
  17. </div>
  18. </div>
  19. <div class="scrolling content ui form">
  20. <div id="inlineEditBasicAuthCredentials" class="field">
  21. <p>Enter the username and password for allowing them to access this proxy endpoint</p>
  22. <table class="ui very basic compacted unstackable celled table">
  23. <thead>
  24. <tr>
  25. <th>Username</th>
  26. <th>Password</th>
  27. <th>Remove</th>
  28. </tr></thead>
  29. <tbody id="inlineEditBasicAuthCredentialTable">
  30. <tr>
  31. <td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. <div class="three small fields credentialEntry">
  36. <div class="field">
  37. <input id="inlineEditBasicAuthCredUsername" type="text" placeholder="Username" autocomplete="off">
  38. </div>
  39. <div class="field">
  40. <input id="inlineEditBasicAuthCredPassword" type="password" placeholder="Password" autocomplete="off">
  41. </div>
  42. <div class="field" >
  43. <button class="ui basic button" onclick="addCredentialsToEditingList();"><i class="blue add icon"></i> Add Credential</button>
  44. </div>
  45. <div class="ui divider"></div>
  46. <div class="field" >
  47. <button class="ui basic button" style="float: right;" onclick="saveCredentials();"><i class="green save icon"></i> Save</button>
  48. <button class="ui basic button" style="float: right;" onclick="cancelCredentialEdit();"><i class="remove icon"></i> Cancel</button>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <script>
  55. let editingCredentials = [];
  56. if (window.location.hash.length > 1){
  57. let payloadHash = window.location.hash.substr(1);
  58. try{
  59. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  60. loadBasicAuthCredentials(payloadHash.ept, payloadHash.ep);
  61. }catch(ex){
  62. console.log("Unable to load endpoint data from hash")
  63. }
  64. }
  65. function loadBasicAuthCredentials(endpointType, uuid){
  66. $.ajax({
  67. url: "/api/proxy/updateCredentials",
  68. method: "GET",
  69. data: {
  70. ep: uuid,
  71. ptype: endpointType
  72. },
  73. success: function(data){
  74. //Push the existing account to list
  75. for(var i = 0; i < data.length; i++){
  76. // Create a new credential object
  77. var credential = {
  78. username: data[i],
  79. password: ""
  80. };
  81. // Add the credential to the global credentials array
  82. editingCredentials.push(credential);
  83. }
  84. console.log(data);
  85. updateEditingCredentialList();
  86. }
  87. })
  88. }
  89. function addCredentialsToEditingList() {
  90. // Retrieve the username and password input values
  91. var username = $('#inlineEditBasicAuthCredUsername').val();
  92. var password = $('#inlineEditBasicAuthCredPassword').val();
  93. if(username == "" || password == ""){
  94. parent.msgbox("Username or password cannot be empty", false, 5000);
  95. return;
  96. }
  97. if (alreadyExists(username)){
  98. parent.msgbox("Credential with same username already exists", false, 5000);
  99. return;
  100. }
  101. // Create a new credential object
  102. var credential = {
  103. username: username,
  104. password: password
  105. };
  106. // Add the credential to the global credentials array
  107. editingCredentials.push(credential);
  108. // Clear the input fields
  109. $('#inlineEditBasicAuthCredUsername').val('');
  110. $('#inlineEditBasicAuthCredPassword').val('');
  111. // Update the table body with the credentials
  112. updateEditingCredentialList();
  113. }
  114. function updateEditingCredentialList() {
  115. var tableBody = $('#inlineEditBasicAuthCredentialTable');
  116. tableBody.empty();
  117. if (editingCredentials.length === 0) {
  118. tableBody.append('<tr><td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td></tr>');
  119. } else {
  120. for (var i = 0; i < editingCredentials.length; i++) {
  121. var credential = editingCredentials[i];
  122. var username = credential.username;
  123. var password = credential.password.replace(/./g, '*'); // Replace each character with '*'
  124. if (credential.password == ""){
  125. password = `<span style="color: #c9c9c9;"><i class="eye slash outline icon"></i> Hidden<span>`;
  126. }
  127. var row = '<tr>' +
  128. '<td>' + username + '</td>' +
  129. '<td>' + password + '</td>' +
  130. '<td><button class="ui basic button" onclick="removeCredentialFromEditingList(' + i + ');"><i class="red remove icon"></i> Remove</button></td>' +
  131. '</tr>';
  132. tableBody.append(row);
  133. }
  134. }
  135. }
  136. function removeCredentialFromEditingList(index) {
  137. // Remove the credential from the credentials array
  138. editingCredentials.splice(index, 1);
  139. // Update the table body
  140. updateEditingCredentialList();
  141. }
  142. function alreadyExists(username){
  143. let isExists = false;
  144. editingCredentials.forEach(function(cred){
  145. if (cred.username == username){
  146. isExists = true;
  147. }
  148. });
  149. return isExists;
  150. }
  151. function cancelCredentialEdit(){
  152. parent.hideSideWrapper(true);
  153. }
  154. </script>
  155. </body>
  156. </html>