From 5dc97276c1a94640aee9b1346afb1d515e60ceac Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 16 Nov 2023 19:16:14 +0800 Subject: [PATCH] =?UTF-8?q?keepalived=20=E8=84=9A=E6=9C=AC=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/keepalived/index.html | 2 +- plugins/keepalived/index.py | 18 +++-- route/static/app/public.js | 119 ++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 7 deletions(-) diff --git a/plugins/keepalived/index.html b/plugins/keepalived/index.html index 3743d47af..8634d5ca0 100755 --- a/plugins/keepalived/index.html +++ b/plugins/keepalived/index.html @@ -6,7 +6,7 @@

自启动

配置修改

-

脚本模板

+

脚本模板

diff --git a/plugins/keepalived/index.py b/plugins/keepalived/index.py index 3c17abe97..d1d3a2d24 100755 --- a/plugins/keepalived/index.py +++ b/plugins/keepalived/index.py @@ -144,12 +144,18 @@ def copyScripts(): src_scripts_path = getPluginDir() + '/scripts' dst_scripts_path = getServerDir() + '/scripts' if not os.path.exists(dst_scripts_path): - cmd = 'cp -rf ' +src_scripts_path+' '+dst_scripts_path - t = mw.execShell(cmd) - acl_cmd = 'chmod +x '+dst_scripts_path+'/*.sh' - # print(acl_cmd) - mw.execShell(acl_cmd) - # print(t) + mw.execShell('mkdir -p ' + dst_scripts_path) + olist = os.listdir(src_scripts_path) + for o in range(len(olist)): + src_file = src_scripts_path+'/'+olist[o] + dst_file = dst_scripts_path+'/'+olist[o] + + content = mw.readFile(src_file) + content = contentReplace(content) + mw.writeFile(dst_file, content) + + cmd = 'chmod +x ' + dst_file + mw.execShell(cmd) return True return False diff --git a/route/static/app/public.js b/route/static/app/public.js index 5e272d260..35c2ab71c 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -2356,6 +2356,125 @@ function pluginConfigTpl(_name, version, func, config_tpl_func, read_config_tpl_ },'json'); } +//配置模版列表 --- start +function pluginConfigListTpl(_name, version, config_tpl_func, read_config_tpl_func){ + if ( typeof(version) == 'undefined' ){ + version = ''; + } + + var _config_tpl_func = 'config_tpl'; + if ( typeof(config_tpl_func) != 'undefined' ){ + _config_tpl_func = config_tpl_func; + } + + var _read_config_tpl_func = 'read_config_tpl'; + if ( typeof(read_config_tpl_func) != 'undefined' ){ + _read_config_tpl_func = read_config_tpl_func; + } + + + var con = '

提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!

\ + \ + \ + \ + '; + $(".soft-man-con").html(con); + + function getFileName(file){ + var list = file.split('/'); + var f = list[list.length-1]; + return f + } + + function loadTextBody(fileName){ + $.post('/files/get_body', 'path=' + fileName, function(rdata) { + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + $("#textBody").empty().text(rdata.data.data); + $(".CodeMirror").remove(); + var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { + extraKeys: { + "Ctrl-Space": "autocomplete", + "Ctrl-F": "findPersistent", + "Ctrl-H": "replaceAll", + "Ctrl-S": function() { + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + } + }, + lineNumbers: true, + matchBrackets:true, + }); + editor.focus(); + $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); + $("#onlineEditFileBtn").click(function(){ + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + }); + },'json'); + } + + + + var fileName = ''; + $.post('/plugins/run',{name:_name, func:_config_tpl_func,version:version}, function(data){ + var rdata = $.parseJSON(data.data); + for (var i = 0; i < rdata.length; i++) { + $('#config_tpl').append(''); + } + + if (rdata.length>0){ + loadTextBody(rdata[0]); + } + + $('#config_tpl').change(function(){ + var selected = $(this).val(); + fileName = selected; + + var loadT = layer.msg('配置模版获取中...',{icon:16,time:0,shade: [0.3, '#000']}); + + var _args = JSON.stringify({file:selected}); + $.post('/plugins/run', {name:_name, func:_read_config_tpl_func,version:version,args:_args}, function(data){ + layer.close(loadT); + var rdata = $.parseJSON(data.data); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + $("#textBody").empty().text(rdata.data); + $(".CodeMirror").remove(); + var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { + extraKeys: { + "Ctrl-Space": "autocomplete", + "Ctrl-F": "findPersistent", + "Ctrl-H": "replaceAll", + "Ctrl-S": function() { + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + } + }, + lineNumbers: true, + matchBrackets:true, + }); + editor.focus(); + $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); + $("#onlineEditFileBtn").unbind('click'); + $("#onlineEditFileBtn").click(function(){ + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + }); + },'json'); + + }); + + },'json'); +} + //配置保存 function pluginConfigSave(fileName) {