From db33070f647efb30c30a2d30bedac37ce2949734 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Wed, 6 Mar 2019 20:31:29 +0800 Subject: [PATCH] update --- plugins/rsyncd/conf/rsyncd.conf | 4 +- plugins/rsyncd/index.html | 1 + plugins/rsyncd/index.py | 132 ++++++++++++++++++++++---------- plugins/rsyncd/js/rsyncd.js | 36 +++++++-- 4 files changed, 124 insertions(+), 49 deletions(-) diff --git a/plugins/rsyncd/conf/rsyncd.conf b/plugins/rsyncd/conf/rsyncd.conf index e8c386149..3517ccc1c 100644 --- a/plugins/rsyncd/conf/rsyncd.conf +++ b/plugins/rsyncd/conf/rsyncd.conf @@ -4,4 +4,6 @@ use chroot = no max connections = 100 log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid -list = false \ No newline at end of file +list = false +hosts allow = * +secrets file = /etc/rsyncd.secrets \ No newline at end of file diff --git a/plugins/rsyncd/index.html b/plugins/rsyncd/index.html index 8c97902cb..be8c4a452 100755 --- a/plugins/rsyncd/index.html +++ b/plugins/rsyncd/index.html @@ -4,6 +4,7 @@

服务

自启动

配置修改

+

密钥配置

接收配置

日志

说明

