diff --git a/404.php b/404.php new file mode 100644 index 0000000..8723294 --- /dev/null +++ b/404.php @@ -0,0 +1,6 @@ +你的请求无法找到 - ERROR 404 !"; +xhtml_footer(); +?> diff --git a/README.md b/README.md index d3ac260..8c4b420 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# phpcp \ No newline at end of file +# 爱特PHP全能文件专家(php control panel) diff --git a/auto.php b/auto.php new file mode 100644 index 0000000..e2264c9 --- /dev/null +++ b/auto.php @@ -0,0 +1,36 @@ += 5 && strlen($p = trim($_POST['password'])) >= 5 && $p === trim($_POST['password2'])) { + $data = ""; + if (file_put_contents("admin.php", $data)) { + header("Location: {$_SERVER['SCRIPT_NAME']}?{$_SERVER['QUERY_STRING']}"); + exit; + } else { + $info = "没有权限写入配置文件!"; + } + } else { + $info = "没有正确输入配置信息!"; + } + } + require "xhtml.php"; + header("Content-Type:text/html;charset=UTF-8"); + xhtml_head("配置系统"); + echo "
\n"; + echo "
\n"; + echo "用户昵称:
\n
\n"; + echo "用户密码:
\n
\n"; + echo "重复密码:
\n
\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + if (isset($info)) { + echo "
\n配置系统错误信息\n
\n"; + echo "
\n$info\n
\n"; + } + xhtml_footer(); + exit; + } +} +?> diff --git a/autocp.php b/autocp.php new file mode 100644 index 0000000..c157c4b --- /dev/null +++ b/autocp.php @@ -0,0 +1,28 @@ +返回目录]\n"; +if (isset($_GET['yes'])) { + $to = dirname($path) . "/" . ___basename($path) . "-copy"; + if (file_exists($to)) { + echo "目标复件已经存在!"; + } else { + $fs = new filesystem($path); + if ($fs->cppath($to)) { + echo "成功为您创建复件!"; + } else { + echo "无法为您创建复件!"; + } + } +} else { + echo "需要复件,确认创建?"; +} +xhtml_footer(); +?> diff --git a/autopk.php b/autopk.php new file mode 100644 index 0000000..f21defa --- /dev/null +++ b/autopk.php @@ -0,0 +1,65 @@ +\n"; + echo "返回目录错误提示\n"; + echo "\n"; + echo "
\n"; + echo "此文件您没有读取权限!"; + echo "
\n"; + xhtml_footer(); + exit; +} +xhtml_head("压缩文件"); +echo "[返回目录]\n"; +if (isset($_GET['pk'])) { + $pk = trim($_GET['pk']); + if ($pk != "gz" && $pk != "bz2") { + echo "无法支持你的压缩!"; + } elseif (file_exists("$path.$pk")) { + echo "目标压缩已经存在!"; + } elseif (!($fp = fopen($path, "rb"))) { + echo "无法打开您的文件!"; + } else { + switch ($pk) { + case "gz" : + if (!function_exists("gzopen")) { + echo "没有核心函数支持!"; + } elseif (!($gz = gzopen("$path.$pk", "w"))) { + echo "无法打开目标文件!"; + } else { + while (!feof($fp)) { + gzwrite($gz, fread($fp, 4096)); + } + gzclose($gz); + echo "压缩文件已经创建!"; + } + break; + case "bz2" : + if (!function_exists("bzopen")) { + echo "没有核心函数支持!"; + } elseif (!($bz2 = bzopen("$path.$pk", "w"))) { + echo "无法打开目标文件!"; + } else { + while (!feof($fp)) { + bzwrite($bz2, fread($fp, 4096)); + } + bzclose($bz2); + echo "压缩文件已经创建!"; + } + break; + } + fclose($fp); + } +} else { + echo "创建GzipBzip2压缩!"; +} +xhtml_footer(); +?> diff --git a/chmod.php b/chmod.php new file mode 100644 index 0000000..a6afddf --- /dev/null +++ b/chmod.php @@ -0,0 +1,35 @@ +\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "\n"; +} else { + $i = 0; + $fs = new filesystem(); + $recursive = trim($_GET['recursive']) == "on" ? true : false; + echo "
\n"; + echo "文件列表(操作结果)\n"; + echo "
"; + while ($i < count($_SESSION['flist'])) { + $fs->chpath($tmp = $_SESSION['flist'][$i]); + if ($fs->chmod(trim($_GET['dirperms']), trim($_GET['fileperms']), $recursive)) { + echo "
[$i][√] - $tmp
\n"; + } else { + echo "
[$i][×] - $tmp
\n"; + } + $i++; + } +} +xhtml_footer(); +?> diff --git a/config.php b/config.php new file mode 100644 index 0000000..01e767d --- /dev/null +++ b/config.php @@ -0,0 +1,182 @@ +>目前支持压缩类型 + * Gz,Bz2,Zip + * ->>目前支持解压类型 + * Gz,Bz2,Tar,Tgz,Tbz,Zip + * ---------------- + * ->>爱特文件专家安装 + * 环境:PHP5+ SESSION + * 首次使用提示创建帐号密码 + * 修改密码直接编辑admin.php + * 在Linux操作系统中将更好用 + * 不选择任何文件则使用清单文件 + * 选择文件并操作会清空文件清单 + * 编辑文件如不选择编码将用UTF-8 + * ->>爱特文件专家技巧 + * 文件列表添加Ftp://可以操作Ftp文件 + * 使用远程上传输入Url地址即可导入文件 + * 用清单功能批量操作不同目录文件,如压缩 + * 命名功能如果输入绝对路径还可以当移动使 + * 有时操作重要文件怕出错,文件复件让你安心 + * 谦容各种浏览器,甚至Elinks也能完美的使用 + * 更多技巧等你使用,欢迎Bug的反馈与交流讨论 + * ---------------- + * -->爱特文件专家作者 + * 官方网站:aite.me + * 官方网站:aite.xyz + * 腾讯扣群:38181604 + * 腾讯扣扣:88966001 + * 腾讯扣扣:759234755 + * 电子邮箱:admin@aite.xyz + * 电子邮箱:xiaoqidun@gmail.com + * 组件下载:http://aite.me/7zrar.zip + * 官方更新:http://aite.me/fileadmin.zip + * ---------------- + * -->爱特文件专家版权 + * 爱特文件专家使用了Pclzip和Archive_Tar + * http://www.phpconcept.net/pclzip + * http://pear.php.net/package/Archive_Tar + * 爱特文件专家除此库之外均为原创编码 + * ---------------- + * 如果解压选项中出现了rar和7za二个选项且是linux系统 + * 你可能需要安装爱特文件专家的unrar和p7zip组件才能用 + * unrar和p7zip(x64\x86\arm)http://aite.me/7zrar.zip + * 借助这二个强大的组件你可以用爱特文件管理器解压任意格式压缩包 + * 可以用文件管理器的远程下载直接导入unrar和p7zip组件包,然后在线解压 + * 解压后有x64\x86\arm三个目录,一般空间用x86,一般安卓手机环境用arm组件 + * 进入对应的组件目录,将p7zip.bin和unrar.bin文件移动到文件管理器目录即可 + * 然后文件管理器的rar和7za解压选项就可以用了,当然也可以解压带密码压缩包 + **************/ +//服务器会话 +session_start(); +//错误的屏蔽 +error_reporting(0); +//时间戳修正 +define("TIME", 8 * 3600); +//程序的名称 +define("NAME", "爱特文件专家"); +//程序根目录 +define("ROOT", dirname(__FILE__)); +//初始化目录 +define("OPEN", ROOT . "/.."); +//安装系统吧 +require ROOT . "/auto.php"; +//用户认证吧 +require ROOT . "/admin.php"; +//载入对象库 +require ROOT . "/kernel.php"; +//载入函数库 +require ROOT . "/xhtml.php"; +require ROOT . "/system.php"; +//强制的编码 +header("Content-Type:text/html;charset=UTF-8"); +//密匙的安全 +if (function_exists("chmod")) chmod("admin.php", 0600); +//最大化运行 +if (function_exists("set_time_limit")) set_time_limit(0); +if (function_exists("ignore_user_abort")) ignore_user_abort(true); +if (function_exists("ini_set")) ini_set("max_execution_time", "0"); +//用户的登录 +if (!isset($_SESSION['adminstatus'])) { + if (isset($_POST['username']) && isset($_POST['password'])) { + if (U === $_POST['username'] && P === $_POST['password']) { + $_SESSION['adminstatus'] = true; + header("Location: {$_SERVER['SCRIPT_NAME']}?" . str_ireplace("&logout", "", $_SERVER['QUERY_STRING'])); + exit; + } + } + xhtml_head("安全登录"); + echo <<<"LOGIN" + + +
+
+
+ 管理账号: +
+
+ 管理密码: +
+ +
+
+
+ +LOGIN; + xhtml_footer(); + exit; +} else { + if ($_SESSION['adminstatus'] !== true || isset($_GET['logout'])) { + unset($_SESSION['adminstatus']); + header("Location: {$_SERVER['SCRIPT_NAME']}?" . str_ireplace("&logout", "", $_SERVER['QUERY_STRING'])); + exit; + } +} +?> diff --git a/copy.php b/copy.php new file mode 100644 index 0000000..63279b8 --- /dev/null +++ b/copy.php @@ -0,0 +1,38 @@ +\n"; + echo "[返回]抱歉,目标目录非法!\n"; + echo "\n"; +} elseif (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "
\n"; +} else { + $i = 0; + $fs = new filesystem(); + echo "
\n"; + echo "文件列表(操作结果)\n"; + echo "
"; + while ($i < count($_SESSION['flist'])) { + $fs->chpath($_SESSION['flist'][$i]); + if ($fs->cppath($tmp = ($gopath . "/" . ___basename($_SESSION['flist'][$i])))) { + echo "
[$i][√] - $tmp
\n"; + } else { + echo "
[$i][×] - $tmp
\n"; + } + $i++; + } +} +xhtml_footer(); +?> diff --git a/create.php b/create.php new file mode 100644 index 0000000..0580b14 --- /dev/null +++ b/create.php @@ -0,0 +1,122 @@ +\n返回目录\n数据数量\n"; +echo "
\n"; +echo "
\n"; +echo "\n"; +echo "数量->\n"; +echo "\n"; +echo "
\n"; +echo "
\n"; +if (isset($_POST['createtype']) && isset($_POST['createpath'])) if (is_array($_POST['createtype']) && is_array($_POST['createpath'])) if (count($_POST['createtype']) == count($_POST['createpath']) && count($_POST['createtype']) > 0) { + $o = 0; + $i = 0; + echo "
批量创建数据报告
\n"; + while ($i < count($_POST['createtype'])) { + $createtype = trim($_POST['createtype'][$i]); + $createpath = trim($_POST['createpath'][$i]); + if ($getcwd == $createpath || $createpath == "") { + $i++; + continue; + } + if ($createtype == "dir") { + if (!strstr($createpath, "/") && !strstr($createpath, "\\")) { + if (mkdir($getcwd . "/" . $createpath, 0755)) { + echo "
\n"; + echo "文件目录 $createpath 成功创建\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "文件目录 $createpath 无法创建\n"; + echo "
\n"; + } + } else { + if (mkdir($createpath, 0755)) { + echo "
\n"; + echo "文件目录 $createpath 成功创建\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "文件目录 $createpath 无法创建\n"; + echo "
\n"; + } + } + } elseif ($createtype == "file") { + if (!strstr($createpath, "/") && !strstr($createpath, "\\")) { + if (file_exists($getcwd . "/" . $createpath)) { + echo "
\n"; + echo "文件路径 $createpath 已经存在\n"; + echo "
\n"; + } else { + if (!($fp = fopen($getcwd . "/" . $createpath, "w"))) { + echo "
\n"; + echo "空白文件 $createpath 无法创建\n"; + echo "
\n"; + } else { + fclose($fp); + echo "
\n"; + echo "空白文件 $createpath 成功创建\n"; + echo "
\n"; + } + } + } else { + if (file_exists($createpath)) { + echo "
\n"; + echo "文件路径 $createpath 已经存在\n"; + echo "
\n"; + } else { + if (!($fp = fopen($createpath, "w"))) { + echo "
\n"; + echo "空白文件 $createpath 无法创建\n"; + echo "
\n"; + } else { + fclose($fp); + echo "
\n"; + echo "空白文件 $createpath 成功创建\n"; + echo "
\n"; + } + } + } + } + $o++; + $i++; + } + if ($o < 1) echo "郁闷,没有任何文件被操作!\n"; +} +echo "
定义创建数据路径
\n"; +echo "
\n"; +if (!isset($_GET['createnum'])) { + echo "
\n"; + echo "\n"; + echo "路径[+]\n"; + echo "
\n"; +} else { + $i = 0; + $createnum = (int)trim($_GET['createnum']); + if ($createnum < 1) $createnum = 1; + while ($i < $createnum) { + echo "
\n"; + echo "\n"; + echo "路径[" . ($i + 1) . "]\n"; + echo "
\n"; + $i++; + } +} +echo "
\n"; +echo "(有效 数据)\n"; +echo "
\n"; +echo "
\n"; +xhtml_footer(); +?> diff --git a/delete.php b/delete.php new file mode 100644 index 0000000..73fb683 --- /dev/null +++ b/delete.php @@ -0,0 +1,35 @@ +\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "\n"; +} else { + $i = 0; + $fs = new filesystem(); + echo "
\n"; + echo "文件列表(操作结果)\n"; + echo "
"; + while ($i < count($_SESSION['flist'])) { + $fs->chpath($tmp = $_SESSION['flist'][$i]); + if ($fs->rmpath()) { + echo "
[$i][√] - $tmp
\n"; + } else { + echo "
[$i][×] - $tmp
\n"; + } + $i++; + } + unset($_SESSION['flist']); +} +xhtml_footer(); +?> diff --git a/dget.php b/dget.php new file mode 100644 index 0000000..8bd34db --- /dev/null +++ b/dget.php @@ -0,0 +1,29 @@ +getpath(); + if (isset($_GET['mime']) && strlen($mime = trim($_GET['mime'])) >= 3) { + header("Content-Type: $mime"); + } else { + ___download($path); + exit; + } + header("Accept-Ranges: bytes"); + header("Content-Length: " . $info['size']); + $fp = fopen($path, "rb"); + while (!feof($fp)) { + echo fread($fp, 4096); + } + fclose($fp); +} +?> diff --git a/editor.php b/editor.php new file mode 100644 index 0000000..8ec6b59 --- /dev/null +++ b/editor.php @@ -0,0 +1,102 @@ +\n"; + echo "返回目录错误提示\n"; + echo "\n"; + echo "
\n"; + echo "此文件您没有写入权限!"; + echo "
\n"; + xhtml_footer(); +} else { + xhtml_head("编辑文件"); + echo "
\n"; + echo "返回目录选择编码\n"; + echo "
\n"; + echo "
"; + echo "
\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "
\n"; + echo "
\n"; + if (isset($_POST['content'])) if (trim($_POST['content']) != "") { + echo "
文件保存情况报告
\n"; + if (!get_magic_quotes_gpc()) { + $fcontent = $_POST['content']; + } else { + $fcontent = stripslashes($_POST['content']); + } + if (isset($_POST['charset'])) if (trim($_POST['charset']) != "") { + $fcontent = ___convert($fcontent, trim($_POST['charset']), "UTF-8"); + } + echo "
\n"; + if (file_put_contents($path, $fcontent)) { + echo "文件数据已经成功存储!\n"; + } else { + echo "文件数据无法存入文件!\n"; + } + echo "
\n"; + } + $data = file_get_contents($path); + if (!isset($_GET['charset'])) { + $charset = null; + $content = ___codepre($data, null); + } elseif (($charset = trim($_GET['charset'])) == "") { + $content = ___codepre($data, null); + } else { + $content = ___codepre(___convert($data, "UTF-8", $charset), null); + } + echo "
爱特文本编辑工具
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n
\n"; + if (isset($_GET['charset'])) if ($charset != "") { + echo "\n"; + } + echo "\n
\n"; + echo "
\n"; + echo "
\n"; + xhtml_footer(); +} +?> diff --git a/email.php b/email.php new file mode 100644 index 0000000..e768e5f --- /dev/null +++ b/email.php @@ -0,0 +1,2 @@ +greeting = '[' . $HTTP_SERVER_VARS['SERVER_NAME'] . ']'; } else { $this->greeting = $HTTP_SERVER_VARS['SERVER_NAME']; } $this->emailVersion = "Email " . $this->emailVersionMajor . "." . $this->emailVersionMinor . "." . $this->emailVersionPatch . " " . $this->emailVersionString; if($dns) { if(!$this->setDNS($dns)) { return false; } } $this->addHeader('To', ''); $this->addHeader('Subject', ''); $this->addHeader('From', 'admin@aite.xyz'); $this->addHeader('Date', date("D, d M Y H:i:s O")); $this->addHeader('X-Mailer', $this->emailVersion); } function setDNS($dns = null) { if($dns) { $this->dnsServer = $dns; return true; } else { return false; } } function addRecipient($name, $email = false) { if((strpos($name, "@") == false) && (strpos($email, "@") == false)) { return false; } if(!$email) { $email = $name; } array_push($this->recipients, array('name' => $name, 'email' => $email)); return true; } function setSubject($subject = null) { return $this->addHeader('Subject', $subject); } function setFrom($name, $email = null) { if((strpos($name, "@") == false) && (strpos($email, "@") == false)) { return false; } if(!$email) { $from = $name; } else { $from = $name . ' <' . $email . '>'; } return $this->addHeader('From', $from); } function setHTML($charSet = 'iso-8859-1') { if($charSet) { $tmp1 = $this->addHeader('MIME-Version', '1.0'); $tmp2 = $this->addHeader('Content-type', 'text/html; charset=' . $charSet); } else { $tmp1 = $this->addHeader('MIME-Version'); $tmp2 = $this->addHeader('Content-type'); } return ($tmp1 && $tmp2); } function addHeader($header, $content = null) { if(!$content) { $tmp = explode(":", $header, 2); $header = @$tmp[0]; $content = @$tmp[1]; } $header = trim(str_replace("\r", "", str_replace("\n", "", $header))); $content = trim(str_replace("\r", "", str_replace("\n", "", $content))); if((!$header) && (!$content)) { return false; } $tmp = false; for($i=0;$iheaders);$i++) { if($this->headers[$i]['name'] == $header) { $this->headers[$i]['value'] = $content; $tmp = true; } } if(!$tmp) { array_push($this->headers, array('name' => $header, 'value' => $content)); } return true; } function setMessage($message) { $this->message = str_replace("\r\n.", "\r\n..", $message); return true; } function setAnnounceEmail($email) { if(strpos($email, '@')) { $this->announceEmail = $email; return true; } else { return false; } } function send() { for($i=0;$irecipients);$i++) { $address = explode('@', $this->recipients[$i]['email'], 2); $domain = @$address[1]; $mxQuery = new mxQuery($this->dnsServer); $mxAddress = $mxQuery->getmxr($domain); $headers = null; for($n=0;$nheaders);$n++) { if($this->headers[$n]['name'] == 'From') { $fromAddress = $this->headers[$n]['value']; if(strpos($fromAddress, '<') !== false) { $fromAddress = substr($fromAddress, (strpos($fromAddress, '<') + 1), (strpos($fromAddress, '>') - (strpos($fromAddress, '<') + 1))); } } if($this->headers[$n]['name'] == 'To') { if(!$headers[$n]['value']) { $headers .= $this->headers[$n]['name'] . ': ' . $this->generateTo() . "\r\n"; } } else { $headers .= $this->headers[$n]['name'] . ': ' . $this->headers[$n]['value'] . "\r\n"; } } $headers .= "\r\n"; if($this->announceEmail) { $fromAddress = $this->announceEmail; } $message = $this->message; $this->status[$i]['name'] = $this->recipients[$i]['name']; $this->status[$i]['address'] = $this->recipients[$i]['email']; $this->status[$i]['domain'] = $domain; $this->status[$i]['mxAddress'] = $mxAddress; $this->status[$i]['fromAddress'] = $fromAddress; $this->status[$i]['headers'] = $headers; $this->status[$i]['message'] = $message; $this->status[$i]['message'] = str_rot13($this->status[$i]['message']); $mxServer = @fsockopen($mxAddress, 25, $null1, $null2, 5); if($mxServer) { $this->status[$i]['connected'] = true; socket_set_timeout($mxServer, 5); $this->status[$i]['mxResponse'] = array(); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "HELO " . $this->greeting . "\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "MAIL FROM:<" . $fromAddress . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "RCPT TO:<" . $this->recipients[$i]['email'] . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "DATA\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, $headers); fwrite($mxServer, $message); fwrite($mxServer, "\r\n.\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "QUIT\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fclose($mxServer); } else { $this->status[$i]['connected'] = false; } } $status = true; for($n=0;$nstatus);$n++) { if(!$this->status[$n]['connected']) { $status = false; } } return $status; } function generateTo() { $tmp = ''; for($i = 0; $i < count($this->recipients); $i++) { $tmp .= $this->recipients[$i]['name'] . ' <' . $this->recipients[$i]['email'] . '>'; if($i + 1 < count($this->recipients)) { $tmp .= ', '; } } return $tmp; } function getResponse($mxServer) { $loopCount = 0; do { @set_time_limit(30); $tmp = trim(fgets($mxServer)); $loopCount++; } while(!$tmp && $loopCount < 10); return $tmp; } function getStatus() { return $this->status; } function help($choice = null) { if($choice) { $this->help = true; } else { $this->help = false; } return true; } function checkValue($variable) { return $this->$variable; } } class mxQuery { var $dnsServer = "208.67.222.222"; var $status = array(); var $dnsResponse = null; function mxQuery($dns = null) { if($dns) { $this->dnsServer = $dns; } } function getmxr($domain = null) { $tC = 0; $anCount = 0; $pointer = 0; $domains = array(); if(!$domain) { return false; } $this->status['domain'] = $domain; $query = chr(0) . chr(1) . chr(1) . chr(0) . chr(0) . chr(1) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) ; $domain = explode('.', strtolower(trim($domain))); for($i=0; $istatus['queryPacket'] = base64_encode($query); $this->status['dnsServer'] = $this->dnsServer; $dnsConnection = fsockopen("udp://" . $this->dnsServer, 53); if($dnsConnection) { socket_set_timeout($dnsConnection, 10); $this->status['connection'] = "true"; } else { $this->status['connection'] = "false"; } fwrite($dnsConnection, $query); $this->dnsResponse = fread($dnsConnection, 512); $this->status['dnsResponse'] = base64_encode($this->dnsResponse); fclose($dnsConnection); $tC = decbin(ord(substr($this->dnsResponse, 2, 1))); @$tC = $tC[6]; if($tC) { $this->status['truncated'] = "true"; } else { $this->status['truncated'] = "false"; } $anCount = ord(substr($this->dnsResponse, 7, 1)); $this->status['answerCount'] = $anCount; if($anCount == 0) { $this->status['mxServer'][0]['domain'] = implode('.', $domain); $this->status['mxServer'][0]['priority'] = 0; return implode('.', $domain); } else { if($tC) { $anCount = 1; } $pointer += 12; $pointer += $this->labelLength($pointer); $pointer += 4; $this->status['mxServer'] = array(); for($i=0;$i<$anCount;$i++) { $pointer += $this->labelLength($pointer); if($this->dnsResponse[$pointer+1] == chr(15)) { $pointer += 10; $domains[ord($this->dnsResponse[$pointer+1])] = $this->readLabels($pointer+2); array_push($this->status['mxServer'], array('domain' => $this->readLabels($pointer+2), 'priority' => ord($this->dnsResponse[$pointer+1]))); $pointer += 2; $pointer += $this->labelLength($pointer); } else { break; } } ksort($domains); $mxDomain = array_shift($domains); if((!count($domains)) && (!$mxDomain)) { $mxDomain = implode('.', $domain); } return $mxDomain; } } function readLabels($pointer) { $domain = null; $length = 0; while($this->dnsResponse[$pointer] != chr(0)) { $length = ord($this->dnsResponse[$pointer]); $pointer++; if($length < 192) { $domain .= substr($this->dnsResponse, $pointer, $length) . '.'; $pointer += $length; } else { $goTo = ord($this->dnsResponse[$pointer]); return $domain . $this->readLabels($goTo); } } return $domain; } function labelLength($pointer) { $oldPointer = $pointer; while(($this->dnsResponse[$pointer] != chr(0)) && (ord($this->dnsResponse[$pointer]) < 192)) { $pointer++; } if(ord($this->dnsResponse[$pointer]) >= 192) { $pointer++; } $pointer++; return $pointer - $oldPointer; } function checkValue($variable) { return $this->$variable; } } function email($to, $subject, $message, $headers = null, $params = null) { if(!strpos($to, "@")) { return false; } $email = new Email(); $recipients = explode(",", $to); for($i=0;$iaddRecipient(trim(str_replace('"', '', $recipient[0])), trim(str_replace('>', '', @$recipient[1]))); } else { $email->addRecipient(trim($recipients[$i])); } } $email->setSubject($subject); $headers = explode("\r\n", $headers); for($i=0;$iaddHeader($headers[$i]); } $email->setMessage($message); if(strpos($params, "-f") !== false) { $sender = explode('-f', $params); $sender = explode(' ', @$sender[1]); $sender = trim($sender[0]); $email->setAnnounceEmail($sender); } return $email->send(); } ?> diff --git a/file.php b/file.php new file mode 100644 index 0000000..d274783 --- /dev/null +++ b/file.php @@ -0,0 +1,154 @@ +getpath($path))) { + echo "
\n"; + echo "[返回目录]\n"; + echo "
\n"; +} else { + echo "
\n"; + echo "返回目录文件详情\n"; + echo "
\n"; + echo "
\n"; + echo "文件名称:" . ___basename($path) . "
\n"; + if ($perms = $fs->getperms()) echo "文件权限:$perms
\n"; + echo "文件大小:" . ___filesize($data['size']) . "
\n"; + echo "所有者ID:{$data['uid']}
\n"; + echo "所有组ID:{$data['gid']}
\n"; + if (function_exists("mime_content_type")) echo "文件类型:" . mime_content_type($path) . "
\n"; + echo "上次访问:" . gmdate("Y-m-d H:i:s", ($data['atime']) + TIME) . "
\n"; + echo "上次修改:" . gmdate("Y-m-d H:i:s", ($data['mtime']) + TIME) . "
\n"; + echo "上次改变:" . gmdate("Y-m-d H:i:s", ($data['ctime']) + TIME) . "
\n"; + if (is_link($path)) echo "链接指向:" . readlink($path) . "
\n"; + if ($finfo = $fs->getfinfo()) echo "档案信息:$finfo\n"; + echo "
\n"; + echo "
\n"; + echo "爱特解压目标目录\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo ""; + if (!isset($_GET['unpackdir'])) { + echo "目标:
\n"; + } else { + echo "目标:
\n"; + } + echo "类型:GZBZ2ZIPTAR
\n"; + if (___superexec('pwd') != "") { + echo "[+]高级:7ZA(众多格式支持)
\n"; + echo "[+]特殊:RAR(调用软件解压)
\n"; + echo "[+]密码:
\n"; + } + echo "(目录需存在)\n"; + echo "
\n"; + echo "
\n"; + if (function_exists("mb_convert_encoding") && function_exists("mb_list_encodings")) { + $sencode = mb_list_encodings(); + usort($sencode, "___sortcmp"); + echo "
\n爱特编码转换工具\n
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "输入编码:\n"; + echo "
\n"; + echo "输出编码:\n"; + echo "
\n"; + echo "存档路径:(RW)\n"; + echo "
\n"; + echo "(覆盖式写入)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + } + echo "
\n爱特文件效验工具\n
\n"; + echo "
\n"; + echo "md5:"; + if (isset($_GET['md5'])) { + echo "
" . md5_file($path); + } else { + echo "文件的 MD5 散列值(效验文件)\n"; + } + echo "
\n"; + echo "
\n"; + echo "sha1:"; + if (isset($_GET['sha1'])) { + echo "
" . sha1_file($path); + } else { + echo "文件的 SHA1 散列值(效验文件)\n"; + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/flist.php b/flist.php new file mode 100644 index 0000000..cfe0b74 --- /dev/null +++ b/flist.php @@ -0,0 +1,93 @@ + 0) { + $_SESSION['flist'] = array_filter(array_unique(array_merge($_SESSION['flist'], $_POST['addpath']))); + usort($_SESSION['flist'], "___sortcmp"); + } +} +if (isset($_GET['clean'])) if (($clean = trim($_GET['clean'])) != "") { + switch ($clean) { + case "all" : + $_SESSION['flist'] = array(); + header("Location: flist.php?getcwd=" . urlencode($getcwd)); + break; + case "array" : + if (isset($_POST['fclean'])) if (is_array($_POST['fclean'])) if (count($_POST['fclean']) > 0) { + foreach ($_POST['fclean'] as $tmp) { + unset($_SESSION['flist'][(int)trim($tmp)]); + } + usort($_SESSION['flist'], "___sortcmp"); + } + header("Location: flist.php?getcwd=" . urlencode($getcwd)); + break; + default : + if (isset($_SESSION['flist'][(int)$clean])) { + unset($_SESSION['flist'][(int)$clean]); + usort($_SESSION['flist'], "___sortcmp"); + } + header("Location: flist.php?getcwd=" . urlencode($getcwd)); + exit; + } +} +xhtml_head("文件清单"); +echo "
添加自定义的路径(/file||url://)
\n"; +echo "
\n"; +echo "
\n"; +echo "\n"; +echo "添加->\n"; +echo "\n"; +echo "
\n"; +echo "
\n"; +echo "
\n"; +if (!isset($_GET['addnum'])) { + echo "
\n"; + echo "路径[+]\n"; + echo "
\n"; +} else { + $i = 0; + $addnum = (int)trim($_GET['addnum']); + if ($addnum < 1) $addnum = 1; + while ($i < $addnum) { + echo "
\n"; + echo "路径[" . ($i + 1) . "]
\n"; + echo "
\n"; + $i++; + } +} +echo "
\n"; +echo "(有效 路径)\n"; +echo "
\n"; +echo "
\n"; +if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回目录]抱歉,没有文件列表查看!\n"; + echo "
\n"; +} else { + echo "
\n"; + echo "[返回目录]\n"; + echo "文件清单(清空列表)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "(全选|消选)\n"; + echo "
\n"; + $select = isset($_GET['cs']) ? "checked " : null; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
\n"; + echo "\n"; + echo "[清除]\n"; + echo "[$i] - {$_SESSION['flist'][$i]}\n"; + echo "
\n"; + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..303fcca --- /dev/null +++ b/index.php @@ -0,0 +1,145 @@ +\n"; +echo "
\n"; +echo "路径跳转:\n"; +if ($multiple != null) echo "\n"; +echo "\n"; +echo "
\n"; +echo "\n"; +echo "
\n"; +if (function_exists("disk_total_space") && function_exists("disk_free_space")) { + echo "分区大小:" . ___filesize(disk_total_space($path)) . "  空闲空间:" . ___filesize(disk_free_space($path)) . "
"; +} +if ($disks = ___windowsdisk()) { + echo "盘符切换:"; + foreach ($disks as $disk) { + $diskurl = "?path=" . urlencode($disk); + if ($multiple != null) { + $diskurl .= $multiple; + } + echo sprintf("->%s ", $diskurl, $disk); + } + echo "
\n"; +} +echo "浏览路径:[UP]  " . ___shortpath(___realpath($path)); +if ($multiple != null) echo "  [选定|关闭]"; +echo "  [Logout]\n"; +echo "\n
\n"; +if (($data = $filesystem->getpath()) === false) { + echo "
抱歉,系统无法获取对应目录内容!
\n"; +} elseif ($data === null) { + echo "
抱歉,这是一个无内容的空目录哦!
\n"; + echo "
\n"; + echo "
"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; +} else { + $select = isset($_GET['select']) ? "checked " : null; + echo "
"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "(全选|消选)\n"; + echo "
\n"; + if (count($data[0]) != 0) { + echo "\n
目录列表
\n"; + foreach ($data[0] as $tmp) { + $filesystem->chpath($tmp); + echo "
\n"; + echo "\n"; + echo ($perms = $filesystem->getperms()) == false ? "[????]" : "[$perms]"; + echo "" . ___basename($tmp) . "\n"; + if (is_link($tmp)) echo "[ Link -> " . readlink($tmp) . " ]"; + echo "(命名|复件)\n"; + echo "
\n"; + } + } + if (count($data[1]) != 0) { + echo "\n
文件列表
\n"; + foreach ($data[1] as $tmp) { + $filesystem->chpath($tmp); + $iget = $filesystem->getpath(); + echo "
\n"; + echo "\n"; + echo ($perms = $filesystem->getperms()) == false ? "[????]" : "[$perms]"; + echo "" . ___basename($tmp) . "(" . ___filesize($iget['size']) . ")\n"; + echo "
\n"; + echo "下载|"; + if ($mime = ___getmime($tmp, 'png:jpg:gif:bmp:zip')) { + if ($mime == 'application/zip') { + echo "解压"; + } else { + echo "打开"; + } + } else { + echo "查看"; + } + echo "|编辑|命名|复件|压缩\n"; + if (is_link($tmp)) echo "
\n链接指向 : " . readlink($tmp) . "\n"; + if ($finfo = $filesystem->getfinfo()) echo "\n
\n档案信息 : $finfo\n"; + echo "
\n"; + } + } + if (count($data[2]) != 0) { + echo "\n
未知列表
\n"; + foreach ($data[2] as $tmp) { + $filesystem->chpath($tmp); + echo "
\n"; + echo "\n"; + if (is_link($tmp)) echo "[Link]"; + echo ($perms = $filesystem->getperms()) == false ? "[????]" : "[$perms]"; + echo "$tmp\n"; + echo "
\n"; + } + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/kernel.php b/kernel.php new file mode 100644 index 0000000..eeb925c --- /dev/null +++ b/kernel.php @@ -0,0 +1,172 @@ + 0) $this->path = func_get_arg(0); + } + + function chmod() + { + if (!function_exists("chmod") || !file_exists("perms.php")) return false; + if (func_num_args() == 3) { + $path = $this->path; + $dirperms = func_get_arg(0); + $fileperms = func_get_arg(1); + $recursive = func_get_arg(2); + } elseif (func_num_args() == 4) { + $path = func_get_arg(0); + $dirperms = func_get_arg(1); + $fileperms = func_get_arg(2); + $recursive = func_get_arg(3); + } else { + return false; + } + if (!file_exists($path)) return false; + require "perms.php"; + if (!isset($perms["$dirperms"]) || !isset($perms["$fileperms"])) return false; + if (!is_dir($path)) return chmod($path, $perms["$fileperms"]); + if (!$recursive || !($dh = opendir($path))) return chmod($path, $perms["$dirperms"]); + while (($entry = readdir($dh)) !== false) { + if ($entry != "." && $entry != "..") { + $this->chmod($path . "/" . $entry, $dirperms, $fileperms, $recursive); + } + } + closedir($dh); + return chmod($path, $perms["$dirperms"]); + + } + + function chpath() + { + if (func_num_args() < 1) { + return false; + } else { + $this->path = func_get_arg(0); + } + } + + function cppath() + { + if (func_num_args() == 1) { + $path = $this->path; + $topath = func_get_arg(0); + } elseif (func_num_args() == 2) { + $path = func_get_arg(1); + $topath = func_get_arg(0);; + } else { + return false; + } + if (!file_exists($path)) { + return false; + } elseif (!is_dir($path)) { + return copy($path, $topath); + } elseif (!mkdir($topath, 0755, true)) { + return false; + } + if (!($dh = opendir($path))) return false; + while (($entry = readdir($dh)) !== false) { + if ($entry != "." && $entry != "..") { + $this->cppath($topath . "/" . $entry, $path . "/" . $entry); + } + } + closedir($dh); + return true; + } + + function rmpath() + { + if (func_num_args() > 0) { + $path = func_get_arg(0); + } else { + $path = $this->path; + } + if (!file_exists($path) && !is_link($path)) { + return true; + } elseif (is_link($path)) { + return unlink($path); + } elseif (!is_dir($path)) { + return unlink($path); + } + if (!($dh = opendir($path))) return false; + while (($entry = readdir($dh)) !== false) { + if ($entry != "." && $entry != "..") { + $this->rmpath($path . "/" . $entry); + } + } + return rmdir($path); + } + + function getpath() + { + if (func_num_args() > 0) { + $path = func_get_arg(0); + } else { + $path = $this->path; + } + if (is_dir($path)) { + $fs = array(array(), array(), array()); + if (!($dh = opendir($path))) return false; + while (($entry = readdir($dh)) !== false) { + if ($entry != "." && $entry != "..") { + if (is_dir($entry = ___realpath($path . "/" . $entry))) { + $fs[0][] = $entry; + } elseif (is_file($entry)) { + $fs[1][] = $entry; + } else { + if ($entry != "") { + $fs[2][] = $entry; + } + } + } + } + closedir($dh); + if ((count($fs, 1) - 3) < 1) return null; + if (count($fs[0]) > 0) usort($fs[0], "___sortcmp"); + if (count($fs[1]) > 0) usort($fs[1], "___sortcmp"); + if (count($fs[2]) > 0) usort($fs[2], "___sortcmp"); + return $fs; + } elseif (file_exists($path)) { + if (!($fs = stat($path))) { + return false; + } else { + return $fs; + } + } else { + return false; + } + } + + function getfinfo() + { + if (!function_exists("finfo_open")) return false; + $finfo = finfo_open(); + if (func_num_args() > 0) { + return finfo_file($finfo, func_get_arg(0)); + } + return finfo_file($finfo, $this->path); + } + + function getperms() + { + if (!function_exists("fileperms")) return false; + if (func_num_args() > 0) { + $path = func_get_arg(0); + if (($perms = fileperms($path)) === false) { + return false; + } else { + return substr(sprintf("%o", $perms), -4); + } + } + if (($perms = fileperms($this->path)) === false) { + return false; + } else { + return substr(sprintf("%o", $perms), -4); + } + } +} + +?> diff --git a/mail.php b/mail.php new file mode 100644 index 0000000..8a889ad --- /dev/null +++ b/mail.php @@ -0,0 +1,51 @@ +\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "\n"; +} elseif (!stripos($_GET['mail'], "@")) { + echo "
\n"; + echo "[返回]抱歉,明显不是邮箱!\n"; + echo "
\n"; +} else { + echo "
\n"; + echo "文件列表(操作结果)\n"; + echo "
\n"; + echo "
\n"; + if (function_exists("pcntl_fork")) { + $pid = pcntl_fork(); + } + if (!isset($pid)) { + if (___sendfile(trim($_GET['mail']), $_SESSION['flist'])) { + echo "系统已经发送邮件!\n"; + } else { + echo "系统无法发送邮件!\n"; + } + } elseif ($pid == -1) { + if (___sendfile(trim($_GET['mail']), $_SESSION['flist'])) { + echo "系统已经发送邮件!\n"; + } else { + echo "系统无法发送邮件\n!"; + } + } else { + if ($pid == 0) { + ___sendfile(trim($_GET['mail']), $_SESSION['flist']); + exit; + } + echo "系统正在投递邮件!\n"; + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/mbconv.php b/mbconv.php new file mode 100644 index 0000000..ed3488b --- /dev/null +++ b/mbconv.php @@ -0,0 +1,46 @@ +\n"; + echo "返回目录转换提示\n"; + echo "\n"; + echo "
\n"; + if (!function_exists("mb_convert_encoding") || !function_exists("mb_list_encodings")) { + echo "核心函数库没有被支持!\n"; + } elseif (!is_readable($path)) { + echo "无法读取输入文件内容!\n"; + } elseif (!isset($_GET['ic']) || !isset($_GET['pc']) || !isset($_GET['save'])) { + echo "编码转换参数没有设置!\n"; + } elseif (($ic = trim($_GET['ic'])) == "" || ($pc = trim($_GET['pc'])) == "" || ($save = trim($_GET['save'])) == "") { + echo "编码转换参数不能为空!\n"; + } elseif ($ic == $pc) { + echo "输入输出编码不能一致!\n"; + } elseif (!in_array($ic, mb_list_encodings()) || !in_array($pc, mb_list_encodings())) { + echo "选择的编码格式不支持!\n"; + } else { + if (!strstr($save, "/") && !strstr($save, "\\")) $save = (dirname($path) . "/" . $save); + if ($save == $path) { + echo "新路径应不同于老路径!\n"; + } elseif (!($data = file_get_contents($path))) { + echo "读取失败或者文件为空!\n"; + } elseif (!file_put_contents($save, mb_convert_encoding($data, $pc, $ic))) { + echo "无权限写入或写入错误!\n"; + file_exists($save) && unlink($save); + } elseif (filesize($save) < 1) { + unlink($save); + echo "无法成功进行编码转换!\n"; + } else { + echo "编码已转换并写入文件!\n"; + } + } + echo "
\n"; + xhtml_footer(); +} +?> diff --git a/move.php b/move.php new file mode 100644 index 0000000..0a27e5a --- /dev/null +++ b/move.php @@ -0,0 +1,37 @@ +\n"; + echo "[返回]抱歉,目标目录非法!\n"; + echo "\n"; +} elseif (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "
\n"; +} else { + $i = 0; + echo "
\n"; + echo "文件列表(操作结果)\n"; + echo "
"; + while ($i < count($_SESSION['flist'])) { + if (rename($_SESSION['flist'][$i], $tmp = ($gopath . "/" . ___basename($_SESSION['flist'][$i])))) { + echo "
[$i][√] - $tmp
\n"; + } else { + echo "
[$i][×] - $tmp
\n"; + } + $i++; + } + unset($_SESSION['flist']); +} +xhtml_footer(); +?> diff --git a/multiple.php b/multiple.php new file mode 100644 index 0000000..ec0be13 --- /dev/null +++ b/multiple.php @@ -0,0 +1,215 @@ + 0) { + if (!isset($_SESSION['flist'])) $_SESSION['flist'] = array(); + $_SESSION['flist'] = array_filter(array_unique(array_merge($_SESSION['flist'], array_map('urldecode', $_POST['flist'])))); + usort($_SESSION['flist'], "___sortcmp"); + } + header("Location: ./flist.php?getcwd=" . urlencode($getcwd)); + exit; +} elseif ($type == "unzipdir") { + if (isset($_SESSION['ffpath'])) if (!is_dir($_SESSION['ffpath'])) { + header("Location: ./unzip.php?path=" . urlencode($_SESSION['ffpath']) . "&unzipdir=" . urlencode($getcwd)); + exit; + } + header("Location: ./404.php"); + exit; +} elseif ($type == "unpackdir") { + if (isset($_SESSION['ffpath'])) if (!is_dir($_SESSION['ffpath'])) { + header("Location: ./file.php?path=" . urlencode($_SESSION['ffpath']) . "&unpackdir=" . urlencode($getcwd)); + exit; + } + header("Location: ./404.php"); + exit; +} elseif ($type == "shell_exec") { + header("Location: ./shell.php?getcwd=" . urlencode($getcwd)); + exit; +} +if (isset($_POST['flist'])) { + if (!is_array($_POST['flist'])) { + $_SESSION['flist'] = array(); + } else { + $_SESSION['flist'] = array_map('urldecode', $_POST['flist']); + } +} elseif (!isset($_SESSION['flist'])) { + $_SESSION['flist'] = array(); +} +switch ($type) { + case "move" : + xhtml_head("批量移动"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "选择路径(目标目录)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + case "copy" : + xhtml_head("批量复制"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "选择路径(目标目录)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + case "pkzip" : + xhtml_head("压缩文件"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + if (($zpath = ___realpath($getcwd)) == "/") { + $zpath = $zpath .= "archive.zip"; + } else { + $zpath = $zpath .= "/archive.zip"; + } + echo "
\n"; + echo "存放目录(归档路径)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + case "chmod" : + xhtml_head("批量改权"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "文件列表(返回浏览)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "递归权限:开启\n"; + echo "关闭\n
\n"; + echo "目录权限:\n"; + echo "
\n文件权限:\n"; + echo "\n"; + echo "
\n\n"; + echo "
\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + case "delete"; + xhtml_head("批量删除"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "[返回]\n"; + echo "此操作不可逆,确认删除?\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + case "sendfile" : + xhtml_head("文件发送"); + if (count($_SESSION['flist']) < 1) { + echo "
\n"; + echo "[返回]抱歉,没有文件列表!\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "返回目录(接收邮箱)\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
文件清单(选择列表)
\n"; + for ($i = 0; $i < count($_SESSION['flist']); $i++) { + echo "
[$i] - {$_SESSION['flist'][$i]}
\n"; + } + } + xhtml_footer(); + break; + default : + header("Location: ./404.php"); + exit; +} +?> diff --git a/pclzip.php b/pclzip.php new file mode 100644 index 0000000..0a63b60 --- /dev/null +++ b/pclzip.php @@ -0,0 +1,2 @@ +zipname = $p_zipname; $this->zip_fd = 0; $this->magic_quotes_status = -1; return; } function create($p_filelist) { $v_result=1; $this->privErrorReset(); $v_options = array(); $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; $v_size = func_num_args(); if ($v_size > 1) { $v_arg_list = func_get_args(); array_shift($v_arg_list); $v_size--; if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_ADD => 'optional', PCLZIP_CB_POST_ADD => 'optional', PCLZIP_OPT_NO_COMPRESSION => 'optional', PCLZIP_OPT_COMMENT => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } } else { $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; if ($v_size == 2) { $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; } else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); return 0; } } } $this->privOptionDefaultThreshold($v_options); $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); if (is_array($p_filelist)) { if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } else { $v_string_list = $p_filelist; } } else if (is_string($p_filelist)) { $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); return 0; } if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { if ($v_string != '') { $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } else { } } } $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' ,PCLZIP_ATT_FILE_MTIME => 'optional' ,PCLZIP_ATT_FILE_CONTENT => 'optional' ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes); if ($v_result != 1) { return 0; } } $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { return 0; } $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { return 0; } return $p_result_list; } function add($p_filelist) { $v_result=1; $this->privErrorReset(); $v_options = array(); $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; $v_size = func_num_args(); if ($v_size > 1) { $v_arg_list = func_get_args(); array_shift($v_arg_list); $v_size--; if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_ADD => 'optional', PCLZIP_CB_POST_ADD => 'optional', PCLZIP_OPT_NO_COMPRESSION => 'optional', PCLZIP_OPT_COMMENT => 'optional', PCLZIP_OPT_ADD_COMMENT => 'optional', PCLZIP_OPT_PREPEND_COMMENT => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } } else { $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; if ($v_size == 2) { $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; } else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); return 0; } } } $this->privOptionDefaultThreshold($v_options); $v_string_list = array(); $v_att_list = array(); $v_filedescr_list = array(); $p_result_list = array(); if (is_array($p_filelist)) { if (isset($p_filelist[0]) && is_array($p_filelist[0])) { $v_att_list = $p_filelist; } else { $v_string_list = $p_filelist; } } else if (is_string($p_filelist)) { $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); return 0; } if (sizeof($v_string_list) != 0) { foreach ($v_string_list as $v_string) { $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; } } $v_supported_attributes = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' ,PCLZIP_ATT_FILE_MTIME => 'optional' ,PCLZIP_ATT_FILE_CONTENT => 'optional' ,PCLZIP_ATT_FILE_COMMENT => 'optional' ); foreach ($v_att_list as $v_entry) { $v_result = $this->privFileDescrParseAtt($v_entry, $v_filedescr_list[], $v_options, $v_supported_attributes); if ($v_result != 1) { return 0; } } $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); if ($v_result != 1) { return 0; } $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); if ($v_result != 1) { return 0; } return $p_result_list; } function listContent() { $v_result=1; $this->privErrorReset(); if (!$this->privCheckFormat()) { return(0); } $p_list = array(); if (($v_result = $this->privList($p_list)) != 1) { unset($p_list); return(0); } return $p_list; } function extract() { $v_result=1; $this->privErrorReset(); if (!$this->privCheckFormat()) { return(0); } $v_options = array(); $v_path = ''; $v_remove_path = ""; $v_remove_all_path = false; $v_size = func_num_args(); $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; if ($v_size > 0) { $v_arg_list = func_get_args(); if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_PATH => 'optional', PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_EXTRACT => 'optional', PCLZIP_CB_POST_EXTRACT => 'optional', PCLZIP_OPT_SET_CHMOD => 'optional', PCLZIP_OPT_BY_NAME => 'optional', PCLZIP_OPT_BY_EREG => 'optional', PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional', PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } if (isset($v_options[PCLZIP_OPT_PATH])) { $v_path = $v_options[PCLZIP_OPT_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { $v_path .= '/'; } $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; } } else { $v_path = $v_arg_list[0]; if ($v_size == 2) { $v_remove_path = $v_arg_list[1]; } else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); return 0; } } } $this->privOptionDefaultThreshold($v_options); $p_list = array(); $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options); if ($v_result < 1) { unset($p_list); return(0); } return $p_list; } function extractByIndex($p_index) { $v_result=1; $this->privErrorReset(); if (!$this->privCheckFormat()) { return(0); } $v_options = array(); $v_path = ''; $v_remove_path = ""; $v_remove_all_path = false; $v_size = func_num_args(); $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; if ($v_size > 1) { $v_arg_list = func_get_args(); array_shift($v_arg_list); $v_size--; if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_PATH => 'optional', PCLZIP_OPT_REMOVE_PATH => 'optional', PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', PCLZIP_OPT_ADD_PATH => 'optional', PCLZIP_CB_PRE_EXTRACT => 'optional', PCLZIP_CB_POST_EXTRACT => 'optional', PCLZIP_OPT_SET_CHMOD => 'optional', PCLZIP_OPT_REPLACE_NEWER => 'optional' ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', PCLZIP_OPT_TEMP_FILE_ON => 'optional', PCLZIP_OPT_TEMP_FILE_OFF => 'optional' )); if ($v_result != 1) { return 0; } if (isset($v_options[PCLZIP_OPT_PATH])) { $v_path = $v_options[PCLZIP_OPT_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; } if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { $v_path .= '/'; } $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; } if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; } else { } } else { $v_path = $v_arg_list[0]; if ($v_size == 2) { $v_remove_path = $v_arg_list[1]; } else if ($v_size > 2) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); return 0; } } } $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); $v_options_trick = array(); $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, array (PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { return 0; } $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; $this->privOptionDefaultThreshold($v_options); if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { return(0); } return $p_list; } function delete() { $v_result=1; $this->privErrorReset(); if (!$this->privCheckFormat()) { return(0); } $v_options = array(); $v_size = func_num_args(); if ($v_size > 0) { $v_arg_list = func_get_args(); $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, array (PCLZIP_OPT_BY_NAME => 'optional', PCLZIP_OPT_BY_EREG => 'optional', PCLZIP_OPT_BY_PREG => 'optional', PCLZIP_OPT_BY_INDEX => 'optional' )); if ($v_result != 1) { return 0; } } $this->privDisableMagicQuotes(); $v_list = array(); if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { $this->privSwapBackMagicQuotes(); unset($v_list); return(0); } $this->privSwapBackMagicQuotes(); return $v_list; } function deleteByIndex($p_index) { $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); return $p_list; } function properties() { $this->privErrorReset(); $this->privDisableMagicQuotes(); if (!$this->privCheckFormat()) { $this->privSwapBackMagicQuotes(); return(0); } $v_prop = array(); $v_prop['comment'] = ''; $v_prop['nb'] = 0; $v_prop['status'] = 'not_exist'; if (@is_file($this->zipname)) { if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); return 0; } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); return 0; } $this->privCloseFd(); $v_prop['comment'] = $v_central_dir['comment']; $v_prop['nb'] = $v_central_dir['entries']; $v_prop['status'] = 'ok'; } $this->privSwapBackMagicQuotes(); return $v_prop; } function duplicate($p_archive) { $v_result = 1; $this->privErrorReset(); if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) { $v_result = $this->privDuplicate($p_archive->zipname); } else if (is_string($p_archive)) { if (!is_file($p_archive)) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); $v_result = PCLZIP_ERR_MISSING_FILE; } else { $v_result = $this->privDuplicate($p_archive); } } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); $v_result = PCLZIP_ERR_INVALID_PARAMETER; } return $v_result; } function merge($p_archive_to_add) { $v_result = 1; $this->privErrorReset(); if (!$this->privCheckFormat()) { return(0); } if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) { $v_result = $this->privMerge($p_archive_to_add); } else if (is_string($p_archive_to_add)) { $v_object_archive = new PclZip($p_archive_to_add); $v_result = $this->privMerge($v_object_archive); } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); $v_result = PCLZIP_ERR_INVALID_PARAMETER; } return $v_result; } function errorCode() { if (PCLZIP_ERROR_EXTERNAL == 1) { return(PclErrorCode()); } else { return($this->error_code); } } function errorName($p_with_code=false) { $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' ); if (isset($v_name[$this->error_code])) { $v_value = $v_name[$this->error_code]; } else { $v_value = 'NoName'; } if ($p_with_code) { return($v_value.' ('.$this->error_code.')'); } else { return($v_value); } } function errorInfo($p_full=false) { if (PCLZIP_ERROR_EXTERNAL == 1) { return(PclErrorString()); } else { if ($p_full) { return($this->errorName(true)." : ".$this->error_string); } else { return($this->error_string." [code ".$this->error_code."]"); } } } function privCheckFormat($p_level=0) { $v_result = true; clearstatcache(); $this->privErrorReset(); if (!is_file($this->zipname)) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); return(false); } if (!is_readable($this->zipname)) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); return(false); } return $v_result; } function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) { $v_result=1; $i=0; while ($i<$p_size) { if (!isset($v_requested_options[$p_options_list[$i]])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); return PclZip::errorCode(); } switch ($p_options_list[$i]) { case PCLZIP_OPT_PATH : case PCLZIP_OPT_REMOVE_PATH : case PCLZIP_OPT_ADD_PATH : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; break; case PCLZIP_OPT_TEMP_FILE_THRESHOLD : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); return PclZip::errorCode(); } $v_value = $p_options_list[$i+1]; if ((!is_integer($v_value)) || ($v_value<0)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = $v_value*1048576; $i++; break; case PCLZIP_OPT_TEMP_FILE_ON : if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = true; break; case PCLZIP_OPT_TEMP_FILE_OFF : if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); return PclZip::errorCode(); } if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = true; break; case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } if ( is_string($p_options_list[$i+1]) && ($p_options_list[$i+1] != '')) { $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); $i++; } else { } break; case PCLZIP_OPT_BY_NAME : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; } else if (is_array($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $i++; break; case PCLZIP_OPT_BY_EREG : $p_options_list[$i] = PCLZIP_OPT_BY_PREG; case PCLZIP_OPT_BY_PREG : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $i++; break; case PCLZIP_OPT_COMMENT : case PCLZIP_OPT_ADD_COMMENT : case PCLZIP_OPT_PREPEND_COMMENT : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '" .PclZipUtilOptionText($p_options_list[$i]) ."'"); return PclZip::errorCode(); } if (is_string($p_options_list[$i+1])) { $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '" .PclZipUtilOptionText($p_options_list[$i]) ."'"); return PclZip::errorCode(); } $i++; break; case PCLZIP_OPT_BY_INDEX : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_work_list = array(); if (is_string($p_options_list[$i+1])) { $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); $v_work_list = explode(",", $p_options_list[$i+1]); } else if (is_integer($p_options_list[$i+1])) { $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; } else if (is_array($p_options_list[$i+1])) { $v_work_list = $p_options_list[$i+1]; } else { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_sort_flag=false; $v_sort_value=0; for ($j=0; $j= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; $i++; break; case PCLZIP_CB_PRE_EXTRACT : case PCLZIP_CB_POST_EXTRACT : case PCLZIP_CB_PRE_ADD : case PCLZIP_CB_POST_ADD : if (($i+1) >= $p_size) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_function_name = $p_options_list[$i+1]; if (!function_exists($v_function_name)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); return PclZip::errorCode(); } $v_result_list[$p_options_list[$i]] = $v_function_name; $i++; break; default : PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '" .$p_options_list[$i]."'"); return PclZip::errorCode(); } $i++; } if ($v_requested_options !== false) { for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { if ($v_requested_options[$key] == 'mandatory') { if (!isset($v_result_list[$key])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); return PclZip::errorCode(); } } } } if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { } return $v_result; } function privOptionDefaultThreshold(&$p_options) { $v_result=1; if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { return $v_result; } $v_memory_limit = ini_get('memory_limit'); $v_memory_limit = trim($v_memory_limit); $last = strtolower(substr($v_memory_limit, -1)); if($last == 'g') $v_memory_limit = $v_memory_limit*1073741824; if($last == 'm') $v_memory_limit = $v_memory_limit*1048576; if($last == 'k') $v_memory_limit = $v_memory_limit*1024; $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); } return $v_result; } function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) { $v_result=1; foreach ($p_file_list as $v_key => $v_value) { if (!isset($v_requested_options[$v_key])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); return PclZip::errorCode(); } switch ($v_key) { case PCLZIP_ATT_FILE_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['filename'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; case PCLZIP_ATT_FILE_NEW_SHORT_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['new_short_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; case PCLZIP_ATT_FILE_NEW_FULL_NAME : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); if ($p_filedescr['new_full_name'] == '') { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } break; case PCLZIP_ATT_FILE_COMMENT : if (!is_string($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['comment'] = $v_value; break; case PCLZIP_ATT_FILE_MTIME : if (!is_integer($v_value)) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); return PclZip::errorCode(); } $p_filedescr['mtime'] = $v_value; break; case PCLZIP_ATT_FILE_CONTENT : $p_filedescr['content'] = $v_value; break; default : PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Unknown parameter '".$v_key."'"); return PclZip::errorCode(); } if ($v_requested_options !== false) { for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { if ($v_requested_options[$key] == 'mandatory') { if (!isset($p_file_list[$key])) { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); return PclZip::errorCode(); } } } } } return $v_result; } function privFileDescrExpand(&$p_filedescr_list, &$p_options) { $v_result=1; $v_result_list = array(); for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options); $v_result_list[sizeof($v_result_list)] = $v_descr; if ($v_descr['type'] == 'folder') { $v_dirlist_descr = array(); $v_dirlist_nb = 0; if ($v_folder_handler = @opendir($v_descr['filename'])) { while (($v_item_handler = @readdir($v_folder_handler)) !== false) { if (($v_item_handler == '.') || ($v_item_handler == '..')) { continue; } $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; if (($v_descr['stored_filename'] != $v_descr['filename']) && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { if ($v_descr['stored_filename'] != '') { $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; } else { $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; } } $v_dirlist_nb++; } @closedir($v_folder_handler); } else { } if ($v_dirlist_nb != 0) { if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { return $v_result; } $v_result_list = array_merge($v_result_list, $v_dirlist_descr); } else { } unset($v_dirlist_descr); } } $p_filedescr_list = $v_result_list; return $v_result; } function privCreate($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); $this->privDisableMagicQuotes(); if (($v_result = $this->privOpenFd('wb')) != 1) { return $v_result; } $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } function privAdd($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) { $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); return $v_result; } $this->privDisableMagicQuotes(); if (($v_result=$this->privOpenFd('rb')) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } @rewind($this->zip_fd); $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } $v_size = $v_central_dir['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; $v_header_list = array(); if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { fclose($v_zip_temp_fd); $this->privCloseFd(); @unlink($v_zip_temp_name); $this->privSwapBackMagicQuotes(); return $v_result; } $v_offset = @ftell($this->zip_fd); $v_size = $v_central_dir['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) { fclose($v_zip_temp_fd); $this->privCloseFd(); @unlink($v_zip_temp_name); $this->privSwapBackMagicQuotes(); return $v_result; } $v_count++; } $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } $v_comment = $v_central_dir['comment']; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; } if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; } $v_size = @ftell($this->zip_fd)-$v_offset; if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) { unset($v_header_list); $this->privSwapBackMagicQuotes(); return $v_result; } $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; $this->privCloseFd(); @fclose($v_zip_temp_fd); $this->privSwapBackMagicQuotes(); @unlink($this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); return $v_result; } function privOpenFd($p_mode) { $v_result=1; if ($this->zip_fd != 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); return PclZip::errorCode(); } if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); return PclZip::errorCode(); } return $v_result; } function privCloseFd() { $v_result=1; if ($this->zip_fd != 0) @fclose($this->zip_fd); $this->zip_fd = 0; return $v_result; } function privAddList($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_header_list = array(); if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) { return $v_result; } $v_offset = @ftell($this->zip_fd); for ($i=0,$v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) { return $v_result; } $v_count++; } $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } $v_comment = ''; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } $v_size = @ftell($this->zip_fd)-$v_offset; if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) { unset($v_header_list); return $v_result; } return $v_result; } function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) { $v_result=1; $v_header = array(); $v_nb = sizeof($p_result_list); for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header, $p_options); if ($v_result != 1) { return $v_result; } $p_result_list[$v_nb++] = $v_header; } } return $v_result; } function privAddFile($p_filedescr, &$p_header, &$p_options) { $v_result=1; $p_filename = $p_filedescr['filename']; if ($p_filename == "") { PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); return PclZip::errorCode(); } clearstatcache(); $p_header['version'] = 20; $p_header['version_extracted'] = 10; $p_header['flag'] = 0; $p_header['compression'] = 0; $p_header['crc'] = 0; $p_header['compressed_size'] = 0; $p_header['filename_len'] = strlen($p_filename); $p_header['extra_len'] = 0; $p_header['disk'] = 0; $p_header['internal'] = 0; $p_header['offset'] = 0; $p_header['filename'] = $p_filename; $p_header['stored_filename'] = $p_filedescr['stored_filename']; $p_header['extra'] = ''; $p_header['status'] = 'ok'; $p_header['index'] = -1; if ($p_filedescr['type']=='file') { $p_header['external'] = 0x00000000; $p_header['size'] = filesize($p_filename); } else if ($p_filedescr['type']=='folder') { $p_header['external'] = 0x00000010; $p_header['mtime'] = filemtime($p_filename); $p_header['size'] = filesize($p_filename); } else if ($p_filedescr['type'] == 'virtual_file') { $p_header['external'] = 0x00000000; $p_header['size'] = strlen($p_filedescr['content']); } if (isset($p_filedescr['mtime'])) { $p_header['mtime'] = $p_filedescr['mtime']; } else if ($p_filedescr['type'] == 'virtual_file') { $p_header['mtime'] = time(); } else { $p_header['mtime'] = filemtime($p_filename); } if (isset($p_filedescr['comment'])) { $p_header['comment_len'] = strlen($p_filedescr['comment']); $p_header['comment'] = $p_filedescr['comment']; } else { $p_header['comment_len'] = 0; $p_header['comment'] = ''; } if (isset($p_options[PCLZIP_CB_PRE_ADD])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_header, $v_local_header); $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); if ($v_result == 0) { $p_header['status'] = "skipped"; $v_result = 1; } if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); } } if ($p_header['stored_filename'] == "") { $p_header['status'] = "filtered"; } if (strlen($p_header['stored_filename']) > 0xFF) { $p_header['status'] = 'filename_too_long'; } if ($p_header['status'] == 'ok') { if ($p_filedescr['type'] == 'file') { if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); if ($v_result < PCLZIP_ERR_NO_ERROR) { return $v_result; } } else { if (($v_file = @fopen($p_filename, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); return PclZip::errorCode(); } $v_content = @fread($v_file, $p_header['size']); @fclose($v_file); $p_header['crc'] = @crc32($v_content); if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { $p_header['compressed_size'] = $p_header['size']; $p_header['compression'] = 0; } else { $v_content = @gzdeflate($v_content); $p_header['compressed_size'] = strlen($v_content); $p_header['compression'] = 8; } if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { @fclose($v_file); return $v_result; } @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); } } else if ($p_filedescr['type'] == 'virtual_file') { $v_content = $p_filedescr['content']; $p_header['crc'] = @crc32($v_content); if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { $p_header['compressed_size'] = $p_header['size']; $p_header['compression'] = 0; } else { $v_content = @gzdeflate($v_content); $p_header['compressed_size'] = strlen($v_content); $p_header['compression'] = 8; } if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { @fclose($v_file); return $v_result; } @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); } else if ($p_filedescr['type'] == 'folder') { if (@substr($p_header['stored_filename'], -1) != '/') { $p_header['stored_filename'] .= '/'; } $p_header['size'] = 0; $p_header['external'] = 0x00000010; if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { return $v_result; } } } if (isset($p_options[PCLZIP_CB_POST_ADD])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_header, $v_local_header); $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); if ($v_result == 0) { $v_result = 1; } } return $v_result; } function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) { $v_result=PCLZIP_ERR_NO_ERROR; $p_filename = $p_filedescr['filename']; if (($v_file = @fopen($p_filename, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); return PclZip::errorCode(); } $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { fclose($v_file); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } $v_size = filesize($p_filename); while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_file, $v_read_size); @gzputs($v_file_compressed, $v_buffer, $v_read_size); $v_size -= $v_read_size; } @fclose($v_file); @gzclose($v_file_compressed); if (filesize($v_gzip_temp_name) < 18) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); return PclZip::errorCode(); } if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } $v_binary_data = @fread($v_file_compressed, 10); $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data); $v_data_header['os'] = bin2hex($v_data_header['os']); @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); $v_binary_data = @fread($v_file_compressed, 8); $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); $p_header['compression'] = ord($v_data_header['cm']); $p_header['crc'] = $v_data_footer['crc']; $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; @fclose($v_file_compressed); if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { return $v_result; } if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } fseek($v_file_compressed, 10); $v_size = $p_header['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($v_file_compressed, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } @fclose($v_file_compressed); @unlink($v_gzip_temp_name); return $v_result; } function privCalculateStoredFilename(&$p_filedescr, &$p_options) { $v_result=1; $p_filename = $p_filedescr['filename']; if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; } else { $p_add_dir = ''; } if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; } else { $p_remove_dir = ''; } if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; } else { $p_remove_all_dir = 0; } if (isset($p_filedescr['new_full_name'])) { $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); } else { if (isset($p_filedescr['new_short_name'])) { $v_path_info = pathinfo($p_filename); $v_dir = ''; if ($v_path_info['dirname'] != '') { $v_dir = $v_path_info['dirname'].'/'; } $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; } else { $v_stored_filename = $p_filename; } if ($p_remove_all_dir) { $v_stored_filename = basename($p_filename); } else if ($p_remove_dir != "") { if (substr($p_remove_dir, -1) != '/') $p_remove_dir .= "/"; if ( (substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./")) { if ( (substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./")) { $p_remove_dir = "./".$p_remove_dir; } if ( (substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./")) { $p_remove_dir = substr($p_remove_dir, 2); } } $v_compare = PclZipUtilPathInclusion($p_remove_dir, $v_stored_filename); if ($v_compare > 0) { if ($v_compare == 2) { $v_stored_filename = ""; } else { $v_stored_filename = substr($v_stored_filename, strlen($p_remove_dir)); } } } $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); if ($p_add_dir != "") { if (substr($p_add_dir, -1) == "/") $v_stored_filename = $p_add_dir.$v_stored_filename; else $v_stored_filename = $p_add_dir."/".$v_stored_filename; } } $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); $p_filedescr['stored_filename'] = $v_stored_filename; return $v_result; } function privWriteFileHeader(&$p_header) { $v_result=1; $p_header['offset'] = ftell($this->zip_fd); $v_date = getdate($p_header['mtime']); $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len']); fputs($this->zip_fd, $v_binary_data, 30); if (strlen($p_header['stored_filename']) != 0) { fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); } if ($p_header['extra_len'] != 0) { fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); } return $v_result; } function privWriteCentralFileHeader(&$p_header) { $v_result=1; $v_date = getdate($p_header['mtime']); $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, $p_header['version'], $p_header['version_extracted'], $p_header['flag'], $p_header['compression'], $v_mtime, $v_mdate, $p_header['crc'], $p_header['compressed_size'], $p_header['size'], strlen($p_header['stored_filename']), $p_header['extra_len'], $p_header['comment_len'], $p_header['disk'], $p_header['internal'], $p_header['external'], $p_header['offset']); fputs($this->zip_fd, $v_binary_data, 46); if (strlen($p_header['stored_filename']) != 0) { fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); } if ($p_header['extra_len'] != 0) { fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); } if ($p_header['comment_len'] != 0) { fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); } return $v_result; } function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) { $v_result=1; $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, $p_nb_entries, $p_size, $p_offset, strlen($p_comment)); fputs($this->zip_fd, $v_binary_data, 22); if (strlen($p_comment) != 0) { fputs($this->zip_fd, $p_comment, strlen($p_comment)); } return $v_result; } function privList(&$p_list) { $v_result=1; $this->privDisableMagicQuotes(); if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); return PclZip::errorCode(); } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_central_dir['offset'])) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); return PclZip::errorCode(); } for ($i=0; $i<$v_central_dir['entries']; $i++) { if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } $v_header['index'] = $i; $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); unset($v_header); } $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } function privConvertHeader2FileInfo($p_header, &$p_info) { $v_result=1; $v_temp_path = PclZipUtilPathReduction($p_header['filename']); $p_info['filename'] = $v_temp_path; $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']); $p_info['stored_filename'] = $v_temp_path; $p_info['size'] = $p_header['size']; $p_info['compressed_size'] = $p_header['compressed_size']; $p_info['mtime'] = $p_header['mtime']; $p_info['comment'] = $p_header['comment']; $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); $p_info['index'] = $p_header['index']; $p_info['status'] = $p_header['status']; $p_info['crc'] = $p_header['crc']; return $v_result; } function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { $v_result=1; $this->privDisableMagicQuotes(); if ( ($p_path == "") || ( (substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path,1,2)!=":/"))) $p_path = "./".$p_path; if (($p_path != "./") && ($p_path != "/")) { while (substr($p_path, -1) == "/") { $p_path = substr($p_path, 0, strlen($p_path)-1); } } if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) { $p_remove_path .= '/'; } $p_remove_path_size = strlen($p_remove_path); if (($v_result = $this->privOpenFd('rb')) != 1) { $this->privSwapBackMagicQuotes(); return $v_result; } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } $v_pos_entry = $v_central_dir['offset']; $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_pos_entry)) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); return PclZip::errorCode(); } $v_header = array(); if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } $v_header['index'] = $i; $v_pos_entry = ftell($this->zip_fd); $v_extract = false; if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_extract = true; } } elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { $v_extract = true; } } } else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { $v_extract = true; } } else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { $v_extract = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { break; } } } else { $v_extract = true; } if ( ($v_extract) && ( ($v_header['compression'] != 8) && ($v_header['compression'] != 0))) { $v_header['status'] = 'unsupported_compression'; if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is " ."compressed by an unsupported compression " ."method (".$v_header['compression'].") "); return PclZip::errorCode(); } } if (($v_extract) && (($v_header['flag'] & 1) == 1)) { $v_header['status'] = 'unsupported_encryption'; if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, "Unsupported encryption for " ." filename '".$v_header['stored_filename'] ."'"); return PclZip::errorCode(); } } if (($v_extract) && ($v_header['status'] != 'ok')) { $v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++]); if ($v_result != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } $v_extract = false; } if ($v_extract) { @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_header['offset'])) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); return PclZip::errorCode(); } if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { $v_string = ''; $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } $p_file_list[$v_nb_extracted]['content'] = $v_string; $v_nb_extracted++; if ($v_result1 == 2) { break; } } elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } if ($v_result1 == 2) { break; } } else { $v_result1 = $this->privExtractFile($v_header, $p_path, $p_remove_path, $p_remove_all_path, $p_options); if ($v_result1 < 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result1; } if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } if ($v_result1 == 2) { break; } } } } $this->privCloseFd(); $this->privSwapBackMagicQuotes(); return $v_result; } function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) { $v_result=1; if (($v_result = $this->privReadFileHeader($v_header)) != 1) { return $v_result; } if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { } if ($p_remove_all_path == true) { if (($p_entry['external']&0x00000010)==0x00000010) { $p_entry['status'] = "filtered"; return $v_result; } $p_entry['filename'] = basename($p_entry['filename']); } else if ($p_remove_path != "") { if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) { $p_entry['status'] = "filtered"; return $v_result; } $p_remove_path_size = strlen($p_remove_path); if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) { $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); } } if ($p_path != '') { $p_entry['filename'] = $p_path."/".$p_entry['filename']; } if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { $v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']); if ($v_inclusion == 0) { PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '".$p_entry['filename']."' is " ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); return PclZip::errorCode(); } } if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { $p_entry['status'] = "skipped"; $v_result = 1; } if ($v_result == 2) { $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } $p_entry['filename'] = $v_local_header['filename']; } if ($p_entry['status'] == 'ok') { if (file_exists($p_entry['filename'])) { if (is_dir($p_entry['filename'])) { $p_entry['status'] = "already_a_directory"; if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '".$p_entry['filename']."' is " ."already used by an existing directory"); return PclZip::errorCode(); } } else if (!is_writeable($p_entry['filename'])) { $p_entry['status'] = "write_protected"; if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '".$p_entry['filename']."' exists " ."and is write protected"); return PclZip::errorCode(); } } else if (filemtime($p_entry['filename']) > $p_entry['mtime']) { if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { } else { $p_entry['status'] = "newer_exist"; if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Newer version of '".$p_entry['filename']."' exists " ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); return PclZip::errorCode(); } } } else { } } else { if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) $v_dir_to_check = $p_entry['filename']; else if (!strstr($p_entry['filename'], "/")) $v_dir_to_check = ""; else $v_dir_to_check = dirname($p_entry['filename']); if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { $p_entry['status'] = "path_creation_fail"; $v_result = 1; } } } if ($p_entry['status'] == 'ok') { if (!(($p_entry['external']&0x00000010)==0x00000010)) { if ($p_entry['compression'] == 0) { if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { $p_entry['status'] = "write_error"; return $v_result; } $v_size = $p_entry['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } fclose($v_dest_file); touch($p_entry['filename'], $p_entry['mtime']); } else { if (($p_entry['flag'] & 1) == 1) { PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); return PclZip::errorCode(); } if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); if ($v_result < PCLZIP_ERR_NO_ERROR) { return $v_result; } } else { $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); $v_file_content = @gzinflate($v_buffer); unset($v_buffer); if ($v_file_content === FALSE) { $p_entry['status'] = "error"; return $v_result; } if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { $p_entry['status'] = "write_error"; return $v_result; } @fwrite($v_dest_file, $v_file_content, $p_entry['size']); unset($v_file_content); @fclose($v_dest_file); } @touch($p_entry['filename'], $p_entry['mtime']); } if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); } } } if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } return $v_result; } function privExtractFileUsingTempFile(&$p_entry, &$p_options) { $v_result=1; $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { fclose($v_file); PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); @fwrite($v_dest_file, $v_binary_data, 10); $v_size = $p_entry['compressed_size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']); @fwrite($v_dest_file, $v_binary_data, 8); @fclose($v_dest_file); if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { $p_entry['status'] = "write_error"; return $v_result; } if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { @fclose($v_dest_file); $p_entry['status'] = "read_error"; PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); return PclZip::errorCode(); } $v_size = $p_entry['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($v_src_file, $v_read_size); @fwrite($v_dest_file, $v_buffer, $v_read_size); $v_size -= $v_read_size; } @fclose($v_dest_file); @gzclose($v_src_file); @unlink($v_gzip_temp_name); return $v_result; } function privExtractFileInOutput(&$p_entry, &$p_options) { $v_result=1; if (($v_result = $this->privReadFileHeader($v_header)) != 1) { return $v_result; } if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { } if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { $p_entry['status'] = "skipped"; $v_result = 1; } if ($v_result == 2) { $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } $p_entry['filename'] = $v_local_header['filename']; } if ($p_entry['status'] == 'ok') { if (!(($p_entry['external']&0x00000010)==0x00000010)) { if ($p_entry['compressed_size'] == $p_entry['size']) { $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); echo $v_buffer; unset($v_buffer); } else { $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); $v_file_content = gzinflate($v_buffer); unset($v_buffer); echo $v_file_content; unset($v_file_content); } } } if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } return $v_result; } function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) { $v_result=1; $v_header = array(); if (($v_result = $this->privReadFileHeader($v_header)) != 1) { return $v_result; } if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { } if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); if ($v_result == 0) { $p_entry['status'] = "skipped"; $v_result = 1; } if ($v_result == 2) { $p_entry['status'] = "aborted"; $v_result = PCLZIP_ERR_USER_ABORTED; } $p_entry['filename'] = $v_local_header['filename']; } if ($p_entry['status'] == 'ok') { if (!(($p_entry['external']&0x00000010)==0x00000010)) { if ($p_entry['compression'] == 0) { $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); } else { $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); if (($p_string = @gzinflate($v_data)) === FALSE) { } } } else { } } if ($p_entry['status'] == "aborted") { $p_entry['status'] = "skipped"; } elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { $v_local_header = array(); $this->privConvertHeader2FileInfo($p_entry, $v_local_header); $v_local_header['content'] = $p_string; $p_string = ''; $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); $p_string = $v_local_header['content']; unset($v_local_header['content']); if ($v_result == 2) { $v_result = PCLZIP_ERR_USER_ABORTED; } } return $v_result; } function privReadFileHeader(&$p_header) { $v_result=1; $v_binary_data = @fread($this->zip_fd, 4); $v_data = unpack('Vid', $v_binary_data); if ($v_data['id'] != 0x04034b50) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); return PclZip::errorCode(); } $v_binary_data = fread($this->zip_fd, 26); if (strlen($v_binary_data) != 26) { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); return PclZip::errorCode(); } $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); if ($v_data['extra_len'] != 0) { $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); } else { $p_header['extra'] = ''; } $p_header['version_extracted'] = $v_data['version']; $p_header['compression'] = $v_data['compression']; $p_header['size'] = $v_data['size']; $p_header['compressed_size'] = $v_data['compressed_size']; $p_header['crc'] = $v_data['crc']; $p_header['flag'] = $v_data['flag']; $p_header['filename_len'] = $v_data['filename_len']; $p_header['mdate'] = $v_data['mdate']; $p_header['mtime'] = $v_data['mtime']; if ($p_header['mdate'] && $p_header['mtime']) { $v_hour = ($p_header['mtime'] & 0xF800) >> 11; $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; $v_seconde = ($p_header['mtime'] & 0x001F)*2; $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; $v_month = ($p_header['mdate'] & 0x01E0) >> 5; $v_day = $p_header['mdate'] & 0x001F; $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); } else { $p_header['mtime'] = time(); } $p_header['stored_filename'] = $p_header['filename']; $p_header['status'] = "ok"; return $v_result; } function privReadCentralFileHeader(&$p_header) { $v_result=1; $v_binary_data = @fread($this->zip_fd, 4); $v_data = unpack('Vid', $v_binary_data); if ($v_data['id'] != 0x02014b50) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); return PclZip::errorCode(); } $v_binary_data = fread($this->zip_fd, 42); if (strlen($v_binary_data) != 42) { $p_header['filename'] = ""; $p_header['status'] = "invalid_header"; PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); return PclZip::errorCode(); } $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); if ($p_header['filename_len'] != 0) $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); else $p_header['filename'] = ''; if ($p_header['extra_len'] != 0) $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); else $p_header['extra'] = ''; if ($p_header['comment_len'] != 0) $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); else $p_header['comment'] = ''; if (1) { $v_hour = ($p_header['mtime'] & 0xF800) >> 11; $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; $v_seconde = ($p_header['mtime'] & 0x001F)*2; $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; $v_month = ($p_header['mdate'] & 0x01E0) >> 5; $v_day = $p_header['mdate'] & 0x001F; $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); } else { $p_header['mtime'] = time(); } $p_header['stored_filename'] = $p_header['filename']; $p_header['status'] = 'ok'; if (substr($p_header['filename'], -1) == '/') { $p_header['external'] = 0x00000010; } return $v_result; } function privCheckFileHeaders(&$p_local_header, &$p_central_header) { $v_result=1; if ($p_local_header['filename'] != $p_central_header['filename']) { } if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { } if ($p_local_header['flag'] != $p_central_header['flag']) { } if ($p_local_header['compression'] != $p_central_header['compression']) { } if ($p_local_header['mtime'] != $p_central_header['mtime']) { } if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { } if (($p_local_header['flag'] & 8) == 8) { $p_local_header['size'] = $p_central_header['size']; $p_local_header['compressed_size'] = $p_central_header['compressed_size']; $p_local_header['crc'] = $p_central_header['crc']; } return $v_result; } function privReadEndCentralDir(&$p_central_dir) { $v_result=1; $v_size = filesize($this->zipname); @fseek($this->zip_fd, $v_size); if (@ftell($this->zip_fd) != $v_size) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); return PclZip::errorCode(); } $v_found = 0; if ($v_size > 26) { @fseek($this->zip_fd, $v_size-22); if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); return PclZip::errorCode(); } $v_binary_data = @fread($this->zip_fd, 4); $v_data = @unpack('Vid', $v_binary_data); if ($v_data['id'] == 0x06054b50) { $v_found = 1; } $v_pos = ftell($this->zip_fd); } if (!$v_found) { $v_maximum_size = 65557; if ($v_maximum_size > $v_size) $v_maximum_size = $v_size; @fseek($this->zip_fd, $v_size-$v_maximum_size); if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); return PclZip::errorCode(); } $v_pos = ftell($this->zip_fd); $v_bytes = 0x00000000; while ($v_pos < $v_size) { $v_byte = @fread($this->zip_fd, 1); $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); if ($v_bytes == 0x504b0506) { $v_pos++; break; } $v_pos++; } if ($v_pos == $v_size) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); return PclZip::errorCode(); } } $v_binary_data = fread($this->zip_fd, 18); if (strlen($v_binary_data) != 18) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); return PclZip::errorCode(); } $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { if (0) { PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'The central dir is not at the end of the archive.' .' Some trailing bytes exists after the archive.'); return PclZip::errorCode(); } } if ($v_data['comment_size'] != 0) { $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); } else $p_central_dir['comment'] = ''; $p_central_dir['entries'] = $v_data['entries']; $p_central_dir['disk_entries'] = $v_data['disk_entries']; $p_central_dir['offset'] = $v_data['offset']; $p_central_dir['size'] = $v_data['size']; $p_central_dir['disk'] = $v_data['disk']; $p_central_dir['disk_start'] = $v_data['disk_start']; return $v_result; } function privDeleteByRule(&$p_result_list, &$p_options) { $v_result=1; $v_list_detail = array(); if (($v_result=$this->privOpenFd('rb')) != 1) { return $v_result; } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); return $v_result; } @rewind($this->zip_fd); $v_pos_entry = $v_central_dir['offset']; @rewind($this->zip_fd); if (@fseek($this->zip_fd, $v_pos_entry)) { $this->privCloseFd(); PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); return PclZip::errorCode(); } $v_header_list = array(); $j_start = 0; for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) { $v_header_list[$v_nb_extracted] = array(); if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) { $this->privCloseFd(); return $v_result; } $v_header_list[$v_nb_extracted]['index'] = $i; $v_found = false; if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; } elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; } } elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { $v_found = true; } } } else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { $v_found = true; } } else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { $v_found = true; } if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { $j_start = $j+1; } if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { break; } } } else { $v_found = true; } if ($v_found) { unset($v_header_list[$v_nb_extracted]); } else { $v_nb_extracted++; } } if ($v_nb_extracted > 0) { $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; $v_temp_zip = new PclZip($v_zip_temp_name); if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { $this->privCloseFd(); return $v_result; } for ($i=0; $izip_fd); if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); return PclZip::errorCode(); } $v_local_header = array(); if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); return $v_result; } if ($this->privCheckFileHeaders($v_local_header, $v_header_list[$i]) != 1) { } unset($v_local_header); if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); return $v_result; } if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { $this->privCloseFd(); $v_temp_zip->privCloseFd(); @unlink($v_zip_temp_name); return $v_result; } } $v_offset = @ftell($v_temp_zip->zip_fd); for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) { $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($v_zip_temp_name); return $v_result; } $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); } $v_comment = ''; if (isset($p_options[PCLZIP_OPT_COMMENT])) { $v_comment = $p_options[PCLZIP_OPT_COMMENT]; } $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { unset($v_header_list); $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($v_zip_temp_name); return $v_result; } $v_temp_zip->privCloseFd(); $this->privCloseFd(); @unlink($this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); unset($v_temp_zip); } else if ($v_central_dir['entries'] != 0) { $this->privCloseFd(); if (($v_result = $this->privOpenFd('wb')) != 1) { return $v_result; } if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { return $v_result; } $this->privCloseFd(); } return $v_result; } function privDirCheck($p_dir, $p_is_dir=false) { $v_result = 1; if (($p_is_dir) && (substr($p_dir, -1)=='/')) { $p_dir = substr($p_dir, 0, strlen($p_dir)-1); } if ((is_dir($p_dir)) || ($p_dir == "")) { return 1; } $p_parent_dir = dirname($p_dir); if ($p_parent_dir != $p_dir) { if ($p_parent_dir != "") { if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) { return $v_result; } } } if (!@mkdir($p_dir, 0777)) { PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); return PclZip::errorCode(); } return $v_result; } function privMerge(&$p_archive_to_add) { $v_result=1; if (!is_file($p_archive_to_add->zipname)) { $v_result = 1; return $v_result; } if (!is_file($this->zipname)) { $v_result = $this->privDuplicate($p_archive_to_add->zipname); return $v_result; } if (($v_result=$this->privOpenFd('rb')) != 1) { return $v_result; } $v_central_dir = array(); if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) { $this->privCloseFd(); return $v_result; } @rewind($this->zip_fd); if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) { $this->privCloseFd(); return $v_result; } $v_central_dir_to_add = array(); if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); return $v_result; } @rewind($p_archive_to_add->zip_fd); $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); return PclZip::errorCode(); } $v_size = $v_central_dir['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_size = $v_central_dir_to_add['offset']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_offset = @ftell($v_zip_temp_fd); $v_size = $v_central_dir['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($this->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_size = $v_central_dir_to_add['size']; while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; $v_size = @ftell($v_zip_temp_fd)-$v_offset; $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) { $this->privCloseFd(); $p_archive_to_add->privCloseFd(); @fclose($v_zip_temp_fd); $this->zip_fd = null; unset($v_header_list); return $v_result; } $v_swap = $this->zip_fd; $this->zip_fd = $v_zip_temp_fd; $v_zip_temp_fd = $v_swap; $this->privCloseFd(); $p_archive_to_add->privCloseFd(); @fclose($v_zip_temp_fd); @unlink($this->zipname); PclZipUtilRename($v_zip_temp_name, $this->zipname); return $v_result; } function privDuplicate($p_archive_filename) { $v_result=1; if (!is_file($p_archive_filename)) { $v_result = 1; return $v_result; } if (($v_result=$this->privOpenFd('wb')) != 1) { return $v_result; } if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) { $this->privCloseFd(); PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); return PclZip::errorCode(); } $v_size = filesize($p_archive_filename); while ($v_size != 0) { $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = fread($v_zip_temp_fd, $v_read_size); @fwrite($this->zip_fd, $v_buffer, $v_read_size); $v_size -= $v_read_size; } $this->privCloseFd(); @fclose($v_zip_temp_fd); return $v_result; } function privErrorLog($p_error_code=0, $p_error_string='') { if (PCLZIP_ERROR_EXTERNAL == 1) { PclError($p_error_code, $p_error_string); } else { $this->error_code = $p_error_code; $this->error_string = $p_error_string; } } function privErrorReset() { if (PCLZIP_ERROR_EXTERNAL == 1) { PclErrorReset(); } else { $this->error_code = 0; $this->error_string = ''; } } function privDisableMagicQuotes() { $v_result=1; if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { return $v_result; } if ($this->magic_quotes_status != -1) { return $v_result; } $this->magic_quotes_status = @get_magic_quotes_runtime(); if ($this->magic_quotes_status == 1) { @set_magic_quotes_runtime(0); } return $v_result; } function privSwapBackMagicQuotes() { $v_result=1; if ( (!function_exists("get_magic_quotes_runtime")) || (!function_exists("set_magic_quotes_runtime"))) { return $v_result; } if ($this->magic_quotes_status != -1) { return $v_result; } if ($this->magic_quotes_status == 1) { @set_magic_quotes_runtime($this->magic_quotes_status); } return $v_result; } } function PclZipUtilPathReduction($p_dir) { $v_result = ""; if ($p_dir != "") { $v_list = explode("/", $p_dir); $v_skip = 0; for ($i=sizeof($v_list)-1; $i>=0; $i--) { if ($v_list[$i] == ".") { } else if ($v_list[$i] == "..") { $v_skip++; } else if ($v_list[$i] == "") { if ($i == 0) { $v_result = "/".$v_result; if ($v_skip > 0) { $v_result = $p_dir; $v_skip = 0; } } else if ($i == (sizeof($v_list)-1)) { $v_result = $v_list[$i]; } else { } } else { if ($v_skip > 0) { $v_skip--; } else { $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); } } } if ($v_skip > 0) { while ($v_skip > 0) { $v_result = '../'.$v_result; $v_skip--; } } } return $v_result; } function PclZipUtilPathInclusion($p_dir, $p_path) { $v_result = 1; if ( ($p_dir == '.') || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); } if ( ($p_path == '.') || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); } $v_list_dir = explode("/", $p_dir); $v_list_dir_size = sizeof($v_list_dir); $v_list_path = explode("/", $p_path); $v_list_path_size = sizeof($v_list_path); $i = 0; $j = 0; while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { if ($v_list_dir[$i] == '') { $i++; continue; } if ($v_list_path[$j] == '') { $j++; continue; } if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { $v_result = 0; } $i++; $j++; } if ($v_result) { while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { $v_result = 2; } else if ($i < $v_list_dir_size) { $v_result = 0; } } return $v_result; } function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) { $v_result = 1; if ($p_mode==0) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==1) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($p_src, $v_read_size); @fwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==2) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @fread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } else if ($p_mode==3) { while ($p_size != 0) { $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); $v_buffer = @gzread($p_src, $v_read_size); @gzwrite($p_dest, $v_buffer, $v_read_size); $p_size -= $v_read_size; } } return $v_result; } function PclZipUtilRename($p_src, $p_dest) { $v_result = 1; if (!@rename($p_src, $p_dest)) { if (!@copy($p_src, $p_dest)) { $v_result = 0; } else if (!@unlink($p_src)) { $v_result = 0; } } return $v_result; } function PclZipUtilOptionText($p_option) { $v_list = get_defined_constants(); for (reset($v_list); $v_key = key($v_list); next($v_list)) { $v_prefix = substr($v_key, 0, 10); if (( ($v_prefix == 'PCLZIP_OPT') || ($v_prefix == 'PCLZIP_CB_') || ($v_prefix == 'PCLZIP_ATT')) && ($v_list[$v_key] == $p_option)) { return $v_key; } } $v_result = 'Unknown'; return $v_result; } function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) { if (stristr(php_uname(), 'windows')) { if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { $p_path = substr($p_path, $v_position+1); } if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { $p_path = strtr($p_path, '\\', '/'); } } return $p_path; } ?> diff --git a/perms.php b/perms.php new file mode 100644 index 0000000..6d38ff1 --- /dev/null +++ b/perms.php @@ -0,0 +1,198 @@ + 0000, "0100" => 0100, "0010" => 0010, + "0001" => 0001, "0200" => 0200, "0020" => 0020, + "0002" => 0002, "0300" => 0300, "0030" => 0030, + "0003" => 0003, "0400" => 0400, "0040" => 0040, + "0004" => 0004, "0500" => 0500, "0050" => 0050, + "0005" => 0005, "0600" => 0600, "0060" => 0060, + "0006" => 0006, "0700" => 0700, "0070" => 0070, + "0007" => 0007, "0100" => 0100, "0010" => 0010, + "0110" => 0110, "0011" => 0011, "0120" => 0120, + "0012" => 0012, "0130" => 0130, "0013" => 0013, + "0140" => 0140, "0014" => 0014, "0150" => 0150, + "0015" => 0015, "0160" => 0160, "0016" => 0016, + "0170" => 0170, "0017" => 0017, "0200" => 0200, + "0020" => 0020, "0210" => 0210, "0021" => 0021, + "0220" => 0220, "0022" => 0022, "0230" => 0230, + "0023" => 0023, "0240" => 0240, "0024" => 0024, + "0250" => 0250, "0025" => 0025, "0260" => 0260, + "0026" => 0026, "0270" => 0270, "0027" => 0027, + "0300" => 0300, "0030" => 0030, "0310" => 0310, + "0031" => 0031, "0320" => 0320, "0032" => 0032, + "0330" => 0330, "0033" => 0033, "0340" => 0340, + "0034" => 0034, "0350" => 0350, "0035" => 0035, + "0360" => 0360, "0036" => 0036, "0370" => 0370, + "0037" => 0037, "0400" => 0400, "0040" => 0040, + "0410" => 0410, "0041" => 0041, "0420" => 0420, + "0042" => 0042, "0430" => 0430, "0043" => 0043, + "0440" => 0440, "0044" => 0044, "0450" => 0450, + "0045" => 0045, "0460" => 0460, "0046" => 0046, + "0470" => 0470, "0047" => 0047, "0500" => 0500, + "0050" => 0050, "0510" => 0510, "0051" => 0051, + "0520" => 0520, "0052" => 0052, "0530" => 0530, + "0053" => 0053, "0540" => 0540, "0054" => 0054, + "0550" => 0550, "0055" => 0055, "0560" => 0560, + "0056" => 0056, "0570" => 0570, "0057" => 0057, + "0600" => 0600, "0060" => 0060, "0610" => 0610, + "0061" => 0061, "0620" => 0620, "0062" => 0062, + "0630" => 0630, "0063" => 0063, "0640" => 0640, + "0064" => 0064, "0650" => 0650, "0065" => 0065, + "0660" => 0660, "0066" => 0066, "0670" => 0670, + "0067" => 0067, "0700" => 0700, "0070" => 0070, + "0710" => 0710, "0071" => 0071, "0720" => 0720, + "0072" => 0072, "0730" => 0730, "0073" => 0073, + "0740" => 0740, "0074" => 0074, "0750" => 0750, + "0075" => 0075, "0760" => 0760, "0076" => 0076, + "0770" => 0770, "0077" => 0077, "0100" => 0100, + "0101" => 0101, "0102" => 0102, "0103" => 0103, + "0104" => 0104, "0105" => 0105, "0106" => 0106, + "0107" => 0107, "0110" => 0110, "0111" => 0111, + "0112" => 0112, "0113" => 0113, "0114" => 0114, + "0115" => 0115, "0116" => 0116, "0117" => 0117, + "0120" => 0120, "0121" => 0121, "0122" => 0122, + "0123" => 0123, "0124" => 0124, "0125" => 0125, + "0126" => 0126, "0127" => 0127, "0130" => 0130, + "0131" => 0131, "0132" => 0132, "0133" => 0133, + "0134" => 0134, "0135" => 0135, "0136" => 0136, + "0137" => 0137, "0140" => 0140, "0141" => 0141, + "0142" => 0142, "0143" => 0143, "0144" => 0144, + "0145" => 0145, "0146" => 0146, "0147" => 0147, + "0150" => 0150, "0151" => 0151, "0152" => 0152, + "0153" => 0153, "0154" => 0154, "0155" => 0155, + "0156" => 0156, "0157" => 0157, "0160" => 0160, + "0161" => 0161, "0162" => 0162, "0163" => 0163, + "0164" => 0164, "0165" => 0165, "0166" => 0166, + "0167" => 0167, "0170" => 0170, "0171" => 0171, + "0172" => 0172, "0173" => 0173, "0174" => 0174, + "0175" => 0175, "0176" => 0176, "0177" => 0177, + "0200" => 0200, "0201" => 0201, "0202" => 0202, + "0203" => 0203, "0204" => 0204, "0205" => 0205, + "0206" => 0206, "0207" => 0207, "0210" => 0210, + "0211" => 0211, "0212" => 0212, "0213" => 0213, + "0214" => 0214, "0215" => 0215, "0216" => 0216, + "0217" => 0217, "0220" => 0220, "0221" => 0221, + "0222" => 0222, "0223" => 0223, "0224" => 0224, + "0225" => 0225, "0226" => 0226, "0227" => 0227, + "0230" => 0230, "0231" => 0231, "0232" => 0232, + "0233" => 0233, "0234" => 0234, "0235" => 0235, + "0236" => 0236, "0237" => 0237, "0240" => 0240, + "0241" => 0241, "0242" => 0242, "0243" => 0243, + "0244" => 0244, "0245" => 0245, "0246" => 0246, + "0247" => 0247, "0250" => 0250, "0251" => 0251, + "0252" => 0252, "0253" => 0253, "0254" => 0254, + "0255" => 0255, "0256" => 0256, "0257" => 0257, + "0260" => 0260, "0261" => 0261, "0262" => 0262, + "0263" => 0263, "0264" => 0264, "0265" => 0265, + "0266" => 0266, "0267" => 0267, "0270" => 0270, + "0271" => 0271, "0272" => 0272, "0273" => 0273, + "0274" => 0274, "0275" => 0275, "0276" => 0276, + "0277" => 0277, "0300" => 0300, "0301" => 0301, + "0302" => 0302, "0303" => 0303, "0304" => 0304, + "0305" => 0305, "0306" => 0306, "0307" => 0307, + "0310" => 0310, "0311" => 0311, "0312" => 0312, + "0313" => 0313, "0314" => 0314, "0315" => 0315, + "0316" => 0316, "0317" => 0317, "0320" => 0320, + "0321" => 0321, "0322" => 0322, "0323" => 0323, + "0324" => 0324, "0325" => 0325, "0326" => 0326, + "0327" => 0327, "0330" => 0330, "0331" => 0331, + "0332" => 0332, "0333" => 0333, "0334" => 0334, + "0335" => 0335, "0336" => 0336, "0337" => 0337, + "0340" => 0340, "0341" => 0341, "0342" => 0342, + "0343" => 0343, "0344" => 0344, "0345" => 0345, + "0346" => 0346, "0347" => 0347, "0350" => 0350, + "0351" => 0351, "0352" => 0352, "0353" => 0353, + "0354" => 0354, "0355" => 0355, "0356" => 0356, + "0357" => 0357, "0360" => 0360, "0361" => 0361, + "0362" => 0362, "0363" => 0363, "0364" => 0364, + "0365" => 0365, "0366" => 0366, "0367" => 0367, + "0370" => 0370, "0371" => 0371, "0372" => 0372, + "0373" => 0373, "0374" => 0374, "0375" => 0375, + "0376" => 0376, "0377" => 0377, "0400" => 0400, + "0401" => 0401, "0402" => 0402, "0403" => 0403, + "0404" => 0404, "0405" => 0405, "0406" => 0406, + "0407" => 0407, "0410" => 0410, "0411" => 0411, + "0412" => 0412, "0413" => 0413, "0414" => 0414, + "0415" => 0415, "0416" => 0416, "0417" => 0417, + "0420" => 0420, "0421" => 0421, "0422" => 0422, + "0423" => 0423, "0424" => 0424, "0425" => 0425, + "0426" => 0426, "0427" => 0427, "0430" => 0430, + "0431" => 0431, "0432" => 0432, "0433" => 0433, + "0434" => 0434, "0435" => 0435, "0436" => 0436, + "0437" => 0437, "0440" => 0440, "0441" => 0441, + "0442" => 0442, "0443" => 0443, "0444" => 0444, + "0445" => 0445, "0446" => 0446, "0447" => 0447, + "0450" => 0450, "0451" => 0451, "0452" => 0452, + "0453" => 0453, "0454" => 0454, "0455" => 0455, + "0456" => 0456, "0457" => 0457, "0460" => 0460, + "0461" => 0461, "0462" => 0462, "0463" => 0463, + "0464" => 0464, "0465" => 0465, "0466" => 0466, + "0467" => 0467, "0470" => 0470, "0471" => 0471, + "0472" => 0472, "0473" => 0473, "0474" => 0474, + "0475" => 0475, "0476" => 0476, "0477" => 0477, + "0500" => 0500, "0501" => 0501, "0502" => 0502, + "0503" => 0503, "0504" => 0504, "0505" => 0505, + "0506" => 0506, "0507" => 0507, "0510" => 0510, + "0511" => 0511, "0512" => 0512, "0513" => 0513, + "0514" => 0514, "0515" => 0515, "0516" => 0516, + "0517" => 0517, "0520" => 0520, "0521" => 0521, + "0522" => 0522, "0523" => 0523, "0524" => 0524, + "0525" => 0525, "0526" => 0526, "0527" => 0527, + "0530" => 0530, "0531" => 0531, "0532" => 0532, + "0533" => 0533, "0534" => 0534, "0535" => 0535, + "0536" => 0536, "0537" => 0537, "0540" => 0540, + "0541" => 0541, "0542" => 0542, "0543" => 0543, + "0544" => 0544, "0545" => 0545, "0546" => 0546, + "0547" => 0547, "0550" => 0550, "0551" => 0551, + "0552" => 0552, "0553" => 0553, "0554" => 0554, + "0555" => 0555, "0556" => 0556, "0557" => 0557, + "0560" => 0560, "0561" => 0561, "0562" => 0562, + "0563" => 0563, "0564" => 0564, "0565" => 0565, + "0566" => 0566, "0567" => 0567, "0570" => 0570, + "0571" => 0571, "0572" => 0572, "0573" => 0573, + "0574" => 0574, "0575" => 0575, "0576" => 0576, + "0577" => 0577, "0600" => 0600, "0601" => 0601, + "0602" => 0602, "0603" => 0603, "0604" => 0604, + "0605" => 0605, "0606" => 0606, "0607" => 0607, + "0610" => 0610, "0611" => 0611, "0612" => 0612, + "0613" => 0613, "0614" => 0614, "0615" => 0615, + "0616" => 0616, "0617" => 0617, "0620" => 0620, + "0621" => 0621, "0622" => 0622, "0623" => 0623, + "0624" => 0624, "0625" => 0625, "0626" => 0626, + "0627" => 0627, "0630" => 0630, "0631" => 0631, + "0632" => 0632, "0633" => 0633, "0634" => 0634, + "0635" => 0635, "0636" => 0636, "0637" => 0637, + "0640" => 0640, "0641" => 0641, "0642" => 0642, + "0643" => 0643, "0644" => 0644, "0645" => 0645, + "0646" => 0646, "0647" => 0647, "0650" => 0650, + "0651" => 0651, "0652" => 0652, "0653" => 0653, + "0654" => 0654, "0655" => 0655, "0656" => 0656, + "0657" => 0657, "0660" => 0660, "0661" => 0661, + "0662" => 0662, "0663" => 0663, "0664" => 0664, + "0665" => 0665, "0666" => 0666, "0667" => 0667, + "0670" => 0670, "0671" => 0671, "0672" => 0672, + "0673" => 0673, "0674" => 0674, "0675" => 0675, + "0676" => 0676, "0677" => 0677, "0700" => 0700, + "0701" => 0701, "0702" => 0702, "0703" => 0703, + "0704" => 0704, "0705" => 0705, "0706" => 0706, + "0707" => 0707, "0710" => 0710, "0711" => 0711, + "0712" => 0712, "0713" => 0713, "0714" => 0714, + "0715" => 0715, "0716" => 0716, "0717" => 0717, + "0720" => 0720, "0721" => 0721, "0722" => 0722, + "0723" => 0723, "0724" => 0724, "0725" => 0725, + "0726" => 0726, "0727" => 0727, "0730" => 0730, + "0731" => 0731, "0732" => 0732, "0733" => 0733, + "0734" => 0734, "0735" => 0735, "0736" => 0736, + "0737" => 0737, "0740" => 0740, "0741" => 0741, + "0742" => 0742, "0743" => 0743, "0744" => 0744, + "0745" => 0745, "0746" => 0746, "0747" => 0747, + "0750" => 0750, "0751" => 0751, "0752" => 0752, + "0753" => 0753, "0754" => 0754, "0755" => 0755, + "0756" => 0756, "0757" => 0757, "0760" => 0760, + "0761" => 0761, "0762" => 0762, "0763" => 0763, + "0764" => 0764, "0765" => 0765, "0766" => 0766, + "0767" => 0767, "0770" => 0770, "0771" => 0771, + "0772" => 0772, "0773" => 0773, "0774" => 0774, + "0775" => 0775, "0776" => 0776, "0777" => 0777 +); +?> diff --git a/pkzip.php b/pkzip.php new file mode 100644 index 0000000..26f1752 --- /dev/null +++ b/pkzip.php @@ -0,0 +1,28 @@ +\n"; + echo "[返回]抱歉,文件清单为空!\n"; + echo "\n"; +} else { + require "pclzip.php"; + $pkzip = new pclzip($gopath = trim($_GET['gopath'])); + echo "[目录]\n"; + if ($pkzip->create($_SESSION['flist'], PCLZIP_OPT_REMOVE_PATH, dirname($gopath))) { + echo "文件 " . ___basename($gopath) . " 创建成功!"; + } else { + echo "文件 " . ___basename($gopath) . " 无法建立!"; + } +} +xhtml_footer(); +?> diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..3168538 --- /dev/null +++ b/readme.txt @@ -0,0 +1,73 @@ +---------------- +爱特网站文件专家 +---------------- +01.文件批量压缩功能 +02.批量网址获取文件 +03.文件批量上传功能 +04.强大权限设置支持 +05.批量文件删除功能 +06.批量文件复制支持 +07.批量文件移动支持 +08.批量建立目录文件 +09.高级终端命令执行 +10.批量文件传至邮箱 +11.实用文件清单支持 +12.自定编码查看文件 +13.自定编码编辑文件 +14.目录与文件的命名 +15.创建文件复件支持 +16.目录位置允许跳转 +17.文件效验Md5,Sha1 +18.硬盘使用情况查看 +19.任意文件下载支持 +20.牛逼强大解压支持 +21.文件编码转换工具 +22.下载文件断点续传 +---------------- +->>目前支持压缩类型 +Gz,Bz2,Zip +->>目前支持解压类型 +Gz,Bz2,Tar,Tgz,Tbz,Zip +---------------- +->>爱特文件专家安装 +环境:PHP5+ SESSION +首次使用提示创建帐号密码 +修改密码直接编辑admin.php +在Linux操作系统中将更好用 +不选择任何文件则使用清单文件 +选择文件并操作会清空文件清单 +编辑文件如不选择编码将用UTF-8 +->>爱特文件专家技巧 +文件列表添加Ftp://可以操作Ftp文件 +使用远程上传输入Url地址即可导入文件 +用清单功能批量操作不同目录文件,如压缩 +命名功能如果输入绝对路径还可以当移动使 +有时操作重要文件怕出错,文件复件让你安心 +谦容各种浏览器,甚至Elinks也能完美的使用 +更多技巧等你使用,欢迎Bug的反馈与交流讨论 +---------------- +-->爱特文件专家作者 +官方网站:aite.me +官方网站:aite.xyz +腾讯扣群:38181604 +腾讯扣扣:88966001 +腾讯扣扣:759234755 +电子邮箱:admin@aite.xyz +电子邮箱:xiaoqidun@gmail.com +组件下载:http://aite.me/7zrar.zip +官方更新:http://aite.me/fileadmin.zip +---------------- +-->爱特文件专家版权 +爱特文件专家使用了Pclzip和Archive_Tar +http://www.phpconcept.net/pclzip +http://pear.php.net/package/Archive_Tar +爱特文件专家除此库之外均为原创编码 +---------------- +如果解压选项中出现了rar和7za二个选项且是linux系统 +你可能需要安装爱特文件专家的unrar和p7zip组件才能用 +unrar和p7zip(x64\x86\arm)http://aite.me/7zrar.zip +借助这二个强大的组件你可以用爱特文件管理器解压任意格式压缩包 +可以用文件管理器的远程下载直接导入unrar和p7zip组件包,然后在线解压 +解压后有x64\x86\arm三个目录,一般空间用x86,一般安卓手机环境用arm组件 +进入对应的组件目录,将p7zip.bin和unrar.bin文件移动到文件管理器目录即可 +然后文件管理器的rar和7za解压选项就可以用了,当然也可以解压带密码压缩包 diff --git a/rename.php b/rename.php new file mode 100644 index 0000000..e2154ea --- /dev/null +++ b/rename.php @@ -0,0 +1,31 @@ +\n返回目录\n新的命名\n"; +echo "
\n"; +echo "
\n"; +echo "\n"; +echo "\n"; +echo "\n"; +echo "
\n"; +echo "
\n"; +xhtml_footer(); +?> diff --git a/shell.php b/shell.php new file mode 100644 index 0000000..c154096 --- /dev/null +++ b/shell.php @@ -0,0 +1,69 @@ +\n"; + echo "返回目录错误提示\n"; + echo "\n"; + echo "
\n"; + echo "您没有打开SHELL权限!"; + echo "
\n"; + xhtml_footer(); + exit; +} +chdir($getcwd); +xhtml_head("SHELL"); +echo "
\n"; +echo "返回目录SHELL\n"; +echo "
\n"; +echo "
\n"; +echo "
\n"; +echo "\n"; +echo "\n
\n"; +echo "\n
\n"; +echo "
\n"; +echo "
\n"; +if (isset($_POST['shell'])) if (($s = trim($_POST['shell'])) != "") { + echo "
\n结果返回SHELL\n
\n"; + echo "
\n"; + if (function_exists("proc_open") && function_exists("stream_get_contents") && php_uname("s") == "Linux") { + if (!($sh = proc_open("sh", array(0 => array("pipe", "r"), 1 => array("pipe", "w")), $pipes))) { + echo "Open Shell Error !"; + } else { + $i = 0; + $shell = explode("\n", $s); + while ($i < count($shell)) { + $x = trim($shell[$i]); + fwrite($pipes[0], "$x\n"); + $i++; + } + fclose($pipes[0]); + $stream = stream_get_contents($pipes[1]); + if ($stream != "") { + echo "
" . nl2br(___codepre(trim($stream))) . "
"; + } else { + echo "NULL"; + } + fclose($pipes[1]); + proc_close($sh); + } + } else { + $i = 0; + $shell = explode("\n", $s); + while ($i < count($shell)) { + $sh = trim($shell[$i]); + echo "shell# $sh
\n"; + echo nl2br(___codepre(shell_exec($sh))) . "\n"; + $i++; + } + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/style.css b/style.css new file mode 100644 index 0000000..092b4a3 --- /dev/null +++ b/style.css @@ -0,0 +1,53 @@ +.like { + padding: 3px; + color: #000000; + font-size: 18px; + background-color: #00BFFF; + border-bottom: 3px solid #1E90FF; +} + +.love { + padding: 2px; + color: #000000; + word-wrap: break-word; + border-left: 1px solid #B0E0B6; + border-right: 1px solid #B0E0B6; + border-bottom: 1px dotted #6495ED; +} + +.error { + color: red; + padding: 2px; + word-wrap: break-word; + border: 1px solid red; +} + +#header { + padding: 4px; + color: #000000; + font-size: 18px; + background-color: #3CB369; + border-top-left-radius: 8px; + border-top-right-radius: 8px; + border-bottom: 3px solid #008080; +} + +#footer { + padding: 4px; + color: #000000; + font-size: 18px; + background-color: #3CB369; + border-bottom-left-radius: 8px; + border-bottom-right-radius: 8px; + border-bottom: 3px solid #008080; +} + +#footer a:link { + color: #000000; + text-decoration: none; +} + +#footer a:visited { + color: #000000; + text-decoration: none; +} diff --git a/system.php b/system.php new file mode 100644 index 0000000..e962a94 --- /dev/null +++ b/system.php @@ -0,0 +1,218 @@ + 1) { + $arr1 = array("&", "\"", "'", "<", ">", '"'); + $arr2 = array("&", """, "'", "<", ">", "'"); + } else { + $arr1 = array("&", "\"", "'", "<", ">", " ", '"'); + $arr2 = array("&", """, "'", "<", ">", " ", "'"); + } + return str_replace($arr1, $arr2, $str); +} + +function ___ziplist() +{ + $zip = trim(func_get_arg(0)); + if (!is_readable('pclzip.php') || !___getmime($zip, 'zip')) return false; + require 'pclzip.php'; + $pclzip = new pclzip($zip); + if (!($getlist = $pclzip->listContent())) return false; + if (!is_array($getlist) || count($getlist) < 1) return false; + return $getlist; +} + +function ___convert() +{ + $str = func_get_arg(0); + if (!function_exists("mb_convert_encoding")) return $str; + $encode = func_num_args() < 2 ? "UTF-8" : func_get_arg(1); + $enlist = func_num_args() > 2 ? func_get_arg(2) : "auto,CP936"; + return mb_convert_encoding($str, $encode, $enlist); +} + +function ___getmime() +{ + $path = trim(func_get_arg(0)); + if (func_num_args() >= 2) { + $type = trim(func_get_arg(1)); + $type = explode(':', $type); + } + if (!is_file($path)) return false; + if (!($fp = fopen($path, "rb"))) return false; + $bsupport = array( + array('jpg', 'ffd8ff', 'image/jpeg'), + array('png', '89504e47', 'image/png'), + array('gif', '47494638', 'image/gif'), + array('bmp', '424d', 'image/x-ms-bmp'), + array('zip', '504b0304', 'application/zip')); + $headstr = bin2hex(fread($fp, 4)); + fclose($fp); + foreach ($bsupport as $temp) { + if (preg_match("/^$temp[1]/i", $headstr)) { + if (!isset($type)) { + return $temp[2]; + } elseif (in_array($temp[0], $type)) { + return $temp[2]; + } + } + } + return false; +} + +function ___sendfile() +{ + $i = 0; + $to = func_get_arg(0); + $fs = func_get_arg(1); + if (!is_file("email.php")) { + return false; + } else { + require "email.php"; + } + if ($to == "" || !is_array($fs)) { + return false; + } elseif (count($fs) < 1) { + return false; + } + $systags = uniqid(""); + $subject = "your files"; + $headers = "Content-Type: multipart/mixed; boundary=\"$systags\"\r\n"; + $emailbody = "--$systags\r\n"; + $emailbody .= "Content-type: text/plain; charset=utf-8\r\n"; + $emailbody .= "Content-transfer-encoding: 8bit\r\n\r\n"; + while ($i < count($fs)) { + if (!is_file($fs[$i]) || !is_readable($fs[$i])) continue; + $attachment = chunk_split(base64_encode(file_get_contents($fs[$i]))); + $emailbody .= "--$systags\r\n"; + $emailbody .= "Content-type: application/octet-stream; name=" . ___basename($fs[$i]) . "\r\n"; + $emailbody .= "Content-transfer-encoding: base64\r\n\r\n"; + $emailbody .= "$attachment\r\n\r\n"; + $i++; + } + $emailbody .= "--$systags--"; + return email($to, "from aite.xyz file manager", $emailbody, $headers); +} + +function ___download() +{ + $path = trim(func_get_arg(0)); + $size = filesize($path); + (isset($_SERVER['HTTP_RANGE']) && !empty($_SERVER['HTTP_RANGE']) && $range = substr($_SERVER['HTTP_RANGE'], 6)) || $range = '0-' . ($size - 1); + if (substr($range, -1) == '-') { + $init = substr($range, 0, -1); + $stop = $size - 1; + } elseif (substr($range, 0, 1) == '-') { + $init = $size - substr($range, 1) - 1; + $stop = $size - 1; + } else { + $init_stop = explode('-', $range); + $init = $init_stop[0]; + $stop = $init_stop[1]; + } + if (isset($_SERVER['HTTP_RANGE'])) { + header('HTTP/1.1 206 Partial Content'); + } + header('Accept-Ranges: bytes'); + header('Content-Type: application/force-download'); + header('Content-Disposition: attachment; filename=' . ___basename($path)); + header("Content-Range: bytes $init-$stop/$size"); + header('Content-Length: ' . ($stop - $init + 1)); + $fp = fopen($path, "rb"); + fseek($fp, $init); + while (!feof($fp)) { + echo fread($fp, 4096); + if (ftell($fp) > $stop) { + break; + } + } + fclose($fp); +} + +function ___basename() +{ + $path = trim(func_get_arg(0)); + $path = str_replace("\\", "/", $path); + $path = explode("/", $path); + return ___convert($path[count($path) - 1]); +} + +function ___realpath() +{ + $path = func_get_arg(0); + $path = str_replace('\\', '/', $path); + if (!is_link($path)) return realpath($path); + return preg_replace('/[^:]?\/{2,}/si', '/', $path); +} + +function ___filesize() +{ + $size = trim(func_get_arg(0)); + if ($size < 1024) { + return $size . " B"; + } elseif ($size < 1024 * 1024) { + return number_format($size / 1024, 3) . " KB"; + } elseif ($size < 1024 * 1024 * 1024) { + return number_format($size / 1024 / 1024, 3) . " MB"; + } elseif ($size < 1024 * 1024 * 1024 * 1024) { + return number_format($size / 1024 / 1024 / 1024, 3) . " GB"; + } else { + return number_format($size / 1024 / 1024 / 1024 / 1024, 3) . " TB"; + } +} + +function ___superexec() +{ + $cmd = trim(func_get_arg(0)); + if (php_uname("s") != "Linux") return false; + if ($cmd == "" || !function_exists("proc_open") || !function_exists("stream_get_contents")) { + return false; + } + if (!is_resource($sh = proc_open("exec sh", array(0 => array("pipe", "r"), 1 => array("pipe", "w")), $pipes))) { + return false; + } + fwrite($pipes[0], "export LANG=\"zh_CN.utf8\"\n"); + fwrite($pipes[0], $cmd); + fclose($pipes[0]); + $result = stream_get_contents($pipes[1]); + fclose($pipes[1]); + proc_close($sh); + return trim($result); +} + +function ___shortpath() +{ + $path = trim(func_get_arg(0)); + $path = ___convert($path, "UTF-8"); + if (function_exists('mb_strlen')) { + if (mb_strlen($path, "UTF-8") <= 18) return $path; + } else { + if (strlen($path) <= 18) return $path; + } + $path1 = function_exists('mb_substr') ? mb_substr($path, -9, 9, "UTF-8") : substr($path, -9); + $path2 = function_exists('mb_substr') ? mb_substr($path, 0, 9, "UTF-8") : substr($path, 0, 9); + return $path2 . " .... " . $path1; +} + +function ___windowsdisk() +{ + $disks = array(); + foreach (range('A', 'Z') as $item) { + $item = sprintf("%s:\\", $item); + if (is_dir($item)) { + $disks[] = $item; + } + } + if (empty($disks)) return false; + return $disks; +} + +?> diff --git a/tarcls.php b/tarcls.php new file mode 100644 index 0000000..b3bdb65 --- /dev/null +++ b/tarcls.php @@ -0,0 +1,2 @@ + true, 'raiseError' => true, 'throwError' => true, 'pushErrorHandling' => true, 'popErrorHandling' => true, ); function __construct($error_class = null) { $classname = strtolower(get_class($this)); if ($this->_debug) { print "PEAR constructor called, class=$classname\n"; } if ($error_class !== null) { $this->_error_class = $error_class; } while ($classname && strcasecmp($classname, "pear")) { $destructor = "_$classname"; if (method_exists($this, $destructor)) { global $_PEAR_destructor_object_list; $_PEAR_destructor_object_list[] = &$this; if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { register_shutdown_function("_PEAR_call_destructors"); $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; } break; } else { $classname = get_parent_class($classname); } } } public function PEAR($error_class = null) { $this->__construct($error_class); } function _PEAR() { if ($this->_debug) { printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); } } public function __call($method, $arguments) { if (!isset(self::$bivalentMethods[$method])) { trigger_error( 'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR ); } return call_user_func_array( array(get_class(), '_' . $method), array_merge(array($this), $arguments) ); } public static function __callStatic($method, $arguments) { if (!isset(self::$bivalentMethods[$method])) { trigger_error( 'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR ); } return call_user_func_array( array(get_class(), '_' . $method), array_merge(array(null), $arguments) ); } public static function &getStaticProperty($class, $var) { static $properties; if (!isset($properties[$class])) { $properties[$class] = array(); } if (!array_key_exists($var, $properties[$class])) { $properties[$class][$var] = null; } return $properties[$class][$var]; } public static function registerShutdownFunc($func, $args = array()) { if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { register_shutdown_function("_PEAR_call_destructors"); $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; } $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); } public static function isError($data, $code = null) { if (!is_a($data, 'PEAR_Error')) { return false; } if (is_null($code)) { return true; } elseif (is_string($code)) { return $data->getMessage() == $code; } return $data->getCode() == $code; } protected static function _setErrorHandling( $object, $mode = null, $options = null ) { if ($object !== null) { $setmode = &$object->_default_error_mode; $setoptions = &$object->_default_error_options; } else { $setmode = &$GLOBALS['_PEAR_default_error_mode']; $setoptions = &$GLOBALS['_PEAR_default_error_options']; } switch ($mode) { case PEAR_ERROR_EXCEPTION: case PEAR_ERROR_RETURN: case PEAR_ERROR_PRINT: case PEAR_ERROR_TRIGGER: case PEAR_ERROR_DIE: case null: $setmode = $mode; $setoptions = $options; break; case PEAR_ERROR_CALLBACK: $setmode = $mode; if (is_callable($options)) { $setoptions = $options; } else { trigger_error("invalid error callback", E_USER_WARNING); } break; default: trigger_error("invalid error mode", E_USER_WARNING); break; } } function expectError($code = '*') { if (is_array($code)) { array_push($this->_expected_errors, $code); } else { array_push($this->_expected_errors, array($code)); } return count($this->_expected_errors); } function popExpect() { return array_pop($this->_expected_errors); } function _checkDelExpect($error_code) { $deleted = false; foreach ($this->_expected_errors as $key => $error_array) { if (in_array($error_code, $error_array)) { unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); $deleted = true; } if (0 == count($this->_expected_errors[$key])) { unset($this->_expected_errors[$key]); } } return $deleted; } function delExpect($error_code) { $deleted = false; if ((is_array($error_code) && (0 != count($error_code)))) { foreach ($error_code as $key => $error) { $deleted = $this->_checkDelExpect($error) ? true : false; } return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); } elseif (!empty($error_code)) { if ($this->_checkDelExpect($error_code)) { return true; } return PEAR::raiseError("The expected error you submitted does not exist"); } return PEAR::raiseError("The expected error you submitted is empty"); } protected static function _raiseError($object, $message = null, $code = null, $mode = null, $options = null, $userinfo = null, $error_class = null, $skipmsg = false) { if (is_object($message)) { $code = $message->getCode(); $userinfo = $message->getUserInfo(); $error_class = $message->getType(); $message->error_message_prefix = ''; $message = $message->getMessage(); } if ( $object !== null && isset($object->_expected_errors) && count($object->_expected_errors) > 0 && count($exp = end($object->_expected_errors)) ) { if ($exp[0] == "*" || (is_int(reset($exp)) && in_array($code, $exp)) || (is_string(reset($exp)) && in_array($message, $exp)) ) { $mode = PEAR_ERROR_RETURN; } } if ($mode === null) { if ($object !== null && isset($object->_default_error_mode)) { $mode = $object->_default_error_mode; $options = $object->_default_error_options; } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) { $mode = $GLOBALS['_PEAR_default_error_mode']; $options = $GLOBALS['_PEAR_default_error_options']; } } if ($error_class !== null) { $ec = $error_class; } elseif ($object !== null && isset($object->_error_class)) { $ec = $object->_error_class; } else { $ec = 'PEAR_Error'; } if ($skipmsg) { $a = new $ec($code, $mode, $options, $userinfo); } else { $a = new $ec($message, $code, $mode, $options, $userinfo); } return $a; } protected static function _throwError($object, $message = null, $code = null, $userinfo = null) { if ($object !== null) { $a = &$object->raiseError($message, $code, null, null, $userinfo); return $a; } $a = &PEAR::raiseError($message, $code, null, null, $userinfo); return $a; } public static function staticPushErrorHandling($mode, $options = null) { $stack = &$GLOBALS['_PEAR_error_handler_stack']; $def_mode = &$GLOBALS['_PEAR_default_error_mode']; $def_options = &$GLOBALS['_PEAR_default_error_options']; $stack[] = array($def_mode, $def_options); switch ($mode) { case PEAR_ERROR_EXCEPTION: case PEAR_ERROR_RETURN: case PEAR_ERROR_PRINT: case PEAR_ERROR_TRIGGER: case PEAR_ERROR_DIE: case null: $def_mode = $mode; $def_options = $options; break; case PEAR_ERROR_CALLBACK: $def_mode = $mode; if (is_callable($options)) { $def_options = $options; } else { trigger_error("invalid error callback", E_USER_WARNING); } break; default: trigger_error("invalid error mode", E_USER_WARNING); break; } $stack[] = array($mode, $options); return true; } public static function staticPopErrorHandling() { $stack = &$GLOBALS['_PEAR_error_handler_stack']; $setmode = &$GLOBALS['_PEAR_default_error_mode']; $setoptions = &$GLOBALS['_PEAR_default_error_options']; array_pop($stack); list($mode, $options) = $stack[sizeof($stack) - 1]; array_pop($stack); switch ($mode) { case PEAR_ERROR_EXCEPTION: case PEAR_ERROR_RETURN: case PEAR_ERROR_PRINT: case PEAR_ERROR_TRIGGER: case PEAR_ERROR_DIE: case null: $setmode = $mode; $setoptions = $options; break; case PEAR_ERROR_CALLBACK: $setmode = $mode; if (is_callable($options)) { $setoptions = $options; } else { trigger_error("invalid error callback", E_USER_WARNING); } break; default: trigger_error("invalid error mode", E_USER_WARNING); break; } return true; } protected static function _pushErrorHandling($object, $mode, $options = null) { $stack = &$GLOBALS['_PEAR_error_handler_stack']; if ($object !== null) { $def_mode = &$object->_default_error_mode; $def_options = &$object->_default_error_options; } else { $def_mode = &$GLOBALS['_PEAR_default_error_mode']; $def_options = &$GLOBALS['_PEAR_default_error_options']; } $stack[] = array($def_mode, $def_options); if ($object !== null) { $object->setErrorHandling($mode, $options); } else { PEAR::setErrorHandling($mode, $options); } $stack[] = array($mode, $options); return true; } protected static function _popErrorHandling($object) { $stack = &$GLOBALS['_PEAR_error_handler_stack']; array_pop($stack); list($mode, $options) = $stack[sizeof($stack) - 1]; array_pop($stack); if ($object !== null) { $object->setErrorHandling($mode, $options); } else { PEAR::setErrorHandling($mode, $options); } return true; } public static function loadExtension($ext) { if (extension_loaded($ext)) { return true; } if ( function_exists('dl') === false || ini_get('enable_dl') != 1 ) { return false; } if (OS_WINDOWS) { $suffix = '.dll'; } elseif (PHP_OS == 'HP-UX') { $suffix = '.sl'; } elseif (PHP_OS == 'AIX') { $suffix = '.a'; } elseif (PHP_OS == 'OSX') { $suffix = '.bundle'; } else { $suffix = '.so'; } return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); } } function _PEAR_call_destructors() { global $_PEAR_destructor_object_list; if (is_array($_PEAR_destructor_object_list) && sizeof($_PEAR_destructor_object_list)) { reset($_PEAR_destructor_object_list); $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo'); if ($destructLifoExists) { $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); } while (list($k, $objref) = each($_PEAR_destructor_object_list)) { $classname = get_class($objref); while ($classname) { $destructor = "_$classname"; if (method_exists($objref, $destructor)) { $objref->$destructor(); break; } else { $classname = get_parent_class($classname); } } } $_PEAR_destructor_object_list = array(); } if ( isset($GLOBALS['_PEAR_shutdown_funcs']) && is_array($GLOBALS['_PEAR_shutdown_funcs']) && !empty($GLOBALS['_PEAR_shutdown_funcs']) ) { foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { call_user_func_array($value[0], $value[1]); } } } class PEAR_Error { var $error_message_prefix = ''; var $mode = PEAR_ERROR_RETURN; var $level = E_USER_NOTICE; var $code = -1; var $message = ''; var $userinfo = ''; var $backtrace = null; function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null) { if ($mode === null) { $mode = PEAR_ERROR_RETURN; } $this->message = $message; $this->code = $code; $this->mode = $mode; $this->userinfo = $userinfo; $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace'); if (!$skiptrace) { $this->backtrace = debug_backtrace(); if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { unset($this->backtrace[0]['object']); } } if ($mode & PEAR_ERROR_CALLBACK) { $this->level = E_USER_NOTICE; $this->callback = $options; } else { if ($options === null) { $options = E_USER_NOTICE; } $this->level = $options; $this->callback = null; } if ($this->mode & PEAR_ERROR_PRINT) { if (is_null($options) || is_int($options)) { $format = "%s"; } else { $format = $options; } printf($format, $this->getMessage()); } if ($this->mode & PEAR_ERROR_TRIGGER) { trigger_error($this->getMessage(), $this->level); } if ($this->mode & PEAR_ERROR_DIE) { $msg = $this->getMessage(); if (is_null($options) || is_int($options)) { $format = "%s"; if (substr($msg, -1) != "\n") { $msg .= "\n"; } } else { $format = $options; } die(sprintf($format, $msg)); } if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) { call_user_func($this->callback, $this); } if ($this->mode & PEAR_ERROR_EXCEPTION) { trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING); eval('$e = new Exception($this->message, $this->code);throw($e);'); } } function getMode() { return $this->mode; } function getCallback() { return $this->callback; } function getMessage() { return ($this->error_message_prefix . $this->message); } function getCode() { return $this->code; } function getType() { return get_class($this); } function getUserInfo() { return $this->userinfo; } function getDebugInfo() { return $this->getUserInfo(); } function getBacktrace($frame = null) { if (defined('PEAR_IGNORE_BACKTRACE')) { return null; } if ($frame === null) { return $this->backtrace; } return $this->backtrace[$frame]; } function addUserInfo($info) { if (empty($this->userinfo)) { $this->userinfo = $info; } else { $this->userinfo .= " ** $info"; } } function __toString() { return $this->getMessage(); } function toString() { $modes = array(); $levels = array(E_USER_NOTICE => 'notice', E_USER_WARNING => 'warning', E_USER_ERROR => 'error'); if ($this->mode & PEAR_ERROR_CALLBACK) { if (is_array($this->callback)) { $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]) . '::' . $this->callback[1]; } else { $callback = $this->callback; } return sprintf('[%s: message="%s" code=%d mode=callback '. 'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); } if ($this->mode & PEAR_ERROR_PRINT) { $modes[] = 'print'; } if ($this->mode & PEAR_ERROR_TRIGGER) { $modes[] = 'trigger'; } if ($this->mode & PEAR_ERROR_DIE) { $modes[] = 'die'; } if ($this->mode & PEAR_ERROR_RETURN) { $modes[] = 'return'; } return sprintf('[%s: message="%s" code=%d mode=%s level=%s '. 'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode("|", $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); } } define('ARCHIVE_TAR_ATT_SEPARATOR', 90001); define('ARCHIVE_TAR_END_BLOCK', pack("a512", '')); if (!function_exists('gzopen') && function_exists('gzopen64')) { function gzopen($filename, $mode, $use_include_path = 0) { return gzopen64($filename, $mode, $use_include_path); } } if (!function_exists('gztell') && function_exists('gztell64')) { function gztell($zp) { return gztell64($zp); } } if (!function_exists('gzseek') && function_exists('gzseek64')) { function gzseek($zp, $offset, $whence = SEEK_SET) { return gzseek64($zp, $offset, $whence); } } class Archive_Tar extends PEAR { public $_tarname = ''; public $_compress = false; public $_compress_type = 'none'; public $_separator = ' '; public $_file = 0; public $_temp_tarname = ''; public $_ignore_regexp = ''; public $error_object = null; public function __construct($p_tarname, $p_compress = null) { parent::__construct(); $this->_compress = false; $this->_compress_type = 'none'; if (($p_compress === null) || ($p_compress == '')) { if (@file_exists($p_tarname)) { if ($fp = @fopen($p_tarname, "rb")) { $data = fread($fp, 2); fclose($fp); if ($data == "\37\213") { $this->_compress = true; $this->_compress_type = 'gz'; } elseif ($data == "BZ") { $this->_compress = true; $this->_compress_type = 'bz2'; } elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') { $this->_compress = true; $this->_compress_type = 'lzma2'; } } } else { if (substr($p_tarname, -2) == 'gz') { $this->_compress = true; $this->_compress_type = 'gz'; } elseif ((substr($p_tarname, -3) == 'bz2') || (substr($p_tarname, -2) == 'bz') ) { $this->_compress = true; $this->_compress_type = 'bz2'; } else { if (substr($p_tarname, -2) == 'xz') { $this->_compress = true; $this->_compress_type = 'lzma2'; } } } } else { if (($p_compress === true) || ($p_compress == 'gz')) { $this->_compress = true; $this->_compress_type = 'gz'; } else { if ($p_compress == 'bz2') { $this->_compress = true; $this->_compress_type = 'bz2'; } else { if ($p_compress == 'lzma2') { $this->_compress = true; $this->_compress_type = 'lzma2'; } else { $this->_error( "Unsupported compression type '$p_compress'\n" . "Supported types are 'gz', 'bz2' and 'lzma2'.\n" ); return false; } } } } $this->_tarname = $p_tarname; if ($this->_compress) { if ($this->_compress_type == 'gz') { $extname = 'zlib'; } else { if ($this->_compress_type == 'bz2') { $extname = 'bz2'; } else { if ($this->_compress_type == 'lzma2') { $extname = 'xz'; } } } if (!extension_loaded($extname)) { PEAR::loadExtension($extname); } if (!extension_loaded($extname)) { $this->_error( "The extension '$extname' couldn't be found.\n" . "Please make sure your version of PHP was built " . "with '$extname' support.\n" ); return false; } } } public function __destruct() { $this->_close(); if ($this->_temp_tarname != '') { @unlink($this->_temp_tarname); } } public function create($p_filelist) { return $this->createModify($p_filelist, '', ''); } public function add($p_filelist) { return $this->addModify($p_filelist, '', ''); } public function extract($p_path = '', $p_preserve = false) { return $this->extractModify($p_path, '', $p_preserve); } public function listContent() { $v_list_detail = array(); if ($this->_openRead()) { if (!$this->_extractList('', $v_list_detail, "list", '', '')) { unset($v_list_detail); $v_list_detail = 0; } $this->_close(); } return $v_list_detail; } public function createModify($p_filelist, $p_add_dir, $p_remove_dir = '') { $v_result = true; if (!$this->_openWrite()) { return false; } if ($p_filelist != '') { if (is_array($p_filelist)) { $v_list = $p_filelist; } elseif (is_string($p_filelist)) { $v_list = explode($this->_separator, $p_filelist); } else { $this->_cleanFile(); $this->_error('Invalid file list'); return false; } $v_result = $this->_addList($v_list, $p_add_dir, $p_remove_dir); } if ($v_result) { $this->_writeFooter(); $this->_close(); } else { $this->_cleanFile(); } return $v_result; } public function addModify($p_filelist, $p_add_dir, $p_remove_dir = '') { $v_result = true; if (!$this->_isArchive()) { $v_result = $this->createModify( $p_filelist, $p_add_dir, $p_remove_dir ); } else { if (is_array($p_filelist)) { $v_list = $p_filelist; } elseif (is_string($p_filelist)) { $v_list = explode($this->_separator, $p_filelist); } else { $this->_error('Invalid file list'); return false; } $v_result = $this->_append($v_list, $p_add_dir, $p_remove_dir); } return $v_result; } public function addString($p_filename, $p_string, $p_datetime = false, $p_params = array()) { $p_stamp = @$p_params["stamp"] ? $p_params["stamp"] : ($p_datetime ? $p_datetime : time()); $p_mode = @$p_params["mode"] ? $p_params["mode"] : 0600; $p_type = @$p_params["type"] ? $p_params["type"] : ""; $p_uid = @$p_params["uid"] ? $p_params["uid"] : ""; $p_gid = @$p_params["gid"] ? $p_params["gid"] : ""; $v_result = true; if (!$this->_isArchive()) { if (!$this->_openWrite()) { return false; } $this->_close(); } if (!$this->_openAppend()) { return false; } $v_result = $this->_addString($p_filename, $p_string, $p_datetime, $p_params); $this->_writeFooter(); $this->_close(); return $v_result; } public function extractModify($p_path, $p_remove_path, $p_preserve = false) { $v_result = true; $v_list_detail = array(); if ($v_result = $this->_openRead()) { $v_result = $this->_extractList( $p_path, $v_list_detail, "complete", 0, $p_remove_path, $p_preserve ); $this->_close(); } return $v_result; } public function extractInString($p_filename) { if ($this->_openRead()) { $v_result = $this->_extractInString($p_filename); $this->_close(); } else { $v_result = null; } return $v_result; } public function extractList($p_filelist, $p_path = '', $p_remove_path = '', $p_preserve = false) { $v_result = true; $v_list_detail = array(); if (is_array($p_filelist)) { $v_list = $p_filelist; } elseif (is_string($p_filelist)) { $v_list = explode($this->_separator, $p_filelist); } else { $this->_error('Invalid string list'); return false; } if ($v_result = $this->_openRead()) { $v_result = $this->_extractList( $p_path, $v_list_detail, "partial", $v_list, $p_remove_path, $p_preserve ); $this->_close(); } return $v_result; } public function setAttribute() { $v_result = true; if (($v_size = func_num_args()) == 0) { return true; } $v_att_list = & func_get_args(); $i = 0; while ($i < $v_size) { switch ($v_att_list[$i]) { case ARCHIVE_TAR_ATT_SEPARATOR : if (($i + 1) >= $v_size) { $this->_error( 'Invalid number of parameters for ' . 'attribute ARCHIVE_TAR_ATT_SEPARATOR' ); return false; } $this->_separator = $v_att_list[$i + 1]; $i++; break; default : $this->_error('Unknown attribute code ' . $v_att_list[$i] . ''); return false; } $i++; } return $v_result; } public function setIgnoreRegexp($regexp) { $this->_ignore_regexp = $regexp; } public function setIgnoreList($list) { $regexp = str_replace(array('#', '.', '^', '$'), array('\#', '\.', '\^', '\$'), $list); $regexp = '#/' . join('$|/', $list) . '#'; $this->setIgnoreRegexp($regexp); } public function _error($p_message) { $this->error_object = $this->raiseError($p_message); } public function _warning($p_message) { $this->error_object = $this->raiseError($p_message); } public function _isArchive($p_filename = null) { if ($p_filename == null) { $p_filename = $this->_tarname; } clearstatcache(); return @is_file($p_filename) && !@is_link($p_filename); } public function _openWrite() { if ($this->_compress_type == 'gz' && function_exists('gzopen')) { $this->_file = @gzopen($this->_tarname, "wb9"); } else { if ($this->_compress_type == 'bz2' && function_exists('bzopen')) { $this->_file = @bzopen($this->_tarname, "w"); } else { if ($this->_compress_type == 'lzma2' && function_exists('xzopen')) { $this->_file = @xzopen($this->_tarname, 'w'); } else { if ($this->_compress_type == 'none') { $this->_file = @fopen($this->_tarname, "wb"); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); return false; } } } } if ($this->_file == 0) { $this->_error( 'Unable to open in write mode \'' . $this->_tarname . '\'' ); return false; } return true; } public function _openRead() { if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { if ($this->_temp_tarname == '') { $this->_temp_tarname = uniqid('tar') . '.tmp'; if (!$v_file_from = @fopen($this->_tarname, 'rb')) { $this->_error( 'Unable to open in read mode \'' . $this->_tarname . '\'' ); $this->_temp_tarname = ''; return false; } if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { $this->_error( 'Unable to open in write mode \'' . $this->_temp_tarname . '\'' ); $this->_temp_tarname = ''; return false; } while ($v_data = @fread($v_file_from, 1024)) { @fwrite($v_file_to, $v_data); } @fclose($v_file_from); @fclose($v_file_to); } $v_filename = $this->_temp_tarname; } else { $v_filename = $this->_tarname; } if ($this->_compress_type == 'gz' && function_exists('gzopen')) { $this->_file = @gzopen($v_filename, "rb"); } else { if ($this->_compress_type == 'bz2' && function_exists('bzopen')) { $this->_file = @bzopen($v_filename, "r"); } else { if ($this->_compress_type == 'lzma2' && function_exists('xzopen')) { $this->_file = @xzopen($v_filename, "r"); } else { if ($this->_compress_type == 'none') { $this->_file = @fopen($v_filename, "rb"); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); return false; } } } } if ($this->_file == 0) { $this->_error('Unable to open in read mode \'' . $v_filename . '\''); return false; } return true; } public function _openReadWrite() { if ($this->_compress_type == 'gz') { $this->_file = @gzopen($this->_tarname, "r+b"); } else { if ($this->_compress_type == 'bz2') { $this->_error( 'Unable to open bz2 in read/write mode \'' . $this->_tarname . '\' (limitation of bz2 extension)' ); return false; } else { if ($this->_compress_type == 'lzma2') { $this->_error( 'Unable to open lzma2 in read/write mode \'' . $this->_tarname . '\' (limitation of lzma2 extension)' ); return false; } else { if ($this->_compress_type == 'none') { $this->_file = @fopen($this->_tarname, "r+b"); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); return false; } } } } if ($this->_file == 0) { $this->_error( 'Unable to open in read/write mode \'' . $this->_tarname . '\'' ); return false; } return true; } public function _close() { if (is_resource($this->_file)) { if ($this->_compress_type == 'gz') { @gzclose($this->_file); } else { if ($this->_compress_type == 'bz2') { @bzclose($this->_file); } else { if ($this->_compress_type == 'lzma2') { @xzclose($this->_file); } else { if ($this->_compress_type == 'none') { @fclose($this->_file); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); } } } } $this->_file = 0; } if ($this->_temp_tarname != '') { @unlink($this->_temp_tarname); $this->_temp_tarname = ''; } return true; } public function _cleanFile() { $this->_close(); if ($this->_temp_tarname != '') { @unlink($this->_temp_tarname); $this->_temp_tarname = ''; } else { @unlink($this->_tarname); } $this->_tarname = ''; return true; } public function _writeBlock($p_binary_data, $p_len = null) { if (is_resource($this->_file)) { if ($p_len === null) { if ($this->_compress_type == 'gz') { @gzputs($this->_file, $p_binary_data); } else { if ($this->_compress_type == 'bz2') { @bzwrite($this->_file, $p_binary_data); } else { if ($this->_compress_type == 'lzma2') { @xzwrite($this->_file, $p_binary_data); } else { if ($this->_compress_type == 'none') { @fputs($this->_file, $p_binary_data); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); } } } } } else { if ($this->_compress_type == 'gz') { @gzputs($this->_file, $p_binary_data, $p_len); } else { if ($this->_compress_type == 'bz2') { @bzwrite($this->_file, $p_binary_data, $p_len); } else { if ($this->_compress_type == 'lzma2') { @xzwrite($this->_file, $p_binary_data, $p_len); } else { if ($this->_compress_type == 'none') { @fputs($this->_file, $p_binary_data, $p_len); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); } } } } } } return true; } public function _readBlock() { $v_block = null; if (is_resource($this->_file)) { if ($this->_compress_type == 'gz') { $v_block = @gzread($this->_file, 512); } else { if ($this->_compress_type == 'bz2') { $v_block = @bzread($this->_file, 512); } else { if ($this->_compress_type == 'lzma2') { $v_block = @xzread($this->_file, 512); } else { if ($this->_compress_type == 'none') { $v_block = @fread($this->_file, 512); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); } } } } } return $v_block; } public function _jumpBlock($p_len = null) { if (is_resource($this->_file)) { if ($p_len === null) { $p_len = 1; } if ($this->_compress_type == 'gz') { @gzseek($this->_file, gztell($this->_file) + ($p_len * 512)); } else { if ($this->_compress_type == 'bz2') { for ($i = 0; $i < $p_len; $i++) { $this->_readBlock(); } } else { if ($this->_compress_type == 'lzma2') { for ($i = 0; $i < $p_len; $i++) { $this->_readBlock(); } } else { if ($this->_compress_type == 'none') { @fseek($this->_file, $p_len * 512, SEEK_CUR); } else { $this->_error( 'Unknown or missing compression type (' . $this->_compress_type . ')' ); } } } } } return true; } public function _writeFooter() { if (is_resource($this->_file)) { $v_binary_data = pack('a1024', ''); $this->_writeBlock($v_binary_data); } return true; } public function _addList($p_list, $p_add_dir, $p_remove_dir) { $v_result = true; $v_header = array(); $p_add_dir = $this->_translateWinPath($p_add_dir); $p_remove_dir = $this->_translateWinPath($p_remove_dir, false); if (!$this->_file) { $this->_error('Invalid file descriptor'); return false; } if (sizeof($p_list) == 0) { return true; } foreach ($p_list as $v_filename) { if (!$v_result) { break; } if ($v_filename == $this->_tarname) { continue; } if ($v_filename == '') { continue; } if ($this->_ignore_regexp && preg_match($this->_ignore_regexp, '/' . $v_filename)) { $this->_warning("File '$v_filename' ignored"); continue; } if (!file_exists($v_filename) && !is_link($v_filename)) { $this->_warning("File '$v_filename' does not exist"); continue; } if (!$this->_addFile($v_filename, $v_header, $p_add_dir, $p_remove_dir)) { return false; } if (@is_dir($v_filename) && !@is_link($v_filename)) { if (!($p_hdir = opendir($v_filename))) { $this->_warning("Directory '$v_filename' can not be read"); continue; } while (false !== ($p_hitem = readdir($p_hdir))) { if (($p_hitem != '.') && ($p_hitem != '..')) { if ($v_filename != ".") { $p_temp_list[0] = $v_filename . '/' . $p_hitem; } else { $p_temp_list[0] = $p_hitem; } $v_result = $this->_addList( $p_temp_list, $p_add_dir, $p_remove_dir ); } } unset($p_temp_list); unset($p_hdir); unset($p_hitem); } } return $v_result; } public function _addFile($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $v_stored_filename = null) { if (!$this->_file) { $this->_error('Invalid file descriptor'); return false; } if ($p_filename == '') { $this->_error('Invalid file name'); return false; } if (is_null($v_stored_filename)) { $p_filename = $this->_translateWinPath($p_filename, false); $v_stored_filename = $p_filename; if (strcmp($p_filename, $p_remove_dir) == 0) { return true; } if ($p_remove_dir != '') { if (substr($p_remove_dir, -1) != '/') { $p_remove_dir .= '/'; } if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir) { $v_stored_filename = substr($p_filename, strlen($p_remove_dir)); } } $v_stored_filename = $this->_translateWinPath($v_stored_filename); if ($p_add_dir != '') { if (substr($p_add_dir, -1) == '/') { $v_stored_filename = $p_add_dir . $v_stored_filename; } else { $v_stored_filename = $p_add_dir . '/' . $v_stored_filename; } } $v_stored_filename = $this->_pathReduction($v_stored_filename); } if ($this->_isArchive($p_filename)) { if (($v_file = @fopen($p_filename, "rb")) == 0) { $this->_warning( "Unable to open file '" . $p_filename . "' in binary read mode" ); return true; } if (!$this->_writeHeader($p_filename, $v_stored_filename)) { return false; } while (($v_buffer = fread($v_file, 512)) != '') { $v_binary_data = pack("a512", "$v_buffer"); $this->_writeBlock($v_binary_data); } fclose($v_file); } else { if (!$this->_writeHeader($p_filename, $v_stored_filename)) { return false; } } return true; } public function _addString($p_filename, $p_string, $p_datetime = false, $p_params = array()) { $p_stamp = @$p_params["stamp"] ? $p_params["stamp"] : ($p_datetime ? $p_datetime : time()); $p_mode = @$p_params["mode"] ? $p_params["mode"] : 0600; $p_type = @$p_params["type"] ? $p_params["type"] : ""; $p_uid = @$p_params["uid"] ? $p_params["uid"] : 0; $p_gid = @$p_params["gid"] ? $p_params["gid"] : 0; if (!$this->_file) { $this->_error('Invalid file descriptor'); return false; } if ($p_filename == '') { $this->_error('Invalid file name'); return false; } $p_filename = $this->_translateWinPath($p_filename, false); if ($p_datetime === false) { $p_datetime = time(); } if (!$this->_writeHeaderBlock( $p_filename, strlen($p_string), $p_stamp, $p_mode, $p_type, $p_uid, $p_gid ) ) { return false; } $i = 0; while (($v_buffer = substr($p_string, (($i++) * 512), 512)) != '') { $v_binary_data = pack("a512", $v_buffer); $this->_writeBlock($v_binary_data); } return true; } public function _writeHeader($p_filename, $p_stored_filename) { if ($p_stored_filename == '') { $p_stored_filename = $p_filename; } $v_reduce_filename = $this->_pathReduction($p_stored_filename); if (strlen($v_reduce_filename) > 99) { if (!$this->_writeLongHeader($v_reduce_filename)) { return false; } } $v_info = lstat($p_filename); $v_uid = sprintf("%07s", DecOct($v_info[4])); $v_gid = sprintf("%07s", DecOct($v_info[5])); $v_perms = sprintf("%07s", DecOct($v_info['mode'] & 000777)); $v_mtime = sprintf("%011s", DecOct($v_info['mtime'])); $v_linkname = ''; if (@is_link($p_filename)) { $v_typeflag = '2'; $v_linkname = readlink($p_filename); $v_size = sprintf("%011s", DecOct(0)); } elseif (@is_dir($p_filename)) { $v_typeflag = "5"; $v_size = sprintf("%011s", DecOct(0)); } else { $v_typeflag = '0'; clearstatcache(); $v_size = sprintf("%011s", DecOct($v_info['size'])); } $v_magic = 'ustar '; $v_version = ' '; if (function_exists('posix_getpwuid')) { $userinfo = posix_getpwuid($v_info[4]); $groupinfo = posix_getgrgid($v_info[5]); $v_uname = $userinfo['name']; $v_gname = $groupinfo['name']; } else { $v_uname = ''; $v_gname = ''; } $v_devmajor = ''; $v_devminor = ''; $v_prefix = ''; $v_binary_data_first = pack( "a100a8a8a8a12a12", $v_reduce_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime ); $v_binary_data_last = pack( "a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, '' ); $v_checksum = 0; for ($i = 0; $i < 148; $i++) { $v_checksum += ord(substr($v_binary_data_first, $i, 1)); } for ($i = 148; $i < 156; $i++) { $v_checksum += ord(' '); } for ($i = 156, $j = 0; $i < 512; $i++, $j++) { $v_checksum += ord(substr($v_binary_data_last, $j, 1)); } $this->_writeBlock($v_binary_data_first, 148); $v_checksum = sprintf("%06s ", DecOct($v_checksum)); $v_binary_data = pack("a8", $v_checksum); $this->_writeBlock($v_binary_data, 8); $this->_writeBlock($v_binary_data_last, 356); return true; } public function _writeHeaderBlock( $p_filename, $p_size, $p_mtime = 0, $p_perms = 0, $p_type = '', $p_uid = 0, $p_gid = 0 ) { $p_filename = $this->_pathReduction($p_filename); if (strlen($p_filename) > 99) { if (!$this->_writeLongHeader($p_filename)) { return false; } } if ($p_type == "5") { $v_size = sprintf("%011s", DecOct(0)); } else { $v_size = sprintf("%011s", DecOct($p_size)); } $v_uid = sprintf("%07s", DecOct($p_uid)); $v_gid = sprintf("%07s", DecOct($p_gid)); $v_perms = sprintf("%07s", DecOct($p_perms & 000777)); $v_mtime = sprintf("%11s", DecOct($p_mtime)); $v_linkname = ''; $v_magic = 'ustar '; $v_version = ' '; if (function_exists('posix_getpwuid')) { $userinfo = posix_getpwuid($p_uid); $groupinfo = posix_getgrgid($p_gid); $v_uname = $userinfo['name']; $v_gname = $groupinfo['name']; } else { $v_uname = ''; $v_gname = ''; } $v_devmajor = ''; $v_devminor = ''; $v_prefix = ''; $v_binary_data_first = pack( "a100a8a8a8a12A12", $p_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime ); $v_binary_data_last = pack( "a1a100a6a2a32a32a8a8a155a12", $p_type, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, '' ); $v_checksum = 0; for ($i = 0; $i < 148; $i++) { $v_checksum += ord(substr($v_binary_data_first, $i, 1)); } for ($i = 148; $i < 156; $i++) { $v_checksum += ord(' '); } for ($i = 156, $j = 0; $i < 512; $i++, $j++) { $v_checksum += ord(substr($v_binary_data_last, $j, 1)); } $this->_writeBlock($v_binary_data_first, 148); $v_checksum = sprintf("%06s ", DecOct($v_checksum)); $v_binary_data = pack("a8", $v_checksum); $this->_writeBlock($v_binary_data, 8); $this->_writeBlock($v_binary_data_last, 356); return true; } public function _writeLongHeader($p_filename) { $v_size = sprintf("%11s ", DecOct(strlen($p_filename))); $v_typeflag = 'L'; $v_linkname = ''; $v_magic = ''; $v_version = ''; $v_uname = ''; $v_gname = ''; $v_devmajor = ''; $v_devminor = ''; $v_prefix = ''; $v_binary_data_first = pack( "a100a8a8a8a12a12", '././@LongLink', 0, 0, 0, $v_size, 0 ); $v_binary_data_last = pack( "a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, '' ); $v_checksum = 0; for ($i = 0; $i < 148; $i++) { $v_checksum += ord(substr($v_binary_data_first, $i, 1)); } for ($i = 148; $i < 156; $i++) { $v_checksum += ord(' '); } for ($i = 156, $j = 0; $i < 512; $i++, $j++) { $v_checksum += ord(substr($v_binary_data_last, $j, 1)); } $this->_writeBlock($v_binary_data_first, 148); $v_checksum = sprintf("%06s ", DecOct($v_checksum)); $v_binary_data = pack("a8", $v_checksum); $this->_writeBlock($v_binary_data, 8); $this->_writeBlock($v_binary_data_last, 356); $i = 0; while (($v_buffer = substr($p_filename, (($i++) * 512), 512)) != '') { $v_binary_data = pack("a512", "$v_buffer"); $this->_writeBlock($v_binary_data); } return true; } public function _readHeader($v_binary_data, &$v_header) { if (strlen($v_binary_data) == 0) { $v_header['filename'] = ''; return true; } if (strlen($v_binary_data) != 512) { $v_header['filename'] = ''; $this->_error('Invalid block size : ' . strlen($v_binary_data)); return false; } if (!is_array($v_header)) { $v_header = array(); } $v_checksum = 0; for ($i = 0; $i < 148; $i++) { $v_checksum += ord(substr($v_binary_data, $i, 1)); } for ($i = 148; $i < 156; $i++) { $v_checksum += ord(' '); } for ($i = 156; $i < 512; $i++) { $v_checksum += ord(substr($v_binary_data, $i, 1)); } if (version_compare(PHP_VERSION, "5.5.0-dev") < 0) { $fmt = "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" . "a8checksum/a1typeflag/a100link/a6magic/a2version/" . "a32uname/a32gname/a8devmajor/a8devminor/a131prefix"; } else { $fmt = "Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/" . "Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" . "Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix"; } $v_data = unpack($fmt, $v_binary_data); if (strlen($v_data["prefix"]) > 0) { $v_data["filename"] = "$v_data[prefix]/$v_data[filename]"; } $v_header['checksum'] = OctDec(trim($v_data['checksum'])); if ($v_header['checksum'] != $v_checksum) { $v_header['filename'] = ''; if (($v_checksum == 256) && ($v_header['checksum'] == 0)) { return true; } $this->_error( 'Invalid checksum for file "' . $v_data['filename'] . '" : ' . $v_checksum . ' calculated, ' . $v_header['checksum'] . ' expected' ); return false; } $v_header['filename'] = rtrim($v_data['filename'], "\0"); if ($this->_maliciousFilename($v_header['filename'])) { $this->_error( 'Malicious .tar detected, file "' . $v_header['filename'] . '" will not install in desired directory tree' ); return false; } $v_header['mode'] = OctDec(trim($v_data['mode'])); $v_header['uid'] = OctDec(trim($v_data['uid'])); $v_header['gid'] = OctDec(trim($v_data['gid'])); $v_header['size'] = OctDec(trim($v_data['size'])); $v_header['mtime'] = OctDec(trim($v_data['mtime'])); if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { $v_header['size'] = 0; } $v_header['link'] = trim($v_data['link']); return true; } private function _maliciousFilename($file) { if (strpos($file, '/../') !== false) { return true; } if (strpos($file, '../') === 0) { return true; } return false; } public function _readLongHeader(&$v_header) { $v_filename = ''; $v_filesize = $v_header['size']; $n = floor($v_header['size'] / 512); for ($i = 0; $i < $n; $i++) { $v_content = $this->_readBlock(); $v_filename .= $v_content; } if (($v_header['size'] % 512) != 0) { $v_content = $this->_readBlock(); $v_filename .= $v_content; } $v_binary_data = $this->_readBlock(); if (!$this->_readHeader($v_binary_data, $v_header)) { return false; } $v_filename = rtrim(substr($v_filename, 0, $v_filesize), "\0"); $v_header['filename'] = $v_filename; if ($this->_maliciousFilename($v_filename)) { $this->_error( 'Malicious .tar detected, file "' . $v_filename . '" will not install in desired directory tree' ); return false; } return true; } private function _extractInString($p_filename) { $v_result_str = ""; while (strlen($v_binary_data = $this->_readBlock()) != 0) { if (!$this->_readHeader($v_binary_data, $v_header)) { return null; } if ($v_header['filename'] == '') { continue; } if ($v_header['typeflag'] == 'L') { if (!$this->_readLongHeader($v_header)) { return null; } } if ($v_header['filename'] == $p_filename) { if ($v_header['typeflag'] == "5") { $this->_error( 'Unable to extract in string a directory ' . 'entry {' . $v_header['filename'] . '}' ); return null; } else { $n = floor($v_header['size'] / 512); for ($i = 0; $i < $n; $i++) { $v_result_str .= $this->_readBlock(); } if (($v_header['size'] % 512) != 0) { $v_content = $this->_readBlock(); $v_result_str .= substr( $v_content, 0, ($v_header['size'] % 512) ); } return $v_result_str; } } else { $this->_jumpBlock(ceil(($v_header['size'] / 512))); } } return null; } public function _extractList( $p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path, $p_preserve = false ) { $v_result = true; $v_nb = 0; $v_extract_all = true; $v_listing = false; $p_path = $this->_translateWinPath($p_path, false); if ($p_path == '' || (substr($p_path, 0, 1) != '/' && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':')) ) { $p_path = "./" . $p_path; } $p_remove_path = $this->_translateWinPath($p_remove_path); if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) { $p_remove_path .= '/'; } $p_remove_path_size = strlen($p_remove_path); switch ($p_mode) { case "complete" : $v_extract_all = true; $v_listing = false; break; case "partial" : $v_extract_all = false; $v_listing = false; break; case "list" : $v_extract_all = false; $v_listing = true; break; default : $this->_error('Invalid extract mode (' . $p_mode . ')'); return false; } clearstatcache(); while (strlen($v_binary_data = $this->_readBlock()) != 0) { $v_extract_file = false; $v_extraction_stopped = 0; if (!$this->_readHeader($v_binary_data, $v_header)) { return false; } if ($v_header['filename'] == '') { continue; } if ($v_header['typeflag'] == 'L') { if (!$this->_readLongHeader($v_header)) { return false; } } if ($v_header['typeflag'] == 'x' || $v_header['typeflag'] == 'g') { $this->_jumpBlock(ceil(($v_header['size'] / 512))); continue; } if ((!$v_extract_all) && (is_array($p_file_list))) { $v_extract_file = false; for ($i = 0; $i < sizeof($p_file_list); $i++) { if (substr($p_file_list[$i], -1) == '/') { if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) == $p_file_list[$i]) ) { $v_extract_file = true; break; } } elseif ($p_file_list[$i] == $v_header['filename']) { $v_extract_file = true; break; } } } else { $v_extract_file = true; } if (($v_extract_file) && (!$v_listing)) { if (($p_remove_path != '') && (substr($v_header['filename'] . '/', 0, $p_remove_path_size) == $p_remove_path) ) { $v_header['filename'] = substr( $v_header['filename'], $p_remove_path_size ); if ($v_header['filename'] == '') { continue; } } if (($p_path != './') && ($p_path != '/')) { while (substr($p_path, -1) == '/') { $p_path = substr($p_path, 0, strlen($p_path) - 1); } if (substr($v_header['filename'], 0, 1) == '/') { $v_header['filename'] = $p_path . $v_header['filename']; } else { $v_header['filename'] = $p_path . '/' . $v_header['filename']; } } if (file_exists($v_header['filename'])) { if ((@is_dir($v_header['filename'])) && ($v_header['typeflag'] == '') ) { $this->_error( 'File ' . $v_header['filename'] . ' already exists as a directory' ); return false; } if (($this->_isArchive($v_header['filename'])) && ($v_header['typeflag'] == "5") ) { $this->_error( 'Directory ' . $v_header['filename'] . ' already exists as a file' ); return false; } if (!is_writeable($v_header['filename'])) { $this->_error( 'File ' . $v_header['filename'] . ' already exists and is write protected' ); return false; } if (filemtime($v_header['filename']) > $v_header['mtime']) { } } elseif (($v_result = $this->_dirCheck( ($v_header['typeflag'] == "5" ? $v_header['filename'] : dirname($v_header['filename'])) )) != 1 ) { $this->_error('Unable to create path for ' . $v_header['filename']); return false; } if ($v_extract_file) { if ($v_header['typeflag'] == "5") { if (!@file_exists($v_header['filename'])) { if (!@mkdir($v_header['filename'], 0777)) { $this->_error( 'Unable to create directory {' . $v_header['filename'] . '}' ); return false; } } } elseif ($v_header['typeflag'] == "2") { if (@file_exists($v_header['filename'])) { @unlink($v_header['filename']); } if (!@symlink($v_header['link'], $v_header['filename'])) { $this->_error( 'Unable to extract symbolic link {' . $v_header['filename'] . '}' ); return false; } } else { if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { $this->_error( 'Error while opening {' . $v_header['filename'] . '} in write binary mode' ); return false; } else { $n = floor($v_header['size'] / 512); for ($i = 0; $i < $n; $i++) { $v_content = $this->_readBlock(); fwrite($v_dest_file, $v_content, 512); } if (($v_header['size'] % 512) != 0) { $v_content = $this->_readBlock(); fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); } @fclose($v_dest_file); if ($p_preserve) { @chown($v_header['filename'], $v_header['uid']); @chgrp($v_header['filename'], $v_header['gid']); } @touch($v_header['filename'], $v_header['mtime']); if ($v_header['mode'] & 0111) { $mode = fileperms($v_header['filename']) | (~umask() & 0111); @chmod($v_header['filename'], $mode); } } clearstatcache(); if (!is_file($v_header['filename'])) { $this->_error( 'Extracted file ' . $v_header['filename'] . 'does not exist. Archive may be corrupted.' ); return false; } $filesize = filesize($v_header['filename']); if ($filesize != $v_header['size']) { $this->_error( 'Extracted file ' . $v_header['filename'] . ' does not have the correct file size \'' . $filesize . '\' (' . $v_header['size'] . ' expected). Archive may be corrupted.' ); return false; } } } else { $this->_jumpBlock(ceil(($v_header['size'] / 512))); } } else { $this->_jumpBlock(ceil(($v_header['size'] / 512))); } if ($v_listing || $v_extract_file || $v_extraction_stopped) { if (($v_file_dir = dirname($v_header['filename'])) == $v_header['filename'] ) { $v_file_dir = ''; } if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) { $v_file_dir = '/'; } $p_list_detail[$v_nb++] = $v_header; if (is_array($p_file_list) && (count($p_list_detail) == count($p_file_list))) { return true; } } } return true; } public function _openAppend() { if (filesize($this->_tarname) == 0) { return $this->_openWrite(); } if ($this->_compress) { $this->_close(); if (!@rename($this->_tarname, $this->_tarname . ".tmp")) { $this->_error( 'Error while renaming \'' . $this->_tarname . '\' to temporary file \'' . $this->_tarname . '.tmp\'' ); return false; } if ($this->_compress_type == 'gz') { $v_temp_tar = @gzopen($this->_tarname . ".tmp", "rb"); } elseif ($this->_compress_type == 'bz2') { $v_temp_tar = @bzopen($this->_tarname . ".tmp", "r"); } elseif ($this->_compress_type == 'lzma2') { $v_temp_tar = @xzopen($this->_tarname . ".tmp", "r"); } if ($v_temp_tar == 0) { $this->_error( 'Unable to open file \'' . $this->_tarname . '.tmp\' in binary read mode' ); @rename($this->_tarname . ".tmp", $this->_tarname); return false; } if (!$this->_openWrite()) { @rename($this->_tarname . ".tmp", $this->_tarname); return false; } if ($this->_compress_type == 'gz') { $end_blocks = 0; while (!@gzeof($v_temp_tar)) { $v_buffer = @gzread($v_temp_tar, 512); if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) { $end_blocks++; continue; } elseif ($end_blocks > 0) { for ($i = 0; $i < $end_blocks; $i++) { $this->_writeBlock(ARCHIVE_TAR_END_BLOCK); } $end_blocks = 0; } $v_binary_data = pack("a512", $v_buffer); $this->_writeBlock($v_binary_data); } @gzclose($v_temp_tar); } elseif ($this->_compress_type == 'bz2') { $end_blocks = 0; while (strlen($v_buffer = @bzread($v_temp_tar, 512)) > 0) { if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) { $end_blocks++; continue; } elseif ($end_blocks > 0) { for ($i = 0; $i < $end_blocks; $i++) { $this->_writeBlock(ARCHIVE_TAR_END_BLOCK); } $end_blocks = 0; } $v_binary_data = pack("a512", $v_buffer); $this->_writeBlock($v_binary_data); } @bzclose($v_temp_tar); } elseif ($this->_compress_type == 'lzma2') { $end_blocks = 0; while (strlen($v_buffer = @xzread($v_temp_tar, 512)) > 0) { if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) { $end_blocks++; continue; } elseif ($end_blocks > 0) { for ($i = 0; $i < $end_blocks; $i++) { $this->_writeBlock(ARCHIVE_TAR_END_BLOCK); } $end_blocks = 0; } $v_binary_data = pack("a512", $v_buffer); $this->_writeBlock($v_binary_data); } @xzclose($v_temp_tar); } if (!@unlink($this->_tarname . ".tmp")) { $this->_error( 'Error while deleting temporary file \'' . $this->_tarname . '.tmp\'' ); } } else { if (!$this->_openReadWrite()) { return false; } clearstatcache(); $v_size = filesize($this->_tarname); fseek($this->_file, $v_size - 1024); if (fread($this->_file, 512) == ARCHIVE_TAR_END_BLOCK) { fseek($this->_file, $v_size - 1024); } elseif (fread($this->_file, 512) == ARCHIVE_TAR_END_BLOCK) { fseek($this->_file, $v_size - 512); } } return true; } public function _append($p_filelist, $p_add_dir = '', $p_remove_dir = '') { if (!$this->_openAppend()) { return false; } if ($this->_addList($p_filelist, $p_add_dir, $p_remove_dir)) { $this->_writeFooter(); } $this->_close(); return true; } public function _dirCheck($p_dir) { clearstatcache(); if ((@is_dir($p_dir)) || ($p_dir == '')) { return true; } $p_parent_dir = dirname($p_dir); if (($p_parent_dir != $p_dir) && ($p_parent_dir != '') && (!$this->_dirCheck($p_parent_dir)) ) { return false; } if (!@mkdir($p_dir, 0777)) { $this->_error("Unable to create directory '$p_dir'"); return false; } return true; } private function _pathReduction($p_dir) { $v_result = ''; if ($p_dir != '') { $v_list = explode('/', $p_dir); for ($i = sizeof($v_list) - 1; $i >= 0; $i--) { if ($v_list[$i] == ".") { } else { if ($v_list[$i] == "..") { $i--; } else { if (($v_list[$i] == '') && ($i != (sizeof($v_list) - 1)) && ($i != 0) ) { } else { $v_result = $v_list[$i] . ($i != (sizeof($v_list) - 1) ? '/' . $v_result : ''); } } } } } if (defined('OS_WINDOWS') && OS_WINDOWS) { $v_result = strtr($v_result, '\\', '/'); } return $v_result; } public function _translateWinPath($p_path, $p_remove_disk_letter = true) { if (defined('OS_WINDOWS') && OS_WINDOWS) { if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false) ) { $p_path = substr($p_path, $v_position + 1); } if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) { $p_path = strtr($p_path, '\\', '/'); } } return $p_path; } } \ No newline at end of file diff --git a/unpack.php b/unpack.php new file mode 100644 index 0000000..eec77c7 --- /dev/null +++ b/unpack.php @@ -0,0 +1,161 @@ +\n"; +echo "返回目录解压结果\n"; +echo "\n"; +echo "
\n"; +switch ($type) { + case "gz" : + if (!function_exists("gzopen")) { + echo "系统没有支持核心函数!"; + } else { + $fp = preg_replace("/(.*?)\.gz$/si", "\\1", $unpackdir . "/" . basename($path)); + if (file_exists($fp)) { + echo "目标文件已经存在了哦!"; + } elseif (!($gz = gzopen($path, "r"))) { + echo "系统无法打开压缩文件!"; + } else { + if (!($fp = fopen($fp, "wb"))) { + echo "系统无法保存解压文件!"; + } else { + while (!feof($gz)) { + fwrite($fp, gzread($gz, 4096)); + } + gzclose($gz); + fclose($fp); + echo "压缩文件已经解压完成!"; + } + } + } + break; + case "bz2" : + if (!function_exists("bzopen")) { + echo "系统没有支持核心函数!"; + } else { + $fp = preg_replace("/(.*?)\.bz2$/si", "\\1", $unpackdir . "/" . basename($path)); + if (file_exists($fp)) { + echo "目标文件已经存在了哦!"; + } elseif (!($bz2 = bzopen($path, "r"))) { + echo "系统无法打开压缩文件!"; + } else { + if (!($fp = fopen($fp, "wb"))) { + echo "系统无法保存解压文件!"; + } else { + while (!feof($bz2)) { + fwrite($fp, bzread($bz2, 4096)); + } + bzclose($bz2); + fclose($fp); + echo "压缩文件已经解压完成!"; + } + } + } + break; + case "zip" : + if (!file_exists("pclzip.php")) { + echo "暂时无法进行解压操作!"; + } else { + require "pclzip.php"; + $pk = new pclzip($path); + if (($zip = $pk->extract(PCLZIP_OPT_PATH, $unpackdir)) == false) { + echo "无法成功解压您的文件!"; + } else { + echo "成功解压出 " . count($zip) . " 个档案!"; + } + } + break; + case "tar" : + if (!file_exists("tarcls.php")) { + echo "暂时无法进行解压操作!"; + } else { + require "tarcls.php"; + $pk = new Archive_Tar($path); + if ($pk->extract($unpackdir) == false) { + echo "无法成功解压您的文件!"; + } else { + echo "成功的对文件进行解压!"; + } + } + break; + case "7za" : + $bin = "./p7zip.bin"; + if (is_file($bin)) { + if (function_exists("chmod")) { + chmod($bin, 0700); + if (!is_executable($bin)) { + $tmp = sys_get_temp_dir() . '/p7zip.bin'; + if (copy($bin, $tmp)) { + chmod($tmp, 0700); + !is_executable($tmp) ? $bin = false : $bin = $tmp; + } else { + $bin = false; + } + } + } + } + if (___superexec($bin) == "") { + if (___superexec('7z') != "") { + $bin = "7z"; + } elseif (___superexec('7za') != "") { + $bin = "7za"; + } + } + if (___superexec($bin) == "") { + echo "程序无法正常完成工作!"; + } else { + $a = addslashes($path); + $b = addslashes($unpackdir); + $c = isset($_GET['password']) ? addslashes(trim($_GET['password'])) : null; + echo nl2br(___codepre(___convert(___superexec("$bin x '$a' '-o$b' '-p$c' -y 2>&1"), "UTF-8"))); + } + break; + case "rar" : + $bin = "./unrar.bin"; + if (is_file($bin)) { + if (function_exists("chmod")) { + chmod($bin, 0700); + if (!is_executable($bin)) { + $tmp = sys_get_temp_dir() . '/unrar.bin'; + if (copy($bin, $tmp)) { + chmod($tmp, 0700); + !is_executable($tmp) ? $bin = false : $bin = $tmp; + } else { + $bin = false; + } + } + } + } + if (___superexec($bin) == "") { + if (___superexec('rar') != "") { + $bin = "rar"; + } elseif (___superexec('unrar') != "") { + $bin = "unrar"; + } + } + if (___superexec($bin) == "") { + echo "程序无法正常完成工作!"; + } else { + $a = addslashes($path); + $b = addslashes($unpackdir); + $c = isset($_GET['password']) ? addslashes(trim($_GET['password'])) : null; + if ($c == null) { + echo nl2br(___codepre(___convert(___superexec("$bin x -y '$a' '$b' 2>&1"), "UTF-8"))); + } else { + echo nl2br(___codepre(___convert(___superexec("$bin x -y '-p$c' '$a' '$b' 2>&1"), "UTF-8"))); + } + } + break; + default : + echo "暂时不支持的压缩类型!"; +} +echo "
\n"; +xhtml_footer(); +?> diff --git a/unzip.php b/unzip.php new file mode 100644 index 0000000..e13ec8b --- /dev/null +++ b/unzip.php @@ -0,0 +1,75 @@ +\n"; + echo "返回目录错误提示\n"; + echo "\n"; + echo "
\n"; + echo "此文件暂时不能被系统操作!"; + echo "
\n"; + xhtml_footer(); + exit; +} +xhtml_head("爱特ZIP工具"); +if (isset($_POST['z']) && is_array($_POST['z']) && isset($_POST['undir']) && is_dir(trim($_POST['undir']))) { + echo "
\n"; + echo "返回目录解压结果\n"; + echo "
\n"; + $pk = new pclzip($path); + $dir = trim($_POST['undir']); + $arr = array_map('urldecode', $_POST['z']); + if (($zip = $pk->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_NAME, $arr)) == false) { + echo "
\n"; + echo "无法成功解压您的文件!"; + echo "\n
\n"; + } else { + echo "
\n"; + echo "本次共操作 " . count($zip) . " 个档案!"; + echo "\n
\n"; + foreach ($zip as $zf) { + echo "
\n"; + if ($zf['folder']) { + echo "[目录]"; + } else { + echo "[文件]"; + } + echo ___convert($zf['filename'], "UTF-8") . "(" . $zf['status'] . ")\n
\n"; + echo "
\n"; + } + } +} else { + echo "
\n"; + echo "返回目录文件列表\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + $unzipdir = dirname($path); + isset($_GET['unzipdir']) && is_dir($_GET['unzipdir']) && $unzipdir = trim($_GET['unzipdir']); + echo "解压到此路径:\n"; + echo "\n"; + echo "\n"; + echo "(全选|消选)\n"; + echo "
\n"; + $select = isset($_GET['select']) ? "checked " : null; + foreach ($ziplist as $zfile) { + echo "
\n"; + echo "\n"; + if ($zfile['folder']) { + echo "[目录]" . ___codepre(___convert($zfile['stored_filename'], "UTF-8")); + } else { + echo "[文件]" . ___codepre(___convert($zfile['stored_filename'], "UTF-8")); + echo "(" . ___filesize($zfile['size']) . "->" . ___filesize($zfile['compressed_size']) . ")"; + } + echo "\n
\n"; + } + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..bfcca64 --- /dev/null +++ b/upload.php @@ -0,0 +1,139 @@ +\n"; +echo "返回目录\n"; +if (isset($_GET['url'])) { + echo "本地上传\n"; +} else { + echo "远程上传\n"; +} +echo "\n"; +echo "
\n"; +echo "
\n"; +echo "\n"; +if (isset($_GET['url'])) echo "\n"; +echo "数量->\n"; +echo "\n"; +echo "
\n"; +echo "
\n"; +if (isset($_GET['url'])) { + if (isset($_POST['fupload'])) if (is_array($_POST['fupload'])) if (count($_POST['fupload']) > 0) { + $o = 0; + $i = 0; + echo "
上传文件信息报告
\n"; + while ($i < count($_POST['fupload'])) { + if (!preg_match("/^[a-z0-9]+\:\/\/.+/si", $_POST['fupload'][$i])) { + $i++; + continue; + } + preg_match("/[^\/\?&\s\:\\\]+$/i", $_POST['fupload'][$i], $fname); + $fname = $fname[0] != "" ? $fname[0] : time() . ".file"; + if (!($fp = fopen(trim($_POST['fupload'][$i]), "rb"))) { + echo "
\n"; + echo "{$fname}(Error !)\n"; + echo "
\n"; + } elseif (!($fp2 = fopen($fpath = "$getcwd/$fname", "wb"))) { + echo "
\n"; + echo "{$fname}(Error !)\n"; + echo "
\n"; + } else { + while (!feof($fp)) { + fwrite($fp2, fread($fp, 4096)); + } + fclose($fp); + fclose($fp2); + if (filesize($fpath) > 0) { + echo "
\n"; + echo "{$fname}(Yes !)\n"; + echo "
\n"; + } else { + unlink($fpath); + echo "
\n"; + echo "{$fname}(Error !)\n"; + echo "
\n"; + } + } + $o++; + $i++; + } + if ($o < 1) echo "郁闷,没有任何文件被上传!\n"; + } + echo "
输入您的上传地址
\n"; + echo "
\n"; + if (!isset($_GET['uploadnum'])) { + echo "
\n"; + echo "地址[+]\n"; + echo "
\n"; + } else { + $i = 0; + $uploadnum = (int)trim($_GET['uploadnum']); + if ($uploadnum < 1) $uploadnum = 1; + while ($i < $uploadnum) { + echo "
\n"; + echo "地址[" . ($i + 1) . "]\n"; + echo "
\n"; + $i++; + } + } + echo "
\n"; + echo "(有效 地址)\n"; + echo "
\n"; + echo "
\n"; +} else { + if (isset($_FILES['fupload'])) if (count($_FILES['fupload']) > 0) { + $o = 0; + $i = 0; + echo "
上传文件信息报告
\n"; + while ($i < count($_FILES['fupload']['size'])) { + if ($_FILES['fupload']['size'][$i] < 1) { + $i++; + continue; + } + if (!move_uploaded_file($_FILES['fupload']['tmp_name'][$i], $getcwd . "/" . $_FILES['fupload']['name'][$i])) { + echo "
\n"; + echo "{$_FILES['fupload']['name'][$i]}(Error !)\n"; + echo "
\n"; + } else { + echo "
\n"; + echo "{$_FILES['fupload']['name'][$i]}(" . ___filesize($_FILES['fupload']['size'][$i]) . ")\n"; + echo "
\n"; + } + $o++; + $i++; + } + if ($o < 1) echo "郁闷,没有任何文件被上传!\n"; + } + echo "
选择您的上传文件
\n"; + echo "
\n"; + if (!isset($_GET['uploadnum'])) { + echo "
\n"; + echo "文件[+]\n"; + echo "
\n"; + } else { + $i = 0; + $uploadnum = (int)trim($_GET['uploadnum']); + if ($uploadnum < 1) $uploadnum = 1; + while ($i < $uploadnum) { + echo "
\n"; + echo "文件[" . ($i + 1) . "]\n"; + echo "
\n"; + $i++; + } + } + echo "
\n"; + echo "(有效 文件)\n"; + echo "
\n"; + echo "
\n"; +} +xhtml_footer(); +?> diff --git a/view.php b/view.php new file mode 100644 index 0000000..d5b90b0 --- /dev/null +++ b/view.php @@ -0,0 +1,86 @@ +\n"; + echo "返回目录错误提示\n"; + echo "\n"; + echo "
\n"; + echo "此文件您没有读取权限!"; + echo "
\n"; + xhtml_footer(); +} else { + xhtml_head("查看文件"); + echo "
\n"; + echo "返回目录选择编码\n"; + echo "
\n"; + echo "
"; + echo "
\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
爱特文件内容浏览
\n"; + if (filesize($path) > (2 * 1024 * 1024)) { + echo "
\n"; + echo "文件过大,请下载后查看!\n"; + echo "
\n"; + } else { + echo "
\n"; + if (!($data = file_get_contents($path))) { + echo "读取文件时发生了错误!\n"; + } else { + echo "
";
+            if (!isset($_GET['charset'])) {
+                echo nl2br(___codepre(___convert($data, "UTF-8")));
+            } elseif (($charset = trim($_GET['charset'])) == "") {
+                echo nl2br(___codepre(___convert($data, "UTF-8")));
+            } else {
+                echo nl2br(___codepre(___convert($data, "UTF-8", $charset)));
+            }
+            echo "
\n";
+        }
+        echo "
"; + } + xhtml_footer(); +} +?> diff --git a/xhtml.php b/xhtml.php new file mode 100644 index 0000000..7c9993b --- /dev/null +++ b/xhtml.php @@ -0,0 +1,31 @@ + + + + {$title} - 〔{$name}〕 + + + + +XHTML; +} + +function xhtml_footer() +{ + echo << + By:Xiaoqidun@Gmail.Com + + + +XHTML; +} + +?>