opr.php 2.8 KB

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