From 47c813c0a66b1b756abf4907bfacf3da7fd827c6 Mon Sep 17 00:00:00 2001 From: midoks Date: Thu, 14 Mar 2019 02:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.mysql修改备注 2.修改版本号 3.mysql迁移功能 4.选择文件优化 --- .gitignore | 1 + class/core/config_api.py | 2 +- plugins/mysql/index.html | 1 + plugins/mysql/index.py | 108 +++++++++++++++++++++++++++++++------ plugins/mysql/js/mysql.js | 65 +++++++++++++--------- route/static/app/public.js | 23 +++++--- tools.py | 4 +- 7 files changed, 151 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 86909aa52..324660097 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,4 @@ data/site.pl data/admin_path.pl data/close.pl ssl/input.pl +data/datadir.pl diff --git a/class/core/config_api.py b/class/core/config_api.py index dfb048748..69ba2aa9b 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -15,7 +15,7 @@ from flask import request class config_api: - __version = '0.2.1' + __version = '0.3.7' def __init__(self): pass diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 104612b6a..b8e4ec2ba 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -31,6 +31,7 @@

服务

自启动

配置文件

+

存储位置

端口

当前状态

性能优化

diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index e14bc3344..aceff5ef6 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -151,10 +151,6 @@ def getDataDir(): def binLog(): args = getArgs() - # data = checkArgs(args, ['status']) - # if not data[0]: - # return data[1] - conf = getConf() con = public.readFile(conf) @@ -163,7 +159,7 @@ def binLog(): return public.returnJson(False, '0') con = con.replace('#log-bin=mysql-bin', 'log-bin=mysql-bin') con = con.replace('#binlog_format=mixed', 'binlog_format=mixed') - os.system('sync') + public.execShell('sync') restart() else: path = getDataDir() @@ -177,9 +173,9 @@ def binLog(): return public.returnJson(True, dsize) con = con.replace('log-bin=mysql-bin', '#log-bin=mysql-bin') con = con.replace('binlog_format=mixed', '#binlog_format=mixed') - os.system('sync') + public.execShell('sync') restart() - os.system('rm -f ' + path + '/mysql-bin.*') + public.execShell('rm -f ' + path + '/mysql-bin.*') public.writeFile(conf, con) return public.returnJson(True, '设置成功!') @@ -195,12 +191,14 @@ def getErrorLog(): if n == 'error.log': filename = path + '/' + n break + print filename if not os.path.exists(filename): return public.returnJson(False, '指定文件不存在!') if args.has_key('close'): public.writeFile(filename, '') - return public.returnJson(True, '日志已清空') - return public.getNumLines(filename, 1000) + return public.returnJson(False, '日志已清空') + info = public.getNumLines(filename, 1000) + return public.returnJson(True, 'OK', info) def getShowLogFile(): @@ -307,6 +305,57 @@ def initdUinstall(): return 'ok' +def getMyDbPos(): + file = getConf() + content = public.readFile(file) + rep = 'datadir\s*=\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + + +def setMyDbPos(): + args = getArgs() + data = checkArgs(args, ['datadir']) + if not data[0]: + return data[1] + + s_datadir = getMyDbPos() + t_datadir = args['datadir'] + if t_datadir == s_datadir: + return public.returnJson(False, '与当前存储目录相同,无法迁移文件!') + + if not os.path.exists(t_datadir): + public.execShell('mkdir -p ' + t_datadir) + + # public.execShell('/etc/init.d/mysqld stop') + stop() + public.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/') + public.execShell('chown -R mysql.mysql ' + t_datadir) + public.execShell('chmod -R 755 ' + t_datadir) + public.execShell('rm -f ' + t_datadir + '/*.pid') + public.execShell('rm -f ' + t_datadir + '/*.err') + + path = getServerDir() + myfile = path + '/etc/my.cnf' + mycnf = public.readFile(myfile) + public.writeFile(path + '/etc/my_backup.cnf', mycnf) + + mycnf = mycnf.replace(s_datadir, t_datadir) + public.writeFile(myfile, mycnf) + start() + + result = public.execShell( + 'ps aux|grep mysqld| grep -v grep|grep -v python') + if len(result[0]) > 10: + public.writeFile('data/datadir.pl', t_datadir) + return public.returnJson(True, '存储目录迁移成功!') + else: + public.execShell('pkill -9 mysqld') + public.writeFile(myfile, public.readFile(path + '/etc/my_backup.cnf')) + start() + return public.returnJson(False, '文件迁移失败!') + + def getMyPort(): file = getConf() content = public.readFile(file) @@ -317,8 +366,9 @@ def getMyPort(): def setMyPort(): args = getArgs() - if not 'port' in args: - return 'port missing' + data = checkArgs(args, ['port']) + if not data[0]: + return data[1] port = args['port'] file = getConf() @@ -586,8 +636,10 @@ def syncToDatabases(): def setRootPwd(): args = getArgs() - if not 'password' in args: - return 'password missing' + data = checkArgs(args, ['password']) + if not data[0]: + return data[1] + password = args['password'] try: pdb = pMysqlDb() @@ -648,15 +700,31 @@ def setUserPwd(): return isError pdb.execute("flush privileges") psdb.where("id=?", (id,)).setField('password', newpassword) - return public.returnJson(True, public.getInfo('修改数据库[{1}]密码成功!', (name))) + return public.returnJson(True, public.getInfo('修改数据库[{1}]密码成功!', (name,))) except Exception as ex: - print str(ex) - return public.returnJson(False, public.getInfo('修改数据库[{1}]密码失败!', (name))) + # print str(ex) + return public.returnJson(False, public.getInfo('修改数据库[{1}]密码失败!', (name,))) -def addDb(): +def setDbPs(): args = getArgs() + data = checkArgs(args, ['id', 'name', 'ps']) + if not data[0]: + return data[1] + ps = args['ps'] + sid = args['id'] + name = args['name'] + try: + psdb = pSqliteDb('databases') + psdb.where("id=?", (sid,)).setField('ps', ps) + return public.returnJson(True, public.getInfo('修改数据库[{1}]备注成功!', (name,))) + except Exception as e: + return public.returnJson(True, public.getInfo('修改数据库[{1}]备注失败!', (name,))) + + +def addDb(): + args = getArgs() data = checkArgs(args, ['password', 'name', 'codeing', 'db_user', 'dataAccess', 'ps']) if not data[0]: @@ -990,6 +1058,10 @@ if __name__ == "__main__": print getErrorLog() elif func == 'show_log': print getShowLogFile() + elif func == 'my_db_pos': + print getMyDbPos() + elif func == 'set_db_pos': + print setMyDbPos() elif func == 'my_port': print getMyPort() elif func == 'set_my_port': @@ -1014,6 +1086,8 @@ if __name__ == "__main__": print getDbAccess() elif func == 'set_db_access': print setDbAccess() + elif func == 'set_db_ps': + print setDbPs() elif func == 'get_db_info': print getDbInfo() elif func == 'repair_table': diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index d8ed8ed4e..09b6b695c 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -88,6 +88,26 @@ function runInfo(){ } +function myDbPos(){ + myPost('my_db_pos','',function(data){ + var con = '
\ +
\ + \ + \ + \ +
'; + $(".soft-man-con").html(con); + + $('#btn_change_path').click(function(){ + var datadir = $("input[name='datadir']").val(); + myPost('set_db_pos','datadir='+datadir,function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg,{icon:rdata.status ? 1 : 5,time:2000,shade: [0.3, '#000']}); + }); + }); + }); +} + function myPort(){ myPost('my_port','',function(data){ var con = '
\ @@ -740,36 +760,26 @@ function delDbBatch(){ } -function setDataByKey(tab, key, obj) { +function setDbPs(id, name, obj) { var _span = $(obj); - var _input = $(""); + var _input = $(""); _span.hide().after(_input); _input.focus(); _input.blur(function(){ - // var item = $(this).parents('tr').data('item'); - // console.log(item); - // var _txt = $(this); - // var data = {table:tab,id:item.id}; - // data[key] = _txt.val() - // bt.pub.set_data_ps(data,function(rdata){ - // if(rdata.status){ - // _span.text(_txt.val()); - // _span.show(); - // _txt.remove(); - // } - // }) - }) + $(this).remove(); + var ps = _input.val(); + _span.text(ps).show(); + var data = {name:name,id:id,ps:ps}; + myPost('set_db_ps', data, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); + }); _input.keyup(function(){ if(event.keyCode == 13){ _input.trigger('blur'); } - }) -} - -function setDbPs(data,callback){ - bt.send('setPs','data/setPs',data,function(rdata){ - if(callback) callback(rdata); - }) + }); } function openPhpmyadmin(name,username,password){ @@ -838,7 +848,7 @@ function dbList(page, search){ ''+ ''; // list += '备份'; - list += ''+rdata.data[i]['ps']+''; + list += ''+rdata.data[i]['ps']+''; list += '' + '管理 | ' + '工具 | ' + @@ -935,9 +945,12 @@ function myLogs(){ }) myPost('error_log', 'p=1', function(data){ - var error_body = data.data; - if (error_body == "") { - error_body = '当前没有日志内容!'; + var rdata = $.parseJSON(data.data); + var error_body = ''; + if (rdata.status){ + error_body = rdata.data; + } else { + error_body = rdata.msg; } $("#error_log").text(error_body); var ob = document.getElementById('error_log'); diff --git a/route/static/app/public.js b/route/static/app/public.js index 2fb8d65f0..49a4a101c 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -235,7 +235,11 @@ function getDiskList(b) { } function createFolder() { - var a = "   "; + var a = "\ + \ + \ +   \ + "; if($("#tbody tr").length == 0) { $("#tbody").append(a) } else { @@ -247,7 +251,7 @@ function createFolder() { var b = $("#PathPlace").find("span").text(); newTxt = b.replace(new RegExp(/(\/\/)/g), "/") + c; var d = "path=" + newTxt; - $.post("/files?action=CreateDir", d, function(e) { + $.post("/files/create_dir", d, function(e) { if(e.status == true) { layer.msg(e.msg, { icon: 1 @@ -257,8 +261,8 @@ function createFolder() { icon: 2 }) } - getDiskList(b) - }) + getDiskList(b); + },'json'); }); $("#nameNOk").click(function() { $(this).parents("tr").remove() @@ -269,7 +273,7 @@ function NewDelFile(c) { var a = $("#PathPlace").find("span").text(); newTxt = c.replace(new RegExp(/(\/\/)/g), "/"); var b = "path=" + newTxt + "&empty=True"; - $.post("/files?action=DeleteDir", b, function(d) { + $.post("/files/delete_dir", b, function(d) { if(d.status == true) { layer.msg(d.msg, { icon: 1 @@ -280,7 +284,7 @@ function NewDelFile(c) { }) } getDiskList(a); - }) + },'json'); } function activeDisk() { @@ -338,8 +342,13 @@ function backFile() { function getfilePath() { var a = $("#PathPlace").find("span").text(); a = a.replace(new RegExp(/(\\)/g), "/"); + a_len = a.length; + if (a[a_len-1] == '/'){ + a = a.substr(0,a_len-1); + } + $("#" + getCookie("SetId")).val(a + getCookie("SetName")); - layer.close(getCookie("ChangePath")) + layer.close(getCookie("ChangePath")); } function setCookie(a, c) { diff --git a/tools.py b/tools.py index cb5ecb9d5..89322ca9f 100755 --- a/tools.py +++ b/tools.py @@ -57,9 +57,9 @@ echo "The root password set ${pwd} successuful"''' os.system("/bin/bash mysql_root.sh " + password) os.system("rm -f mysql_root.sh") - result = sql.table('config').where( + pos = public.getServerDir() + '/mysql' + result = sql.table('config').dbPos(pos, 'mysql').where( 'id=?', (1,)).setField('mysql_root', password) - print(result) def set_panel_pwd(password, ncli=False):