fshedit.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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:#242424 !important;
  17. color:white !important;
  18. background-image: url("img/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. .backgroundIcon{
  47. position: fixed;
  48. bottom: 0px;
  49. right: 0px;
  50. opacity: 0.1;
  51. margin-right: -3em;
  52. margin-bottom: -5em;
  53. z-index: -99;
  54. pointer-events: none;
  55. user-select: none;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div class="backgroundIcon">
  61. <img class="ui medium image" src="../../img/system/drive-virtual.svg">
  62. </div>
  63. <!--
  64. <div class="ui fluid attached segment themebackground" >
  65. <h4 class="ui inverted header">
  66. <i class="folder icon"></i>
  67. <div class="content">
  68. <span id="pagetitle">Edit File System Handler</span>
  69. <div class="sub header" id="pageSubTitle">Edit the selected File System Handler (FSH)</div>
  70. </div>
  71. </h4>
  72. </div>
  73. -->
  74. <br>
  75. <div class="ui container">
  76. <h3 class="ui header">
  77. <img src="../../img/system/drive-virtual.svg">
  78. <div class="content">
  79. <span>Bridge File System Handler </span><span id="poolid"></span>
  80. <div class="sub header">Share Storage across Storage Pools</div>
  81. </div>
  82. </h3>
  83. <form id="mainForm" class="ui form" onsubmit="handleFormSubmit(event);">
  84. <div class="field" style="display: none;">
  85. <label>Group</label>
  86. <input type="text" name="group" id="groupfield" readonly="true">
  87. </div>
  88. <div class="field">
  89. <label>Name</label>
  90. <input type="text" name="name" placeholder="e.g. My Drive">
  91. </div>
  92. <div class="field">
  93. <label>UUID</label>
  94. <input type="text" name="uuid" placeholder="e.g. mydrive">
  95. </div>
  96. <div class="field">
  97. <label>Path</label>
  98. <input type="text" name="path" placeholder="e.g. /media/mydrive">
  99. </div>
  100. <div class="field">
  101. <label>Access Permission</label>
  102. <div id="accessfield" class="ui selection dropdown">
  103. <input type="hidden" name="access" value="readwrite">
  104. <i class="dropdown icon"></i>
  105. <div class="default text">Access Permission</div>
  106. <div class="menu">
  107. <div class="item" data-value="readonly">Read Only</div>
  108. <div class="item" data-value="readwrite">Read Write</div>
  109. </div>
  110. </div>
  111. </div>
  112. <div class="field">
  113. <label>Storage Hierarchy</label>
  114. <div id="hierarchyfield" class="ui selection dropdown" onchange="handleHierarchyChange(this);">
  115. <input type="hidden" name="hierarchy" value="public">
  116. <i class="dropdown icon"></i>
  117. <div class="default text">Storage Hierarchy</div>
  118. <div class="menu">
  119. <div class="item" data-value="user">Isolated User Folders</div>
  120. <div class="item" data-value="public">Public Access Folders</div>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="ui divider"></div>
  125. <p>Physical Disks Settings</p>
  126. <div class="field">
  127. <label>Filesystem Type</label>
  128. <div id="fstype" class="ui selection dropdown">
  129. <input type="hidden" name="filesystem" value="ntfs" onchange="handleFileSystemTypeChange(this.value);">
  130. <i class="dropdown icon"></i>
  131. <div class="default text">Filesystem Type</div>
  132. <div class="menu">
  133. <div class="item" data-value="ext4">EXT4</div>
  134. <!-- <div class="item" data-value="ext3">EXT3</div> -->
  135. <div class="item" data-value="ntfs">NTFS</div>
  136. <div class="item" data-value="vfat">VFAT</div>
  137. <div class="item" data-value="fat">FAT</div>
  138. <div class="item" data-value="webdav">WebDAV</div>
  139. <div class="item" data-value="smb">SMB</div>
  140. <div class="item" data-value="ftp">FTP</div>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="localfs">
  145. <div class="field">
  146. <label>Mount Device</label>
  147. <input type="text" name="mountdev" placeholder="e.g. /dev/sda1">
  148. </div>
  149. <div class="field">
  150. <label>Mount Point</label>
  151. <input type="text" name="mountpt" placeholder="e.g. /media/myfolder">
  152. </div>
  153. <div class="field">
  154. <div class="ui checkbox">
  155. <input type="checkbox" id="automount" tabindex="0" class="hidden">
  156. <label>Automount</label>
  157. </div>
  158. </div>
  159. <br>
  160. </div>
  161. <div class="networkfs" style="display:none;">
  162. <div class="ui divider"></div>
  163. <p>Security and Authentication</p>
  164. <div class="field">
  165. <label>Username</label>
  166. <input type="text" name="username" placeholder="">
  167. </div>
  168. <div class="field">
  169. <label>Password</label>
  170. <input type="password" name="password" placeholder="">
  171. </div>
  172. <small>Leave Username / Password field empty for using the old config</small>
  173. <br><br>
  174. </div>
  175. <button class="ui right floated button" onclick='handleCancel();'>Cancel</button>
  176. <button class="ui green right floated button" type="submit">Confirm</button>
  177. <br><br><br><br>
  178. </form>
  179. </div>
  180. <script>
  181. //Get target fsh uuid and group from hash
  182. var targetFSH = "";
  183. var opr = "set";
  184. $(".ui.dropdown").dropdown();
  185. $(".ui.checkbox").checkbox();
  186. if (window.location.hash.length > 0){
  187. //Get a list of vroot from system
  188. $("#backupIdList").html(``);
  189. $.get("../../system/storage/pool/list", function(data){
  190. data.forEach(usergroup => {
  191. if (usergroup.Storages != null){
  192. usergroup.Storages.forEach(storage => {
  193. $("#backupIdList").append(`<div class="item" data-value="${storage.UUID}">${storage.Name} (${storage.UUID}:/)</div>`);
  194. });
  195. }
  196. });
  197. $("#backupIdList").parent().dropdown();
  198. renderFSHCurrentSettings();
  199. });
  200. }
  201. function handleFormSubmit(e){
  202. e.preventDefault();
  203. //Get the form value
  204. let payload = new FormData(e.target);
  205. let fshObject = {};
  206. [...payload.entries()].forEach(function(field){
  207. fshObject[field[0]] = field[1];
  208. });
  209. //Inject other payloads
  210. fshObject.automount = $("#automount")[0].checked;
  211. $.ajax({
  212. url: "../../system/storage/pool/edit",
  213. method: "POST",
  214. data: {
  215. opr: opr,
  216. group: $("#groupfield").val(),
  217. config: JSON.stringify(fshObject),
  218. },
  219. success: function(data){
  220. if (data.error !== undefined){
  221. alert(data.error);
  222. }else{
  223. //Done
  224. window.location.href = "updateComplete.html";
  225. }
  226. }
  227. });
  228. }
  229. function renderFSHCurrentSettings(){
  230. //Request server side to provide info on this FSH
  231. var input = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  232. $("#groupfield").val(input.group);
  233. if (input.uuid == undefined){
  234. //New fsh
  235. $("#pagetitle").text("New File System Handler");
  236. $("#pageSubTitle").text("Mount a new file system into this host as storage");
  237. opr = "new";
  238. }else{
  239. $.ajax({
  240. url: "../../system/storage/pool/edit",
  241. method: "GET",
  242. data: {opr: "get", uuid: input.uuid, group: input.group},
  243. success: function(data){
  244. renderOptionsToForm(data);
  245. }
  246. });
  247. $("#mainForm").attr("action", "../../system/storage/pool/edit?opr=set&uuid=" + input.uuid + "&group=" + input.group);
  248. }
  249. }
  250. function handleHierarchyChange(object){
  251. var newHierarcy = $(object).find("input").val();
  252. //Force access mode to readonly if backup mode
  253. if (newHierarcy == "backup"){
  254. $("#accessfield").dropdown("set selected", "readonly")
  255. $("#accessfield").addClass("disabled");
  256. }else{
  257. $("#accessfield").removeClass("disabled");
  258. }
  259. }
  260. function handleFileSystemTypeChange(fstype){
  261. if (fstype == "webdav" || fstype == "ftp" || fstype == "smb"){
  262. $(".localfs").hide();
  263. $(".networkfs").show();
  264. }else{
  265. $(".localfs").show();
  266. $(".networkfs").hide();
  267. }
  268. }
  269. function renderOptionsToForm(option){
  270. console.log(option);
  271. $("input[name=name]").val(option.name);
  272. $("input[name=uuid]").val(option.uuid);
  273. $("input[name=path]").val(option.path);
  274. $("#accessfield").dropdown("set selected", option.access);
  275. $("#hierarchyfield").dropdown("set selected", option.hierarchy);
  276. if (isNetworkFs(option.filesystem)){
  277. $(".localfs").hide();
  278. $(".networkfs").show();
  279. }
  280. $("#fstype").dropdown("set selected",option.filesystem);
  281. handleFileSystemTypeChange(option.filesystem);
  282. $("input[name=mountdev]").val(option.mountdev);
  283. $("input[name=mountpt]").val(option.mountpt);
  284. if (option.automount == true){
  285. $("input[name=automount]")[0].checked = true;
  286. $("#automount").parent().checkbox("set checked");
  287. }
  288. }
  289. function isNetworkFs(name){
  290. if (name == "webdav" || name == "ftp"){
  291. return true;
  292. }
  293. return false;
  294. }
  295. function handleCancel(){
  296. ao_module_parentCallback(true);
  297. ao_module_close();
  298. }
  299. </script>
  300. </body>
  301. </html>