$STORAGE = '/users/webs/latincomex.com.ar/htdocs/filemanager/ftparchivos/';
$maxFileCol = 5;
$maxDirCol = 5;
//Seteamos los users
$users = array();
$userTxt = file($STORAGE . "user.txt");
foreach ($userTxt as $txt) {
$txtArr = explode("=", $txt);
$userName = trim($txtArr[0]);
$userPass = trim(doString(array_slice($txtArr, 1), "="));
$users[$userName] = $userPass;
}
session_start();
//Si se quiere desloguear, lo dejamos
if (isset($_GET["logout"])) $_SESSION = array();
//Si viene por post, sacamos el user y la pass y los guardamos
if ($_POST) {
if ($_POST["a"] == "login") { //Login
$username = $_POST["username"];
$userpass = $_POST["userpass"];
$_SESSION["user"] = $username;
$_SESSION["pass"] = $userpass;
$_SESSION[$username . "_dir"] = "/";
}
}
//Los sacamos de la sesion
$username = $_SESSION["user"];
$userpass = $_SESSION["pass"];
$thisDir = $_SESSION[$username . "_dir"];
$adminLogin = false;
//if (isset($_SESSION["adminlogin"])) $adminLogin = true;
//Nos fijamos si existen
if (($users[$username] && $users[$username] == $userpass) || $adminLogin) {
//Existen, mostramos
if ($adminLogin) { //Admin
if (isset($_GET["adminlogin"])) $_SESSION["_dir"] = "/";
$STORAGE = substr($STORAGE, 0, strlen($STORAGE) - 1);
$username = "";
$userpass = "";
$thisDir = $_SESSION["_dir"];
}
$userDir = $STORAGE . $username;
//Si pide cambiar de directorio
if ($_REQUEST) {
$dirStat = $_REQUEST["dirstat"];
$T_MP = explode("/", $dirStat);
$dirStat = $T_MP[0];
if ($dirStat) { //Cambia de directorio
if ($dirStat == ".." || $dirStat == ".") { //Anda uno para abajo
$dirArr = explode("/", $thisDir);
$thisDir = doString(array_slice($dirArr, 0, count($dirArr) - 2), "/") . "/";
} else {
if (file_exists($userDir . $thisDir . $dirStat . "/")) {
$thisDir .= $dirStat . "/";
}
}
$_SESSION[$username . "_dir"] = $thisDir;
}
$getFile = $_REQUEST["getfile"];
if ($getFile) { //Envia un archivo
$T_MP = explode("/", $getFile);
$getFile = $T_MP[0];
$filePath = $userDir . $thisDir . $getFile;
if (file_exists($filePath) && is_file($filePath)) {
if ($adminLogin && $getFile == "user.txt" && $thisDir == "/") { //Es el secreto
} else {
$fhFile = fopen($filePath, "rb");
header("Content-type: " . mime_content_type($filePath));
header('Content-Disposition: attachment; filename="' . $getFile . '"');
fpassthru($fhFile);
fclose($fhFile);
}
exit;
}
}
}
$userDir .= $thisDir;
$dirArr = explode("/", $thisDir);
$dirCount = count($dirArr);
//Subir archivo y otros
if ($_POST) {
switch ($_POST["a"]) {
case "cdir": //Crear directorio
$dirName = str_replace("/", "", $_POST["dir"]);
$dirName = str_replace(" ", "_", $dirName);
if (!file_exists($userDir . $dirName . "/")) { //Puede crear
mkdir($userDir . $dirName . "/", 0777);
}
break;
case "cfile": //Crear archivo
if ($_FILES) {
$file = $_FILES['file'];
$file["name"] = trim($file["name"]);
if ($adminLogin && $file["name"] == "user.txt" && $thisDir == "/") { //Todo mal
} else {
@move_uploaded_file($file['tmp_name'], $userDir . $file["name"]);
}
}
break;
case "ddir" : //Borrar directorio
if ($thisDir != "/") { //Puede borrar
//Si es admin y esta borrando el user
if ($adminLogin && count($dirCount) == 2) {
break;
}
shell_exec("rm -r -f " . $userDir);
$userDir = $STORAGE . $username;
while (!file_exists($userDir . $thisDir) && !is_dir($userDir . $thisDir) && $thisDir != "/") {
$dirArr = explode("/", $thisDir);
$thisDir = doString(array_slice($dirArr, 0, count($dirArr) - 2), "/") . "/";
}
$userDir .= $thisDir;
$dirArr = explode("/", $thisDir);
$dirCount = count($dirArr);
$_SESSION[$username . "_dir"] = $thisDir;
}
break;
case "dfile" : //Borrar archivo
$fileName = $_POST["file"];
$filePath = $userDir . $fileName;
if (file_exists($filePath) && is_file($filePath)) { //Puede borrar
if ($adminLogin && $file["name"] == "user.txt" && $thisDir == "/") { //Casi...
} else {
@unlink($filePath);
}
}
break;
case "kdir" : //Limpiar directorio
if ($thisDir == "/" || ($dirCount == 3 && $adminLogin)) { //Puede borrar
shell_exec("rm -r -f " . $userDir . "*");
}
break;
}
}
$files = scandir($userDir);
?>
LatinComEx: Gestión online
Usted está en: echo $username . $thisDir ?> |
foreach ($files as $file) {
if (is_dir($userDir . $file)) { //Se fija si es un directorio
if ($file == "..") {
if ($thisDir <> "/") {
echo "";
echo " | ";
echo ".. | ";
echo " | ";
echo " | ";
echo " ";
}
} else if ($file == ".") {
} else {
echo "";
echo " | ";
echo "" . trunc($file) . " | ";
echo " | ";
echo "";
echo "";
echo " | ";
echo " ";
}
}
}
foreach ($files as $file) {
if (is_file($userDir . $file)) { //Se fija si es un archivo
echo "";
echo " | ";
echo "" . trunc($file, 100) . " | ";
echo "" . getSize(filesize($userDir . $file)) . " | ";
echo "";
echo "";
echo " | ";
echo " ";
}
}
?>
|
} else {
//No existen, mostramos login
?>
LatinComEx: Gestión online
}
function doString($arr, $str) {
$first = true;
$toReturn = "";
foreach ($arr as $text) {
if ($first) {
$first = false;
} else {
$toReturn .= $str;
}
$toReturn .= $text;
}
return $toReturn;
}
function trunc($str, $len = 100) {
if (strlen($str) > $len) {
return substr($str, 0, $len - 3) . "...";
}
return $str;
}
function getSize($bytes) {
$stat = 0;
while ($bytes > 1024) {
$bytes = ($bytes / 1024);
$stat ++;
}
$size = ((int) ($bytes * 100)) / 100;
switch ($stat) {
case 0:
return $size . "B";
break;
case 1:
return $size . "KB";
break;
case 2:
return $size . "MB";
break;
case 3:
return $size . "GB";
break;
case 4:
return $size . "TB";
break;
}
return "Gigante";
}
?>