diff --git a/web/admin/files/files.py b/web/admin/files/files.py index 8a6109e73..a9f93d711 100644 --- a/web/admin/files/files.py +++ b/web/admin/files/files.py @@ -79,6 +79,15 @@ def zip(): path = request.form.get('path', '') return file.zip(sfile, dfile, stype, path) +# 文件权限查看 +@blueprint.route('/file_access', endpoint='file_access', methods=['POST']) +@panel_login_required +def file_access(): + filename = request.form.get('filename', '') + data = file.getAccess(filename) + data['sys_users'] = file.getSysUserList() + return data + # 复制文件内容 @blueprint.route('/copy_file', endpoint='copy_file', methods=['POST']) @panel_login_required diff --git a/web/utils/file.py b/web/utils/file.py index c3b593c1b..78445d516 100644 --- a/web/utils/file.py +++ b/web/utils/file.py @@ -294,6 +294,17 @@ def unzip(sfile, dfile, stype, path): except: return mw.returnData(False, '文件解压失败!') +def getAccess(filename): + data = {} + try: + stat = os.stat(filename) + data['chmod'] = str(oct(stat.st_mode)[-3:]) + data['chown'] = pwd.getpwuid(stat.st_uid).pw_name + except: + data['chmod'] = 755 + data['chown'] = 'www' + return data + def copyDir(src_file, dst_file): if not os.path.exists(src_file): return mw.returnData(False, '指定目录不存在!') @@ -649,6 +660,20 @@ def getAccess(fname): data['chown'] = 'www' return data +def getSysUserList(): + pwd_file = '/etc/passwd' + if os.path.exists(pwd_file): + content = mw.readFile(pwd_file) + clist = content.split('\n') + sys_users = [] + for line in clist: + if line.find(":")<0: + continue + lines = line.split(":",1) + sys_users.append(lines[0]) + return sys_users + return ['root','mysql','www'] + def fileDelete(path): if not os.path.exists(path): return mw.returnData(False, '指定文件不存在!')