Skip to content

Commit

Permalink
version 4.38 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kalcaddle committed Feb 25, 2019
1 parent ae89910 commit 4bdfcd6
Show file tree
Hide file tree
Showing 46 changed files with 196 additions and 221 deletions.
11 changes: 10 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### ver4.38 `2019/2/25`
-----
#### update:
- 针对移动端APP进行兼容适配优化
- 部门列表过多时,排序效率优化。
- https请求优化兼容
- cad分享无法预览问题解决
- 新增hook点
- 其他细节优化

### ver4.37 `2018/11/28`
-----
#### update:
Expand Down Expand Up @@ -28,7 +38,6 @@
- 插件配置:文件选择组件支持配置参数;同文件选择组件参数;插件表单组件formMake增强
- 断点续传分片重传加入延时;断网等类似情况下15s内自动上传
- 通用前端worker调用支持
- 分享的的失效时间可以设置当前时间前
- 分享的的失效时间是否可以设置到分钟
- 分享后设置禁止下载,禁用打开方式等相关操作
- https的curl请求加入ssl版本声明;兼容性调整
Expand Down
7 changes: 6 additions & 1 deletion app/controller/explorer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ public function fileDownload(){
file_put_out($this->path,true);
}
//文件下载后删除,用于文件夹下载
public function fileDownloadRemove(){
public function fileDownloadRemove(){
$path = get_path_this(_DIR_CLEAR($this->in['path']));
$path = iconv_system(USER_TEMP.$path);
$fileName = substr(get_path_this($path),10);//前10个字符为随机前缀
Expand Down Expand Up @@ -1167,6 +1167,11 @@ public function fileThumb(){
//通用预览
public function fileView(){
Hook::trigger("explorer.fileViewStart",$this->path);
if(!isset($this->in['path'])){
show_tips('参数错误!');
}
$this->tpl = TEMPLATE.'api/';
$this->display('view.html');
}
//通用保存
public function fileSave(){
Expand Down
5 changes: 3 additions & 2 deletions app/controller/pluginApp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function to() {
if(!$_SESSION['kodLogin']){
show_tips("出错了!您尚未登录",APP_HOST,3);
}
show_tips("出错了!插件未开启,或您没有{$app}插件的权限");
show_tips("出错了!插件未开启,或您没有{$app}插件的权限!");
}

$appConfig = $model->getConfig($app);
Expand Down Expand Up @@ -63,7 +63,7 @@ private function checkAccessShare(){
return false;
}
$share = KOD_USER_SHARE;
if(substr($this->in['path'],0,strlen($share)) == $share){
if(substr(urldecode($this->in['path']),0,strlen($share)) == $share){
return true;
}
return false;
Expand Down Expand Up @@ -197,6 +197,7 @@ private function pluginInfo($app){
"versionHash" => $this->config['settingSystem']['versionHash'],
"systemOS" => $this->config['systemOS'],
"phpVersion" => PHP_VERSION,
"channel" => INSTALL_CHANNEL,
"lang" => I18n::getType()
);
$info = url_request($api,'POST',$param);
Expand Down
4 changes: 4 additions & 0 deletions app/controller/share.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ public function commonJs(){
'ACT' => $this->in['act'],
);

if(ST.''.ACT == 'explorer.fileView'){
unset($theConfig['sharePage']);
}

$userConfig = $GLOBALS['config']['settingDefault'];
if(isset($this->in['user'])){
$member = systemMember::loadData();
Expand Down
20 changes: 18 additions & 2 deletions app/controller/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function _loginSuccess($user){
$GLOBALS['isRoot'] = 0;
}

define('DESKTOP_FOLDER',$this->config['settingSystemDefault']['desktopFolder']);
define('DESKTOP_FOLDER',$this->config['settingSystem']['desktopFolder']);
$this->config['user'] = FileCache::load(USER.'data/config.php');

if(!is_array($this->config['user'])){
Expand Down Expand Up @@ -309,6 +309,22 @@ public function commonJs(){
}
echo 'LNG='.$lang.';G.useTime='.$useTime.';';
}
public function appConfig(){
$theConfig = array(
'lang' => I18n::getType(),
'isRoot' => $GLOBALS['isRoot'],
'userID' => $this->user['userID'],
'myhome' => MYHOME,
'settings' => array(
'updloadChunkSize' => file_upload_size(),
'updloadThreads' => $this->config['settings']['updloadThreads'],
'uploadCheckChunk' => $this->config['settings']['uploadCheckChunk'],
),
'version' => KOD_VERSION,
// 'userConfig' => $this->config['user'],
);
show_json($theConfig);
}

/**
* 登录view
Expand Down Expand Up @@ -425,7 +441,7 @@ public function loginSubmit(){

//首次登陆,初始化app 没有最后登录时间
$this->_loginSuccess($user);//登陆成功
if($user['lastLogin'] == ''){
if(!$user['lastLogin']){
$app = init_controller('app');
$app->initApp($user);
}
Expand Down
2 changes: 1 addition & 1 deletion app/controller/utils.php

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions app/function/common.function.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ function str_trim($str,$remove){
return str_rtrim(str_ltrim($str,$remove),$remove);
}
function str_ltrim($str,$remove){
if(!$str || !$remove) return false;
if(!$str || !$remove) return $str;
while(substr($str,0,strlen($remove)) == $remove){
$str = substr($str,strlen($remove));
}
return $str;
}
function str_rtrim($str,$remove){
if(!$str || !$remove) return false;
if(!$str || !$remove) return $str;
while(substr($str,-strlen($remove)) == $remove){
$str = substr($str,0,-strlen($remove));
echo $str;
}
return $str;
}
Expand Down
90 changes: 5 additions & 85 deletions app/function/file.function.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,83 +657,14 @@ function dir_list($path){
return array_merge($dirs,$files);
}

/**
* 借用临时文件方式对读写文件进行锁定标记
*
* fopen mode: http://www.w3school.com.cn/php/func_filesystem_fopen.asp
* flock mode: http://www.w3school.com.cn/php/func_filesystem_flock.asp
*/
function file_lock($file,$open=true,$type='read',$timeout=5){
clearstatcache();
$lockFile = $file.'.'.$type.'.lock';
$lockRead = $file.'.read.lock';
$lockWrite = $file.'.write.lock';
if(!$open){
@unlink($lockFile);
clearstatcache();
return;
}

$startTime = microtime(true);
do{
clearstatcache();
$canLock = true;
if( $type=='read' ){
if( file_exists($lockWrite) ){
$canLock = false;
}
}else if( $type=='write' ){
if( file_exists($lockWrite) || file_exists($lockRead) ){
$canLock = false;
}
}
if(!$canLock){
usleep(mt_rand(10, 50) * 1000);//10~50ms;
}
} while((!$canLock) && ((microtime(true) - $startTime) < $timeout ));
$result = false;
if($canLock){
$result = file_put_contents($lockFile,time(),LOCK_EX);
clearstatcache();
$result = $result && file_exists($lockFile);
//if(!$result){write_log($_GET['action'].';file not exists','test2');}
}
return $result;
}

// 安全读取文件,避免并发下读取数据为空
function file_read_safe1($file,$timeout = 5){
if(file_lock($file,true,'read',$timeout)){
$fp = @fopen($file, 'r');
if(!$fp || !flock($fp, LOCK_EX)) return false;
$result = fread($fp, filesize($file));
flock($fp,LOCK_UN);fclose($fp);

file_lock($file,false,'read');
return $result;
}
return false;
}
// 安全读取文件,避免并发下读取数据为空
function file_wirte_safe1($file,$buffer,$timeout=5){
if(file_lock($file,true,'write',$timeout)){
$result = @file_put_contents($file,$buffer,LOCK_EX);
file_lock($file,false,'write');
return $result;
}
return false;
}


// 安全读取文件,避免并发下读取数据为空
function file_read_safe($file,$timeout = 5){
//return file_read_safe1($file,$timeout);
function file_read_safe($file,$timeout = 3){
if(!$file || !file_exists($file)) return false;
$fp = @fopen($file, 'r');
if(!$fp) return false;
$startTime = microtime(true);
do{
$locked = flock($fp, LOCK_EX|LOCK_NB);//LOCK_EX|LOCK_NB
$locked = flock($fp, LOCK_SH);//LOCK_EX|LOCK_NB
if(!$locked){
usleep(mt_rand(1, 50) * 1000);//1~50ms;
}
Expand All @@ -753,8 +684,7 @@ function file_read_safe($file,$timeout = 5){
}

// 安全读取文件,避免并发下读取数据为空
function file_wirte_safe($file,$buffer,$timeout=5){
//return file_wirte_safe1($file,$buffer,$timeout);
function file_wirte_safe($file,$buffer,$timeout=3){
clearstatcache();
if(strlen($file) == 0 || !$file || !file_exists($file)) return false;
$fp = fopen($file,'r+');
Expand Down Expand Up @@ -1069,21 +999,11 @@ function file_put_out($file,$download=-1,$downFilename=false){
}

$mime = get_file_mime(get_path_ext($filename));
$filenameOutput = rawurlencode(iconv_app($filename));
if ($download === -1 && !mime_support($mime)){
$download = true;
}
$headerName = $filenameOutput;
if(ua_has("Chrome") && !ua_has('Edge')){ //chrome下载
$filenameOutput = '"'.$filenameOutput.'"';
}
if(!is_wap()){
$headerName.=";filename*=utf-8''".$filenameOutput;
}
if( ua_has("Safari") && !ua_has('Edge')){//safari 中文下载问题
$headerName = rawurldecode($filenameOutput);
}
//var_dump($headerName,$filenameOutput,$_SERVER['HTTP_USER_AGENT']);exit;
$headerName = rawurlencode(iconv_app($filename));
$headerName = '"'.$headerName."\"; filename*=utf-8''".$headerName;
if ($download) {
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
Expand Down
2 changes: 1 addition & 1 deletion app/function/helper.function.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function serverInfo(){
"php" => floatval(PHP_VERSION),
"server"=> $_SERVER['SERVER_SOFTWARE'],
"lib" => $libStr,
"info" => php_uname().';phpv='.PHP_VERSION,
"info" => php_uname().';php='.PHP_VERSION,
);
$result = str_replace("\/","@",json_encode($env));
return $result;
Expand Down
2 changes: 1 addition & 1 deletion app/function/web.function.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ function url_request($url,$method='GET',$data=false,$headers=false,$options=fals
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSLVERSION,1);//1|5|6; http://t.cn/RZy5nXF
// curl_setopt($ch, CURLOPT_SSLVERSION,1);//1|5|6; http://t.cn/RZy5nXF
curl_setopt($ch, CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_REFERER,get_url_link($url));
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36');
Expand Down
25 changes: 18 additions & 7 deletions app/kod/Downloader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ static function start($url,$saveFile,$timeout = 10) {
if(!$url){
return array('code'=>false,'data'=>'url error!');
}

//默认下载方式if not support range
if(!$fileHeader['supportRange'] ||
$fileHeader['length'] == 0 ){
@unlink($saveTemp);
@unlink($saveFile);
@unlink($saveTemp);@unlink($saveFile);
$result = self::fileDownloadFopen($url,$saveFile,$fileHeader['length']);
if($result['code']) {
return $result;
}else{
@unlink($saveTemp);
@unlink($saveFile);
return self::fileDownloadCurl($url,$saveFile,false,0,$fileHeader['length']);
@unlink($saveTemp);@unlink($saveFile);
$result = self::fileDownloadCurl($url,$saveFile,false,0,$fileHeader['length']);
@unlink($saveTemp);@unlink($saveFile);
return $result;
}
}

Expand Down Expand Up @@ -106,7 +105,7 @@ static function fileDownloadFopen($url, $fileName,$headerSize=0){
if($headerSize != 0 && $filesize != $headerSize){
return array('code'=>false,'data'=>'file size error');
}

self::checkGzip($fileTemp);
if(!@rename($fileTemp,$fileName)){
usleep(round(rand(0,1000)*50));//0.01~10ms
@unlink($fileName);
Expand Down Expand Up @@ -152,6 +151,7 @@ static function fileDownloadCurl($url, $fileName,$supportRange=false,$existsLeng
}

if($res && filesize($fileTemp) != 0){
self::checkGzip($fileTemp);
if(!@rename($fileTemp,$fileName)){
@unlink($fileName);
$res = @rename($fileTemp,$fileName);
Expand All @@ -166,4 +166,15 @@ static function fileDownloadCurl($url, $fileName,$supportRange=false,$existsLeng
return array('code'=>false,'data'=>'file create error');
}
}

static function checkGzip($file){
$char = "\x1f\x8b";
$str = file_sub_str($file,0,2);
if($char != $str) return;

ob_start();
readgzfile($file);
$out = ob_get_clean();
file_put_contents($file,$out);
}
}
1 change: 1 addition & 0 deletions app/kod/I18n.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static function defaultLang(){
$lang = "en";
$arr = $GLOBALS['config']['settingAll']['language'];
$langs = array();
if(!$arr) return 'zh-CN';
foreach ($arr as $key => $value) {
$langs[$key] = $key;
}
Expand Down
3 changes: 2 additions & 1 deletion app/kod/archiveLib/kodRarArchive.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ static function listContent7z($file,$bin=false) {

// 不允许双引号
function escapeShell($param){
return escapeshellarg($param);
//$param = escapeshellarg($param);
$os = strtoupper(substr(PHP_OS, 0,3));
if ( $os != 'WIN' && $os != 'DAR') {//linux
$param = str_replace('!','\!',$param);
}
$param = rtrim($param,"\\");
return '"'.str_replace(array('"',"\0"),'_',$param).'"';
return '"'.str_replace(array('"',"\0",'`'),'_',$param).'"';
}
3 changes: 3 additions & 0 deletions app/model/PluginModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public function viewList(){
$list = $this->loadData();
$result = array();
foreach ($list as $key => $item) {
if(!plugin_check_allow($key)){
continue;
}
unset($item['regiest']);
$package = Hook::apply($item['id'].'Plugin.appPackage');
if(is_array($package)){
Expand Down
3 changes: 2 additions & 1 deletion app/template/api/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
<script type="text/javascript">
G.shareInfo = {
path:"<?php echo $_GET['path'];?>",
name:"<?php echo $name;?>",
name:"<?php echo get_path_this($_GET['path']);?>",
mtime:0,
size:0
}
<?php if(ST.'.'.ACT == 'explorer.fileView'){echo "G.shareInfo.view = true;";}?>
G['accessToken'] = "<?php echo access_token_get();?>";
seajs.config({
base: "<?php echo STATIC_PATH;?>js/",
Expand Down
2 changes: 1 addition & 1 deletion app/template/common/footerCommon.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script type="text/javascript" src="<?php echo STATIC_PATH;?>js/lib/seajs/sea.js?ver=<?php echo KOD_VERSION;?>"></script>
<?php
//commonjs
Hook::trigger('templateCommonFooter');
if(ST == 'share' || isset($GLOBALS['loadCommonJs'])){
if(isset($_GET['user'])){
$userInfo = '&user='.clear_html($_GET['user']).'&sid='.clear_html($_GET['sid']);
Expand Down Expand Up @@ -45,3 +44,4 @@
]
});
</script>
<?php Hook::trigger('templateCommonFooter');?>
1 change: 1 addition & 0 deletions app/template/common/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php Hook::trigger('templateCommonHeaderStart'); ?>
<!DOCTYPE html>
<html>
<head>
Expand Down
Loading

0 comments on commit 4bdfcd6

Please sign in to comment.