Skip to content
Merged
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ rsa==4.9
safe-pysha3==1.0.4
screeninfo==0.8.1
SecretStorage==3.3.3
sentinel-sdk==0.1.1
sentinel_protobuf==0.5.1
sentinel_sdk==0.1.4
six==1.16.0
sniffio==1.3.1
stripe==4.2.0
Expand Down
6 changes: 3 additions & 3 deletions src/bin/routes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ if [[ ${STATE} = "up" ]]; then
# start v2ray
echo "Running xray: /home/${USER}/.meile-gui/bin/v2ray run -c /home/${USER}/.meile-gui/v2ray_config.json &"
/home/${USER}/.meile-gui/bin/xray run -c /home/${USER}/.meile-gui/v2ray_config.json &
sleep 3
sleep 1

# get v2ray proxy IP
PROXY_IP=`cat /home/${USER}/.meile-gui/v2ray.proxy`
#echo ${PROXY_IP} > /home/${USER}/.meile-gui/v2ray.proxy
echo "Proxy IP: ${PROXY_IP}"
sleep 2
sleep 1

# add tun interface
TUNID=${RANDOM}
Expand Down Expand Up @@ -64,7 +64,7 @@ if [[ ${STATE} = "up" ]]; then
echo "Routing table: "
ip route show

sleep 3
sleep 1
echo "-----------------------_CURLING_---------------------------"
curl https://icanhazip.com
else
Expand Down
Binary file removed src/bin/sentinelcli
Binary file not shown.
77 changes: 58 additions & 19 deletions src/cli/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from dataclasses import dataclass
import sys
import os
import tempfile
import socket, time

from conf.meile_config import MeileGuiConfig
from helpers.helpers import wait_for_port

# Platform-conditional imports
if sys.platform == 'win32':
Expand All @@ -22,6 +25,7 @@
elif sys.platform.startswith('linux'):
import psutil
from typedef.konstants import ConfParams
import threading

# ---------------------------------------------------------------------------
# V2RayHandler – one class per platform, selected at the bottom of this
Expand Down Expand Up @@ -50,15 +54,47 @@ def fork_v2ray(self):

self.v2ray_pid = v2ray_srvc_proc.pid



def start_daemon(self):
'''

print("Starting v2ray service...")

multiprocessing.get_context('fork')
warp_fork = Process(target=self.fork_v2ray)
warp_fork.run()
sleep(1.5)
return True
ok = wait_for_port(host="127.0.0.1", port=1080, timeout=120)
if ok:
return True
else:
return False
'''
print("Starting v2ray service...")

try:
self.fork_v2ray()
except Exception as e:
print(f"[start_daemon] fork_v2ray failed: {e!r}")
return False

result = {"ok": False}

def worker():
try:
result["ok"] = wait_for_port("127.0.0.1", 1080, timeout=120)
except Exception as e:
print(f"[start_daemon] worker error: {e!r}")
result["ok"] = False

t = threading.Thread(target=worker, daemon=True)
t.start()

while t.is_alive():
print(".", end="", flush=True)
time.sleep(0.3)

return result["ok"]

def kill_daemon(self):
v2ray_daemon_cmd = (
Expand Down Expand Up @@ -253,8 +289,8 @@ def read_v2ray_config(self):
class _DarwinV2RayHandler:
v2ray_pid = 0

def __init__(self, script, **kwargs):
self.script_path = script
def __init__(self, script_path, **kwargs):
self.script_path = script_path
self.processes = []
self.MeileConfig = MeileGuiConfig()

Expand Down Expand Up @@ -325,25 +361,33 @@ def run_cmd(self, cmd, background=False):

def start_daemon(self):
print("Starting v2ray service...")
PLIST_DIR = os.path.expanduser("~/.meile-gui/launchd")
xray_plist = f"{PLIST_DIR}/app.meile.xray.plist"
tun2_plist = f"{PLIST_DIR}/app.meile.tun2socks.plist"

privileged_commands = [
"launchctl bootstrap system"
" /Library/LaunchDaemons/app.meile.xray.plist"
'mkdir -p "/Library/Application Support/Meile/launchd"',
f'cp "{xray_plist}" "/Library/Application Support/Meile/launchd/"',
f'cp "{tun2_plist}" "/Library/Application Support/Meile/launchd/"',
'chown -R root:wheel "/Library/Application Support/Meile"',
'chmod 755 "/Library/Application Support/Meile" "/Library/Application Support/Meile/launchd"',
'chmod 644 "/Library/Application Support/Meile/launchd/"*.plist',
"rm -rf /Library/LaunchDaemons/app.meile.tun2socks.plist",
"rm -rf /Library/LaunchDaemons/app.meile.wireguard.plist",
"rm -rf /Library/LaunchDaemons/app.meile.xray.plist",
"launchctl enable system/app.meile.xray",
'launchctl bootstrap system "/Library/Application Support/Meile/launchd/app.meile.xray.plist"',
]
privileged_commands.append("sleep 3")
privileged_commands.append(
"curl --preproxy socks5://localhost:1080"
" -s https://icanhazip.com"
)
privileged_commands.append("sleep 1")
privileged_commands.append(
"launchctl bootstrap system"
" /Library/LaunchDaemons/app.meile.tun2socks.plist"
)
privileged_commands.append(f"launchctl enable system/app.meile.tun2socks")
privileged_commands.append(f'launchctl bootstrap system "/Library/Application Support/Meile/launchd/app.meile.tun2socks.plist"')
privileged_commands.append("sleep 2")
privileged_commands.append(
"ifconfig utun123 198.18.0.1 198.18.0.1 up"
)
privileged_commands.append("ifconfig utun123 198.18.0.1 198.18.0.1 up")

networks = [
"1.0.0.0/8",
Expand Down Expand Up @@ -391,12 +435,7 @@ def kill_daemon(self):
privileged_commands.append(
"ifconfig utun123 198.18.0.1 198.18.0.1 down"
)
privileged_commands.append(
"launchctl bootout system"
" /Library/LaunchDaemons/app.meile.xray.plist"
" ; launchctl bootout system"
" /Library/LaunchDaemons/app.meile.tun2socks.plist"
)
privileged_commands.append(f'launchctl bootout system "/Library/Application Support/Meile/launchd/app.meile.xray.plist" ; launchctl bootout system "/Library/Application Support/Meile/launchd/app.meile.tun2socks.plist" ; launchctl disable system/app.meile.xray ; launchctl disable system/app.meile.tun2socks')

self.run_privileged_script(privileged_commands)

Expand Down
Loading