basicAuthEditor.html 7.4 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. <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" style="float: right;" onclick="addCredentialsToEditingList();"><i class="blue add icon"></i> Add Credential</button>
  44. <button class="ui basic button" style="float: right;" onclick="cancelCredentialEdit();"><i class="remove icon"></i> Cancel</button>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <script>
  51. let editingCredentials = [];
  52. if (window.location.hash.length > 1){
  53. let payloadHash = window.location.hash.substr(1);
  54. try{
  55. payloadHash = JSON.parse(decodeURIComponent(payloadHash));
  56. loadBasicAuthCredentials(payloadHash.ept, payloadHash.ep);
  57. }catch(ex){
  58. console.log("Unable to load endpoint data from hash")
  59. }
  60. }
  61. function loadBasicAuthCredentials(endpointType, uuid){
  62. $.ajax({
  63. url: "/api/proxy/updateCredentials",
  64. method: "GET",
  65. data: {
  66. ep: uuid,
  67. ptype: endpointType
  68. },
  69. success: function(data){
  70. //Push the existing account to list
  71. for(var i = 0; i < data.length; i++){
  72. // Create a new credential object
  73. var credential = {
  74. username: data[i],
  75. password: ""
  76. };
  77. // Add the credential to the global credentials array
  78. editingCredentials.push(credential);
  79. }
  80. console.log(data);
  81. updateEditingCredentialList();
  82. }
  83. })
  84. }
  85. function addCredentialsToEditingList() {
  86. // Retrieve the username and password input values
  87. var username = $('#inlineEditBasicAuthCredUsername').val();
  88. var password = $('#inlineEditBasicAuthCredPassword').val();
  89. if(username == "" || password == ""){
  90. parent.msgbox("Username or password cannot be empty", false, 5000);
  91. return;
  92. }
  93. if (alreadyExists(username)){
  94. parent.msgbox("Credential with same username already exists", false, 5000);
  95. return;
  96. }
  97. // Create a new credential object
  98. var credential = {
  99. username: username,
  100. password: password
  101. };
  102. // Add the credential to the global credentials array
  103. editingCredentials.push(credential);
  104. // Clear the input fields
  105. $('#inlineEditBasicAuthCredUsername').val('');
  106. $('#inlineEditBasicAuthCredPassword').val('');
  107. // Update the table body with the credentials
  108. updateEditingCredentialList();
  109. }
  110. function updateEditingCredentialList() {
  111. var tableBody = $('#inlineEditBasicAuthCredentialTable');
  112. tableBody.empty();
  113. if (editingCredentials.length === 0) {
  114. tableBody.append('<tr><td colspan="3"><i class="ui green circle check icon"></i> No Entered Credential</td></tr>');
  115. } else {
  116. for (var i = 0; i < editingCredentials.length; i++) {
  117. var credential = editingCredentials[i];
  118. var username = credential.username;
  119. var password = credential.password.replace(/./g, '*'); // Replace each character with '*'
  120. if (credential.password == ""){
  121. password = `<span style="color: #c9c9c9;"><i class="eye slash outline icon"></i> Hidden<span>`;
  122. }
  123. var row = '<tr>' +
  124. '<td>' + username + '</td>' +
  125. '<td>' + password + '</td>' +
  126. '<td><button class="ui basic button" onclick="removeCredentialFromEditingList(' + i + ');"><i class="red remove icon"></i> Remove</button></td>' +
  127. '</tr>';
  128. tableBody.append(row);
  129. }
  130. }
  131. }
  132. function removeCredentialFromEditingList(index) {
  133. // Remove the credential from the credentials array
  134. editingCredentials.splice(index, 1);
  135. // Update the table body
  136. updateEditingCredentialList();
  137. }
  138. function alreadyExists(username){
  139. let isExists = false;
  140. editingCredentials.forEach(function(cred){
  141. if (cred.username == username){
  142. isExists = true;
  143. }
  144. });
  145. return isExists;
  146. }
  147. function cancelCredentialEdit(){
  148. parent.hideSideWrapper(true);
  149. }
  150. </script>
  151. </body>
  152. </html>