disk_restore.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>File Restore</title>
  5. <meta name="mobile-web-app-capable" content="yes">
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta charset="UTF-8">
  8. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  9. <script src="../../script/jquery.min.js"></script>
  10. <script src="../../script/semantic/semantic.min.js"></script>
  11. <script type="text/javascript" src="../../script/ao_module.js"></script>
  12. <style>
  13. .hidden{
  14. display:none;
  15. }
  16. .disabled{
  17. opacity: 0.5;
  18. pointer-events: none;
  19. }
  20. .colorblock{
  21. width: 20px;
  22. height: 20px;
  23. display: inline-block;
  24. vertical-align: bottom;
  25. margin-right: 12px;
  26. }
  27. .blue.colorblock{
  28. background-color: #52bdf2;
  29. }
  30. .grey.colorblock{
  31. background-color: #b9b9b9;
  32. }
  33. .yellow.colorblock{
  34. background-color: #e5e75c;
  35. }
  36. .ui.table tr td{
  37. border-top: 0px solid transparent !important;
  38. }
  39. .overlap.bar{
  40. position: absolute !important;
  41. top:0px;
  42. left: 0px;
  43. }
  44. .nointeract{
  45. pointer-events: none;
  46. user-select: none;
  47. }
  48. #restorableList{
  49. max-height: 300px;
  50. overflow-y: scroll;
  51. padding-right: 4px;
  52. }
  53. #snapshotList{
  54. max-height: 300px;
  55. overflow-y: scroll;
  56. padding-right: 4px;
  57. }
  58. .timeleft{
  59. width: 30px;
  60. height: 30px;
  61. display: inline-block;
  62. user-select: none;
  63. vertical-align: baseline;
  64. margin-bottom: -10px;
  65. margin-right: 4px;
  66. }
  67. .closebtn{
  68. position: absolute;
  69. right: 4px;
  70. top: 4px;
  71. }
  72. </style>
  73. </head>
  74. <body>
  75. <br>
  76. <div class="ui container">
  77. <h3 class="ui header">
  78. Backup & Restore
  79. <div class="sub header">Show restore points for the selected virtual disk</div>
  80. </h3>
  81. <div class="ui divider"></div>
  82. <div id="error" class="ui red inverted segment hidden">
  83. <h4 class="ui header">
  84. <i class="remove icon"></i>
  85. <div class="content">
  86. List Restore Failed
  87. <div class="sub reason header" style="color: white;">Unknown Vroot paramter given</div>
  88. </div>
  89. </h4>
  90. </div>
  91. <div id="succ" class="ui green segment" style="display:none;">
  92. <h4 class="ui header">
  93. <i class="green checkmark icon"></i>
  94. <div class="content">
  95. File Restored
  96. <div class="sub reason header openfolder"><a style="cursor: pointer" onclick="handleOpenRestoreLocation()"><i class="ui folder open icon"></i> Open Location</a></div>
  97. </div>
  98. </h4>
  99. </div>
  100. <div id="fileinfo" class="ui segment" style="display:none;">
  101. <h4 class="ui header">
  102. <div class="content">
  103. <span class="filename">No File Selected</span>
  104. <div class="sub header relpath">N/A</div>
  105. </div>
  106. </h4>
  107. <div class="ui divider"></div>
  108. <h5>Restorable File Properties</h5>
  109. <span class="backupDisk">N/A</span><br>
  110. <span class="restorePoint">N/A</span><br>
  111. <span class="deleteTime">N/A</span><br>
  112. <span class="deleteRemainingTime">N/A</span><br>
  113. <button id="snapshotSummaryBtn" class="ui mini button" style="display:none;" onclick="openSnapshotInfo();">View Snapshot Summary</button>
  114. <button class="circular ui icon basic small button closebtn" onclick='$("#fileinfo").slideUp("fast");'>
  115. <i class="icon remove"></i>
  116. </button>
  117. </div>
  118. <div id="snapshotList" class="ui middle aligned divided list">
  119. <div class="item">
  120. <img class="ui mini image nointeract" src="../../img/system/drive-backup.svg">
  121. <div class="content">
  122. No Restorable Snapshot(s) for this virtual disk.
  123. </div>
  124. </div>
  125. </div>
  126. <div id="restorableList" class="ui middle aligned divided list">
  127. <div class="item">
  128. <img class="ui mini image nointeract" src="../../img/system/file-notfound.svg">
  129. <div class="content">
  130. No Restorable File(s) for this virtual disk.
  131. </div>
  132. </div>
  133. </div>
  134. <div class="ui checkbox">
  135. <input type="checkbox" name="showhidden" autocomplete="false" onchange="toggleHiddenFiles(this.checked);">
  136. <label>Show hidden / cache files</label>
  137. </div>
  138. <div class="ui divider" style="margin-top: 8px; margin-bottom: 8px;"></div>
  139. <br>
  140. <div class="ui tiny green button" onclick="restoreAll();">Restore All</div>
  141. <button class="ui right floated button" onclick="ao_module_close();">Close</button>
  142. <br>
  143. </div>
  144. <br><br>
  145. <script>
  146. var vrootID = "";
  147. var viewingFileInfo = {};
  148. $(".ui.checkbox").checkbox();
  149. //Extract vroot id from the window hash
  150. if (window.location.hash.length > 1){
  151. vrootID = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  152. if (vrootID.length >= 1){
  153. //At least 1 vroot is passed in
  154. listRestorableFiles(vrootID[0]);
  155. }else{
  156. $("#error").removeClass("hidden");
  157. }
  158. }else{
  159. $("#error").removeClass("hidden");
  160. }
  161. function openSnapshotInfo(){
  162. var snapshotInfo = {
  163. SnapshotDisk: viewingFileInfo.BackupDiskUID,
  164. SnapshotName: viewingFileInfo.Filename
  165. };
  166. var hashPassthrough = encodeURIComponent(JSON.stringify(snapshotInfo));
  167. ao_module_newfw({
  168. url: "SystemAO/disk/disk_snapshot.html#" + hashPassthrough,
  169. width: 900,
  170. height: 520,
  171. appicon: "img/system/backup.svg",
  172. title: "Snapshot Summary",
  173. });
  174. }
  175. function showFileInfo(object){
  176. var filedata = $(object).attr("filedata");
  177. filedata = JSON.parse(decodeURIComponent(filedata));
  178. console.log(filedata);
  179. //Show information on page
  180. if (filedata.IsSnapshot){
  181. $("#fileinfo").find(".filename").text("Snapshot " + filedata.Filename);
  182. }else{
  183. $("#fileinfo").find(".filename").text(filedata.Filename + ` (${ao_module_utils.formatBytes(filedata.Filesize, 2)})`);
  184. }
  185. viewingFileInfo=filedata;
  186. //Hide the filename in relpath
  187. var shortenRelpath = filedata.RelpathOnDisk.split("/");
  188. shortenRelpath.pop();
  189. shortenRelpath = shortenRelpath.join("/") + "/";
  190. $("#fileinfo").find(".relpath").text(shortenRelpath);
  191. $("#fileinfo").find(".backupDisk").html('<i class="ui blue disk icon"></i> Restorable file from ' + filedata.BackupDiskUID + ":/");
  192. $("#fileinfo").find(".deleteTime").html('<i class="ui trash icon"></i> File deleted since ' + timeConverter(filedata.DeleteTime));
  193. $("#fileinfo").find(".restorePoint").html('<i class="ui refresh icon"></i> Restore to ' + (filedata.RestorePoint));
  194. $("#fileinfo").find(".deleteRemainingTime").html('<i class="ui red remove icon"></i> Auto delete in '+ secondsToHms(filedata.RemainingTime));
  195. if (filedata.IsSnapshot){
  196. $("#fileinfo").find(".deleteRemainingTime").hide();
  197. $("#fileinfo").find(".deleteTime").hide();
  198. $("#snapshotSummaryBtn").show();
  199. }else{
  200. $("#fileinfo").find(".deleteRemainingTime").show();
  201. $("#fileinfo").find(".deleteTime").show();
  202. $("#snapshotSummaryBtn").hide();
  203. }
  204. $("#fileinfo").slideDown('fast');
  205. }
  206. function secondsToHms(d) {
  207. d = Number(d);
  208. var h = Math.floor(d / 3600);
  209. var m = Math.floor(d % 3600 / 60);
  210. var s = Math.floor(d % 3600 % 60);
  211. var hDisplay = h > 0 ? h.toString().padStart(2, "0") + (h == 1 ? " hour, " : " hours, ") : "";
  212. var mDisplay = m > 0 ? m.toString().padStart(2, "0") + (m == 1 ? " minute, " : " minutes") : "";
  213. return hDisplay + mDisplay;
  214. }
  215. function timeConverter(UNIX_timestamp){
  216. var a = new Date(UNIX_timestamp * 1000);
  217. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  218. var year = a.getFullYear();
  219. var month = months[a.getMonth()];
  220. var date = a.getDate();
  221. var hour = a.getHours().toString().padStart(2, "0");
  222. var min = a.getMinutes().toString().padStart(2, "0");
  223. var sec = a.getSeconds().toString().padStart(2, "0");
  224. var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
  225. return time;
  226. }
  227. function toggleHiddenFiles(status=undefined){
  228. if (status == undefined){
  229. $(".hiddenfile").slideToggle("fast");
  230. }else if (status == true){
  231. $(".hiddenfile").slideDown("fast");
  232. }else if (status == false){
  233. $(".hiddenfile").slideUp("fast");
  234. }
  235. }
  236. //Restore this file
  237. var restoreFileInfo = undefined;
  238. function restoreThisFile(fileObject){
  239. var filedata = $(fileObject).attr("filedata");
  240. filedata = JSON.parse(decodeURIComponent(filedata));
  241. console.log(filedata);
  242. $.ajax({
  243. url: "../../system/backup/restoreFile",
  244. method: "POST",
  245. data: {"bdid": filedata.BackupDiskUID, "relpath": filedata.RelpathOnDisk},
  246. success: function(data){
  247. if (data.error !== undefined){
  248. alert("Restore failed: " + data.error);
  249. }else{
  250. console.log(data);
  251. restoreFileInfo = data;
  252. if (restoreFileInfo.RestoredVirtualPath == ""){
  253. $("#openfolder").hide();
  254. }else{
  255. $("#openfolder").show();
  256. }
  257. $("#succ").finish().stop().slideDown('fast').delay(10000).slideUp('fast');
  258. listRestorableFiles(vrootID[0]);
  259. }
  260. }
  261. })
  262. }
  263. function handleOpenRestoreLocation(){
  264. if (restoreFileInfo.RestoredVirtualPath != undefined && restoreFileInfo.RestoredVirtualPath != ""){
  265. var filepath = restoreFileInfo.RestoredVirtualPath;
  266. var tmp = filepath.split("/");
  267. var filename = tmp.pop();
  268. var dirname = tmp.join("/");
  269. ao_module_openPath(dirname, filename);
  270. }
  271. }
  272. function listRestorableFiles(rootID){
  273. $.ajax({
  274. url: "/system/backup/listRestorable",
  275. data: {vroot: rootID},
  276. success: function(data){
  277. if (data.error !== undefined){
  278. $("#error").find(".reason").texxt(data.error);
  279. }else{
  280. //Filter out the restorable snapshot and files
  281. let restorableFiles = [];
  282. let restorableSnapshots = [];
  283. data.RestorableFiles.forEach(file => {
  284. if (file.IsSnapshot){
  285. restorableSnapshots.push(file);
  286. }else{
  287. restorableFiles.push(file);
  288. }
  289. });
  290. //Sort the result by latest first (file only)
  291. restorableFiles.sort(function(a, b) {
  292. return b.DeleteTime - a.DeleteTime;
  293. });
  294. restorableSnapshots.sort(function(a, b) {
  295. return b.Filename > a.Filename;
  296. });
  297. //Display the reuslt for restorableSnapshot
  298. $("#snapshotList").html("");
  299. restorableSnapshots.forEach(snapshot => {
  300. let snapshotData = encodeURIComponent(JSON.stringify(snapshot));
  301. $("#snapshotList").append(`<div class="item restorableFile" filedata="${snapshotData}">
  302. <div class="right floated content">
  303. <div class="ui tiny button" onclick="showFileInfo(this.parentNode.parentNode)">Info</div>
  304. <div class="ui tiny green button" onclick="restoreThisFile($(this).parent().parent());">Restore</div>
  305. </div>
  306. <div class="content">
  307. <p style="word-break: break-all; font-size: 97%"><img class="ui mini spaced image nointeract" src="../../img/system/drive-backup.svg">
  308. Snapshot ${snapshot.Filename}
  309. </p>
  310. </div>
  311. </div>`);
  312. })
  313. //Display the result for restorableFile
  314. $("#restorableList").html("");
  315. restorableFiles.forEach(fileObject => {
  316. let thisFileData = encodeURIComponent(JSON.stringify(fileObject));
  317. var timerIcon = "100.svg";
  318. if (fileObject.RemainingTime < 75600){
  319. timerIcon = "87_5.svg"
  320. }else if (fileObject.RemainingTime < 64800){
  321. timerIcon = "75.svg"
  322. }else if (fileObject.RemainingTime < 54000){
  323. timerIcon = "62_5.svg"
  324. }else if (fileObject.RemainingTime < 43200){
  325. timerIcon = "50.svg"
  326. }else if (fileObject.RemainingTime < 32400){
  327. timerIcon = "37_5.svg"
  328. }else if (fileObject.RemainingTime < 21600){
  329. timerIcon = "25.svg"
  330. }else if (fileObject.RemainingTime < 10800){
  331. timerIcon = "12_5.svg"
  332. }else if (fileObject.RemainingTime < 7200){
  333. timerIcon = "0.svg"
  334. }
  335. var deleteTimeLeftHumanReadable = secondsToHms(fileObject.RemainingTime);
  336. var fileIcon = "../../img/system/file-restore.svg";
  337. var isHidden = "";
  338. if (fileObject.IsHidden == true){
  339. fileIcon = "../../img/system/file-restore-hidden.svg";
  340. isHidden = "hiddenfile";
  341. }
  342. $("#restorableList").append(`<div class="item restorableFile ${isHidden}" filedata="${thisFileData}">
  343. <div class="right floated content">
  344. <div class="timeleft" title="Will be deleted in ${deleteTimeLeftHumanReadable}">
  345. <img class="ui fluid image" src="../../img/icons/backup/${timerIcon}"/>
  346. </div>
  347. <div class="ui tiny button" onclick="showFileInfo(this.parentNode.parentNode)">Info</div>
  348. <div class="ui tiny green button" onclick="restoreThisFile($(this).parent().parent());">Restore</div>
  349. </div>
  350. <div class="content">
  351. <p style="word-break: break-all;"><img class="ui mini spaced image nointeract" src="${fileIcon}">
  352. ${fileObject.Filename}
  353. </p>
  354. </div>
  355. </div>`);
  356. });
  357. if (restorableFiles.length == 0){
  358. $("#restorableList").html(`<div class="item">
  359. <img class="ui mini image nointeract" src="../../img/system/file-notfound.svg">
  360. <div class="content">
  361. No Restorable File(s) for this virtual disk.
  362. </div>
  363. </div>`);
  364. }
  365. }
  366. $(".hiddenfile").hide();
  367. }
  368. })
  369. }
  370. function restoreAll(){
  371. if (confirm("Confirm restore all files from backup?")){
  372. $(".restorableFile").each(function(){
  373. //Restore this file
  374. restoreThisFile($(this));
  375. });
  376. }
  377. }
  378. </script>
  379. </body>
  380. </html>