fshedit.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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>Edit File System Handler </span><span id="poolid"></span>
  80. <div class="sub header">Mount Local or Connect Remote Disk as Virtual Disk on this Host</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" onchange="checkPathProtocol(this);">
  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 class="item" data-value="sftp">SFTP</div>
  142. </div>
  143. </div>
  144. </div>
  145. <div class="localfs">
  146. <div class="field">
  147. <label>Mount Device</label>
  148. <input type="text" name="mountdev" placeholder="e.g. /dev/sda1">
  149. </div>
  150. <div class="field">
  151. <label>Mount Point</label>
  152. <input type="text" name="mountpt" placeholder="e.g. /media/myfolder">
  153. </div>
  154. <div class="field">
  155. <div class="ui checkbox">
  156. <input type="checkbox" id="automount" tabindex="0" class="hidden">
  157. <label>Automount</label>
  158. </div>
  159. </div>
  160. <br>
  161. </div>
  162. <div class="networkfs" style="display:none;">
  163. <div class="ui divider"></div>
  164. <p>Security and Authentication</p>
  165. <div class="field">
  166. <label>Username</label>
  167. <input type="text" name="username" placeholder="">
  168. </div>
  169. <div class="field">
  170. <label>Password</label>
  171. <input type="password" name="password" placeholder="">
  172. </div>
  173. <small>Leave Username / Password field empty for using the old config</small>
  174. <br><br>
  175. </div>
  176. <button class="ui right floated button" onclick='handleCancel();'>Cancel</button>
  177. <button class="ui green right floated button" type="submit">Confirm</button>
  178. <br><br><br><br>
  179. </form>
  180. </div>
  181. <script>
  182. //Get target fsh uuid and group from hash
  183. var targetFSH = "";
  184. var opr = "set";
  185. $(".ui.dropdown").dropdown();
  186. $(".ui.checkbox").checkbox();
  187. $(document).ready(function(){
  188. initEditor();
  189. });
  190. function initEditor(){
  191. if (window.location.hash.length > 0){
  192. //Get a list of vroot from system
  193. $("#backupIdList").html(``);
  194. $.get("../../system/storage/pool/list", function(data){
  195. data.forEach(usergroup => {
  196. if (usergroup.Storages != null){
  197. usergroup.Storages.forEach(storage => {
  198. $("#backupIdList").append(`<div class="item" data-value="${storage.UUID}">${storage.Name} (${storage.UUID}:/)</div>`);
  199. });
  200. }
  201. });
  202. $("#backupIdList").parent().dropdown();
  203. renderFSHCurrentSettings();
  204. });
  205. }
  206. }
  207. function handleFormSubmit(e){
  208. e.preventDefault();
  209. //Get the form value
  210. let payload = new FormData(e.target);
  211. let fshObject = {};
  212. [...payload.entries()].forEach(function(field){
  213. fshObject[field[0]] = field[1];
  214. });
  215. //Inject other payloads
  216. fshObject.automount = $("#automount")[0].checked;
  217. $.ajax({
  218. url: "../../system/storage/pool/edit",
  219. method: "POST",
  220. data: {
  221. opr: opr,
  222. group: $("#groupfield").val(),
  223. config: JSON.stringify(fshObject),
  224. },
  225. success: function(data){
  226. if (data.error !== undefined){
  227. alert(data.error);
  228. }else{
  229. //Done
  230. window.location.href = "updateComplete.html";
  231. }
  232. }
  233. });
  234. }
  235. function renderFSHCurrentSettings(){
  236. //Request server side to provide info on this FSH
  237. var input = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  238. $("#groupfield").val(input.group);
  239. if (input.uuid == undefined){
  240. //New fsh
  241. $("#pagetitle").text("New File System Handler");
  242. $("#pageSubTitle").text("Mount a new file system into this host as storage");
  243. opr = "new";
  244. }else{
  245. $.ajax({
  246. url: "../../system/storage/pool/edit",
  247. method: "GET",
  248. data: {opr: "get", uuid: input.uuid, group: input.group},
  249. success: function(data){
  250. renderOptionsToForm(data);
  251. }
  252. });
  253. $("#mainForm").attr("action", "../../system/storage/pool/edit?opr=set&uuid=" + input.uuid + "&group=" + input.group);
  254. }
  255. }
  256. function checkPathProtocol(object){
  257. var newPath = $(object).val();
  258. if (newPath.startsWith("http://") || newPath.startsWith("https://")){
  259. //WebDAV
  260. $("#fstype").dropdown("set selected", "webdav");
  261. //newPath = newPath.replace("http://", "");
  262. //newPath = newPath.replace("https://", "");
  263. $(object).val(newPath);
  264. }else if (newPath.startsWith("ftp://")){
  265. //FTP
  266. $("#fstype").dropdown("set selected", "ftp");
  267. newPath = newPath.replace("ftp://", "");
  268. $(object).val(newPath);
  269. }else if (newPath.startsWith("sftp://")){
  270. //SFTP
  271. $("#fstype").dropdown("set selected", "sftp");
  272. newPath = newPath.replace("sftp://", "");
  273. $(object).val(newPath);
  274. }else if (newPath.startsWith("\\\\")){
  275. //SMB, Copy directly from Windows
  276. $("#fstype").dropdown("set selected", "smb");
  277. newPath = newPath.replace("\\\\", "");
  278. newPath = newPath.split("\\").join("/");
  279. $(object).val(newPath);
  280. }
  281. }
  282. function handleHierarchyChange(object){
  283. var newHierarcy = $(object).find("input").val();
  284. //Force access mode to readonly if backup mode
  285. if (newHierarcy == "backup"){
  286. $("#accessfield").dropdown("set selected", "readonly")
  287. $("#accessfield").addClass("disabled");
  288. }else{
  289. $("#accessfield").removeClass("disabled");
  290. }
  291. }
  292. function handleFileSystemTypeChange(fstype){
  293. if (isNetworkFs(fstype)){
  294. $(".localfs").hide();
  295. $(".networkfs").show();
  296. }else{
  297. $(".localfs").show();
  298. $(".networkfs").hide();
  299. }
  300. }
  301. function isNetworkFs(name){
  302. name = name.trim();
  303. if (name == "webdav" || name == "smb" || name == "ftp" || name == "sftp"){
  304. return true;
  305. }
  306. return false;
  307. }
  308. function renderOptionsToForm(option){
  309. console.log(option);
  310. $("input[name=name]").val(option.name);
  311. $("input[name=uuid]").val(option.uuid);
  312. $("input[name=path]").val(option.path);
  313. $("#accessfield").dropdown("set selected", option.access);
  314. $("#hierarchyfield").dropdown("set selected", option.hierarchy);
  315. if (isNetworkFs(option.filesystem)){
  316. $(".localfs").hide();
  317. $(".networkfs").show();
  318. }
  319. $("#fstype").dropdown("set selected",option.filesystem);
  320. handleFileSystemTypeChange(option.filesystem);
  321. $("input[name=mountdev]").val(option.mountdev);
  322. $("input[name=mountpt]").val(option.mountpt);
  323. if (option.automount == true){
  324. //$("input[name=automount]")[0].checked = true;
  325. $("#automount").parent().checkbox("set checked");
  326. }
  327. }
  328. function handleCancel(){
  329. ao_module_parentCallback(true);
  330. ao_module_close();
  331. }
  332. </script>
  333. </body>
  334. </html>