moduleInstaller.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. include '../auth.php';
  3. ?>
  4. <!DOCTYPE HTML>
  5. <html>
  6. <head>
  7. <script src="../script/jquery.min.js"></script>
  8. <script src="../script/dropzone/dropzone.js"></script>
  9. <link rel="stylesheet" href="../script/dropzone/min/dropzone.min.css">
  10. <link rel="stylesheet" href="../script/tocas/tocas.css">
  11. <script src="../script/tocas/tocas.js"></script>
  12. <title>ArOZ Onlineβ</title>
  13. <style type="text/css">
  14. body {
  15. //padding-top: 4em;
  16. background-color: rgb(250, 250, 250);
  17. }
  18. .ts.segmented.list {
  19. //height: 100vh;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <br>
  25. <div class="ts container">
  26. <div class="ts bottom attached vertical menu">
  27. <div class="item" style="background-color:#fcbdbd;"><i class="caution icon"></i>Do not close this page until all installation have been finished.</div>
  28. <?php
  29. $ids = [];
  30. $template = '<div id="%ID%" class="item" decodedName="%DECNAME%">
  31. <div class="ts comments">
  32. <i class="disk outline icon"></i>%CONTENT%
  33. <div id="%ID%_progress" class="sub header"><i class="clock icon"></i>Install Pending...</div>
  34. </div>
  35. </div>';
  36. $files = glob('uploads/*.zip', GLOB_BRACE);
  37. foreach($files as $file) {
  38. $filename = basename($file,".zip");
  39. $decodedName = hex2bin(substr($filename,5));
  40. $box = str_replace("%ID%",substr($filename,5),$template);
  41. $box = str_replace("%DECNAME%",$decodedName,$box);
  42. array_push($ids,substr($filename,5));
  43. $box = str_replace("%CONTENT%","$file / $decodedName",$box);
  44. echo $box;
  45. }
  46. ?>
  47. </div>
  48. </div>
  49. <script>
  50. var installTask = <?php echo json_encode($ids);?>;
  51. var redirectType = "<?php if (isset($_GET['rdt'])){echo $_GET['rdt'];}else{ echo " ";}?>";
  52. var progress = 0;
  53. if (installTask.length == 0){
  54. returnToPreviousPage();
  55. }else{
  56. installNextModule();
  57. }
  58. function returnToPreviousPage(){
  59. if (redirectType == "um"){
  60. window.location.href = "index.php";
  61. }else if (redirectType == "aorw"){
  62. window.location.href = "../SystemAOB/functions/system_management/addOrRemoveWebApp.php";
  63. }else{
  64. window.location.href = "../";
  65. }
  66. }
  67. function installNextModule(){
  68. if (progress >= installTask.length){
  69. //Finished installing
  70. $.get( "cleanUploads.php" + name, function(result) {
  71. returnToPreviousPage();
  72. });
  73. }
  74. updateStatus(progress,'<i class="circle notched loading icon"></i>Unpacking WebApp',"#f9fcbd");
  75. $.get( "unzip_module.php?moduleFilename=uploads/inith" + installTask[progress] + ".zip", function(result) {
  76. if (result.includes("ERROR") == false){
  77. //No problem with the unzip process
  78. updateStatus(progress,'<i class="circle notched loading icon"></i>Installing WebApp',"#bdc6fc");
  79. //alert($("#" + installTask[progress]).attr("decodedName") + " unzip done");
  80. MoveUnzippedWebApp($("#" + installTask[progress]).attr("decodedName"));
  81. }else{
  82. console.log(result);
  83. updateStatus(progress,'<i class="remove icon"></i>Error when unzipping WebAPP.',"#fcbdbd");
  84. progress++;
  85. installNextModule();
  86. }
  87. });
  88. }
  89. function MoveUnzippedWebApp(name){
  90. $.get( "install_module_from_unzip.php?moduleName=" + name, function(result) {
  91. if (result.includes("ERROR") == false){
  92. //No problem with the unzip process
  93. updateStatus(progress,'<i class="checkmark icon"></i>Installation Completed',"#bdfcc1");
  94. progress++;
  95. installNextModule();
  96. }else{
  97. console.log(result);
  98. updateStatus(progress,'<i class="remove icon"></i>Error when installing WebAPP.',"#fcbdbd");
  99. progress++;
  100. installNextModule();
  101. }
  102. });
  103. }
  104. function updateStatus(progressNum,text,color){
  105. $("#" + installTask[progressNum] + "_progress").html(text);
  106. $("#" + installTask[progress]).css("background-color",color);
  107. }
  108. $(document).ready(function(){
  109. console.log(installTask);
  110. });
  111. </script>
  112. </body>
  113. </html>