Файл: ftp/tgz.php
Строк: 157
<?php
error_reporting(0);
$k=trim($_GET['k']); include("key.php");
$d=rawurldecode(trim($_GET['d'])); $n=rawurldecode(trim($_GET['n']));
if ($d==NULL) {$d="";} else {if ($d=="/") {$d="";}}
if ($n==NULL) {$n=preg_replace("~.*/([^/]*)~m","\1",$d);
$d=preg_replace("~(.*)/[^/]*~m","\1",$d);}
$rd=rawurlencode($d); $rn=rawurlencode($n);
$d=str_replace(".|htaccess",".htaccess",$d);
$n=str_replace(".|htaccess",".htaccess",$n);
$ac=trim($_GET['ac']); $nm=trim($_POST['nm']);
$chd=trim($_POST['chd']); $chf=trim($_POST['chf']);
if ($nm<>NULL) {
$repl=array("\"=>"","/"=>"",":"=>"","*"=>"","?"=>"","""=>"","<"=>"",">"=>"","|"=>"");
$nm=trim(strtr($nm,$repl));
include("repl.php"); $nm=u2t($nm);
if (($nm==".")||($nm=="..")) {$nm=".";}
}
if ($nm<>NULL) {
if (($ftp=@ftp_connect($sr))&&(@ftp_login($ftp,$lg,$ps))) {
@ftp_pasv($ftp,true); $sz=ftp_size($ftp,"$d/$n");
if (($sz==-1)||($sz>716800)) {header("Location: $dftp/ftp.php?k=$k&d=$rd"); exit;}
mkdir("data/$k",0777); ftp_get($ftp,"data/$k-$n","$d/$n",FTP_BINARY);
include("tar.php"); $tar=new Archive_Tar("data/$k-$n");
if ($tar->extract("data/$k")==0) {
$st="Файлы из архива не извлечены. Возможно архив повреждён.";
} else {$st="";
if ($nm<>".") {ftp_mkdir($ftp,"$d/$nm"); $nm="/$nm/";} else {$nm="/";}
function scan($dir) {$arr=NULL; $lst=NULL;
$dh=opendir($dir); while (false!==($filename=readdir($dh))) {$lst[]=$filename;}
if ($lst<>NULL) {
for ($i=0;$i<count($lst);$i++) {
if (is_file($dir."/".$lst[$i])) {
$arr.="1:".$dir."/".$lst[$i]."rn";
} elseif ((is_dir($dir."/".$lst[$i]))&&($lst[$i]<>".")&&($lst[$i]<>"..")) {
$arr.="0:".$dir."/".$lst[$i]."rn"; $arr.=scan($dir."/".$lst[$i]);
}
} return $arr;
} else {return false;}
}
$str=scan("data/$k");
if ($str==false) {
$st="Файлы из архива не извлечены.";
} else {
$ar=explode("rn",$str); sort($ar);
for ($i=0;$i<count($ar);$i++) {
if ($ar[$i]<>NULL) {
list($p1,$p2)=split(":",$ar[$i]); $p1=trim($p1); $p2=trim($p2);
if ($p1==0) {
$name=str_replace("data/$k/","",$p2);
ftp_mkdir($ftp,"$d$nm".$name);
if ($chd<>NULL) {$cmd="chmod 0$chd $d$nm".$name; @ftp_site($ftp,$cmd);}
} else {
$name=str_replace("data/$k/","",$p2);
ftp_put($ftp,"$d$nm".$name,"data/$k/".$name,FTP_BINARY);
if ($chf<>NULL) {$cmd="chmod 0$chf $d$nm".$name; @ftp_site($ftp,$cmd);}
}
}
}
}
}
@ftp_close($ftp);
@unlink("data/$k-$n"); include("rmdir.php"); rdir("data/$k");
if ($st==NULL) {$st.="Файлы извлечены из архива.";}
header("Content-Type: text/vnd.wap.wml; charset=Utf-8");
echo ("<?xml version="1.0" encoding="Utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.xml"><wml>
<head><meta forua="true" http-equiv="Cache-Control" content="no-cache,no-store,must-revalidate"/></head><card title="FTP - TAR">
<p align="center"><small>
<a href="ftp.php?k=$k&d=$rd">$d</a><br/>
- - -<br/>
$st
</small></p>
</card></wml>");
} else {
header("Content-Type: text/vnd.wap.wml; charset=Utf-8");
echo ("<?xml version="1.0" encoding="Utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.xml"><wml>
<head><meta forua="true" http-equiv="Cache-Control" content="no-cache,no-store,must-revalidate"/></head><card title="FTP - TAR">
<p align="center"><small>
Нет соединения с сервером.<br/>
- - -<br/>
<anchor>Назад<prev/></anchor>
</small></p>
</card></wml>");
}
} else {
$d=str_replace('$','$$',$d); $n=str_replace('$','$$',$n);
$num=@file_get_contents("allnumbd.dat"); $nar=NULL;
$num++; $nar=$num; if ($num>99999999) {$num=0;}
$f=@fopen("allnumbd.dat","w"); @fwrite($f,$num); @fclose($f);
if (file_exists("data/$k")) {include("rmdir.php"); rdir("data/$k");}
$dnm=preg_replace("~([^.]*).*~m","\1",$n);
header("Content-Type: text/vnd.wap.wml; charset=Utf-8");
echo ("<?xml version="1.0" encoding="Utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.xml"><wml>
<head><meta forua="true" http-equiv="Cache-Control" content="no-cache,no-store,must-revalidate"/></head><card title="FTP - TAR">
<p align="left"><small>
<a href="file.php?k=$k&d=$rd">$d/</a>$n<br/>
- - -<br/>
Извлечь в папку:</small><input name="nm".$nar."" type="text" value="$dnm" maxlength="150"/><br/>
<small>CHMOD файлов:</small>
<input name="chf".$nar."" type="text" value="644" size="3" maxlength="3" format="*N"/><br/>
<small>CHMOD папок:</small>
<input name="chd".$nar."" type="text" value="755" size="3" maxlength="3" format="*N"/><br/>
<small>- - -<br/>
<anchor>Разархивировать
<go href="$dftp/tgz.php?k=$k&d=$rd&n=$rn&ac=$ac" method="post">
<postfield name="nm" value="$(nm".$nar.")"/>
<postfield name="chd" value="$(chd".$nar.")"/>
<postfield name="chf" value="$(chf".$nar.")"/>
</go></anchor><br/>
- - -<br/>
<anchor>Назад<prev/></anchor>
</small></p>
</card></wml>");
}
?>