From 3ad4f0b6eb551b8388df1d4dec1399d8203d5415 Mon Sep 17 00:00:00 2001 From: 1951FDG <1951FDG@users.noreply.github.com> Date: Fri, 2 Apr 2021 23:23:16 +0200 Subject: [PATCH] Bugfix: Improve check VPN client status for Asuswrt-merlin --- openpyn/asus.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/openpyn/asus.py b/openpyn/asus.py index 6b9ce31..863b440 100644 --- a/openpyn/asus.py +++ b/openpyn/asus.py @@ -103,8 +103,8 @@ def write(key, value, unit, service, test=False): try: pprint("/bin/nvram" + " " + "get" + " " + argument1) if not test: - current = subprocess.run(["/bin/nvram", "get", argument1], check=True, stdout=subprocess.PIPE).stdout - if current.decode("utf-8").strip() == value: + process = subprocess.run(["/bin/nvram", "get", argument1], check=True, stdout=subprocess.PIPE) + if process.stdout.decode("utf-8").strip() == value: return pprint("/bin/nvram" + " " + "set" + " " + argument2) if not test: @@ -114,13 +114,13 @@ def write(key, value, unit, service, test=False): def connect(unit, test=False): - argument1 = "vpn" + "_" + "client" + unit + "_" + "state" + argument1 = "vpnclient" + unit argument2 = "start" + "_" + "vpnclient" + unit try: - pprint("/bin/nvram" + " " + "get" + " " + argument1) + pprint("/bin/pidof" + " " + argument1) if not test: - current = subprocess.run(["/bin/nvram", "get", argument1], check=True, stdout=subprocess.PIPE).stdout - if current.decode("utf-8").strip() in {"1", "2"}: # Connected + process = subprocess.run(["/bin/pidof", argument1]) + if process.returncode == 0: # Connected return pprint("/sbin/service" + " " + argument2) if not test: @@ -130,13 +130,13 @@ def connect(unit, test=False): def disconnect(unit, test=False): - argument1 = "vpn" + "_" + "client" + unit + "_" + "state" + argument1 = "vpnclient" + unit argument2 = "stop" + "_" + "vpnclient" + unit try: - pprint("/bin/nvram" + " " + "get" + " " + argument1) + pprint("/bin/pidof" + " " + argument1) if not test: - current = subprocess.run(["/bin/nvram", "get", argument1], check=True, stdout=subprocess.PIPE).stdout - if not current.decode("utf-8").strip() in {"1", "2"}: # Disconnected + process = subprocess.run(["/bin/pidof", argument1]) + if process.returncode == 1: # Disconnected return pprint("/sbin/service" + " " + argument2) if not test: