Skip to content

Commit

Permalink
Exception handling for unicode process names. Extend DNS resolver to …
Browse files Browse the repository at this point in the history
…2s. Wait 3 seconds for wireguard interface to come up.
  • Loading branch information
freQniK committed Apr 24, 2023
1 parent 9d6a72e commit e59a523
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/cli/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
16 changes: 11 additions & 5 deletions src/conf/meile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/typedef/konstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IBCTokens():

class TextStrings():
dash = "-"
VERSION = "v1.6.2"
VERSION = "v1.6.3"

class MeileColors():
DIALOG_BG_COLOR = "#121212"
Expand Down
3 changes: 2 additions & 1 deletion src/ui/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions src/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit e59a523

Please sign in to comment.