opr.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. include '../auth.php';
  3. ?>
  4. <?php
  5. /*
  6. |-----------------------------|
  7. | 77777 ZZZZZ IIIII PPPPP |
  8. | 7 Z I P P |
  9. | 7 - Z I PPPP |
  10. | 7 Z I P |
  11. | 7 ZZZZZ IIIII P |
  12. |-----------------------------|
  13. Yes ! This is an 7Zip logo
  14. */
  15. $rand = $_GET["rand"];
  16. if(!isset($_GET["method"])){
  17. die('["Method Error"]');
  18. }
  19. /*
  20. if(!isset($_GET["rand"])){
  21. die('["Rand Error"]');
  22. }
  23. if(!isset($_GET["file"])){
  24. die('["File Error"]');
  25. }
  26. */
  27. if(strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0){
  28. $executions = "7za";
  29. foreach ($_GET as $key => $value) {
  30. $_GET[$key] = preg_replace('/\//', '\\', $value);
  31. }
  32. }else{
  33. if(strpos(exec('uname -m'), 'arm') !== false){
  34. $executions = "./7za";
  35. }else{
  36. $executions = "./7za_x86";
  37. }
  38. }
  39. if($_GET["method"] == "ListAORDir"){
  40. $result = [];
  41. $dir = $_GET["dir"] !== "" ? "../".$_GET["dir"]."/" : "../";
  42. $data = scandir($dir,1);
  43. array_pop($data); // this two use for remove .. and .
  44. array_pop($data);
  45. foreach($data as $value){
  46. if(is_dir($dir.$value)){
  47. array_push($result,$value);
  48. }
  49. }
  50. echo json_encode($result);
  51. }else if($_GET["method"] == "l"){
  52. $filesnumber = -1;
  53. $FileInformation = [];
  54. $SevenZHeader = [];
  55. exec($executions.' l "'.$_GET["file"].'" -ba -slt',$output);
  56. // echo $_GET["dir"];
  57. if($_GET["dir"] !== ""){
  58. $dir = $_GET["dir"];
  59. }else{
  60. $dir = ".";
  61. }
  62. //* Special designed handler for ZIP (use for show folder)
  63. if(pathinfo($_GET["file"])['extension'] == "zip"){
  64. for($i = 0;$i < sizeOf($output);$i++){
  65. preg_match_all('/(.*[^=]) = (.*)/', $output[$i], $tmp);
  66. if(isset($tmp[1][0])){
  67. if($tmp[1][0] == "Path" && pathinfo($tmp[2][0])["dirname"] !== "."){
  68. if(!in_array("Path = ".pathinfo($tmp[2][0])["dirname"],$output)){
  69. array_push($output,"Path = ".pathinfo($tmp[2][0])["dirname"]);
  70. array_push($output,"Attributes = D");
  71. array_push($output,"");
  72. }
  73. }
  74. }
  75. }
  76. }
  77. //print_r($output);
  78. for($i = 0;$i < sizeOf($output);$i++){
  79. preg_match_all('/(.*[^=]) = (.*)/', $output[$i], $tmp);
  80. if(isset($tmp[1][0])){
  81. if($tmp[1][0] == "Path"){
  82. $currDir = pathinfo($tmp[2][0])["dirname"];
  83. if($currDir == $dir){
  84. $filesnumber += 1;
  85. }
  86. }
  87. if($tmp[1][0] !== NULL && $currDir == $dir){
  88. $FileInformation[$filesnumber][$tmp[1][0]] = $tmp[2][0];
  89. if(!in_array($tmp[1][0],$SevenZHeader)){
  90. array_push($SevenZHeader,$tmp[1][0]);
  91. }
  92. }
  93. }
  94. }
  95. if(strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0){
  96. for($i = 0;$i < sizeOf($FileInformation);$i++){
  97. $FileInformation[$i] = preg_replace('/\\\\/', '/', $FileInformation[$i]);
  98. }
  99. }
  100. echo json_encode(array("Header" => $SevenZHeader,"Information" => $FileInformation));
  101. }else if($_GET["method"] == "e"){
  102. $rand = $_GET["rand"];
  103. mkdir('tmp/'.$rand,0777);
  104. system($executions.' e -bsp1 -bso0 "'.$_GET["file"].'" "'.$_GET["dir"].'" -o"tmp/'.$rand.'/" > tmp/'.$rand.'messages',$output);
  105. //echo './'.$executions.' e -bsp1 -bso0 "'.$_GET["file"].'" "'.$_GET["dir"].'" -o"tmp/'.$rand.'/" > tmp/'.$rand.'messages';
  106. echo json_encode(array("Extract finished. e"));
  107. }else if($_GET["method"] == "x"){
  108. $rand = $_GET["rand"];
  109. mkdir('tmp/'.$rand,0777);
  110. system($executions.' x -bsp1 -bso0 "'.$_GET["file"].'" "'.$_GET["dir"].'" -o"tmp/'.$rand.'/" > tmp/'.$rand.'messages',$output);
  111. echo json_encode(array("Extract finished. x"));
  112. }