regsetting.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <html>
  2. <head>
  3. <title>Register Settings</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.min.css">
  7. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  9. <style>
  10. </style>
  11. </head>
  12. <body>
  13. <div class="ui container">
  14. <div class="ui basic segment">
  15. <div class="ui header">
  16. <i class="registered icon"></i>
  17. <div class="content">
  18. Public Account Registry Settings
  19. <div class="sub header">Setup the public account registry on the current host system</div>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="ui red segment">
  24. <h3><i class="exclamation icon"></i> Warning</h3>
  25. <p>Allow public register flags (public_reg) has been enable on this host. Hence, you can setup an interface for public to register an user account on this host.
  26. Note that this setting interface will change the behavior of the system account creation process and might lead to security issues if this is not configured properly.<br>
  27. Please seek network security professionals for consultation before releasing access to public for registering. </p>
  28. </div>
  29. <div id="updateSuccessMsg" class="ui green segment" style="display:none">
  30. <i class="checkmark icon"></i> Settings Updated
  31. </div>
  32. <div class="field">
  33. <div class="ui toggle checkbox">
  34. <input id="apr" type="checkbox" tabindex="0" onchange="toggleRegistrySettings(this.checked);">
  35. <label>Allow Public Registry</label>
  36. </div>
  37. </div>
  38. <div class="ui divider"></div>
  39. <form id="registerSettings" class="ui form" style="display:none;" onsubmit="formsubmit(event);">
  40. <div class="field">
  41. <div class="ui toggle checkbox">
  42. <input id="eivc" type="checkbox" tabindex="0" onchange="toggleInvideCode(this.checked);">
  43. <label>Enable Invitation Code</label>
  44. </div>
  45. </div>
  46. <div id="ivc" class="field" style="display:none;">
  47. <label>Invitation Code</label>
  48. <input type="text" name="invitecode" placeholder="Invitation Code">
  49. <small>Only user with invitation code can register</small>
  50. </div>
  51. <div class="field">
  52. <div class="ui selection dropdown">
  53. <input id="usergroup" type="hidden" name="group" onchange="updateSelectedGroup(this.value);">
  54. <i class="dropdown icon"></i>
  55. <div class="default text">Default Group</div>
  56. <div id="grouplist" class="menu">
  57. </div>
  58. </div>
  59. <small>Not recommend using administrator as the default user group unless under very specific conditions.</small>
  60. </div>
  61. </form>
  62. <button class="ui primary button" onclick="formsubmit(event);">Apply</button>
  63. <div id="loader" class="ui inverted active dimmer" style="display:none;">
  64. <div class="ui text loader">Updating Configuration</div>
  65. </div>
  66. <br><br>
  67. </div>
  68. <script>
  69. var selectedGroup = "";
  70. $(document).ready(function(){
  71. $.ajax({
  72. url: "../../public/register/settings",
  73. success: function(data){
  74. if (data.AllowPublicRegister == true){
  75. $("#apr")[0].checked = true;
  76. }else{
  77. $("#apr")[0].checked = false;
  78. }
  79. if (data.EnableInvitationCode == true){
  80. $("#eivc")[0].checked = true;
  81. }else{
  82. $("#eivc")[0].checked = false;
  83. }
  84. if ($("#eivc")[0].checked == true){
  85. toggleInvideCode(true);
  86. }
  87. if ($("#apr")[0].checked == true){
  88. toggleRegistrySettings(true);
  89. }
  90. if (data.InvitationCode !== ""){
  91. $("#ivc").find("input").val(data.InvitationCode);
  92. }
  93. initUserGroupList(data.DefaultUserGroup);
  94. },
  95. error: function(){
  96. window.location.reload();
  97. }
  98. });
  99. });
  100. function toggleInvideCode(visable){
  101. if (visable){
  102. $("#ivc").slideDown("fast");
  103. if ($("#ivc").find("input").val() == ""){
  104. $("#ivc").find("input").val(makeid(16));
  105. }
  106. }else{
  107. $("#ivc").slideUp("fast");
  108. }
  109. }
  110. function initUserGroupList(defaultvalue=""){
  111. $.get("../../system/permission/listgroup",function(data){
  112. if (data.error !== undefined){
  113. alert(data.error);
  114. }else{
  115. for (var i =0; i < data.length; i++){
  116. $("#grouplist").append(`<div class="item" value="${data[i]}">${data[i]}</div>`);
  117. }
  118. }
  119. $('.ui.dropdown').dropdown();
  120. if (defaultvalue != ""){
  121. console.log(defaultvalue);
  122. $('.ui.dropdown').dropdown('set selected', defaultvalue);
  123. }
  124. })
  125. }
  126. function makeid(length) {
  127. var result = '';
  128. var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  129. var charactersLength = characters.length;
  130. for ( var i = 0; i < length; i++ ) {
  131. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  132. }
  133. return result;
  134. }
  135. function updateSelectedGroup(newSelectedGroup){
  136. selectedGroup = newSelectedGroup;
  137. if (selectedGroup == "administrator"){
  138. //Dangerous! Add warning label
  139. $("#usergroup").parent().addClass("error");
  140. }else{
  141. $("#usergroup").parent().removeClass("error");
  142. }
  143. }
  144. function toggleRegistrySettings(allowRegistry){
  145. if (allowRegistry){
  146. $("#registerSettings").slideDown("fast");
  147. }else{
  148. $("#registerSettings").slideUp("fast");
  149. }
  150. }
  151. function formsubmit(e){
  152. e.preventDefault();
  153. //Parse the form data
  154. var dataObject = {};
  155. if ($("#apr")[0].checked == false){
  156. dataObject = {
  157. apr: false,
  158. eivc: false,
  159. icode: "",
  160. group: ""
  161. }
  162. }else{
  163. var usergroup = $("#usergroup").val();
  164. if (usergroup == "administrator"){
  165. if (!confirm("Are you confirm you want to use adminstrator as the default group?")){
  166. return;
  167. }
  168. }
  169. var ivc = $("#eivc")[0].checked;
  170. if (!ivc){
  171. var invitationCode = "";
  172. }else{
  173. var invitationCode = $("#ivc").find("input").val();
  174. }
  175. dataObject = {
  176. apr: true,
  177. eivc: ivc,
  178. icode: invitationCode,
  179. group: usergroup
  180. }
  181. }
  182. //Ready to send the config to server
  183. $("#loader").show();
  184. console.log(dataObject);
  185. $.ajax({
  186. url: "../../public/register/settings",
  187. method:"POST",
  188. data: {opr: "write", config: JSON.stringify(dataObject)},
  189. success: function(data){
  190. $("#loader").hide();
  191. if (data.error !== undefined){
  192. alert(data.error);
  193. }else{
  194. $("#updateSuccessMsg").slideDown("fast").delay(3000).slideUp("fast");
  195. }
  196. },
  197. error: function(data){
  198. $("#loader").hide();
  199. alert("Failed to update settings!")
  200. },
  201. timeout:15000
  202. })
  203. }
  204. </script>
  205. </body>
  206. </html>