poolEditor.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  6. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  7. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  8. <script type="text/javascript" src="../../script/ao_module.js"></script>
  9. <title>Storage Pool Editor</title>
  10. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  11. <style>
  12. body{
  13. background-color:white;
  14. }
  15. .themebackground{
  16. background-color:#29cc96 !important;
  17. color:white !important;
  18. background-image: url("/img/public/slate.png") !important;
  19. background-repeat: no-repeat !important;
  20. background-attachment: fixed !important;
  21. height:100px;
  22. border: 0px solid transparent !important;
  23. padding:24px !important;
  24. }
  25. .fshList{
  26. max-height: 300px;
  27. overflow-y: auto;
  28. }
  29. .controls{
  30. position: absolute;
  31. top: 12px;
  32. right: 12px;
  33. }
  34. a{
  35. cursor: pointer;
  36. }
  37. .false{
  38. color: #eb0909;
  39. }
  40. .true{
  41. color: #05b074;
  42. }
  43. .backuponly{
  44. display:none;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div class="ui fluid attached segment themebackground" >
  50. <h24 class="ui inverted header">
  51. <i class="server icon"></i>
  52. <div class="content">
  53. Edit Storage Pool
  54. <div class="sub header">Edit storage pool and its mounted file system handlers</div>
  55. </div>
  56. </h4>
  57. </div>
  58. <br>
  59. <div class="ui container">
  60. <div class="ui header" id="editingGroupName"></div>
  61. <p>File System Handlers currently mounted in this storage pool: </p>
  62. <div class="ui divider"></div>
  63. <div id="fshList">
  64. </div>
  65. <div class="ui divider"></div>
  66. <div id="newfsh" style="display:none;">
  67. <h3><i class="plus icon"></i> Create New File System Handler</h3>
  68. <p>Invalid setting might lead to system fail to start. Please make sure your settings are valid before pressing the create button.</p>
  69. <form class="ui form" action="../../system/storage/pool/newHandler" method="POST">
  70. <p>Basic Virtual Disk Settings</p>
  71. <div class="field" style="display: none;">
  72. <label>Group</label>
  73. <input type="text" name="group" id="groupfield" readonly="true">
  74. </div>
  75. <div class="field">
  76. <label>Name</label>
  77. <input type="text" name="name" placeholder="e.g. My Folder">
  78. </div>
  79. <div class="field">
  80. <label>UUID</label>
  81. <input type="text" name="uuid" placeholder="e.g. myfolder">
  82. </div>
  83. <div class="field">
  84. <label>Path</label>
  85. <input type="text" name="path" placeholder="e.g. /media/myfolder">
  86. </div>
  87. <div id="accPermission" class="field">
  88. <label>Access Permission</label>
  89. <div class="ui selection dropdown">
  90. <input type="hidden" name="access" value="readwrite">
  91. <i class="dropdown icon"></i>
  92. <div class="default text">Access Permission</div>
  93. <div class="menu">
  94. <div class="item" data-value="readonly">Read Only</div>
  95. <div class="item" data-value="readwrite">Read Write</div>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="field">
  100. <label>Storage Hierarchy</label>
  101. <div class="ui selection dropdown">
  102. <input type="hidden" autocomplete="false" name="hierarchy" value="user" onchange="handleHierarchyChange(this.value);">
  103. <i class="dropdown icon"></i>
  104. <div class="default text">Storage Hierarchy</div>
  105. <div class="menu">
  106. <div class="item" data-value="user">Isolated User Folders</div>
  107. <div class="item" data-value="public">Public Access Folders</div>
  108. <div class="item" data-value="backup">Backup Storage</div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="ui divider backuponly"></div>
  113. <p class="backuponly">Backup Settings</p>
  114. <div class="field backuponly">
  115. <label>Backup Virtual Disk UID</label>
  116. <div class="ui selection dropdown">
  117. <input type="hidden" autocomplete="false" name="parentuid" value="">
  118. <i class="dropdown icon"></i>
  119. <div class="default text">Storage Hierarchy</div>
  120. <div class="menu" id="backupIdList">
  121. </div>
  122. </div>
  123. </div>
  124. <div class="field backuponly">
  125. <label>Backup Mode</label>
  126. <div class="ui selection dropdown">
  127. <input type="hidden" autocomplete="false" name="backupmode" value="">
  128. <i class="dropdown icon"></i>
  129. <div class="default text">Storage Hierarchy</div>
  130. <div class="menu">
  131. <div class="item" data-value="smart">Smart</div>
  132. <div class="item" data-value="nightly">Nightly</div>
  133. <div class="item" data-value="append">Append Only</div>
  134. </div>
  135. </div>
  136. </div>
  137. <div class="ui divider"></div>
  138. <p>Physical Disks Settings</p>
  139. <div class="field">
  140. <label>Filesystem Type</label>
  141. <div class="ui selection dropdown">
  142. <input type="hidden" name="filesystem" value="ntfs">
  143. <i class="dropdown icon"></i>
  144. <div class="default text">Filesystem Type</div>
  145. <div class="menu">
  146. <div class="item" data-value="ext4">EXT4</div>
  147. <div class="item" data-value="ext3">EXT3</div>
  148. <div class="item" data-value="ntfs">NTFS</div>
  149. <div class="item" data-value="vfat">VFAT</div>
  150. <div class="item" data-value="fat">FAT</div>
  151. </div>
  152. </div>
  153. </div>
  154. <div class="field">
  155. <label>Mount Device</label>
  156. <input type="text" name="mountdev" placeholder="e.g. /dev/sda1">
  157. </div>
  158. <div class="field">
  159. <label>Mount Point</label>
  160. <input type="text" name="mountpt" placeholder="e.g. /media/myfolder">
  161. </div>
  162. <div class="field">
  163. <div class="ui checkbox">
  164. <input type="checkbox" name="automount" tabindex="0" class="hidden">
  165. <label>Automount</label>
  166. </div>
  167. </div>
  168. <br>
  169. <div class="ui divider"></div>
  170. <p>Security Related (if any)</p>
  171. <div class="field">
  172. <label>Username</label>
  173. <input type="text" name="username" placeholder="">
  174. </div>
  175. <div class="field">
  176. <label>Password</label>
  177. <input type="password" name="password" placeholder="">
  178. </div>
  179. <button class="ui right floated button" onclick='event.preventDefault(); $("#newfsh").slideUp("fast"); '>Close</button>
  180. <button class="ui green right floated button" type="submit">Create</button>
  181. <br><br>
  182. </form>
  183. <div class="ui divider"></div>
  184. </div>
  185. <br>
  186. <button class="ui green button" onclick="toggleCreateNewFileHandler();"><i class="add icon"></i>New File System Handler</button>
  187. <button class="ui right floated button" onclick="done();"></i>Done</button>
  188. <br><br>
  189. </div>
  190. <script>
  191. //Load the editing storage pool from window hash
  192. var editingStoragePool = "system"
  193. if (window.location.hash.length > 1){
  194. editingStoragePool = window.location.hash.substr(1)
  195. }
  196. //List all the current fsh inside this pool
  197. $("#editingGroupName").text(editingStoragePool);
  198. loadStoragePoolForGroup(editingStoragePool);
  199. $("#groupfield").val(editingStoragePool);
  200. //Start dropdown
  201. $(".ui.dropdown").dropdown();
  202. $(".ui.checkbox").checkbox();
  203. function toggleCreateNewFileHandler(){
  204. $("#newfsh").slideToggle("fast", function(){
  205. $(window).scrollTop($("#newfsh").offset().top - 10);
  206. });
  207. }
  208. function PoolAlreadyListed(uuid){
  209. var alreadyExisted = false;
  210. $(".fsh").each(function(){
  211. if ($(this).attr("uuid") == uuid){
  212. alreadyExisted = true
  213. }
  214. });
  215. return alreadyExisted
  216. }
  217. function done(){
  218. ao_module_parentCallback(true);
  219. ao_module_close();
  220. }
  221. function loadStoragePoolForGroup(pgname){
  222. $("#fshList").html("");
  223. $.get("../../system/storage/pool/list?filter=" + pgname, function(data){
  224. var sp = data[0];
  225. var onlineFSH = [];
  226. if (sp.Storages != null){
  227. sp.Storages.forEach(storage => {
  228. var color = "green";
  229. if (storage.Closed){
  230. color = "red";
  231. }
  232. var usableIcon = "checkmark";
  233. if (storage.Closed){
  234. usableIcon = "remove";
  235. }
  236. $("#fshList").append(`<div class="ui ${color} segment fsh" uuid="${storage.UUID}">
  237. <h3><i class="disk icon"></i> ${storage.Name} (${storage.UUID}:/)</h3>
  238. <ol class="ui list">
  239. <li value="-"><i class="folder icon"></i> Mount Point: ${storage.Path}</li>
  240. <li value="-"><i class="user icon"></i> Hierarchy: ${storage.Hierarchy}</li>
  241. <li value="-" class="${!storage.ReadOnly}"> <i class="edit icon"></i> Can Write: ${!storage.ReadOnly}</li>
  242. <li value="-" class="${!storage.Closed}"> <i class="${usableIcon} icon"></i> Usable: ${!storage.Closed}</li>
  243. </ol>
  244. <div class="ui active inverted dimmer oprloader" style="display:none;">
  245. <div class="ui text loader">Waiting Response</div>
  246. </div>
  247. <div class="controls">
  248. <a title="Edit Config" uuid="${storage.UUID}" group="${pgname}" onclick="editFSH(this);"><i class="edit icon"></i></a>
  249. <a title="Close Handler" uuid="${storage.UUID}" group="${pgname}" onclick="toggleFSH(this);"><i class="power off icon"></i></a>
  250. <a title="Remove Handler" uuid="${storage.UUID}" group="${pgname}" onclick="removeThisFSH(this);"><i class="remove icon"></i></a>
  251. </div>
  252. </div>`);
  253. onlineFSH.push(storage.UUID);
  254. });
  255. $(".fsh").each(function(){
  256. if ($(this).attr("uuid") == "user" || $(this).attr("uuid") == "tmp"){
  257. //System storage pool. Do not allow editing
  258. $(this).find(".controls").html("System Reserved")
  259. $(this).attr("class", "ui yellow segment fsh");
  260. }
  261. });
  262. }else{
  263. $("#fshList").append(`<p><i class="remove icon"></i> No File System Handler mounted for ${pgname}</p>`);
  264. }
  265. $("#fshList").append('<div class="ui divider"></div>');
  266. //Get other pools that is not mounted
  267. $.get("../../system/storage/pool/listraw?target=" + pgname, function(data){
  268. var offlineFSH = [];
  269. var allFSH = [];
  270. if (data.error == undefined){
  271. data.forEach(vroot => {
  272. if (!PoolAlreadyListed(vroot.uuid)){
  273. $("#fshList").append(`<div class="ui black segment fsh" uuid="${vroot.uuid}">
  274. <h3><i class="disk icon"></i> ${vroot.name} (${vroot.uuid}:/)</h3>
  275. <ol class="ui list">
  276. <li value="-"><i class="folder icon"></i> Mount Point: ${vroot.path}</li>
  277. <li value="-"><i class="user icon"></i> Hierarchy: ${vroot.hierarchy}</li>
  278. <li value="-" class="${!(vroot.access == "readonly")}"> <i class="edit icon"></i> Can Write: ${!(vroot.access == "readonly")}</li>
  279. <li value="-"> <i class="remove icon"></i> Not Mounted</li>
  280. </ol>
  281. <div class="controls">
  282. <a title="Edit Config" uuid="${vroot.uuid}" group="${pgname}" onclick="editFSH(this);"><i class="edit icon"></i></a>
  283. <a title="Remove Handler" uuid="${vroot.uuid}" group="${pgname}" onclick="removeThisFSH(this);"><i class="remove icon"></i></a>
  284. </div>
  285. </div>`);
  286. offlineFSH.push(vroot.uuid);
  287. }
  288. allFSH.push(vroot.uuid)
  289. });
  290. if (offlineFSH.length == 0){
  291. //All fshandlers are online
  292. $("#fshList").append(`<p><i class="checkmark icon"></i> All File System Handlers for ${pgname} are online</p>`);
  293. }
  294. }else{
  295. $("#fshList").append(`<p><i class="remove icon"></i> No Unmounted File System Handler for ${pgname}</p>`);
  296. }
  297. //List the handlers that will be removed during next boot
  298. onlineFSH.forEach(ofsh => {
  299. if (allFSH.includes(ofsh) == false){
  300. //Currently online but not in original config. aka Delete Pending
  301. $(".fsh").each(function(){
  302. if ($(this).attr("uuid") == ofsh && !($(this).attr("uuid") == "user" || $(this).attr("uuid") == "tmp")){
  303. $(this).append("<p style='color: red;'>**Will be removed after next reboot</p>")
  304. }
  305. });
  306. }
  307. });
  308. });
  309. });
  310. }
  311. function handleHierarchyChange(newHierarchy){
  312. if (newHierarchy == "backup"){
  313. //Force readwrite mode to read only
  314. $("#accPermission").find(".dropdown").dropdown("set selected", "readonly");
  315. $("#accPermission").addClass("disabled");
  316. //Show backup only divs
  317. $(".backuponly").slideDown("fast");
  318. //Render the backup id list
  319. $("#backupIdList").html(``);
  320. $.get("../../system/storage/pool/list", function(data){
  321. data.forEach(usergroup => {
  322. usergroup.Storages.forEach(storage => {
  323. $("#backupIdList").append(`<div class="item" data-value="${storage.UUID}">${storage.Name} (${storage.UUID}:/)</div>`);
  324. })
  325. });
  326. $("#backupIdList").parent().dropdown();
  327. });
  328. }else{
  329. //Restore readwrite mode
  330. $("#accPermission").removeClass("disabled");
  331. //Hide backup only divs
  332. $(".backuponly").slideUp("fast");
  333. $(".backuponly").find("input").val("");
  334. }
  335. }
  336. function removeThisFSH(object){
  337. var uuid = $(object).attr("uuid");
  338. var group = $(object).attr("group");
  339. if (confirm("Confirm removing FSH: " + uuid + ":/ ?")){
  340. $.ajax({
  341. url: "../../system/storage/pool/removeHandler",
  342. data: {uuid: uuid, group: group},
  343. success: function(data){
  344. console.log(data);
  345. window.location.href = "removeSuccess.html#" + JSON.stringify([group, uuid]);
  346. }
  347. });
  348. }
  349. }
  350. function toggleFSH(object){
  351. var uuid = $(object).attr("uuid");
  352. var gpname = $(object).attr("group");
  353. $(object).parent().parent().find(".oprloader").show();
  354. $.ajax({
  355. url: "../../system/storage/pool/toggle",
  356. data: {"fsh":uuid, "group": gpname},
  357. success: function(data){
  358. $(object).parent().parent().find(".oprloader").hide();
  359. if (data.error !== undefined){
  360. alert(data.error);
  361. }else{
  362. loadStoragePoolForGroup(editingStoragePool);
  363. }
  364. }
  365. })
  366. }
  367. function editFSH(object){
  368. var uuid = $(object).attr("uuid");
  369. var gpname = $(object).attr("group");
  370. ao_module_newfw({
  371. url:"SystemAO/storage/fshedit.html#" + encodeURIComponent(JSON.stringify({uuid: uuid, group: gpname})),
  372. width: 530,
  373. height: 740,
  374. appicon: "SystemAO/storage/img/fsh.png",
  375. title: "Edit File System Handler",
  376. callback: "finishFshEdit",
  377. parent: ao_module_windowID
  378. });
  379. }
  380. function finishFshEdit(){
  381. //Reload storage pool
  382. loadStoragePoolForGroup(editingStoragePool);
  383. }
  384. </script>
  385. </body>
  386. </html>