Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/cli/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from adapters import HTTPRequests
from cli.v2ray import V2RayHandler
from helpers import helpers
from helpers.windows_split_tunnel import stop_windows_split_tunnel

import mospy
import grpc
Expand All @@ -42,7 +43,7 @@ class NodeTreeData():
NodeTypes = {}
NodeHealth = {}
NodeFormula = {}

def __init__(self, node_tree):
if not node_tree:
self.NodeTree = Tree()
Expand Down Expand Up @@ -394,15 +395,14 @@ def CreateNodeTreeStructure(self, data, **kwargs):
continue

return NodeTreeBase

def return_denom(self, tokens):
for ibc_coin in IBCTokens.IBCCOINS:
for denom,ibc in ibc_coin.items():
if ibc in tokens:
tokens = tokens.replace(ibc, denom)

return tokens

def parse_coin_deposit(self, tokens):
UnitAmounts = []
tokenString = ""
Expand Down Expand Up @@ -600,6 +600,7 @@ def disconnect(v2ray):
if v2ray:
try:
if pltfrm == Arch.WINDOWS:
stop_windows_split_tunnel()
V2Ray = V2RayHandler(v2ray_tun2routes_connect_bash + " down")
chdir(MeileConfig.BASEBINDIR)
rc = V2Ray.kill_daemon()
Expand All @@ -615,6 +616,7 @@ def disconnect(v2ray):
else:

if pltfrm == Arch.WINDOWS:
stop_windows_split_tunnel()
with open(path.join(MeileConfig.BASEBINDIR, 'disconnect.bat'), 'w') as DISBATFILE:
DISBATFILE.write("%s /uninstalltunnelservice wg99\n" % MeileConfig.WIREGUARD_BIN)
DISBATFILE.write("TASKKILL /F /IM WireGuard.exe\n")
Expand All @@ -632,11 +634,9 @@ def disconnect(v2ray):
else:
CONFFILE = path.join(ConfParams.KEYRINGDIR, 'wg99.conf')
wg_downCMD = ['pkexec', 'env', 'PATH=%s' % ConfParams.PATH, 'wg-quick', 'down', CONFFILE]

proc1 = Popen(wg_downCMD)
proc1.wait(timeout=30)

proc_out,proc_err = proc1.communicate()
return proc1.returncode, False


36 changes: 32 additions & 4 deletions src/cli/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from cli.v2ray import V2RayHandler, V2RayConfiguration, V2RayFragmentConfiguration
from helpers.wireguard import WgKey
from helpers.helpers import resolve_address
from helpers.windows_split_tunnel import activate_windows_split_tunnel, prepare_windows_split_tunnel

import base64
import bcrypt
Expand Down Expand Up @@ -58,12 +59,13 @@ class HandleWalletFunctions():

def __init__(self, **kwargs):
super().__init__(**kwargs)

CONFIG = MeileConfig.read_configuration(MeileConfig.CONFFILE)
self.GRPC = CONFIG['network'].get('grpc', HTTParams.GRPC)
self.sdk = None
self.returncode = None
self.connected = {"v2ray_pid" : None, "result" : False, "status" : None, "session_id" : None}
self.split_tunnel_session = None

# Migrate existing wallet to v2
address = CONFIG['wallet'].get('address', None)
Expand All @@ -74,6 +76,31 @@ def __init__(self, **kwargs):
#if address and version < 200:
# print("Migrating Wallet...")
# self.__migrate_wallets()

def prepare_split_tunnel(self, conndesc):
self.split_tunnel_session = None
if platform.system() != Arch.WINDOWS:
return
try:
self.split_tunnel_session = prepare_windows_split_tunnel(MeileConfig.CONFFILE)
if self.split_tunnel_session:
conndesc.write("Preparing split tunneling...\n")
conndesc.flush()
except Exception as e:
print("Split tunneling preparation failed:", str(e))

def start_split_tunnel(self, conndesc):
if not self.split_tunnel_session:
return
try:
added_routes = activate_windows_split_tunnel(self.split_tunnel_session)
conndesc.write("Split tunneling enabled")
if added_routes:
conndesc.write(f" ({len(added_routes)} route(s) added)")
conndesc.write(".\n")
conndesc.flush()
except Exception as e:
print("Split tunneling start failed:", str(e))

@staticmethod
def decode_jwt_file(fpath: str, password: str) -> dict:
Expand Down Expand Up @@ -1231,6 +1258,8 @@ def connect(self,
"session_id" : session_id}
print(self.connected)
return

self.prepare_split_tunnel(conndesc)

if type == "WireGuard":
iface = "wg99"
Expand Down Expand Up @@ -1270,6 +1299,7 @@ def connect(self,
"result": True,
"status" : iface,
"session_id" : session_id}
self.start_split_tunnel(conndesc)
conndesc.write("Checking network connection...\n")
conndesc.flush()
sleep(1)
Expand Down Expand Up @@ -1338,6 +1368,7 @@ def connect(self,
"result": True,
"status" : tuniface,
"session_id" : session_id}
self.start_split_tunnel(conndesc)
else:
self.connected = {"v2ray_pid" : v2ray_handler.v2ray_pid,
"result": False,
Expand Down Expand Up @@ -1452,6 +1483,3 @@ def get_ip_address(self):
with open(path.join(ConfParams.KEYRINGDIR, 'ip-api.json'), 'w') as f:
f.write(json.dumps('{}'))
return False



16 changes: 16 additions & 0 deletions src/conf/meile_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def read_configuration(self, confpath):
self.CONFIG.set('network', 'fragment', '1')
self.CONFIG.set('network', 'dns', '1.1.1.1')
self.CONFIG.set('network', 'ringsessions', '0')
self.CONFIG.set('network', 'splittunnel', '0')
FILE = open(self.CONFFILE, 'w')
self.CONFIG.write(FILE)
FILE.close()
Expand Down Expand Up @@ -143,10 +144,25 @@ def read_configuration(self, confpath):
self.CONFIG.set('network', 'ringsessions', '1')
if self.CONFIG.has_option('network', 'ringsessions'):
self.CONFIG.set('network', 'ringsessions', '1')
if not self.CONFIG.has_option('network', 'splittunnel'):
self.CONFIG.set('network', 'splittunnel', '0')

FILE = open(self.CONFFILE, 'w')
self.CONFIG.write(FILE)
FILE.close()

if not self.CONFIG.has_section('split_tunnel'):
self.CONFIG.add_section('split_tunnel')
self.CONFIG.set('split_tunnel', 'apps', '[]')
FILE = open(self.CONFFILE, 'w')
self.CONFIG.write(FILE)
FILE.close()
else:
if not self.CONFIG.has_option('split_tunnel', 'apps'):
self.CONFIG.set('split_tunnel', 'apps', '[]')
FILE = open(self.CONFFILE, 'w')
self.CONFIG.write(FILE)
FILE.close()


return self.CONFIG
Loading