From e59a5238eb95626d057c9c3c51beb24716b4c84a Mon Sep 17 00:00:00 2001 From: freqnik Date: Mon, 24 Apr 2023 16:39:00 -0400 Subject: [PATCH] Exception handling for unicode process names. Extend DNS resolver to 2s. Wait 3 seconds for wireguard interface to come up. --- src/cli/sentinel.py | 3 +-- src/conf/meile_config.py | 16 +++++++++++----- src/typedef/konstants.py | 2 +- src/ui/screens.py | 3 ++- src/ui/widgets.py | 20 ++++++++++---------- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/cli/sentinel.py b/src/cli/sentinel.py index 15f911b6..b161670a 100755 --- a/src/cli/sentinel.py +++ b/src/cli/sentinel.py @@ -41,7 +41,6 @@ def get_nodes(self, latency, *kwargs): k=1 - for line in proc.stdout.readlines(): line = str(line.decode('utf-8')) if k < 4: @@ -67,12 +66,12 @@ def get_nodes(self, latency, *kwargs): AllNodesInfo.append(dict(zip(NodeKeys.NodesInfoKeys, ninfos))) AllNodesInfoSorted = sorted(AllNodesInfo, key=lambda d: d[NodeKeys.NodesInfoKeys[4]]) - self.NodeTree = self.CreateNodeTreeStructure() for d in AllNodesInfoSorted: for key in NodeKeys.NodesInfoKeys: d[key] = d[key].lstrip().rstrip() + version = d[NodeKeys.NodesInfoKeys[10]].replace('.','') if version not in NodeKeys.NodeVersions: diff --git a/src/conf/meile_config.py b/src/conf/meile_config.py index 5bf76788..8f630ad9 100755 --- a/src/conf/meile_config.py +++ b/src/conf/meile_config.py @@ -22,11 +22,13 @@ def resource_path(self, relative_path): def process_exists(self, process_name): call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name - # use buildin check_output right away - output = subprocess.check_output(call).decode() - # check in last line for process name + try: + output = subprocess.check_output(call).decode('windows-1252') + except: + print("Decoding error, reverting....") + output = subprocess.check_output(call).decode(errors='ignore') + last_line = output.strip().split('\r\n')[-1] - # because Fail message could be translated return last_line.lower().startswith(process_name.lower()) def kill_process(self, process_name): @@ -38,7 +40,7 @@ def update_bin(self, from_path, to_path): if self.process_exists("WireGuard.exe"): print("WireGuard is running!") self.kill_process("WireGuard.exe") - sleep(5) + sleep(10) if path.exists(to_path): shutil.rmtree(to_path) shutil.copytree(from_path, to_path) @@ -47,7 +49,11 @@ def update_bin(self, from_path, to_path): shutil.rmtree(to_path) shutil.copytree(from_path, to_path) except Exception as e: + print("Process name codec error... Defaulting....") print(str(e)) + if path.exists(to_path): + shutil.rmtree(to_path) + shutil.copytree(from_path, to_path) def rewrite_bin(self): self.update_bin(self.resource_path("bin"), self.BASEBINDIR) diff --git a/src/typedef/konstants.py b/src/typedef/konstants.py index 1f65a2eb..b05bccdf 100755 --- a/src/typedef/konstants.py +++ b/src/typedef/konstants.py @@ -42,7 +42,7 @@ class IBCTokens(): class TextStrings(): dash = "-" - VERSION = "v1.6.2" + VERSION = "v1.6.3" class MeileColors(): DIALOG_BG_COLOR = "#121212" diff --git a/src/ui/screens.py b/src/ui/screens.py index e68e906c..def64c13 100755 --- a/src/ui/screens.py +++ b/src/ui/screens.py @@ -202,6 +202,7 @@ def __init__(self, **kwargs): def RewriteBIN(self): MeileConfig = MeileGuiConfig() MeileConfig.rewrite_bin() + def CreateWarpConfig(self): MeileConfig = MeileGuiConfig() CONFIG = MeileConfig.read_configuration(MeileGuiConfig.CONFFILE) @@ -544,7 +545,7 @@ def get_ip_address(self, dt): self.old_ip = self.ip try: # First check DNS can resolv - resolver = DNSRequests.MakeDNSRequest(domain=ICANHAZDNS, timeout=1, lifetime=1.2) + resolver = DNSRequests.MakeDNSRequest(domain=ICANHAZDNS, timeout=1.7, lifetime=2) icanhazip = resolver.DNSRequest() if icanhazip: print("%s:%s" % (ICANHAZDNS, icanhazip)) diff --git a/src/ui/widgets.py b/src/ui/widgets.py index 8ef792cd..1456b186 100755 --- a/src/ui/widgets.py +++ b/src/ui/widgets.py @@ -26,6 +26,7 @@ from urllib3.exceptions import InsecureRequestWarning from os import path from subprocess import Popen, TimeoutExpired +from time import sleep import requests import re @@ -642,6 +643,7 @@ def UpdateQuotaForNode(self, ID, naddress,BytesDict, dt): pass def init_GetConsumedWhileConnected(self, sConsumed): + sleep(3) try: bytes_sent = round(float(float(psutil.net_io_counters(pernic=True)['wg99'].bytes_sent) / 1073741824),3) bytes_recvd = round(float(float(psutil.net_io_counters(pernic=True)['wg99'].bytes_recv) / 1073741824),3) @@ -653,6 +655,10 @@ def init_GetConsumedWhileConnected(self, sConsumed): IFACE = iface print(IFACE) break + elif "wg" in iface: + IFACE = iface + print(IFACE) + break try: bytes_sent = round(float(float(psutil.net_io_counters(pernic=True)[IFACE].bytes_sent) / 1073741824),3) bytes_recvd = round(float(float(psutil.net_io_counters(pernic=True)[IFACE].bytes_recv) / 1073741824),3) @@ -662,16 +668,6 @@ def init_GetConsumedWhileConnected(self, sConsumed): print(str(e)) return {'sent': 0, 'rcvd' : 0} - ''' - try: - bytes_sent = round(float(float(psutil.net_io_counters(pernic=True)['wg99'].bytes_sent) / 1073741824),3) - bytes_recvd = round(float(float(psutil.net_io_counters(pernic=True)['wg99'].bytes_recv) / 1073741824),3) - - return {'sent' : bytes_sent, "rcvd" : bytes_recvd} - except Exception as e: - return {'sent' : 0, "rcvd" : 0} - - ''' def GetConsumedWhileConnected(self, sConsumed, Bytes): try: bytes_sent = round(float(float(float(psutil.net_io_counters(pernic=True)['wg99'].bytes_sent) / 1073741824) - Bytes['sent']),3) @@ -683,6 +679,10 @@ def GetConsumedWhileConnected(self, sConsumed, Bytes): if "tun" in iface: IFACE = iface break + elif "wg" in iface: + IFACE = iface + break + try: bytes_sent = round(float(float(float(psutil.net_io_counters(pernic=True)[IFACE].bytes_sent) / 1073741824) - Bytes['sent']),3)