diff --git a/plugins/redis/index.py b/plugins/redis/index.py
index 0503c2f73..4c558c055 100755
--- a/plugins/redis/index.py
+++ b/plugins/redis/index.py
@@ -39,7 +39,15 @@ def status():
result[t[0]] = t[1]
return public.getJson(result)
+
+def getConf():
+ path = os.path.dirname(os.getcwd()) + "/redis/redis.conf"
+ return path
+
+
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
print status()
+ elif func == 'conf':
+ print getConf()
diff --git a/plugins/redis/js/redis.js b/plugins/redis/js/redis.js
index 3825806fc..d350e119e 100755
--- a/plugins/redis/js/redis.js
+++ b/plugins/redis/js/redis.js
@@ -6,21 +6,62 @@ function redisService(name,status){
if(status == 'true') status = true;
var serviceCon ='
当前状态:'+(status?lan.soft.on:lan.soft.off)+'
\
- \
- \
- \
- \
-
';
+ \
+ \
+ \
+ \
+
';
$(".soft-man-con").html(serviceCon);
- var help = '- '+lan.soft.mysql_mem_err+'
';
- if(name == 'mysqld'){
- $(".soft-man-con").append(help);
- }
}
-
-function redisConfig(){
+//配置修改
+function redisConfig(type){
console.log('redisConfig');
+ var con = '提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!
\
+ \
+ \
+ - 此处为redis主配置文件,若您不了解配置规则,请勿随意修改。
\
+
';
+ $(".soft-man-con").html(con);
+
+ var loadT = layer.msg('配置文件路径获取中...',{icon:16,time:0,shade: [0.3, '#000']});
+ $.post('/plugins/run', {name:'redis', func:'conf'},function (data) {
+ layer.close(loadT);
+ var loadT2 = layer.msg('文件内容获取中...',{icon:16,time:0,shade: [0.3, '#000']});
+ var fileName = data.data;
+ $.post('/files/get_body', 'path=' + fileName, function(rdata) {
+ layer.close(loadT2);
+ $("#textBody").empty().text(rdata.data.data);
+ $(".CodeMirror").remove();
+ var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), {
+ extraKeys: {"Ctrl-Space": "autocomplete"},
+ lineNumbers: true,
+ matchBrackets:true,
+ });
+ editor.focus();
+ $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0});
+ $("#OnlineEditFileBtn").click(function(){
+ $("#textBody").text(editor.getValue());
+ redisConfSafe(fileName);
+ });
+ },'json');
+ },'json');
+}
+
+//配置保存
+function redisConfSafe(fileName) {
+ var data = encodeURIComponent($("#textBody").val());
+ var encoding = 'utf-8';
+ var loadT = layer.msg('保存中...', {
+ icon: 16,
+ time: 0
+ });
+ $.post('/files/save_body', 'data=' + data + '&path=' + fileName + '&encoding=' + encoding, function(rdata) {
+ layer.close(loadT);
+ layer.msg(rdata.msg, {
+ icon: rdata.status ? 1 : 2
+ });
+ },'json');
}
@@ -59,4 +100,4 @@ function redisStatus() {
},'json');
}
-redisService('redis', false);
+redisService('redis', false);
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index bc7ab163e..736b11df8 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,5 @@
flask
gunicorn
psutil
-pillow
\ No newline at end of file
+pillow
+chardet
\ No newline at end of file
diff --git a/route/files.py b/route/files.py
index 8995186ca..fe96d5f5c 100644
--- a/route/files.py
+++ b/route/files.py
@@ -19,6 +19,91 @@ def index():
return render_template('default/files.html')
+@files.route('get_body', methods=['POST'])
+def getBody():
+ path = request.form.get('path', '').encode('utf-8')
+ if not os.path.exists(path):
+ return public.returnJson(False, '文件不存在', (path,))
+
+ if os.path.getsize(path) > 2097152:
+ return public.returnJson(False, u'不能在线编辑大于2MB的文件!')
+
+ fp = open(path, 'rb')
+ data = {}
+ data['status'] = True
+ try:
+ if fp:
+ from chardet.universaldetector import UniversalDetector
+ detector = UniversalDetector()
+ srcBody = b""
+ for line in fp.readlines():
+ detector.feed(line)
+ srcBody += line
+ detector.close()
+ char = detector.result
+ data['encoding'] = char['encoding']
+ if char['encoding'] == 'GB2312' or not char['encoding'] or char[
+ 'encoding'] == 'TIS-620' or char['encoding'] == 'ISO-8859-9':
+ data['encoding'] = 'GBK'
+ if char['encoding'] == 'ascii' or char[
+ 'encoding'] == 'ISO-8859-1':
+ data['encoding'] = 'utf-8'
+ if char['encoding'] == 'Big5':
+ data['encoding'] = 'BIG5'
+ if not char['encoding'] in ['GBK', 'utf-8',
+ 'BIG5']:
+ data['encoding'] = 'utf-8'
+ try:
+ if sys.version_info[0] == 2:
+ data['data'] = srcBody.decode(
+ data['encoding']).encode('utf-8', errors='ignore')
+ else:
+ data['data'] = srcBody.decode(data['encoding'])
+ except:
+ data['encoding'] = char['encoding']
+ if sys.version_info[0] == 2:
+ data['data'] = srcBody.decode(
+ data['encoding']).encode('utf-8', errors='ignore')
+ else:
+ data['data'] = srcBody.decode(data['encoding'])
+ else:
+ if sys.version_info[0] == 2:
+ data['data'] = srcBody.decode('utf-8').encode('utf-8')
+ else:
+ data['data'] = srcBody.decode('utf-8')
+ data['encoding'] = u'utf-8'
+
+ return public.returnJson(True, 'OK', data)
+ except Exception as ex:
+ return public.returnJson(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))
+
+
+@files.route('save_body', methods=['POST'])
+def saveBody():
+ path = request.form.get('path', '').encode('utf-8')
+ data = request.form.get('data', '').encode('utf-8')
+ encoding = request.form.get('encoding', '').encode('utf-8')
+ if not os.path.exists(path):
+ return public.returnJson(False, '文件不存在')
+ try:
+ if encoding == 'ascii':
+ encoding = 'utf-8'
+ if sys.version_info[0] == 2:
+ data = data.encode(encoding, errors='ignore')
+ fp = open(path, 'w+')
+ else:
+ data = data.encode(
+ encoding, errors='ignore').decode(encoding)
+ fp = open(path, 'w+', encoding=encoding)
+ fp.write(data)
+ fp.close()
+
+ public.writeLog('TYPE_FILE', '文件保存成功', (path,))
+ return public.returnJson(True, '文件保存成功')
+ except Exception as ex:
+ return public.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
+
+
@files.route('/get_dir', methods=['POST'])
def getDir():
path = request.form.get('path', '').encode('utf-8')
diff --git a/static/js/soft.js b/static/js/soft.js
index 952e17764..2ca786393 100755
--- a/static/js/soft.js
+++ b/static/js/soft.js
@@ -282,21 +282,7 @@ function configChange(type) {
});
});
}
-//配置保存
-function confSafe(fileName) {
- var data = encodeURIComponent($("#textBody").val());
- var encoding = 'utf-8';
- var loadT = layer.msg(lan.soft.the_save, {
- icon: 16,
- time: 0
- });
- $.post('/files?action=SaveFileBody', 'data=' + data + '&path=' + fileName + '&encoding=' + encoding, function(rdata) {
- layer.close(loadT);
- layer.msg(rdata.msg, {
- icon: rdata.status ? 1 : 2
- });
- });
-}
+
//设置PATHINFO