summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-17 08:10:56 +0200
committerGitHub <noreply@github.com>2020-04-17 08:10:56 +0200
commit3964ee10a3a85e3655135d7e0235b4d1b2f08214 (patch)
tree8123ceab6e6cfba7cb31fe0de4e1542a7b690266
parentb4544f196c2beededdd76f581690b1490c755dac (diff)
parent4b3510f7726812e4f697a03cba14751d27db4fd8 (diff)
downloadvyos-1x-3964ee10a3a85e3655135d7e0235b4d1b2f08214.tar.gz
vyos-1x-3964ee10a3a85e3655135d7e0235b4d1b2f08214.zip
Merge pull request #350 from DmitriyEshenko/impl-uf-op-ppp
vpn: T2256: Improve op commands for l2tp, pptp, sstp and pppoe servers
-rw-r--r--op-mode-definitions/l2tp-server.xml10
-rw-r--r--op-mode-definitions/pppoe-server.xml20
-rw-r--r--op-mode-definitions/pptp-server.xml10
-rw-r--r--op-mode-definitions/sstp-server.xml6
-rwxr-xr-xsrc/op_mode/ppp-server-ctrl.py71
5 files changed, 100 insertions, 17 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 @@
<children>
<node name="l2tp-server">
<properties>
- <help>show l2tp-server status</help>
+ <help>Show L2TP server information</help>
</properties>
<children>
<leafNode name="sessions">
<properties>
<help>Show active L2TP server sessions</help>
</properties>
- <command>/usr/bin/accel-cmd -p 2004 'show sessions'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="l2tp" --action="show sessions"</command>
+ </leafNode>
+ <leafNode name="statistics">
+ <properties>
+ <help>Show L2TP server statistics</help>
+ </properties>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="l2tp" --action="show stat"</command>
</leafNode>
</children>
</node>
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 @@
<children>
<node name="pppoe-server">
<properties>
- <help>show pppoe-server status</help>
+ <help>Show pppoe-server status</help>
</properties>
<children>
<leafNode name="sessions">
<properties>
<help>Show active PPPoE server sessions</help>
</properties>
- <command>/usr/bin/accel-cmd 'show sessions ifname,username,ip,ip6,ip6-dp,calling-sid,rate-limit,state,uptime,rx-bytes,tx-bytes'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="show sessions"</command>
</leafNode>
<leafNode name="statistics">
<properties>
<help>Show PPPoE server statistics</help>
</properties>
- <command>/usr/bin/accel-cmd 'show stat'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="show stat"</command>
</leafNode>
<leafNode name="interfaces">
<properties>
<help>Show interfaces where pppoe-server listens on</help>
</properties>
- <command>/usr/bin/accel-cmd 'pppoe interface show'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="pppoe interface show"</command>
</leafNode>
</children>
</node>
@@ -35,7 +35,7 @@
<properties>
<help>Restarts pppoe-server</help>
</properties>
- <command>if [ -e /var/run/accel_pppoe.pid ]; then /usr/bin/accel-cmd restart -p 2001; else echo "pppoe-server not running"; fi</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="restart"</command>
</leafNode>
</children>
</node>
@@ -53,19 +53,19 @@
<properties>
<help>Terminate all pppoe-server users</help>
</properties>
- <command>/usr/bin/accel-cmd terminate all</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate all"</command>
</leafNode>
<tagNode name="interface">
<properties>
<help>Terminate a ppp interface</help>
</properties>
- <command>/usr/bin/accel-cmd terminate if "$4"</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate if $4"</command>
</tagNode>
<tagNode name="username">
<properties>
<help>Terminate specified users</help>
</properties>
- <command>/usr/bin/accel-cmd terminate match username "$4"</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="terminate username $4"</command>
</tagNode>
</children>
</node>
@@ -87,13 +87,13 @@
<properties>
<help>Deny new connections and stop to serve pppoe after disconnect last session</help>
</properties>
- <command>/usr/bin/accel-cmd shutdown soft</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="shutdown soft"</command>
</leafNode>
<leafNode name="cancel">
<properties>
<help>Cancel maintenance mode</help>
</properties>
- <command>/usr/bin/accel-cmd shutdown cancel</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pppoe" --action="shutdown cancel"</command>
</leafNode>
</children>
</node>
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 @@
<children>
<node name="pptp-server">
<properties>
- <help>show pptp-server status</help>
+ <help>Show PPTP server information</help>
</properties>
<children>
<leafNode name="sessions">
<properties>
<help>Show active PPTP server sessions</help>
</properties>
- <command>/usr/bin/accel-cmd -p 2003 'show sessions'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pptp" --action="show sessions"</command>
+ </leafNode>
+ <leafNode name="statistics">
+ <properties>
+ <help>Show PPTP server statistics</help>
+ </properties>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="pptp" --action="show stat"</command>
</leafNode>
</children>
</node>
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 @@
<children>
<node name="sstp-server">
<properties>
- <help>show sstp-server status</help>
+ <help>Show SSTP server information</help>
</properties>
<children>
<leafNode name="sessions">
<properties>
<help>Show active SSTP server sessions</help>
</properties>
- <command>/usr/bin/accel-cmd -p 2005 'show sessions ifname,username,ip,ip6,ip6-dp,calling-sid,rate-limit,state,uptime,rx-bytes,tx-bytes'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="sstp" --action="show sessions"</command>
</leafNode>
<leafNode name="statistics">
<properties>
<help>Show SSTP server statistics</help>
</properties>
- <command>/usr/bin/accel-cmd -p 2005 'show stat'</command>
+ <command>${vyos_op_scripts_dir}/ppp-server-ctrl.py --proto="sstp" --action="show stat"</command>
</leafNode>
</children>
</node>
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 <http://www.gnu.org/licenses/>.
+
+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()