- 兼容部分服务器问题。
### ver1.2 `2013/10/16`
-----
#### fix bug:
- - 设置,外部通用调用方式
+ - 设置,外部通用调用方式
- 打包中文乱码问题。
- - simple,default主题,navbar 下拉菜单右边位置问题。
- - 文件管理:有滚动条时,上下超过可视区域框选问题修复,统一和win操作一致。
- - 文件大小写不敏感设置,扩展名获取bug
- - 目录读取权限判断,解决“系统错误”相关问题。
+ - simple,default主题,navbar 下拉菜单右边位置问题。
+ - 文件管理:有滚动条时,上下超过可视区域框选问题修复,统一和win操作一致。
+ - 文件大小写不敏感设置,扩展名获取bug
+ - 目录读取权限判断,解决“系统错误”相关问题。
#### update:
- - 地址栏宽度自适应优化,支持浏览器窗口调整
- - 增加远程下载功能;上传功能优化,
- - 整体样式风格优化,
- - 右键菜单优化(可持续粘贴,剪切后粘贴清空剪贴板)。
+ - 地址栏宽度自适应优化,支持浏览器窗口调整
+ - 增加远程下载功能;上传功能优化,
+ - 整体样式风格优化,
+ - 右键菜单优化(可持续粘贴,剪切后粘贴清空剪贴板)。
- 新建文件、文件重命名高度自适应优化
- 关闭调试状态错误信息
- - 图片播放幻灯片优化,支持浏览器窗口调整,解决事件绑定bug,添加图片倒影;添加关闭按钮,关闭动画等功能
- - 优化桌面,弹出层层级问题;任务栏为最上层
- - 优化多标签,没有标签时不显示标签容器,放至层级覆盖
- - 地址栏超出宽度,自动隐藏最左边内容
- - 右键菜单状态同步,排序方式初始化当前值,设置后标记当前值。
- - 优化编辑器:拖动内容&文件到编辑区,内容处理。
- - 拖拽上传,信息框自动隐出后关闭
- - setting,editor,player最小化时,再次调用则显示出弹出层
- - 优化影音播放器,皮肤及相关配置信息存储于js中,不用之前的服务器请求方式,修改皮肤后可以直接更新到界面上。
+ - 图片播放幻灯片优化,支持浏览器窗口调整,解决事件绑定bug,添加图片倒影;添加关闭按钮,关闭动画等功能
+ - 优化桌面,弹出层层级问题;任务栏为最上层
+ - 优化多标签,没有标签时不显示标签容器,放至层级覆盖
+ - 地址栏超出宽度,自动隐藏最左边内容
+ - 右键菜单状态同步,排序方式初始化当前值,设置后标记当前值。
+ - 优化编辑器:拖动内容&文件到编辑区,内容处理。
+ - 拖拽上传,信息框自动隐出后关闭
+ - setting,editor,player最小化时,再次调用则显示出弹出层
+ - 优化影音播放器,皮肤及相关配置信息存储于js中,不用之前的服务器请求方式,修改皮肤后可以直接更新到界面上。
### ver1.01 `2013/9/10`
-----
#### fix bug:
- 添加到收藏
- - simple,default主题,navbar 下拉菜单右边位置问题。
+ - simple,default主题,navbar 下拉菜单右边位置问题。
#### update:
- - 添加到收藏夹,修改收藏夹,更新文件管理收藏夹部分。
- - 修改主题,同时修改编辑器主题。【编辑区,文件管理,桌面】
- - 优化setting部分代码,整合为一个整体。
- - 优化debug,增加less编译,导出功能优化,先编译后复制再操作
+ - 添加到收藏夹,修改收藏夹,更新文件管理收藏夹部分。
+ - 修改主题,同时修改编辑器主题。【编辑区,文件管理,桌面】
+ - 优化setting部分代码,整合为一个整体。
+ - 优化debug,增加less编译,导出功能优化,先编译后复制再操作
### ver1.0 `2013.9.1`
-----
#### update:
- - 代码模块化优化,静态文件分离,可以分开部署
- - 编辑器单独逻辑提取,完整融合到文件管理,树目录融合文件管理,懒加载语法高亮
- - 多标签实现,弹层对话框多标签支持,桌面任务栏实现;编辑器多标签支持
- - 弹层功能优化,实现最大最小化,最小化关联多标签任务栏管理
+ - 代码模块化优化,静态文件分离,可以分开部署
+ - 编辑器单独逻辑提取,完整融合到文件管理,树目录融合文件管理,懒加载语法高亮
+ - 多标签实现,弹层对话框多标签支持,桌面任务栏实现;编辑器多标签支持
+ - 弹层功能优化,实现最大最小化,最小化关联多标签任务栏管理
#### fix bug:
- - linux 下浏览器打开文件和文件夹,中文问题
- - 重命名&新建&上传 刷新列表使用动画,当前选中失效问题,不使用动画加载方式。
+ - linux 下浏览器打开文件和文件夹,中文问题
+ - 重命名&新建&上传 刷新列表使用动画,当前选中失效问题,不使用动画加载方式。
- html5拖拽上传优化
### ver0.8 `2013.6.15`
-----
#### update:
- - 整体优化,实现全部操作ajax本地化 ,进一步提升体验
- - 浏览器强刷新,保持之前最后所在路径
- - 重命名,新建,粘贴操作后添加选中状态
- - 代码主题列表优化,重新设计,提高可配置性
- - 优化代码,添加getTplList模版,简化关联配置获取
- - 增加设置功能,ajax刷新设置。缩略图片增加tips预览(被注释frame/setting.php)
+ - 整体优化,实现全部操作ajax本地化 ,进一步提升体验
+ - 浏览器强刷新,保持之前最后所在路径
+ - 重命名,新建,粘贴操作后添加选中状态
+ - 代码主题列表优化,重新设计,提高可配置性
+ - 优化代码,添加getTplList模版,简化关联配置获取
+ - 增加设置功能,ajax刷新设置。缩略图片增加tips预览(被注释frame/setting.php)
- 增加重命名只选择名称部分功能
- 增加iframe js api互操作ie支持。四大浏览器内核皆支持。
- - 文件夹打开,采用ajax实现。包括头部地址栏,父级目录,左边树目录以及收藏夹
- - 历史记录完美实现,前进后退按钮实时变化状态。
- - 快捷键backspace实现后退(left header main 分别加入函数,屏蔽默认history(-1)操作) -
+ - 文件夹打开,采用ajax实现。包括头部地址栏,父级目录,左边树目录以及收藏夹
+ - 历史记录完美实现,前进后退按钮实时变化状态。
+ - 快捷键backspace实现后退(left header main 分别加入函数,屏蔽默认history(-1)操作) -
#### fix bug:
- - 完善修改windows以及linux获取文件列表,中文路径属性获取失败问题。
- - 复制,剪切。剪贴板内容覆盖判空处理
- - 修复一些地方ajax线程同步问题,重命名后选中失效问题解决
- - 修复返回上层目录,根目录检测
- - 修复linux下 音视频播放,中文路径问题
+ - 完善修改windows以及linux获取文件列表,中文路径属性获取失败问题。
+ - 复制,剪切。剪贴板内容覆盖判空处理
+ - 修复一些地方ajax线程同步问题,重命名后选中失效问题解决
+ - 修复返回上层目录,根目录检测
+ - 修复linux下 音视频播放,中文路径问题
- 修复文件右键菜单位置出错问题
- 修复ie下frame js相互通信问题
- - ajax更新文件列表下,各种bug修复。进一步提升操作友好性
- - 修复当前目录改变的情况下,播放器消失的问题。现在能使播放器始终保留
+ - ajax更新文件列表下,各种bug修复。进一步提升操作友好性
+ - 修复当前目录改变的情况下,播放器消失的问题。现在能使播放器始终保留
diff --git a/README.md b/README.md
index 9a698944..3e4d3022 100755
--- a/README.md
+++ b/README.md
@@ -15,6 +15,11 @@
- [中文文档](http://kodcloud.com/#lang=zh_CN)
- [Donate](https://www.paypal.me/kalcaddle)
+### Source code
+----
+- [github](https://github.com/kalcaddle/KodExplorer)
+- [gitee](https://gitee.com/kalcaddle/KODExplorer)
+
# Features
- Use experience like operating system, Rich context menu and toolbar, drag and drop, shortcut keys......
- Available in more than 40 languages.
@@ -169,8 +174,10 @@ kod is made possible by the following open source projects.
* ...
-
# License
kodcloud is issued under GPLv3. license.[License](http://kodcloud.com/tools/licenses/license.txt)
-Contact: kalcaddle#qq.com
+Contact: warlee#kodcloud.com
Copyright (C) 2013 kodcloud.com
+
+# 版权声明
+kodexplorer 使用 GPL v3 协议.
diff --git a/app/api/sso.class.php b/app/api/sso.class.php
index 552ca81c..fe9e9ead 100755
--- a/app/api/sso.class.php
+++ b/app/api/sso.class.php
@@ -8,8 +8,8 @@ static private function init(){
$sessionID = $_COOKIE[$sessionName]?$_COOKIE[$sessionName]:md5(uniqid());
$basicPath = dirname(dirname(dirname(__FILE__))).'/';
$sessionPath = $basicPath.'data/session/';
- if(file_exists($basicPath.'define.php')){
- include($basicPath.'define.php');
+ if(file_exists($basicPath.'config/define.php')){
+ include($basicPath.'config/define.php');
$sessionPath = DATA_PATH.'session/';
}
if(!file_exists($sessionPath)){
@@ -78,12 +78,16 @@ static public function sessionAuth($appKey,$auth,$kodHost='',$appUrl=''){
if(strstr($appUrl,'/plugins/')){
$kodHost = substr($appUrl,0,strpos($appUrl,'/plugins/'));
}else{
- $kodHost = $_SERVER['HTTP_REFERER'];
- if(strstr($kodHost,'/index.php?')){
- $kodHost = substr($kodHost,0,strpos($kodHost,'/index.php?'));
- }else if(strstr($kodHost,'/?')){
- $kodHost = substr($kodHost,0,strpos($kodHost,'/?'));
- }
+ if(isset($_COOKIE['APP_HOST'])){
+ $kodHost = $_COOKIE['APP_HOST'];
+ }else{
+ $kodHost = $_SERVER['HTTP_REFERER'];
+ if(strstr($kodHost,'/index.php?')){
+ $kodHost = substr($kodHost,0,strpos($kodHost,'/index.php?'));
+ }else if(strstr($kodHost,'/?')){
+ $kodHost = substr($kodHost,0,strpos($kodHost,'/?'));
+ }
+ }
}
}
$authUrl = rtrim($kodHost,'/').'/index.php?user/sso&app='.$appKey.'&'.$auth;
@@ -96,6 +100,4 @@ static public function sessionAuth($appKey,$auth,$kodHost='',$appUrl=''){
exit;
}
}
-}
-
-
+}
\ No newline at end of file
diff --git a/app/controller/editor.class.php b/app/controller/editor.class.php
index 509bb898..2de5fd4d 100755
--- a/app/controller/editor.class.php
+++ b/app/controller/editor.class.php
@@ -46,8 +46,10 @@ private function themeSet(){
public function fileGet(){
if(isset($this->in['fileUrl'])){
$pass = $this->config['settingSystem']['systemPassword'];
- $fileUrl = _DIR_CLEAR($this->in['fileUrl']);
- $fileUrl = str_replace(':/','://',$fileUrl);
+ $fileUrl = $this->in['fileUrl'];
+ if(!request_url_safe($fileUrl)){
+ show_json(LNG('url error!'),false);
+ }
$urlInfo = parse_url_query($fileUrl);
if( isset($urlInfo['fid']) &&
strlen(Mcrypt::decode($urlInfo['fid'],$pass)) != 0
@@ -58,9 +60,6 @@ public function fileGet(){
$displayName = rawurldecode($urlInfo['downFilename']);
}
}else{
- if(is_file($filepath) || substr($filepath,0,4) != 'http'){
- show_json(LNG('not url'),false);
- }
$displayName = rawurldecode($urlInfo['name']);
$filepath = $fileUrl.'&accessToken='.access_token_get();
}
diff --git a/app/controller/explorer.class.php b/app/controller/explorer.class.php
index b03cfe91..212afc89 100755
--- a/app/controller/explorer.class.php
+++ b/app/controller/explorer.class.php
@@ -77,7 +77,7 @@ public function pathInfo(){
if (count($infoList)==1 && $infoList[0]['type']!='folder') {//单个文件
$file = $infoList[0]['path'];
if( $GLOBALS['isRoot'] ||
- $GLOBALS['auth']["explorer.fileDownloa"]==1 ||
+ $GLOBALS['auth']["explorer.fileDownload"]==1 ||
isset($this->in['viewPage'])){
$data['downloadPath'] = _make_file_proxy($file);
}
@@ -156,16 +156,28 @@ public function mkdir(){
}
$new = rtrim($this->path,'/');
$new = get_filename_auto($new,'',$repeatType);//已存在处理 创建副本
- Hook::trigger("explorer.mkdirBefore",$new);
- if(mk_dir($new,DEFAULT_PERRMISSIONS)){
- chmod_path($new,DEFAULT_PERRMISSIONS);
- Hook::trigger("explorer.mkdirAfter",$new);
+ if($this->_mkdir($new)){
show_json(LNG('create_success'),true,_DIR_OUT(iconv_app($new)) );
}else{
show_json(LNG('create_error'),false);
}
}
-
+ private function _mkdir($path){
+ if(!$GLOBALS['isRoot']){
+ //IIS6 解析漏洞 /a.php/2.jpg 得到解析
+ $temp = str_replace('\\','/',$path);
+ if(substr(rtrim($temp,'/'),-4) == '.php'){
+ show_json(LNG('no_permission_ext'),false);
+ }
+ }
+ Hook::trigger("explorer.mkdirBefore",$path);
+ if(mk_dir($path,DEFAULT_PERRMISSIONS)){
+ chmod_path($path,DEFAULT_PERRMISSIONS);
+ Hook::trigger("explorer.mkdirAfter",$path);
+ return true;
+ }
+ return false;
+ }
public function pathRname(){
$rnameTo=_DIR($this->in['rnameTo']);
if (file_exists_case($rnameTo)) {
@@ -964,9 +976,8 @@ public function unzip(){
$unzipToAdd = $name;
}
- //所在目录不可写
- mk_dir($unzipTo);
- if (!path_writeable($unzipTo)){
+ $this->_mkdir($unzipTo);
+ if (!path_writeable($unzipTo)){//所在目录不可写
show_json(LNG('no_permission_write'),false);
}
$unzipTo = $unzipTo.$unzipToAdd;
@@ -1007,7 +1018,15 @@ public function imageRotate(){
}
//缩略图
public function image(){
- if (filesize($this->path) <= 1024*50 ||
+ $thumbWidth = 250;
+ if(isset($this->in['thumbWidth'])){
+ $thumbWidth = intval($this->in['thumbWidth']);//自定义预览大图
+ }
+ if(substr($this->path,0,4) == 'http'){
+ header('Location: '.$this->in['path']);
+ exit;
+ }
+ if (@filesize($this->path) <= 1024*50 ||
!function_exists('imagecolorallocate') ) {//小于50k或者不支持gd库 不再生成缩略图
file_put_out($this->path,false);
return;
@@ -1016,9 +1035,9 @@ public function image(){
mk_dir(DATA_THUMB);
}
$image = $this->path;
- $imageMd5 = @md5_file($image);//文件md5
+ $imageMd5 = @md5_file($image).'_'.$thumbWidth;//文件md5
if (strlen($imageMd5)<5) {
- $imageMd5 = md5($image);
+ $imageMd5 = md5($image).'_'.$thumbWidth;
}
$imageThumb = DATA_THUMB.$imageMd5.'.png';
if (!file_exists($imageThumb)){//如果拼装成的url不存在则没有生成过
@@ -1026,7 +1045,7 @@ public function image(){
$imageThumb=$this->path;
}else {
$cm = new ImageThumb($image,'file');
- $cm->prorate($imageThumb,250,250);//生成等比例缩略图
+ $cm->prorate($imageThumb,$thumbWidth,$thumbWidth);//生成等比例缩略图
}
}
if (!file_exists($imageThumb) ||
@@ -1063,7 +1082,7 @@ public function serverDownload() {
}
//下载
$savePath = _DIR(rawurldecode($this->in['savePath']));
- mk_dir($savePath);
+ $this->_mkdir($savePath);
if (!$savePath || !path_writeable($savePath)){
show_json(LNG('no_permission_write'),false);
}
@@ -1078,7 +1097,7 @@ public function serverDownload() {
$filename = $header['name'];
}
- $saveFile = $savePath.$filename;
+ $saveFile = $savePath._DIR_CLEAR($filename);
if (!checkExt($saveFile)){//不允许的扩展名
$saveFile = $savePath.date('h:i:s').'.dat';
}
@@ -1136,7 +1155,7 @@ public function fileUpload(){
$fullPath = _DIR_CLEAR(rawurldecode($this->in['fullPath']));
$fullPath = get_path_father($fullPath);
$fullPath = iconv_system($fullPath);
- if (mk_dir($savePath.$fullPath)) {
+ if ($this->_mkdir($savePath.$fullPath)) {
$savePath = $savePath.$fullPath;
}
}
@@ -1162,10 +1181,12 @@ private function _pathShare(&$list){
$value['exists'] = intval(file_exists($thePath));
$value['metaInfo'] = 'path-self-share';
$value['menuType'] = "menu-share-path";
- $value['aa'] = $thePath;
+ if(is_file($thePath)){
+ $value['size'] = get_filesize($thePath);;
+ }
//分享列表oexe
- if(get_path_ext($value['name']) == 'oexe'){
+ if(get_path_ext($value['name']) == 'oexe' && is_file($thePath) ){
$json = json_decode(@file_get_contents($thePath),true);
if(is_array($json)) $value = array_merge($value,$json);
}
@@ -1225,7 +1246,7 @@ private function _pathFav(&$list){
}
//分享列表oexe
- if(get_path_ext($val['name']) == 'oexe'){
+ if(get_path_ext($val['name']) == 'oexe' && is_file($thePath)){
$json = json_decode(@file_get_contents($thePath),true);
if(is_array($json)) $val = array_merge($val,$json);
}
diff --git a/app/controller/share.class.php b/app/controller/share.class.php
index 5983f8f6..f55a79d8 100755
--- a/app/controller/share.class.php
+++ b/app/controller/share.class.php
@@ -383,7 +383,7 @@ public function search(){
public function fileUpload(){
$fileName = $_FILES['file']['name']? $_FILES['file']['name']:$GLOBALS['in']['name'];
$GLOBALS['isRoot']=0;
- $GLOBALS['auth']['extNotAllow'] = "php|asp|jsp|html|htm|htaccess";
+ $GLOBALS['auth']['extNotAllow'] = "htm|html|php|phtml|pwml|asp|aspx|ascx|jsp|pl|htaccess|shtml|shtm|phtm";
if(!checkExt($fileName)){
show_json(LNG('no_permission_ext'),false);
}
@@ -411,7 +411,7 @@ public function fileUpload(){
//代理输出
public function fileProxy(){
$mime = get_file_mime(get_path_ext($this->path));
- if($mime == 'text/plain'){//文本则转编码
+ if($mime == 'text/plain' && is_file($this->path)){//文本则转编码
$fileContents = file_get_contents($this->path);
$charset=get_charset($fileContents);
if ($charset!='' || $charset!='utf-8') {
@@ -495,9 +495,8 @@ private function zip($zipPath){
public function fileGet(){
if(isset($this->in['fileUrl'])){ //http
$displayName = $this->in['name'];
- $filepath = _DIR_CLEAR($this->in['fileUrl']);
- $filepath = str_replace(':/','://',$filepath);
- if(is_file($filepath) || substr($filepath,0,4) != 'http'){
+ $filepath = $this->in['fileUrl'];
+ if(!request_url_safe($filepath)){
show_json(LNG('url error!'),false);
}
}else{
@@ -538,31 +537,41 @@ function_exists("mb_convert_encoding")
}
public function image(){
- if (filesize($this->path) <= 1024*50 ||
+ $thumbWidth = 250;
+ if(isset($this->in['thumbWidth'])){
+ $thumbWidth = intval($this->in['thumbWidth']);//自定义预览大图
+ }
+ if(substr($this->path,0,4) == 'http'){
+ header('Location: '.$this->in['path']);
+ exit;
+ }
+ if (@filesize($this->path) <= 1024*50 ||
!function_exists('imagecolorallocate') ) {//小于50k或者不支持gd库 不再生成缩略图
- file_put_out($this->path);
+ file_put_out($this->path,false);
return;
}
- $image = $this->path;
- $image_md5 = @md5_file($image);//文件md5
- if (strlen($image_md5)<5) {
- $image_md5 = md5($image);
- }
- $imageThumb = DATA_THUMB.$image_md5.'.png';
if (!is_dir(DATA_THUMB)){
mk_dir(DATA_THUMB);
}
+ $image = $this->path;
+ $imageMd5 = @md5_file($image).'_'.$thumbWidth;//文件md5
+ if (strlen($imageMd5)<5) {
+ $imageMd5 = md5($image).'_'.$thumbWidth;
+ }
+ $imageThumb = DATA_THUMB.$imageMd5.'.png';
if (!file_exists($imageThumb)){//如果拼装成的url不存在则没有生成过
if (get_path_father($image)==DATA_THUMB){//当前目录则不生成缩略图
- $imageThumb = $this->path;
+ $imageThumb=$this->path;
}else {
- $cm=new ImageThumb($image,'file');
- $cm->prorate($imageThumb,224,200);//生成等比例缩略图
+ $cm = new ImageThumb($image,'file');
+ $cm->prorate($imageThumb,$thumbWidth,$thumbWidth);//生成等比例缩略图
}
}
- if (!file_exists($imageThumb) || filesize($imageThumb)<100){//缩略图生成失败则用默认图标
- $imageThumb = $this->path;
+ if (!file_exists($imageThumb) ||
+ filesize($imageThumb)<100){//缩略图生成失败则使用原图
+ $imageThumb=$this->path;
}
+ file_put_out($imageThumb,false);
file_put_out($imageThumb);//输出
}
diff --git a/app/controller/systemMember.class.php b/app/controller/systemMember.class.php
index f16d2d74..2df8ff49 100755
--- a/app/controller/systemMember.class.php
+++ b/app/controller/systemMember.class.php
@@ -361,7 +361,7 @@ public function edit() {
unset($userInfo['homePath']);
}
if($this->sql->set($userID,$userInfo)){
- self::spaceChange($userID);//重置用户使用空间
+ //self::spaceChange($userID);//重置用户使用空间
show_json(LNG('success'),true,$userInfo);
}
show_json(LNG('error_repeat'),false);
diff --git a/app/controller/util.php b/app/controller/util.php
index 90a9741c..9773b47b 100755
--- a/app/controller/util.php
+++ b/app/controller/util.php
@@ -1,2 +1,2 @@
-| |7|9请检查php.ini相关配置,查看磁盘是否已满,或咨询服务商。
| |7|9session.save_path=| |7|9
| |7|9session.save_handler=| |7|9settingSystem| |7|9systemPassword| |7|9kodExplorer_| |7|9accessToken error!');̅ԹѫҗϾáޡ袨ˡش«;
- define($_SERVER{}[0],$_SERVER{}{0x001});define($_SERVER{}[0x0002],$_SERVER{}{0x00003});define($_SERVER{}[0x000004],$_SERVER{}{0x05});define($_SERVER{}[0x006],$_SERVER{}{0x0007});define($_SERVER{}[0x00008],$_SERVER{}{0x000009});define($_SERVER{}[0x0a],$_SERVER{}{0x00b});define($_SERVER{}[0x000c],$_SERVER{}{0x0000d});define($_SERVER{}[0x00000e],$_SERVER{}{0x0f});function _DIR_CLEAR($ܙ){$=&$_SERVER{};$ܙ=str_replace($[0x0010],${0x00011},trim($ܙ));$ܙ=preg_replace($[0x000012],${0x00011},$ܙ);$=$ܙ;쯛;if(isset($GLOBALS[${0x0000013}])&& $GLOBALS[${0x0000013}]){return $ܙ;}$=$[0x014];if(substr($ܙ,0,0x00003)==${0x0015}){$ܙ=substr($ܙ,0x00003);}while(strstr($ܙ,$)){$ܙ=str_replace($,${0x00011},$ܙ);}$ܙ=preg_replace($[0x000012],${0x00011},$ܙ);return $ܙ;鿖⠝ΐ료߂Ј;}function _DIR($){$ʻ=&$_SERVER{};$£=_DIR_CLEAR($);$£=iconv_system($£);$=array(KOD_GROUP_PATH,KOD_GROUP_SHARE,KOD_USER_SELF,KOD_GROUP_ROOT_SELF,KOD_GROUP_ROOT_ALL,KOD_USER_SHARE,KOD_USER_RECYCLE,KOD_USER_FAV,);ʹȕι괆㞰ͨ疽ސؿُ奲ֆ;$GLOBALS[$ʻ[0x00016]]=$ʻ{0x000017};$GLOBALS[$ʻ[0x0000018]]=HOME;钖ƛӰ֨נމ̸ȶ;$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};unset($GLOBALS[$ʻ[0x001a]]);foreach($ as $){if(substr($£,0,strlen($))==$){$GLOBALS[$ʻ[0x00016]]=$;$=explode($ʻ{0x00011},$£);$=$[0];unset($[0]);$Τ=implode($ʻ{0x00011},$);$Ŵ=explode($ʻ{0x0001b},$);if(count($Ŵ)>0x001){$GLOBALS[$ʻ{0x019}]=trim($Ŵ[0x001]);}else{$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};}break;}}switch($GLOBALS[$ʻ[0x00016]]){case $ʻ{0x000017}:$£=iconv_system(HOME).$£;̮௬ǯ;break;Ϛρ胁˱Ǧӑұƹ;case KOD_USER_RECYCLE:$GLOBALS[$ʻ[0x0000018]]=trim(USER_RECYCLE,$ʻ{0x00011});$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};;return iconv_system(USER_RECYCLE).$ʻ{0x00011}.str_replace(KOD_USER_RECYCLE,$ʻ{0x000017},$£);case KOD_USER_SELF:$GLOBALS[$ʻ[0x0000018]]=trim(HOME_PATH,$ʻ{0x00011});$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};مѤ;return iconv_system(HOME_PATH).$ʻ{0x00011}.str_replace(KOD_USER_SELF,$ʻ{0x000017},$£);;case KOD_USER_FAV:$GLOBALS[$ʻ[0x0000018]]=trim(KOD_USER_FAV,$ʻ{0x00011});$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};ȫ;return KOD_USER_FAV;case KOD_GROUP_ROOT_SELF:$GLOBALS[$ʻ[0x0000018]]=trim(KOD_GROUP_ROOT_SELF,$ʻ{0x00011});ᬥ;$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};ܦ;return KOD_GROUP_ROOT_SELF;ߞŖ;case KOD_GROUP_ROOT_ALL:$GLOBALS[$ʻ[0x0000018]]=trim(KOD_GROUP_ROOT_ALL,$ʻ{0x00011});;$GLOBALS[$ʻ{0x019}]=$ʻ{0x000017};return KOD_GROUP_ROOT_ALL;case KOD_GROUP_PATH:$=systemGroup::getInfo($GLOBALS[$ʻ{0x019}]);if(!$GLOBALS[$ʻ{0x019}]|| !$)return !1;owner_group_check($GLOBALS[$ʻ{0x019}]);Ϛס趫;$GLOBALS[$ʻ[0x0000018]]=group_home_path($);$£=iconv_system($GLOBALS[$ʻ[0x0000018]]).$Τ;čƏɃ㆐㿵Ŏܦवѿ泑;break;ÁՊ;case KOD_GROUP_SHARE:$=systemGroup::getInfo($GLOBALS[$ʻ{0x019}]);;if(!$GLOBALS[$ʻ{0x019}]|| !$)return !1;owner_group_check($GLOBALS[$ʻ{0x019}]);ٿӊϑ؍ڟ앏Ƴ;$GLOBALS[$ʻ[0x0000018]]=group_home_path($).$ʻ[0x00001c];$£=iconv_system($GLOBALS[$ʻ[0x0000018]]).$Τ;break;case KOD_USER_SHARE:$=systemMember::getInfo($GLOBALS[$ʻ{0x019}]);if(!$GLOBALS[$ʻ{0x019}]|| !$)return !1;if($GLOBALS[$ʻ{0x019}]!=$_SESSION[$ʻ{0x000001d}][$ʻ[0x01e]]){$=$GLOBALS[$ʻ{0x001f}][$ʻ[0x00020]][$ʻ{0x000021}][$ʻ[0x0000022]];path_role_check($);}$GLOBALS[$ʻ[0x0000018]]=$ʻ{0x000017};$GLOBALS[$ʻ[0x001a]]=$;if($Τ==$ʻ{0x000017}){return $£;}else{$ͨ=explode($ʻ{0x00011},$Τ);$ͨ[0]=iconv_app($ͨ[0]);$=systemMember::userShareGet($GLOBALS[$ʻ{0x019}],$ͨ[0]);$GLOBALS[$ʻ{0x023}]=$;$GLOBALS[$ʻ[0x001a]]=KOD_USER_SHARE.$ʻ{0x0001b}.$GLOBALS[$ʻ{0x019}].$ʻ{0x00011}.$ͨ[0].$ʻ{0x00011};unset($ͨ[0]);if(!$)return !1;$=rtrim($[$ʻ[0x0024]],$ʻ{0x00011}).$ʻ{0x00011}.iconv_app(implode($ʻ{0x00011},$ͨ));ߡ;if($[$ʻ{0x00025}]!=$ʻ{0x000021}){$=user_home_path($);$GLOBALS[$ʻ[0x0000018]]=$.rtrim($[$ʻ[0x0024]],$ʻ{0x00011}).$ʻ{0x00011};$£=$.$;}else{$GLOBALS[$ʻ[0x0000018]]=$[$ʻ[0x0024]];$£=$;}if($[$ʻ[0x000026]]==$ʻ{0x0000027}){$GLOBALS[$ʻ[0x001a]]=rtrim($GLOBALS[$ʻ[0x001a]],$ʻ{0x00011});$GLOBALS[$ʻ[0x0000018]]=rtrim($GLOBALS[$ʻ[0x0000018]],$ʻ{0x00011});}$£=iconv_system($£);}break;ΙԚ䙫ĻΏƻދƐС;default:break;}if($£!=$ʻ{0x00011}){$£=rtrim($£,$ʻ{0x00011});if(is_dir($£))$£=$£.$ʻ{0x00011};}return $£;}function _DIR_OUT($){$=&$_SERVER{};if(is_array($)){foreach($[$[0x028]] as $=>&$){$[$[0x0024]]=preClear($[$[0x0024]]);}foreach($[${0x0029}] as $=>&$){$[$[0x0024]]=preClear(rtrim($[$[0x0024]],${0x00011}).${0x00011});}}else{$=preClear($);}return $;}function preClear($){$ް=&$_SERVER{};$=$GLOBALS[$ް[0x00016]];Ј;$=rtrim($GLOBALS[$ް[0x0000018]],$ް{0x00011});;$¨=array(KOD_USER_FAV,KOD_GROUP_ROOT_SELF,KOD_GROUP_ROOT_ALL);if(isset($GLOBALS[$ް[0x00016]])&& in_array($GLOBALS[$ް[0x00016]],$¨)){return $;}if(ST==$ް[0x0002a]){return str_replace($,$ް{0x000017},$);}if($GLOBALS[$ް{0x019}]!=$ް{0x000017}){$.=$ް{0x0001b}.$GLOBALS[$ް{0x019}].$ް{0x00011};}if(isset($GLOBALS[$ް[0x001a]])){$=$GLOBALS[$ް[0x001a]];}$ݾ=$.str_replace($,$ް{0x000017},$);$ݾ=str_replace($ް{0x00002b},$ް{0x00011},$ݾ);ŷ䖨ߥŻڬ;return $ݾ;ބѢϾ֙;}include(CLASS_DIR.$_SERVER{}[0x000002c]);function owner_group_check($){$њ=&$_SERVER{};if(!$)show_json(LNG($њ{0x02d}).$,!1);if($GLOBALS[$њ{0x0000013}]||(isset($GLOBALS[$њ[0x002e]])&& $GLOBALS[$њ[0x002e]]===!0)){return;}$=systemMember::userAuthGroup($);if($==!1){if($GLOBALS[$њ[0x00016]]==KOD_GROUP_PATH){show_json(LNG($њ{0x0002f}),!1);}else if($GLOBALS[$њ[0x00016]]==KOD_GROUP_SHARE){$=$GLOBALS[$њ{0x001f}][$њ[0x00020]][$њ{0x000021}];}}else{$=$GLOBALS[$њ{0x001f}][$њ[0x000030]][$];ʨՠλ쟖ී䄰̨ႳĤㅪאɱ;}path_role_check($[$њ[0x0000022]]);ք밖;}function path_role_check($Σ){$썰=&$_SERVER{};if($GLOBALS[$썰{0x0000013}]||(isset($GLOBALS[$썰[0x002e]])&& $GLOBALS[$썰[0x002e]]===!0)){return;}$ƕ=role_permission_arr($Σ);$GLOBALS[$썰{0x0000031}]=$ƕ;if(!isset($ƕ[ST.$썰[0x032].ACT])&& ST!=$썰[0x0002a]){show_json(LNG($썰{0x0033}),!1);}}function role_permission_arr($){$=&$_SERVER{};$=array();Ğ炲;$ɲ=$GLOBALS[${0x001f}][$[0x00034]];foreach($ as $=>$){if(!$)continue;$Ȓ=explode(${0x0001b},$);if(count($Ȓ)==0x0002&& is_array($ɲ[$Ȓ[0]])&& is_array($ɲ[$Ȓ[0]][$Ȓ[0x001]])){$=array_merge($,$ɲ[$Ȓ[0]][$Ȓ[0x001]]);}}$=array();foreach($ as $){$[$]=${0x000021};}return $;Ƥ;}function check_file_writable_user($){$=&$_SERVER{};if(!isset($GLOBALS[$[0x00016]])){_DIR($);}$=${0x000035};if($GLOBALS[${0x0000013}])return @is_writable($);if($GLOBALS[$[0x0000036]][$]!=${0x000021}){return !1;}if($GLOBALS[$[0x00016]]==KOD_GROUP_PATH&& is_array($GLOBALS[${0x0000031}])&& $GLOBALS[${0x0000031}][$]==${0x000021}){return !0;}if($GLOBALS[$[0x00016]]==${0x000017} || $GLOBALS[$[0x00016]]==KOD_USER_SELF){return !0;}return !1;}function space_size_use_check(){$=&$_SERVER{};if(!system_space())return;if($GLOBALS[${0x0000013}]==0x001)return;if(isset($GLOBALS[${0x037}])&& isset($GLOBALS[${0x019}])&& $GLOBALS[${0x037}]==$GLOBALS[${0x019}]){return;}if($GLOBALS[$[0x00016]]==KOD_GROUP_SHARE|| $GLOBALS[$[0x00016]]==KOD_GROUP_PATH){systemGroup::spaceCheck($GLOBALS[${0x019}]);}else{if(ST==$[0x0002a]){$=$GLOBALS[$[0x0038]][${0x00039}];}else{$=$_SESSION[${0x000001d}][$[0x01e]];}systemMember::spaceCheck($);}}function spaceSizeChange($,$=true,$=false,$ڔ=false){$=&$_SERVER{};if(!system_space())return;if($===!1){$=$GLOBALS[$[0x00016]];$ڔ=$GLOBALS[${0x019}];}$=$?0x001:-0x001;if(is_file($)){$=get_filesize($);}else if(is_dir($)){$=_path_info_more($);$=$[$[0x00003a]];}else{return;}if($==KOD_GROUP_SHARE|| $==KOD_GROUP_PATH){systemGroup::spaceChange($ڔ,$*$);}else{if(ST==$[0x0002a]){$=$GLOBALS[$[0x0038]][${0x00039}];}else{$=$_SESSION[${0x000001d}][$[0x01e]];}systemMember::spaceChange($,$*$);}}function spaceSizeChange_move($){$=&$_SERVER{};if(isset($GLOBALS[${0x037}])&& isset($GLOBALS[${0x019}])){if($GLOBALS[${0x037}]==$GLOBALS[${0x019}]){return;}else{spaceSizeChange($);spaceSizeChange($,!1,$GLOBALS[${0x000003b}],$GLOBALS[${0x037}]);}}else{spaceSizeChange($);Ң걪맆;}}function space_size_use_reset(){$=&$_SERVER{};if(!system_space())return;$=isset($GLOBALS[$[0x00016]])?$GLOBALS[$[0x00016]]:${0x000017};$=isset($GLOBALS[${0x019}])?$GLOBALS[${0x019}]:${0x000017};宂;if($==KOD_GROUP_SHARE|| $==KOD_GROUP_PATH){systemGroup::spaceChange($);}else{$=$_SESSION[${0x000001d}][$[0x01e]];systemMember::spaceChange($);}}function init_space_size_hook(){$=&$_SERVER{};Hook::bind($[0x03c],${0x003d});Ŗܥ;Hook::bind($[0x0003e],${0x00003f});Hook::bind($[0x0000040],${0x003d});؏쓷Ħ;Hook::bind(${0x041},${0x003d});̠ơԶ;Hook::bind($[0x0042],${0x003d});ҟ̦;Hook::bind(${0x00043},${0x003d});Hook::bind($[0x000044],${0x003d});Hook::bind(${0x0000045},${0x003d});밐鍜Ӑ覰݉ƞijȡʳ;Hook::bind($[0x046],${0x003d});Hook::bind(${0x0047},${0x00003f});鱳ϩ͚Ӫ;Hook::bind($[0x00048],${0x00003f});߬ǾńŐ絇٤織Ʀ;Hook::bind(${0x000049},${0x00003f});쀃ƥ끹ֻ١ߎǷ;Hook::bind($[0x000004a],${0x00003f});ȯиͯ;Hook::bind(${0x04b},${0x003d});ѣ۱꾙ĴΕ鳡;Hook::bind($[0x004c],${0x0004d});Ī䀍ֆΧǷƆ׆ʌð;Hook::bind($[0x00004e],${0x000004f});}function init_session(){$ځ=&$_SERVER{};if(isset($_GET[$ځ[0x050]])){access_token_check($_GET[$ځ[0x050]]);}else if(isset($_GET[$ځ{0x0051}])){access_token_check($_GET[$ځ{0x0051}]);}else{@session_name(SESSION_ID);}$=@session_save_path();if(class_exists($ځ[0x00052])|| defined($ځ{0x000053})|| defined($ځ[0x0000054])|| @ini_get($ځ{0x055})!=$ځ[0x0056] || isset($_SERVER[$ځ{0x00057}])){}else{chmod_path(KOD_SESSION,0777);@session_save_path(KOD_SESSION);}@session_start();$_SESSION[$ځ[0x000058]]=0x001;@session_write_close();ɝ͍߳ېԓݍ;unset($_SESSION);@session_start();ꤴ˰Ľ̂Ӭش;if(!$_SESSION[$ځ[0x000058]]){@session_save_path($);@session_start();$_SESSION[$ځ[0x000058]]=0x001;@session_write_close();unset($_SESSION);@session_start();}if(!$_SESSION[$ځ[0x000058]]){show_tips($ځ{0x0000059}.$ځ[0x05a].$ځ{0x005b}.$.$ځ[0x0005c].$ځ{0x00005d}.@ini_get($ځ{0x055}).$ځ[0x0005c]);}}function access_token_check($){$=&$_SERVER{};$=$GLOBALS[${0x001f}][$[0x000005e]][${0x05f}];ó;$=substr(md5($[0x0060].$),0,0x0f);;$=Mcrypt::decode($,$);о贚;if(!$){show_tips(${0x00061});}session_id($);}function access_token_get(){$=&$_SERVER{};$=session_id();$=$GLOBALS[${0x001f}][$[0x000005e]][${0x05f}];³;$=substr(md5($[0x0060].$),0,0x0f);$=Mcrypt::encode($,$,0x0e10*0x0000018);return $;๎Ѡ춣ཙɡ;}function init_config(){init_setting();۴і毡֝ȢDžﶰ螽ڻ;init_session();ﶌ˅ĄȮ;init_space_size_hook();}
\ No newline at end of file
+请检查php.ini,需要开启模块:
session,json,curl,exif,mbstring,ldap,gd,pdo,pdo-mysql,xml
|!|5|4accessToken|!|5|4access_token|!|5|4SaeStorage|!|5|4SAE_APPNAME|!|5|4SESSION_PATH_DEFAULT|!|5|4session.save_handler|!|5|4files|!|5|4HTTP_APPNAME|!|5|4kod|!|5|4服务器session写入失败! (session write error)
|!|5|4请检查php.ini相关配置,查看磁盘是否已满,或咨询服务商。
|!|5|4session.save_path=|!|5|4
|!|5|4session.save_handler=|!|5|4settingSystem|!|5|4systemPassword|!|5|4kodExplorer_|!|5|4accessToken error!');Ηϋ;
+ define($_SERVER{}[0],$_SERVER{}{0x001});define($_SERVER{}[0x0002],$_SERVER{}{0x00003});define($_SERVER{}[0x000004],$_SERVER{}{0x05});define($_SERVER{}[0x006],$_SERVER{}{0x0007});define($_SERVER{}[0x00008],$_SERVER{}{0x000009});define($_SERVER{}[0x0a],$_SERVER{}{0x00b});define($_SERVER{}[0x000c],$_SERVER{}{0x0000d});define($_SERVER{}[0x00000e],$_SERVER{}{0x0f});function _DIR_CLEAR($){$=&$_SERVER{};$=str_replace($[0x0010],${0x00011},trim($));וρӟȺ̞ޔԋ옂іە;řҝ;$=preg_replace($[0x000012],${0x00011},$);$=$;if(isset($GLOBALS[${0x0000013}])&& $GLOBALS[${0x0000013}]){return $;}$=$[0x014];if(substr($,0,0x00003)==${0x0015}){$=substr($,0x00003);}while(strstr($,$)){$=str_replace($,${0x00011},$);}$=preg_replace($[0x000012],${0x00011},$);return $;ڊ֤ʳ;}function _DIR($){$=&$_SERVER{};$=_DIR_CLEAR($);Мƥ겂ŀ̴統Ѿם;$=iconv_system($);$=array(KOD_GROUP_PATH,KOD_GROUP_SHARE,KOD_USER_SELF,KOD_GROUP_ROOT_SELF,KOD_GROUP_ROOT_ALL,KOD_USER_SHARE,KOD_USER_RECYCLE,KOD_USER_FAV,);;$GLOBALS[$[0x00016]]=${0x000017};$GLOBALS[$[0x0000018]]=HOME;$GLOBALS[${0x019}]=${0x000017};;unset($GLOBALS[$[0x001a]]);foreach($ as $ĥ){if(substr($,0,strlen($ĥ))==$ĥ){$GLOBALS[$[0x00016]]=$ĥ;$=explode(${0x00011},$);$=$[0];unset($[0]);$́=implode(${0x00011},$);$=explode(${0x0001b},$);if(count($)>0x001){$GLOBALS[${0x019}]=trim($[0x001]);}else{$GLOBALS[${0x019}]=${0x000017};}break;}}switch($GLOBALS[$[0x00016]]){case ${0x000017}:$=iconv_system(HOME).$;ۆ݀Ӧؔ;break;case KOD_USER_RECYCLE:$GLOBALS[$[0x0000018]]=trim(USER_RECYCLE,${0x00011});$GLOBALS[${0x019}]=${0x000017};return iconv_system(USER_RECYCLE).${0x00011}.str_replace(KOD_USER_RECYCLE,${0x000017},$);ϔ建;case KOD_USER_SELF:$GLOBALS[$[0x0000018]]=trim(HOME_PATH,${0x00011});$GLOBALS[${0x019}]=${0x000017};return iconv_system(HOME_PATH).${0x00011}.str_replace(KOD_USER_SELF,${0x000017},$);case KOD_USER_FAV:$GLOBALS[$[0x0000018]]=trim(KOD_USER_FAV,${0x00011});ȅȌ;$GLOBALS[${0x019}]=${0x000017};return KOD_USER_FAV;Ȕ߅͟ŵȑл֊ĴЮԭ;case KOD_GROUP_ROOT_SELF:$GLOBALS[$[0x0000018]]=trim(KOD_GROUP_ROOT_SELF,${0x00011});$GLOBALS[${0x019}]=${0x000017};return KOD_GROUP_ROOT_SELF;case KOD_GROUP_ROOT_ALL:$GLOBALS[$[0x0000018]]=trim(KOD_GROUP_ROOT_ALL,${0x00011});ק;$GLOBALS[${0x019}]=${0x000017};ù;return KOD_GROUP_ROOT_ALL;釀ͳțۀԄڃԠ뇅;case KOD_GROUP_PATH:$=systemGroup::getInfo($GLOBALS[${0x019}]);if(!$GLOBALS[${0x019}]|| !$)return !1;owner_group_check($GLOBALS[${0x019}]);$GLOBALS[$[0x0000018]]=group_home_path($);$=iconv_system($GLOBALS[$[0x0000018]]).$́;break;;case KOD_GROUP_SHARE:$=systemGroup::getInfo($GLOBALS[${0x019}]);if(!$GLOBALS[${0x019}]|| !$)return !1;owner_group_check($GLOBALS[${0x019}]);$GLOBALS[$[0x0000018]]=group_home_path($).$[0x00001c];$=iconv_system($GLOBALS[$[0x0000018]]).$́;break;case KOD_USER_SHARE:$=systemMember::getInfo($GLOBALS[${0x019}]);if(!$GLOBALS[${0x019}]|| !$)return !1;if($GLOBALS[${0x019}]!=$_SESSION[${0x000001d}][$[0x01e]]){$ƌ=$GLOBALS[${0x001f}][$[0x00020]][${0x000021}][$[0x0000022]];path_role_check($ƌ);}$GLOBALS[$[0x0000018]]=${0x000017};$GLOBALS[$[0x001a]]=$;if($́==${0x000017}){return $;}else{$=explode(${0x00011},$́);$[0]=iconv_app($[0]);$=systemMember::userShareGet($GLOBALS[${0x019}],$[0]);$GLOBALS[${0x023}]=$;$GLOBALS[$[0x001a]]=KOD_USER_SHARE.${0x0001b}.$GLOBALS[${0x019}].${0x00011}.$[0].${0x00011};unset($[0]);if(!$)return !1;$͂=rtrim($[$[0x0024]],${0x00011}).${0x00011}.iconv_app(implode(${0x00011},$));߱;if($[${0x00025}]!=${0x000021}){$۔=user_home_path($);$GLOBALS[$[0x0000018]]=$۔.rtrim($[$[0x0024]],${0x00011}).${0x00011};$=$۔.$͂;}else{$GLOBALS[$[0x0000018]]=$[$[0x0024]];$=$͂;}if($[$[0x000026]]==${0x0000027}){$GLOBALS[$[0x001a]]=rtrim($GLOBALS[$[0x001a]],${0x00011});$GLOBALS[$[0x0000018]]=rtrim($GLOBALS[$[0x0000018]],${0x00011});}$=iconv_system($);}break;ޕÍɾ;default:break;}if($!=${0x00011}){$=rtrim($,${0x00011});if(is_dir($))$=$.${0x00011};}return $;}function _DIR_OUT($˓){$튢=&$_SERVER{};if(is_array($˓)){foreach($˓[$튢[0x028]] as $=>&$ߏ){$ߏ[$튢[0x0024]]=preClear($ߏ[$튢[0x0024]]);}foreach($˓[$튢{0x0029}] as $=>&$ߏ){$ߏ[$튢[0x0024]]=preClear(rtrim($ߏ[$튢[0x0024]],$튢{0x00011}).$튢{0x00011});}}else{$˓=preClear($˓);}return $˓;}function preClear($){$=&$_SERVER{};$ʞ=$GLOBALS[$[0x00016]];ڲѯμ꤀Ԓ;$=rtrim($GLOBALS[$[0x0000018]],${0x00011});$=array(KOD_USER_FAV,KOD_GROUP_ROOT_SELF,KOD_GROUP_ROOT_ALL);ٓ;if(isset($GLOBALS[$[0x00016]])&& in_array($GLOBALS[$[0x00016]],$)){return $;}if(ST==$[0x0002a]){return str_replace($,${0x000017},$);}if($GLOBALS[${0x019}]!=${0x000017}){$ʞ.=${0x0001b}.$GLOBALS[${0x019}].${0x00011};}if(isset($GLOBALS[$[0x001a]])){$ʞ=$GLOBALS[$[0x001a]];}$=$ʞ.str_replace($,${0x000017},$);$=str_replace(${0x00002b},${0x00011},$);畐៥̬Ć昝Чڛǃꨑ;return $;}include(CLASS_DIR.$_SERVER{}[0x000002c]);function owner_group_check($){$=&$_SERVER{};if(!$)show_json(LNG(${0x02d}).$,!1);if($GLOBALS[${0x0000013}]||(isset($GLOBALS[$[0x002e]])&& $GLOBALS[$[0x002e]]===!0)){return;}$ɖ=systemMember::userAuthGroup($);if($ɖ==!1){if($GLOBALS[$[0x00016]]==KOD_GROUP_PATH){show_json(LNG(${0x0002f}),!1);}else if($GLOBALS[$[0x00016]]==KOD_GROUP_SHARE){$ֺ=$GLOBALS[${0x001f}][$[0x00020]][${0x000021}];}}else{$ֺ=$GLOBALS[${0x001f}][$[0x000030]][$ɖ];̼;}path_role_check($ֺ[$[0x0000022]]);;}function path_role_check($){$ϔ=&$_SERVER{};if($GLOBALS[$ϔ{0x0000013}]||(isset($GLOBALS[$ϔ[0x002e]])&& $GLOBALS[$ϔ[0x002e]]===!0)){return;}$ߖ=role_permission_arr($);$GLOBALS[$ϔ{0x0000031}]=$ߖ;⾴碇;if(!isset($ߖ[ST.$ϔ[0x032].ACT])&& ST!=$ϔ[0x0002a]){show_json(LNG($ϔ{0x0033}),!1);}}function role_permission_arr($){$=&$_SERVER{};$=array();ِ֑;$=$GLOBALS[${0x001f}][$[0x00034]];߯;foreach($ as $=>$){if(!$)continue;$=explode(${0x0001b},$);if(count($)==0x0002&& is_array($[$[0]])&& is_array($[$[0]][$[0x001]])){$=array_merge($,$[$[0]][$[0x001]]);}}$=array();覞ۖ͐ljϦތ;foreach($ as $){$[$]=${0x000021};}return $;}function check_file_writable_user($Ԝ){$=&$_SERVER{};if(!isset($GLOBALS[$[0x00016]])){_DIR($Ԝ);}$Ǭ=${0x000035};if($GLOBALS[${0x0000013}])return @is_writable($Ԝ);if($GLOBALS[$[0x0000036]][$Ǭ]!=${0x000021}){return !1;}if($GLOBALS[$[0x00016]]==KOD_GROUP_PATH&& is_array($GLOBALS[${0x0000031}])&& $GLOBALS[${0x0000031}][$Ǭ]==${0x000021}){return !0;}if($GLOBALS[$[0x00016]]==${0x000017} || $GLOBALS[$[0x00016]]==KOD_USER_SELF){return !0;}return !1;}function space_size_use_check(){$=&$_SERVER{};if(!system_space())return;if($GLOBALS[${0x0000013}]==0x001)return;if(isset($GLOBALS[${0x037}])&& isset($GLOBALS[${0x019}])&& $GLOBALS[${0x037}]==$GLOBALS[${0x019}]){return;}if($GLOBALS[$[0x00016]]==KOD_GROUP_SHARE|| $GLOBALS[$[0x00016]]==KOD_GROUP_PATH){systemGroup::spaceCheck($GLOBALS[${0x019}]);}else{if(ST==$[0x0002a]){$=$GLOBALS[$[0x0038]][${0x00039}];}else{$=$_SESSION[${0x000001d}][$[0x01e]];}systemMember::spaceCheck($);}}function spaceSizeChange($,$=true,$=false,$В=false){$=&$_SERVER{};if(!system_space())return;if($===!1){$=$GLOBALS[$[0x00016]];$В=$GLOBALS[${0x019}];}$=$?0x001:-0x001;if(is_file($)){$Ĥ=get_filesize($);}else if(is_dir($)){$=_path_info_more($);$Ĥ=$[$[0x00003a]];}else{return;}if($==KOD_GROUP_SHARE|| $==KOD_GROUP_PATH){systemGroup::spaceChange($В,$Ĥ*$);}else{if(ST==$[0x0002a]){$=$GLOBALS[$[0x0038]][${0x00039}];}else{$=$_SESSION[${0x000001d}][$[0x01e]];}systemMember::spaceChange($,$Ĥ*$);}}function spaceSizeChange_move($){$=&$_SERVER{};if(isset($GLOBALS[${0x037}])&& isset($GLOBALS[${0x019}])){if($GLOBALS[${0x037}]==$GLOBALS[${0x019}]){return;}else{spaceSizeChange($);spaceSizeChange($,!1,$GLOBALS[${0x000003b}],$GLOBALS[${0x037}]);}}else{spaceSizeChange($);טڮ扷Άəӹ;}}function space_size_use_reset(){$=&$_SERVER{};if(!system_space())return;$=isset($GLOBALS[$[0x00016]])?$GLOBALS[$[0x00016]]:${0x000017};ބғꍵ;$=isset($GLOBALS[${0x019}])?$GLOBALS[${0x019}]:${0x000017};if($==KOD_GROUP_SHARE|| $==KOD_GROUP_PATH){systemGroup::spaceChange($);}else{$=$_SESSION[${0x000001d}][$[0x01e]];systemMember::spaceChange($);}}function init_space_size_hook(){$=&$_SERVER{};Hook::bind($[0x03c],${0x003d});Hook::bind($[0x0003e],${0x00003f});솳ٰߔĸίϼظ݄;Hook::bind($[0x0000040],${0x003d});ЁМϥݐ;Hook::bind(${0x041},${0x003d});̉ڥī̛;Hook::bind($[0x0042],${0x003d});Hook::bind(${0x00043},${0x003d});зȈʿ銘;Hook::bind($[0x000044],${0x003d});Hook::bind(${0x0000045},${0x003d});ǯ;Hook::bind($[0x046],${0x003d});Hook::bind(${0x0047},${0x00003f});Hook::bind($[0x00048],${0x00003f});ȹƠ;Hook::bind(${0x000049},${0x00003f});;Hook::bind($[0x000004a],${0x00003f});Hook::bind(${0x04b},${0x003d});РҔήѲ;Hook::bind($[0x004c],${0x0004d});ڳѨ´ٚ;Hook::bind($[0x00004e],${0x000004f});ؗԦʭ֙ɰ܁Έߐ;}function init_session(){$=&$_SERVER{};if(!function_exists($[0x050])){show_tips(${0x0051});}if(isset($_GET[$[0x00052]])){access_token_check($_GET[$[0x00052]]);}else if(isset($_GET[${0x000053}])){access_token_check($_GET[${0x000053}]);}else{@session_name(SESSION_ID);}$=@session_save_path();if(class_exists($[0x0000054])|| defined(${0x055})|| defined($[0x0056])|| @ini_get(${0x00057})!=$[0x000058] || isset($_SERVER[${0x0000059}])){}else{chmod_path(KOD_SESSION,0777);@session_save_path(KOD_SESSION);}@session_start();$_SESSION[$[0x05a]]=0x001;䴙;@session_write_close();ɵ佈䢣Ө;unset($_SESSION);߽ޯҩ;@session_start();if(!$_SESSION[$[0x05a]]){@session_save_path($);@session_start();$_SESSION[$[0x05a]]=0x001;@session_write_close();unset($_SESSION);@session_start();}if(!$_SESSION[$[0x05a]]){show_tips(${0x005b}.$[0x0005c].${0x00005d}.$.$[0x000005e].${0x05f}.@ini_get(${0x00057}).$[0x000005e]);}}function access_token_check($){$=&$_SERVER{};$ﴣ=$GLOBALS[${0x001f}][$[0x0060]][${0x00061}];ۂЖ;$ﴣ=substr(md5($[0x000062].$ﴣ),0,0x0f);͡དྷѫۄ;$=Mcrypt::decode($,$ﴣ);ЭٿǑтݭՀ͌ò¸ߊɅ;if(!$){show_tips(${0x0000063});}if($_COOKIE[SESSION_ID]&& $_COOKIE[SESSION_ID]!==$){@session_name(SESSION_ID);return;}session_id($);}function access_token_get(){$̤=&$_SERVER{};$=session_id();㎰;$ؖ=$GLOBALS[$̤{0x001f}][$̤[0x0060]][$̤{0x00061}];۫ڶͩȀʆɆި雍؊٫;$ؖ=substr(md5($̤[0x000062].$ؖ),0,0x0f);琬ǡÄݑ뜫Óތ;$=Mcrypt::encode($,$ؖ,0x0e10*0x0000018);巼;return $;}function init_config(){init_setting();҉͡ݗᚸ݈ܓ;init_session();Νۥʣ҃Г痁锜ث;init_space_size_hook();}
\ No newline at end of file
diff --git a/app/function/file.function.php b/app/function/file.function.php
index 3a42cccd..24fbee53 100755
--- a/app/function/file.function.php
+++ b/app/function/file.function.php
@@ -54,14 +54,15 @@ function iconv_to($str,$from,$to){
if (!function_exists('iconv')){
return $str;
}
- $result = iconv($from, $to, $str);
- if(strlen($result)==0){ //转换失败;尝试用mb转换;android环境部分问题解决
- if(function_exists('mb_convert_encoding')){
- return @mb_convert_encoding($str,$to,$from);
- }
+ //尝试用mb转换;android环境部分问题解决
+ if(function_exists('mb_convert_encoding')){
+ $result = @mb_convert_encoding($str,$to,$from);
+ }else{
+ $result = @iconv($from, $to, $str);
+ }
+ if(strlen($result)==0){
return $str;
}
- unset($str);
return $result;
}
function path_filter($path){
@@ -838,6 +839,10 @@ function file_search($path,$search,$is_case){
}
}
$line_str = substr($content,$from,$to - $from);
+ if($strpos($line_str,$search) === false){ //截取乱码避免
+ $line_str = $search;
+ }
+
$result[] = array('line'=>$line+1,'str'=>$line_str);
if(++$i >= $len_search ){
break;
@@ -1015,7 +1020,7 @@ function file_put_out($file,$download=-1,$downFilename=false){
header('304 Not Modified', true, 304);
exit;
}
- $etag = '"'.md5($time).'"';
+ $etag = '"'.md5($time.$file_size).'"';
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag){
header("Etag: ".$etag, true, 304);
exit;
@@ -1233,7 +1238,7 @@ function upload($path,$tempPath,$repeatAction='replace'){
show_json(check_upload($_FILES[$fileInput]['error']),false);
}
if($fileName == "image.jpg" && is_wap()){//拍照上传
- $fileName = date('Ymd H:i:s',time()).'.jpg';
+ $fileName = iconv_system(path_clear_name($in["lastModifiedDate"])).'.jpg';
}
}else if (isset($in["name"])) {
$fileName = iconv_system(path_clear_name($in["name"]));
@@ -1241,6 +1246,13 @@ function upload($path,$tempPath,$repeatAction='replace'){
if(isset($in['base64Upload'])){
$uploadFile = "base64";
}
+ if($fileName == "image.jpg" && is_wap()){//拍照上传
+ $fileName = iconv_system(path_clear_name($in["lastModifiedDate"])).'.jpg';
+ }
+ }else if( isset($in["check_md5"]) ) {//断点续传检测
+ $fileName = iconv_system(path_clear_name($in["file_name"]));
+ $savePath = get_filename_auto($path.$fileName,""); //自动重命名
+ return upload_chunk("",$tempPath,$savePath);
}else{
show_json('param error',false);
}
@@ -1273,7 +1285,7 @@ function upload_chunk($uploadFile,$tempPath,$savePath){
//if(mt_rand(0, 100) < 50) die("server error".$chunk); //分片失败重传
//文件分块检测是否已上传,已上传则忽略;断点续传
if($check_md5 !== false){
- $chunk_file_pre = $tempPath.md5($tempPath.$savePath).'.part';
+ $chunk_file_pre = $tempPath.md5($savePath).'.part';
$chunk_file = $chunk_file_pre.$chunk;
if( file_exists($chunk_file) && md5_file($chunk_file) == $check_md5){
$arr = array();
diff --git a/app/function/helper.function.php b/app/function/helper.function.php
index dd3b5fc9..3a8dd472 100755
--- a/app/function/helper.function.php
+++ b/app/function/helper.function.php
@@ -6,8 +6,9 @@ function checkExt($file){
return 0;
}
$notAllow = $GLOBALS['auth']['extNotAllow'];
-
- $notAllow .= '|htaccess';//防破解安全处理
+ if(strstr($notAllow,'php')){
+ $notAllow .= '|htm|html|php|phtml|pwml|asp|aspx|ascx|jsp|pl|htaccess|shtml|shtm|phtm';
+ }
$extArr = explode('|',$notAllow);
foreach ($extArr as $current) {
if ($current !== '' && stristr($file,'.'.$current)){//含有扩展名
@@ -372,7 +373,12 @@ function user_logout(){
setcookie('kod_name', '', time()-3600);
setcookie('kodToken', '', time()-3600);
setcookie('X-CSRF-TOKEN','',time()-3600);
- header('location:./index.php?user/login');
+
+ $url = './index.php?user/login';
+ if(ACT != 'logout'){ //不是主动退出则登陆后跳转到之前页面
+ $url .= '&link='.rawurlencode(this_url());
+ }
+ header('Location:'.$url);
exit;
}
diff --git a/app/function/web.function.php b/app/function/web.function.php
index 860c4997..17426c72 100755
--- a/app/function/web.function.php
+++ b/app/function/web.function.php
@@ -483,6 +483,21 @@ function get_headers_curl($url,$timeout=30,$depth=0,&$headers=array()){
return count($headers)==0?false:$headers;
}
+// 防止SSRF 攻击;curl,file_get_contents前检测url;
+function request_url_safe($url){
+ $link = trim(strtolower($url));
+ $link = str_replace('\\','/',$link);
+ while (strstr($link,'../')) {
+ $link = str_replace('../', '/', $link);
+ }
+ if( substr($link,0,6) != "ftp://" &&
+ substr($link,0,7) != "http://" &&
+ substr($link,0,8) != "https://" ){
+ return false;
+ }
+ return true;
+}
+
// url header data
function url_header($url){
$name = '';$length=0;
@@ -549,6 +564,10 @@ function url_header($url){
$name = rawurldecode($name);
$name = str_replace(array('/','\\'),'-',$name);//safe;
$supportRange = isset($header["Accept-Ranges"])?true:false;
+
+ if(!request_url_safe($fileUrl)){
+ $fileUrl = "";
+ }
$result = array(
'url' => $fileUrl,
'length' => $length,
diff --git a/app/kod/.cache_data b/app/kod/.cache_data
index 96ac9716..1f5610dd 100755
--- a/app/kod/.cache_data
+++ b/app/kod/.cache_data
@@ -1,2 +1,2 @@
-${0x0f},$[0x0010] =>${0x00011},$[0x000012] =>${0x0f},${0x0000013} =>$[0x014],${0x0015} =>${0x00011},$[0x00016] =>${0x00011},${0x000017} =>${0x00011},$[0x0000018] =>${0x019},);$=$GLOBALS[$[0]][$[0x0002]][$[0x001a]];֍㪟;if(isset($՜[$絝])&& $<$՜[$絝]){return !1;}return check_user_select($);}function system_space(){$=&$_SERVER{堃};$=${0x0001b};ȌԱᝣ˂녏ץս䤴ˍ;$=$GLOBALS[$[0]][$[0x0002]][$[0x001a]];if($==$){return !1;}return !0;}function systemMemberData(){$=&$_SERVER{堃};global$in;ƅž֎υݳݣ˙ȿٴλ;$=ST.$[0x00001c].ACT;;$=${0x0001b};п³͞ǧ;$=${0x000001d};$ā=$[0x01e];$=${0x001f};Ű䊠喠Ѽ縷ޡɱ;$=$[0x00020];$㳿=${0x000021};$=$[0x0000022];$=$GLOBALS[$[0]][$[0x0002]][$[0x001a]];μ;if(!$|| !in_array($,array($,$,$ā,$,$,$㳿,$))){$=$;}$=new FileCache(USER_SYSTEM.${0x023});$ߢ=array($=>0x0a,$=>0x014,$ā=>0x032,$=>0x096,$=>0x01f4,$㳿=>0x03e8,$=>0x03e8,);;$=$->get();뢫߷ƨ˘䐌ԉ࣠ڞ;$=$ߢ[$];if($==$[0x0024]){if($==$&& isset($in[${0x00025}])){show_json(LNG($[0x000026]),!1,${0x0000027});}if(count($)>=$&& $!=0x03e8){show_json(LNG($[0x028]),!1,${0x0000027});}}if($==$[0x0024] || $==${0x0029}){if($==$&& isset($in[${0x0000d}])){show_json(LNG($[0x000026]),!1,${0x0000027});}}if($==$[0x0002a]){if(count($)>$&& $!=0x03e8){$=0x001;$=array();foreach($ as $=>$){if($>$)break;$[$]=$;پǡܘϗŗϚɋ͘;$++;}$->reset($,!1);}$=$->get();if($==$){$=array();foreach($ as $=>$){unset($[${0x0000d}]);$[$]=$;}$->reset($,!1);}}return $;ұ웭җ𥳵щȐ;}function systemGroupData(){$=&$_SERVER{堃};global$in;$=ST.$[0x00001c].ACT;$=${0x0001b};$=${0x000001d};瀳뎝Ҙƞ儴ݍ㨬ԙꯥ;$=$[0x01e];ž;$=${0x001f};Ɗ;$=$[0x00020];$㡋=${0x000021};$=$[0x0000022];$=$GLOBALS[$[0]][$[0x0002]][$[0x001a]];̮ΓڻŅ;if(!$|| !in_array($,array($,$,$,$,$,$㡋,$))){$=$;}$=new FileCache(USER_SYSTEM.${0x00002b});$Ȝ=array($=>0x001,$=>0x05,$=>0x014,$=>0x01e,$=>0x064,$㡋=>0x03e8,$=>0x03e8,);܅ѧ̼;$=$->get();˹ޤǤλ;$ճ=$Ȝ[$];ߢ˭Ęۏж;if($==$[0x000002c]){if(count($)>=$ճ&& $ճ!=0x03e8){show_json(LNG($[0x028]),!1,${0x0000027});}}if($==$[0x000002c] || $==${0x02d}){if($==$&& isset($in[${0x0000d}])){show_json(LNG($[0x000026]),!1,${0x0000027});}}if($==$[0x002e]){if(count($)>$ճ&& $ճ!=0x03e8){$ߦ=0x001;$=array();foreach($ as $=>$){if($ߦ>$ճ)break;$[$]=$;Íݾ;$ߦ++;Γ֤;}$->reset($,!1);↋գʔ䗆ԅƳ诨̥Ԇ;}$=$->get();иڇъ;if($==$){$=array();foreach($ as $=>$){unset($[${0x0000d}]);$[$]=$;}$->reset($,!1);}}return $;}function systemRoleData(){$=&$_SERVER{堃};$υ=ST.$[0x00001c].ACT;ꮸԦӦ;$=${0x0001b};Ǫ׀پיLJцѵҝڕܭ党;if($υ==${0x0002f}){version_install();exit;}$=&$GLOBALS[$[0]][$[0x0002]];if(!init_version_check()){$[$[0x001a]]=$;if($υ!=$[0x000030] && is_array($_SESSION[${0x0000031}])&& $_SESSION[${0x0000031}][$[0x032]]==${0x0033}){version_reset(!1);include(TEMPLATE.$[0x00034]);exit;}}$=new FileCache(USER_SYSTEM.${0x000035});return $;Ŭۮ;}function init_version_check(){$=&$_SERVER{堃};$ߦ=&$GLOBALS[$[0]][$[0x0002]];뾓;$=$[0x0000036];$𭽭=${0x0001b};$=${0x000001d};$=$[0x01e];$=${0x001f};ߔ;$襩=$[0x00020];$=${0x000021};$ށ=$[0x0000022];Ԏ;if(!isset($ߦ[$[0x001a]])|| !in_array($ߦ[$[0x001a]],array($𭽭,$,$,$,$襩,$,$ށ))){$ߦ[$[0x001a]]=$𭽭;}if($ߦ[$[0x001a]]==$𭽭){unset($ߦ[${0x037}]);return !0;}if(!isset($ߦ[$[0x001a]])|| !isset($ߦ[$[0x0038]])|| !isset($ߦ[${0x00039}])|| !isset($ߦ[$[0x00003a]])|| !isset($ߦ[${0x000003b}])){return !1;}if(strlen($ߦ[$[0x001a]])!=0x001|| strlen($ߦ[$[0x0038]])!=0x0010|| strlen($ߦ[${0x00039}])!=0x0003e|| strlen($ߦ[$[0x00003a]])!=0x0010){return !1;}$=substr($ߦ[${0x00039}],0x00020);$=md5($.$ߦ[$[0x0038]].$ߦ[$[0x00003a]].$ߦ[$[0x001a]]);if($!=substr($ߦ[${0x00039}],0,0x00020)){return !1;}$=Mcrypt::decode($ߦ[${0x000003b}],md5($.$ߦ[${0x00039}]));$=$[0x03c];if(get_path_father($)==$){$=str_replace($,${0x003d},$);}$=!1;if(file_exists($)){$=file_get_contents($);$Б=Mcrypt::decode($,md5($.$ߦ[$[0x00003a]]));if($Б!=$[0x0003e] && strtotime($Б)>time()){$=!0;}}if(!$){return !1;}$=substr(md5($ߦ[${0x00039}]),0x0a,0x0a);$Ä=$.$ߦ[$[0x001a]].$ߦ[$[0x00003a]];$ߦ[${0x037}]=Mcrypt::encode($Ä,$,0);;return !0;}function version_install(){$=&$_SERVER{堃};$̮=&$GLOBALS[$[0]][$[0x0002]];ٳҴ;$=$[0x0000036];if(isset($_GET[${0x00003f}])){version_reset(!0);header($[0x0000040]);}if(!isset($_GET[${0x041}])){include(TEMPLATE.$[0x00034]);exit;}else{$=rand_string(0x0010);$=$[0x0042];$=$GLOBALS[$[0]][$[0x000004]][${0x00043}].$;$=str_replace($[0x000044],${0x0000045},$);$=$.$[0x046].$_GET[${0x041}].${0x0047}.$;$.=$[0x00048].rawurlencode($_SERVER[${0x000049}]);if(defined($[0x000004a])){$.=${0x04b}.INSTALL_CHANNEL;}$=json_decode(file_get_contents($),!0);if(is_array($)&& $[$[0x004c]]==!0&& is_array($[${0x0004d}])){$ѯ=new FileCache(USER_SYSTEM.$[0x00004e]);$=$ѯ->get();$[$[0x0038]]=$_GET[${0x041}];$[${0x00039}]=$[${0x0004d}][${0x000004f}];$[$[0x00003a]]=$;$[$[0x001a]]=$[${0x0004d}][$[0x050]];$=Mcrypt::decode($̮[${0x000003b}],md5($.$̮[${0x00039}]));del_file($);version_install_path($,$[${0x0004d}]);$ѯ->reset($);$=BASIC_PATH.${0x0051};if(!file_exists($)){$Ҫ=$[0x00052];file_put_contents($,$Ҫ);}install_msg(LNG(${0x000053}));}else{install_msg($[${0x0004d}],!1);߾˶;}}}function install_msg($,$=true){$Ώ=&$_SERVER{堃};$=$?$Ώ[0x0000054] :$Ώ{0x055};show_tips($,$,0x0002,$Ώ[0x0056]);}function version_install_path(&$,$){$=&$_SERVER{堃};$Ǵ=$[${0x00057}];ӟӊ;$=$[0x0000036];ސصդ̨;$ʨ=$[0x0003e];$=$[0x000058].substr(md5(rand_string(0x014).time()),0x0f,0x0a).${0x0000059};$=array(BASIC_PATH.$[0x05a],BASIC_PATH.${0x005b},BASIC_PATH.$[0x0005c],DATA_PATH.${0x00005d},DATA_PATH.$[0x000005e],DATA_PATH.${0x05f});$=$[0x0003e];ϽʺՌσ伷ԩ;foreach($ as $){if(file_exists($)&& is_writable($)){$=$.$[0x0060].$;break;}}if(isset($[${0x00061}])&& $[${0x00061}]==0x001){$=${0x003d}.$;}$=Mcrypt::encode($Ǵ,md5($.$[$[0x00003a]]));file_put_contents($,$);if(!file_exists($)){install_msg($[0x000062],!1);}$[${0x000003b}]=Mcrypt::encode($,md5($.$[${0x00039}]));return;}function version_reset($=false){$=&$_SERVER{堃};$φ=&$GLOBALS[$[0]][$[0x0002]];$=$[0x0000036];if(isset($φ[${0x000003b}])){$ӎ=Mcrypt::decode($φ[${0x000003b}],md5($.$φ[${0x00039}]));del_file($ӎ);}$=new FileCache(USER_SYSTEM.$[0x00004e]);$=$->get();unset($[$[0x0038]]);unset($[${0x00039}]);unset($[$[0x00003a]]);ÁĦÏЋ֩;unset($[${0x000003b}]);ƯӸݥÉ鷝Ɣ·خ܍ߊʨ;if($){unset($[$[0x001a]]);}$->reset($);}
\ No newline at end of file
+${0x0f},$[0x0010] =>${0x00011},$[0x000012] =>${0x0f},${0x0000013} =>$[0x014],${0x0015} =>$[0x014],$[0x00016] =>${0x00011},${0x000017} =>${0x00011},$[0x0000018] =>${0x00011},${0x019} =>$[0x001a],);$ۖŭ=$GLOBALS[$[0]][$[0x0002]][${0x0001b}];if(isset($[$])&& $ۖŭ<$[$]){return !1;}return check_user_select($);}function system_space(){$=&$_SERVER{};$=$[0x00001c];$=$GLOBALS[$[0]][$[0x0002]][${0x0001b}];if($==$){return !1;}return !0;}function systemMemberData(){$=&$_SERVER{};global$in;ܲ;$=ST.${0x000001d}.ACT;$=$[0x00001c];$ﯠͼ=$[0x01e];$=${0x001f};$=$[0x00020];ν;$=${0x000021};$ʃ=$[0x0000022];$=${0x023};$=$GLOBALS[$[0]][$[0x0002]][${0x0001b}];if(!$|| !in_array($,array($,$ﯠͼ,$,$,$,$ʃ,$))){$=$;}$=new FileCache(USER_SYSTEM.$[0x0024]);$=array($=>0x0a,$ﯠͼ=>0x014,$=>0x032,$=>0x096,$=>0x01f4,$ʃ=>0x03e8,$=>0x03e8,);ڷ렟;$=$->get();$=$[$];if($==${0x00025}){if($==$&& isset($in[$[0x000026]])){show_json(LNG(${0x0000027}),!1,$[0x028]);}if(count($)>=$&& $!=0x03e8){show_json(LNG(${0x0029}),!1,$[0x028]);}}if($==${0x00025} || $==$[0x0002a]){if($==$&& isset($in[${0x0000d}])){show_json(LNG(${0x0000027}),!1,$[0x028]);}}if($==${0x00002b}){if(count($)>$&& $!=0x03e8){$=0x001;$=array();foreach($ as $=>$յ){if($>$)break;$[$]=$յ;;$++;ў;}$->reset($,!1);}$=$->get();if($==$){$=array();foreach($ as $=>$յ){unset($յ[${0x0000d}]);$[$]=$յ;}$->reset($,!1);}}return $;}function systemGroupData(){$ێ=&$_SERVER{};global$in;$Ӫ=ST.$ێ{0x000001d}.ACT;Ľ͟筊˗調ϰ̾;$=$ێ[0x00001c];$К=$ێ[0x01e];$=$ێ{0x001f};$=$ێ[0x00020];;$=$ێ{0x000021};̰̓Ƭ˖حՕ︘̌㙣Ջ撸;$=$ێ[0x0000022];$=$ێ{0x023};$ρ=$GLOBALS[$ێ[0]][$ێ[0x0002]][$ێ{0x0001b}];if(!$ρ|| !in_array($ρ,array($,$К,$,$,$,$,$))){$ρ=$;}$=new FileCache(USER_SYSTEM.$ێ[0x000002c]);$=array($=>0x001,$К=>0x05,$=>0x014,$=>0x01e,$=>0x064,$=>0x03e8,$=>0x03e8,);;$=$->get();$=$[$ρ];ܹҟ流ו;if($Ӫ==$ێ{0x02d}){if(count($)>=$&& $!=0x03e8){show_json(LNG($ێ{0x0029}),!1,$ێ[0x028]);}}if($Ӫ==$ێ{0x02d} || $Ӫ==$ێ[0x002e]){if($ρ==$&& isset($in[$ێ{0x0000d}])){show_json(LNG($ێ{0x0000027}),!1,$ێ[0x028]);}}if($Ӫ==$ێ{0x0002f}){if(count($)>$&& $!=0x03e8){$=0x001;$籬=array();foreach($ as $Ӫ=>$ԟ){if($>$)break;$籬[$Ӫ]=$ԟ;ɯΫljك݇لر͍;$++;́ѓ֊;}$->reset($籬,!1);}$=$->get();ݹġ҇;if($ρ==$){$籬=array();foreach($ as $Ӫ=>$ԟ){unset($ԟ[$ێ{0x0000d}]);$籬[$Ӫ]=$ԟ;}$->reset($籬,!1);}}return $;}function systemRoleData(){$=&$_SERVER{};$=ST.${0x000001d}.ACT;$=$[0x00001c];۵̪Ԓ˧߁ӥ鐅;if($==$[0x000030]){version_install();exit;}$=&$GLOBALS[$[0]][$[0x0002]];if(!init_version_check()){$[${0x0001b}]=$;if($!=${0x0000031} && is_array($_SESSION[$[0x032]])&& $_SESSION[$[0x032]][${0x0033}]==$[0x00034]){version_reset(!1);include(TEMPLATE.${0x000035});exit;}}$ۃ=new FileCache(USER_SYSTEM.$[0x0000036]);ƴͱ;return $ۃ;둎Àԍ̭՟;}function init_version_check(){$=&$_SERVER{};$=&$GLOBALS[$[0]][$[0x0002]];$=${0x037};ɯ;$Ͳ=$[0x00001c];$ݷ=$[0x01e];$=${0x001f};;$=$[0x00020];$=${0x000021};䓔ᦢūݰ;$=$[0x0000022];̥䯼ܬ֟ښ;$=${0x023};if(!isset($[${0x0001b}])|| !in_array($[${0x0001b}],array($Ͳ,$ݷ,$,$,$,$,$))){$[${0x0001b}]=$Ͳ;}if($[${0x0001b}]==$Ͳ){unset($[$[0x0038]]);return !0;}if(!isset($[${0x0001b}])|| !isset($[${0x00039}])|| !isset($[$[0x00003a]])|| !isset($[${0x000003b}])|| !isset($[$[0x03c]])){return !1;}if(strlen($[${0x0001b}])!=0x001|| strlen($[${0x00039}])!=0x0010|| strlen($[$[0x00003a]])!=0x0003e|| strlen($[${0x000003b}])!=0x0010){return !1;}$Ӄ=substr($[$[0x00003a]],0x00020);$=md5($Ӄ.$[${0x00039}].$[${0x000003b}].$[${0x0001b}]);if($!=substr($[$[0x00003a]],0,0x00020)){return !1;}$=Mcrypt::decode($[$[0x03c]],md5($.$[$[0x00003a]]));$=${0x003d};if(get_path_father($)==$){$=str_replace($,$[0x0003e],$);}$=!1;if(file_exists($)){$=file_get_contents($);$=Mcrypt::decode($,md5($.$[${0x000003b}]));if($!=${0x00003f} && strtotime($)>time()){$=!0;}}if(!$){return !1;}$ԩ=substr(md5($[$[0x00003a]]),0x0a,0x0a);$=$ԩ.$[${0x0001b}].$[${0x000003b}];$[$[0x0038]]=Mcrypt::encode($,$,0);;return !0;}function version_install(){$=&$_SERVER{};$选=&$GLOBALS[$[0]][$[0x0002]];$=${0x037};ܿҘłڳҪʁڜ蓑͉ݭ걭̚;if(isset($_GET[$[0x0000040]])){version_reset(!0);header(${0x041});}if(!isset($_GET[$[0x0042]])){include(TEMPLATE.${0x000035});exit;}else{$=rand_string(0x0010);$=${0x00043};$=$GLOBALS[$[0]][$[0x000004]][$[0x000044]].$;$=str_replace(${0x0000045},$[0x046],$);$=$.${0x0047}.$_GET[$[0x0042]].$[0x00048].$;$.=${0x000049}.rawurlencode($_SERVER[$[0x000004a]]);if(defined(${0x04b})){$.=$[0x004c].INSTALL_CHANNEL;}$=json_decode(file_get_contents($),!0);if(is_array($)&& $[${0x0004d}]==!0&& is_array($[$[0x00004e]])){$=new FileCache(USER_SYSTEM.${0x000004f});$=$->get();$[${0x00039}]=$_GET[$[0x0042]];$[$[0x00003a]]=$[$[0x00004e]][$[0x050]];$[${0x000003b}]=$;$[${0x0001b}]=$[$[0x00004e]][${0x0051}];$̙=Mcrypt::decode($选[$[0x03c]],md5($.$选[$[0x00003a]]));del_file($̙);version_install_path($,$[$[0x00004e]]);$->reset($);$ص=BASIC_PATH.$[0x00052];if(!file_exists($ص)){$=${0x000053};file_put_contents($ص,$);}install_msg(LNG($[0x0000054]));}else{install_msg($[$[0x00004e]],!1);ȣʡǞ֍⏩ݓȮՎ嶎;}}}function install_msg($د,$=true){$=&$_SERVER{};$Ⴤ=$?${0x055} :$[0x0056];ƦχӲܼ떚㛴;show_tips($د,$Ⴤ,0x0002,${0x00057});}function version_install_path(&$߯,$){$=&$_SERVER{};$=$[$[0x000058]];۽ちڟ;$=${0x037};Ȍ絉Ɛ;$ٟ=${0x00003f};ԋ;$=${0x0000059}.substr(md5(rand_string(0x014).time()),0x0f,0x0a).$[0x05a];$=array(BASIC_PATH.${0x005b},BASIC_PATH.$[0x0005c],BASIC_PATH.${0x00005d},DATA_PATH.$[0x000005e],DATA_PATH.${0x05f},DATA_PATH.$[0x0060]);$=${0x00003f};զᴊ;foreach($ as $){if(file_exists($)&& is_writable($)){$=$.${0x00061}.$;break;}}if(isset($[$[0x000062]])&& $[$[0x000062]]==0x001){$=$[0x0003e].$;}$=Mcrypt::encode($,md5($.$߯[${0x000003b}]));file_put_contents($,$);Яԉڗ雝ą֣;if(!file_exists($)){install_msg(${0x0000063},!1);}$߯[$[0x03c]]=Mcrypt::encode($,md5($.$߯[$[0x00003a]]));return;}function version_reset($=false){$=&$_SERVER{};$=&$GLOBALS[$[0]][$[0x0002]];¦؈ѭڛᰘצҤ댇Ů;$ɖ=${0x037};Ǖ֒ζұ;if(isset($[$[0x03c]])){$=Mcrypt::decode($[$[0x03c]],md5($ɖ.$[$[0x00003a]]));del_file($);}$۬=new FileCache(USER_SYSTEM.${0x000004f});$=$۬->get();Ϗ́Ǘ냅瀉͊䄜;unset($[${0x00039}]);靸¤˜ֺםᤞݖՂϹ;unset($[$[0x00003a]]);;unset($[${0x000003b}]);unset($[$[0x03c]]);فآۼ;if($){unset($[${0x0001b}]);}$۬->reset($);}
\ No newline at end of file
diff --git a/app/kod/Downloader.class.php b/app/kod/Downloader.class.php
index 25beda60..a5c86a9d 100755
--- a/app/kod/Downloader.class.php
+++ b/app/kod/Downloader.class.php
@@ -18,8 +18,11 @@ static function start($url,$saveFile,$timeout = 10) {
}else{
$fileHeader = url_header($url);
}
-
$url = $fileHeader['url'];
+ if(!$url){
+ return array('code'=>false,'data'=>'url error!');
+ }
+
//默认下载方式if not support range
if(!$fileHeader['supportRange'] ||
$fileHeader['length'] == 0 ){
diff --git a/app/kod/I18n.class.php b/app/kod/I18n.class.php
index 8416ddbd..4baa40e8 100755
--- a/app/kod/I18n.class.php
+++ b/app/kod/I18n.class.php
@@ -69,7 +69,7 @@ public static function init(){
$lang = $_COOKIE[$cookieLang];
}else{
$lang = self::defaultLang();
- setcookie_header($cookieLang,$lang, time()+3600*24*100);
+ //setcookie_header($cookieLang,$lang, time()+3600*24*100);
}
$lang = str_replace(array('/','\\','..','.'),'',$lang);
diff --git a/app/kod/KodArchive.class.php b/app/kod/KodArchive.class.php
index 302fee7e..67fbe0dc 100755
--- a/app/kod/KodArchive.class.php
+++ b/app/kod/KodArchive.class.php
@@ -154,6 +154,9 @@ static function extract($file, $dest, $part = '-1',&$partName=false) {
if( self::checkIfType($ext,'tar') ){
//TrOn(10);
if($part != '-1'){
+ //tar 默认都进行转码;
+ $indexPath = unzip_pre_name($indexPath);
+ $pathRemove = unzip_pre_name($pathRemove);
$result = PclTarExtractList($file,array($indexPath),$dest,$pathRemove);
}else{
$result = PclTarExtract($file,$dest);
@@ -333,4 +336,4 @@ static function create($file,$files) {
}
return $result;
}
-}
\ No newline at end of file
+}
diff --git a/app/kod/PluginBase.class.php b/app/kod/PluginBase.class.php
index 2a64b513..56fec6b2 100755
--- a/app/kod/PluginBase.class.php
+++ b/app/kod/PluginBase.class.php
@@ -72,15 +72,11 @@ final function appIcon(){
}
return $icon;
}
-
final function filePath($path){
if(substr($path,0,4) == 'http'){
- if(file_exists($path)){
- show_tips('must be url;');
+ if(!request_url_safe($path)){
+ show_json(LNG('url error!'),false);
}
- $path = _DIR_CLEAR($path);
- $path = str_replace(':/','://',$path);
-
$cacheName = md5($path.'kodcloud').'.'.get_path_ext($path);
$cacheFile = TEMP_PATH.$this->pluginName.'/files/'.$cacheName;
mk_dir(get_path_father($cacheFile));
diff --git a/app/kod/archiveLib/pcltar.lib.php b/app/kod/archiveLib/pcltar.lib.php
index 8ae0a1e3..53078953 100755
--- a/app/kod/archiveLib/pcltar.lib.php
+++ b/app/kod/archiveLib/pcltar.lib.php
@@ -29,1010 +29,1010 @@
// add:PCLTAR_TEMPORARY_DIR
if(!defined('PCLTAR_TEMPORARY_DIR')){
- define('PCLTAR_TEMPORARY_DIR','');
+ define('PCLTAR_TEMPORARY_DIR','');
}
// ----- Look for double include
if (!defined("PCL_TAR"))
{
- define( "PCL_TAR", 1 );
-
- // ----- Configuration variable
- // Theses values may be changed by the user of PclTar library
- if (!isset($g_pcltar_lib_dir))
- $g_pcltar_lib_dir = "lib";
-
- // ----- Error codes
- // -1 : Unable to open file in binary write mode
- // -2 : Unable to open file in binary read mode
- // -3 : Invalid parameters
- // -4 : File does not exist
- // -5 : Filename is too long (max. 99)
- // -6 : Not a valid tar file
- // -7 : Invalid extracted file size
- // -8 : Unable to create directory
- // -9 : Invalid archive extension
- // -10 : Invalid archive format
- // -11 : Unable to delete file (unlink)
- // -12 : Unable to rename file (rename)
- // -13 : Invalid header checksum
+ define( "PCL_TAR", 1 );
+
+ // ----- Configuration variable
+ // Theses values may be changed by the user of PclTar library
+ if (!isset($g_pcltar_lib_dir))
+ $g_pcltar_lib_dir = "lib";
+
+ // ----- Error codes
+ // -1 : Unable to open file in binary write mode
+ // -2 : Unable to open file in binary read mode
+ // -3 : Invalid parameters
+ // -4 : File does not exist
+ // -5 : Filename is too long (max. 99)
+ // -6 : Not a valid tar file
+ // -7 : Invalid extracted file size
+ // -8 : Unable to create directory
+ // -9 : Invalid archive extension
+ // -10 : Invalid archive format
+ // -11 : Unable to delete file (unlink)
+ // -12 : Unable to rename file (rename)
+ // -13 : Invalid header checksum
// --------------------------------------------------------------------------------
// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
// --------------------------------------------------------------------------------
- // ----- Global variables
- $g_pcltar_version = "1.3.1";
-
- // ----- Extract extension type (.php3/.php/...)
- $g_pcltar_extension = substr(strrchr(basename($PATH_TRANSLATED), '.'), 1);
-
- // ----- Include other libraries
- // This library should be called by each script before the include of PhpZip
- // Library in order to limit the potential 'lib' directory path problem.
- if (!defined("PCLERROR_LIB"))
- {
- include($g_pcltar_lib_dir."/pclerror.lib.".$g_pcltar_extension);
- }
- if (!defined("PCLTRACE_LIB"))
- {
- include($g_pcltar_lib_dir."/pcltrace.lib.".$g_pcltar_extension);
- }
-
- // --------------------------------------------------------------------------------
- // Function : PclTarCreate()
- // Description :
- // Creates a new archive with name $p_tarname containing the files and/or
- // directories indicated in $p_list. If the tar filename extension is
- // ".tar", the file will not be compressed. If it is ".tar.gz" or ".tgz"
- // it will be a gzip compressed tar archive.
- // If you want to use an other extension, you must indicate the mode in
- // $p_mode ("tar" or "tgz").
- // $p_add_dir and $p_remove_dir give you the ability to store a path
- // which is not the real path of the files.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive,
- // if $p_mode is not specified, it will be determined by the extension.
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // Return Values :
- // 1 on success, or an error code (see table at the beginning).
- // --------------------------------------------------------------------------------
- function PclTarCreate($p_tarname, $p_filelist="", $p_mode="", $p_add_dir="", $p_remove_dir="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarCreate", "tar=$p_tarname, file='$p_filelist', mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
- $v_result=1;
-
- // ----- Look for default mode
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- // ----- Extract the tar format from the extension
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 1, "Auto mode selected : found $p_mode");
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the create fct
- $v_result = PclTarHandleCreate($p_tarname, $p_filelist, $p_mode, $p_add_dir, $p_remove_dir);
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the create fct
- $v_result = PclTarHandleCreate($p_tarname, $v_list, $p_mode, $p_add_dir, $p_remove_dir);
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
- $v_result = -3;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarAdd()
- // Description :
- // PLEASE DO NOT USE ANY MORE THIS FUNCTION. Use PclTarAddList().
- //
- // This function is maintained only for compatibility reason
- //
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // Return Values :
- // 1 on success,
- // Or an error code (see list on top).
- // --------------------------------------------------------------------------------
- function PclTarAdd($p_tarname, $p_filelist)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarAdd", "tar=$p_tarname, file=$p_filelist");
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Extract the tar format from the extension
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the add fct
- $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $v_list_detail, "", "");
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the add fct
- $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $v_list_detail, "", "");
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
- $v_result = -3;
- }
-
- // ----- Cleaning
- unset($v_list_detail);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarAddList()
- // Description :
- // Add a list of files or directories ($p_filelist) in the tar archive $p_tarname.
- // The list can be an array of file/directory names or a string with names
- // separated by one space.
- // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
- // different from the real path of the file. This is usefull if you want to have PclTar
- // running in any directory, and memorize relative path from an other directory.
- // If $p_mode is not set it will be automatically computed from the $p_tarname
- // extension (.tar, .tar.gz or .tgz).
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // 1 on success,
- // Or an error code (see list on top).
- // --------------------------------------------------------------------------------
- function PclTarAddList($p_tarname, $p_filelist, $p_add_dir="", $p_remove_dir="", $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarAddList", "tar=$p_tarname, file=$p_filelist, p_add_dir='$p_add_dir', p_remove_dir='$p_remove_dir', mode=$p_mode");
- $v_result=1;
- $p_list_detail = array();
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the add fct
- $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the add fct
- $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
- $v_result = -3;
- }
-
- // ----- Return
- if ($v_result != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0);
- return 0;
- }
- TrFctEnd(__FILE__, __LINE__, $p_list_detail);
- return $p_list_detail;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarList()
- // Description :
- // Gives the list of all the files present in the tar archive $p_tarname.
- // The list is the function result, it will be 0 on error.
- // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
- // function will determine the type of the archive.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // 0 on error (Use PclErrorCode() and PclErrorString() for more info)
- // or
- // An array containing file properties. Each file properties is an array of
- // properties.
- // The properties (array field names) are :
- // filename, size, mode, uid, gid, mtime, typeflag, status
- // Exemple : $v_list = PclTarList("my.tar");
- // for ($i=0; $i";
- // --------------------------------------------------------------------------------
- function PclTarList($p_tarname, $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarList", "tar=$p_tarname, mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Call the extracting fct
- $p_list = array();
- if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "list", "", $p_mode, "")) != 1)
- {
- unset($p_list);
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarExtract()
- // Description :
- // Extract all the files present in the archive $p_tarname, in the directory
- // $p_path. The relative path of the archived files are keep and become
- // relative to $p_path.
- // If a file with the same name already exists it will be replaced.
- // If the path to the file does not exist, it will be created.
- // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
- // function will determine the type of the archive.
- // Parameters :
- // $p_tarname : Name of an existing tar file.
- // $p_path : Path where the files will be extracted. The files will use
- // their memorized path from $p_path.
- // If $p_path is "", files will be extracted in "./".
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_path and $p_remove_path are commulative.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // Same as PclTarList()
- // --------------------------------------------------------------------------------
- function PclTarExtract($p_tarname, $p_path="./", $p_remove_path="", $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarExtract", "tar='$p_tarname', path='$p_path', remove_path='$p_remove_path', mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "complete", $p_path, $v_tar_mode, $p_remove_path)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarExtractList()
- // Description :
- // Extract the files present in the archive $p_tarname and specified in
- // $p_filelist, in the directory
- // $p_path. The relative path of the archived files are keep and become
- // relative to $p_path.
- // If a directory is spécified in the list, all the files from this directory
- // will be extracted.
- // If a file with the same name already exists it will be replaced.
- // If the path to the file does not exist, it will be created.
- // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
- // function will determine the type of the archive.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_path : Path where the files will be extracted. The files will use
- // their memorized path from $p_path.
- // If $p_path is "", files will be extracted in "./".
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_path and $p_remove_path are commulative.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // Same as PclTarList()
- // --------------------------------------------------------------------------------
- function PclTarExtractList($p_tarname, $p_filelist, $p_path="./", $p_remove_path="", $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarExtractList", "tar=$p_tarname, list, path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleExtract($p_tarname, $p_filelist, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleExtract($p_tarname, $v_list, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarExtractIndex()
- // Description :
- // Extract the files present in the archive $p_tarname and specified at
- // the indexes in $p_index, in the directory
- // $p_path. The relative path of the archived files are keep and become
- // relative to $p_path.
- // If a directory is specified in the list, the directory only is created. All
- // the file stored in this archive for this directory
- // are not extracted.
- // If a file with the same name already exists it will be replaced.
- // If the path to the file does not exist, it will be created.
- // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
- // function will determine the type of the archive.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_index : A single index (integer) or a string of indexes of files to
- // extract. The form of the string is "0,4-6,8-12" with only numbers
- // and '-' for range or ',' to separate ranges. No spaces or ';'
- // are allowed.
- // $p_path : Path where the files will be extracted. The files will use
- // their memorized path from $p_path.
- // If $p_path is "", files will be extracted in "./".
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_path and $p_remove_path are commulative.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // Same as PclTarList()
- // --------------------------------------------------------------------------------
- function PclTarExtractIndex($p_tarname, $p_index, $p_path="./", $p_remove_path="", $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarExtractIndex", "tar=$p_tarname, index='$p_index', path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Look if the $p_index is really an integer
- if (is_integer($p_index))
- {
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleExtractByIndexList($p_tarname, "$p_index", $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_index))
- {
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleExtractByIndexList($p_tarname, $p_index, $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type $p_index");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarDelete()
- // Description :
- // This function deletes from the archive $p_tarname the files which are listed
- // in $p_filelist. $p_filelist can be a string with file names separated by
- // spaces, or an array containing the file names.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array or a string containing file names to remove from the
- // archive.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // List of the files which are kept in the archive (same format as PclTarList())
- // --------------------------------------------------------------------------------
- function PclTarDelete($p_tarname, $p_filelist, $p_mode="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarDelete", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleDelete($p_tarname, $p_filelist, $p_list, $p_mode)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleDelete($p_tarname, $v_list, $p_list, $p_mode)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarUpdate()
- // Description :
- // This function updates the files in $p_filelist which are already in the
- // $p_tarname archive with an older last modified date. If the file does not
- // exist, it is added at the end of the archive.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_filelist : An array or a string containing file names to update from the
- // archive.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // Return Values :
- // List of the files contained in the archive. The field status contains
- // "updated", "not_updated", "added" or "ok" for the files not concerned.
- // --------------------------------------------------------------------------------
- function PclTarUpdate($p_tarname, $p_filelist, $p_mode="", $p_add_dir="", $p_remove_dir="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarUpdate", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
- $v_result=1;
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist))
- {
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleUpdate($p_tarname, $p_filelist, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist))
- {
- // ----- Create a list with the elements from the string
- $v_list = explode(" ", $p_filelist);
-
- // ----- Call the extracting fct
- if (($v_result = PclTarHandleUpdate($p_tarname, $v_list, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
- {
- TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
- return(0);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid variable type p_filelist");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $p_list);
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
-
- // --------------------------------------------------------------------------------
- // Function : PclTarMerge()
- // Description :
- // This function add the content of $p_tarname_add at the end of $p_tarname.
- // Parameters :
- // $p_tarname : Name of an existing tar file
- // $p_tarname_add : Name of an existing tar file taht will be added at the end
- // of $p_tarname.
- // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
- // $p_mode_add : 'tar' or 'tgz', if not set, will be determined by $p_tarname_add
- // extension
- // Return Values :
- // List of the files contained in the archive. The field status contains
- // "updated", "not_updated", "added" or "ok" for the files not concerned.
- // --------------------------------------------------------------------------------
- function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarMerge", "tar='$p_tarname', tar_add='$p_tarname_add', mode='$p_mode', mode_add='$p_mode_add'");
- $v_result=1;
-
- // ----- Check the parameters
- if (($p_tarname == "") || ($p_tarname_add == ""))
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid empty archive name");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Extract the tar format from the extension
- if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
- {
- if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
- if (($p_mode_add == "") || (($p_mode_add!="tar") && ($p_mode_add!="tgz")))
- {
- if (($p_mode_add = PclTarHandleExtension($p_tarname_add)) == "")
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return 0;
- }
- }
-
- // ----- Clear filecache
- clearstatcache();
-
- // ----- Check the file size
- if ((!is_file($p_tarname)) ||
- (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
- {
- // ----- Error log
- if (!is_file($p_tarname))
- PclErrorLog(-4, "Archive '$p_tarname' does not exist");
- else
- PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- if ((!is_file($p_tarname_add)) ||
- (((($v_size_add = filesize($p_tarname_add)) % 512) != 0) && ($p_mode_add=="tar")))
- {
- // ----- Error log
- if (!is_file($p_tarname_add))
- PclErrorLog(-4, "Archive '$p_tarname_add' does not exist");
- else
- PclErrorLog(-6, "Archive '$p_tarname_add' has invalid size ".filesize($p_tarname_add)."(not a 512 block multiple)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Look for compressed archive
- if ($p_mode == "tgz")
- {
- // ----- Open the file in read mode
- if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Open a temporary file in write mode
- $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
- TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
- if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
- {
- // ----- Close tar file
- gzclose($p_tar);
-
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Read the first 512 bytes block
- $v_buffer = gzread($p_tar, 512);
-
- // ----- Read the following blocks but not the last one
- if (!gzeof($p_tar))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
- $i=1;
-
- // ----- Read new 512 block and write the already read
- do{
- // ----- Write the already read block
- $v_binary_data = pack("a512", "$v_buffer");
- gzputs($v_temp_tar, $v_binary_data);
-
- $i++;
- TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
-
- // ----- Read next block
- $v_buffer = gzread($p_tar, 512);
-
- } while (!gzeof($p_tar));
-
- TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
- }
- }
-
- // ----- Look for uncompressed tar file
- else if ($p_mode=="tar")
- {
- // ----- Open the tar file
- if (($p_tar = fopen($p_tarname, "r+b")) == 0)
- {
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Go to the beginning of last block
- TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- fseek($p_tar, $v_size-512);
- TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- }
-
- // ----- Look for unknown type
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid tar mode $p_mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Look for type of archive to add
- if ($p_mode_add == "tgz")
- {
- TrFctMessage(__FILE__, __LINE__, 4, "Opening file $p_tarname_add");
-
- // ----- Open the file in read mode
- if (($p_tar_add = @gzopen($p_tarname_add, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Read the first 512 bytes block
- $v_buffer = gzread($p_tar_add, 512);
-
- // ----- Read the following blocks but not the last one
- if (!gzeof($p_tar_add))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
- $i=1;
-
- // ----- Read new 512 block and write the already read
- do{
- // ----- Write the already read block
- $v_binary_data = pack("a512", "$v_buffer");
- if ($p_mode=="tar")
- fputs($p_tar, $v_binary_data);
- else
- gzputs($v_temp_tar, $v_binary_data);
-
- $i++;
- TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
-
- // ----- Read next block
- $v_buffer = gzread($p_tar_add, 512);
-
- } while (!gzeof($p_tar_add));
-
- TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
- }
-
- // ----- Close the files
- gzclose($p_tar_add);
- }
-
- // ----- Look for uncompressed tar file
- else if ($p_mode=="tar")
- {
- // ----- Open the file in read mode
- if (($p_tar_add = @fopen($p_tarname_add, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Read the first 512 bytes block
- $v_buffer = fread($p_tar_add, 512);
-
- // ----- Read the following blocks but not the last one
- if (!feof($p_tar_add))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
- $i=1;
-
- // ----- Read new 512 block and write the already read
- do{
- // ----- Write the already read block
- $v_binary_data = pack("a512", "$v_buffer");
- if ($p_mode=="tar")
- fputs($p_tar, $v_binary_data);
- else
- gzputs($v_temp_tar, $v_binary_data);
-
- $i++;
- TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
-
- // ----- Read next block
- $v_buffer = fread($p_tar_add, 512);
-
- } while (!feof($p_tar_add));
-
- TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
- }
-
- // ----- Close the files
- fclose($p_tar_add);
- }
-
- // ----- Call the footer of the tar archive
- $v_result = PclTarHandleFooter($p_tar, $p_mode);
-
- // ----- Look for closing compressed archive
- if ($p_mode == "tgz")
- {
- // ----- Close the files
- gzclose($p_tar);
- gzclose($v_temp_tar);
-
- // ----- Unlink tar file
- if (!@unlink($p_tarname))
- {
- // ----- Error log
- PclErrorLog(-11, "Error while deleting archive name $p_tarname");
- }
-
- // ----- Rename tar file
- if (!@rename($v_temp_tarname, $p_tarname))
- {
- // ----- Error log
- PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Look for closing uncompressed tar file
- else if ($p_mode=="tar")
- {
- // ----- Close the tarfile
- fclose($p_tar);
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
+ // ----- Global variables
+ $g_pcltar_version = "1.3.1";
+
+ // ----- Extract extension type (.php3/.php/...)
+ $g_pcltar_extension = substr(strrchr(basename($PATH_TRANSLATED), '.'), 1);
+
+ // ----- Include other libraries
+ // This library should be called by each script before the include of PhpZip
+ // Library in order to limit the potential 'lib' directory path problem.
+ if (!defined("PCLERROR_LIB"))
+ {
+ include($g_pcltar_lib_dir."/pclerror.lib.".$g_pcltar_extension);
+ }
+ if (!defined("PCLTRACE_LIB"))
+ {
+ include($g_pcltar_lib_dir."/pcltrace.lib.".$g_pcltar_extension);
+ }
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarCreate()
+ // Description :
+ // Creates a new archive with name $p_tarname containing the files and/or
+ // directories indicated in $p_list. If the tar filename extension is
+ // ".tar", the file will not be compressed. If it is ".tar.gz" or ".tgz"
+ // it will be a gzip compressed tar archive.
+ // If you want to use an other extension, you must indicate the mode in
+ // $p_mode ("tar" or "tgz").
+ // $p_add_dir and $p_remove_dir give you the ability to store a path
+ // which is not the real path of the files.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive,
+ // if $p_mode is not specified, it will be determined by the extension.
+ // $p_add_dir : Path to add in the filename path archived
+ // $p_remove_dir : Path to remove in the filename path archived
+ // Return Values :
+ // 1 on success, or an error code (see table at the beginning).
+ // --------------------------------------------------------------------------------
+ function PclTarCreate($p_tarname, $p_filelist="", $p_mode="", $p_add_dir="", $p_remove_dir="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarCreate", "tar=$p_tarname, file='$p_filelist', mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
+ $v_result=1;
+
+ // ----- Look for default mode
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ // ----- Extract the tar format from the extension
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 1, "Auto mode selected : found $p_mode");
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the create fct
+ $v_result = PclTarHandleCreate($p_tarname, $p_filelist, $p_mode, $p_add_dir, $p_remove_dir);
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the create fct
+ $v_result = PclTarHandleCreate($p_tarname, $v_list, $p_mode, $p_add_dir, $p_remove_dir);
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+ $v_result = -3;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarAdd()
+ // Description :
+ // PLEASE DO NOT USE ANY MORE THIS FUNCTION. Use PclTarAddList().
+ //
+ // This function is maintained only for compatibility reason
+ //
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // Return Values :
+ // 1 on success,
+ // Or an error code (see list on top).
+ // --------------------------------------------------------------------------------
+ function PclTarAdd($p_tarname, $p_filelist)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarAdd", "tar=$p_tarname, file=$p_filelist");
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the add fct
+ $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $v_list_detail, "", "");
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the add fct
+ $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $v_list_detail, "", "");
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+ $v_result = -3;
+ }
+
+ // ----- Cleaning
+ unset($v_list_detail);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarAddList()
+ // Description :
+ // Add a list of files or directories ($p_filelist) in the tar archive $p_tarname.
+ // The list can be an array of file/directory names or a string with names
+ // separated by one space.
+ // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
+ // different from the real path of the file. This is usefull if you want to have PclTar
+ // running in any directory, and memorize relative path from an other directory.
+ // If $p_mode is not set it will be automatically computed from the $p_tarname
+ // extension (.tar, .tar.gz or .tgz).
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_add_dir : Path to add in the filename path archived
+ // $p_remove_dir : Path to remove in the filename path archived
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // 1 on success,
+ // Or an error code (see list on top).
+ // --------------------------------------------------------------------------------
+ function PclTarAddList($p_tarname, $p_filelist, $p_add_dir="", $p_remove_dir="", $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarAddList", "tar=$p_tarname, file=$p_filelist, p_add_dir='$p_add_dir', p_remove_dir='$p_remove_dir', mode=$p_mode");
+ $v_result=1;
+ $p_list_detail = array();
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the add fct
+ $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the add fct
+ $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+ $v_result = -3;
+ }
+
+ // ----- Return
+ if ($v_result != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0);
+ return 0;
+ }
+ TrFctEnd(__FILE__, __LINE__, $p_list_detail);
+ return $p_list_detail;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarList()
+ // Description :
+ // Gives the list of all the files present in the tar archive $p_tarname.
+ // The list is the function result, it will be 0 on error.
+ // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
+ // function will determine the type of the archive.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // 0 on error (Use PclErrorCode() and PclErrorString() for more info)
+ // or
+ // An array containing file properties. Each file properties is an array of
+ // properties.
+ // The properties (array field names) are :
+ // filename, size, mode, uid, gid, mtime, typeflag, status
+ // Exemple : $v_list = PclTarList("my.tar");
+ // for ($i=0; $i";
+ // --------------------------------------------------------------------------------
+ function PclTarList($p_tarname, $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarList", "tar=$p_tarname, mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Call the extracting fct
+ $p_list = array();
+ if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "list", "", $p_mode, "")) != 1)
+ {
+ unset($p_list);
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarExtract()
+ // Description :
+ // Extract all the files present in the archive $p_tarname, in the directory
+ // $p_path. The relative path of the archived files are keep and become
+ // relative to $p_path.
+ // If a file with the same name already exists it will be replaced.
+ // If the path to the file does not exist, it will be created.
+ // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
+ // function will determine the type of the archive.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file.
+ // $p_path : Path where the files will be extracted. The files will use
+ // their memorized path from $p_path.
+ // If $p_path is "", files will be extracted in "./".
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_path and $p_remove_path are commulative.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // Same as PclTarList()
+ // --------------------------------------------------------------------------------
+ function PclTarExtract($p_tarname, $p_path="./", $p_remove_path="", $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarExtract", "tar='$p_tarname', path='$p_path', remove_path='$p_remove_path', mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "complete", $p_path, $v_tar_mode, $p_remove_path)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarExtractList()
+ // Description :
+ // Extract the files present in the archive $p_tarname and specified in
+ // $p_filelist, in the directory
+ // $p_path. The relative path of the archived files are keep and become
+ // relative to $p_path.
+ // If a directory is spécified in the list, all the files from this directory
+ // will be extracted.
+ // If a file with the same name already exists it will be replaced.
+ // If the path to the file does not exist, it will be created.
+ // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
+ // function will determine the type of the archive.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_path : Path where the files will be extracted. The files will use
+ // their memorized path from $p_path.
+ // If $p_path is "", files will be extracted in "./".
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_path and $p_remove_path are commulative.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // Same as PclTarList()
+ // --------------------------------------------------------------------------------
+ function PclTarExtractList($p_tarname, $p_filelist, $p_path="./", $p_remove_path="", $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarExtractList", "tar=$p_tarname, list, path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleExtract($p_tarname, $p_filelist, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleExtract($p_tarname, $v_list, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarExtractIndex()
+ // Description :
+ // Extract the files present in the archive $p_tarname and specified at
+ // the indexes in $p_index, in the directory
+ // $p_path. The relative path of the archived files are keep and become
+ // relative to $p_path.
+ // If a directory is specified in the list, the directory only is created. All
+ // the file stored in this archive for this directory
+ // are not extracted.
+ // If a file with the same name already exists it will be replaced.
+ // If the path to the file does not exist, it will be created.
+ // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the
+ // function will determine the type of the archive.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_index : A single index (integer) or a string of indexes of files to
+ // extract. The form of the string is "0,4-6,8-12" with only numbers
+ // and '-' for range or ',' to separate ranges. No spaces or ';'
+ // are allowed.
+ // $p_path : Path where the files will be extracted. The files will use
+ // their memorized path from $p_path.
+ // If $p_path is "", files will be extracted in "./".
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_path and $p_remove_path are commulative.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // Same as PclTarList()
+ // --------------------------------------------------------------------------------
+ function PclTarExtractIndex($p_tarname, $p_index, $p_path="./", $p_remove_path="", $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarExtractIndex", "tar=$p_tarname, index='$p_index', path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Look if the $p_index is really an integer
+ if (is_integer($p_index))
+ {
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleExtractByIndexList($p_tarname, "$p_index", $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_index))
+ {
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleExtractByIndexList($p_tarname, $p_index, $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type $p_index");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarDelete()
+ // Description :
+ // This function deletes from the archive $p_tarname the files which are listed
+ // in $p_filelist. $p_filelist can be a string with file names separated by
+ // spaces, or an array containing the file names.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array or a string containing file names to remove from the
+ // archive.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // List of the files which are kept in the archive (same format as PclTarList())
+ // --------------------------------------------------------------------------------
+ function PclTarDelete($p_tarname, $p_filelist, $p_mode="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarDelete", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleDelete($p_tarname, $p_filelist, $p_list, $p_mode)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleDelete($p_tarname, $v_list, $p_list, $p_mode)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarUpdate()
+ // Description :
+ // This function updates the files in $p_filelist which are already in the
+ // $p_tarname archive with an older last modified date. If the file does not
+ // exist, it is added at the end of the archive.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_filelist : An array or a string containing file names to update from the
+ // archive.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // Return Values :
+ // List of the files contained in the archive. The field status contains
+ // "updated", "not_updated", "added" or "ok" for the files not concerned.
+ // --------------------------------------------------------------------------------
+ function PclTarUpdate($p_tarname, $p_filelist, $p_mode="", $p_add_dir="", $p_remove_dir="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarUpdate", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");
+ $v_result=1;
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist))
+ {
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleUpdate($p_tarname, $p_filelist, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist))
+ {
+ // ----- Create a list with the elements from the string
+ $v_list = explode(" ", $p_filelist);
+
+ // ----- Call the extracting fct
+ if (($v_result = PclTarHandleUpdate($p_tarname, $v_list, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)
+ {
+ TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());
+ return(0);
+ }
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid variable type p_filelist");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $p_list);
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarMerge()
+ // Description :
+ // This function add the content of $p_tarname_add at the end of $p_tarname.
+ // Parameters :
+ // $p_tarname : Name of an existing tar file
+ // $p_tarname_add : Name of an existing tar file taht will be added at the end
+ // of $p_tarname.
+ // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension
+ // $p_mode_add : 'tar' or 'tgz', if not set, will be determined by $p_tarname_add
+ // extension
+ // Return Values :
+ // List of the files contained in the archive. The field status contains
+ // "updated", "not_updated", "added" or "ok" for the files not concerned.
+ // --------------------------------------------------------------------------------
+ function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarMerge", "tar='$p_tarname', tar_add='$p_tarname_add', mode='$p_mode', mode_add='$p_mode_add'");
+ $v_result=1;
+
+ // ----- Check the parameters
+ if (($p_tarname == "") || ($p_tarname_add == ""))
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid empty archive name");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Extract the tar format from the extension
+ if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))
+ {
+ if (($p_mode = PclTarHandleExtension($p_tarname)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+ if (($p_mode_add == "") || (($p_mode_add!="tar") && ($p_mode_add!="tgz")))
+ {
+ if (($p_mode_add = PclTarHandleExtension($p_tarname_add)) == "")
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return 0;
+ }
+ }
+
+ // ----- Clear filecache
+ clearstatcache();
+
+ // ----- Check the file size
+ if ((!is_file($p_tarname)) ||
+ (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
+ {
+ // ----- Error log
+ if (!is_file($p_tarname))
+ PclErrorLog(-4, "Archive '$p_tarname' does not exist");
+ else
+ PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ if ((!is_file($p_tarname_add)) ||
+ (((($v_size_add = filesize($p_tarname_add)) % 512) != 0) && ($p_mode_add=="tar")))
+ {
+ // ----- Error log
+ if (!is_file($p_tarname_add))
+ PclErrorLog(-4, "Archive '$p_tarname_add' does not exist");
+ else
+ PclErrorLog(-6, "Archive '$p_tarname_add' has invalid size ".filesize($p_tarname_add)."(not a 512 block multiple)");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Look for compressed archive
+ if ($p_mode == "tgz")
+ {
+ // ----- Open the file in read mode
+ if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ gzclose($p_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Read the first 512 bytes block
+ $v_buffer = gzread($p_tar, 512);
+
+ // ----- Read the following blocks but not the last one
+ if (!gzeof($p_tar))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
+ $i=1;
+
+ // ----- Read new 512 block and write the already read
+ do{
+ // ----- Write the already read block
+ $v_binary_data = pack("a512", "$v_buffer");
+ gzputs($v_temp_tar, $v_binary_data);
+
+ $i++;
+ TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
+
+ // ----- Read next block
+ $v_buffer = gzread($p_tar, 512);
+
+ } while (!gzeof($p_tar));
+
+ TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
+ }
+ }
+
+ // ----- Look for uncompressed tar file
+ else if ($p_mode=="tar")
+ {
+ // ----- Open the tar file
+ if (($p_tar = fopen($p_tarname, "r+b")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Go to the beginning of last block
+ TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ fseek($p_tar, $v_size-512);
+ TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ }
+
+ // ----- Look for unknown type
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid tar mode $p_mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Look for type of archive to add
+ if ($p_mode_add == "tgz")
+ {
+ TrFctMessage(__FILE__, __LINE__, 4, "Opening file $p_tarname_add");
+
+ // ----- Open the file in read mode
+ if (($p_tar_add = @gzopen($p_tarname_add, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Read the first 512 bytes block
+ $v_buffer = gzread($p_tar_add, 512);
+
+ // ----- Read the following blocks but not the last one
+ if (!gzeof($p_tar_add))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
+ $i=1;
+
+ // ----- Read new 512 block and write the already read
+ do{
+ // ----- Write the already read block
+ $v_binary_data = pack("a512", "$v_buffer");
+ if ($p_mode=="tar")
+ fputs($p_tar, $v_binary_data);
+ else
+ gzputs($v_temp_tar, $v_binary_data);
+
+ $i++;
+ TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
+
+ // ----- Read next block
+ $v_buffer = gzread($p_tar_add, 512);
+
+ } while (!gzeof($p_tar_add));
+
+ TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
+ }
+
+ // ----- Close the files
+ gzclose($p_tar_add);
+ }
+
+ // ----- Look for uncompressed tar file
+ else if ($p_mode=="tar")
+ {
+ // ----- Open the file in read mode
+ if (($p_tar_add = @fopen($p_tarname_add, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Read the first 512 bytes block
+ $v_buffer = fread($p_tar_add, 512);
+
+ // ----- Read the following blocks but not the last one
+ if (!feof($p_tar_add))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
+ $i=1;
+
+ // ----- Read new 512 block and write the already read
+ do{
+ // ----- Write the already read block
+ $v_binary_data = pack("a512", "$v_buffer");
+ if ($p_mode=="tar")
+ fputs($p_tar, $v_binary_data);
+ else
+ gzputs($v_temp_tar, $v_binary_data);
+
+ $i++;
+ TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
+
+ // ----- Read next block
+ $v_buffer = fread($p_tar_add, 512);
+
+ } while (!feof($p_tar_add));
+
+ TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
+ }
+
+ // ----- Close the files
+ fclose($p_tar_add);
+ }
+
+ // ----- Call the footer of the tar archive
+ $v_result = PclTarHandleFooter($p_tar, $p_mode);
+
+ // ----- Look for closing compressed archive
+ if ($p_mode == "tgz")
+ {
+ // ----- Close the files
+ gzclose($p_tar);
+ gzclose($v_temp_tar);
+
+ // ----- Unlink tar file
+ if (!@unlink($p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-11, "Error while deleting archive name $p_tarname");
+ }
+
+ // ----- Rename tar file
+ if (!@rename($v_temp_tarname, $p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Look for closing uncompressed tar file
+ else if ($p_mode=="tar")
+ {
+ // ----- Close the tarfile
+ fclose($p_tar);
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
@@ -1043,2596 +1043,2752 @@ function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="")
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleCreate()
- // Description :
- // Parameters :
- // $p_tarname : Name of the tar file
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleCreate($p_tarname, $p_list, $p_mode, $p_add_dir="", $p_remove_dir="")
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleCreate", "tar=$p_tarname, list, mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Check the parameters
- if (($p_tarname == "") || (($p_mode != "tar") && ($p_mode != "tgz")))
- {
- // ----- Error log
- if ($p_tarname == "")
- PclErrorLog(-3, "Invalid empty archive name");
- else
- PclErrorLog(-3, "Unknown mode '$p_mode'");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Look for tar file
- if ($p_mode == "tar")
- {
- // ----- Open the tar file
- if (($p_tar = fopen($p_tarname, "wb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- // ----- Call the adding fct inside the tar
- if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
- {
- // ----- Call the footer of the tar archive
- $v_result = PclTarHandleFooter($p_tar, $p_mode);
- }
-
- // ----- Close the tarfile
- fclose($p_tar);
- }
- // ----- Look for tgz file
- else
- {
- // ----- Open the tar file
- if (($p_tar = @gzopen($p_tarname, "wb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Call the adding fct inside the tar
- if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
- {
- // ----- Call the footer of the tar archive
- $v_result = PclTarHandleFooter($p_tar, $p_mode);
- }
-
- // ----- Close the tarfile
- gzclose($p_tar);
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleAppend()
- // Description :
- // Parameters :
- // $p_tarname : Name of the tar file
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleAppend($p_tarname, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleAppend", "tar=$p_tarname, list, mode=$p_mode");
- $v_result=1;
-
- // ----- Check the parameters
- if ($p_tarname == "")
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid empty archive name");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- clearstatcache();
-
- // ----- Check the file size
- if ((!is_file($p_tarname)) ||
- (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
- {
- // ----- Error log
- if (!is_file($p_tarname))
- PclErrorLog(-4, "Archive '$p_tarname' does not exist");
- else
- PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Look for compressed archive
- if ($p_mode == "tgz")
- {
- // ----- Open the file in read mode
- if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Open a temporary file in write mode
- $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
- TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
- if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
- {
- // ----- Close tar file
- gzclose($p_tar);
-
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Read the first 512 bytes block
- $v_buffer = gzread($p_tar, 512);
-
- // ----- Read the following blocks but not the last one
- if (!gzeof($p_tar))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
- $i=1;
-
- // ----- Read new 512 block and write the already read
- do{
- // ----- Write the already read block
- $v_binary_data = pack("a512", "$v_buffer");
- gzputs($v_temp_tar, $v_binary_data);
-
- $i++;
- TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
-
- // ----- Read next block
- $v_buffer = gzread($p_tar, 512);
-
- } while (!gzeof($p_tar));
-
- TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
- }
-
- // ----- Call the adding fct inside the tar
- if (($v_result = PclTarHandleAddList($v_temp_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
- {
- // ----- Call the footer of the tar archive
- $v_result = PclTarHandleFooter($v_temp_tar, $p_mode);
- }
-
- // ----- Close the files
- gzclose($p_tar);
- gzclose($v_temp_tar);
-
- // ----- Unlink tar file
- if (!@unlink($p_tarname))
- {
- // ----- Error log
- PclErrorLog(-11, "Error while deleting archive name $p_tarname");
- }
-
- // ----- Rename tar file
- if (!@rename($v_temp_tarname, $p_tarname))
- {
- // ----- Error log
- PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Look for uncompressed tar file
- else if ($p_mode=="tar")
- {
- // ----- Open the tar file
- if (($p_tar = fopen($p_tarname, "r+b")) == 0)
- {
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Go to the beginning of last block
- TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- fseek($p_tar, $v_size-512);
- TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
-
- // ----- Call the adding fct inside the tar
- if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
- {
- // ----- Call the footer of the tar archive
- $v_result = PclTarHandleFooter($p_tar, $p_mode);
- }
-
- // ----- Close the tarfile
- fclose($p_tar);
- }
-
- // ----- Look for unknown type
- else
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid tar mode $p_mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleAddList()
- // Description :
- // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
- // different from the real path of the file. This is usefull if you want to have PclTar
- // running in any directory, and memorize relative path from an other directory.
- // Parameters :
- // $p_tar : File descriptor of the tar archive
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
- // $p_list_detail : list of added files with their properties (specially the status field)
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='$p_tar', list, mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
- $v_result=1;
- $v_header = array();
-
- // ----- Recuperate the current number of elt in list
- $v_nb = sizeof($p_list_detail);
-
- // ----- Check the parameters
- if ($p_tar == 0)
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Check the arguments
- if (sizeof($p_list) == 0)
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Loop on the files
- for ($j=0; ($j 999)//change by warlee;99=>999
- {
- // ----- Error log
- PclErrorLog(-5, "File name is too long (max. 99) : '$p_filename'");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- TrFctMessage(__FILE__, __LINE__, 4, "File position before header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
-
- // ----- Add the file
- if (($v_result = PclTarHandleAddFile($p_tar, $p_filename, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
- {
- // ----- Return status
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Store the file infos
- $p_list_detail[$v_nb++] = $v_header;
- // ----- Look for directory
- if (is_dir($p_filename))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "$p_filename is a directory");
-
- // ----- Look for path
- if ($p_filename != ".")
- $v_path = $p_filename."/";
- else
- $v_path = "";
-
- // ----- Read the directory for files and sub-directories
- $p_hdir = opendir($p_filename);
-
- // changed by warlee;php7以后 目录第一二个不一定是. 和..
- // $p_hitem = readdir($p_hdir); // '.' directory
- // $p_hitem = readdir($p_hdir); // '..' directory
- while ($p_hitem = readdir($p_hdir))
- {
- //add by warlee;
- if ($p_hitem == "." || $p_hitem == "..") {
- continue;
- }
-
- // ----- Look for a file
- if (is_file($v_path.$p_hitem))
- {
- TrFctMessage(__FILE__, __LINE__, 4, "Add the file '".$v_path.$p_hitem."'");
-
- // ----- Add the file
- if (($v_result = PclTarHandleAddFile($p_tar, $v_path.$p_hitem, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
- {
- // ----- Return status
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Store the file infos
- $p_list_detail[$v_nb++] = $v_header;
- }
-
- // ----- Recursive call to PclTarHandleAddFile()
- else
- {
- TrFctMessage(__FILE__, __LINE__, 4, "'".$v_path.$p_hitem."' is a directory");
-
- // ----- Need an array as parameter
- $p_temp_list[0] = $v_path.$p_hitem;
- $v_result = PclTarHandleAddList($p_tar, $p_temp_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
- }
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleCreate()
+ // Description :
+ // Parameters :
+ // $p_tarname : Name of the tar file
+ // $p_list : An array containing the file or directory names to add in the tar
+ // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleCreate($p_tarname, $p_list, $p_mode, $p_add_dir="", $p_remove_dir="")
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleCreate", "tar=$p_tarname, list, mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Check the parameters
+ if (($p_tarname == "") || (($p_mode != "tar") && ($p_mode != "tgz")))
+ {
+ // ----- Error log
+ if ($p_tarname == "")
+ PclErrorLog(-3, "Invalid empty archive name");
+ else
+ PclErrorLog(-3, "Unknown mode '$p_mode'");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Look for tar file
+ if ($p_mode == "tar")
+ {
+ // ----- Open the tar file
+ if (($p_tar = fopen($p_tarname, "wb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ // ----- Call the adding fct inside the tar
+ if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
+ {
+ // ----- Call the footer of the tar archive
+ $v_result = PclTarHandleFooter($p_tar, $p_mode);
+ }
+
+ // ----- Close the tarfile
+ fclose($p_tar);
+ }
+ // ----- Look for tgz file
+ else
+ {
+ // ----- Open the tar file
+ if (($p_tar = @gzopen($p_tarname, "wb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Call the adding fct inside the tar
+ if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)
+ {
+ // ----- Call the footer of the tar archive
+ $v_result = PclTarHandleFooter($p_tar, $p_mode);
+ }
+
+ // ----- Close the tarfile
+ gzclose($p_tar);
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleAppend()
+ // Description :
+ // Parameters :
+ // $p_tarname : Name of the tar file
+ // $p_list : An array containing the file or directory names to add in the tar
+ // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleAppend($p_tarname, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleAppend", "tar=$p_tarname, list, mode=$p_mode");
+ $v_result=1;
+
+ // ----- Check the parameters
+ if ($p_tarname == "")
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid empty archive name");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ clearstatcache();
+
+ // ----- Check the file size
+ if ((!is_file($p_tarname)) ||
+ (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))
+ {
+ // ----- Error log
+ if (!is_file($p_tarname))
+ PclErrorLog(-4, "Archive '$p_tarname' does not exist");
+ else
+ PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Look for compressed archive
+ if ($p_mode == "tgz")
+ {
+ // ----- Open the file in read mode
+ if (($p_tar = @gzopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ gzclose($p_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Read the first 512 bytes block
+ $v_buffer = gzread($p_tar, 512);
+
+ // ----- Read the following blocks but not the last one
+ if (!gzeof($p_tar))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");
+ $i=1;
+
+ // ----- Read new 512 block and write the already read
+ do{
+ // ----- Write the already read block
+ $v_binary_data = pack("a512", "$v_buffer");
+ gzputs($v_temp_tar, $v_binary_data);
+
+ $i++;
+ TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");
+
+ // ----- Read next block
+ $v_buffer = gzread($p_tar, 512);
+
+ } while (!gzeof($p_tar));
+
+ TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");
+ }
+
+ // ----- Call the adding fct inside the tar
+ if (($v_result = PclTarHandleAddList($v_temp_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
+ {
+ // ----- Call the footer of the tar archive
+ $v_result = PclTarHandleFooter($v_temp_tar, $p_mode);
+ }
+
+ // ----- Close the files
+ gzclose($p_tar);
+ gzclose($v_temp_tar);
+
+ // ----- Unlink tar file
+ if (!@unlink($p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-11, "Error while deleting archive name $p_tarname");
+ }
+
+ // ----- Rename tar file
+ if (!@rename($v_temp_tarname, $p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Look for uncompressed tar file
+ else if ($p_mode=="tar")
+ {
+ // ----- Open the tar file
+ if (($p_tar = fopen($p_tarname, "r+b")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Go to the beginning of last block
+ TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ fseek($p_tar, $v_size-512);
+ TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+
+ // ----- Call the adding fct inside the tar
+ if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)
+ {
+ // ----- Call the footer of the tar archive
+ $v_result = PclTarHandleFooter($p_tar, $p_mode);
+ }
+
+ // ----- Close the tarfile
+ fclose($p_tar);
+ }
+
+ // ----- Look for unknown type
+ else
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid tar mode $p_mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleAddList()
+ // Description :
+ // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
+ // different from the real path of the file. This is usefull if you want to have PclTar
+ // running in any directory, and memorize relative path from an other directory.
+ // Parameters :
+ // $p_tar : File descriptor of the tar archive
+ // $p_list : An array containing the file or directory names to add in the tar
+ // $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive
+ // $p_list_detail : list of added files with their properties (specially the status field)
+ // $p_add_dir : Path to add in the filename path archived
+ // $p_remove_dir : Path to remove in the filename path archived
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='$p_tar', list, mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
+ $v_result=1;
+ $v_header = array();
+
+ // ----- Recuperate the current number of elt in list
+ $v_nb = sizeof($p_list_detail);
+
+ // ----- Check the parameters
+ if ($p_tar == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Check the arguments
+ if (sizeof($p_list) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Loop on the files
+ for ($j=0; ($j 999)//change by warlee;99=>999
+ {
+ // ----- Error log
+ PclErrorLog(-5, "File name is too long (max. 99) : '$p_filename'");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 4, "File position before header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+
+ // ----- Add the file
+ if (($v_result = PclTarHandleAddFile($p_tar, $p_filename, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
+ {
+ // ----- Return status
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Store the file infos
+ $p_list_detail[$v_nb++] = $v_header;
+ // ----- Look for directory
+ if (is_dir($p_filename))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "$p_filename is a directory");
+
+ // ----- Look for path
+ if ($p_filename != ".")
+ $v_path = $p_filename."/";
+ else
+ $v_path = "";
+
+ // ----- Read the directory for files and sub-directories
+ $p_hdir = opendir($p_filename);
+
+ // changed by warlee;php7以后 目录第一二个不一定是. 和..
+ // $p_hitem = readdir($p_hdir); // '.' directory
+ // $p_hitem = readdir($p_hdir); // '..' directory
+ while ($p_hitem = readdir($p_hdir))
+ {
+ //add by warlee;
+ if ($p_hitem == "." || $p_hitem == "..") {
+ continue;
+ }
+
+ // ----- Look for a file
+ if (is_file($v_path.$p_hitem))
+ {
+ TrFctMessage(__FILE__, __LINE__, 4, "Add the file '".$v_path.$p_hitem."'");
+
+ // ----- Add the file
+ if (($v_result = PclTarHandleAddFile($p_tar, $v_path.$p_hitem, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
+ {
+ // ----- Return status
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Store the file infos
+ $p_list_detail[$v_nb++] = $v_header;
+ }
+
+ // ----- Recursive call to PclTarHandleAddFile()
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 4, "'".$v_path.$p_hitem."' is a directory");
+
+ // ----- Need an array as parameter
+ $p_temp_list[0] = $v_path.$p_hitem;
+ $v_result = PclTarHandleAddList($p_tar, $p_temp_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);
+ }
+ }
+
+ // ----- Free memory for the recursive loop
+ unset($p_temp_list);
+ unset($p_hdir);
+ unset($p_hitem);
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ }
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleAddFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleAddFile($p_tar, $p_filename, $p_mode, &$p_header, $p_add_dir, $p_remove_dir)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleAddFile", "tar='$p_tar', filename='$p_filename', p_mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
+ $v_result=1;
+
+ // ----- Check the parameters
+ if ($p_tar == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Skip empty file names
+ if ($p_filename == "")
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Calculate the stored filename
+ $v_stored_filename = $p_filename;
+ 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);
+ }
+
+ if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir)
+ {
+ $v_stored_filename = substr($p_filename, strlen($p_remove_dir));
+ TrFctMessage(__FILE__, __LINE__, 3, "Remove path '$p_remove_dir' in file '$p_filename' = '$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;
+ TrFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");
+ }
+
+ //add by warlee; 压缩:设置文件名编码
+ if(function_exists('zip_pre_name')){
+ $temp_store_name = $v_stored_filename;
+ $v_stored_filename = zip_pre_name($v_stored_filename,'utf-8');
+ if($v_stored_filename == ''){
+ $v_stored_filename = $temp_store_name;
+ }
+ }
+
+ // ----- Check the path length
+ if (strlen($v_stored_filename) > 999) //add by warlee; 99=>999
+ {
+ // ----- Error log
+ PclErrorLog(-5, "Stored file name is too long (max. 99) : '$v_stored_filename'");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ // ----- Look for a file
+ if (is_file($p_filename))
+ {
+ // ----- Open the source file
+ if (($v_file = fopen($p_filename, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_filename' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Call the header generation
+ if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)
+ {
+ // ----- Return status
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+
+ // ----- Read the file by 512 octets blocks
+ $i=0;
+ while (($v_buffer = fread($v_file, 512)) != "")
+ {
+ $v_binary_data = pack("a512", "$v_buffer");
+ if ($p_mode == "tar")
+ fputs($p_tar, $v_binary_data);
+ else
+ gzputs($p_tar, $v_binary_data);
+ $i++;
+ }
+ TrFctMessage(__FILE__, __LINE__, 2, "$i 512 bytes blocks");
+
+ // ----- Close the file
+ fclose($v_file);
+
+ TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ }
+
+ // ----- Look for a directory
+ else
+ {
+ // ----- Call the header generation
+ if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)
+ {
+ // ----- Return status
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleHeader()
+ // Description :
+ // This function creates in the TAR $p_tar, the TAR header for the file
+ // $p_filename.
+ //
+ // 1. The informations needed to compose the header are recuperated and formatted
+ // 2. Two binary strings are composed for the first part of the header, before
+ // and after checksum field.
+ // 3. The checksum is calculated from the two binary strings
+ // 4. The header is write in the tar file (first binary string, binary string
+ // for checksum and last binary string).
+ // Parameters :
+ // $p_tar : a valid file descriptor, opened in write mode,
+ // $p_filename : The name of the file the header is for,
+ // $p_mode : The mode of the archive ("tar" or "tgz").
+ // $p_header : A pointer to a array where will be set the file properties
+ // Return Values :
+ // --------------------------------------------------------------------------------
+
+ //长文件名处理,将文件名存储为文件
+ function PclTarHandleHeaderAdd($p_tar,$p_mode,$name, $uid, $gid, $perm, $size, $mtime, $typeflag = ''){
+ // handle filename length restrictions
+ $prefix = '';
+ $namelen = strlen($name);
+
+ $uid = sprintf("%6s ", decoct($uid));
+ $gid = sprintf("%6s ", decoct($gid));
+ $perm = sprintf("%6s ", decoct($perm));
+ $size = sprintf("%11s ", decoct($size));
+ $mtime = sprintf("%11s", decoct($mtime));
+ $data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime);
+ $data_last = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, "");
+ for ($i = 0, $chks = 0; $i < 148; $i++) {
+ $chks += ord($data_first[$i]);
}
-
- // ----- Free memory for the recursive loop
- unset($p_temp_list);
- unset($p_hdir);
- unset($p_hitem);
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- }
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleAddFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleAddFile($p_tar, $p_filename, $p_mode, &$p_header, $p_add_dir, $p_remove_dir)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleAddFile", "tar='$p_tar', filename='$p_filename', p_mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");
- $v_result=1;
-
- // ----- Check the parameters
- if ($p_tar == 0)
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Skip empty file names
- if ($p_filename == "")
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Calculate the stored filename
- $v_stored_filename = $p_filename;
- 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);
- }
-
- if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir)
- {
- $v_stored_filename = substr($p_filename, strlen($p_remove_dir));
- TrFctMessage(__FILE__, __LINE__, 3, "Remove path '$p_remove_dir' in file '$p_filename' = '$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;
- TrFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");
- }
-
- //add by warlee; 压缩:设置文件名编码
- if(function_exists('zip_pre_name')){
- $temp_store_name = $v_stored_filename;
- $v_stored_filename = zip_pre_name($v_stored_filename,'utf-8');
- if($v_stored_filename == ''){
- $v_stored_filename = $temp_store_name;
- }
- }
-
- // ----- Check the path length
- if (strlen($v_stored_filename) > 999) //add by warlee; 99=>999
- {
- // ----- Error log
- PclErrorLog(-5, "Stored file name is too long (max. 99) : '$v_stored_filename'");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- // ----- Look for a file
- if (is_file($p_filename))
- {
- // ----- Open the source file
- if (($v_file = fopen($p_filename, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_filename' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Call the header generation
- if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)
- {
- // ----- Return status
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
-
- // ----- Read the file by 512 octets blocks
- $i=0;
- while (($v_buffer = fread($v_file, 512)) != "")
- {
- $v_binary_data = pack("a512", "$v_buffer");
- if ($p_mode == "tar")
- fputs($p_tar, $v_binary_data);
- else
- gzputs($p_tar, $v_binary_data);
- $i++;
- }
- TrFctMessage(__FILE__, __LINE__, 2, "$i 512 bytes blocks");
-
- // ----- Close the file
- fclose($v_file);
-
- TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- }
-
- // ----- Look for a directory
- else
- {
- // ----- Call the header generation
- if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)
- {
- // ----- Return status
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleHeader()
- // Description :
- // This function creates in the TAR $p_tar, the TAR header for the file
- // $p_filename.
- //
- // 1. The informations needed to compose the header are recuperated and formatted
- // 2. Two binary strings are composed for the first part of the header, before
- // and after checksum field.
- // 3. The checksum is calculated from the two binary strings
- // 4. The header is write in the tar file (first binary string, binary string
- // for checksum and last binary string).
- // Parameters :
- // $p_tar : a valid file descriptor, opened in write mode,
- // $p_filename : The name of the file the header is for,
- // $p_mode : The mode of the archive ("tar" or "tgz").
- // $p_header : A pointer to a array where will be set the file properties
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleHeader($p_tar, $p_filename, $p_mode, &$p_header, $p_stored_filename)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleHeader", "tar=$p_tar, file='$p_filename', mode='$p_mode', stored_filename='$p_stored_filename'");
- $v_result=1;
-
- // ----- Check the parameters
- if (($p_tar == 0) || ($p_filename == ""))
- {
- // ----- Error log
- PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Filename (reduce the path of stored name)
- if ($p_stored_filename == "")
- $p_stored_filename = $p_filename;
- $v_reduce_filename = PclTarHandlePathReduction($p_stored_filename);
- TrFctMessage(__FILE__, __LINE__, 2, "Filename (reduced) '$v_reduce_filename', strlen ".strlen($v_reduce_filename));
-
- // ----- Get file info
- $v_info = stat($p_filename);
- $v_uid = sprintf("%6s ", DecOct($v_info[4]));
- $v_gid = sprintf("%6s ", DecOct($v_info[5]));
- TrFctMessage(__FILE__, __LINE__, 3, "uid=$v_uid, gid=$v_gid");
- $v_perms = sprintf("%6s ", DecOct(fileperms($p_filename)));
- TrFctMessage(__FILE__, __LINE__, 3, "file permissions $v_perms");
-
- // ----- File mtime
- $v_mtime_data = filemtime($p_filename);
- TrFctMessage(__FILE__, __LINE__, 2, "File mtime : $v_mtime_data");
- $v_mtime = sprintf("%11s", DecOct($v_mtime_data));
-
- // ----- File typeflag
- // '0' or '\0' is the code for regular file
- // '5' is directory
- if (is_dir($p_filename))
- {
- $v_typeflag = "5";
- $v_size = 0;
- }
- else
- {
- $v_typeflag = "";
-
- // ----- Get the file size
- clearstatcache();
- $v_size = filesize($p_filename);
- }
-
- TrFctMessage(__FILE__, __LINE__, 2, "File size : $v_size");
- $v_size = sprintf("%11s ", DecOct($v_size));
-
- TrFctMessage(__FILE__, __LINE__, 2, "File typeflag : $v_typeflag");
-
- // ----- Linkname
- $v_linkname = "";
-
- // ----- Magic
- $v_magic = "";
-
- // ----- Version
- $v_version = "";
-
- // ----- uname
- $v_uname = "";
-
- // ----- gname
- $v_gname = "";
-
- // ----- devmajor
- $v_devmajor = "";
-
- // ----- devminor
- $v_devminor = "";
-
- // ----- prefix
- $v_prefix = "";
-
- // ----- Compose the binary string of the header in two parts arround the checksum position
- $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, "");
-
- // ----- Calculate the checksum
- $v_checksum = 0;
- // ..... First part of the header
- for ($i=0; $i<148; $i++)
- {
- $v_checksum += ord(substr($v_binary_data_first,$i,1));
- }
- // ..... Ignore the checksum value and replace it by ' ' (space)
- for ($i=148; $i<156; $i++)
- {
- $v_checksum += ord(' ');
- }
- // ..... Last part of the header
- for ($i=156, $j=0; $i<512; $i++, $j++)
- {
- $v_checksum += ord(substr($v_binary_data_last,$j,1));
- }
- TrFctMessage(__FILE__, __LINE__, 3, "Calculated checksum : $v_checksum");
-
- // ----- Write the first 148 bytes of the header in the archive
- if ($p_mode == "tar")
- fputs($p_tar, $v_binary_data_first, 148);
- else
- gzputs($p_tar, $v_binary_data_first, 148);
-
- // ----- Write the calculated checksum
- $v_checksum = sprintf("%6s ", DecOct($v_checksum));
- $v_binary_data = pack("a8", $v_checksum);
- if ($p_mode == "tar")
- fputs($p_tar, $v_binary_data, 8);
- else
- gzputs($p_tar, $v_binary_data, 8);
-
- // ----- Write the last 356 bytes of the header in the archive
- if ($p_mode == "tar")
- fputs($p_tar, $v_binary_data_last, 356);
- else
- gzputs($p_tar, $v_binary_data_last, 356);
-
- // ----- Set the properties in the header "structure"
- $p_header[filename] = $v_reduce_filename;
- $p_header[mode] = $v_perms;
- $p_header[uid] = $v_uid;
- $p_header[gid] = $v_gid;
- $p_header[size] = $v_size;
- $p_header[mtime] = $v_mtime;
- $p_header[typeflag] = $v_typeflag;
- $p_header[status] = "added";
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleFooter()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleFooter($p_tar, $p_mode)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleFooter", "tar='$p_tar', p_mode=$p_mode");
- $v_result=1;
-
- // ----- Write the last 0 filled block for end of archive
- $v_binary_data = pack("a512", "");
- if ($p_mode == "tar")
- fputs($p_tar, $v_binary_data);
- else
- gzputs($p_tar, $v_binary_data);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleExtract()
- // Description :
- // Parameters :
- // $p_tarname : Filename of the tar (or tgz) archive
- // $p_file_list : An array which contains the list of files to extract, this
- // array may be empty when $p_mode is 'complete'
- // $p_list_detail : An array where will be placed the properties of each extracted/listed file
- // $p_mode : 'complete' will extract all files from the archive,
- // 'partial' will look for files in $p_file_list
- // 'list' will only list the files from the archive without any extract
- // $p_path : Path to add while writing the extracted files
- // $p_tar_mode : 'tar' for GNU TAR archive, 'tgz' for compressed archive
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_remove_path does not apply to 'list' mode.
- // $p_path and $p_remove_path are commulative.
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleExtract($p_tarname, $p_file_list, &$p_list_detail, $p_mode, $p_path, $p_tar_mode, $p_remove_path)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleExtract", "archive='$p_tarname', list, mode=$p_mode, path=$p_path, tar_mode=$p_tar_mode, remove_path='$p_remove_path'");
- $v_result=1;
- $v_nb = 0;
- $v_extract_all = TRUE;
- $v_listing = FALSE;
-
- // ----- Check the path
+ for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) {
+ $chks += ord($data_last[$j]);
+ }
+ if ($p_mode == "tar"){
+ fputs($p_tar, $data_first);
+ }else{
+ gzputs($p_tar, $data_first);
+ }
+
+ $chks = pack("a8", sprintf("%6s ", decoct($chks)));
+ if ($p_mode == "tar"){
+ fputs($p_tar, $chks.$data_last);
+ }else{
+ gzputs($p_tar, $chks.$data_last);
+ }
+ }
+
+ //add by warlee; 文件名长度大于100的问题解决
+ function PclTarHandleHeaderLong($p_tar, $p_mode, $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, '');
+ // ----- Calculate the checksum
+ $v_checksum = 0;
+ // ..... First part of the header
+ for ($i=0; $i<148; $i++)
+ $v_checksum += ord(substr($v_binary_data_first,$i,1));
+ // ..... Ignore the checksum value and replace it by ' ' (space)
+ for ($i=148; $i<156; $i++)
+ $v_checksum += ord(' ');
+ // ..... Last part of the header
+ for ($i=156, $j=0; $i<512; $i++, $j++)
+ $v_checksum += ord(substr($v_binary_data_last,$j,1));
+ // ----- Write the first 148 bytes of the header in the archive
+ if ($p_mode == "tar"){
+ fputs($p_tar, $v_binary_data_first);
+ }else{
+ gzputs($p_tar, $v_binary_data_first);
+ }
+
+ // ----- Write the calculated checksum
+ $v_checksum = sprintf("%6s ", DecOct($v_checksum));
+ $v_binary_data = pack("a8", $v_checksum);
+ if ($p_mode == "tar"){
+ fputs($p_tar, $v_binary_data);
+ }else{
+ gzputs($p_tar, $v_binary_data);
+ }
+ if ($p_mode == "tar"){
+ fputs($p_tar, $v_binary_data_last);
+ }else{
+ gzputs($p_tar, $v_binary_data_last);
+ }
+ $i=0;
+ while (($v_buffer = substr($p_filename, (($i++)*512), 512)) != '') {
+ $v_binary_data = pack("a512", "$v_buffer");
+ if ($p_mode == "tar"){
+ fputs($p_tar, $v_binary_data);
+ }else{
+ gzputs($p_tar, $v_binary_data);
+ }
+ }
+ return true;
+ }
+
+ function PclTarHandleHeader($p_tar, $p_filename, $p_mode, &$p_header, $p_stored_filename)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleHeader", "tar=$p_tar, file='$p_filename', mode='$p_mode', stored_filename='$p_stored_filename'");
+ $v_result=1;
+
+ // ----- Check the parameters
+ if (($p_tar == 0) || ($p_filename == ""))
+ {
+ // ----- Error log
+ PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ // ----- Filename (reduce the path of stored name)
+ if ($p_stored_filename == "")
+ $p_stored_filename = $p_filename;
+
+ $v_reduce_filename = PclTarHandlePathReduction($p_stored_filename);
+
+
+ //add by warlee; 文件名长度大于100的问题解决
+ if (strlen($v_reduce_filename) > 100) {
+ PclTarHandleHeaderLong($p_tar, $p_mode, $v_reduce_filename);
+ }
+
+
+ TrFctMessage(__FILE__, __LINE__, 2, "Filename (reduced) '$v_reduce_filename', strlen ".strlen($v_reduce_filename));
+ // ----- Get file info
+ $v_info = stat($p_filename);
+ $v_uid = sprintf("%6s ", DecOct($v_info[4]));
+ $v_gid = sprintf("%6s ", DecOct($v_info[5]));
+ TrFctMessage(__FILE__, __LINE__, 3, "uid=$v_uid, gid=$v_gid");
+ $v_perms = sprintf("%6s ", DecOct(fileperms($p_filename)));
+ TrFctMessage(__FILE__, __LINE__, 3, "file permissions $v_perms");
+
+ // ----- File mtime
+ $v_mtime_data = filemtime($p_filename);
+ TrFctMessage(__FILE__, __LINE__, 2, "File mtime : $v_mtime_data");
+ $v_mtime = sprintf("%11s", DecOct($v_mtime_data));
+
+ // ----- File typeflag
+ // '0' or '\0' is the code for regular file
+ // '5' is directory
+ if (is_dir($p_filename))
+ {
+ $v_typeflag = "5";
+ $v_size = 0;
+ }
+ else
+ {
+ $v_typeflag = "";
+
+ // ----- Get the file size
+ clearstatcache();
+ $v_size = filesize($p_filename);
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 2, "File size : $v_size");
+ $v_size = sprintf("%11s ", DecOct($v_size));
+
+ TrFctMessage(__FILE__, __LINE__, 2, "File typeflag : $v_typeflag");
+
+ // ----- Linkname
+ $v_linkname = "";
+
+ // ----- Magic
+ $v_magic = "";
+
+ // ----- Version
+ $v_version = "";
+
+ // ----- uname
+ $v_uname = "";
+
+ // ----- gname
+ $v_gname = "";
+
+ // ----- devmajor
+ $v_devmajor = "";
+
+ // ----- devminor
+ $v_devminor = "";
+
+ // ----- prefix
+ $v_prefix = "";
+
+ // ----- Compose the binary string of the header in two parts arround the checksum position
+ $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, "");
+
+
+ var_dump($v_reduce_filename, $v_perms, $v_uid, $v_gid, $v_prefix,111);
+
+ // ----- Calculate the checksum
+ $v_checksum = 0;
+ // ..... First part of the header
+ for ($i=0; $i<148; $i++)
+ {
+ $v_checksum += ord(substr($v_binary_data_first,$i,1));
+ }
+ // ..... Ignore the checksum value and replace it by ' ' (space)
+ for ($i=148; $i<156; $i++)
+ {
+ $v_checksum += ord(' ');
+ }
+ // ..... Last part of the header
+ for ($i=156, $j=0; $i<512; $i++, $j++)
+ {
+ $v_checksum += ord(substr($v_binary_data_last,$j,1));
+ }
+ TrFctMessage(__FILE__, __LINE__, 3, "Calculated checksum : $v_checksum");
+
+ // ----- Write the first 148 bytes of the header in the archive
+ if ($p_mode == "tar")
+ fputs($p_tar, $v_binary_data_first, 148);
+ else
+ gzputs($p_tar, $v_binary_data_first, 148);
+
+ // ----- Write the calculated checksum
+ $v_checksum = sprintf("%6s ", DecOct($v_checksum));
+ $v_binary_data = pack("a8", $v_checksum);
+ if ($p_mode == "tar")
+ fputs($p_tar, $v_binary_data, 8);
+ else
+ gzputs($p_tar, $v_binary_data, 8);
+
+ // ----- Write the last 356 bytes of the header in the archive
+ if ($p_mode == "tar")
+ fputs($p_tar, $v_binary_data_last, 356);
+ else
+ gzputs($p_tar, $v_binary_data_last, 356);
+
+ // ----- Set the properties in the header "structure"
+ $p_header[filename] = $v_reduce_filename;
+ $p_header[mode] = $v_perms;
+ $p_header[uid] = $v_uid;
+ $p_header[gid] = $v_gid;
+ $p_header[size] = $v_size;
+ $p_header[mtime] = $v_mtime;
+ $p_header[typeflag] = $v_typeflag;
+ $p_header[status] = "added";
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleFooter()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleFooter($p_tar, $p_mode)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleFooter", "tar='$p_tar', p_mode=$p_mode");
+ $v_result=1;
+
+ // ----- Write the last 0 filled block for end of archive
+ $v_binary_data = pack("a512", "");
+ if ($p_mode == "tar")
+ fputs($p_tar, $v_binary_data);
+ else
+ gzputs($p_tar, $v_binary_data);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleExtract()
+ // Description :
+ // Parameters :
+ // $p_tarname : Filename of the tar (or tgz) archive
+ // $p_file_list : An array which contains the list of files to extract, this
+ // array may be empty when $p_mode is 'complete'
+ // $p_list_detail : An array where will be placed the properties of each extracted/listed file
+ // $p_mode : 'complete' will extract all files from the archive,
+ // 'partial' will look for files in $p_file_list
+ // 'list' will only list the files from the archive without any extract
+ // $p_path : Path to add while writing the extracted files
+ // $p_tar_mode : 'tar' for GNU TAR archive, 'tgz' for compressed archive
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_remove_path does not apply to 'list' mode.
+ // $p_path and $p_remove_path are commulative.
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleExtract($p_tarname, $p_file_list, &$p_list_detail, $p_mode, $p_path, $p_tar_mode, $p_remove_path)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleExtract", "archive='$p_tarname', list, mode=$p_mode, path=$p_path, tar_mode=$p_tar_mode, remove_path='$p_remove_path'");
+ $v_result=1;
+ $v_nb = 0;
+ $v_extract_all = TRUE;
+ $v_listing = FALSE;
+
+ // ----- Check the path
// if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../")))
// $p_path = "./".$p_path;
// var_dump($p_path); changed by warlee;
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
- {
- $p_remove_path .= '/';
- }
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Study the mode
- switch ($p_mode) {
- case "complete" :
- // ----- Flag extract of all files
- $v_extract_all = TRUE;
- $v_listing = FALSE;
- break;
- case "partial" :
- // ----- Flag extract of specific files
- $v_extract_all = FALSE;
- $v_listing = FALSE;
- break;
- case "list" :
- // ----- Flag list of all files
- $v_extract_all = FALSE;
- $v_listing = TRUE;
- break;
- default :
- // ----- Error log
- PclErrorLog(-3, "Invalid extract mode ($p_mode)");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Open the tar file
- if ($p_tar_mode == "tar")
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
- $v_tar = fopen($p_tarname, "rb");
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
- $v_tar = @gzopen($p_tarname, "rb");
- }
-
- // ----- Check that the archive is open
- if ($v_tar == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
-
- //add by warlee;
- if( $p_tar_mode == "gz" ||
- (substr($p_tarname,-3) == '.gz' && substr($p_tarname,-7) != '.tar.gz') ){
- $result = array(array(
- 'filename' => substr(basename($p_tarname),0,-3),
- 'size' => filesize($p_tarname),
- 'typeflag' => "",
- 'mtime' => "",
- 'status' => 'ok'
- ));
- $result[0]['filename'] = unzip_pre_name($result[0]['filename']);
-
- $p_list_detail = $result;
- if($v_listing){
- return 1;
- }else{
- mk_dir($p_path);
- $dest_fp = @fopen($p_path.'/'.$result[0]['filename'], "wb");
- if(!$dest_fp){
- PclErrorLog(-10010,"create file error!");
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- while (!gzeof($v_tar)){
- $v_content = gzread($v_tar, 512);
- fwrite($dest_fp,$v_content);
- }
- fclose($dest_fp);
- gzclose($v_tar);
- }
- return 1;
- }
-
-
- // ----- Read the blocks
- While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");
-
- // ----- Clear cache of file infos
- clearstatcache();
-
- // ----- Reset extract tag
- $v_extract_file = FALSE;
- $v_extraction_stopped = 0;
-
- // ----- Read the 512 bytes header
- if ($p_tar_mode == "tar")
- $v_binary_data = fread($v_tar, 512);
- else
- $v_binary_data = gzread($v_tar, 512);
-
- // ----- Read the header properties
- if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
- {
- // ----- Close the archive file
- if ($p_tar_mode == "tar")
- fclose($v_tar);
- else
- gzclose($v_tar);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Look for empty blocks to skip
- if ($v_header[filename] == "")
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
- continue;
- }
-
- TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
-
-
- //add by warlee;解压 设置编码
- if(!$v_listing){
- if(function_exists('unzip_pre_name')){
- if( $v_header['typeflag'] == 'x'||
- $v_header['typeflag'] == 'g'){
- $v_header['typeflag'] = '-10';//不解压;设置成文件夹类型
- }
- $v_header['filename'] = unzip_pre_name($v_header['filename']);
- }
- //echo "";var_dump(22,$v_header);echo "
";
- }
-
- // ----- Look for partial extract
- if ((!$v_extract_all) && (is_array($p_file_list)))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Look if the file '$v_header[filename]' need to be extracted");
- // ----- By default no unzip if the file is not found
- $v_extract_file = FALSE;
- // ----- Look into the file list
- for ($i=0; $i strlen($p_file_list[$i])) && (substr($v_header[filename], 0, strlen($p_file_list[$i])) == $p_file_list[$i]))
- {
- // ----- The file is in the directory, so extract it
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in directory '$p_file_list[$i]' : extract it");
- $v_extract_file = TRUE;
-
- // ----- End of loop
- break;
- }
- }
-
- // ----- It is a file, so compare the file names
- else if ($p_file_list[$i] == $v_header[filename])
- {
- // ----- File found
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should be extracted");
- $v_extract_file = TRUE;
-
- // ----- End of loop
- break;
- }
-
-
- }
-
- // ----- Trace
- if (!$v_extract_file)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should not be extracted");
- }
- }
- else
- {
- // ----- All files need to be extracted
- $v_extract_file = TRUE;
- }
-
- // ----- Look if this file need to be extracted
- if (($v_extract_file) && (!$v_listing))
- {
- // ----- Look for path to remove
- if (($p_remove_path != "")
- && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");
- // ----- Remove the path
- $v_header[filename] = substr($v_header[filename], $p_remove_path_size);
- TrFctMessage(__FILE__, __LINE__, 3, "Reslting file is '$v_header[filename]'");
- }
-
- // ----- Add the path to the file
- if (($p_path != "./") && ($p_path != "/"))
- {
- // ----- Look for the path end '/'
- while (substr($p_path, -1) == "/")
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
- $p_path = substr($p_path, 0, strlen($p_path)-1);
- TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
- }
-
- // ----- Add the path
- if (substr($v_header[filename], 0, 1) == "/")
- $v_header[filename] = $p_path.$v_header[filename];
- else
- $v_header[filename] = $p_path."/".$v_header[filename];
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");
-
- // ----- Check that the file does not exists
- if (file_exists($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");
-
- // ----- Look if file is a directory
- if (is_dir($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");
-
- // ----- Change the file status
- $v_header[status] = "already_a_directory";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- // ----- Look if file is write protected
- else if (!is_writeable($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");
-
- // ----- Change the file status
- $v_header[status] = "write_protected";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- // ----- Look if the extracted file is older
- else if (filemtime($v_header[filename]) > $v_header[mtime])
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");
-
- // ----- Change the file status
- $v_header[status] = "newer_exist";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- else
- {
- if ($v_header[typeflag]=="5")
- $v_dir_to_check = $v_header[filename];
- else if (!strstr($v_header[filename], "/"))
- $v_dir_to_check = "";
- else
- $v_dir_to_check = dirname($v_header[filename]);
-
- //changed by warlee; 解压新建目录;不建立tar下的PaxHeader临时目录
- if( $v_header['typeflag'] == '-10' || $v_header['typeflag'] == 'g'){
- $v_dir_to_check="";
- }
-
- if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");
-
- // ----- Change the file status
- $v_header[status] = "path_creation_fail";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- }
- // ----- Do the extraction
- if (($v_extract_file) && ($v_header[typeflag]!="5") && ($v_header[typeflag]!="-10"))
- //changed by warlee; add $v_header[typeflag]
- {
- // ----- Open the destination file in write mode
- if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");
-
- // ----- Change the file status
- $v_header[status] = "write_error";
-
- // ----- Jump to next file
- TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
- if ($p_tar_mode == "tar")
- fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");
-
- // ----- Read data
- $n = floor($v_header[size]/512);
- for ($i=0; $i<$n; $i++)
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));
- if ($p_tar_mode == "tar")
- $v_content = fread($v_tar, 512);
- else
- $v_content = gzread($v_tar, 512);
- fwrite($v_dest_file, $v_content, 512);
- }
- if (($v_header[size] % 512) != 0)
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");
- if ($p_tar_mode == "tar")
- $v_content = fread($v_tar, 512);
- else
- $v_content = gzread($v_tar, 512);
- fwrite($v_dest_file, $v_content, ($v_header[size] % 512));
- }
-
- // ----- Close the destination file
- fclose($v_dest_file);
-
- // ----- Change the file mode, mtime
- touch($v_header[filename], $v_header[mtime]);
- //chmod($v_header[filename], DecOct($v_header[mode]));
- }
-
- // ----- Check the file size
- clearstatcache();
- //changed by warlee; 大小对比时查看是否存在
- if (file_exists($v_header[filename]) && filesize($v_header[filename]) != $v_header[size])
- {
- // ----- Close the archive file
- if ($p_tar_mode == "tar")
- fclose($v_tar);
- else
- gzclose($v_tar);
-
- // ----- Error log
- PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");
- }
-
- else
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");
-
- // ----- Jump to next file
- TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
- if ($p_tar_mode == "tar")
- fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
- }
- }
-
- // ----- Look for file that is not to be unzipped
- else
- {
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");
- TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
-
- // ----- Jump to next file
- if ($p_tar_mode == "tar")
- fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
-
- TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
- }
-
- if ($p_tar_mode == "tar")
- $v_end_of_file = feof($v_tar);
- else
- $v_end_of_file = gzeof($v_tar);
-
- // ----- File name and properties are logged if listing mode or file is extracted
- if ($v_listing || $v_extract_file || $v_extraction_stopped)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
-
- // ----- Log extracted files
- 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 = "/";
-
- // ----- Add the array describing the file into the list
- $p_list_detail[$v_nb] = $v_header;
-
- // ----- Increment
- $v_nb++;
- }
- }
-
- // ----- Close the tarfile
- if ($p_tar_mode == "tar")
- fclose($v_tar);
- else
- gzclose($v_tar);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleExtractByIndexList()
- // Description :
- // Extract the files which are at the indexes specified. If the 'file' at the
- // index is a directory, the directory only is created, not all the files stored
- // for that directory.
- // Parameters :
- // $p_index_string : String of indexes of files to extract. The form of the
- // string is "0,4-6,8-12" with only numbers and '-' for
- // for range, and ',' to separate ranges. No spaces or ';'
- // are allowed.
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleExtractByIndexList($p_tarname, $p_index_string, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndexList", "archive='$p_tarname', index_string='$p_index_string', list, path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");
- $v_result=1;
- $v_nb = 0;
-
- // ----- TBC : I should check the string by a regexp
-
- // ----- Check the path
- if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path, 0, 2) != "./")))
- $p_path = "./".$p_path;
-
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
- {
- $p_remove_path .= '/';
- }
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Open the tar file
- if ($p_tar_mode == "tar")
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
- $v_tar = @fopen($p_tarname, "rb");
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
- $v_tar = @gzopen($p_tarname, "rb");
- }
-
- // ----- Check that the archive is open
- if ($v_tar == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Manipulate the index list
- $v_list = explode(",", $p_index_string);
- sort($v_list);
-
- // ----- Loop on the index list
- $v_index=0;
- for ($i=0; ($i $p_index_stop)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Stop extraction, past stop index");
- break;
- }
-
- // ----- Clear cache of file infos
- clearstatcache();
-
- // ----- Reset extract tag
- $v_extract_file = FALSE;
- $v_extraction_stopped = 0;
-
- // ----- Read the 512 bytes header
- if ($p_tar_mode == "tar")
- $v_binary_data = fread($v_tar, 512);
- else
- $v_binary_data = gzread($v_tar, 512);
-
- // ----- Read the header properties
- if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Look for empty blocks to skip
- if ($v_header[filename] == "")
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
- continue;
- }
-
- TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
-
- // ----- Look if file is in the range to be extracted
- if (($p_index_current >= $p_index_start) && ($p_index_current <= $p_index_stop))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in the range to be extracted");
- $v_extract_file = TRUE;
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is out of the range");
- $v_extract_file = FALSE;
- }
-
- // ----- Look if this file need to be extracted
- if ($v_extract_file)
- {
- if (($v_result = PclTarHandleExtractFile($v_tar, $v_header, $p_path, $p_remove_path, $p_tar_mode)) != 1)
- {
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- }
-
- // ----- Look for file that is not to be extracted
- else
- {
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");
- TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
-
- // ----- Jump to next file
- if ($p_tar_mode == "tar")
- fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
-
- TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
- }
-
- if ($p_tar_mode == "tar")
- $v_end_of_file = feof($v_tar);
- else
- $v_end_of_file = gzeof($v_tar);
-
- // ----- File name and properties are logged if listing mode or file is extracted
- if ($v_extract_file)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
-
- // ----- Log extracted files
- 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 = "/";
-
- // ----- Add the array describing the file into the list
- $p_list_detail[$v_nb] = $v_header;
-
- // ----- Increment
- $v_nb++;
- }
-
- // ----- Increment the current file index
- $p_index_current++;
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleExtractFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleExtractFile($p_tar, &$v_header, $p_path, $p_remove_path, $p_tar_mode)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractFile", "archive_descr='$p_tar', path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");
- $v_result=1;
-
- // TBC : I should replace all $v_tar by $p_tar in this function ....
- $v_tar = $p_tar;
- $v_extract_file = 1;
-
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Look for path to remove
- if (($p_remove_path != "")
- && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");
- // ----- Remove the path
- $v_header[filename] = substr($v_header[filename], $p_remove_path_size);
- TrFctMessage(__FILE__, __LINE__, 3, "Resulting file is '$v_header[filename]'");
- }
-
- // ----- Add the path to the file
- if (($p_path != "./") && ($p_path != "/"))
- {
- // ----- Look for the path end '/'
- while (substr($p_path, -1) == "/")
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
- $p_path = substr($p_path, 0, strlen($p_path)-1);
- TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
- }
-
- // ----- Add the path
- if (substr($v_header[filename], 0, 1) == "/")
- $v_header[filename] = $p_path.$v_header[filename];
- else
- $v_header[filename] = $p_path."/".$v_header[filename];
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");
-
- // ----- Check that the file does not exists
- if (file_exists($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");
-
- // ----- Look if file is a directory
- if (is_dir($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");
-
- // ----- Change the file status
- $v_header[status] = "already_a_directory";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- // ----- Look if file is write protected
- else if (!is_writeable($v_header[filename]))
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");
-
- // ----- Change the file status
- $v_header[status] = "write_protected";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- // ----- Look if the extracted file is older
- else if (filemtime($v_header[filename]) > $v_header[mtime])
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");
-
- // ----- Change the file status
- $v_header[status] = "newer_exist";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- else
- {
- if ($v_header[typeflag]=="5")
- $v_dir_to_check = $v_header[filename];
- else if (!strstr($v_header[filename], "/"))
- $v_dir_to_check = "";
- else
- $v_dir_to_check = dirname($v_header[filename]);
-
- if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");
-
- // ----- Change the file status
- $v_header[status] = "path_creation_fail";
-
- // ----- Skip the extract
- $v_extraction_stopped = 1;
- $v_extract_file = 0;
- }
- }
-
- // ----- Do the real bytes extraction (if not a directory)
- if (($v_extract_file) && ($v_header[typeflag]!="5"))
- {
- // ----- Open the destination file in write mode
- if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");
-
- // ----- Change the file status
- $v_header[status] = "write_error";
-
- // ----- Jump to next file
- TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
- if ($p_tar_mode == "tar")
- fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");
-
- // ----- Read data
- $n = floor($v_header[size]/512);
- for ($i=0; $i<$n; $i++)
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));
- if ($p_tar_mode == "tar")
- $v_content = fread($v_tar, 512);
- else
- $v_content = gzread($v_tar, 512);
- fwrite($v_dest_file, $v_content, 512);
- }
- if (($v_header[size] % 512) != 0)
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");
- if ($p_tar_mode == "tar")
- $v_content = fread($v_tar, 512);
- else
- $v_content = gzread($v_tar, 512);
- fwrite($v_dest_file, $v_content, ($v_header[size] % 512));
- }
-
- // ----- Close the destination file
- fclose($v_dest_file);
-
- // ----- Change the file mode, mtime
- touch($v_header[filename], $v_header[mtime]);
- //chmod($v_header[filename], DecOct($v_header[mode]));
- }
-
- // ----- Check the file size
- clearstatcache();
- if (filesize($v_header[filename]) != $v_header[size])
- {
- // ----- Error log
- PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");
-
- // ----- Jump to next file
- TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
- if ($p_tar_mode == "tar")
- fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclTarHandleDelete()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclTarHandleDelete($p_tarname, $p_file_list, &$p_list_detail, $p_tar_mode)
- {
- TrFctStart(__FILE__, __LINE__, "PclTarHandleDelete", "archive='$p_tarname', list, tar_mode=$p_tar_mode");
- $v_result=1;
- $v_nb=0;
-
- // ----- Look for regular tar file
- if ($p_tar_mode == "tar")
- {
- // ----- Open file
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
- if (($v_tar = @fopen($p_tarname, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Open a temporary file in write mode
- $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
- TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
- if (($v_temp_tar = @fopen($v_temp_tarname, "wb")) == 0)
- {
- // ----- Close tar file
- fclose($v_tar);
-
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- }
-
- // ----- Look for compressed tar file
- else
- {
- // ----- Open the file in read mode
- TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
- if (($v_tar = @gzopen($p_tarname, "rb")) == 0)
- {
- // ----- Error log
- PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
-
- // ----- Open a temporary file in write mode
- $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
- TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
- if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
- {
- // ----- Close tar file
- gzclose($v_tar);
-
- // ----- Error log
- PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
- return PclErrorCode();
- }
- }
-
- // ----- Read the blocks
- While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");
-
- // ----- Clear cache of file infos
- clearstatcache();
-
- // ----- Reset delete tag
- $v_delete_file = FALSE;
-
- // ----- Read the first 512 block header
- if ($p_tar_mode == "tar")
- $v_binary_data = fread($v_tar, 512);
- else
- $v_binary_data = gzread($v_tar, 512);
-
- // ----- Read the header properties
- if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
- {
- // ----- Close the archive file
- if ($p_tar_mode == "tar")
- {
- fclose($v_tar);
- fclose($v_temp_tar);
- }
- else
- {
- gzclose($v_tar);
- gzclose($v_temp_tar);
- }
- @unlink($v_temp_tarname);
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Look for empty blocks to skip
- if ($v_header[filename] == "")
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
- continue;
- }
-
- TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
-
- // ----- Look for filenames to delete
- for ($i=0, $v_delete_file=FALSE; ($i substr(basename($p_tarname),0,-3),
+ 'size' => filesize($p_tarname),
+ 'typeflag' => "",
+ 'mtime' => "",
+ 'status' => 'ok'
+ ));
+ $result[0]['filename'] = unzip_pre_name($result[0]['filename']);
+
+ $p_list_detail = $result;
+ if($v_listing){
+ return 1;
+ }else{
+ mk_dir($p_path);
+ $dest_fp = @fopen($p_path.'/'.$result[0]['filename'], "wb");
+ if(!$dest_fp){
+ PclErrorLog(-10010,"create file error!");
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ while (!gzeof($v_tar)){
+ $v_content = gzread($v_tar, 512);
+ fwrite($dest_fp,$v_content);
+ }
+ fclose($dest_fp);
+ gzclose($v_tar);
+ }
+ return 1;
+ }
+
+
+ // ----- Read the blocks
+ While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");
+
+ // ----- Clear cache of file infos
+ clearstatcache();
+
+ // ----- Reset extract tag
+ $v_extract_file = FALSE;
+ $v_extraction_stopped = 0;
+
+ // ----- Read the 512 bytes header
+ if ($p_tar_mode == "tar")
+ $v_binary_data = fread($v_tar, 512);
+ else
+ $v_binary_data = gzread($v_tar, 512);
+
+ // ----- Read the header properties
+ if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
+ {
+ // ----- Close the archive file
+ if ($p_tar_mode == "tar")
+ fclose($v_tar);
+ else
+ gzclose($v_tar);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Look for empty blocks to skip
+ if ($v_header[filename] == "")
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
+ continue;
+ }
+
+
+ //add by warlee ;文件名过长问题
+ if ($v_header['typeflag'] == 'L') {
+ if (($v_result = PclTarHandleReadHeaderLong($v_tar,$p_tar_mode,$v_binary_data, $v_header)) != 1){
+ if ($p_tar_mode == "tar")
+ fclose($v_tar);
+ else
+ gzclose($v_tar);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
+
+
+ //add by warlee;解压 设置编码
+ if(!$v_listing){
+ if(function_exists('unzip_pre_name')){
+ if( $v_header['typeflag'] == 'x'||
+ $v_header['typeflag'] == 'g'){
+ $v_header['typeflag'] = '-10';//不解压;设置成文件夹类型
+ }
+ $v_header['filename'] = unzip_pre_name($v_header['filename']);
+ }
+ //echo "";var_dump(22,$v_header);echo "
";
+ }
+
+ // ----- Look for partial extract
+ if ((!$v_extract_all) && (is_array($p_file_list)))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Look if the file '$v_header[filename]' need to be extracted");
+ // ----- By default no unzip if the file is not found
+ $v_extract_file = FALSE;
+ // ----- Look into the file list
+ for ($i=0; $i strlen($p_file_list[$i])) && (substr($v_header[filename], 0, strlen($p_file_list[$i])) == $p_file_list[$i]))
+ {
+ // ----- The file is in the directory, so extract it
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in directory '$p_file_list[$i]' : extract it");
+ $v_extract_file = TRUE;
+
+ // ----- End of loop
+ break;
+ }
+ }
+
+ // ----- It is a file, so compare the file names
+ else if ($p_file_list[$i] == $v_header[filename])
+ {
+ // ----- File found
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should be extracted");
+ $v_extract_file = TRUE;
+
+ // ----- End of loop
+ break;
+ }
+
+
+ }
+
+ // ----- Trace
+ if (!$v_extract_file)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should not be extracted");
+ }
+ }
+ else
+ {
+ // ----- All files need to be extracted
+ $v_extract_file = TRUE;
+ }
+
+ // ----- Look if this file need to be extracted
+ if (($v_extract_file) && (!$v_listing))
+ {
+ // ----- Look for path to remove
+ if (($p_remove_path != "")
+ && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");
+ // ----- Remove the path
+ $v_header[filename] = substr($v_header[filename], $p_remove_path_size);
+ TrFctMessage(__FILE__, __LINE__, 3, "Reslting file is '$v_header[filename]'");
+ }
+
+ // ----- Add the path to the file
+ if (($p_path != "./") && ($p_path != "/"))
+ {
+ // ----- Look for the path end '/'
+ while (substr($p_path, -1) == "/")
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
+ TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
+ }
+
+ // ----- Add the path
+ if (substr($v_header[filename], 0, 1) == "/")
+ $v_header[filename] = $p_path.$v_header[filename];
+ else
+ $v_header[filename] = $p_path."/".$v_header[filename];
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");
+
+ // ----- Check that the file does not exists
+ if (file_exists($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");
+
+ // ----- Look if file is a directory
+ if (is_dir($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");
+
+ // ----- Change the file status
+ $v_header[status] = "already_a_directory";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ // ----- Look if file is write protected
+ else if (!is_writeable($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");
+
+ // ----- Change the file status
+ $v_header[status] = "write_protected";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ // ----- Look if the extracted file is older
+ else if (filemtime($v_header[filename]) > $v_header[mtime])
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");
+
+ // ----- Change the file status
+ $v_header[status] = "newer_exist";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ }
+
+ // ----- Check the directory availability and create it if necessary
+ else
+ {
+ if ($v_header[typeflag]=="5")
+ $v_dir_to_check = $v_header[filename];
+ else if (!strstr($v_header[filename], "/"))
+ $v_dir_to_check = "";
+ else
+ $v_dir_to_check = dirname($v_header[filename]);
+
+ //changed by warlee; 解压新建目录;不建立tar下的PaxHeader临时目录
+ if( $v_header['typeflag'] == '-10' || $v_header['typeflag'] == 'g'){
+ $v_dir_to_check="";
+ }
+
+ if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");
+
+ // ----- Change the file status
+ $v_header[status] = "path_creation_fail";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ }
+ // ----- Do the extraction
+ if (($v_extract_file) && ($v_header[typeflag]!="5") && ($v_header[typeflag]!="-10"))
+ //changed by warlee; add $v_header[typeflag]
+ {
+ // ----- Open the destination file in write mode
+ if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");
+
+ // ----- Change the file status
+ $v_header[status] = "write_error";
+
+ // ----- Jump to next file
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");
+
+ // ----- Read data
+ $n = floor($v_header[size]/512);
+ for ($i=0; $i<$n; $i++)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));
+ if ($p_tar_mode == "tar")
+ $v_content = fread($v_tar, 512);
+ else
+ $v_content = gzread($v_tar, 512);
+ fwrite($v_dest_file, $v_content, 512);
+ }
+ if (($v_header[size] % 512) != 0)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");
+ if ($p_tar_mode == "tar")
+ $v_content = fread($v_tar, 512);
+ else
+ $v_content = gzread($v_tar, 512);
+ fwrite($v_dest_file, $v_content, ($v_header[size] % 512));
+ }
+
+ // ----- Close the destination file
+ fclose($v_dest_file);
+
+ // ----- Change the file mode, mtime
+ touch($v_header[filename], $v_header[mtime]);
+ //chmod($v_header[filename], DecOct($v_header[mode]));
+ }
+
+ // ----- Check the file size
+ clearstatcache();
+ //changed by warlee; 大小对比时查看是否存在
+ if (file_exists($v_header[filename]) && filesize($v_header[filename]) != $v_header[size])
+ {
+ // ----- Close the archive file
+ if ($p_tar_mode == "tar")
+ fclose($v_tar);
+ else
+ gzclose($v_tar);
+
+ // ----- Error log
+ PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");
+ }
+
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");
+
+ // ----- Jump to next file
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+ }
+ }
+
+ // ----- Look for file that is not to be unzipped
+ else
+ {
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");
+ TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+
+ // ----- Jump to next file
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+
+ TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+ }
+
+ if ($p_tar_mode == "tar")
+ $v_end_of_file = feof($v_tar);
+ else
+ $v_end_of_file = gzeof($v_tar);
+
+ // ----- File name and properties are logged if listing mode or file is extracted
+ if ($v_listing || $v_extract_file || $v_extraction_stopped)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
+
+ // ----- Log extracted files
+ 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 = "/";
+
+ // ----- Add the array describing the file into the list
+ $p_list_detail[$v_nb] = $v_header;
+
+ // ----- Increment
+ $v_nb++;
+ }
+ }
+
+ // ----- Close the tarfile
+ if ($p_tar_mode == "tar")
+ fclose($v_tar);
+ else
+ gzclose($v_tar);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleExtractByIndexList()
+ // Description :
+ // Extract the files which are at the indexes specified. If the 'file' at the
+ // index is a directory, the directory only is created, not all the files stored
+ // for that directory.
+ // Parameters :
+ // $p_index_string : String of indexes of files to extract. The form of the
+ // string is "0,4-6,8-12" with only numbers and '-' for
+ // for range, and ',' to separate ranges. No spaces or ';'
+ // are allowed.
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleExtractByIndexList($p_tarname, $p_index_string, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndexList", "archive='$p_tarname', index_string='$p_index_string', list, path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");
+ $v_result=1;
+ $v_nb = 0;
+
+ // ----- TBC : I should check the string by a regexp
+
+ // ----- Check the path
+ if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path, 0, 2) != "./")))
+ $p_path = "./".$p_path;
+
+ // ----- Look for path to remove format (should end by /)
+ if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
+ {
+ $p_remove_path .= '/';
+ }
+ $p_remove_path_size = strlen($p_remove_path);
+
+ // ----- Open the tar file
+ if ($p_tar_mode == "tar")
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
+ $v_tar = @fopen($p_tarname, "rb");
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
+ $v_tar = @gzopen($p_tarname, "rb");
+ }
+
+ // ----- Check that the archive is open
+ if ($v_tar == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Manipulate the index list
+ $v_list = explode(",", $p_index_string);
+ sort($v_list);
+
+ // ----- Loop on the index list
+ $v_index=0;
+ for ($i=0; ($i $p_index_stop)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Stop extraction, past stop index");
+ break;
+ }
+
+ // ----- Clear cache of file infos
+ clearstatcache();
+
+ // ----- Reset extract tag
+ $v_extract_file = FALSE;
+ $v_extraction_stopped = 0;
+
+ // ----- Read the 512 bytes header
+ if ($p_tar_mode == "tar")
+ $v_binary_data = fread($v_tar, 512);
+ else
+ $v_binary_data = gzread($v_tar, 512);
+
+ // ----- Read the header properties
+ if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Look for empty blocks to skip
+ if ($v_header[filename] == "")
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
+ continue;
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
+
+ // ----- Look if file is in the range to be extracted
+ if (($p_index_current >= $p_index_start) && ($p_index_current <= $p_index_stop))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in the range to be extracted");
+ $v_extract_file = TRUE;
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is out of the range");
+ $v_extract_file = FALSE;
+ }
+
+ // ----- Look if this file need to be extracted
+ if ($v_extract_file)
+ {
+ if (($v_result = PclTarHandleExtractFile($v_tar, $v_header, $p_path, $p_remove_path, $p_tar_mode)) != 1)
+ {
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ }
+
+ // ----- Look for file that is not to be extracted
+ else
+ {
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");
+ TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+
+ // ----- Jump to next file
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+
+ TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+ }
+
+ if ($p_tar_mode == "tar")
+ $v_end_of_file = feof($v_tar);
+ else
+ $v_end_of_file = gzeof($v_tar);
+
+ // ----- File name and properties are logged if listing mode or file is extracted
+ if ($v_extract_file)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
+
+ // ----- Log extracted files
+ 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 = "/";
+
+ // ----- Add the array describing the file into the list
+ $p_list_detail[$v_nb] = $v_header;
+
+ // ----- Increment
+ $v_nb++;
+ }
+
+ // ----- Increment the current file index
+ $p_index_current++;
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleExtractFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleExtractFile($p_tar, &$v_header, $p_path, $p_remove_path, $p_tar_mode)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractFile", "archive_descr='$p_tar', path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");
+ $v_result=1;
+
+ // TBC : I should replace all $v_tar by $p_tar in this function ....
+ $v_tar = $p_tar;
+ $v_extract_file = 1;
+
+ $p_remove_path_size = strlen($p_remove_path);
+
+ // ----- Look for path to remove
+ if (($p_remove_path != "")
+ && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");
+ // ----- Remove the path
+ $v_header[filename] = substr($v_header[filename], $p_remove_path_size);
+ TrFctMessage(__FILE__, __LINE__, 3, "Resulting file is '$v_header[filename]'");
+ }
+
+ // ----- Add the path to the file
+ if (($p_path != "./") && ($p_path != "/"))
+ {
+ // ----- Look for the path end '/'
+ while (substr($p_path, -1) == "/")
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
+ TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");
+ }
+
+ // ----- Add the path
+ if (substr($v_header[filename], 0, 1) == "/")
+ $v_header[filename] = $p_path.$v_header[filename];
+ else
+ $v_header[filename] = $p_path."/".$v_header[filename];
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");
+
+ // ----- Check that the file does not exists
+ if (file_exists($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");
+
+ // ----- Look if file is a directory
+ if (is_dir($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");
+
+ // ----- Change the file status
+ $v_header[status] = "already_a_directory";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ // ----- Look if file is write protected
+ else if (!is_writeable($v_header[filename]))
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");
+
+ // ----- Change the file status
+ $v_header[status] = "write_protected";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ // ----- Look if the extracted file is older
+ else if (filemtime($v_header[filename]) > $v_header[mtime])
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");
+
+ // ----- Change the file status
+ $v_header[status] = "newer_exist";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ }
+
+ // ----- Check the directory availability and create it if necessary
+ else
+ {
+ if ($v_header[typeflag]=="5")
+ $v_dir_to_check = $v_header[filename];
+ else if (!strstr($v_header[filename], "/"))
+ $v_dir_to_check = "";
+ else
+ $v_dir_to_check = dirname($v_header[filename]);
+
+ if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");
+
+ // ----- Change the file status
+ $v_header[status] = "path_creation_fail";
+
+ // ----- Skip the extract
+ $v_extraction_stopped = 1;
+ $v_extract_file = 0;
+ }
+ }
+
+ // ----- Do the real bytes extraction (if not a directory)
+ if (($v_extract_file) && ($v_header[typeflag]!="5"))
+ {
+ // ----- Open the destination file in write mode
+ if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");
+
+ // ----- Change the file status
+ $v_header[status] = "write_error";
+
+ // ----- Jump to next file
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");
+
+ // ----- Read data
+ $n = floor($v_header[size]/512);
+ for ($i=0; $i<$n; $i++)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));
+ if ($p_tar_mode == "tar")
+ $v_content = fread($v_tar, 512);
+ else
+ $v_content = gzread($v_tar, 512);
+ fwrite($v_dest_file, $v_content, 512);
+ }
+ if (($v_header[size] % 512) != 0)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");
+ if ($p_tar_mode == "tar")
+ $v_content = fread($v_tar, 512);
+ else
+ $v_content = gzread($v_tar, 512);
+ fwrite($v_dest_file, $v_content, ($v_header[size] % 512));
+ }
+
+ // ----- Close the destination file
+ fclose($v_dest_file);
+
+ // ----- Change the file mode, mtime
+ touch($v_header[filename], $v_header[mtime]);
+ //chmod($v_header[filename], DecOct($v_header[mode]));
+ }
+
+ // ----- Check the file size
+ clearstatcache();
+ if (filesize($v_header[filename]) != $v_header[size])
+ {
+ // ----- Error log
+ PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");
+
+ // ----- Jump to next file
+ TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleDelete()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleDelete($p_tarname, $p_file_list, &$p_list_detail, $p_tar_mode)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleDelete", "archive='$p_tarname', list, tar_mode=$p_tar_mode");
+ $v_result=1;
+ $v_nb=0;
+
+ // ----- Look for regular tar file
+ if ($p_tar_mode == "tar")
+ {
+ // ----- Open file
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
+ if (($v_tar = @fopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @fopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ fclose($v_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ }
+
+ // ----- Look for compressed tar file
+ else
+ {
+ // ----- Open the file in read mode
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
+ if (($v_tar = @gzopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ gzclose($v_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ }
+
+ // ----- Read the blocks
+ While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");
+
+ // ----- Clear cache of file infos
+ clearstatcache();
+
+ // ----- Reset delete tag
+ $v_delete_file = FALSE;
+
+ // ----- Read the first 512 block header
+ if ($p_tar_mode == "tar")
+ $v_binary_data = fread($v_tar, 512);
+ else
+ $v_binary_data = gzread($v_tar, 512);
+
+ // ----- Read the header properties
+ if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)
+ {
+ // ----- Close the archive file
+ if ($p_tar_mode == "tar")
+ {
+ fclose($v_tar);
+ fclose($v_temp_tar);
+ }
+ else
+ {
+ gzclose($v_tar);
+ gzclose($v_temp_tar);
+ }
+ @unlink($v_temp_tarname);
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Look for empty blocks to skip
+ if ($v_header[filename] == "")
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");
+ continue;
+ }
+
+ TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");
+
+ // ----- Look for filenames to delete
+ for ($i=0, $v_delete_file=FALSE; ($i $v_header[mtime])
- {
- TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' need to be updated");
- $v_update_file = TRUE;
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' does not need to be updated");
- $v_update_file = FALSE;
- }
-
- // ----- Flag the name in order not to add the file at the end
- $v_found_list[$i] = 1;
- }
- else
- {
- TrFctMessage(__FILE__, __LINE__, 4, "File '$p_file_list[$i]' is not '$v_header[filename]'");
- }
- }
-
- // ----- Copy files that do not need to be updated
- if (!$v_update_file)
- {
- TrFctMessage(__FILE__, __LINE__, 2, "Keep file '$v_header[filename]'");
-
- // ----- Write the file header
- if ($p_tar_mode == "tar")
- {
- fputs($v_temp_tar, $v_binary_data, 512);
- }
- else
- {
- gzputs($v_temp_tar, $v_binary_data, 512);
- }
-
- // ----- Write the file data
- $n = ceil($v_header[size]/512);
- for ($j=0; $j<$n; $j++)
- {
- TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($j+1));
- if ($p_tar_mode == "tar")
- {
- $v_content = fread($v_tar, 512);
- fwrite($v_temp_tar, $v_content, 512);
- }
- else
- {
- $v_content = gzread($v_tar, 512);
- gzwrite($v_temp_tar, $v_content, 512);
- }
- }
-
- // ----- File name and properties are logged if listing mode or file is extracted
- TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
-
- // ----- Add the array describing the file into the list
- $p_list_detail[$v_nb] = $v_header;
- $p_list_detail[$v_nb][status] = ($v_found_file?"not_updated":"ok");
-
- // ----- Increment
- $v_nb++;
- }
-
- // ----- Look for file that need to be updated
- else
- {
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Start update of file '$v_current_filename'");
-
- // ----- Store the old file size
- $v_old_size = $v_header[size];
-
- // ----- Add the file
- if (($v_result = PclTarHandleAddFile($v_temp_tar, $v_current_filename, $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
- {
- // ----- Close the tarfile
- if ($p_tar_mode == "tar")
- {
- fclose($v_tar);
- fclose($v_temp_tar);
- }
- else
- {
- gzclose($v_tar);
- gzclose($v_temp_tar);
- }
- @unlink($p_temp_tarname);
-
- // ----- Return status
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
-
- // ----- Trace
- TrFctMessage(__FILE__, __LINE__, 2, "Skip old file '$v_header[filename]'");
-
- // ----- Jump to next file
- if ($p_tar_mode == "tar")
- fseek($v_tar, ftell($v_tar)+(ceil(($v_old_size/512))*512));
- else
- gzseek($v_tar, gztell($v_tar)+(ceil(($v_old_size/512))*512));
-
- // ----- Add the array describing the file into the list
- $p_list_detail[$v_nb] = $v_header;
- $p_list_detail[$v_nb][status] = "updated";
-
- // ----- Increment
- $v_nb++;
- }
-
- // ----- Look for end of file
- if ($p_tar_mode == "tar")
- $v_end_of_file = feof($v_tar);
- else
- $v_end_of_file = gzeof($v_tar);
- }
-
- // ----- Look for files that does not exists in the archive and need to be added
- for ($i=0; $i=0; $i--)
- {
- // ----- Look for current path
- if ($v_list[$i] == ".")
- {
- // ----- Ignore this directory
- // Should be the first $i=0, but no check is done
- }
- else if ($v_list[$i] == "..")
- {
- // ----- Ignore it and ignore the $i-1
- $i--;
- }
- else if (($v_list[$i] == "") && ($i!=(sizeof($v_list)-1)) && ($i!=0))
- {
- // ----- Ignore only the double '//' in path,
- // but not the first and last '/'
- }
- else
- {
- $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
- }
- }
- }
-
- // ----- Return
- TrFctEnd(__FILE__, __LINE__, $v_result);
- return $v_result;
- }
- // --------------------------------------------------------------------------------
+ if (($v_len = strcmp($p_file_list[$i], $v_header[filename])) <= 0)
+ {
+ if ($v_len==0)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Found that '$v_header[filename]' need to be deleted");
+ $v_delete_file = TRUE;
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Look if '$v_header[filename]' is a file in $p_file_list[$i]");
+ if (substr($v_header[filename], strlen($p_file_list[$i]), 1) == "/")
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "'$v_header[filename]' is a file in $p_file_list[$i]");
+ $v_delete_file = TRUE;
+ }
+ }
+ }
+ }
+
+ // ----- Copy files that do not need to be deleted
+ if (!$v_delete_file)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Keep file '$v_header[filename]'");
+
+ // ----- Write the file header
+ if ($p_tar_mode == "tar")
+ {
+ fputs($v_temp_tar, $v_binary_data, 512);
+ }
+ else
+ {
+ gzputs($v_temp_tar, $v_binary_data, 512);
+ }
+
+ // ----- Write the file data
+ $n = ceil($v_header[size]/512);
+ for ($i=0; $i<$n; $i++)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));
+ if ($p_tar_mode == "tar")
+ {
+ $v_content = fread($v_tar, 512);
+ fwrite($v_temp_tar, $v_content, 512);
+ }
+ else
+ {
+ $v_content = gzread($v_tar, 512);
+ gzwrite($v_temp_tar, $v_content, 512);
+ }
+ }
+
+ // ----- File name and properties are logged if listing mode or file is extracted
+ TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
+
+ // ----- Add the array describing the file into the list
+ $p_list_detail[$v_nb] = $v_header;
+ $p_list_detail[$v_nb][status] = "ok";
+
+ // ----- Increment
+ $v_nb++;
+ }
+
+ // ----- Look for file that is to be deleted
+ else
+ {
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Start deletion of '$v_header[filename]'");
+ TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+
+ // ----- Jump to next file
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));
+
+ TrFctMessage(__FILE__, __LINE__, 4, "Position après jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");
+ }
+
+ // ----- Look for end of file
+ if ($p_tar_mode == "tar")
+ $v_end_of_file = feof($v_tar);
+ else
+ $v_end_of_file = gzeof($v_tar);
+ }
+
+ // ----- Write the last empty buffer
+ PclTarHandleFooter($v_temp_tar, $p_tar_mode);
+
+ // ----- Close the tarfile
+ if ($p_tar_mode == "tar")
+ {
+ fclose($v_tar);
+ fclose($v_temp_tar);
+ }
+ else
+ {
+ gzclose($v_tar);
+ gzclose($v_temp_tar);
+ }
+
+ // ----- Unlink tar file
+ if (!@unlink($p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-11, "Error while deleting archive name $p_tarname");
+ }
+
+
+ // ----- Rename tar file
+ if (!@rename($v_temp_tarname, $p_tarname))
+ {
+ // ----- Error log
+ PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclTarHandleUpdate()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclTarHandleUpdate($p_tarname, $p_file_list, &$p_list_detail, $p_tar_mode, $p_add_dir, $p_remove_dir)
+ {
+ TrFctStart(__FILE__, __LINE__, "PclTarHandleUpdate", "archive='$p_tarname', list, tar_mode=$p_tar_mode");
+ $v_result=1;
+ $v_nb=0;
+ $v_found_list = array();
+
+ // ----- Look for regular tar file
+ if ($p_tar_mode == "tar")
+ {
+ // ----- Open file
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
+ if (($v_tar = @fopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @fopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ fclose($v_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ }
+
+ // ----- Look for compressed tar file
+ else
+ {
+ // ----- Open the file in read mode
+ TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");
+ if (($v_tar = @gzopen($p_tarname, "rb")) == 0)
+ {
+ // ----- Error log
+ PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+
+ // ----- Open a temporary file in write mode
+ $v_temp_tarname = PCLTAR_TEMPORARY_DIR.uniqid("pcltar-").".tmp";//add by warlee;
+ TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");
+ if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)
+ {
+ // ----- Close tar file
+ gzclose($v_tar);
+
+ // ----- Error log
+ PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());
+ return PclErrorCode();
+ }
+ }
+
+ // ----- Prepare the list of files
+ for ($i=0; $i $v_header[mtime])
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' need to be updated");
+ $v_update_file = TRUE;
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' does not need to be updated");
+ $v_update_file = FALSE;
+ }
+
+ // ----- Flag the name in order not to add the file at the end
+ $v_found_list[$i] = 1;
+ }
+ else
+ {
+ TrFctMessage(__FILE__, __LINE__, 4, "File '$p_file_list[$i]' is not '$v_header[filename]'");
+ }
+ }
+
+ // ----- Copy files that do not need to be updated
+ if (!$v_update_file)
+ {
+ TrFctMessage(__FILE__, __LINE__, 2, "Keep file '$v_header[filename]'");
+
+ // ----- Write the file header
+ if ($p_tar_mode == "tar")
+ {
+ fputs($v_temp_tar, $v_binary_data, 512);
+ }
+ else
+ {
+ gzputs($v_temp_tar, $v_binary_data, 512);
+ }
+
+ // ----- Write the file data
+ $n = ceil($v_header[size]/512);
+ for ($j=0; $j<$n; $j++)
+ {
+ TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($j+1));
+ if ($p_tar_mode == "tar")
+ {
+ $v_content = fread($v_tar, 512);
+ fwrite($v_temp_tar, $v_content, 512);
+ }
+ else
+ {
+ $v_content = gzread($v_tar, 512);
+ gzwrite($v_temp_tar, $v_content, 512);
+ }
+ }
+
+ // ----- File name and properties are logged if listing mode or file is extracted
+ TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");
+
+ // ----- Add the array describing the file into the list
+ $p_list_detail[$v_nb] = $v_header;
+ $p_list_detail[$v_nb][status] = ($v_found_file?"not_updated":"ok");
+
+ // ----- Increment
+ $v_nb++;
+ }
+
+ // ----- Look for file that need to be updated
+ else
+ {
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Start update of file '$v_current_filename'");
+
+ // ----- Store the old file size
+ $v_old_size = $v_header[size];
+
+ // ----- Add the file
+ if (($v_result = PclTarHandleAddFile($v_temp_tar, $v_current_filename, $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)
+ {
+ // ----- Close the tarfile
+ if ($p_tar_mode == "tar")
+ {
+ fclose($v_tar);
+ fclose($v_temp_tar);
+ }
+ else
+ {
+ gzclose($v_tar);
+ gzclose($v_temp_tar);
+ }
+ @unlink($p_temp_tarname);
+
+ // ----- Return status
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+
+ // ----- Trace
+ TrFctMessage(__FILE__, __LINE__, 2, "Skip old file '$v_header[filename]'");
+
+ // ----- Jump to next file
+ if ($p_tar_mode == "tar")
+ fseek($v_tar, ftell($v_tar)+(ceil(($v_old_size/512))*512));
+ else
+ gzseek($v_tar, gztell($v_tar)+(ceil(($v_old_size/512))*512));
+
+ // ----- Add the array describing the file into the list
+ $p_list_detail[$v_nb] = $v_header;
+ $p_list_detail[$v_nb][status] = "updated";
+
+ // ----- Increment
+ $v_nb++;
+ }
+
+ // ----- Look for end of file
+ if ($p_tar_mode == "tar")
+ $v_end_of_file = feof($v_tar);
+ else
+ $v_end_of_file = gzeof($v_tar);
+ }
+
+ // ----- Look for files that does not exists in the archive and need to be added
+ for ($i=0; $i=0; $i--)
+ {
+ // ----- Look for current path
+ if ($v_list[$i] == ".")
+ {
+ // ----- Ignore this directory
+ // Should be the first $i=0, but no check is done
+ }
+ else if ($v_list[$i] == "..")
+ {
+ // ----- Ignore it and ignore the $i-1
+ $i--;
+ }
+ else if (($v_list[$i] == "") && ($i!=(sizeof($v_list)-1)) && ($i!=0))
+ {
+ // ----- Ignore only the double '//' in path,
+ // but not the first and last '/'
+ }
+ else
+ {
+ $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
+ }
+ }
+ }
+
+ // ----- Return
+ TrFctEnd(__FILE__, __LINE__, $v_result);
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
// ----- End of double include look
diff --git a/app/template/common/footer.html b/app/template/common/footer.html
index bc11eb93..2f592bb9 100755
--- a/app/template/common/footer.html
+++ b/app/template/common/footer.html
@@ -1,4 +1,4 @@
-