diff --git a/README.md b/README.md
index aa5bc78d2..bb4c51286 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,7 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
* 安装时默认监控开启。
* MySQL/MYSQL-YUM/MySQL-APT添加重置master功能。
* 支持华为欧拉系统。
+* 支持rar解压。
### JSDelivr安装地址
diff --git a/class/core/files_api.py b/class/core/files_api.py
index 332fb9574..f7e7598cb 100755
--- a/class/core/files_api.py
+++ b/class/core/files_api.py
@@ -87,6 +87,12 @@ class files_api:
path = request.form.get('path', '')
return self.unzip(sfile, dfile, stype, path)
+ def uncompressApi(self):
+ sfile = request.form.get('sfile', '')
+ dfile = request.form.get('dfile', '')
+ path = request.form.get('path', '')
+ return self.uncompress(sfile, dfile, path)
+
# 移动文件或目录
def mvFileApi(self):
sfile = request.form.get('sfile', '')
@@ -830,10 +836,54 @@ class files_api:
except:
return mw.returnJson(False, '文件压缩失败!')
- def unzip(self, sfile, dfile, stype, path):
+ def uncompress(self, sfile, dfile, path):
+ if not os.path.exists(sfile):
+ return mw.returnJson(False, '指定文件不存在!')
+
+ filename = os.path.basename(sfile)
+ extension = os.path.splitext(filename)[-1]
+ extension = extension.strip('.')
+
+ tar_gz = 'tar.gz'
+ tar_gz_len = len(tar_gz)
+ suffix_gz = sfile[-tar_gz_len:]
+ if suffix_gz == tar_gz:
+ extension = suffix_gz
+
+ if not extension in ['tar.gz', 'gz', 'zip', 'rar']:
+ return mw.returnJson(False, '现在仅支持gz,zip,rar格式解压!')
+ if mw.isAppleSystem() and extension == 'rar':
+ return mw.returnJson(False, 'macosx暂时不支持rar格式解压')
+
+ try:
+ tmps = mw.getRunDir() + '/tmp/panelExec.log'
+ if extension == 'zip':
+ cmd = "cd " + path + " && unzip -o -d '" + dfile + \
+ "' '" + sfile + "' > " + tmps + " 2>&1 &"
+ mw.execShell(cmd)
+ if extension == 'tar.gz':
+ cmd = "cd " + path + " && tar -zxvf " + sfile + \
+ " -C " + dfile + " > " + tmps + " 2>&1 &"
+ mw.execShell(cmd)
+ if extension == 'gz':
+ cmd = "cd " + path + " && gunzip -k " + sfile + " > " + tmps + " 2>&1 &"
+ mw.execShell(cmd)
+ if extension == 'rar':
+ cmd = "cd " + path + " && unrar x " + sfile + \
+ " " + dfile + " > " + tmps + " 2>&1 &"
+ mw.execShell(cmd)
+
+ if os.path.exists(dfile):
+ self.setFileAccept(dfile)
+ mw.writeLog("文件管理", '文件解压成功!', (sfile, dfile))
+ return mw.returnJson(True, '文件解压成功!')
+ except Exception as e:
+ return mw.returnJson(False, '文件解压失败!:' + str(e))
+
+ def unzip(self, sfile, dfile, stype, path):
if not os.path.exists(sfile):
- return mw.returnMsg(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
try:
tmps = mw.getRunDir() + '/tmp/panelExec.log'
diff --git a/route/static/app/files.js b/route/static/app/files.js
index 9bee48b4b..415502ac8 100755
--- a/route/static/app/files.js
+++ b/route/static/app/files.js
@@ -351,7 +351,6 @@ function getFiles(Path) {
}
var body = '';
var data = 'path=' + Path;
- var loadT = layer.load();
var totalSize = 0;
var search_all = '';
@@ -359,7 +358,8 @@ function getFiles(Path) {
if(all){
search_all = "&all=yes";
}
-
+
+ var loadT = layer.load();
$.post('/files/get_dir?p=' + p + '&showRow=' + showRow + search + search_all, data, function(rdata) {
layer.close(loadT);
@@ -400,13 +400,14 @@ function getFiles(Path) {
"+fmp[3]+" | \
"+fmp[4]+" | \
";
+ 复制 | \
+ 剪切 | \
+ 重命名 | \
+ 权限 | \
+ 压缩 | \
+ 删除\
+ \
+ ";
} else {
$("#set_icon").addClass("active");
$("#set_list").removeClass("active");
@@ -414,28 +415,33 @@ function getFiles(Path) {
+ toSize(fmp[1])+"
"+lan.files.file_etime+":"+getLocalTime(fmp[2])+"
"+lan.files.file_auth+":"+fmp[3]+"
"+lan.files.file_own+":"+fmp[4]+"'>\
\
\
- " + fmp[0] + "
\
- ";
+ \
+ " + fmp[0] + "\
+
\
+ ";
}
}
for (var i = 0; i < rdata.FILES.length; i++) {
if(rdata.FILES[i] == null) continue;
var fmp = rdata.FILES[i].split(";");
- var displayZip = isZip(fmp[0]);
var bodyZip = '';
var download = '';
var cnametext =fmp[0] + fmp[5];
fmp[0] = fmp[0].replace(/'/,"\\'");
- if(cnametext.length>48){
- cnametext = cnametext.substring(0,48) + '...';
- }
+
if(isChineseChar(cnametext)){
if(cnametext.length>16){
cnametext = cnametext.substring(0,16) + '...';
}
+ } else{
+ if( cnametext.length > 48 ){
+ cnametext = cnametext.substring(0,48) + '...';
+ }
}
- if(displayZip != -1){
- bodyZip = "解压 | ";
+
+ var displayCompress = 1;
+ if(isCompressFile(fmp[0])){
+ bodyZip = "解压 | ";
}
if(isText(fmp[0])){
@@ -462,17 +468,21 @@ function getFiles(Path) {
剪切 | \
重命名 | \
权限 | \
- 压缩 | "+bodyZip+download+"\
- 删除\
+ 压缩 | "
+ + bodyZip
+ + download
+ + "删除\
\
";
}
else{
body += "";
}
}
@@ -481,19 +491,19 @@ function getFiles(Path) {
$("#dir_info").html(dirInfo);
if( getCookie('rank') == 'a' ){
var tablehtml = '';
+ \
+ \
+ | \
+ 文件名 | \
+ 大小 | \
+ 修改时间 | \
+ 权限 | \
+ 所有者 | \
+ 操作 | \
+
\
+ \
+ '+body+'\
+ ';
$("#fileCon").removeClass("fileList").html(tablehtml);
$("#tipTools").width($("#fileCon").width());
} else {
@@ -502,14 +512,14 @@ function getFiles(Path) {
}
$("#DirPathPlace input").val(rdata.PATH);
var BarTools = '\
- \
- \
-
';
+ \
+ \
+ ';
if (rdata.PATH != '/') {
BarTools += ' ';
}
@@ -1288,21 +1298,24 @@ function unZip(fileName, type) {
if(type.length ==3){
var sfile = encodeURIComponent($("#sfile").val());
var dfile = encodeURIComponent($("#dfile").val());
- coding = $("select[name='coding']").val();
- layer.closeAll();
- layer.msg(lan.files.unzip_the, {icon: 16,time: 0,shade: [0.3, '#000']});
+ var coding = $("select[name='coding']").val();
+ var tip = layer.msg(lan.files.unzip_the, {icon: 16,time: 0,shade: [0.3, '#000']});
$.post('/files/unzip', 'sfile=' + sfile + '&dfile=' + dfile +'&type=' + type + '&path='+encodeURIComponent(path), function(rdata) {
- layer.closeAll();
- layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2});
- getFiles(path);
+ layer.close(tip);
+ showMsg(rdata.msg, function(){
+ getFiles(path);
+ },{icon: rdata.status ? 1 : 2},2000);
},'json');
- return
+ return;
}
type = (type == 1) ? 'tar':'zip';
var umpass = '';
if(type == 'zip'){
- umpass = ''+lan.files.zip_pass_title+'
'
+ umpass = '\
+ '+lan.files.zip_pass_title+'\
+ \
+
';
}
layer.open({
type: 1,
@@ -1327,6 +1340,70 @@ function unZip(fileName, type) {
});
}
+function isCompressFile(fileName){
+ var ext = fileName.split('.');
+ var extName = ext[ext.length-1].toLowerCase();
+ var support = ['zip','gz','tgz','rar'];
+ for (x in support) {
+ if (support[x]==extName){
+ return true;
+ }
+ }
+ return false;
+}
+
+function unCompressFile(fileName, type = 0){
+ // 解压文件
+ var path = $("#DirPathPlace input").val();
+ if(type == 3){
+ var sfile = encodeURIComponent($("#sfile").val());
+ var dfile = encodeURIComponent($("#dfile").val());
+ var coding = $("select[name='coding']").val();
+ var tip = layer.msg('正在解压,请稍候...', {icon: 16,time: 0,shade: [0.3, '#000']});
+ $.post('/files/uncompress', 'sfile=' + sfile + '&dfile=' + dfile +'&type=' + type + '&path='+encodeURIComponent(path), function(rdata) {
+ layer.close(tip);
+ showMsg(rdata.msg, function(){
+ layer.closeAll();
+ getFiles(path);
+ },{icon: rdata.status ? 1 : 2},2000);
+ },'json');
+ return;
+ }
+
+ // var umpass = '\
+ // 解压密码\
+ // \
+ //
';
+ layer.open({
+ type: 1,
+ shift: 5,
+ closeBtn: 1,
+ area: '490px',
+ title: '解压文件',
+ content: ''
+ });
+}
+
//是否压缩文件
function isZip(fileName){
var ext = fileName.split('.');
diff --git a/route/static/app/public.js b/route/static/app/public.js
index 0abe3cb66..5e272d260 100755
--- a/route/static/app/public.js
+++ b/route/static/app/public.js
@@ -362,14 +362,17 @@ function getDiskList(b) {
for(var f = 0; f < h.DIR.length; f++) {
var g = h.DIR[f].split(";");
var e = g[0];
- if(e.length > 20) {
- e = e.substring(0, 20) + "..."
- }
+
if(isChineseChar(e)) {
if(e.length > 10) {
- e = e.substring(0, 10) + "..."
+ e = e.substring(0, 10) + "...";
+ }
+ } else{
+ if(e.length > 20) {
+ e = e.substring(0, 20) + "...";
}
}
+
d += "\
\
" + e + " | " + getLocalTime(g[2]) + " | \
@@ -382,14 +385,16 @@ function getDiskList(b) {
for(var f = 0; f < h.FILES.length; f++) {
var g = h.FILES[f].split(";");
var e = g[0];
- if(e.length > 20) {
- e = e.substring(0, 20) + "..."
- }
if(isChineseChar(e)) {
if(e.length > 10) {
e = e.substring(0, 10) + "..."
}
+ } else{
+ if(e.length > 20) {
+ e = e.substring(0, 20) + "..."
+ }
}
+
d += "
\
" + e + " | \
" + getLocalTime(g[2]) + " | \
@@ -403,7 +408,7 @@ function getDiskList(b) {
$(".file-list").show();
$("#tbody").html(d);
if(h.PATH.substr(h.PATH.length - 1, 1) != "/") {
- h.PATH += "/"
+ h.PATH += "/";
}
$("#PathPlace").find("span").html(h.PATH);
activeDisk();