diff --git a/plugins/rsyncd/index.py b/plugins/rsyncd/index.py index ef665c4bc..6cdf445bb 100755 --- a/plugins/rsyncd/index.py +++ b/plugins/rsyncd/index.py @@ -71,6 +71,12 @@ def appConf(): return '/etc/rsyncd.conf' +def appConfPwd(): + if public.isAppleSystem(): + return getServerDir() + '/rsyncd.passwd' + return '/etc/rsyncd.passwd' + + def getLog(): conf_path = appConf() conf = public.readFile(conf_path) @@ -89,6 +95,10 @@ def initConf(): if conf.strip() == '': content = public.readFile(conf_tpl_path) public.writeFile(conf_path, content) + confpwd_path = appConfPwd() + if not os.path.exists(confpwd_path): + public.writeFile(confpwd_path, '') + public.execShell('chmod 0600 ' + confpwd_path) def start(): @@ -104,7 +114,6 @@ def start(): def stop(): - initConf() if public.isAppleSystem(): return "Apple Computer does not support" data = public.execShell('systemctl stop rsyncd.service') @@ -114,7 +123,6 @@ def stop(): def restart(): - initConf() if public.isAppleSystem(): return "Apple Computer does not support" data = public.execShell('systemctl restart rsyncd.service') @@ -124,7 +132,6 @@ def restart(): def reload(): - initConf() if public.isAppleSystem(): return "Apple Computer does not support" @@ -137,8 +144,9 @@ def reload(): def initdStatus(): if public.isAppleSystem(): return "Apple Computer does not support" - initd_bin = getInitDFile() - if os.path.exists(initd_bin): + + data = public.execShell('systemctl status rsyncd.service | grep enabled') + if data[1] == '': return 'ok' return 'fail' @@ -146,21 +154,19 @@ def initdStatus(): def initdInstall(): if public.isAppleSystem(): return "Apple Computer does not support" - - source_bin = initDreplace() - initd_bin = getInitDFile() - shutil.copyfile(source_bin, initd_bin) - public.execShell('chmod +x ' + initd_bin) - return 'ok' + data = public.execShell('systemctl enable rsyncd.service') + if data[1] == '': + return 'ok' + return 'fail' def initdUinstall(): if public.isAppleSystem(): return "Apple Computer does not support" - - initd_bin = getInitDFile() - os.remove(initd_bin) - return 'ok' + data = public.execShell('systemctl disable rsyncd.service') + if data[1] == '': + return 'ok' + return 'fail' def getRecListData(): @@ -196,23 +202,41 @@ def getRecList(): return public.returnJson(True, 'ok', ret_list) +def getUPwdList(): + pwd_path = appConfPwd() + pwd_content = public.readFile(pwd_path) + plist = pwd_content.strip().split('\n') + plist_len = len(plist) + data = {} + for x in range(plist_len): + tmp = plist[x].split(':') + data[tmp[0]] = tmp[1] + return data + + def addRec(): args = getArgs() - - data = checkArgs(args, ['name', 'path', 'ps']) + data = checkArgs(args, ['name', 'path', 'pwd', 'ps']) if not data[0]: return data[1] args_name = args['name'] + args_pwd = args['pwd'] args_path = args['path'] args_ps = args['ps'] + pwd_path = appConfPwd() + pwd_content = public.readFile(pwd_path) + pwd_content += args_name + ':' + args_pwd + "\n" + public.writeFile(pwd_path, pwd_content) + path = appConf() content = public.readFile(path) con = "\n\n" + '[' + args_name + ']' + "\n" con += 'path = ' + args_path + "\n" con += 'comment = ' + args_ps + "\n" + con += 'auth users = ' + args_name + "\n" con += 'read only = false' content = content + con @@ -222,39 +246,59 @@ def addRec(): def delRec(): args = getArgs() - data = checkArgs(args, ['name']) if not data[0]: return data[1] - args_name = args['name'] - path = appConf() - content = public.readFile(path) + cmd = "sed -i '_bak' '/" + args_name + "/d' " + appConfPwd() + public.execShell(cmd) + + try: + + path = appConf() + content = public.readFile(path) + + ret_list = getRecListData() + ret_list_len = len(ret_list) + is_end = False + next_name = '' + for x in range(ret_list_len): + tmp = ret_list[x] + if tmp['name'] == args_name: + if x + 1 == ret_list_len: + is_end = True + else: + next_name = ret_list[x + 1]['name'] + reg = '' + if is_end: + reg = '\[' + args_name + '\]\s*(.*)' + else: + reg = '\[' + args_name + '\]\s*(.*)\s*\[' + next_name + '\]' - ret_list = getRecListData() - ret_list_len = len(ret_list) - is_end = False - next_name = '' - for x in range(ret_list_len): - tmp = ret_list[x] - if tmp['name'] == args_name: - if x == ret_list_len: - is_end = True - else: - next_name = ret_list[x + 1]['name'] - - reg = '' - if is_end: - reg = '\[' + args_name + '\]\s*(.*)' - else: - reg = '\[' + args_name + '\]\s*(.*)\s*\[' + next_name + '\]' + conre = re.search(reg, content, re.S) + content = content.replace( + "[" + args_name + "]\n" + conre.groups()[0], '') + public.writeFile(path, content) + return public.returnJson(True, '删除成功!') + except Exception as e: + return public.returnJson(False, '删除失败!') - conre = re.search(reg, content, re.S) - content = content.replace("[" + args_name + "]\n" + conre.groups()[0], '') - public.writeFile(path, content) - return public.returnJson(True, '删除成功!') +def cmdRec(): + args = getArgs() + data = checkArgs(args, ['name']) + if not data[0]: + return data[1] + + an = args['name'] + pwd_list = getUPwdList() + ip = public.getLocalIp() + + cmd = 'echo "' + pwd_list[an] + '" > /tmp/p.pass' + "
" + cmd += 'rsync -arv --password-file=/tmp/p.pass --progress --delete /project ' + \ + an + '@' + ip + '::' + an + return public.returnJson(True, 'OK!', cmd) # rsyncdReceive if __name__ == "__main__": @@ -277,6 +321,8 @@ if __name__ == "__main__": print initdUinstall() elif func == 'conf': print appConf() + elif func == 'conf_pwd': + print appConfPwd() elif func == 'run_log': print getLog() elif func == 'rec_list': @@ -285,5 +331,7 @@ if __name__ == "__main__": print addRec() elif func == 'del_rec': print delRec() + elif func == 'cmd_rec': + print cmdRec() else: print 'error' diff --git a/plugins/rsyncd/js/rsyncd.js b/plugins/rsyncd/js/rsyncd.js index 92a0bb9cd..32b26d577 100755 --- a/plugins/rsyncd/js/rsyncd.js +++ b/plugins/rsyncd/js/rsyncd.js @@ -44,7 +44,7 @@ function rsyncdReceive(){ layer.msg(rdata.msg,{icon:rdata.status?1:2,time:2000,shade: [0.3, '#000']}); return; } - console.log(rdata); + // console.log(rdata); var list = rdata.data; var con = ''; con += '
'; @@ -57,15 +57,14 @@ function rsyncdReceive(){ con += ''; + //编辑 for (var i = 0; i < list.length; i++) { con += ''+ '' + '' + '' + '\ '; } @@ -89,6 +88,13 @@ function addReceive(){ \ \ \ +
\ + 密钥\ +
\ + \ + \ +
\ +
\
\ 同步到\
\ @@ -105,12 +111,16 @@ function addReceive(){
\ \
\ -
" +
", + success:function(layero, index){ + repeatPwd(16); + } }); $('#add_ok').click(function(){ _data = {}; _data['name'] = $('#name').val(); + _data['pwd'] = $('#MyPassword').val(); _data['path'] = $('#inputPath').val(); _data['ps'] = $('#ps').val(); var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); @@ -136,10 +146,24 @@ function delReceive(name){ }); } +function cmdReceive(name){ + var _data = {}; + _data['name'] = name; + rsPost('cmd_rec', _data, function(data){ + var rdata = $.parseJSON(data.data); + layer.open({ + type: 1, + title: '命令事例', + area: '400px', + content:"
"+rdata.data+"
" + }); + }); +} + function rsRead(){ var readme = ''; $('.soft-man-con').html(readme);
' + list[i]['name']+'' + list[i]['path']+'' + list[i]['comment']+'\ - 密钥\ - | 编辑\ - | 命令\ + 命令\ | 删除