index.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. include_once '../auth.php';
  3. ?>
  4. <html>
  5. <head>
  6. <link rel="stylesheet" href="../script/tocas/tocas.css">
  7. <script src="../script/tocas/tocas.js"></script>
  8. <script src="../script/jquery.min.js"></script>
  9. <script src="../script/ao_module.js"></script>
  10. </head>
  11. <body>
  12. <div class="ts container">
  13. <br>
  14. <div class="ts segment">
  15. <div class="ts header">
  16. <i class="file icon"></i>
  17. <div class="content">
  18. arozdfs Demo Module
  19. <div class="sub header">Reference code for how to use the arozdfs sybsystem</div>
  20. </div>
  21. </div>
  22. </div>
  23. <?php
  24. //Check if arozdfs services exists.
  25. if (!file_exists("../SystemAOB/functions/arozdfs/")){
  26. die("ERROR. Arozdfs service not found or permission denied.");
  27. }
  28. $dfsroot = "../SystemAOB/functions/arozdfs/";
  29. $settings = json_decode(file_get_contents($dfsroot . "clusterSetting.config"),true);
  30. $uploadTargets = explode("\n",trim(file_get_contents($dfsroot . "remoteDisks.config")));
  31. $storeDir = file_get_contents($dfsroot . "storageDirectory.config");
  32. $parentDir = dirname(__FILE__);
  33. ?>
  34. <div class="ts primary segment">
  35. <p>There are five main functions in using arozdfs. Select the following functions one by one and try out the process.</p>
  36. <div class="ts breadcrumb">
  37. <a class="section">Upload</a>
  38. <i class="right chevron icon divider"></i>
  39. <a class="section">Slice</a>
  40. <i class="right chevron icon divider"></i>
  41. <a class="section">Download</a>
  42. <i class="right chevron icon divider"></i>
  43. <a class="section">Open</a>
  44. <i class="right chevron icon divider"></i>
  45. <a class="section">Remove</a>
  46. </div>
  47. </div>
  48. <div class="ts segment">
  49. <p>1. Upload the file that you want to send into the arozdfs. Click <a href="">here</a> after the upload is finished.</p>
  50. <?php $moduleName = basename($parentDir); ?>
  51. <iframe width="100%" height="260px" src="../Upload%20Manager/upload_interface_min.php?target=SystemAOB\functions\arozdfs&filetype="> </iframe>
  52. </div>
  53. <div class="ts segment">
  54. <p>2. Select the file you want slice and click on it. The page will refresh automatically when slicing processes ended.</p>
  55. <div class="ts ordered list">
  56. <?php
  57. $uploadedFiles = glob($dfsroot . "uploads/*");
  58. foreach ($uploadedFiles as $file){
  59. if (is_file($file)){
  60. echo '<a class="item hexfoldername" rawname="' . basename($file) . '" onClick="sliceThis(this);">' . basename($file) .'</a>';
  61. }
  62. }
  63. ?>
  64. </div>
  65. <div class="ts horizontal form">
  66. <div class="field">
  67. <label>Chunk Size (MB)</label>
  68. <input id="chunksize" type="number" value="32">
  69. </div>
  70. </div>
  71. </div>
  72. <div class="ts segment">
  73. <p>3. Upload the chunks to the listed clusters. If nothing is displayed below, please redo step 2 until the file chunks are shown below.<br>Upload pending chunk: </p>
  74. <div class="ts ordered list">
  75. <?php
  76. $valid = false;
  77. if (isset($_GET['uuid'])){
  78. $valid = true;
  79. $chunks = glob($dfsroot . "chunks/" . $_GET['uuid'] . "/" . $_GET['uuid'] . "*");
  80. foreach ($chunks as $chunk){
  81. if (is_file($chunk)){
  82. echo '<a class="item">' . basename($chunk) . '</a>';
  83. }
  84. }
  85. }
  86. ?>
  87. </div>
  88. <div class="ts horizontal form">
  89. <div class="field">
  90. <label>Storage Filename</label>
  91. <input type="text" value="<?php
  92. if (isset($_GET['filename'])){
  93. echo strip_tags($_GET['filename']);
  94. }
  95. ?>">
  96. </div>
  97. </div>
  98. <?php
  99. //Echo the upload button if uuid and filename is given
  100. if ($valid){
  101. echo '<button class="ts primary button" filename="' . strip_tags($_GET['filename']) . '" uuid="' . $_GET['uuid'] . '" onClick="startUpload(this);">Upload</button>';
  102. }
  103. ?>
  104. </div>
  105. <div class="ts segment">
  106. <p>4. Download and Merge: These are the files uploaded to the arozdfs clusters. Click any of the filename below to download.</p>
  107. <div class="ts ordered list">
  108. <?php
  109. $fileIndexs = glob($dfsroot . "index/*.index");
  110. foreach ($fileIndexs as $index){
  111. echo '<a class="item hexfoldername" rawname="' . basename($index,".index") . '" onclick="downloadFile(this);" >' . basename($index,".index") . '</a>';
  112. }
  113. ?>
  114. </div>
  115. </div>
  116. <div class="ts segment">
  117. <p>5. Preview exported files. Click any file in the list below to view its content.</p>
  118. <div class="ts ordered list">
  119. <?php
  120. $mergedFiles = glob($dfsroot . "tmp/outfiles/*");
  121. foreach ($mergedFiles as $file){
  122. if (is_file($file)){
  123. echo '<a class="item hexfoldername" filename="' . $file. '" onclick="openFile(this);" >' . basename($file) . '</a>';
  124. }
  125. }
  126. ?>
  127. </div>
  128. </div>
  129. <div class="ts primary segment">
  130. <p>Here is the file index tree that is currently stored inside the distrubuted file system.</p>
  131. <div class="ts ordered list">
  132. <?php
  133. function getDirContents($path) {
  134. $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
  135. $files = array();
  136. foreach ($rii as $file)
  137. if (!$file->isDir())
  138. $files[] = $file->getPathname();
  139. return $files;
  140. }
  141. foreach (getDirContents($dfsroot . trim("index/")) as $index){
  142. echo '<div class="item">' . str_replace("\\","/",str_replace($dfsroot,"arozdfs//",$index)) . '</div>'; //Fix the problem on Window host which display a mix of / and \
  143. }
  144. ?>
  145. </div>
  146. <p>Here is a list of chunks stored on this host.</p>
  147. <div class="ts ordered list">
  148. <?php
  149. $realStorePath = $storeDir;
  150. if (file_exists($dfsroot . trim($storeDir))){
  151. $realStorePath = $dfsroot . trim($storeDir);
  152. }
  153. foreach (getDirContents($realStorePath) as $index){
  154. echo '<div class="item">' . str_replace("\\","/",str_replace($dfsroot,"arozdfs//",$index)) . '</div>';
  155. }
  156. ?>
  157. </div>
  158. </div>
  159. <div class="ts primary segment">
  160. <p>The followings are "arozdfs root", "cluster setting", "upload target UUID" and "local storage directory" information.<br>
  161. These can be modified using NotepadA before the upload process start.</p>
  162. <?php
  163. var_dump([$dfsroot,$settings,$uploadTargets,$storeDir]);
  164. ?>
  165. </div>
  166. <div id="msgbox" class="ts active bottom right snackbar" style="display:none;">
  167. <div id="message" class="content">
  168. This is a message box.
  169. </div>
  170. </div>
  171. </div>
  172. <script>
  173. var arozdfsModule = "../ArOZDFS/"; //Current module path from ArOZ Online Root
  174. $(document).ready(function(){
  175. //Translate all the hex foldername to human readable filename if found
  176. $(".hexfoldername").each(function(){
  177. var decodedName = ao_module_codec.decodeUmFilename($(this).text()); //Decode the umfile naming method.
  178. $(this).text(decodedName); //Upload the hex filename to its original filename
  179. });
  180. });
  181. function baseName(str){
  182. var tmp = str.split("/");
  183. return tmp.pop();
  184. }
  185. function openFile(object){
  186. var filename = $(object).attr("filename");
  187. var displayname = ao_module_codec.decodeUmFilename(baseName(filename));
  188. if (ao_module_virtualDesktop){
  189. ao_module_openFile(filename.replace("../",""),displayname);
  190. }else{
  191. window.open("../SystemAOB/functions/file_system/index.php?controlLv=2&mode=file&dir=" + filename.replace("../","") + "&filename=" + displayname);
  192. }
  193. }
  194. function downloadFile(object){
  195. var vdir = $(object).attr("rawname");
  196. msgbox("Download started. This might take a while.");
  197. $.get("../SystemAOB/functions/arozdfs/requestFromCluster.php?vdir=" + vdir.trim(),function(data){
  198. console.log(data);
  199. mergeFileChunks(data.trim(),vdir);
  200. });
  201. }
  202. function mergeFileChunks(chunkid, outfilename){
  203. msgbox("Merging process started.");
  204. $.get("../SystemAOB/functions/arozdfs/mergeFileChunks.php?chunkid=" + chunkid + "&outfile=" + outfilename ,function(data){
  205. console.log(data);
  206. if (data.includes("DONE")){
  207. window.location.reload();
  208. }
  209. });
  210. }
  211. function startUpload(object){
  212. var uuid = $(object).attr("uuid");
  213. var vdir = $(object).attr("filename");
  214. msgbox("Upload started. This might take a while.");
  215. $.get("../SystemAOB/functions/arozdfs/uploadToCluster.php?uuid=" + uuid.trim() + "&filename=" + vdir.trim(),function(data){
  216. console.log(data);
  217. if (data.includes("[OK] All chunks uploaded")){
  218. window.location.reload();
  219. }
  220. });
  221. }
  222. function sliceThis(object){
  223. var filename = $(object).attr("rawname"); //Get the original name from the DOM attibute
  224. $.get("../SystemAOB/functions/arozdfs/slice.php?filename=" + filename + "&chunksize=" + $("#chunksize").val(),function(data){
  225. //After slicing, an UUID should return. The sliced file chunks are now lying inside arozdfs/chunks/{uuid}/{uuid}_*
  226. console.log(data);
  227. window.location.href = "index.php?uuid=" + data + "&filename=" + filename;
  228. });
  229. }
  230. function msgbox(msg){
  231. //Just a utility function to show that something is working
  232. $("#message").text(msg);
  233. $("#msgbox").fadeIn().delay(5000).fadeOut();
  234. }
  235. </script>
  236. </body>
  237. </html>