function str2Obj(str){ var data = {}; kv = str.split('&'); for(i in kv){ v = kv[i].split('='); data[v[0]] = v[1]; } return data; } function myPost(method,args,callback, title){ var _args = null; if (typeof(args) == 'string'){ _args = JSON.stringify(str2Obj(args)); } else { _args = JSON.stringify(args); } var _title = '正在获取...'; if (typeof(title) != 'undefined'){ _title = title; } var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 }); $.post('/plugins/run', {name:'postgresql', func:method, args:_args}, function(data) { layer.close(loadT); if (!data.status){ layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; } if(typeof(callback) == 'function'){ callback(data); } },'json'); } function myPostN(method,args,callback, title){ var _args = null; if (typeof(args) == 'string'){ _args = JSON.stringify(str2Obj(args)); } else { _args = JSON.stringify(args); } var _title = '正在获取...'; if (typeof(title) != 'undefined'){ _title = title; } $.post('/plugins/run', {name:'postgresql', func:method, args:_args}, function(data) { if(typeof(callback) == 'function'){ callback(data); } },'json'); } function myAsyncPost(method,args){ var _args = null; if (typeof(args) == 'string'){ _args = JSON.stringify(str2Obj(args)); } else { _args = JSON.stringify(args); } var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); return syncPost('/plugins/run', {name:'mysql', func:method, args:_args}); } function runInfo(){ myPost('run_info','',function(data){ var rdata = $.parseJSON(data.data); if (typeof(rdata['status']) != 'undefined'){ layer.msg(rdata['msg'],{icon:0,time:2000,shade: [0.3, '#000']}); return; } var con = '
\ \ \ \ \ \
启动时间' + rdata.uptime + '进程数' +rdata.progress_num+ '
总连接次数' + rdata.connections + 'PID' +rdata.pid+ '
占用空间' + rdata.pg_size + '占用内存' +rdata.pg_mem+ '
\ \ \ \ \ \ \ \ \ \ \ \ \ \
表进程已经锁住的物理内存的大小' + rdata.pg_vm_lock + '
数据库分配到物理内存的峰值' + rdata.pg_vm_high + '
进程数据段的大小' + rdata.pg_vm_data_size + '
进程堆栈段的大小' + rdata.pg_vm_sk_size + '
进程代码的大小' + rdata.pg_vm_code_size + '
进程所使用LIB库的大小' + rdata.pg_vm_lib_size + '
进程占用Swap的大小' + rdata.pg_vm_swap_size + '
占用的页表的大小' + rdata.pg_vm_page_size + '
当前待处理信号的个数' + rdata.pg_sigq + '
'; $(".soft-man-con").html(con); }); } function pgPort(){ myPost('pg_port','',function(data){ var con = '
\
\ \ \
'; $(".soft-man-con").html(con); $('#btn_change_port').click(function(){ var port = $("input[name='port']").val(); myPost('set_pg_port','port='+port,function(data){ var rdata = $.parseJSON(data.data); if (rdata.status){ layer.msg('修改成功!',{icon:1,time:2000,shade: [0.3, '#000']}); } else { layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']}); } }); }); }); } //数据库配置状态 function pgPerfOpt() { //获取MySQL配置 myPost('db_status','',function(data){ var rdata = $.parseJSON(data.data); var html_p = ''; for (i in rdata){ if (i != 'status' ){ var v = rdata[i]; html_p += '

'+i+''+v[1] +', ' + v[2] + '

' } } var memCon = '
'+html_p +'
\
\ \
\
' +'
' $(".soft-man-con").html(memCon); $("#pg_conf").change(function (e) {   e.preventDefault(); var data = {}; $('#pg_conf p input').each(function (index, element) { data[$(this).attr('name')] = $(this).val() + ($(this).attr('unit') || ''); }) // console.log(data); myPost('set_db_status', data, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ },{ icon: rdata.status ? 1 : 2 }); }); return false; }); }); } function reBootPgSqld(){ pluginOpService('postgresql','restart',''); } //设置PG配置参数 function setPgConf() { return false; } 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 syncToDatabase(type){ var data = []; $('input[type="checkbox"].check:checked').each(function () { if (!isNaN($(this).val())) data.push($(this).val()); }); var postData = 'type='+type+'&ids='+JSON.stringify(data); myPost('sync_to_databases', postData, function(data){ var rdata = $.parseJSON(data.data); // console.log(rdata); 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, area: '500px', title: '修改数据库密码', closeBtn: 1, shift: 5, shadeClose: true, btn:["取消","提交"], content: "
\
\ root密码\
\
\
", yes:function(){ setRootPwd(1); } }); } 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) { layer.msg('复制成功',{icon:1,time:2000}); }); clipboard.on('error', function (e) { layer.msg('复制失败,浏览器不兼容!',{icon:2,time:2000}); }); $("#bt_copys").attr('data-clipboard-text',password); $("#bt_copys").click(); } function checkSelect(){ setTimeout(function () { var num = $('input[type="checkbox"].check:checked').length; // console.log(num); if (num == 1) { $('button[batch="true"]').hide(); $('button[batch="false"]').show(); }else if (num>1){ $('button[batch="true"]').show(); $('button[batch="false"]').show(); }else{ $('button[batch="true"]').hide(); $('button[batch="false"]').hide(); } },5) } function setDbRw(id,username,val){ myPost('set_db_rw',{id:id,username:username,rw:val}, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg, function(){ dbList(); },{icon:rdata.status ? 1 : 5,shade: [0.3, '#000']}, 2000); }); } function setDbAccess(name){ myPost('get_db_access','name='+name, function(data){ var rdata = $.parseJSON(data.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2,shade: [0.3, '#000']}); return; } var index = layer.open({ type: 1, area: '500px', title: '设置数据库权限', closeBtn: 1, shift: 5, btn:["提交","取消"], shadeClose: true, content: "
\
\ 访问权限\
\ \
\
\
", success:function(){ if (rdata.msg == '127.0.0.1/32'){ $('select[name="dataAccess"]').find("option[value='127.0.0.1/32']").attr("selected",true); } else if (rdata.msg == '0.0.0.0/0'){ $('select[name="dataAccess"]').find('option[value="%"]').attr("selected",true); } else { $('select[name="dataAccess"]').find('option[value="ip"]').attr("selected",true); $('select[name="dataAccess"]').after(""); } $('select[name="dataAccess"]').change(function(){ var v = $(this).val(); if (v == 'ip'){ $(this).after(""); } else { $('#dataAccess_subid').remove(); } }); }, yes:function(index){ var data = $("#set_db_access").serialize(); data = decodeURIComponent(data); var dataObj = str2Obj(data); if(!dataObj['access']){ dataObj['access'] = dataObj['dataAccess']; if ( dataObj['dataAccess'] == 'ip'){ if (dataObj['address']==''){ layer.msg('IP地址不能空!',{icon:2,shade: [0.3, '#000']}); return; } dataObj['access'] = dataObj['address']; } } dataObj['name'] = name; myPost('set_db_access', dataObj, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ layer.close(index); dbList(); },{icon: rdata.status ? 1 : 2}); }); } }); }); } function setDbPass(id, username, password){ var index = layer.open({ type: 1, area: '500px', title: '修改数据库密码', closeBtn: 1, shift: 5, shadeClose: true, btn:["提交","关闭"], content: "
\
\ 用户名\
\
\
\ 密码\
\
\ \
", yes:function(index){ var data = $("#mod_pwd").serialize(); myPost('set_user_pwd', data, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ layer.close(index); dbList(); },{icon: rdata.status ? 1 : 2}); }); } }); } function addDatabase(type,layer_index){ if (type == 1){ var data = $("#add_db").serialize(); data = decodeURIComponent(data); var dataObj = str2Obj(data); if(!dataObj['address']){ dataObj['address'] = dataObj['dataAccess']; } var ip_segment = $('[name="dataAccess"]').val(); if ($('[name="dataAccess"]').val() == 'ip'){ dataObj['listen_ip'] = ip_segment; } myPost('add_db', dataObj, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ layer.close(layer_index); if (rdata.status){ dbList(); } },{icon: rdata.status ? 1 : 2},2000); }); return; } layer.open({ type: 1, area: '450px', title: '添加数据库', closeBtn: 1, shift: 5, shadeClose: true, btn:["提交","取消"], content: "
\
\ 数据库名\
\ \
\
\
用户名
\
\ 密码\
\
\
\
\ 访问权限\
\ \ \
\
\
", success:function(){ $("input[name='name']").keyup(function(){ var v = $(this).val(); $("input[name='db_user']").val(v); }); $('select[name="dataAccess"]').change(function(){ var v = $(this).val(); if (v == 'ip'){ $('input[name="ip_segment"]').show(); } else { $('input[name="ip_segment"]').hide(); } }); }, yes:function(index){ addDatabase(1,index); } }); } 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}, 600); }); }); } function delDbBatch(){ var arr = []; $('input[type="checkbox"].check:checked').each(function () { var _val = $(this).val(); var _name = $(this).parent().next().text(); if (!isNaN(_val)) { arr.push({'id':_val,'name':_name}); } }); safeMessage('批量删除数据库','您共选择了[2]个数据库,删除后将无法恢复,真的要删除吗?',function(){ var i = 0; $(arr).each(function(){ var data = myAsyncPost('del_db', this); var rdata = $.parseJSON(data.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2,time:2000,shade: [0.3, '#000']}); } i++; }); var msg = '成功删除['+i+']个数据库!'; showMsg(msg,function(){ dbList(); },{icon: 1}, 600); }); } function setDbPs(id, name, obj) { var _span = $(obj); var _input = $(""); _span.hide().after(_input); _input.focus(); _input.blur(function(){ $(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 delBackup(filename,name){ myPost('delete_db_backup',{filename:filename},function(){ layer.msg('执行成功!'); setTimeout(function(){ $('.layui-layer-close2').click(); setBackup(name); },2000); }); } function downloadBackup(file){ window.open('/files/download?filename='+encodeURIComponent(file)); } function importBackup(file,name){ myPost('import_db_backup',{file:file,name:name}, function(data){ // console.log(data); layer.msg('执行成功!'); }); } function setBackup(db_name,obj){ myPost('pg_back_list', {name:db_name}, function(data){ var rdata = $.parseJSON(data.data); console.log(rdata); var tbody = ''; for (var i = 0; i < rdata.data.length; i++) { tbody += '\ ' + rdata.data[i]['name'] + '\ ' + rdata.data[i]['size'] + '\ ' + rdata.data[i]['time'] + '\ \ 导入 | \ 下载 | \ 删除\ \ '; } var s = layer.open({ type: 1, title: "数据库备份详情", area: ['600px', '280px'], closeBtn: 2, shadeClose: false, content: '
\
\ \
\
\
\ \ \ \ \ \ \ \ \ \ ' + tbody + '\
文件名称文件大小备份时间操作
\
\
\
' }); $('#btn_backup').click(function(){ myPost('pg_back',{name:db_name}, function(data){ layer.msg('执行成功!'); setTimeout(function(){ layer.close(s); setBackup(db_name,obj); },2000); }); }); }); } 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); var list = ''; for(i in rdata.data){ list += ''; list +=''; list += '' + rdata.data[i]['name'] +''; list += '' + rdata.data[i]['username'] +''; list += '' + '***' + ''+ ''+ ''; list += ''+rdata.data[i]['ps']+''; list += ''; list += ''+(rdata.data[i]['is_backup']?'备份':'未备份') +' | '; var rw = ''; var rw_change = 'all'; if (typeof(rdata.data[i]['rw'])!='undefined'){ var rw_val = '读写'; if (rdata.data[i]['rw'] == 'all'){ rw_val = "所有"; rw_change = 'rw'; } else if (rdata.data[i]['rw'] == 'rw'){ rw_val = "读写"; rw_change = 'r'; } else if (rdata.data[i]['rw'] == 'r'){ rw_val = "只读"; rw_change = 'all'; } rw = ''+rw_val+' | '; } list += '权限 | ' + rw + '改密 | ' + '删除' + ''; list += ''; } // var con = '
\ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ \ '+ list +'\
数据库名用户名密码备注操作
\
\
\
\ 从服务器获取\
\
\
'; con += ''; $(".soft-man-con").html(con); $('#databasePage').html(rdata.page); readerTableChecked(); }); } ///////////////////////////////// 主从 ///////////////////////// function setDbMaster(name){ myPost('set_db_master', {name:name}, function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); setTimeout(function(){ masterOrSlaveConf(); }, 2000); }); } function setDbSlave(name){ myPost('set_db_slave', {name:name}, function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); setTimeout(function(){ masterOrSlaveConf(); }, 2000); }); } function addMasterRepSlaveUser(){ layer.open({ type: 1, area: '500px', title: '添加同步账户', closeBtn: 1, shift: 5, shadeClose: true, btn:["提交","取消"], content: "
\
用户名
\
\ 密码\
\
\ \
", success:function(){ $("input[name='name']").keyup(function(){ var v = $(this).val(); $("input[name='db_user']").val(v); $("input[name='ps']").val(v); }); $('select[name="dataAccess"]').change(function(){ var v = $(this).val(); if (v == 'ip'){ $(this).after(""); } else { $('#dataAccess_subid').remove(); } }); }, yes:function(index){ var data = $("#add_master").serialize(); data = decodeURIComponent(data); var dataObj = str2Obj(data); if(!dataObj['address']){ dataObj['address'] = dataObj['dataAccess']; } myPost('add_master_rep_slave_user', dataObj, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ layer.close(index); if (rdata.status){ getMasterRepSlaveList(); } },{icon: rdata.status ? 1 : 2},600); }); } }); } function updateMasterRepSlaveUser(username){ var index = layer.open({ type: 1, area: '500px', title: '更新账户', closeBtn: 1, shift: 5, shadeClose: true, content: "
\
用户名
\
\ 密码\
\
\ \
\ \
\
", }); $('#submit_update_master').click(function(){ var data = $("#update_master").serialize(); data = decodeURIComponent(data); var dataObj = str2Obj(data); myPost('update_master_rep_slave_user', data, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ if (rdata.status){ getMasterRepSlaveList(); } $('.layui-layer-close1').click(); },{icon: rdata.status ? 1 : 2},600); }); }); } function getMasterRepSlaveUserCmd(username, db=''){ myPost('get_master_rep_slave_user_cmd', {username:username,db:db}, function(data){ var rdata = $.parseJSON(data.data); if (!rdata['status']){ layer.msg(rdata['msg']); return; } var cmd = rdata.data['cmd']; var loadOpen = layer.open({ type: 1, title: '同步命令', area: '500px', content:"
\
"+cmd+"
\
\ \
\
", }); copyPass(cmd); $('.class-copy-cmd').click(function(){ copyPass(cmd); }); }); } function delMasterRepSlaveUser(username){ myPost('del_master_rep_slave_user', {username:username}, function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg); $('.layui-layer-close1').click(); setTimeout(function(){ getMasterRepSlaveList(); },1000); }); } function setDbMasterAccess(username){ myPost('get_db_access','username='+username, function(data){ var rdata = $.parseJSON(data.data); if (!rdata.status){ layer.msg(rdata.msg,{icon:2,shade: [0.3, '#000']}); return; } var index = layer.open({ type: 1, area: '500px', title: '设置数据库权限', closeBtn: 1, shift: 5, btn:["提交","取消"], shadeClose: true, content: "
\
\ 访问权限\
\ \
\
\
", success:function(){ if (rdata.msg == '127.0.0.1'){ $('select[name="dataAccess"]').find("option[value='127.0.0.1']").attr("selected",true); } else if (rdata.msg == '%'){ $('select[name="dataAccess"]').find('option[value="%"]').attr("selected",true); } else if ( rdata.msg == 'ip' ){ $('select[name="dataAccess"]').find('option[value="ip"]').attr("selected",true); $('select[name="dataAccess"]').after(""); } else { $('select[name="dataAccess"]').find('option[value="ip"]').attr("selected",true); $('select[name="dataAccess"]').after(""); } $('select[name="dataAccess"]').change(function(){ var v = $(this).val(); if (v == 'ip'){ $(this).after(""); } else { $('#dataAccess_subid').remove(); } }); }, yes:function(index){ var data = $("#set_db_access").serialize(); data = decodeURIComponent(data); var dataObj = str2Obj(data); if(!dataObj['access']){ dataObj['access'] = dataObj['dataAccess']; if ( dataObj['dataAccess'] == 'ip'){ if (dataObj['address']==''){ layer.msg('IP地址不能空!',{icon:2,shade: [0.3, '#000']}); return; } dataObj['access'] = dataObj['address']; } } dataObj['username'] = username; myPost('set_dbmaster_access', dataObj, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ layer.close(index); },{icon: rdata.status ? 1 : 2}); }); } }); }); } function getMasterRepSlaveList(){ var _data = {}; if (typeof(page) =='undefined'){ var page = 1; } _data['page'] = page; _data['page_size'] = 10; myPost('get_master_rep_slave_list', _data, function(data){ // console.log(data); var rdata = []; try { rdata = $.parseJSON(data.data); } catch(e){ console.log(e); } var list = ''; // console.log(rdata['data']); var user_list = rdata['data']; for (i in user_list) { // console.log(i); var name = user_list[i]['username']; list += ''+name+'\ '+user_list[i]['password']+'\ \ 修改 | \ 删除 | \ 权限 | \ 从库同步命令\ \ '; } $('#get_master_rep_slave_list_page tbody').html(list); $('.dataTables_paginate_4').html(rdata['page']); }); } function getMasterRepSlaveListPage(){ var page = '
'; page += '
添加同步账户
'; var loadOpen = layer.open({ type: 1, title: '同步账户列表', area: '500px', content:"
\
\
\ \ \
用户名密码操作
\ "+page +"\
\
", success:function(){ getMasterRepSlaveList(); } }); } function deleteSlave(){ myPost('delete_slave', {}, function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata['msg'], function(){ masterOrSlaveConf(); },{},3000); }); } function getFullSyncStatus(db){ var timeId = null; var btn = '
开始
'; var loadOpen = layer.open({ type: 1, title: '全量同步['+db+']', area: '500px', content:"
\
\ \
\
0%
\
\
\ "+btn+"\
", cancel: function(){ clearInterval(timeId); } }); function fullSync(db,begin){ myPostN('full_sync', {db:db,begin:begin}, function(data){ var rdata = $.parseJSON(data.data); $('#full_msg').text(rdata['msg']); $('.progress-bar').css('width',rdata['progress']+'%'); $('.progress-bar').text(rdata['progress']+'%'); if (rdata['code']==6 ||rdata['code']<0){ layer.msg(rdata['msg']); clearInterval(timeId); $("#begin_full_sync").attr('data-status','init'); } }); } $('#begin_full_sync').click(function(){ var val = $(this).attr('data-status'); if (val == 'init'){ fullSync(db,1); timeId = setInterval(function(){ fullSync(db,0); }, 1000); $(this).attr('data-status','starting'); } else { layer.msg("正在同步中.."); } }); } function addSlaveSSH(ip=''){ myPost('get_slave_ssh_by_ip', {ip:ip}, function(rdata){ var rdata = $.parseJSON(rdata.data); var ip = '127.0.0.1'; var port = "22"; var id_rsa = ''; var db_user =''; if (rdata.data.length>0){ ip = rdata.data[0]['ip']; port = rdata.data[0]['port']; id_rsa = rdata.data[0]['id_rsa']; db_user = rdata.data[0]['db_user']; } var index = layer.open({ type: 1, area: ['500px','480px'], title: '添加SSH', closeBtn: 1, shift: 5, shadeClose: true, btn:["确认","取消"], content: "
\
IP
\
端口
\
同步账户[DB]
\
\ ID_RSA\
\
\ \
", success:function(){ $('textarea[name="id_rsa"]').html(id_rsa); }, yes:function(index){ var ip = $('input[name="ip"]').val(); var port = $('input[name="port"]').val(); var db_user = $('input[name="db_user"]').val(); var id_rsa = $('textarea[name="id_rsa"]').val(); var data = {ip:ip,port:port,id_rsa:id_rsa,db_user:db_user}; myPost('add_slave_ssh', data, function(data){ layer.close(index); var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ if (rdata.status){ getSlaveSSHPage(); } },{icon: rdata.status ? 1 : 2},600); }); } }); }); } function delSlaveSSH(ip){ myPost('del_slave_ssh', {ip:ip}, function(rdata){ var rdata = $.parseJSON(rdata.data); layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); getSlaveSSHPage(); }); } function getSlaveSSHPage(page=1){ var _data = {}; _data['page'] = page; _data['page_size'] = 5; _data['tojs'] ='getSlaveSSHPage'; myPost('get_slave_ssh_list', _data, function(data){ var layerId = null; var rdata = []; try { rdata = $.parseJSON(data.data); } catch(e) { console.log(e); } var list = ''; var ssh_list = rdata['data']; for (i in ssh_list) { var ip = ssh_list[i]['ip']; var port = ssh_list[i]['port']; var id_rsa = '未设置'; if ( ssh_list[i]['port'] != ''){ id_rsa = '已设置'; } var db_user = '未设置'; if ( ssh_list[i]['db_user'] != ''){ db_user = ssh_list[i]['db_user']; } list += ''+ip+'\ '+port+'\ '+db_user+'\ '+id_rsa+'\ \ 修改 | \ 删除\ \ '; } $('.get-slave-ssh-list tbody').html(list); $('.dataTables_paginate_4').html(rdata['page']); }); } function getSlaveSSHList(page=1){ var page = '
'; page += '
添加SSH
'; layerId = layer.open({ type: 1, title: 'SSH列表', area: '500px', content:"
\
\
\ \ \
IPPORT同步账户SSH操作
\ "+page +"\
\
", success:function(){ getSlaveSSHPage(1); } }); } function handlerRun(){ myPostN('get_slave_sync_cmd', {}, function(data){ var rdata = $.parseJSON(data.data); var cmd = rdata['data']; var loadOpen = layer.open({ type: 1, title: '手动执行', area: '500px', content:"
\
"+cmd+"
\
\ \
\
", }); copyPass(cmd); $('.class-copy-cmd').click(function(){ copyPass(cmd); }); }); } function initSlaveStatus(){ myPost('init_slave_status', '', function(data){ var rdata = $.parseJSON(data.data); showMsg(rdata.msg,function(){ if (rdata.status){ masterOrSlaveConf(); } },{icon:rdata.status?1:2},2000); }); } function masterOrSlaveConf(version=''){ function getMasterDbList(){ var _data = {}; if (typeof(page) =='undefined'){ var page = 1; } _data['page'] = page; _data['page_size'] = 10; myPost('get_masterdb_list', _data, function(data){ var rdata = $.parseJSON(data.data); var list = ''; for(i in rdata.data){ list += ''; list += '' + rdata.data[i]['name'] +''; list += '' + (rdata.data[i]['master']?'是':'否') +''; list += '' + ''+(rdata.data[i]['master']?'退出':'加入')+' | ' + '同步命令' + ''; list += ''; } var con = '
\
\ \ \ \ \ \ \ '+ list +'\
数据库名同步操作
\
\
\
\ 同步账户列表\
\
'; $(".table_master_list").html(con); $('#databasePage').html(rdata.page); }); } function getAsyncMasterDbList(){ var _data = {}; if (typeof(page) =='undefined'){ var page = 1; } _data['page'] = page; _data['page_size'] = 10; myPost('get_slave_list', _data, function(data){ var rdata = $.parseJSON(data.data); var list = ''; for(i in rdata.data){ var v = rdata.data[i]; var status = "异常"; if (v['Slave_SQL_Running'] == 'Yes' && v['Slave_IO_Running'] == 'Yes'){ status = "正常"; } list += ''; list += '' + rdata.data[i]['Master_Host'] +''; list += '' + rdata.data[i]['Master_Port'] +''; list += '' + rdata.data[i]['Master_User'] +''; list += '' + rdata.data[i]['Master_Log_File'] +''; list += '' + rdata.data[i]['Slave_IO_Running'] +''; list += '' + rdata.data[i]['Slave_SQL_Running'] +''; list += '' + status +''; list += '' + '删除' + ''; list += ''; } var con = '
\
\ \ \ \ \ \ \ \ \ \ \ \ '+ list +'\
主[服务]端口用户日志IOSQL状态操作
\
\
'; //
\ //
\ // 添加\ //
$(".table_slave_status_list").html(con); }); } function getAsyncDataList(){ var _data = {}; if (typeof(page) =='undefined'){ var page = 1; } _data['page'] = page; _data['page_size'] = 10; myPost('get_masterdb_list', _data, function(data){ var rdata = $.parseJSON(data.data); var list = ''; for(i in rdata.data){ list += ''; list += '' + rdata.data[i]['name'] +''; list += '' + ''+(rdata.data[i]['slave']?'退出':'加入')+' | ' + '同步' + ''; list += ''; } var con = '
\
\ \ \ \ \ \ '+ list +'\
本地库名操作
\
\
\
\ 手动命令\ 全量同步\
\
'; $(".table_slave_list").html(con); $('#databasePage').html(rdata.page); }); } function getMasterStatus(){ myPost('get_master_status', '', function(data){ var rdata = $.parseJSON(data.data); // console.log('mode:',rdata.data); var rdata = rdata.data; var limitCon = '\

\ 主从同步模式\ \ \

\
\

\ Master[主]配置\ \

\
\ \
\
\ \

\ Slave[从]配置\ \ \ \

\
\ \
\ \
\ '; $(".soft-man-con").html(limitCon); //设置主服务器配置 $(".btn-master").click(function () { myPost('set_master_status', 'close=change', function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); setTimeout(function(){ getMasterStatus(); }, 3000); }); }); $(".btn-slave").click(function () { myPost('set_slave_status', 'close=change', function(data){ var rdata = $.parseJSON(data.data); layer.msg(rdata.msg, { icon: rdata.status ? 1 : 5 }); setTimeout(function(){ getMasterStatus(); }, 3000); }); }); $('.db-mode').click(function(){ if ($(this).hasClass('btn-success')){ //no action return; } var mode = 'classic'; if ($(this).hasClass('btn-gtid')){ mode = 'gtid'; } layer.open({ type:1, title:"MySQL主从模式切换", shadeClose:false, btnAlign: 'c', btn: ['切换并重启', '切换不重启'], yes: function(index, layero){ this.change(index,mode,"yes"); }, btn2: function(index, layero){ this.change(index,mode,"no"); return false; }, change:function(index,mode,reload){ console.log(index,mode,reload); myPost('set_dbrun_mode',{'mode':mode,'reload':reload},function(data){ layer.close(index); var rdata = $.parseJSON(data.data); showMsg(rdata.msg ,function(){ getMasterStatus(); },{ icon: rdata.status ? 1 : 5 }); }); } }); }); if (rdata.status){ getMasterDbList(); } if (rdata.slave_status){ getAsyncMasterDbList(); getAsyncDataList() } }); } getMasterStatus(); }