summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-openvpn.py17
-rwxr-xr-xsrc/helpers/vyos-merge-config.py12
-rwxr-xr-xsrc/op_mode/reset_vpn.py69
3 files changed, 40 insertions, 58 deletions
diff --git a/src/conf_mode/interfaces-openvpn.py b/src/conf_mode/interfaces-openvpn.py
index f34e4f7fe..8a615ec62 100755
--- a/src/conf_mode/interfaces-openvpn.py
+++ b/src/conf_mode/interfaces-openvpn.py
@@ -490,7 +490,11 @@ def verify(openvpn):
# OpenVPN site-to-site - VERIFY
#
if openvpn['mode'] == 'site-to-site':
- if not (openvpn['local_address'] or openvpn['bridge_member']):
+ if openvpn['ncp_ciphers']:
+ raise ConfigError('encryption ncp-ciphers cannot be specified in site-to-site mode, only server or client')
+
+ if openvpn['mode'] == 'site-to-site' and not openvpn['bridge_member']:
+ if not openvpn['local_address']:
raise ConfigError('Must specify "local-address" or "bridge member interface"')
for host in openvpn['remote_host']:
@@ -507,15 +511,10 @@ def verify(openvpn):
if openvpn['local_address'] == openvpn['local_host']:
raise ConfigError('"local-address" cannot be the same as "local-host"')
- if openvpn['ncp_ciphers']:
- raise ConfigError('encryption ncp-ciphers cannot be specified in site-to-site mode, only server or client')
-
else:
+ # checks for client-server or site-to-site bridged
if openvpn['local_address'] or openvpn['remote_address']:
- raise ConfigError('Cannot specify "local-address" or "remote-address" in client-server mode')
-
- elif openvpn['bridge_member']:
- raise ConfigError('Cannot specify "local-address" or "remote-address" in bridge mode')
+ raise ConfigError('Cannot specify "local-address" or "remote-address" in client-server or bridge mode')
#
# OpenVPN server mode - VERIFY
@@ -538,7 +537,7 @@ def verify(openvpn):
if not openvpn['server_subnet']:
if not openvpn['bridge_member']:
- raise ConfigError('Must specify "server subnet" option in server mode')
+ raise ConfigError('Must specify "server subnet" or "bridge member interface" in server mode')
else:
# checks for both client and site-to-site go here
diff --git a/src/helpers/vyos-merge-config.py b/src/helpers/vyos-merge-config.py
index 10a5ea4bc..14df2734b 100755
--- a/src/helpers/vyos-merge-config.py
+++ b/src/helpers/vyos-merge-config.py
@@ -17,13 +17,13 @@
import sys
import os
-import subprocess
import tempfile
import vyos.defaults
import vyos.remote
from vyos.config import Config
from vyos.configtree import ConfigTree
from vyos.migrator import Migrator, VirtualMigrator
+from vyos.util import cmd, DEVNULL
if (len(sys.argv) < 2):
@@ -99,13 +99,11 @@ if (len(sys.argv) > 2):
if path:
add_cmds = [ cmd for cmd in add_cmds if path in cmd ]
-for cmd in add_cmds:
- cmd = "/opt/vyatta/sbin/my_" + cmd
-
+for add in add_cmds:
try:
- subprocess.check_call(cmd, shell=True)
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
+ cmd(f'/opt/vyatta/sbin/my_{add}', shell=True, stderr=DEVNULL)
+ except OSError as err:
+ print(err)
if effective_config.session_changed():
print("Merge complete. Use 'commit' to make changes effective.")
diff --git a/src/op_mode/reset_vpn.py b/src/op_mode/reset_vpn.py
index 8962df212..3a0ad941c 100755
--- a/src/op_mode/reset_vpn.py
+++ b/src/op_mode/reset_vpn.py
@@ -14,64 +14,49 @@
# 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 os
import sys
import argparse
-#import re
from vyos.util import run
-from vyos.util import DEVNULL
-pptp_base = '/usr/bin/accel-cmd -p 2003 terminate {} {}'
-l2tp_base = '/usr/bin/accel-cmd -p 2004 terminate {} {}'
+cmd_dict = {
+ 'cmd_base' : '/usr/bin/accel-cmd -p {} terminate {} {}',
+ 'vpn_types' : {
+ 'pptp' : 2003,
+ 'l2tp' : 2004,
+ 'sstp' : 2005
+ }
+}
def terminate_sessions(username='', interface='', protocol=''):
- if username:
- if username == "all_users":
- if protocol == "pptp":
- pptp_cmd = pptp_base.format('all','')
- run(pptp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
- elif protocol == "l2tp":
- l2tp_cmd = l2tp_base.format('all', '')
- run(l2tp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
- else:
- pptp_cmd = pptp_base.format('all', '')
- run(pptp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- l2tp_cmd = l2tp_base.format('all', '')
- run(l2tp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
- if protocol == "pptp":
- pptp_cmd = pptp_base.format('username', username)
- run(pptp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
- elif protocol == "l2tp":
- l2tp_cmd = l2tp_base.format('username', username)
- run(l2tp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
+ # Reset vpn connections by username
+ if protocol in cmd_dict['vpn_types']:
+ if username == "all_users":
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][protocol], 'all', ''))
else:
- pptp_cmd = pptp_base.format('username', username)
- run(pptp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- l2tp_cmd.append("terminate username {0}".format(username))
- run(l2tp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- return
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][protocol], 'username', username))
+
+ # Reset vpn connections by ifname
+ elif interface:
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'if', interface))
- # rewrite `terminate by interface` if pptp will have pptp%d interface naming
- if interface:
- pptp_cmd = pptp_base.format('if', interface)
- run(pptp_cmd, stdout=DEVNULL, stderr=DEVNULL)
- l2tp_cmd = l2tp_base.format('if', interface)
- run(l2tp_cmd, stdout=DEVNULL, stderr=DEVNULL)
-
+ elif username:
+ # Reset all vpn connections
+ if username == "all_users":
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'all', ''))
+ else:
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'username', username))
def main():
#parese args
parser = argparse.ArgumentParser()
parser.add_argument('--username', help='Terminate by username (all_users used for disconnect all users)', required=False)
parser.add_argument('--interface', help='Terminate by interface', required=False)
- parser.add_argument('--protocol', help='Set protocol (pptp|l2tp)', required=False)
+ parser.add_argument('--protocol', help='Set protocol (pptp|l2tp|sstp)', required=False)
args = parser.parse_args()
if args.username or args.interface: