From e87968aebc6e990a0caa01ba6545bddd7bf93907 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 12 Nov 2018 11:41:00 +0800 Subject: [PATCH] o --- class/core/public.py | 2 +- route/files.py | 82 +++++++++++++++++++++++++++++++----- route/system.py | 42 ++++++++++++++++++ static/js/files.js | 6 +-- templates/default/files.html | 22 +++++----- 5 files changed, 128 insertions(+), 26 deletions(-) diff --git a/class/core/public.py b/class/core/public.py index ecaf10450..620b901f9 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -49,7 +49,7 @@ def getPage(args, result='1,2,3,4,5,8'): info['p'] = 1 if args.has_key('p'): - info['p'] = int(get['p']) + info['p'] = int(args['p']) info['uri'] = {} info['return_js'] = '' if args.has_key('tojs'): diff --git a/route/files.py b/route/files.py index ca060c2b4..efff2217d 100644 --- a/route/files.py +++ b/route/files.py @@ -1,14 +1,15 @@ # coding:utf-8 -from flask import Flask -from flask import Blueprint, render_template -from flask import jsonify - import os import sys -sys.path.append("class/") +sys.path.append("class/core") import public +from flask import Flask +from flask import Blueprint, render_template +from flask import jsonify +from flask import request + files = Blueprint('files', __name__, template_folder='templates') @@ -18,11 +19,70 @@ def index(): return render_template('default/files.html') -@files.route("/GetDiskInfo") -def GetDiskInfo(): - return jsonify({'result': 'ok'}) +@files.route('/get_dir', methods=['POST']) +def getDir(): + path = request.form.get('path', '').encode('utf-8') + print path + path = "/" + + info = {} + info['count'] = 10 + info['row'] = 10 + info['p'] = 1 + if request.form.has_key('p'): + info['p'] = int(request.form.get('p')) + info['uri'] = {} + info['return_js'] = '' + if request.form.has_key('tojs'): + info['return_js'] = request.form.get('tojs') + if request.form.has_key('showRow'): + info['row'] = int(request.form.get('showRow')) + + data = {} + data['PAGE'] = public.getPage(info, '1,2,3,4,5,6,7,8') + + search = None + if request.form.has_key('search'): + search = request.form.get('search').strip().lower() + i = 0 + n = 0 + for filename in os.listdir(path): + if search: + if filename.lower().find(search) == -1: + continue + i += 1 + if n >= 10: + break + if i < 0: + continue + try: + filePath = (path + '/' + filename).encode('utf8') + link = '' + if os.path.islink(filePath): + filePath = os.readlink(filePath) + link = ' -> ' + filePath + if not os.path.exists(filePath): + filePath = path + '/' + filePath + if not os.path.exists(filePath): + continue -@files.route('/GetExecLogs', methods=['POST']) -def GetExecLogs(): - pass + stat = os.stat(filePath) + accept = str(oct(stat.st_mode)[-3:]) + mtime = str(int(stat.st_mtime)) + user = '' + try: + user = pwd.getpwuid(stat.st_uid).pw_name + except: + user = str(stat.st_uid) + size = str(stat.st_size) + if os.path.isdir(filePath): + dirnames.append(filename + ';' + size + ';' + + mtime + ';' + accept + ';' + user + ';' + link) + else: + filenames.append(filename + ';' + size + ';' + + mtime + ';' + accept + ';' + user + ';' + link) + n += 1 + except: + continue + return public.getJson(data) diff --git a/route/system.py b/route/system.py index 8c405a62d..a91afb711 100644 --- a/route/system.py +++ b/route/system.py @@ -157,3 +157,45 @@ def systemtotal(): data['isuser'] = public.M('users').where('username=?', ('admin',)).count() data['version'] = '0.0.1' return jsonify(data) + + +@system.route("/disk_info") +def diskInfo(): + # 取磁盘分区信息 + temp = public.execShell("df -h -P|grep '/'|grep -v tmpfs")[0] + tempInodes = public.execShell("df -i -P|grep '/'|grep -v tmpfs")[0] + temp1 = temp.split('\n') + tempInodes1 = tempInodes.split('\n') + diskInfo = [] + n = 0 + cuts = ['/mnt/cdrom', '/boot', '/boot/efi', '/dev', + '/dev/shm', '/run/lock', '/run', '/run/shm', '/run/user'] + for tmp in temp1: + n += 1 + inodes = tempInodes1[n - 1].split() + disk = tmp.split() + if len(disk) < 5: + continue + if disk[1].find('M') != -1: + continue + if disk[1].find('K') != -1: + continue + if len(disk[5].split('/')) > 4: + continue + if disk[5] in cuts: + continue + arr = {} + arr['path'] = disk[5] + tmp1 = [disk[1], disk[2], disk[3], disk[4]] + arr['size'] = tmp1 + arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]] + if disk[5] == '/': + bootLog = os.getcwd() + '/tmp/panelBoot.pl' + if disk[2].find('M') != -1: + if os.path.exists(bootLog): + os.system('rm -f ' + bootLog) + else: + if not os.path.exists(bootLog): + pass + diskInfo.append(arr) + return public.getJson(diskInfo) diff --git a/static/js/files.js b/static/js/files.js index 0fac35880..5cfbb217d 100755 --- a/static/js/files.js +++ b/static/js/files.js @@ -334,7 +334,7 @@ function GetFiles(Path) { var data = 'path=' + Path; var loadT = layer.load(); var totalSize = 0; - $.post('/files?action=GetDir&tojs=GetFiles&p=' + p + '&showRow=' + showRow + search, data, function(rdata) { + $.post('/files/get_dir?tojs=GetFiles&p=' + p + '&showRow=' + showRow + search, data, function(rdata) { layer.close(loadT); var rows = ['100','200','500','1000','2000']; @@ -781,14 +781,14 @@ function GetFileName(fileNameFull) { //取磁盘 function GetDisk() { var LBody = ''; - $.get('/system?action=GetDiskInfo', function(rdata) { + $.get('/system/disk_info', function(rdata) { for (var i = 0; i < rdata.length; i++) { LBody += " " + (rdata[i].path=='/'?lan.files.path_root:rdata[i].path) + "(" + rdata[i].size[2] + ")"; } var trash = ' '+lan.files.recycle_bin_title+''; $("#comlist").html(LBody+trash); IsDiskWidth(); - }); + },'json'); } //返回上一级 diff --git a/templates/default/files.html b/templates/default/files.html index 19de9f628..bc7a50ef1 100755 --- a/templates/default/files.html +++ b/templates/default/files.html @@ -52,10 +52,10 @@
  • $tData['lan']['L4']
  • $tData['lan']['L5']
  • - - - - + + + +