This commit is contained in:
midoks
2021-01-29 16:13:40 +08:00
parent 2073fbd680
commit 44c55ee923
6 changed files with 23 additions and 108 deletions
+12 -104
View File
@@ -51,7 +51,7 @@ def checkArgs(data, ck=[]):
def status():
cmd = "ps -ef|grep xl2tpd |grep -v grep | grep -v python | awk '{print $2}'"
cmd = "ps -ef|grep ss5 |grep -v grep | grep -v python | awk '{print $2}'"
data = mw.execShell(cmd)
if data[0] == '':
return 'stop'
@@ -59,15 +59,15 @@ def status():
def initConf():
l2tp_cs = getServerDir() + '/chap-secrets'
if not os.path.exists(l2tp_cs):
ss5_conf = getServerDir() + '/ss5.conf'
if not os.path.exists(ss5_conf):
mw.execShell('cp -rf ' + getPluginDir() +
'/tmp/chap-secrets' + ' ' + getServerDir())
'/tmp/ss5.conf' + ' ' + getServerDir())
l2tp_is = getServerDir() + '/ipsec.secrets'
if not os.path.exists(l2tp_is):
ss5_pwd = getServerDir() + '/ss5.passwd'
if not os.path.exists(ss5_pwd):
mw.execShell('cp -rf ' + getPluginDir() +
'/tmp/ipsec.secrets' + ' ' + getServerDir())
'/tmp/ss5.passwd' + ' ' + getServerDir())
def start():
@@ -76,7 +76,7 @@ def start():
if mw.isAppleSystem():
return "Apple Computer does not support"
data = mw.execShell('service xl2tpd start')
data = mw.execShell('service ss5 start')
if data[0] == '':
return 'ok'
return data[1]
@@ -86,7 +86,7 @@ def stop():
if mw.isAppleSystem():
return "Apple Computer does not support"
data = mw.execShell('service xl2tpd stop')
data = mw.execShell('service ss5 stop')
if data[0] == '':
return 'ok'
return data[1]
@@ -96,14 +96,14 @@ def restart():
if mw.isAppleSystem():
return "Apple Computer does not support"
data = mw.execShell('service xl2tpd restart')
data = mw.execShell('service ss5 restart')
if data[0] == '':
return 'ok'
return data[1]
def reload():
data = mw.execShell('service xl2tpd reload')
data = mw.execShell('service ss5 reload')
if data[0] == '':
return 'ok'
return data[1]
@@ -121,90 +121,6 @@ def getPathFilePwd():
return '/etc/opt/ss5/ss5.passwd'
def getUserList():
import re
path = getPathFile()
if not os.path.exists(path):
return mw.returnJson(False, '密码配置文件不存在!')
conf = mw.readFile(path)
conf = re.sub('#(.*)\n', '', conf)
if conf.strip() == '':
return mw.returnJson(True, 'ok', [])
ulist = conf.strip().split('\n')
user = []
for line in ulist:
line_info = {}
line = re.match(r'(\w*)\s*(\w*)\s*(\w*)\s*(.*)',
line.strip(), re.M | re.I).groups()
line_info['user'] = line[0]
line_info['pwd'] = line[2]
line_info['type'] = line[1]
line_info['ip'] = line[3]
user.append(line_info)
return mw.returnJson(True, 'ok', user)
def addUser():
if mw.isAppleSystem():
return mw.returnJson(False, "Apple Computer does not support")
args = getArgs()
data = checkArgs(args, ['username'])
if not data[0]:
return data[1]
ret = mw.execShell('echo ' + args['username'] + '|l2tp -a')
if ret[1] == '':
return mw.returnJson(True, '添加成功!:' + ret[0])
return mw.returnJson(False, '添加失败:' + ret[0])
def delUser():
if mw.isAppleSystem():
return mw.returnJson(False, "Apple Computer does not support")
args = getArgs()
data = checkArgs(args, ['username'])
if not data[0]:
return data[1]
ret = mw.execShell('echo ' + args['username'] + '|l2tp -d')
if ret[1] == '':
return mw.returnJson(True, '删除成功!:' + ret[0])
return mw.returnJson(False, '删除失败:' + ret[0])
def modUser():
args = getArgs()
data = checkArgs(args, ['username', 'password'])
if not data[0]:
return data[1]
path = getPathFile()
username = args['username']
password = args['password']
# sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets
# echo "${user} l2tpd ${pass} *" >> /etc/ppp/chap-secrets
if mw.isAppleSystem():
mw.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path)
else:
mw.execShell("sed -i '/^\(" + username + "\)/d' " + path)
# print 'echo "' + username + " l2tpd " + password + " *\" >>"
# + path
ret = mw.execShell("echo \"" + username +
" l2tpd " + password + " *\" >>" + path)
if ret[1] == '':
return mw.returnJson(True, '修改成功!')
return mw.returnJson(False, '修改失败')
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
@@ -219,15 +135,7 @@ if __name__ == "__main__":
print reload()
elif func == 'conf':
print getPathFile()
elif func == 'conf_psk':
elif func == 'conf_pwd':
print getPathFilePwd()
elif func == 'user_list':
print getUserList()
elif func == 'add_user':
print addUser()
elif func == 'del_user':
print delUser()
elif func == 'mod_user':
print modUser()
else:
print 'error'
+2
View File
@@ -36,6 +36,8 @@ Uninstall_socket5()
{
rm -rf $serverPath/socket5
rm -rf /usr/sbin/ss5
service ss5 stop
rm -rf /etc/init.d/ss5
echo "Uninstall completed" > $install_tmp
}
-3
View File
@@ -1,3 +0,0 @@
# Secrets for authentication using CHAP
# client server secret IP addresses
demo demo demo *
-1
View File
@@ -1 +0,0 @@
%any %any : PSK "midoks"
+8
View File
@@ -0,0 +1,8 @@
# 无用户配置
auth 0.0.0.0/0 - -
permit - 0.0.0.0/0 - 0.0.0.0/0 - - - - -
# 用户配置
#auth 0.0.0.0/0 - u
#permit - 0.0.0.0/0 - 0.0.0.0/0 - - - - -
+1
View File
@@ -0,0 +1 @@
test test