Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/plugins/rsyncd/index.py

965 lines
25 KiB

6 years ago
# coding: utf-8
import time
import random
import os
import json
import re
import sys
sys.path.append(os.getcwd() + "/class/core")
import mw
6 years ago
app_debug = False
if mw.isAppleSystem():
6 years ago
app_debug = True
def getPluginName():
return 'rsyncd'
6 years ago
def getInitDTpl():
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path
6 years ago
def getPluginDir():
return mw.getPluginDir() + '/' + getPluginName()
6 years ago
def getServerDir():
return mw.getServerDir() + '/' + getPluginName()
6 years ago
def getInitDFile():
if app_debug:
return '/tmp/' + getPluginName()
return '/etc/init.d/' + getPluginName()
def getArgs():
args = sys.argv[2:]
tmp = {}
args_len = len(args)
if args_len == 1:
t = args[0].strip('{').strip('}')
t = t.split(':')
tmp[t[0]] = t[1]
elif args_len > 1:
for i in range(len(args)):
t = args[i].split(':')
tmp[t[0]] = t[1]
return tmp
def checkArgs(data, ck=[]):
for i in range(len(ck)):
if not ck[i] in data:
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
return (True, mw.returnJson(True, 'ok'))
6 years ago
6 years ago
def contentReplace(content):
service_path = mw.getServerDir()
6 years ago
content = content.replace('{$SERVER_PATH}', service_path)
return content
6 years ago
def status():
data = mw.execShell(
6 years ago
"ps -ef|grep rsync |grep -v grep | grep -v python | awk '{print $2}'")
6 years ago
if data[0] == '':
return 'stop'
3 years ago
3 years ago
# data = mw.execShell(
# "ps -ef|grep lsyncd |grep -v grep | grep -v python | awk '{print $2}'")
# if data[0] == '':
# return 'stop'
3 years ago
6 years ago
return 'start'
6 years ago
def appConf():
3 years ago
return getServerDir() + '/rsyncd.conf'
6 years ago
3 years ago
def appAuthPwd(name):
3 years ago
nameDir = getServerDir() + '/receive/' + name
3 years ago
if not os.path.exists(nameDir):
mw.execShell("mkdir -p " + nameDir)
return nameDir + '/auth.db'
6 years ago
6 years ago
def getLog():
conf_path = appConf()
conf = mw.readFile(conf_path)
6 years ago
rep = 'log file\s*=\s*(.*)'
tmp = re.search(rep, conf)
if not tmp:
return ''
return tmp.groups()[0]
3 years ago
def getLsyncdLog():
path = getServerDir() + "/lsyncd.conf"
conf = mw.readFile(path)
rep = 'logfile\s*=\s*\"(.*)\"'
tmp = re.search(rep, conf)
if not tmp:
return ''
return tmp.groups()[0]
3 years ago
def __release_port(port):
try:
import firewall_api
firewall_api.firewall_api().addAcceptPortArgs(port, 'RSYNC同步', 'port')
return port
except Exception as e:
return "Release failed {}".format(e)
def openPort():
for i in ["873"]:
__release_port(i)
return True
3 years ago
def initDReceive():
3 years ago
# conf
conf_path = appConf()
6 years ago
conf_tpl_path = getPluginDir() + '/conf/rsyncd.conf'
3 years ago
if not os.path.exists(conf_path):
content = mw.readFile(conf_tpl_path)
mw.writeFile(conf_path, content)
3 years ago
6 years ago
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
6 years ago
3 years ago
file_bin = initD_path + '/' + getPluginName()
6 years ago
file_tpl = getInitDTpl()
3 years ago
# print(file_bin, file_tpl)
6 years ago
# initd replace
if not os.path.exists(file_bin):
content = mw.readFile(file_tpl)
6 years ago
content = contentReplace(content)
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
6 years ago
3 years ago
lock_file = getServerDir() + "/installed_rsyncd.pl"
# systemd
3 years ago
systemDir = mw.systemdCfgDir()
systemService = systemDir + '/rsyncd.service'
systemServiceTpl = getPluginDir() + '/init.d/rsyncd.service.tpl'
3 years ago
if not os.path.exists(lock_file):
3 years ago
rsync_bin = mw.execShell('which rsync')[0].strip()
3 years ago
if rsync_bin == '':
3 years ago
print('rsync missing!')
3 years ago
exit(0)
service_path = mw.getServerDir()
3 years ago
se = mw.readFile(systemServiceTpl)
se = se.replace('{$SERVER_PATH}', service_path)
se = se.replace('{$RSYNC_BIN}', rsync_bin)
mw.writeFile(systemService, se)
mw.execShell('systemctl daemon-reload')
6 years ago
3 years ago
mw.writeFile(lock_file, "ok")
3 years ago
openPort()
3 years ago
6 years ago
rlog = getLog()
6 years ago
if os.path.exists(rlog):
mw.writeFile(rlog, '')
6 years ago
return file_bin
6 years ago
6 years ago
3 years ago
def initDSend():
service_path = mw.getServerDir()
conf_path = getServerDir() + '/lsyncd.conf'
conf_tpl_path = getPluginDir() + '/conf/lsyncd.conf'
if not os.path.exists(conf_path):
content = mw.readFile(conf_tpl_path)
content = content.replace('{$SERVER_PATH}', service_path)
mw.writeFile(conf_path, content)
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
# initd replace
file_bin = initD_path + '/lsyncd'
file_tpl = getPluginDir() + "/init.d/lsyncd.tpl"
if not os.path.exists(file_bin):
content = mw.readFile(file_tpl)
content = contentReplace(content)
mw.writeFile(file_bin, content)
mw.execShell('chmod +x ' + file_bin)
3 years ago
lock_file = getServerDir() + "/installed.pl"
3 years ago
# systemd
systemDir = mw.systemdCfgDir()
systemService = systemDir + '/lsyncd.service'
systemServiceTpl = getPluginDir() + '/init.d/lsyncd.service.tpl'
3 years ago
if not os.path.exists(lock_file):
3 years ago
lsyncd_bin = mw.execShell('which lsyncd')[0].strip()
if lsyncd_bin == '':
print('lsyncd missing!')
exit(0)
content = mw.readFile(systemServiceTpl)
content = content.replace('{$SERVER_PATH}', service_path)
content = content.replace('{$LSYNCD_BIN}', lsyncd_bin)
mw.writeFile(systemService, content)
mw.execShell('systemctl daemon-reload')
3 years ago
mw.writeFile(lock_file, "ok")
3 years ago
3 years ago
lslog = getLsyncdLog()
if os.path.exists(lslog):
mw.writeFile(lslog, '')
return file_bin
3 years ago
def getDefaultConf():
path = getServerDir() + "/config.json"
data = mw.readFile(path)
data = json.loads(data)
return data
def setDefaultConf(data):
path = getServerDir() + "/config.json"
mw.writeFile(path, json.dumps(data))
return True
def initConfigJson():
path = getServerDir() + "/config.json"
tpl = getPluginDir() + "/conf/config.json"
if not os.path.exists(path):
data = mw.readFile(tpl)
data = json.loads(data)
mw.writeFile(path, json.dumps(data))
3 years ago
def initDreplace():
initDSend()
# conf
file_bin = initDReceive()
3 years ago
initConfigJson()
3 years ago
return file_bin
3 years ago
def rsyncOp(method):
6 years ago
file = initDreplace()
if not mw.isAppleSystem():
data = mw.execShell('systemctl ' + method + ' rsyncd')
if data[1] == '':
return 'ok'
return 'fail'
data = mw.execShell(file + ' ' + method)
6 years ago
if data[1] == '':
return 'ok'
return 'fail'
6 years ago
def start():
return rsyncOp('start')
6 years ago
def stop():
return rsyncOp('stop')
6 years ago
def restart():
return rsyncOp('restart')
6 years ago
def reload():
return rsyncOp('reload')
6 years ago
def initdStatus():
if mw.isAppleSystem():
return "Apple Computer does not support"
6 years ago
shell_cmd = 'systemctl status rsyncd | grep loaded | grep "enabled;"'
data = mw.execShell(shell_cmd)
if data[0] == '':
return 'fail'
3 years ago
shell_cmd = 'systemctl status lsyncd | grep loaded | grep "enabled;"'
data = mw.execShell(shell_cmd)
if data[0] == '':
return 'fail'
return 'ok'
6 years ago
6 years ago
6 years ago
def initdInstall():
if mw.isAppleSystem():
return "Apple Computer does not support"
6 years ago
3 years ago
mw.execShell('systemctl enable lsyncd')
mw.execShell('systemctl enable rsyncd')
6 years ago
return 'ok'
6 years ago
def initdUinstall():
6 years ago
if not app_debug:
if mw.isAppleSystem():
6 years ago
return "Apple Computer does not support"
3 years ago
mw.execShell('systemctl diable lsyncd')
mw.execShell('systemctl diable rsyncd')
6 years ago
return 'ok'
6 years ago
def getRecListData():
path = appConf()
content = mw.readFile(path)
flist = re.findall("\[(.*)\]", content)
3 years ago
flist_len = len(flist)
ret_list = []
for i in range(flist_len):
tmp = {}
tmp['name'] = flist[i]
n = i + 1
reg = ''
if n == flist_len:
reg = '\[' + flist[i] + '\](.*)\[?'
else:
reg = '\[' + flist[i] + '\](.*)\[' + flist[n] + '\]'
t1 = re.search(reg, content, re.S)
if t1:
args = t1.groups()[0]
3 years ago
# print('args start', args, 'args_end')
t2 = re.findall('\s*(.*)\s*\=\s*?(.*)?', args, re.M | re.I)
for i in range(len(t2)):
3 years ago
tmp[t2[i][0].strip()] = t2[i][1].strip()
ret_list.append(tmp)
3 years ago
return ret_list
3 years ago
def getRecListDataBy(name):
l = getRecListData()
for x in range(len(l)):
if name == l[x]["name"]:
return l[x]
def getRecList():
ret_list = getRecListData()
return mw.returnJson(True, 'ok', ret_list)
def addRec():
args = getArgs()
6 years ago
data = checkArgs(args, ['name', 'path', 'pwd', 'ps'])
if not data[0]:
return data[1]
args_name = args['name']
6 years ago
args_pwd = args['pwd']
args_path = args['path']
args_ps = args['ps']
if not mw.isAppleSystem():
2 years ago
os.system("mkdir -p " + args_path + " &")
os.system("chown -R www:www " + args_path + " &")
os.system("chmod -R 755 " + args_path + " &")
3 years ago
delRecBy(args_name)
3 years ago
auth_path = appAuthPwd(args_name)
pwd_content = args_name + ':' + args_pwd + "\n"
mw.writeFile(auth_path, pwd_content)
mw.execShell("chmod 600 " + auth_path)
6 years ago
path = appConf()
content = mw.readFile(path)
con = "\n\n" + '[' + args_name + ']' + "\n"
con += 'path = ' + args_path + "\n"
con += 'comment = ' + args_ps + "\n"
6 years ago
con += 'auth users = ' + args_name + "\n"
3 years ago
con += 'ignore errors' + "\n"
con += 'secrets file = ' + auth_path + "\n"
con += 'read only = false'
3 years ago
content = content.strip() + "\n" + con
mw.writeFile(path, content)
return mw.returnJson(True, '添加成功')
3 years ago
def getRec():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
3 years ago
name = args['name']
6 years ago
3 years ago
if name == "":
tmp = {}
tmp["name"] = ""
3 years ago
tmp["comment"] = ""
3 years ago
tmp["path"] = mw.getWwwDir()
tmp["pwd"] = mw.getRandomString(16)
return mw.returnJson(True, 'OK', tmp)
data = getRecListDataBy(name)
content = mw.readFile(data['secrets file'])
pwd = content.strip().split(":")
data['pwd'] = pwd[1]
return mw.returnJson(True, 'OK', data)
6 years ago
3 years ago
def delRecBy(name):
try:
6 years ago
path = appConf()
content = mw.readFile(path)
6 years ago
3 years ago
reclist = getRecListData()
ret_list_len = len(reclist)
6 years ago
is_end = False
next_name = ''
for x in range(ret_list_len):
3 years ago
tmp = reclist[x]
if tmp['name'] == name:
secrets_file = tmp['secrets file']
tp = os.path.dirname(secrets_file)
if os.path.exists(tp):
mw.execShell("rm -rf " + tp)
6 years ago
if x + 1 == ret_list_len:
is_end = True
else:
3 years ago
next_name = reclist[x + 1]['name']
6 years ago
reg = ''
if is_end:
3 years ago
reg = '\[' + name + '\]\s*(.*)'
6 years ago
else:
3 years ago
reg = '\[' + name + '\]\s*(.*)\s*\[' + next_name + '\]'
6 years ago
conre = re.search(reg, content, re.S)
content = content.replace(
3 years ago
"[" + name + "]\n" + conre.groups()[0], '')
mw.writeFile(path, content)
6 years ago
except Exception as e:
3 years ago
return False
return True
3 years ago
def delRec():
6 years ago
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
3 years ago
name = args['name']
ok = delRecBy(name)
if ok:
return mw.returnJson(True, '删除成功!')
return mw.returnJson(False, '删除失败!')
6 years ago
3 years ago
def cmdRecSecretKey():
import base64
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
name = args['name']
info = getRecListDataBy(name)
3 years ago
secrets_file = info['secrets file']
content = mw.readFile(info['secrets file'])
pwd = content.strip().split(":")
m = {"A": info['name'], "B": pwd[1], "C": "873"}
m = json.dumps(m)
3 years ago
m = m.encode("utf-8")
m = base64.b64encode(m)
cmd = m.decode("utf-8")
return mw.returnJson(True, 'OK!', cmd)
def cmdRecCmd():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
name = args['name']
info = getRecListDataBy(name)
ip = mw.getLocalIp()
6 years ago
3 years ago
content = mw.readFile(info['secrets file'])
pwd = content.strip().split(":")
tmp_name = '/tmp/' + name + '.pass'
cmd = 'echo "' + pwd[1] + '" > ' + tmp_name + '<br>'
cmd += 'chmod 600 ' + tmp_name + ' <br>'
cmd += 'rsync -arv --password-file=' + tmp_name + \
' --progress --delete /project ' + name + '@' + ip + '::' + name
return mw.returnJson(True, 'OK!', cmd)
3 years ago
# ----------------------------- rsyncdSend start -------------------------
3 years ago
def lsyncdReload():
3 years ago
data = mw.execShell(
"ps -ef|grep lsyncd |grep -v grep | grep -v python | awk '{print $2}'")
if data[0] == '':
mw.execShell('systemctl start lsyncd')
else:
mw.execShell('systemctl restart lsyncd')
3 years ago
3 years ago
def makeLsyncdConf(data):
# print(data)
lsyncd_data = data['send']
lsyncd_setting = lsyncd_data['default']
3 years ago
content = "settings {\n"
3 years ago
for x in lsyncd_setting:
v = lsyncd_setting[x]
# print(v, type(v))
if type(v) == str:
content += "\t" + x + ' = "' + v + "\",\n"
elif type(v) == int:
content += "\t" + x + ' = ' + str(v) + ",\n"
content += "}\n\n"
lsyncd_list = lsyncd_data['list']
rsync_bin = mw.execShell('which rsync')[0].strip()
send_dir = getServerDir() + "/send"
if len(lsyncd_list) > 0:
for x in range(len(lsyncd_list)):
3 years ago
3 years ago
t = lsyncd_list[x]
name_dir = send_dir + "/" + t["name"]
if not os.path.exists(name_dir):
mw.execShell("mkdir -p " + name_dir)
cmd_exclude = name_dir + "/exclude"
3 years ago
cmd_exclude_txt = ""
for x in t['exclude']:
cmd_exclude_txt += x + "\n"
mw.writeFile(cmd_exclude, cmd_exclude_txt)
3 years ago
cmd_pass = name_dir + "/pass"
mw.writeFile(cmd_pass, t['password'])
3 years ago
mw.execShell("chmod 600 " + cmd_pass)
3 years ago
3 years ago
delete_ok = ' '
if t['delete'] == "true":
delete_ok = ' --delete '
3 years ago
remote_addr = t['name'] + '@' + t['ip'] + "::" + t['name']
cmd = rsync_bin + " -avzP " + "--port=" + str(t['rsync']['port']) + " --bwlimit=" + t['rsync'][
3 years ago
'bwlimit'] + delete_ok + " --exclude-from=" + cmd_exclude + " --password-file=" + cmd_pass + " " + t["path"] + " " + remote_addr
3 years ago
mw.writeFile(name_dir + "/cmd", cmd)
mw.execShell("cmod +x " + name_dir + "/cmd")
3 years ago
if t['realtime'] == "false":
continue
3 years ago
# print(x, t)
content += "sync {\n"
content += "\tdefault.rsync,\n"
content += "\tsource = \"" + t['path'] + "\",\n"
content += "\ttarget = \"" + remote_addr + "\",\n"
content += "\tdelete = " + t['delete'] + ",\n"
content += "\tdelay = " + t['delay'] + ",\n"
content += "\tinit = false,\n"
3 years ago
exclude_str = json.dumps(t['exclude'])
exclude_str = exclude_str.replace("[", "{")
exclude_str = exclude_str.replace("]", "}")
# print(exclude_str)
content += "\texclude = " + exclude_str + ",\n"
3 years ago
# rsync
3 years ago
content += "\trsync = {\n"
3 years ago
content += "\t\tbinary = \"" + rsync_bin + "\",\n"
content += "\t\tarchive = true,\n"
content += "\t\tverbose = true,\n"
content += "\t\tcompress = " + t['rsync']['compress'] + ",\n"
3 years ago
content += "\t\tpassword_file = \"" + cmd_pass + "\",\n"
3 years ago
3 years ago
content += "\t\t_extra = {\"--bwlimit=" + t['rsync'][
3 years ago
'bwlimit'] + "\", \"--port=" + str(t['rsync']['port']) + "\"},\n"
3 years ago
content += "\t}\n"
content += "}\n"
path = getServerDir() + "/lsyncd.conf"
mw.writeFile(path, content)
3 years ago
lsyncdReload()
import tool_task
tool_task.createBgTask(lsyncd_list)
3 years ago
3 years ago
def lsyncdListFindIp(slist, ip):
for x in range(len(slist)):
if slist[x]["ip"] == ip:
return (True, x)
return (False, -1)
3 years ago
def lsyncdListFindName(slist, name):
for x in range(len(slist)):
if slist[x]["name"] == name:
return (True, x)
return (False, -1)
3 years ago
def lsyncdList():
data = getDefaultConf()
send = data['send']
return mw.returnJson(True, "设置成功!", send)
3 years ago
def lsyncdGet():
import base64
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
name = args['name']
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, name)
rsync = {
'bwlimit': "1024",
"compress": "true",
"archive": "true",
"verbose": "true"
}
info = {
"secret_key": '',
"ip": '',
3 years ago
"path": mw.getServerDir(),
3 years ago
'rsync': rsync,
'realtime': "true",
3 years ago
'delete': "false",
3 years ago
}
if res[0]:
list_index = res[1]
info = slist[list_index]
m = {"A": info['name'], "B": info["password"], "C": "873"}
m = json.dumps(m)
m = m.encode("utf-8")
m = base64.b64encode(m)
info['secret_key'] = m.decode("utf-8")
return mw.returnJson(True, "OK", info)
def lsyncdDelete():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
name = args['name']
data = getDefaultConf()
slist = data['send']["list"]
res = lsyncdListFindName(slist, name)
retdata = {}
if res[0]:
list_index = res[1]
slist.pop(list_index)
data['send']["list"] = slist
setDefaultConf(data)
3 years ago
makeLsyncdConf(data)
3 years ago
return mw.returnJson(True, "OK")
3 years ago
def lsyncdAdd():
3 years ago
import base64
3 years ago
args = getArgs()
2 years ago
data = checkArgs(args, ['ip', 'conn_type', 'path', 'delay', 'period'])
3 years ago
if not data[0]:
return data[1]
ip = args['ip']
path = args['path']
3 years ago
if not mw.isAppleSystem():
2 years ago
os.system("mkdir -p " + path + " &")
os.system("chown -R www:www " + path + " &")
os.system("chmod -R 755 " + path + " &")
3 years ago
conn_type = args['conn_type']
2 years ago
3 years ago
delete = args['delete']
realtime = args['realtime']
delay = args['delay']
bwlimit = args['bwlimit']
compress = args['compress']
period = args['period']
hour = args['hour']
minute = args['minute']
minute_n = args['minute-n']
3 years ago
info = {
"ip": ip,
3 years ago
"path": path,
"delete": delete,
"realtime": realtime,
'delay': delay,
"conn_type": conn_type,
"period": period,
"hour": hour,
"minute": minute,
"minute-n": minute_n,
}
if conn_type == "key":
2 years ago
secret_key_check = checkArgs(args, ['secret_key'])
if not secret_key_check[0]:
return secret_key_check[1]
secret_key = args['secret_key']
3 years ago
try:
m = base64.b64decode(secret_key)
m = json.loads(m)
info['name'] = m['A']
info['password'] = m['B']
info['port'] = m['C']
except Exception as e:
return mw.returnJson(False, "接收密钥格式错误!")
else:
2 years ago
data = checkArgs(args, ['sname', 'password'])
3 years ago
if not data[0]:
return data[1]
2 years ago
info['name'] = args['sname']
info['password'] = args['password']
2 years ago
info['port'] = args['port']
3 years ago
rsync = {
'bwlimit': bwlimit,
"port": info['port'],
"compress": compress,
"archive": "true",
"verbose": "true"
3 years ago
}
3 years ago
info['rsync'] = rsync
3 years ago
data = getDefaultConf()
3 years ago
slist = data['send']["list"]
3 years ago
res = lsyncdListFindName(slist, info['name'])
if not 'exclude' in info:
if res[0]:
info["exclude"] = slist[res[1]]['exclude']
else:
info["exclude"] = [
"/**.upload.tmp", "**/*.log", "**/*.tmp",
"**/*.temp", ".git", ".gitignore", ".user.ini",
]
3 years ago
if res[0]:
list_index = res[1]
slist[list_index] = info
else:
slist.append(info)
3 years ago
3 years ago
data['send']["list"] = slist
setDefaultConf(data)
3 years ago
makeLsyncdConf(data)
3 years ago
return mw.returnJson(True, "设置成功!")
3 years ago
def lsyncdRun():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
send_dir = getServerDir() + "/send"
name = args['name']
app_dir = send_dir + "/" + name
3 years ago
cmd = "bash " + app_dir + "/cmd >> " + app_dir + "/run.log" + " 2>&1 &"
3 years ago
mw.execShell(cmd)
return mw.returnJson(True, "执行成功!")
3 years ago
def lsyncdConfLog():
logs_path = getServerDir() + "/lsyncd.log"
return logs_path
3 years ago
def lsyncdLog():
args = getArgs()
data = checkArgs(args, ['name'])
if not data[0]:
return data[1]
send_dir = getServerDir() + "/send"
name = args['name']
app_dir = send_dir + "/" + name
return app_dir + "/run.log"
3 years ago
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)
6 years ago
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
4 years ago
print(status())
6 years ago
elif func == 'start':
4 years ago
print(start())
6 years ago
elif func == 'stop':
4 years ago
print(stop())
6 years ago
elif func == 'restart':
4 years ago
print(restart())
6 years ago
elif func == 'reload':
4 years ago
print(reload())
6 years ago
elif func == 'initd_status':
4 years ago
print(initdStatus())
6 years ago
elif func == 'initd_install':
4 years ago
print(initdInstall())
6 years ago
elif func == 'initd_uninstall':
4 years ago
print(initdUinstall())
6 years ago
elif func == 'conf':
4 years ago
print(appConf())
6 years ago
elif func == 'run_log':
4 years ago
print(getLog())
elif func == 'rec_list':
4 years ago
print(getRecList())
elif func == 'add_rec':
4 years ago
print(addRec())
elif func == 'del_rec':
4 years ago
print(delRec())
3 years ago
elif func == 'get_rec':
print(getRec())
elif func == 'cmd_rec_secret_key':
print(cmdRecSecretKey())
elif func == 'cmd_rec_cmd':
print(cmdRecCmd())
elif func == 'lsyncd_list':
print(lsyncdList())
elif func == 'lsyncd_add':
print(lsyncdAdd())
3 years ago
elif func == 'lsyncd_get':
print(lsyncdGet())
elif func == 'lsyncd_delete':
print(lsyncdDelete())
3 years ago
elif func == 'lsyncd_run':
print(lsyncdRun())
elif func == 'lsyncd_log':
print(lsyncdLog())
3 years ago
elif func == 'lsyncd_conf_log':
print(lsyncdConfLog())
3 years ago
elif func == 'lsyncd_get_exclude':
print(lsyncdGetExclude())
elif func == 'lsyncd_remove_exclude':
print(lsyncdRemoveExclude())
elif func == 'lsyncd_add_exclude':
print(lsyncdAddExclude())
6 years ago
else:
4 years ago
print('error')