summaryrefslogtreecommitdiff
path: root/src/conf_mode/vpn_sstp.py
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-04-05 16:56:41 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-04-06 20:22:35 +0100
commitc51b8f3e2fe1a8425fba2d3eb9c07049ef9b22bb (patch)
tree48514654e5b44b50002dbc4a0e0b70ce4e00cdd7 /src/conf_mode/vpn_sstp.py
parent4b30d3d6545b108c0b043baae2d57a465a8c8999 (diff)
downloadvyos-1x-c51b8f3e2fe1a8425fba2d3eb9c07049ef9b22bb.tar.gz
vyos-1x-c51b8f3e2fe1a8425fba2d3eb9c07049ef9b22bb.zip
util: T2226: rewrite conf accel-ppp commands to use cmd
Diffstat (limited to 'src/conf_mode/vpn_sstp.py')
-rwxr-xr-xsrc/conf_mode/vpn_sstp.py51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/conf_mode/vpn_sstp.py b/src/conf_mode/vpn_sstp.py
index 66b1822df..d4fd0f4a3 100755
--- a/src/conf_mode/vpn_sstp.py
+++ b/src/conf_mode/vpn_sstp.py
@@ -18,16 +18,16 @@ import os
from time import sleep
from sys import exit
-from subprocess import check_output
from socket import socket, AF_INET, SOCK_STREAM
from copy import deepcopy
from stat import S_IRUSR, S_IWUSR, S_IRGRP
from jinja2 import FileSystemLoader, Environment
from vyos.config import Config
+from vyos import ConfigError
from vyos.defaults import directories as vyos_data_dir
from vyos.util import process_running, subprocess_cmd
-from vyos import ConfigError
+from vyos.util import process_running, cmd, run
pidfile = r'/var/run/accel_sstp.pid'
sstp_cnf_dir = r'/etc/accel-ppp/sstp'
@@ -53,16 +53,9 @@ def chk_con():
raise("failed to start sstp server")
break
-def accel_cmd(cmd):
- if not cmd:
- return None
-
- try:
- ret = check_output(['/usr/bin/accel-cmd', '-p', '2005', cmd])
- return ret.decode().strip()
- except:
- return 1
+def _accel_cmd(command):
+ return run(f'/usr/bin/accel-cmd -p 2005 {command}')
default_config_data = {
'local_users' : [],
@@ -363,12 +356,12 @@ def generate(sstp):
def apply(sstp):
if sstp is None:
if process_running(pidfile):
- cmd = 'start-stop-daemon'
- cmd += ' --stop '
- cmd += ' --quiet'
- cmd += ' --oknodo'
- cmd += ' --pidfile ' + pidfile
- subprocess_cmd(cmd)
+ command = 'start-stop-daemon'
+ command += ' --stop '
+ command += ' --quiet'
+ command += ' --oknodo'
+ command += ' --pidfile ' + pidfile
+ cmd(command)
if os.path.exists(pidfile):
os.remove(pidfile)
@@ -379,23 +372,23 @@ def apply(sstp):
if os.path.exists(pidfile):
os.remove(pidfile)
- cmd = 'start-stop-daemon'
- cmd += ' --start '
- cmd += ' --quiet'
- cmd += ' --oknodo'
- cmd += ' --pidfile ' + pidfile
- cmd += ' --exec /usr/sbin/accel-pppd'
+ command = 'start-stop-daemon'
+ command += ' --start '
+ command += ' --quiet'
+ command += ' --oknodo'
+ command += ' --pidfile ' + pidfile
+ command += ' --exec /usr/sbin/accel-pppd'
# now pass arguments to accel-pppd binary
- cmd += ' --'
- cmd += ' -c ' + sstp_conf
- cmd += ' -p ' + pidfile
- cmd += ' -d'
- subprocess_cmd(cmd)
+ command += ' --'
+ command += ' -c ' + sstp_conf
+ command += ' -p ' + pidfile
+ command += ' -d'
+ cmd(command)
chk_con()
else:
- accel_cmd('restart')
+ _accel_cmd('restart')
if __name__ == '__main__':