1、新增用户和密码
def add_rsync_user_and_password(username):
password_file_path = "/etc/rsync/pass.pass"
try:
f = open(password_file_path,"r")
infos = f.read().split("\n")
except:
import traceback
traceback.print_exc()
else:
f.close()
d = dict([ elem.split(":") for elem in infos if elem ])
if username not in d: #不存在
raw_pwd = get_random_password(8)
d[username] = raw_pwd
s = "\n".join(["%s:%s"%(k,v) for k,v in d.items()])
f = open(password_file_path,"w")
f.write(s)
f.close()
auth_file_path = "/etc/rsyncd.conf"
#匹配rsync文件中配置用户的行,检查并增加用户到目录行中
try:
f = open(auth_file_path,"r")
s = f.read()
except:
pass