From aa0f53f2fb9718450da80681b9be4a02fa3ed359 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 7 Jan 2019 13:49:03 +0800 Subject: [PATCH] update --- plugins/mysql/index.py | 78 ++++++++++++++++++- plugins/mysql/js/mysql.js | 157 ++++++++++++++++++++++++++++++++++---- 2 files changed, 219 insertions(+), 16 deletions(-) diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 557206904..dfc230e38 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -339,10 +339,9 @@ def setDbStatus(): public.writeFile(conFile, content) return public.returnJson(True, '设置成功!') -# 检测数据库执行错误 - def isSqlError(mysqlMsg): + # 检测数据库执行错误 mysqlMsg = str(mysqlMsg) if "MySQLdb" in mysqlMsg: return public.returnJson(False, 'MySQLdb组件缺失!
进入SSH命令行输入: pip install mysql-python') @@ -357,6 +356,46 @@ def isSqlError(mysqlMsg): return None +def getDbList(): + args = getArgs() + page = 1 + page_size = 10 + search = '' + data = {} + if 'page' in args: + page = int(args['page']) + + if 'page_size' in args: + page_size = int(args['page_size']) + + if 'search' in args: + search = args['search'] + + conn = pSqliteDb('databases') + limit = str((page - 1) * page_size) + ',' + str(page_size) + condition = '' + if not search == '': + condition = "name like '%" + search + "%'" + field = 'id,pid,name,username,password,accept,ps,addtime' + clist = conn.where(condition, ()).field( + field).limit(limit).order('id desc').select() + count = conn.where(condition, ()).count() + _page = {} + _page['count'] = count + _page['p'] = page + _page['row'] = page_size + _page['tojs'] = 'dbList' + data['page'] = public.getPage(_page) + data['data'] = clist + + info = {} + info['root_pwd'] = pSqliteDb('config').where( + 'id=?', (1,)).getField('mysql_root') + data['info'] = info + + return public.getJson(data) + + def syncGetDatabases(): pdb = pMysqlDb() psdb = pSqliteDb('databases') @@ -394,6 +433,37 @@ def syncGetDatabases(): msg = public.getInfo('本次共从服务器获取了{1}个数据库!', (str(n),)) return public.returnJson(True, msg) + +def setRootPwd(): + args = getArgs() + if not 'password' in args: + return 'password missing' + password = args['password'] + try: + pdb = pMysqlDb() + result = pdb.query("show databases") + isError = isSqlError(result) + if isError != None: + return isError + + m_version = public.readFile(getServerDir() + '/version.pl') + if m_version.find('5.7') == 0 or m_version.find('8.0') == 0: + pdb.execute( + "UPDATE mysql.user SET authentication_string='' WHERE user='root'") + pdb.execute( + "ALTER USER 'root'@'localhost' IDENTIFIED BY '%s'" % password) + pdb.execute( + "ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '%s'" % password) + else: + result = pdb.execute( + "update mysql.user set Password=password('" + password + "') where User='root'") + pdb.execute("flush privileges") + pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (password,)) + return public.returnJson(True, '数据库root密码修改成功!') + except Exception as ex: + return public.returnJson(False, '修改错误:' + str(ex)) + + if __name__ == "__main__": func = sys.argv[1] if func == 'status': @@ -428,7 +498,11 @@ if __name__ == "__main__": print setMyPort() elif func == 'init_pwd': print initMysqlPwd() + elif func == 'get_db_list': + print getDbList() elif func == 'sync_get_databases': print syncGetDatabases() + elif func == 'set_root_pwd': + print setRootPwd() else: print 'error' diff --git a/plugins/mysql/js/mysql.js b/plugins/mysql/js/mysql.js index 4044b57b1..078befc93 100755 --- a/plugins/mysql/js/mysql.js +++ b/plugins/mysql/js/mysql.js @@ -413,10 +413,144 @@ function comMySqlMem() { $("input[name='memSize']").val(memSize.toFixed(2)); } -function dbList(){ - var con = '
\ - \ - \ +function syncGetDatabase(){ + myPost('sync_get_databases', null, function(data){ + var rdata = $.parseJSON(data.data); + showMsg(rdata.msg,function(){ + dbList(); + },{ icon: rdata.status ? 1 : 2 }); + }); +} + +function setRootPwd(type, pwd){ + if (type==1){ + var data = $("#mod_pwd").serialize(); + myPost('set_root_pwd', data, function(data){ + var rdata = $.parseJSON(data.data); + // console.log(rdata); + showMsg(rdata.msg,function(){ + dbList(); + $('.layui-layer-close1').click(); + },{icon: rdata.status ? 1 : 2}); + }); + return; + } + + var index = layer.open({ + type: 1, + skin: 'demo-class', + area: '500px', + title: '修改数据库密码', + closeBtn: 1, + shift: 5, + shadeClose: true, + content: "
\ +
\ + root密码\ +
\ +
\ +
\ + \ + \ +
\ +
", + }); + + $('#my_mod_close').click(function(){ + $('.layui-layer-close1').click(); + }); +} + +function addDatabase(){ + var index = layer.open({ + type: 1, + skin: 'demo-class', + area: '500px', + title: '添加数据库', + closeBtn: 1, + shift: 5, + shadeClose: true, + content: "
\ +
\ + 数据库名\ +
\ + \ +
\ +
\ +
用户名
\ +
\ + 密码\ +
\ +
\ +
\ + 访问权限\ +
\ + \ + \ +
\ +
\ +
\ + \ + \ +
\ +
", + }); + + $('#my_mod_close').click(function(){ + $('.layui-layer-close1').click(); + }); +} + +function dbList(page, search){ + var _data = {}; + if (typeof(page) =='undefined'){ + var page = 1; + } + + _data['page'] = page; + _data['page_size'] = 10; + if(typeof(search) != 'undefined'){ + _data['search'] = search; + } + myPost('get_db_list', _data, function(data){ + var rdata = $.parseJSON(data.data); + // console.log(rdata); + var list = ''; + for(i in rdata.data){ + // console.log(i, rdata.data[i]); + list += ''; + list +=''; + list += '' + rdata.data[i]['name'] +''; + list += '' + rdata.data[i]['username'] +''; + list += '' + + '**********' + + ''+ + ''+ + ''; + list += '备份'; + list += '' + rdata.data[i]['ps'] +''; + list += '' + + '管理 | ' + + '工具 | ' + + '权限 | ' + + '改密 | ' + + '删除' + + ''; + list += ''; + } + + var con = '
\ + \ + \ \ \ \ @@ -432,9 +566,10 @@ function dbList(){ 备份备注\ 操作\ \ + '+ list +'\ \
\ -
1共2条数据
\ +
\
\ 同步选中\ 同步所有\ @@ -443,14 +578,8 @@ function dbList(){
\
'; - $(".soft-man-con").html(con); -} - -function syncGetDatabase(){ - myPost('sync_get_databases', null, function(data){ - var rdata = $.parseJSON(data.data); - showMsg(rdata.msg,function(){ - dbList(); - },{ icon: rdata.status ? 1 : 2 }); + $(".soft-man-con").html(con); + $('#databasePage').html(rdata.page); }); } +