From 026e42d8173b4c0b8550ee85f1648ebd19aa2110 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 8 Jan 2019 20:23:18 +0800 Subject: [PATCH] update --- plugins/mysql/index.html | 2 +- plugins/mysql/index.py | 57 +++++++++++++++++++++++-------- plugins/mysql/js/mysql.js | 72 ++++++++++++++++++++++++++++++++------- 3 files changed, 102 insertions(+), 29 deletions(-) diff --git a/plugins/mysql/index.html b/plugins/mysql/index.html index 381ae98cf..29db4e29b 100755 --- a/plugins/mysql/index.html +++ b/plugins/mysql/index.html @@ -17,7 +17,7 @@ \ No newline at end of file diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index fae4cfaa8..51638fe79 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -54,6 +54,13 @@ def getArgs(): return tmp +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, public.returnJson(False, ck[i] + 'missing!')) + return (True, public.returnJson(True, 'ok')) + + def getConf(): path = getServerDir() + '/etc/my.cnf' return path @@ -482,20 +489,11 @@ def __createUser(dbname, username, password, address): def addDb(): args = getArgs() - if not 'password' in args: - return 'password missing' - if not 'name' in args: - return 'name missing' - - if not 'codeing' in args: - return 'codeing missing' - - if not 'db_user' in args: - return 'db_user missing' - - if not 'dataAccess' in args: - return 'dataAccess missing' + data = checkArgs(args, + ['password', 'name', 'codeing', 'db_user', 'dataAccess', 'ps']) + if not data[0]: + return data[1] if not 'address' in args: address = '' @@ -507,6 +505,7 @@ def addDb(): codeing = args['codeing'].strip() password = args['password'].strip() dataAccess = args['dataAccess'].strip() + ps = args['ps'].strip() reg = "^[\w\.-]+$" if not re.match(reg, args['name']): @@ -549,15 +548,43 @@ def addDb(): addTime = time.strftime('%Y-%m-%d %X', time.localtime()) psdb.add('pid,name,username,password,accept,ps,addtime', - (0, dbname, dbuser, password, address, '', addTime)) + (0, dbname, dbuser, password, address, ps, addTime)) return public.returnJson(True, '添加成功!') def delDb(): + args = getArgs() + data = checkArgs(args, ['id', 'name']) + if not data[0]: + return data[1] try: + id = args['id'] + name = args['name'] + psdb = pSqliteDb('databases') + pdb = pMysqlDb() + find = psdb.where("id=?", (id,)).field( + 'id,pid,name,username,password,accept,ps,addtime').find() + accept = find['accept'] + username = find['username'] + + # 删除MYSQL + result = pdb.execute("drop database `" + name + "`") + isError = isSqlError(result) + if isError != None: + return isError + + users = pdb.query( + "select Host from mysql.user where User='" + username + "' AND Host!='localhost'") + pdb.execute("drop user '" + username + "'@'localhost'") + for us in users: + pdb.execute("drop user '" + username + "'@'" + us[0] + "'") + pdb.execute("flush privileges") + + # 删除SQLITE + psdb.where("id=?", (id,)).delete() return public.returnJson(True, '删除成功!') except Exception as ex: - return public.returnJson(False, '删除失败!') + return public.returnJson(False, '删除失败!' + str(ex)) if __name__ == "__main__": func = sys.argv[1] diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 32a957ee7..e711111e3 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -460,16 +460,49 @@ function setRootPwd(type, pwd){ }); } +function showHidePass(obj){ + var a = "glyphicon-eye-open"; + var b = "glyphicon-eye-close"; + + if($(obj).hasClass(a)){ + $(obj).removeClass(a).addClass(b); + $(obj).prev().text($(obj).prev().attr('data-pw')) + } + else{ + $(obj).removeClass(b).addClass(a); + $(obj).prev().text('***'); + } +} + +function copyPass(password){ + var clipboard = new ClipboardJS('#bt_copys'); + clipboard.on('success', function (e) { + bt.msg({msg:'复制成功',icon:1}); + }); + + clipboard.on('error', function (e) { + bt.msg({msg:'复制失败,浏览器不兼容!',icon:2}); + }); + $("#bt_copys").attr('data-clipboard-text',password); + $("#bt_copys").click(); +} + function addDatabase(type){ if (type==1){ var data = $("#add_db").serialize(); - myPost('add_db', data, function(data){ + data = decodeURIComponent(data); + var dataObj = str2Obj(data); + if(!dataObj['address']){ + dataObj['address'] = dataObj['dataAccess']; + } + myPost('add_db', dataObj, function(data){ var rdata = $.parseJSON(data.data); - console.log(rdata); - // showMsg(rdata.msg,function(){ - // dbList(); - // $('.layui-layer-close1').click(); - // },{icon: rdata.status ? 1 : 2}); + showMsg(rdata.msg,function(){ + if (rdata.status){ + dbList(); + } + $('.layui-layer-close1').click(); + },{icon: rdata.status ? 1 : 2},600); }); return; } @@ -503,11 +536,12 @@ function addDatabase(type){
\ \
\ \ + \
\ \ \ @@ -515,10 +549,15 @@ function addDatabase(type){ ", }); + $("input[name='name']").keyup(function(){ + var v = $(this).val(); + $("input[name='db_user']").val(v); + $("input[name='ps']").val(v); + }); + $('#my_mod_close').click(function(){ $('.layui-layer-close1').click(); }); - $('select[name="dataAccess"]').change(function(){ var v = $(this).val(); if (v == 'ip'){ @@ -531,7 +570,14 @@ function addDatabase(type){ function delDb(id, name){ safeMessage('删除['+name+']','您真的要删除['+name+']吗?',function(){ - + var data='id='+id+'&name='+name + myPost('del_db', data, function(data){ + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg,function(){ + dbList(); + $('.layui-layer-close1').click(); + },{icon: rdata.status ? 1 : 2},1000); + }); }); } @@ -598,12 +644,12 @@ function dbList(page, search){ list += '' + rdata.data[i]['name'] +''; list += '' + rdata.data[i]['username'] +''; list += '' + - '**********' + - ''+ - ''+ + '***' + + ''+ + ''+ ''; list += '备份'; - list += '' + rdata.data[i]['ps'] +''; + list += ''+rdata.data[i]['ps']+''; list += '' + '管理 | ' + '工具 | ' +