pull/109/head
Mr Chen 6 years ago
parent f9440291b3
commit db33070f64
  1. 4
      plugins/rsyncd/conf/rsyncd.conf
  2. 1
      plugins/rsyncd/index.html
  3. 132
      plugins/rsyncd/index.py
  4. 36
      plugins/rsyncd/js/rsyncd.js

@ -4,4 +4,6 @@ use chroot = no
max connections = 100
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
list = false
list = false
hosts allow = *
secrets file = /etc/rsyncd.secrets

@ -4,6 +4,7 @@
<p class="bgw" onclick="pluginService('rsyncd');">服务</p>
<p onclick="pluginInitD('rsyncd');">自启动</p>
<p onclick="pluginConfig('rsyncd');">配置修改</p>
<p onclick="pluginConfig('rsyncd','','conf_pwd');">密钥配置</p>
<p onclick="rsyncdReceive();">接收配置</p>
<p onclick="pluginLogs('rsyncd','','run_log');">日志</p>
<p onclick="rsRead()">说明</p>

@ -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' + "<br>"
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'

@ -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 += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
@ -57,15 +57,14 @@ function rsyncdReceive(){
con += '<tbody>';
//<a class="btlink" onclick="modReceive(\''+list[i]['name']+'\')">编辑</a>
for (var i = 0; i < list.length; i++) {
con += '<tr>'+
'<td>' + list[i]['name']+'</td>' +
'<td>' + list[i]['path']+'</td>' +
'<td>' + list[i]['comment']+'</td>' +
'<td>\
<a class="btlink" onclick="modReceive(\''+list[i]['name']+'\')">密钥</a>\
| <a class="btlink" onclick="modReceive(\''+list[i]['name']+'\')">编辑</a>\
| <a class="btlink" onclick="cmdReceive(\''+list[i]['name']+'\')">命令</a>\
<a class="btlink" onclick="cmdReceive(\''+list[i]['name']+'\')">命令</a>\
| <a class="btlink" onclick="delReceive(\''+list[i]['name']+'\')">删除</a></td>\
</tr>';
}
@ -89,6 +88,13 @@ function addReceive(){
<input id='name' class='bt-input-text' type='text' name='name' placeholder='项目名' style='width:200px' />\
</div>\
</div>\
<div class='line'>\
<span class='tname'>密钥</span>\
<div class='info-r c4'>\
<input id='MyPassword' class='bt-input-text' type='text' name='pwd' placeholder='密钥' style='width:200px' />\
<span title='随机密码' class='glyphicon glyphicon-repeat cursor' onclick='repeatPwd(16)'></span>\
</div>\
</div>\
<div class='line'>\
<span class='tname'>同步到</span>\
<div class='info-r c4'>\
@ -105,12 +111,16 @@ function addReceive(){
<div class='bt-form-submit-btn'>\
<button type='button' id='add_ok' class='btn btn-success btn-sm btn-title bi-btn'>确认</button>\
</div>\
</div>"
</div>",
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:"<div class='bt-form pd20 pb70 c6'>"+rdata.data+"</div>"
});
});
}
function rsRead(){
var readme = '<ul class="help-info-text c7">';
readme += '<li>如需将其他服务器数据同步到本地服务器,请在接受配置中 "创建接受任务" </li>';
readme += '<li>如需将其他服务器数据同步到本地服务器,请在接受配置中 "创建接任务" </li>';
readme += '</ul>';
$('.soft-man-con').html(readme);

Loading…
Cancel
Save