From bb69c92a9c352bdb70f74044fdbb75bab156106c Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 1 Mar 2019 15:53:29 +0800 Subject: [PATCH] update --- plugins/l2tp/index.html | 3 +- plugins/l2tp/index.py | 58 +++++++++++++++++++-- plugins/l2tp/js/l2tp.js | 81 ++++++++++++++++++++++++++++- plugins/l2tp/{ => tmp}/chap-secrets | 2 +- 4 files changed, 137 insertions(+), 7 deletions(-) rename plugins/l2tp/{ => tmp}/chap-secrets (70%) diff --git a/plugins/l2tp/index.html b/plugins/l2tp/index.html index 63ff7faa1..8176b605c 100755 --- a/plugins/l2tp/index.html +++ b/plugins/l2tp/index.html @@ -2,7 +2,8 @@

服务

-

用户列表

+

用户配置

+

用户列表

diff --git a/plugins/l2tp/index.py b/plugins/l2tp/index.py index e250685d2..250e03137 100755 --- a/plugins/l2tp/index.py +++ b/plugins/l2tp/index.py @@ -49,6 +49,13 @@ def getArgs(): return tmp +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, public.returnJson(True, 'ok')) + + def status(): cmd = "ps -ef|grep xl2tpd |grep -v grep | grep -v python | awk '{print $2}'" data = public.execShell(cmd) @@ -81,9 +88,50 @@ def reload(): return 'ok' +def getPathFile(): + if public.isAppleSystem(): + return getServerDir() + '/chap-secrets' + return '/etc/ppp/chap-secrets' + + def getUserList(): - data = [] - return public.getJson(data) + import re + path = getPathFile() + if not os.path.exists(path): + return public.returnJson(False, '密码配置文件不存在!') + conf = public.readFile(path) + + conf = re.sub('#(.*)\n', '', conf) + 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[1] + line_info['psk'] = line[2] + line_info['ip'] = line[3] + user.append(line_info) + + return public.returnJson(True, 'ok', user) + + +def addUser(): + args = getArgs() + data = checkArgs(args, ['username']) + if not data[0]: + return data[1] + + public.execShell('echo ' + args['username'] + '> ') + + +def delUser(): + args = getArgs() + data = checkArgs(args, ['username']) + if not data[0]: + return data[1] if __name__ == "__main__": func = sys.argv[1] @@ -97,11 +145,13 @@ if __name__ == "__main__": print restart() elif func == 'reload': print reload() + elif func == 'conf': + print getPathFile() elif func == 'user_list': print getUserList() elif func == 'add_user': print addUser() - elif func == 'delete_user': - print '' + elif func == 'del_user': + print delUser() else: print 'error' diff --git a/plugins/l2tp/js/l2tp.js b/plugins/l2tp/js/l2tp.js index 5480b86f8..580118aa6 100755 --- a/plugins/l2tp/js/l2tp.js +++ b/plugins/l2tp/js/l2tp.js @@ -45,5 +45,84 @@ function lpAsyncPost(method,args){ } var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); - return syncPost('/plugins/run', {name:'l2tp', func:method, args:_args}); + return syncPost('/plugins/run', {name:'l2tp', func:method, args:_args}); } + +function userList(){ + lpPost('user_list', '' ,function(data){ + var rdata = $.parseJSON(data['data']); + + if (!rdata['status']){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + var list = rdata['data']; + + var con = ''; + con += '
'; + con += ''; + con += ''; + con += ''; + con += ''; + con += ''; + con += ''; + + con += ''; + + for (var i = 0; i < list.length; i++) { + con += ''+ + '' + + '' + + '' + + ''; + } + + con += ''; + con += '
用户密码PSK操作(添加)
' + list[i]['user']+'' + list[i]['pwd']+'' + list[i]['psk']+'改密|删除
'; + + $(".soft-man-con").html(con); + }); +} + + +function addUser(){ + var loadOpen = layer.open({ + type: 1, + title: '添加用户', + area: '240px', + content:"
\ +
\ +
\ +
\ +
\ + \ + \ +
\ +
" + }); + + $('#add_close').click(function(){ + layer.close(loadOpen); + }); + + $('#add_ok').click(function(){ + _data = {}; + _data['username'] = $('#username').val(); + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + lpPost('user_add', _data, function(data){ + var rdata = $.parseJSON(data); + + layer.msg(rdata.msg,{icon:rdata.status?1:2,time:2000,shade: [0.3, '#000']}); + userList(); + }); + }); +} + +function delUser(username){ + lpPost('user_del', {username:username}, function(data){ + var rdata = $.parseJSON(data); + layer.msg(rdata.msg,{icon:rdata.status?1:2,time:2000,shade: [0.3, '#000']}); + userList(); + }); +} + diff --git a/plugins/l2tp/chap-secrets b/plugins/l2tp/tmp/chap-secrets similarity index 70% rename from plugins/l2tp/chap-secrets rename to plugins/l2tp/tmp/chap-secrets index 70fddd818..20721096a 100644 --- a/plugins/l2tp/chap-secrets +++ b/plugins/l2tp/tmp/chap-secrets @@ -1,3 +1,3 @@ # Secrets for authentication using CHAP # client server secret IP addresses -teddysun l2tpd 123123 * +demo demo demo *