pull/143/head
midoks 3 years ago
parent 13925f7d7f
commit fe0dda838d
  1. 60
      plugins/rsyncd/index.html
  2. 99
      plugins/rsyncd/index.py
  3. 105
      plugins/rsyncd/js/rsyncd.js

@ -6,6 +6,66 @@
display: inline-block;
vertical-align: middle;
}
.lsyncd_exclude label {
font-weight: normal;
margin-right: 20px
}
.lsyncd_exclude button {
vertical-align: 0
}
.lsyncd_exclude {
overflow: hidden;
margin: 15px;
}
.lsyncd_exclude span {
margin-right: 5px
}
.lsyncd_exclude fieldset {
border: 1px solid #ccc;
border-radius: 3px;
float: left;
padding-bottom: 0;
/* width: 240px; */
}
.wafConf fieldset:nth-of-type(2) {
margin: 0 10px
}
.lsyncd_exclude legend {
border: 0 none;
font-size: 14px;
margin: 0 6px;
padding: 3px;
width: auto
}
.lsyncd_exclude fieldset input {
margin-left: 4px
}
.lsyncd_exclude fieldset .table {
margin-top: -1px;
margin-bottom: 0
}
.lsyncd_exclude fieldset .table tr td:nth-of-type(2) {
width: 42px
}
.lsyncd_exclude fieldset .table-overflow {
height: 210px;
overflow: auto;
margin-top: 10px;
border-top: #ddd 1px solid
}
</style>
<div class="bt-form">
<div class="bt-w-main">

@ -525,7 +525,10 @@ def makeLsyncdConf(data):
mw.execShell("mkdir -p " + name_dir)
cmd_exclude = name_dir + "/exclude"
mw.writeFile(cmd_exclude, "")
cmd_exclude_txt = ""
for x in t['exclude']:
cmd_exclude_txt += x + "\n"
mw.writeFile(cmd_exclude, cmd_exclude_txt)
cmd_pass = name_dir + "/pass"
mw.writeFile(cmd_pass, t['password'])
mw.execShell("chmod 600 " + cmd_pass)
@ -545,6 +548,12 @@ def makeLsyncdConf(data):
content += "\tdelay = " + t['delay'] + ",\n"
content += "\tinit = false,\n"
exclude_str = json.dumps(t['exclude'])
exclude_str = exclude_str.replace("[", "{")
exclude_str = exclude_str.replace("]", "}")
# print(exclude_str)
content += "\texclude = " + exclude_str + ",\n"
# rsync
content += "\trsync{\n"
content += "\t\tbinary = \"" + rsync_bin + "\",\n"
@ -707,6 +716,14 @@ def lsyncdAdd():
info['rsync'] = rsync
if not 'exclude' in info:
info["exclude"] = [
"/**.upload.tmp",
"**/*.log",
"**/*.tmp",
"**/*.temp"
]
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, info['name'])
@ -714,12 +731,6 @@ def lsyncdAdd():
list_index = res[1]
slist[list_index] = info
else:
info["exclude"] = [
"/**.upload.tmp",
"**/*.log",
"**/*.tmp",
"**/*.temp"
]
slist.append(info)
data['send']["list"] = slist
@ -739,7 +750,7 @@ def lsyncdRun():
name = args['name']
app_dir = send_dir + "/" + name
cmd = "bash " + app_dir + "/cmd >> " + app_dir + "/run.log" + " 2>&1"
cmd = "bash " + app_dir + "/cmd >> " + app_dir + "/run.log" + " 2>&1 &"
mw.execShell(cmd)
return mw.returnJson(True, "执行成功!")
@ -755,6 +766,72 @@ def lsyncdLog():
app_dir = send_dir + "/" + name
return app_dir + "/run.log"
def lsyncdGetExclude():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, args['name'])
i = res[1]
info = slist[i]
return mw.returnJson(True, "OK!", info['exclude'])
def lsyncdRemoveExclude():
args = getArgs()
data = checkArgs(args, ['name', 'exclude'])
if not data[0]:
return data[1]
exclude = args['exclude']
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, args['name'])
i = res[1]
info = slist[i]
exclude_list = info['exclude']
exclude_pop_key = -1
for x in range(len(exclude_list)):
if exclude_list[x] == exclude:
exclude_pop_key = x
if exclude_pop_key > -1:
exclude_list.pop(exclude_pop_key)
data['send']["list"][i]['exclude'] = exclude_list
setDefaultConf(data)
makeLsyncdConf(data)
return mw.returnJson(True, "OK!", exclude_list)
def lsyncdAddExclude():
args = getArgs()
data = checkArgs(args, ['name', 'exclude'])
if not data[0]:
return data[1]
exclude = args['exclude']
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, args['name'])
i = res[1]
info = slist[i]
exclude_list = info['exclude']
exclude_list.append(exclude)
data['send']["list"][i]['exclude'] = exclude_list
setDefaultConf(data)
makeLsyncdConf(data)
return mw.returnJson(True, "OK!", exclude_list)
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
@ -801,5 +878,11 @@ if __name__ == "__main__":
print(lsyncdRun())
elif func == 'lsyncd_log':
print(lsyncdLog())
elif func == 'lsyncd_get_exclude':
print(lsyncdGetExclude())
elif func == 'lsyncd_remove_exclude':
print(lsyncdRemoveExclude())
elif func == 'lsyncd_add_exclude':
print(lsyncdAddExclude())
else:
print('error')

