diff --git a/ChangeLog.md b/ChangeLog.md index 4c3b13cd..186f6709 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,16 +1,54 @@ -### ver4.24 `2017/10/10` +### ver4.25 `2017/12/01` +----- +#### update: +- 文件通用选择,支持跨域,允许第三方调用 +- 部分服务器获取当前url异常情况兼容处理. +- tar解压,文件名过长兼容处理(路径大于100字符处理) +- 图片预览大图处理;生成多级缩略图 +- 权限组开启了文件下载权限,对应开启外链功能 +- ace更新到1.29,支持emoji;emmt扩展加载机制优化 +- 编辑器markdown多光标编辑,支持关联工具栏快捷功能 +- aero效果支持,登录界面优化 +- 其他优化:文件名超出部分...表示;正在上传、远程下载关闭页面提醒 + +#### fix bug +- 安全漏洞修复:文件越权读取漏洞紧急修复,iis6配置不当导致安全问题优化 +- 插件自动更新数据同步问题优化 +- 分享文件夹,编辑器打开页面,左侧文件夹展开目录异常问题;(没有上传权限==>不显示上传按钮) +- token错误:下载时、zip文件解压等; 压缩文件内图片预览不了问题 +- 压缩文件内文本文件预览;zip提示错误问题优化 +- 文件列表;内容含有乱码兼容处理(iconv报错优化) +- 全文搜索,中文截取导致json解析错误问题 +- 对话框隐藏对应没有tab时的处理 +- 打开方式界面css bug +- 登陆共享兼容data自定义目录 +- 文件输出缓存 etag优化 +- 其他:分享页面双击重命名屏蔽;markdown工具栏状态自适应;用户分享列表文件大小,navbar菜单新窗口打开问题 +- 移动端优化: + - 文件列表,展开操作时页面滚动问题;桌面宽度不足问题 + - 移动端菜单展开后没有自动收缩 + - 编辑器优化: 隐藏函数列表 + - 功能菜单放置在右下角; + - 电脑版切换放置在左侧弹出层中; + - 重命名文件只选中文件名部分; + - 加号菜单优化 + - iOS设备拍照上传自动重命名文件名 + - iOS 对话框含有iframe 时滚动条失效问题优化 + - 桌面开始菜单优化 + +### ver4.24 2017/10/10 ----- #### update: - url获取服务器兼容性优化(sso部分使用) -- 部分特殊服务区环境兼容. +- 部分特殊服务器环境兼容. #### fix bug - 安全漏洞修复:文件越权读取、删除漏洞;getshell漏洞紧急修复 - 服务器做了端口转发,url获取兼容性问题解决 -- 移动端优化:文件列表,展开操作时页面滚动问题;桌面宽度不足问题 +- 移动端优化:文件列表,展开操作时页面滚动问题;桌面宽度不足问题 - 插件自动更新数据同步问题优化 -- 分享文件夹,编辑器打开页面,左侧文件夹展开目录异常问题;(没有上传权限==>不显示上传按钮) -- 其他优化:错别字更正; 移动端编辑器输入法出不来问题; +- 分享文件夹,编辑器打开页面,左侧文件夹展开目录异常问题;(没有上传权限==>不显示上传按钮) +- 其他优化:错别字更正; 移动端编辑器输入法出不来问题; @@ -18,8 +56,8 @@ ----- #### update: - 压缩文件预览:tab栏中文问题;插件filePath文件名优化记录 -- 上传兼容性优化;支持自定义多线程上传,支持自定义是否二进制上传 -- 其他优化: iframe 点击事件冒泡到上级;编辑器主题黑色样式优化;树目录自动记录以及目录展开状态优化;文件大小逗号分隔; +- 上传兼容性优化;支持自定义多线程上传,支持自定义是否二进制上传 +- 其他优化: iframe 点击事件冒泡到上级;编辑器主题黑色样式优化;树目录自动记录以及目录展开状态优化;文件大小逗号分隔; - 图片缩略图缓存问题优化 - 图片exif插件;图片预览时自动修正方向 - ie8: 样式调整优化,js报错兼容优化 @@ -65,7 +103,7 @@ #### fix bug - 编辑器最大化工具菜单失去焦点问题;编辑器最大化后按钮不可点问题优化 - 支持自定义指定host,避免反向代理导致部分主机请求异常问题 -- 部分https转发的网站,相关插件静态资源引用问题;支持指定网站host +- 部分https转发的网站,相关插件静态资源引用问题;支持指定网站host - 分享文件夹含有密码移动端问题 - chrome 下载文件名含有逗号下载失败问题 - 文件api:压缩文件打开问题 @@ -77,7 +115,7 @@ ### ver4.06 `2017/8/30` ----- #### update: -- 新增用户数据自动备份; +- 新增用户数据自动备份; - 部分服务器远程下载不支持,插件中心新增支持手动下载 - 界面样式优化 - 上传进度title实时更新 @@ -109,7 +147,7 @@ - 文件打开接口hook,target统一设置 - 桌面图标大小和文件列表图标大小分开 - 移动端: - - 拖拽兼容触摸事件;宽度调整;对话框拖拽 + - 拖拽兼容触摸事件;宽度调整;对话框拖拽 - 弹出菜单,点击其他区域默认隐藏 - 打开图片播放处理 - 移动端返回:空路径 @@ -118,8 +156,8 @@ #### fix bug - 修复头部导航栏下拉菜单被对话框挡住问题解决 -- photoSwipe 图片播放重复打开,蒙版没有消失问题 -- CAD预览水印显示登录信息; +- photoSwipe 图片播放重复打开,蒙版没有消失问题 +- CAD预览水印显示登录信息; - office在线编辑、授权用户的底部信息会丢失等问题修复 - 桌面默认图标升级丢失问题 @@ -149,7 +187,7 @@ - 默认内置插件 - yzOffice: 永中office的在线office预览工具,无需服务器在外网,即可轻松实现office各类文件的预览和查看 - zipView: 各类压缩文件打开预览、解压缩工具;压缩文件内的各类文件打开同样支持自定义打开方式;强大到无以复加 - - adminer:数据库管理工具;类似于phpmyadmin,但比他更轻量;同时不失强大 + - adminer:数据库管理工具;类似于phpmyadmin,但比他更轻量;同时不失强大 - googleDocs: google开放的office等文件在线预览支持(程序需要部署在外网) - jPlayer: 音乐视频html5播放器 - officeLive: 微软提供的office在线文档预览接口;可以在线预览office系列文件(程序需要部署在外网) @@ -164,9 +202,9 @@ - 没有关联的扩展名可以自己绑定指定应用,管理员可以搜索应用市场进行关联安装 - 支持文件打开的插件,管理员可以在插件中心设置插件的优先级;更高的自定义 - 文件打开在不同场景的支持 - - 分享文件夹; 文件预览;[image;media;oexe;word;cad;pdf;epub;html;text;unknow] - - 分享文件单页;[image;media;oexe;word;cad;pdf;epub;html;text;unknow] - - 压缩文件内预览: [image;media;pdf;oexe;word;cad;html;text;unknow] + - 分享文件夹; 文件预览;[image;media;oexe;word;cad;pdf;epub;html;text;unknow] + - 分享文件单页;[image;media;oexe;word;cad;pdf;epub;html;text;unknow] + - 压缩文件内预览: [image;media;pdf;oexe;word;cad;html;text;unknow] - 文件管理 - 文件多选勾选框,可以左键多选或取消选择文件 @@ -185,16 +223,16 @@ - 编辑器底部菜单定位错误问题; - 移动端优化 - - 解决android下解压缩iconv转码失败问题;采用mb_string系列函数 + - 解决android下解压缩iconv转码失败问题;采用mb_string系列函数 - 移动端地址栏宽度自适应 - 移动端:图片打开title显示;切换目录关闭图片失败问题;大小自动获取 - - 界面样式优化;图标增强;点击反馈;样式优化 + - 界面样式优化;图标增强;点击反馈;样式优化 - 新增文件九宫格排列方式 - - 文件预览:[image;media;oexe;word;cad;pdf;epub;html;text;unknow] + - 文件预览:[image;media;oexe;word;cad;pdf;epub;html;text;unknow] - 移动端底部版权:登陆页;内容页 - 文件通用预览打开接口 - - 压缩文件预览支持;[文件下载-->直接保存到文件,避免内存占用];压缩文件内预览文本-标题处理 + - 压缩文件预览支持;[文件下载-->直接保存到文件,避免内存占用];压缩文件内预览文本-标题处理 - 文本文件通用预览 - 标题title统一为文件名 - 插件文件参数统一处理 @@ -220,15 +258,15 @@ #### fix bug - 移动端打开未知文件,提示下载,access_token错误 -- 编辑器换行采用windows换行模式 \r\n;兼容记事本查看 +- 编辑器换行采用windows换行模式 \r\n;兼容记事本查看 - 文件夹移动到自己的目录;导致丢失问题; - 分享文件夹允许上传,远程下载时提示错误问题 - 地址栏粘贴window路径兼容优化 C:\aaa\b 地址,转为/ - 文件目录/重复时压缩zip丢失文件名解决. - 按文件大小排序,部分情况排序错误问题 -- 系统设置:添加安全tab;dialog大小调整 +- 系统设置:添加安全tab;dialog大小调整 - 文件保存对话框dialog选择文件错误问题 -- gz文件解压;预览等支持;图标优化 +- gz文件解压;预览等支持;图标优化 - 别人的共享:地址栏问题;是否存在展示问题 - 群组设置成员只读——可以创建副本的bug - Edge浏览器下载中文文件名乱码问题;压缩文件含有中文优化处理 @@ -241,10 +279,10 @@ - 图片预览:加入删除按钮;删除快捷键 - 删除文档对话框样式优化 - 0kb文件上传问题;【拖拽单文件,文件夹;选择文件,文件夹;】上传取消后上传失败优化 -- 普通用户压缩到tar,gz时路径问题解决 +- 普通用户压缩到tar,gz时路径问题解决 - 部分服务器反向代理导致不支持csrf防护的,加入设置中手动开关 - 右键文件夹打开:提示仅支持分享您自己的文档 -- 数据丢失:删除install.lock;重置admin密码;—— 新建用户 +- 数据丢失:删除install.lock;重置admin密码;—— 新建用户 - 分享文件夹预览:图片播放,不支持权限则隐藏对应功能;显示列表模式切换 - 适配新浪sae虚拟主机. @@ -256,26 +294,26 @@ ### ver3.45 `2017/4/9` ----- #### update: -- 安全防护;全面防护csrf攻击;安全性提升。 +- 安全防护;全面防护csrf攻击;安全性提升。 - 高并发下:用户数据文件读写异常处理 - 上传优化: 文件权限设置644->755;大文件分片上传优化;ie浏览器兼容处理;上传失败自动重传机制加入 -- 文件编辑:换行切换为\r\n;兼容windows记事本;标签右键菜单图标样式问题 -- 工具栏——更多菜单加入:浏览器打开;图标优化;右键菜单二级菜单偶尔失去焦点情况处理 -- 远程下载优化:windows下载失败处理,优化多级301跳转文件下载;下载加入同域名referer; 断点续传优化;下载0Kb优化;不支持curl服务器优化; +- 文件编辑:换行切换为\r\n;兼容windows记事本;标签右键菜单图标样式问题 +- 工具栏——更多菜单加入:浏览器打开;图标优化;右键菜单二级菜单偶尔失去焦点情况处理 +- 远程下载优化:windows下载失败处理,优化多级301跳转文件下载;下载加入同域名referer; 断点续传优化;下载0Kb优化;不支持curl服务器优化; - 对话框icon点击菜单,双击icon关闭 - 分配了权限组添加用户权限:但提示没有权限。 - 关闭了下载权限:允许文件预览、pdf、office预览等;屏蔽pdfjs上的下载按钮; -- 快捷键新增:shift+delete 直接删除;alt+enter查看文件属性;alt+left alt+right 历史记录前进后退; +- 快捷键新增:shift+delete 直接删除;alt+enter查看文件属性;alt+left alt+right 历史记录前进后退; - shift + 右键菜单彻底删除;删除提示加入文件名; - 编辑器隐藏时;打开文件自动显示到最上层 - 文件管理:复制快捷键允许冒泡;允许快捷键复制选中的文字 - 壁纸自动下载文件夹放置在桌面下;桌面支持自定义中文文件夹 - IE浏览器样式兼容性调整。 - 文件右键——浏览器打开所有用户开启。 -- markdown预览优化:h1 下划线;预览最大化——禁用左右分栏;加入html转义 +- markdown预览优化:h1 下划线;预览最大化——禁用左右分栏;加入html转义 - 服务端强制设置了cookie为httpOnly导致csrf-token获取失败问题兼容性调整;语言切换失败问题 - 收藏夹树目录:文件夹右键菜单加入文件夹对应功能,不存在则红色显示;可以拖拽文件到收藏夹的文件夹 -- 其他细节优化:样式优化,win7主题播放器样式优化; +- 其他细节优化:样式优化,win7主题播放器样式优化; - php7 兼容性优化.部分版本php报错;token error问题 - 设置加入: - 自定义全局css|全局js[统计代码] @@ -284,25 +322,25 @@ - 其他:清空缓存,清空所有用户回收站;自定义程序logo支持图片 - 移动端优化: - 上传窗口大小优化;移动端下载功能处理;iphone拍照上传文件自动重命名 - - 下拉菜单:新建文件加入;失去焦点隐藏; + - 下拉菜单:新建文件加入;失去焦点隐藏; - 分享目录支持上传:手机端功能加入 - 分享文件夹搜索问题解决 - 左侧目录目录列表和pc端一级目录统一 - 分享页面文件打开未知文件,点击下载跳转到登陆页问题 - - android音视频播放优化,直接打开文件; - - android文件下载;文件名去除*filename + - android音视频播放优化,直接打开文件; + - android文件下载;文件名去除*filename - 前进后端;后退到最后undefined检测。 - 在线解压缩全面支持 - - 支持压缩为zip,tar,gz,tar.gz格式文件 - - 单选,多选右键菜单自动压缩指定内容 - - 右键菜单自动关联压缩文件:支持扩展名zip;tar;tar.gz,tgz,rar,7z,apk,ipa + - 支持压缩为zip,tar,gz,tar.gz格式文件 + - 单选,多选右键菜单自动压缩指定内容 + - 右键菜单自动关联压缩文件:支持扩展名zip;tar;tar.gz,tgz,rar,7z,apk,ipa - 压缩乱码解决:压缩包内中文跨系统支持自动识别,解压缩自动重命名为当前系统编码 - - rar解压支持rar5;mac系统解压缩支持作为插件单独存在; + - rar解压支持rar5;mac系统解压缩支持作为插件单独存在; - 在线预览 - - 支持zip,rar,7z,gz,tar,tgz等格式在线预览,在线解压; - - 自动编码识别:[gbk,utf-8];zip,tar,gz,tgz,rar,7z...;windows,linux(centos,debain) + - 支持zip,rar,7z,gz,tar,tgz等格式在线预览,在线解压; + - 自动编码识别:[gbk,utf-8];zip,tar,gz,tgz,rar,7z...;windows,linux(centos,debain) - 文件列表;树目录,列表展开,中文编码自动识别 - - 浏览,文档属性查看,预览子文件,下载子文件,解压子文件,解压子文件夹,解压全部 + - 浏览,文档属性查看,预览子文件,下载子文件,解压子文件,解压子文件夹,解压全部 - 文件预览在:自己目录;自己分享;分享页面;别人的分享;群组文档;群组共享 - 图片、媒体文件、pdf、flash、oexe、html - 大于30m不直接预览,建议解压后预览;zip中含有zip则提示解压 @@ -314,21 +352,21 @@ 群组文档权限配置; - 后端权限组安全性优化,简化逻辑流程 - 群组角色管理:添加,编辑,修改,删除【隐藏&标签样式】 - - 设置用户群组角色:管理处label样式展示;下拉选择;多语言 + - 设置用户群组角色:管理处label样式展示;下拉选择;多语言 - 前端展示:树目录icon read&write区分弱化;地址栏后label展示为label样式;label显示隐藏统一优化 - - 没有权限优化:新建文件&新建文件夹&重命名文件; + - 没有权限优化:新建文件&新建文件夹&重命名文件; - 运行异常检测并提示 - 解压缩出错处理;不支持检测;shell_exec防注入处理 - - 函数检测 gzopen,gzinflate;[不支持则不能解压] - - js文件缺失报错提示; + - 函数检测 gzopen,gzinflate;[不支持则不能解压] + - js文件缺失报错提示; - 文件夹乱码json输出,json_encode优化;允许未知编码文件输出 - 当开启了php cache时更新不生效提示 - 解压错误输出时避免输出真实目录 - 打包编译优化:去除gzinflate调用;空间支持更广。 - 扩展名没有权限的文件解压:不忽略——追加txt扩展名 - - 优化部分主机防火墙误判问题;(post 字段名不能含有list) net::ERR_CONNECTION_RESET + - 优化部分主机防火墙误判问题;(post 字段名不能含有list) net::ERR_CONNECTION_RESET - 检测列目录速度慢问题优化 - - 授权版降级到免费版部分数丢失问题解决;本地授权写入到lib/core; + - 授权版降级到免费版部分数丢失问题解决;本地授权写入到lib/core; - 目录没有写权限,session不可写判断并做提示 - 剩余空间样式优化:过少则提示 #### fix bug @@ -336,7 +374,7 @@ - cdn静态分离优化:播放器加载html跨站问题 - 授权丢失:强制输入授权码页面 commonjs 加载变为页面问题 - 修复safari音视频播放不了问题;下载断点续传逻辑优化 -- 多选右键操作;父子文件夹包含问题误判解决 +- 多选右键操作;父子文件夹包含问题误判解决 - 解压文件权限判断错误:压缩文件目录不可写,解压到某个文件夹可写 - 手动覆盖更新update更新文件没有删除自己权限问题解决。 - 多选下载加入防跨站请求token @@ -382,9 +420,9 @@ - 授权版组织架构不显示 - 系统设置——错误提示位置问题,加入关闭按钮。 - 移动端对话框绝对位置问题 -- 树目录文件名排序问题;排序模式优化(首次打开没有排序);收藏夹、组织架构不排序 +- 树目录文件名排序问题;排序模式优化(首次打开没有排序);收藏夹、组织架构不排序 - office编辑保存权限处理;没有权限则只读 -- office在线编辑新页面打开,文件格式完善;分享页面&分享目录下文件预览; +- office在线编辑新页面打开,文件格式完善;分享页面&分享目录下文件预览; - 上传大文件,同名文件处理策略没有按配置方式 - 上传大文件断点续传优化;上传大文件有概率出现内容错误问题 - 文件频繁读写内容出现异常的问题优化 @@ -402,64 +440,64 @@ - 自定义公共目录名称:使用群组名称(如果name不等于public) #### fix bug - - 下载链接rewrite默认关闭;修复部分主机打不开pdf,office文档问题 + - 下载链接rewrite默认关闭;修复部分主机打不开pdf,office文档问题 - 错误提示统一处理;超时时间优化;不再检测connected状态 - - 输出清空之前缓存(show_json,验证码,文件下载,显示模板) + - 输出清空之前缓存(show_json,验证码,文件下载,显示模板) - 用户管理界面:用户名宽度加宽;授权版支持批量添加用户 - 自动更新优化,更新失败相应处理;util.js误判问题修复; - - 前端处理 app_host;web_host兼容部分反向代理设置;上传等问题解决 + - 前端处理 app_host;web_host兼容部分反向代理设置;上传等问题解决 ### ver3.36 `2016/12/31` ----- #### update: - - UI样式各个细节兼容性调整;ie8图标优化;移动端样式优化;右键二级菜单位置优化(点不到问题) - - 文件(夹)可读写检测兼容性增强;兼容docker、虚拟机挂载目录读写判断 - - 大于4G文件大小获取错误;下载失败问题 - - 移动到回收站——window文件夹新建特殊字符处理;文件名不允许字符检测 win,linux各自检测;群组文件删除,移动到自己的回收站; - - 剪切文件夹,数据不完整处理(遍历问题,删除文件夹导致遍历中断) - - 文件上传分片大小默认设定,可以自定义上传分片大小;提高上传超大文件的成功率 - - 文件夹拖拽上传,文件夹含超过100个时丢失问题;(文件夹内含有软连接会忽略) - - 分享——文件属性(md5懒加载;图片尺寸查看) - - 下载链接优化,采用类伪静态地址;第三方软件下载时文件名能更友好 - - 通用音效设置处理,增加用户设置开关,默认关闭 - - 视频播放自适应宽度高度 - - 文件打开历史记录:不存在时自动关闭标签;浏览器用户数据存储——区分用户id[] - - 输出缓冲区统一处理,兼容下载文件等操作含BOM的影响; - - 分享页面多语言设置 - - 游客打开pdf问题优化,移动端打开pdf自适应优化 - - 扩展应用;应用中心样式修复;ie11新建应用导致丢失问题;含双引号的应用无法添加问题; - - 应用编辑,增加首次打开全屏选项;全屏应用取消全屏大小调整优化 - - 双击文件名重命名功能加入 - - 时间戳统一成24小时制式 - - 文件下载优化: - - 中文文件下载win下文件名乱码修复; - - firefox下载文件,文件名含有空格截断问题 - - 下载大文件,兼容部分服务器反应慢问题;断点续传优化 - - 编辑器优化: - - php文件编辑注释错误;(php,js注释错误;css,html正确);自动补全 php-html-js-css; php--html_worker; - - 编辑器新增php代码格式化功能;(缩进处理,空白字符处理;) - - 编辑器关键字去掉加粗,优化部分浏览器光标问题 - - 中文文件打开乱码问题优化;utf8有bom及无bom、GBK,Unicode等文本编码自动识别 - - markdown快捷键只用于md模式中;markdown公式支持更新(编辑器;分享页面) - - 跨系统含中文,解压缩优化 - - win下压缩,上传到(linux/windows);解压自动识别编码 - - linux下压缩,上传到(linux/windows);解压自动识别编码 - - linux访问(linux/windows)服务器,下载文件夹压缩编码自动识别 - - windows访问(linux/windows)服务器,下载文件夹压缩编码自动识别 - - 自动更新优化 - - 升级失败问题优化 - - 用户组根目录home建立 - - 显示用户目录、显示用户组目录;中文处理(新建用户,删除) - - 去除代码加密;安全狗误报问题优化($_REQUEST['']) - - 禁止列目录检测 +- UI样式各个细节兼容性调整;ie8图标优化;移动端样式优化;右键二级菜单位置优化(点不到问题) +- 文件(夹)可读写检测兼容性增强;兼容docker、虚拟机挂载目录读写判断 +- 大于4G文件大小获取错误;下载失败问题 +- 移动到回收站——window文件夹新建特殊字符处理;文件名不允许字符检测 win,linux各自检测;群组文件删除,移动到自己的回收站; +- 剪切文件夹,数据不完整处理(遍历问题,删除文件夹导致遍历中断) +- 文件上传分片大小默认设定,可以自定义上传分片大小;提高上传超大文件的成功率 +- 文件夹拖拽上传,文件夹含超过100个时丢失问题;(文件夹内含有软连接会忽略) +- 分享——文件属性(md5懒加载;图片尺寸查看) +- 下载链接优化,采用类伪静态地址;第三方软件下载时文件名能更友好 +- 通用音效设置处理,增加用户设置开关,默认关闭 +- 视频播放自适应宽度高度 +- 文件打开历史记录:不存在时自动关闭标签;浏览器用户数据存储——区分用户id[] +- 输出缓冲区统一处理,兼容下载文件等操作含BOM的影响; +- 分享页面多语言设置 +- 游客打开pdf问题优化,移动端打开pdf自适应优化 +- 扩展应用;应用中心样式修复;ie11新建应用导致丢失问题;含双引号的应用无法添加问题; +- 应用编辑,增加首次打开全屏选项;全屏应用取消全屏大小调整优化 +- 双击文件名重命名功能加入 +- 时间戳统一成24小时制式 +- 文件下载优化: + - 中文文件下载win下文件名乱码修复; + - firefox下载文件,文件名含有空格截断问题 + - 下载大文件,兼容部分服务器反应慢问题;断点续传优化 +- 编辑器优化: + - php文件编辑注释错误;(php,js注释错误;css,html正确);自动补全 php-html-js-css; php--html_worker; + - 编辑器新增php代码格式化功能;(缩进处理,空白字符处理;) + - 编辑器关键字去掉加粗,优化部分浏览器光标问题 + - 中文文件打开乱码问题优化;utf8有bom及无bom、GBK,Unicode等文本编码自动识别 + - markdown快捷键只用于md模式中;markdown公式支持更新(编辑器;分享页面) +- 跨系统含中文,解压缩优化 + - win下压缩,上传到(linux/windows);解压自动识别编码 + - linux下压缩,上传到(linux/windows);解压自动识别编码 + - linux访问(linux/windows)服务器,下载文件夹压缩编码自动识别 + - windows访问(linux/windows)服务器,下载文件夹压缩编码自动识别 +- 自动更新优化 + - 升级失败问题优化 + - 用户组根目录home建立 + - 显示用户目录、显示用户组目录;中文处理(新建用户,删除) + - 去除代码加密;安全狗误报问题优化($_REQUEST['']) + - 禁止列目录检测 #### fix bug - 编辑器:树目录多一个undefined问题 - 文件(夹)移动、删除到回收站;————兼容不在同一个磁盘 - 搜索:文字超出部分处理;未知文件打开下载不了问题修复 - 用户组上传权限对管理员开启。虚拟目录读写权限判断优化 - - 登陆偶尔ajax报错;登陆页空flash闪烁 + - 登陆偶尔ajax报错;登陆页空flash闪烁 - 对话框关闭,偶尔闪烁问题修复 - 其他用户分享根目录不允许删除 - 图片旋转,php环境不支持提示 @@ -481,43 +519,43 @@ - 多选后右键加入 "复制到","移动到" 选择指定文件夹 - 幻灯片播放:新增支持图片旋转功能;增加图片当前位置;加入全屏功能 - pdf浏览支持html5方式 - - 文件icon优化:高清重置图标,支持retina;缩略图优化,支持超大图标;icon共享(文件图标,任务栏,树目录,编辑器,标题栏等) + - 文件icon优化:高清重置图标,支持retina;缩略图优化,支持超大图标;icon共享(文件图标,任务栏,树目录,编辑器,标题栏等) - 系统图标:收藏、发送到快捷方式、地址栏;统一对应图标 - 分享、快捷键等图标统一meta标签支持 - 拖拽增强:新增拖拽到回收站——删除;拖拽到地址栏——复制or粘贴;拖拽到树目录——复制粘贴,ctrl拖拽复制到指定文件夹 - 下载权限弱化:禁用下载权限后,任然可以获取文件内容,查看图片,pdf,视频,音乐等在线浏览功能 - 树目录自动记录第一层级打开关闭状态;同时记录编辑器;文件打开对话框等 - 新增状态栏:当前文件夹项目数、选中数展示 - - 文件属性,增加查看文件md5;图片文件支持查看图片尺寸;大文件md5延迟加载 - - 当前目录变更;左侧树目录对应状态选中;编辑器同理 (path相同则忽略——避免树目录多个存在) + - 文件属性,增加查看文件md5;图片文件支持查看图片尺寸;大文件md5延迟加载 + - 当前目录变更;左侧树目录对应状态选中;编辑器同理 (path相同则忽略——避免树目录多个存在) - 文件管理菜单栏优化:功能下拉增加『加入到收藏夹』;自动针对当前目录类型,读写情况功能适配 - 发送到桌面快捷方式:支持文件、文件夹、虚拟目录等创建桌面快捷方式 - 收藏夹:添加取消收藏采用局部刷新;支持收藏文件、回收站、用户分享、群组等虚拟目录;对应不存在则提示 - 收藏夹、全部群组、用户共享、自己的群组等虚拟目录的列表查看;和树目录展开保持一致;是否有子目录处理 - 桌面优化:内容过多时允许滚动条;框选优化;捷键键问题修复,上下左右,shift Ctrl多选 - - 随机壁纸获取;精选壁纸;切换后自动下载到home/picture/wallpage 文件夹;兼容https + - 随机壁纸获取;精选壁纸;切换后自动下载到home/picture/wallpage 文件夹;兼容https - 下载链接,分享链接;对话框内含iframe;加入二维码 - - 桌面回收站空&满,状态自动更新 + - 桌面回收站空&满,状态自动更新 - 左侧树目录宽度修改后支持配置保存服务器 - - 打开文件夹管理时,焦点选择优化;快捷键等定位到当前焦点 + - 打开文件夹管理时,焦点选择优化;快捷键等定位到当前焦点 - 重命名或新建文件&文件夹,名称过长时高度自适应;新建文件、文件夹支持同名策略 - 文件过多时,框选优化;自动滚动屏幕 - 文件拖拽UI简化;多选拖拽对不同状态进行优化展示;动画效果加入 - 框选优化:框选到某个元素弹起时该元素也选中;文件框选最后一个没有选中问题 - 回收站,多选右键菜单不恢复问题;回收站删除问题。新增:加入文件右键——彻底删除; - 文档目录发生变化(新建,删除);左侧目录自动更新; - - 树目录优化:文件夹有子目录没有展开选项;树目录展开文件夹loading状态优化;树目录icon优化;地址栏处理 + - 树目录优化:文件夹有子目录没有展开选项;树目录展开文件夹loading状态优化;树目录icon优化;地址栏处理 - 树目录创建副本问题:文件夹副本需要刷新父节点 - 树目录优化:文件浏览则——单击打开该目录&双击展开收缩;文档编辑——单击则展开收缩 - 解决树目录新建文件、文件夹时,该节点未展开时状态错误 - 文档列表html模板简化啊,文件分离;优化图片picasa浏览 - - oexe图标问题;markdown pre 中文字体; + - oexe图标问题;markdown pre 中文字体; - 前进后退优化,改为客户端维持,多窗口独立自己的前进后退列表;前进后退历史记录问题处理 - 权限提示优化:目录不可写or只读 菜单栏及右键菜单功能屏蔽;目录不存在时提示; - - 文件重命名支持大小写[mac-ok;linux,windows] - - 文件输出加入缓存机制;针对变化才重新输出 + - 文件重命名支持大小写[mac-ok;linux,windows] + - 文件输出加入缓存机制;针对变化才重新输出 - 文件下载优化:实时检测是否下载完成(兼容url读取一直没有中断问题) - - 拖拽:非文件、url、网页文件、文本【上传dialog——只有文件才处理;没有上传权限则不提示上传选项】 + - 拖拽:非文件、url、网页文件、文本【上传dialog——只有文件才处理;没有上传权限则不提示上传选项】 - 非web目录,右键浏览器打开:给出提示 - 新建文件&文件夹;自动滚动到可视区 - 重命名:textarea双击——不再处理 @@ -557,7 +595,7 @@ - 分享页面、目录等细节调整,优化flash文件不显示问题 - 分享目录,列表排序模式等客户端自动记录 - 下载权限和预览权限弱化;【可以预览,但限制下载】 - - 自己共享、别人共享、群组空间、群组共享【对应右键菜单处理,菜单处理】 + - 自己共享、别人共享、群组空间、群组共享【对应右键菜单处理,菜单处理】 - 分享根目录工具栏、右键菜单处理(区分自己和其他人); - 自己的分享加入标签;默认直接分享(名称已存在则弹出层);——已分享则弹出编辑。 - 分享时间上午下午未区分问题 @@ -568,9 +606,9 @@ - 用户分享目录处理;是否存在处理,查看二级目录path问题。 - 分享优化:别人的分享目录:右键简化——编辑共享;取消共享 - 播放器优化 - - 全新的视频播放器,支持格式:mp4,m4v,mov,ogv,webm,webmv,flv - - 全新的音乐播放器,支持格式:mp3,wav,m4a,aac,ogg,oga - - 支持html5及flash自动切换,ie8+,safari,firefox,chrome等主流浏览器 + - 全新的视频播放器,支持格式:mp4,m4v,mov,ogv,webm,webmv,flv + - 全新的音乐播放器,支持格式:mp3,wav,m4a,aac,ogg,oga + - 支持html5及flash自动切换,ie8+,safari,firefox,chrome等主流浏览器 - 视频播放,根据视频宽高自动调整尺寸; - 音乐播放器支持音乐列表;多选文件,右键可添加到播放列表:视频自动过滤 - 跨窗口播放;分享音乐视频文件页面适配 @@ -588,15 +626,15 @@ - 上传优化 - 修复上传时切换目录导致上传到其他地方问题 - 客户端分片上传,不再受限于服务器各种配置限制;分片失败自动重传 - - 改进某个文件夹内容大于100个的限制;(文件夹内含有软连接会忽略) + - 改进某个文件夹内容大于100个的限制;(文件夹内含有软连接会忽略) - 支持断点上传(上传失败,浏览器刷新,即便是换电脑,只要是同一个文件,都会接着上次上传的位置继续上传。) - 小于1k文件大小显示错误,解决大小为0文件上传失败问题 - ie9+ 拖拽上传兼容性调整:未打开对话框时拖拽不生效问题 - webkit内核浏览器支持文件夹拖拽直接上传(保持目录结构) - 选择文件夹上传(支持webkit内核浏览器) - - flash上传失败问题;(采用分片上传),解决ie上传分片问题 + - flash上传失败问题;(采用分片上传),解决ie上传分片问题 - 上传速度显示优化,进度精确到小数点后一位 - - 解决上传失败问题:拼接错误,百分比乱跳【nginx post限制——导致每个包都上传失败;配置最大上传分包】 + - 解决上传失败问题:拼接错误,百分比乱跳【nginx post限制——导致每个包都上传失败;配置最大上传分包】 - 上传大小限制:用户&群组;空间大小记录&上限处理 【上传、远程下载、从回收站删除,剪切——粘贴(是否自己空间——加减)】——组没有回收站 - 编辑器优化 - 鼠标中键多光标选择,ctrl+shift+G多选模式 @@ -604,8 +642,8 @@ - 记录文件打开历史纪录:并自动打开;并按项目区分;新打开不存在则提示 - 状态栏显示:当前行、列、选择时光标位置、多光标选择等、选中内容长度;切换语言高亮语法 - 打开新文件时自动显示编辑器并提到最前面 - - 增加代码格式化功能【js,css,html,php 可以格式化选择部分;没有选中则格式化整个文档】 - - 函数列表匹配优化;全功能匹配php,javascript;支持快捷搜索;函数部分正则匹配卡死问题,增强函数匹配功能(js,c,php等) + - 增加代码格式化功能【js,css,html,php 可以格式化选择部分;没有选中则格式化整个文档】 + - 函数列表匹配优化;全功能匹配php,javascript;支持快捷搜索;函数部分正则匹配卡死问题,增强函数匹配功能(js,c,php等) - 支持扩展名增强;150种语言 - 搜索优化;支持批量选择同时编辑(同sublime快捷键:ctrl+win+G) - 代码主题切换,自动适应整个编辑器主题切换;风格融为一体 @@ -634,7 +672,7 @@ - 搜索历史记录记住;(上下切换历史记录;开启搜索未选中词时,默认展示最后一次搜索内容;搜索历史记录下拉列表)[local_storage] - 搜索设置配置保存 (正则;大小写;全词匹配) - 文档含有引号创建快捷方式转义处理;打开文件dialog头部生成二维码连接及url处理 - - 解决部分apache配置原因导致php-mode.js加载失败问题 php-mode重命名为phhp-mode; + - 解决部分apache配置原因导致php-mode.js加载失败问题 php-mode重命名为phhp-mode; - API支持 - 通用文件夹、文件选择弹框 - 支持限定选择文件、文件夹或混合类型;支持限定文件扩展名 @@ -643,13 +681,13 @@ - kod提供第三方应用同步登陆;支持指定用户名、用户组、权限组等方式登陆;其他系统能共享kod的登陆状态 - 第三方可以通过api方式进行某个用户的自动登陆; 便于集成到另一个系统 - 支持markdown - - 支持markdown文档实时编辑预览;导出网页文件;markdown文档分享则自动转换。 + - 支持markdown文档实时编辑预览;导出网页文件;markdown文档分享则自动转换。 - 自动开启预览;预览去除动画进出;函数列表自动开启关闭; - - 滚动条自动跟随;markdown全屏预览取消scroll跟随 + - 滚动条自动跟随;markdown全屏预览取消scroll跟随 - LaTeX公式支持;行内公式、块级公式;高效率自动绘制;延迟解析 - 根据编辑器主题自动生成对应的风格 - markdown分享页面;TOC连接点击 - - markdown工具栏支持;插入图片支持从文件选择;自动生成图片外链 + - markdown工具栏支持;插入图片支持从文件选择;自动生成图片外链 - 搜索增强 - 文件夹搜索,速度优化(先文件扫描);自动终止搜索(搜索时间计时;超过10s则提示;可取消搜索) - 搜索列表:点击文件对应打开文件或文件夹;支持进入文件所在目录 @@ -657,44 +695,44 @@ - 搜索文件新增全文搜索,支持罗列所有搜索项【对话框展示,搜索按行搜索,避免内存占用问题】 - 搜索结果显示行数,点击能直接定位到指定位置。 - 增加组织架构 - - 创建编辑用户组——父组,可以手动下拉树选择;添加用户选择组同一功能 + - 创建编辑用户组——父组,可以手动下拉树选择;添加用户选择组同一功能 - 用户组管理:右键用户【查看,删除-禁用-启用;移除该组,权限设置为】 - - 用户多选批量【禁用,解除禁用;移动到组,添加到组,设置权限角色为,设置用户空间】 - - 权限设置:下载权限和预览权限分开。默认有预览权限、但没有下载权限//];下载统一不暴露url地址,path_id + - 用户多选批量【禁用,解除禁用;移动到组,添加到组,设置权限角色为,设置用户空间】 + - 权限设置:下载权限和预览权限分开。默认有预览权限、但没有下载权限//];下载统一不暴露url地址,path_id - 支持用户、群组空间大小设置;用户&组空间使用情况; - - 支持自定义群组所在目录; - - 支持自定义用户所在目录; + - 支持自定义群组所在目录; + - 支持自定义用户所在目录; - 其他优化 - - 全面适配htts; + - 全面适配htts; - 增加win10主题;新增炫彩系列主题;用户也可以自定义主题风格 - - 炫彩主题增强:背景——渐变色配色 [开始颜色,终止颜色,旋转角度];背景图片——自定义;选择;跟随壁纸,是否模糊 + - 炫彩主题增强:背景——渐变色配色 [开始颜色,终止颜色,旋转角度];背景图片——自定义;选择;跟随壁纸,是否模糊 - 通用对话框优化:最大化、还原、最小化、显示、隐藏加入动画 - 用户配置数据本地存储 localStorage cookie相互兼容 - - tips控件优化;tips允许重复;loading公用一个;统一后端错误提示 + - tips控件优化;tips允许重复;loading公用一个;统一后端错误提示 - checkbox radiobox ui优化 - 可以设置开启关闭回收站 - 对话框事件焦点优化(打开多个文档管理,快捷键等响应到当前) - 优化拖拽超出当前iframe或者浏览器后事件丢失问题【框选,选中拖拽,tab拖拽,dialog拖拽,editor选择等】 - 更新播放器,拖拽进度条出错的问题。 - - 安装初始化用户目录及公共组:默认用户目录随机生成;【admin/demo/guest;public】;默认数据设为空;安装判空 + - 安装初始化用户目录及公共组:默认用户目录随机生成;【admin/demo/guest;public】;默认数据设为空;安装判空 - 右键菜单优化:宽度自适应 - 分组没有子目录则不显示组织架构【只显示公共目录】 - 复制粘贴;来源和目标权限检测冲突解决。 - 全面隐藏用户真实路径【回收站、树目录、搜索、共享目录查看、文件列表、浏览打开——只有管理员才有web目录结构————html打开等】 - office预览如果是内网或domain不为外网 则提示购买【iframe——提示信息】 - - office 本地转换预览,office预览支持自定义 + - office 本地转换预览,office预览支持自定义 - 应用列表:应用内容更新优化(不可访问部分删除) - 权限分离:角色创建分离————编辑、删除、修改;添加用户限制不能是管理员[] - 群组访问地址栏优化;tips;树目录及地址栏icon:访客,组用户只读,组用户读写 - 群组不同权限的图标有所不同【不在组,在该组,组管理员】 - 权限设置:去掉群组、用户管理配置; - 域名转发:APPHOST兼容性调整 分享地址、文件属性打开地址等等 - - 允许在iframe下使用。【文本打开;setting;应用程序;artdialog.though】 + - 允许在iframe下使用。【文本打开;setting;应用程序;artdialog.though】 - 增加iframe下文件查看类型【type=explorer|file_list】//文档查看、文件列表 - firefox:右键菜单子菜单问题;设置——用户管理弹出层尺寸拖动问题 - 设置部分,后端模板文件处理成前端模板 - - 全局字体调整;用em作单位 - - 各种错误提示优化,更好的兼容php各种环境; + - 全局字体调整;用em作单位 + - 各种错误提示优化,更好的兼容php各种环境; - 首次登陆目录不可写提示,登陆页面多语言选择 - 登陆页面密码找回提示;管理员密码快速找回;
 - 验证码复杂性增强 @@ -712,7 +750,7 @@ - ie 兼容问题。ie透明背景处理【css皮肤不加载-使用默认】 - firefox兼容性优化:选中文件后拖拽问题(没有hover),插入style样式不生效问题 - Safari兼容性优化:对话框打开尺寸错位问题;加载文件时loading位置问题 - - chrome兼容性优化:错位问题:编辑器开启搜索,当搜索不在屏幕区域会撑开头部,53版本编辑器输入中文问题解决 + - chrome兼容性优化:错位问题:编辑器开启搜索,当搜索不在屏幕区域会撑开头部,53版本编辑器输入中文问题解决 - session 重定向循环问题 【本地session-cookie和服务端不一致】 - ie8 兼容性优化 - ie11重命名,点击input失去焦点。 @@ -720,7 +758,7 @@ - 列表时文件夹展开图标不可见 - split文件夹右侧图标不可见;点击展开无效 - 拖拽时hover状态丢失; - - pie ie678界面兼容处理(圆角;background-size;透明度) + - pie ie678界面兼容处理(圆角;background-size;透明度) @@ -746,7 +784,7 @@ - 自动更新失败问题 - 编辑器 中文光标错位问题 - 修复https访问 - - ie8 登陆页面白色背景问题;(没有背景图片);桌面背景图片缩放问题 + - ie8 登陆页面白色背景问题;(没有背景图片);桌面背景图片缩放问题 - ie下载文件,中文文件urlencode问题(windows——服务器;浏览器——ie) - 回收站非admin文件属性;路径隐藏 - 文件夹权限修改bug @@ -805,7 +843,7 @@ ----- #### update: - 文档分享[文件、文件夹分享;支持添加密码;文件分享支持多种格式在线预览] - - 回收站;(避免误删除) + - 回收站;(避免误删除) - 系统设置(自定义程序的一些配置) - 头部菜单管理 - 文件夹下载,多选批量下载 @@ -814,21 +852,21 @@ - 分片上传,不再受php.ini环境限制; - 加入上传速度 - 上传目录:随着当前目录变化而变化。 - - 上传完成可点击,进入文件所在目录 - - 界面简化(不显示切换到当前目录;保存路径不要,列表不自动删除;不需要最大化,以及调整窗口大小) + - 上传完成可点击,进入文件所在目录 + - 界面简化(不显示切换到当前目录;保存路径不要,列表不自动删除;不需要最大化,以及调整窗口大小) - 上传;总status ——放到标题栏 - 大文件分片上传尝试(失败情况处理) - 上传文件夹:不刷新f5 - 最后刷新 - - 显示文件名,大小; + - 显示文件名,大小; - 允许重复文件上传 - 上传前可以删除 - 进图展示优化:显示文件大小、速度、完成进度 - 编辑器: - - 编辑器 函数列表;c9 IDE;展示并定位;实时更新:php function、js:function + - 编辑器 函数列表;c9 IDE;展示并定位;实时更新:php function、js:function - 函数列表开启与关闭配置 - php代码自动补全 缺少关键字部分 - 下拉列表;点击其他地方则消失 - - 非txt则open;不能open则tips bindary:fla ...;右键加入:强制编辑 + - 非txt则open;不能open则tips bindary:fla ...;右键加入:强制编辑 - 字体优化 - 修复github主题光标位置错位问题(选中、编辑都会出现) - 离线下载优化:加入取消机制;避免持续执行;显示文件大小、速度、完成进度 @@ -837,20 +875,20 @@ - 对话框,标题栏右键加入:刷新、新窗口打开 - 对话框双击最大化、取消最大化(只对可以缩放的对话框有效) - 对话框最大化、最小化对话框放大按钮图标改变 - - 权限前端验证(上传等 上传格式前端限制);前端检测 - 新建、上传、删除 + - 权限前端验证(上传等 上传格式前端限制);前端检测 - 新建、上传、删除 - 设置中心 - -用户管理 非管理员显示优化 - 公共js部分采用动态调用方式;后续优化可由js完成前端MVC - 文件、文件夹创建快捷方式 - 文件夹创建工程项目 - 未知文件打开提示、不自动下载 - 右键菜单:加入字母快捷打开 - - 右键自适应:隐藏 - -zip - 视频;多选时:含有视频音频文件时才显示——加入播放列表 + - 右键自适应:隐藏 - -zip - 视频;多选时:含有视频音频文件时才显示——加入播放列表 - 右键触发到菜单上(暂时修改jquery-contentMenu 屏蔽右键按下移动触发菜单功能) - 拖拽优化:框选、tasktap切换;选中其他文字问题;性能问题 - 框选文件,超出屏幕则自定滚动选中;屏蔽文字可以被选中的问题 - simple主题,界面UI优化 - seajs text:tpl修改为html; - - 统一走proxy;隐藏真实地址;web_root,web_host, + - 统一走proxy;隐藏真实地址;web_root,web_host, - 统一proxy后,office打开权限问题解决:加密方式生成临时访问地址 - 播放器更多格式支持:wmv、avi、mpg等 @@ -865,8 +903,8 @@ - 桌面新建位置问题;列表在不同情况下新建问题。始终放在最后 - firefox兼容性 mac兼容性;ie9 10兼容性; - appstore 创建、修复只允许管理员操作,显示优化 - - app创建,js代码类型时,单引号导致不可用问题。 - - 循环跳转 session判断 if(!isset($_SESSION)){session_start();} + - app创建,js代码类型时,单引号导致不可用问题。 + - 循环跳转 session判断 if(!isset($_SESSION)){session_start();} - win下 中文扩展名导致获取目录列表问题:扩展名获取优化 - 编辑器保存 ajax 异步请求。loading - 上传目录错误问题;(上传到了其他目录 ie8 中文) @@ -924,7 +962,7 @@ - 任意执行:远程下载apache 扩漏洞:判断扩展名中是否含有.php. - 不存在的用户 - 桌面:开始按钮被tab盖住了 - - 主题切换,错位问题 + - 主题切换,错位问题 - 透明对话框拖动时 标题栏不显示问题 ### ver2.71 `2014/8/31` @@ -948,7 +986,7 @@ - 安全及性能优化 - 静态文件加入?版本标识,版本更新后不缓存 - webuploader 升级到0.14 优化部分上传问题 - - 错误级别:error_reporting(E_ERROR | E_WARNING); + - 错误级别:error_reporting(E_ERROR | E_WARNING); - 地址栏(tab模式、编辑模式)两种模式宽度自适应 - 自建office解析服务器配置 - 最大化全屏 @@ -965,19 +1003,19 @@ ### ver2.61 `2014/7/12` ----- #### update: - - 实时搜索,根据搜索框内容变化,实时选中匹配到的结果; + - 实时搜索,根据搜索框内容变化,实时选中匹配到的结果; - 弹出搜索框遍历子文件夹递归搜索 - session key 加入kod_前缀 避免和其他系统key冲突 - 编辑器选中优化 选择鼠标到窗口外事件处理 #### fix bug:(bug解决和程序优化) - - backspace后退截获浏览器事件,作为后退前一次访问的文件夹; + - backspace后退截获浏览器事件,作为后退前一次访问的文件夹; - 搜索首字母不匹配问题 - 弹出层中的弹出层关闭,父窗口失去焦点问题。 - 代码中grunt部分代码拆分开,放到程序外面;提交到git、osc - 桌面:删除alert enter快捷键删除 - install 检测 加入跳过,(只判断用到的函数) 加入多语言 - - zip压缩没有权限 提示红色,false 统一查找 + - zip压缩没有权限 提示红色,false 统一查找 - 登录成功后 验证码输错清除 - 非root用户拖拽到文件夹问题 - 非root解压问题 不能解压 @@ -990,30 +1028,30 @@ ### ver2.6 `2014/7/6` ----- #### update: - - 完全性优化;加入严格的校验机制 + - 完全性优化;加入严格的校验机制 - 首次运行环境检测[data目录检测,必须的函数支持提示] - 上传已存在处理——创建副本(另外包括粘贴,解压) - 选中优化 ctrl选中拖拽 - - 键盘快捷键选中文件,多个字符支持 - - 文件文件夹权限修改(右键——属性,即可修改) - - 对话框加入ico,对应任务栏 + - 键盘快捷键选中文件,多个字符支持 + - 文件文件夹权限修改(右键——属性,即可修改) + - 对话框加入ico,对应任务栏 - 右键等部分菜单效果优化 - - 远程下载加入进度条,下载速度等信息 + - 远程下载加入进度条,下载速度等信息 #### fix bug:(bug解决和程序优化) - 下载前判断当前目录可写 - - 文件扩展名处理,分为用户方式和扩展名权限方式 + - 文件扩展名处理,分为用户方式和扩展名权限方式 - 上传结束提示:是否成功、失败原因 - 上传扩展名限制 解决apache .php.*当做php执行bug - 文件名非法字符限定 - 树目录展开箭头状态修复 - - 树目录新建文件,没有子节点刷新bug解决 + - 树目录新建文件,没有子节点刷新bug解决 - 文件大小为0上传不了问题 - windows下进入某些系统文件夹死循环bug解决 - tips 居中显示 - 任务栏标签选中问题:已经显示且为交点窗口 点击——隐藏;否则——显示,并且置为焦点窗口 - 拖入url ——oexe 新窗口打开 - - 选中文件时,移动到屏幕可视区域(解决上下左右选中文件滚动条不一致问题) + - 选中文件时,移动到屏幕可视区域(解决上下左右选中文件滚动条不一致问题) ### ver2.51 `2014/6/22` @@ -1074,11 +1112,11 @@ ### ver2.2 `2014/5/11` ----- #### update: - - 公共目录支持(多个用户可以共享目录,写权限跟随用户组权限设定) + - 公共目录支持(多个用户可以共享目录,写权限跟随用户组权限设定) - 自动升级优化 - 文件管理工具栏 增加菜单选项,方便移动设备操作 - 文件编辑器,文件树目录 上下左右键盘切换 快捷键加入 - - 树目录去掉库,改为个人目录等多处文案修改 + - 树目录去掉库,改为个人目录等多处文案修改 - 默认打开用户目录 #### fix bug:(bug解决和程序优化) @@ -1090,14 +1128,14 @@ ### ver2.1 `2014/4/2` ----- #### update: - - 文件夹拖拽上传,完美解决(保持原始目录结构) - - 解压缩优化;解压中文问题。解压缩整体速度 + - 文件夹拖拽上传,完美解决(保持原始目录结构) + - 解压缩优化;解压中文问题。解压缩整体速度 - 树目录增加快捷键支持(上下、左右展开树目录;复制、粘贴、剪切、删除、打开、搜索、新建文件(夹)、) - pdf预览支持 - mac快捷键 ctrl 一一对应command - 音乐播放器和视频播放器相互独立 - - 图片懒加载、图片较多的情况下只加载首屏图片缩略图; - - 编辑文件打开出错,自动关闭标签;文件打开20M限制(大于20M则不处理,浏览器会卡死) + - 图片懒加载、图片较多的情况下只加载首屏图片缩略图; + - 编辑文件打开出错,自动关闭标签;文件打开20M限制(大于20M则不处理,浏览器会卡死) - 标签关闭提示:检测是否有未保存文件,文件修改实时修改是否修修改的按钮状态 #### fix bug:(bug解决和程序优化) @@ -1105,7 +1143,7 @@ - 右键菜单在最下面时,右键位置重叠导致点击菜单问题 - 编辑器打开文件时光标问题,处理:移动到行尾;编辑器enter建不显示自动提示 - iframe 打开url 优化。解决canvas问题 - - 文件编辑器,载入loading去掉 + - 文件编辑器,载入loading去掉 - 删除错误时,或上传错误时也刷新目录。删除提示颜色错误 - 对话框右键 点击右键菜单隐藏修复 - 手机端 touch =双击 @@ -1123,13 +1161,13 @@ #### fix bug:(bug解决和程序优化) - body右键屏蔽(保留input、textarea) - 重命名&新建时 右键(编辑内容系统菜单) - - 对话框 不显示边框(位移处理,opacity:0) + - 对话框 不显示边框(位移处理,opacity:0) - esc 退出程序 屏蔽该功能。 - - 关闭播放器,还在播放bug + - 关闭播放器,还在播放bug - 增加资源管理器任务栏。任务栏加入右键功能。 - 对话框增加右键功能 - guest [三类用户 root/default/guest] guest登录处加链接。20min - - 打包程序[update user_add,admin/demo; 删除webuploader.js thumb less] + - 打包程序[update user_add,admin/demo; 删除webuploader.js thumb less] - 编辑添加应用权限只能是root用户才可以。 - 保存文件不可写提示! - 解压缩结果提示。(对话框) @@ -1137,41 +1175,41 @@ #### upload - dialog display - root登录 目录修改为服务器路径 - - artdialog 已经打开的窗口 (设了id) 最小化时,再次打开则显示 - - 最小化窗口后,再次打开 dialog display (setting-display) + - artdialog 已经打开的窗口 (设了id) 最小化时,再次打开则显示 + - 最小化窗口后,再次打开 dialog display (setting-display) - 上传进度加入大小 - - 上传窗口关闭,自动停止所有上传队列 - - 拖拽后,更新上传地址为当前地址。(之前上传队列也会这样。bug) - - root用户非服务器路径下文件预览(图片、mp3、视频、html、swf、……php代理输出文件内容,http方式) - - 对话框最小化或关闭,重置最大index为焦点窗口 + - 上传窗口关闭,自动停止所有上传队列 + - 拖拽后,更新上传地址为当前地址。(之前上传队列也会这样。bug) + - root用户非服务器路径下文件预览(图片、mp3、视频、html、swf、……php代理输出文件内容,http方式) + - 对话框最小化或关闭,重置最大index为焦点窗口 - 图片缩略图生成:小于5k则不生成(直接输出) - - 加载文件列表改为异步方式,数据返回采用回调函数方式。增强体验 - - 选中优化,文件&文件夹重命名、文件&文件夹新建 后自动选中。(f5增加回调。); - - 选中保持,选中后如果调整排序等等,保持选中状态。 + - 加载文件列表改为异步方式,数据返回采用回调函数方式。增强体验 + - 选中优化,文件&文件夹重命名、文件&文件夹新建 后自动选中。(f5增加回调。); + - 选中保持,选中后如果调整排序等等,保持选中状态。 - 上传文件选中当前。 - f5改为异步(加入mask loading) 优化文件夹打开体验 - - 键盘按键选中文件 增加字符搜索定位功能(单个字符,增加到多个字符选中。两次响应直接延迟250ms) + - 键盘按键选中文件 增加字符搜索定位功能(单个字符,增加到多个字符选中。两次响应直接延迟250ms) - 幻灯片播放[优化成fancybox或者 重写动画部分、打开时关不掉问题] - 编辑器backspace、delete时不提示。 - - 编辑器,增加选中效果 - - 增加不自动提示功能,配置项作为全局配置。影响后续建立的文件。选中标记状态。 + - 编辑器,增加选中效果 + - 增加不自动提示功能,配置项作为全局配置。影响后续建立的文件。选中标记状态。 - 更换桌面背景图片【load后替换】 - 更换主题【css load 后载入】 - 删除。不清除选中。提前准备数据 - - 构建打包,合并压缩。添加版本、版权 - - 自动升级(本地记录版本,服务器js调用 参数 url、### version;忽略此版本。cookie。统计用户) + - 构建打包,合并压缩。添加版本、版权 + - 自动升级(本地记录版本,服务器js调用 参数 url、### version;忽略此版本。cookie。统计用户) ### ver2.0 debug `2014/3/2` ----- #### fix bug:(bug解决和程序优化) - 优化文件打开处理 - - 文件&文件夹:含有%、+号的处理(显示不出等问题,encoenURIComponent——rawurldecode) - - 文件下载,支持大文件下载、断点续传。 + - 文件&文件夹:含有%、+号的处理(显示不出等问题,encoenURIComponent——rawurldecode) + - 文件下载,支持大文件下载、断点续传。 - 解决更改排序方式后 ——对应右键菜单不同步问题。 - - 优化右键更改列表状态,同步保存配置到服务端。 - - 文件浏览器打开(a点击新窗口跳转,a不支持click,用子元素冒泡来实现点击) - - 优化配置文件存储方案。直接由前端操作后端key,value + - 优化右键更改列表状态,同步保存配置到服务端。 + - 文件浏览器打开(a点击新窗口跳转,a不支持click,用子元素冒泡来实现点击) + - 优化配置文件存储方案。直接由前端操作后端key,value - 修复添加收藏夹问题(已打开设置窗口再添加失败问题) - 修复树目录中文文件名bug - 优化pic图片幻灯片播放 @@ -1180,29 +1218,29 @@ - 优化地址栏过长编辑状态问题 - 优化新建、重命名文件(夹) 高度自适应问题 - firefox ctrl+s 系统对话框屏蔽 - - 树目录:收藏夹优化(右键绑定);右键操作优化,拖拽优化(文件管理&编辑器) + - 树目录:收藏夹优化(右键绑定);右键操作优化,拖拽优化(文件管理&编辑器) - 收藏夹优化(右键 >编辑删除) #### update: **新增功能** - 多用户、权限控制: - - 可以建立权限组,将功能分配给权限组 - - 添加用户,选择所属的权限组。 - - 权限按功能划分成颗粒,可以任意配置,例如普通使用者、游客等 - - 搜索:支持递归搜索,可选择是否搜索文件内容。 + - 可以建立权限组,将功能分配给权限组 + - 添加用户,选择所属的权限组。 + - 权限按功能划分成颗粒,可以任意配置,例如普通使用者、游客等 + - 搜索:支持递归搜索,可选择是否搜索文件内容。 - 增加桌面自定义壁纸。 - 皮肤优化 ok 多色彩支持。 - - 应用商店,root用户可以管理应用。安装、修改、删除。普通用户可以安装应用。 + - 应用商店,root用户可以管理应用。安装、修改、删除。普通用户可以安装应用。 - 应用添加了图标。对应右键功能。 - office文档在线预览。 **上传下载** - - 采用全新上传控件,跟安全,更好的体验。 - - 拖拽支持文件夹,多个文件。上传自动过滤不允许的文件类型 - - 拖拽上传 和上统一优化,修复webuploader的文件判断;火狐拖拽上传,ie9+拖拽上传。 - - 上传时自动过滤不合格的文件,上传失败错误返回。 + - 采用全新上传控件,跟安全,更好的体验。 + - 拖拽支持文件夹,多个文件。上传自动过滤不允许的文件类型 + - 拖拽上传 和上统一优化,修复webuploader的文件判断;火狐拖拽上传,ie9+拖拽上传。 + - 上传时自动过滤不合格的文件,上传失败错误返回。 **文件编辑** @@ -1211,10 +1249,10 @@ - 支持代码自动补全(基于文档、或自定义的代码快照) - 快速预览功能 - 优化文件保存完美解决。编码自动识别转换。(字符串转义问题。1&#'[{'"+~%25\\\\ ////) - - 文件编辑,添加收藏夹 - - 优化音乐播放器,添加音乐后自动播放新添加的第一首;解决之前添加列表后暂停问题。 - - 优化任务栏,多标签;最小化flash问题(left+10000 visiable) - - ctrl,shift 多选时拖拽优化(按住这两个键时,不能拖动;拖动加入延迟200ms) + - 文件编辑,添加收藏夹 + - 优化音乐播放器,添加音乐后自动播放新添加的第一首;解决之前添加列表后暂停问题。 + - 优化任务栏,多标签;最小化flash问题(left+10000 visiable) + - ctrl,shift 多选时拖拽优化(按住这两个键时,不能拖动;拖动加入延迟200ms) - 编辑器在没打开文件的情况下工具栏不可用问题。 - 搜索、替换;vim模式 - …… @@ -1222,15 +1260,15 @@ **登录退出** - 登录优化 ok【页面&验证码&记住密码】 - - 三次错误需要输入验证码,保证系统的安全性 - - 优化自动登录安全性,客户端保存cookie自动登录信息。【tooken加入本地ip】 + - 三次错误需要输入验证码,保证系统的安全性 + - 优化自动登录安全性,客户端保存cookie自动登录信息。【tooken加入本地ip】 **系统优化** - - 解决较慢操作,阻塞其他操作问题。(同一个用户session会加锁,入口处做释放) - - 前后端代码基本全部重构,前端采用模块化方法sea.js|require.js 模块化。 - - 凡是有模板调用的(display——页面部分php解析。并将配置注入到页面js变量,便于js使用) - - 加入模板机制;通用模块采用懒加载模式;使用artTemplate 对模板绑定数据。 + - 解决较慢操作,阻塞其他操作问题。(同一个用户session会加锁,入口处做释放) + - 前后端代码基本全部重构,前端采用模块化方法sea.js|require.js 模块化。 + - 凡是有模板调用的(display——页面部分php解析。并将配置注入到页面js变量,便于js使用) + - 加入模板机制;通用模块采用懒加载模式;使用artTemplate 对模板绑定数据。 - kv结构存储 - 路由权限控制 - 后端统一json输出。 @@ -1239,86 +1277,86 @@ ----- #### fix bug: - 修复文件下载bug - - 修复编辑器自动补全问题, ——> + - 修复编辑器自动补全问题, ——> - 兼容部分服务器问题。 ### 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 @@ -