From 00082f54c3ddd37f8a703c3d87e3593a9fcf186e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 26 Mar 2019 16:46:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=A4=8D=E5=88=B6|=E5=89=AA?= =?UTF-8?q?=E5=88=87|=E6=9D=83=E9=99=90|=E5=8E=8B=E7=BC=A9=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 3 +- class/core/files_api.py | 177 ++++++++++++++++++++++++++++++++++++++ class/core/public.py | 2 +- route/static/app/files.js | 133 +++++++++++++++------------- 4 files changed, 250 insertions(+), 65 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index cb4057867..0f60f38a3 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -17,8 +17,7 @@ class config_api: # 本版解决自启动问题 # 文件管理重命名 - __version = '0.7.2' - + __version = '0.7.3' def __init__(self): pass diff --git a/class/core/files_api.py b/class/core/files_api.py index 097d53e1a..62924142d 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -13,6 +13,7 @@ import shutil from flask import request from flask import send_file, send_from_directory from flask import make_response +from flask import session class files_api: @@ -376,8 +377,184 @@ done tmp = self.getDirSize(logPath) return public.returnJson(True, tmp[0].split()[0]) + def setBatchDataApi(self): + path = request.form.get('path', '').encode('utf-8') + stype = request.form.get('type', '').encode('utf-8') + access = request.form.get('access', '').encode('utf-8') + user = request.form.get('user', '').encode('utf-8') + data = request.form.get('data') + if stype == '1' or stype == '2': + session['selected'] = { + 'path':path, + 'type':stype, + 'access':access, + 'user':user, + 'data':data + } + return public.returnJson(True,'标记成功,请在目标目录点击粘贴所有按钮!') + elif stype == '3': + for key in json.loads(data): + try: + key = key.encode('utf-8') + filename = path+'/'+key + if not self.checkDir(filename): + return public.returnJson(False,'FILE_DANGER'); + os.system('chmod -R '+access+" '"+filename+"'") + os.system('chown -R '+user+':'+user+" '"+filename+"'") + except: + continue; + public.writeLog('文件管理','批量设置权限成功!') + return public.returnJson(True,'批量设置权限成功!') + else: + import shutil + isRecyle = os.path.exists('data/recycle_bin.pl') + data = json.loads(data) + l = len(data); + i = 0; + for key in data: + try: + filename = path + '/'+key.encode('utf-8') + topath = filename; + if not os.path.exists(filename): + continue + + i += 1; + public.writeSpeed(key,i,l); + if os.path.isdir(filename): + if not self.checkDir(filename): + return public.returnJson(False,'请不要花样作死!'); + if isRecyle: + self.mvRecycleBin(topath) + else: + shutil.rmtree(filename) + else: + if key == '.user.ini': + os.system('which chattr && chattr -i ' + filename); + if isRecyle: + self.mvRecycleBin(topath) + else: + os.remove(filename) + except: + continue; + public.writeSpeed(None,0,0); + public.writeLog('文件管理','批量删除成功!') + return public.returnJson(True,'批量删除成功!') + + def checkExistsFilesApi(self): + dfile = request.form.get('dfile', '').encode('utf-8') + filename = request.form.get('filename', '').encode('utf-8') + data = []; + filesx = []; + if filename == '': + filesx = json.loads(session['selected']['data']); + else: + filesx.append(filename); + + print filesx + + for fn in filesx: + if fn == '.': continue + filename = dfile + '/' + fn; + if os.path.exists(filename): + tmp = {} + stat = os.stat(filename) + tmp['filename'] = fn + tmp['size'] = os.path.getsize(filename); + tmp['mtime'] = str(int(stat.st_mtime)); + data.append(tmp) + return public.returnJson(True,'ok', data) + + def batchPasteApi(self): + path = request.form.get('path', '').encode('utf-8') + stype = request.form.get('type', '').encode('utf-8') + # filename = request.form.get('filename', '').encode('utf-8') + import shutil + if not self.checkDir(path): + return public.returnJson(False,'请不要花样作死!'); + i = 0; + myfiles = json.loads(session['selected']['data']) + l = len(myfiles); + if stype == '1': + for key in myfiles: + i += 1 + public.writeSpeed(key,i,l); + try: + + sfile = session['selected']['path'] + '/' + key.encode('utf-8') + dfile = path + '/' + key.encode('utf-8') + + if os.path.isdir(sfile): + shutil.copytree(sfile,dfile) + else: + shutil.copyfile(sfile,dfile) + stat = os.stat(sfile) + os.chown(dfile,stat.st_uid,stat.st_gid) + except: + continue; + msg = public.getInfo('从[{1}]批量复制到[{2}]成功',(session['selected']['path'],path,)) + public.writeLog('文件管理',msg) + else: + for key in myfiles: + try: + i += 1 + public.writeSpeed(key,i,l); + + sfile = session['selected']['path'] + '/' + key.encode('utf-8') + dfile = path + '/' + key.encode('utf-8') + + shutil.move(sfile,dfile) + except: + continue; + msg = public.getInfo('从[{1}]批量移动到[{2}]成功', (session['selected']['path'],path,)) + public.writeLog('文件管理',msg) + public.writeSpeed(None,0,0); + errorCount = len(myfiles) - i + del(session['selected']) + msg = public.getInfo('批量操作成功[{1}],失败[{2}]', (str(i),str(errorCount))) + return public.returnJson(True, msg); + + def copyFileApi(self): + sfile = request.form.get('sfile', '').encode('utf-8') + dfile = request.form.get('dfile', '').encode('utf-8') + + if not os.path.exists(sfile): + return public.returnJson(False,'指定文件不存在!') + + if os.path.isdir(sfile): + return self.copyDir(get) + + import shutil + try: + shutil.copyfile(sfile, dfile) + msg = public.getInfo('复制文件[{1}]到[{2}]成功!', (sfile,dfile,)) + public.writeLog('文件管理',msg) + stat = os.stat(sfile) + os.chown(dfile, stat.st_uid, stat.st_gid) + return public.returnJson(True,'文件复制成功!') + except: + return public.returnJson(False,'文件复制失败!') + + ##### ----- end ----- ### + def copyDir(self, sfile, dfile): + + if not os.path.exists(sfile): + return public.returnJson(False,'指定目录不存在!'); + + if os.path.exists(dfile): + return public.returnJson(False,'指定目录已存在!'); + import shutil + try: + shutil.copytree(sfile, dfile) + stat = os.stat(sfile) + os.chown(dfile,stat.st_uid,stat.st_gid) + msg = public.getInfo('复制目录[{1}]到[{2}]成功!', (sfile,dfile)) + public.writeLog('文件管理',msg) + return public.returnJson(True,'目录复制成功!') + except: + return public.returnJson(False,'目录复制失败!') + # 检查敏感目录 def checkDir(self, path): path = path.replace('//', '/') diff --git a/class/core/public.py b/class/core/public.py index 691499e08..498de2b20 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -429,7 +429,7 @@ def writeSpeed(title, used, total, speed=0): def getSpeed(): # 取进度 - path = public.getRootDir() + path = getRootDir() data = readFile(path + '/tmp/panelSpeed.pl') if not data: data = json.dumps({'title': None, 'progress': 0, diff --git a/route/static/app/files.js b/route/static/app/files.js index 43c6872ce..b9d0c44ad 100755 --- a/route/static/app/files.js +++ b/route/static/app/files.js @@ -348,8 +348,8 @@ function getFiles(Path) { "+fmp[3]+"\ "+fmp[4]+"\ \ - 复制 | \ - 剪切 | \ + 复制 | \ + 剪切 | \ 重命名 | \ 权限 | \ 压缩 | \ @@ -404,8 +404,8 @@ function getFiles(Path) { "+fmp[3]+"\ "+fmp[4]+"\ \ - 复制batch | \ - 剪切 | \ + 复制 | \ + 剪切 | \ 重命名 | \ 权限 | \ 压缩 | \ @@ -414,7 +414,7 @@ function getFiles(Path) { "; } else{ - Body += "