@ -377,6 +377,111 @@ function lsyncdLog(name){
pluginStandAloneLogs("rsyncd", '', "lsyncd_log", JSON.stringify(args));
}
function lsyncdExclude(name){
layer.open({
type:1,
title:'过滤器',
area: '400px',
shadeClose:false,
closeBtn:2,
content:'<div class="lsyncd_exclude">\
<div style="overflow:hidden;">\
<fieldset>\
<legend>排除的文件和目录</legend>\
<input type="text" class="bt-input-text mr5" data-type="exclude" title="例如:/home/www/" placeholder="例如:*.log" style="width:305px;">\
<button data-type="exclude" class=" addList btn btn-default btn-sm">添加</button>\
<div class="table-overflow">\
<table class="table table-hover BlockList"><tbody></tbody></table>\
</div>\
</fieldset>\
</div>\
<div>\
<ul class="help-info-text c7" style="list-style-type:decimal;">\
<li>排除的文件和目录是指当前目录下不需要同步的目录或者文件</li>\
<li>如果规则以斜线 <code>/</code></li>\
<li>如果规则以 <code>/</code></li>\
<li><code>?</code> 匹配任何字符,但不包括<code>/</code></li>\
<li><code>*</code> 匹配0或多个字符,但不包括<code>/</code></li>\
<li><code>**</code> 匹配0或多个字符,可以是<code>/</code></li>\
</ul>\
</div>\
</div>'
});
function getIncludeExclude(mName){
loadT = layer.msg('正在获取数据...',{icon:16,time:0,shade: [0.3, '#000']});
rsPost('lsyncd_get_exclude',{"name":mName}, function(rdata) {
layer.close(loadT);
var rdata = $.parseJSON(rdata.data);
var res = rdata.data;
var list=''
for (var i = 0; i < res.length; i++) {
list += '<tr><td>'+ res[i] +'</td><td><a href="javascript:;" data-type='+ mName +' class="delList">删除</a></td></tr>';
}
$('.lsyncd_exclude .BlockList tbody').empty().append(list);
});
}
getIncludeExclude(name);
function addArgs(name,exclude){
loadT = layer.msg('正在添加...',{icon:16,time:0,shade: [0.3, '#000']});
rsPost('lsyncd_add_exclude', {name:name,exclude:exclude}, function(res){
layer.close(loadT);
console.log('addArgs:',res);
if (res.status){
getIncludeExclude(name);
$('.lsyncd_exclude input').val('');
layer.msg(res.msg);
}else{
layer.msg(res.msg);
}
});
}
$('.addList').click(function(event) {
var val = $(this).prev().val();
if(val == ''){
layer.msg('当前输入内容为空,请输入');
return false;
}
addArgs(name,val);
});
$('.lsyncd_exclude input').keyup(function(event){
if (event.which == 13){
var val = $(this).val();
if(val == ''){
layer.msg('当前输入内容为空,请输入');
return false;
}
addArgs(name,val);
}
});
$('.lsyncd_exclude').on('click', '.delList', function(event) {
loadT = layer.msg('正在删除...',{icon:16,time:0,shade: [0.3, '#000']});
var val = $(this).parent().prev().text();
rsPost('lsyncd_remove_exclude',{"name":name,exclude:val}, function(rdata) {
layer.close(loadT);
console.log(rdata)
var rdata = $.parseJSON(rdata.data);
var res = rdata.data;
var list=''
for (var i = 0; i < res.length; i++) {
list += '<tr><td>'+ res[i] +'</td><td><a href="javascript:;" data-type='+ name +' class="delList">删除</a></td></tr>';
}
$('.lsyncd_exclude .BlockList tbody').empty().append(list);
});
});
}
function lsyncdSend(){
rsPost('lsyncd_list', '', function(data){
var rdata = $.parseJSON(data.data);

Loading…
Cancel
Save