file_permission.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <html>
  2. <head>
  3. <title>File Permissions</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="text/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  9. <script type="text/javascript" src="../../script/ao_module.js"></script>
  10. <style>
  11. body{
  12. }
  13. .fitted.checkbox{
  14. height: 20px;
  15. }
  16. </style>
  17. </head>
  18. <body id="filePropertiesWindow">
  19. <br>
  20. <div class="ui container">
  21. <h3 class="ui header">
  22. File Permissions
  23. <div class="sub header">Update file permissions for other gateways</div>
  24. </h3>
  25. <div class="ui divider"></div>
  26. <p id="filename"></p>
  27. <div class="ui grid">
  28. <div class="five wide column">
  29. <br>
  30. <div class="ui divider"></div>
  31. User
  32. <div class="ui divider"></div>
  33. Group
  34. <div class="ui divider"></div>
  35. Other
  36. </div>
  37. <div class="three wide column" style="text-align: center;">
  38. Read
  39. <div class="ui divider"></div>
  40. <div class="ui fitted disabled checkbox">
  41. <input id="1" type="checkbox" autocomplete="false">
  42. <label></label>
  43. </div>
  44. <div class="ui divider"></div>
  45. <div class="ui fitted disabled checkbox">
  46. <input id="4" type="checkbox" autocomplete="false">
  47. <label></label>
  48. </div>
  49. <div class="ui divider"></div>
  50. <div class="ui fitted checkbox">
  51. <input id="7" type="checkbox" autocomplete="false">
  52. <label></label>
  53. </div>
  54. </div>
  55. <div class="three wide column" style="text-align: center;">
  56. Write
  57. <div class="ui divider"></div>
  58. <div class="ui fitted disabled checkbox">
  59. <input id="2" type="checkbox" autocomplete="false">
  60. <label></label>
  61. </div>
  62. <div class="ui divider"></div>
  63. <div class="ui fitted disabled checkbox">
  64. <input id="5" type="checkbox" autocomplete="false">
  65. <label></label>
  66. </div>
  67. <div class="ui divider"></div>
  68. <div class="ui fitted checkbox">
  69. <input id="8" type="checkbox" autocomplete="false">
  70. <label></label>
  71. </div>
  72. </div>
  73. <div class="three wide column" style="text-align: center;">
  74. Execute
  75. <div class="ui divider"></div>
  76. <div class="ui fitted disabled checkbox">
  77. <input id="3" type="checkbox" autocomplete="false">
  78. <label></label>
  79. </div>
  80. <div class="ui divider"></div>
  81. <div class="ui fitted disabled checkbox">
  82. <input id="6" type="checkbox" autocomplete="false">
  83. <label></label>
  84. </div>
  85. <div class="ui divider"></div>
  86. <div class="ui fitted checkbox">
  87. <input id="9" type="checkbox" autocomplete="false">
  88. <label></label>
  89. </div>
  90. </div>
  91. </div>
  92. <br>
  93. <div class="ui accordion">
  94. <div class="title">
  95. <i class="dropdown icon"></i>
  96. Advance Settings
  97. </div>
  98. <div class="content">
  99. <div class="ui toggle checkbox">
  100. <input type="checkbox" name="removeProtection" onchange="toggleProtection(this);" autocomplete="false" checked="false">
  101. <label>Allow Edit User / Group Permission</label>
  102. </div>
  103. <br>
  104. <small>Removing User / Group permission to critical files might lead to system failure. Please make sure you know what you are doing.</small>
  105. </div>
  106. </div>
  107. <div class="ui divider"></div>
  108. <button class="ui right floated button" onclick="ao_module_close();">Cancel</button>
  109. <button class="ui green right floated button" onclick="update();">Update</button>
  110. <br> <br>
  111. </div>
  112. <div id="filesizeLoader" class="ui active dimmer">
  113. <div class="ui indeterminate text loader">Requesting File System</div>
  114. </div>
  115. <div id="success" class="ui basic modal">
  116. <div class="ui icon header">
  117. <i class="green checkmark icon"></i>
  118. Pernmission Updated
  119. </div>
  120. <div class="actions">
  121. <div class="ui ok inverted button">
  122. OK
  123. </div>
  124. </div>
  125. </div>
  126. <div id="failed" class="ui basic modal">
  127. <div class="ui icon header">
  128. <i class="red remove icon"></i>
  129. Pernmission Update Failed
  130. </div>
  131. <div class="content">
  132. <p id="errmsg"></p>
  133. </div>
  134. <div class="actions">
  135. <div class="ui ok inverted button">
  136. OK
  137. </div>
  138. </div>
  139. </div>
  140. <script>
  141. $(".ui.checkbox").checkbox();
  142. $('.ui.accordion').accordion();
  143. $(".ui.modal").modal();
  144. //Initiate the view model
  145. var files = ao_module_loadInputFiles();
  146. var fileProperties = [];
  147. var groupID = 0;
  148. for (var i =0; i < files.length; i++){
  149. getPermission(files[i]);
  150. }
  151. if (files.length == 1){
  152. var filename = files[0].split("/").pop();
  153. $("#filename").append(filename);
  154. }else{
  155. $("#filename").append(`<i class="file icon"></i>` + files.length + " files selected");
  156. }
  157. function getPermission(filepath){
  158. $.ajax({
  159. url: "../../system/file_system/handleFilePermission",
  160. data: {file: filepath},
  161. success: function(data){
  162. var permissionBites = [];
  163. var perChar = data.split("");
  164. //Shift out the group ID, currently useless
  165. groupID = perChar.shift();
  166. for (var i = 0; i < perChar.length; i++){
  167. //i: 0 - 2 => (7)55
  168. var permissionSettingBit = parseInt(perChar[i]).toString(2).padStart(3, "0").split("")
  169. for (var j = 0; j < permissionSettingBit.length; j++){
  170. //j: 0 - 2 => 111
  171. permissionBites.push(permissionSettingBit[j]);
  172. }
  173. }
  174. //Render the file permission
  175. console.log(data);
  176. //Assign the permission checkbox
  177. for (var i = 0; i < permissionBites.length; i++){
  178. if (permissionBites[i] == "1"){
  179. $("#" + (i + 1))[0].checked = true;
  180. }
  181. }
  182. $("#filesizeLoader").hide();
  183. }
  184. });
  185. }
  186. function toggleProtection(button){
  187. if (button.checked == true){
  188. $(".disabled.checkbox").removeClass("disabled");
  189. }else{
  190. for (var i = 1; i < 7; i++){
  191. $("#" + i).parent().addClass("disabled");
  192. }
  193. }
  194. }
  195. function resetCheckboxes(){
  196. for (var i = 1; i < 10; i++){
  197. $("#" + i)[0].checked = false;
  198. }
  199. }
  200. function update(){
  201. var newPermission = generatePermissionString();
  202. files.forEach(filepath => {
  203. $.ajax({
  204. url: "../../system/file_system/handleFilePermission",
  205. data: {file: filepath, mode: newPermission},
  206. success: function(data){
  207. if (data.error !== undefined){
  208. $("#failed").modal("show");
  209. $("#errmsg").text(data.error);
  210. }else{
  211. $("#success").modal("show");
  212. }
  213. console.log(data);
  214. }
  215. });
  216. })
  217. }
  218. function generatePermissionString(){
  219. var binary = [];
  220. for (var i = 1; i < 10; i++){
  221. if ($("#" + i)[0].checked == true){
  222. binary.push(1);
  223. }else{
  224. binary.push(0);
  225. }
  226. }
  227. //Convert the binary into hex
  228. var octalRepresentation = parseInt(binary.join(""), 2).toString(8);
  229. return groupID + octalRepresentation;
  230. }
  231. </script>
  232. </body>
  233. </html>