From 5c2decfd8085895142022932845ceb8e1ddcb4ca Mon Sep 17 00:00:00 2001 From: DmitriyEshenko Date: Thu, 16 Apr 2020 19:54:41 +0000 Subject: l2tp: T2256: Implement control script for operational commands --- op-mode-definitions/l2tp-server.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/op-mode-definitions/l2tp-server.xml b/op-mode-definitions/l2tp-server.xml index fb1b85ce4..3e96b9365 100644 --- a/op-mode-definitions/l2tp-server.xml +++ b/op-mode-definitions/l2tp-server.xml @@ -4,14 +4,20 @@ - show l2tp-server status + Show L2TP server information Show active L2TP server sessions - /usr/bin/accel-cmd -p 2004 'show sessions' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="l2tp" --action="show sessions" + + + + Show L2TP server statistics + + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="l2tp" --action="show stat" -- cgit v1.2.3 From aa7d9dc789a36aec06bdb57391608c79f22b104d Mon Sep 17 00:00:00 2001 From: DmitriyEshenko Date: Thu, 16 Apr 2020 20:18:42 +0000 Subject: pptp: T2256: Use ppp-server-ctrl.py for op-commands --- op-mode-definitions/pptp-server.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/op-mode-definitions/pptp-server.xml b/op-mode-definitions/pptp-server.xml index 388063885..59be68611 100644 --- a/op-mode-definitions/pptp-server.xml +++ b/op-mode-definitions/pptp-server.xml @@ -4,14 +4,20 @@ - show pptp-server status + Show PPTP server information Show active PPTP server sessions - /usr/bin/accel-cmd -p 2003 'show sessions' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pptp" --action="show sessions" + + + + Show PPTP server statistics + + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pptp" --action="show stat" -- cgit v1.2.3 From 601da2d41437220063de274e9adbac19729275d6 Mon Sep 17 00:00:00 2001 From: DmitriyEshenko Date: Thu, 16 Apr 2020 20:21:42 +0000 Subject: pppoe: T2256: Use ppp-server-ctrl.py for op-commands --- op-mode-definitions/pppoe-server.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/op-mode-definitions/pppoe-server.xml b/op-mode-definitions/pppoe-server.xml index 0293c9502..5ac9d9497 100644 --- a/op-mode-definitions/pppoe-server.xml +++ b/op-mode-definitions/pppoe-server.xml @@ -4,26 +4,26 @@ - show pppoe-server status + Show pppoe-server status Show active PPPoE server sessions - /usr/bin/accel-cmd 'show sessions ifname,username,ip,ip6,ip6-dp,calling-sid,rate-limit,state,uptime,rx-bytes,tx-bytes' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="show sessions" Show PPPoE server statistics - /usr/bin/accel-cmd 'show stat' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="show stat" Show interfaces where pppoe-server listens on - /usr/bin/accel-cmd 'pppoe interface show' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="pppoe interface show" @@ -35,7 +35,7 @@ Restarts pppoe-server - if [ -e /var/run/accel_pppoe.pid ]; then /usr/bin/accel-cmd restart -p 2001; else echo "pppoe-server not running"; fi + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="restart" @@ -53,19 +53,19 @@ Terminate all pppoe-server users - /usr/bin/accel-cmd terminate all + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate all" Terminate a ppp interface - /usr/bin/accel-cmd terminate if "$4" + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate if $4" Terminate specified users - /usr/bin/accel-cmd terminate match username "$4" + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate username $4" @@ -87,13 +87,13 @@ Deny new connections and stop to serve pppoe after disconnect last session - /usr/bin/accel-cmd shutdown soft + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="shutdown soft" Cancel maintenance mode - /usr/bin/accel-cmd shutdown cancel + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="shutdown cancel" -- cgit v1.2.3 From 87ad1faeff250c5bcf4596f00107536f34b10235 Mon Sep 17 00:00:00 2001 From: DmitriyEshenko Date: Thu, 16 Apr 2020 20:27:46 +0000 Subject: sstp: T2256: Use ppp-server-ctrl.py for op-commands --- op-mode-definitions/sstp-server.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/op-mode-definitions/sstp-server.xml b/op-mode-definitions/sstp-server.xml index 36d0b9985..03dfc4262 100644 --- a/op-mode-definitions/sstp-server.xml +++ b/op-mode-definitions/sstp-server.xml @@ -4,20 +4,20 @@ - show sstp-server status + Show SSTP server information Show active SSTP server sessions - /usr/bin/accel-cmd -p 2005 'show sessions ifname,username,ip,ip6,ip6-dp,calling-sid,rate-limit,state,uptime,rx-bytes,tx-bytes' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="sstp" --action="show sessions" Show SSTP server statistics - /usr/bin/accel-cmd -p 2005 'show stat' + ${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="sstp" --action="show stat" -- cgit v1.2.3 From 4b3510f7726812e4f697a03cba14751d27db4fd8 Mon Sep 17 00:00:00 2001 From: DmitriyEshenko Date: Thu, 16 Apr 2020 20:35:53 +0000 Subject: l2tp: T2256: Add op control script --- src/op_mode/ppp-server-ctrl.py | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 src/op_mode/ppp-server-ctrl.py diff --git a/src/op_mode/ppp-server-ctrl.py b/src/op_mode/ppp-server-ctrl.py new file mode 100755 index 000000000..171107b4a --- /dev/null +++ b/src/op_mode/ppp-server-ctrl.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2019 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import sys +import argparse + +from vyos.config import Config +from vyos.util import popen, DEVNULL + +cmd_dict = { + 'cmd_base' : '/usr/bin/accel-cmd -p {} ', + 'vpn_types' : { + 'pppoe' : 2001, + 'pptp' : 2003, + 'l2tp' : 2004, + 'sstp' : 2005 + }, + 'conf_proto' : { + 'pppoe' : 'service pppoe-server', + 'pptp' : 'vpn pptp remote-access', + 'l2tp' : 'vpn l2tp remote-access', + 'sstp' : 'vpn sstp' + } +} + +def is_service_configured(proto): + if not Config().exists_effective(cmd_dict['conf_proto'][proto]): + print("Service {} is not configured".format(proto)) + sys.exit(1) + +def main(): + #parese args + parser = argparse.ArgumentParser() + parser.add_argument('--proto', help='Possible protocols pppoe|pptp|l2tp|sstp', required=True) + parser.add_argument('--action', help='Action command', required=True) + args = parser.parse_args() + + if args.proto in cmd_dict['vpn_types'] and args.action: + # Check is service configured + is_service_configured(args.proto) + + if args.action == "show sessions": + ses_pattern = " ifname,username,ip,ip6,ip6-dp,calling-sid,rate-limit,state,uptime,rx-bytes,tx-bytes" + else: + ses_pattern = "" + + output, err = popen(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][args.proto]) + args.action + ses_pattern, stderr=DEVNULL, decode='utf-8') + if not err: + print(output) + else: + print("{} server is not running".format(args.proto)) + + else: + print("Param --proto and --action required") + sys.exit(1) + +if __name__ == '__main__': + main() -- cgit v1.2.3