ldap.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <html>
  2. <head>
  3. <title>LDAP Login</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.css">
  7. <script type="application/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="application/javascript" src="../../script/clipboard.min.js"></script>
  9. <script type="application/javascript" src="../../script/semantic/semantic.js"></script>
  10. <style>
  11. /* Tooltip container */
  12. .tooltip {
  13. position: relative;
  14. display: inline-block;
  15. border-bottom: 1px dotted black;
  16. /* If you want dots under the hoverable text */
  17. }
  18. /* Tooltip text */
  19. .tooltip .tooltiptext {
  20. visibility: hidden;
  21. width: 120px;
  22. background-color: #555;
  23. color: #fff;
  24. text-align: center;
  25. padding: 5px 0;
  26. border-radius: 6px;
  27. /* Position the tooltip text */
  28. position: absolute;
  29. z-index: 1;
  30. bottom: 125%;
  31. left: 50%;
  32. margin-left: -60px;
  33. /* Fade in tooltip */
  34. opacity: 0;
  35. transition: opacity 0.3s;
  36. }
  37. /* Tooltip arrow */
  38. .tooltip .tooltiptext::after {
  39. content: "";
  40. position: absolute;
  41. top: 100%;
  42. left: 50%;
  43. margin-left: -5px;
  44. border-width: 5px;
  45. border-style: solid;
  46. border-color: #555 transparent transparent transparent;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="ui container">
  52. <div class="ui basic segment">
  53. <div class="ui header">
  54. <i class="key icon"></i>
  55. <div class="content">
  56. LDAP Access
  57. <div class="sub header">Allow external account to access ArozOS with LDAP
  58. <br>
  59. <i class="info circle icon"></i> Your current account MUST exist inside the LDAP server; otherwise synchronize function will not work properly.
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="ui divider"></div>
  65. <div class="ui green inverted segment" style="display:none;" id="updateSet">
  66. <h5 class="ui header">
  67. <i class="checkmark icon"></i>
  68. <div class="content">
  69. Settings Updated
  70. </div>
  71. </h5>
  72. </div>
  73. <div class="ui form">
  74. <div class="field">
  75. <div class="ui toggle checkbox">
  76. <input type="checkbox" id="enable" name="public">
  77. <label>Enable LDAP</label>
  78. </div>
  79. </div>
  80. <div class="field">
  81. <label>Bind Username</label>
  82. <div class="ui fluid input">
  83. <input type="text" id="bind_username" placeholder="root">
  84. </div>
  85. </div>
  86. <div class="field">
  87. <label>Bind Password</label>
  88. <div class="ui fluid input">
  89. <input type="password" id="bind_password" placeholder="p@ssw0rd">
  90. </div>
  91. </div>
  92. <div class="field">
  93. <label>FQDN</label>
  94. <div class="ui fluid input">
  95. <input type="text" id="fqdn" placeholder="10.0.0.1">
  96. </div>
  97. </div>
  98. <div class="field">
  99. <label>Base DN</label>
  100. <div class="ui fluid input">
  101. <input type="text" id="base_dn" placeholder="cn=users,dc=ldap">
  102. </div>
  103. </div>
  104. <button id="ntb" onclick="update();" class="ui green button" type="submit">Update</button>
  105. <button id="test_btn" onclick="test();" class="ui button" type="submit">Test Connection</button>
  106. </div>
  107. <div class="ui divider"></div>
  108. <div id="testConnection" style="display: none">
  109. <table class="ui celled table">
  110. <thead>
  111. <tr>
  112. <th>Username</th>
  113. <th>Group belongs to</th>
  114. <th>Equivalence user group in arozos</th>
  115. </tr>
  116. </thead>
  117. <tbody id="information">
  118. </tbody>
  119. </table>
  120. <button id="sync_btn" onclick="syncorize();" class="ui button" type="submit">Syncorize User</button>
  121. </div>
  122. <br><br>
  123. </div>
  124. <script>
  125. $(document).ready(function() {
  126. read();
  127. });
  128. function read() {
  129. $.getJSON("../../system/auth/ldap/config/read", function(data) {
  130. if (data.enabled) {
  131. $("#enable").parent().checkbox("check")
  132. }
  133. if (data.autoredirect) {
  134. $("#autoredirect").parent().checkbox("check")
  135. }
  136. $("#bind_username").val(data.bind_username);
  137. $("#bind_password").val(data.bind_password);
  138. $("#fqdn").val(data.fqdn);
  139. $("#base_dn").val(data.base_dn);
  140. });
  141. }
  142. function update() {
  143. $.post("../../system/auth/ldap/config/write", {
  144. enabled: $("#enable").parent().checkbox("is checked"),
  145. bind_username: $("#bind_username").val(),
  146. bind_password: $("#bind_password").val(),
  147. fqdn: $("#fqdn").val(),
  148. base_dn: $("#base_dn").val(),
  149. })
  150. .done(function(data) {
  151. if (data.error != undefined) {
  152. alert(data.error);
  153. } else {
  154. //OK!
  155. $("#updateSet").stop().finish().slideDown("fast").delay(3000).slideUp('fast');
  156. }
  157. });
  158. }
  159. function test() {
  160. $("#test_btn").text("Testing...");
  161. $.get("../../system/auth/ldap/config/testConnection")
  162. .done(function(data) {
  163. $("#information").html("");
  164. if (data.error != undefined) {
  165. if (data.error != "") {
  166. $("#information").append(`
  167. <tr>
  168. <td data-label="information" colspan="3">` + data.error + `</td>
  169. </tr>
  170. `);
  171. $("#testConnection").show("fast");
  172. $("#test_btn").text("Test connection");
  173. return;
  174. }
  175. }
  176. if (data.userinfo == null) {
  177. $("#information").append(`
  178. <tr>
  179. <td data-label="information" colspan="3">No entries was found.</td>
  180. </tr>
  181. `);
  182. $("#testConnection").show("fast");
  183. $("#test_btn").text("Test connection");
  184. return;
  185. }
  186. //OK!
  187. $(data.userinfo).each(function(index, element) {
  188. $("#information").append(`
  189. <tr>
  190. <td data-label="username">` + element.username + `</td>
  191. <td data-label="ldap_group">` + element.group + `</td>
  192. <td data-label="equiv_group">` + element.equiv_group + `</td>
  193. </tr>
  194. `);
  195. });
  196. $("#information").append(`
  197. <tr>
  198. <td data-label="length" colspan="3">Showing ` + data.length + ` of ` + data.total_length + ` entries</td>
  199. </tr>
  200. `);
  201. $("#testConnection").show("fast");
  202. $("#test_btn").text("Test connection");
  203. });
  204. }
  205. function syncorize() {
  206. $("#sync_btn").text("Syncorizing...");
  207. $.get("../../system/auth/ldap/config/syncorizeUser")
  208. .done(function(data) {
  209. if (data.error != undefined) {
  210. alert(data.error);
  211. } else {
  212. //OK!
  213. $("#updateSet").stop().finish().slideDown("fast").delay(3000).slideUp('fast');
  214. }
  215. $("#sync_btn").text("Syncorize User");
  216. });
  217. }
  218. </script>
  219. </body>
  220. </html>