allow ssl with remote tunnel

This commit is contained in:
Concedo 2025-02-08 02:11:10 +08:00
parent 27b9358baf
commit b100bcb9e6

View file

@ -4655,6 +4655,7 @@ def setuptunnel(global_memory, has_sd):
import re
global sslvalid
httpsaffix = ("https" if sslvalid else "http")
ssladd = (" --no-tls-verify" if sslvalid else "")
def run_tunnel():
tunnelproc = None
tunneloutput = ""
@ -4662,16 +4663,16 @@ def setuptunnel(global_memory, has_sd):
time.sleep(0.2)
if os.name == 'nt':
print("Starting Cloudflare Tunnel for Windows, please wait...", flush=True)
tunnelproc = subprocess.Popen(f"cloudflared.exe tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
tunnelproc = subprocess.Popen(f"cloudflared.exe tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
elif sys.platform=="darwin":
print("Starting Cloudflare Tunnel for MacOS, please wait...", flush=True)
tunnelproc = subprocess.Popen(f"./cloudflared tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
tunnelproc = subprocess.Popen(f"./cloudflared tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
elif sys.platform == "linux" and platform.machine().lower() == "aarch64":
print("Starting Cloudflare Tunnel for ARM64 Linux, please wait...", flush=True)
tunnelproc = subprocess.Popen(f"./cloudflared-linux-arm64 tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
tunnelproc = subprocess.Popen(f"./cloudflared-linux-arm64 tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
else:
print("Starting Cloudflare Tunnel for Linux, please wait...", flush=True)
tunnelproc = subprocess.Popen(f"./cloudflared-linux-amd64 tunnel --url {httpsaffix}://localhost:{args.port}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
tunnelproc = subprocess.Popen(f"./cloudflared-linux-amd64 tunnel --url {httpsaffix}://localhost:{args.port}{ssladd}", text=True, encoding='utf-8', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
time.sleep(10)
def tunnel_reader():
nonlocal tunnelproc,tunneloutput,tunnelrawlog
@ -4929,7 +4930,7 @@ def analyze_gguf_model_wrapper(filename=""):
dumpthread.start()
def main(launch_args):
global args, showdebug, kcpp_instance, exitcounter, using_gui_launcher
global args, showdebug, kcpp_instance, exitcounter, using_gui_launcher, sslvalid
args = launch_args #note: these are NOT shared with the child processes!
if (args.version) and len(sys.argv) <= 2:
@ -5000,6 +5001,10 @@ def main(launch_args):
time.sleep(3)
sys.exit(2)
if args.ssl: #need to duplicate here for the tunnel
if len(args.ssl)==2 and isinstance(args.ssl[0], str) and os.path.exists(args.ssl[0]) and isinstance(args.ssl[1], str) and os.path.exists(args.ssl[1]):
sslvalid = True
# manager command queue
with multiprocessing.Manager() as mp_manager:
global_memory = mp_manager.dict({"tunnel_url": "", "restart_target":"", "input_to_exit":False})