From 605fde2d7cdcc8d1a6041e9c0fe5e4b6cd12c432 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Mon, 6 Jul 2026 17:21:47 +0800 Subject: [PATCH] feat: add SSL support --- config/deploy.template-cn.yaml | 8 ++++++++ config/deploy.template.yaml | 8 ++++++++ deploy/Windows/config.py | 2 ++ deploy/Windows/template.yaml | 8 ++++++++ gui.py | 21 ++++++++++++++++++++- webapp/packages/main/public/deploy.yaml.tpl | 8 ++++++++ 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/config/deploy.template-cn.yaml b/config/deploy.template-cn.yaml index c36ca93..c12d0ff 100644 --- a/config/deploy.template-cn.yaml +++ b/config/deploy.template-cn.yaml @@ -157,6 +157,14 @@ Deploy: # '["alas"]' specified "alas" config # '["alas","alas2"]' specified "alas" "alas2" configs Run: null + # SSL support + # Only effective when both parameters below are set + # --ssl-key. Path to SSL key file + # [Default] null (no SSL) + WebuiSSLKey: null + # --ssl-cert. Path to SSL cert file + # [Default] null (no SSL) + WebuiSSLCert: null # To update app.asar # [In most cases] true AppAsarUpdate: true diff --git a/config/deploy.template.yaml b/config/deploy.template.yaml index ad137cb..1ce349d 100644 --- a/config/deploy.template.yaml +++ b/config/deploy.template.yaml @@ -157,6 +157,14 @@ Deploy: # '["alas"]' specified "alas" config # '["alas","alas2"]' specified "alas" "alas2" configs Run: null + # SSL support + # Only effective when both parameters below are set + # --ssl-key. Path to SSL key file + # [Default] null (no SSL) + WebuiSSLKey: null + # --ssl-cert. Path to SSL cert file + # [Default] null (no SSL) + WebuiSSLCert: null # To update app.asar # [In most cases] true AppAsarUpdate: true diff --git a/deploy/Windows/config.py b/deploy/Windows/config.py index 64edf7e..48f5731 100644 --- a/deploy/Windows/config.py +++ b/deploy/Windows/config.py @@ -57,6 +57,8 @@ class ConfigModel: # Webui WebuiHost: str = "0.0.0.0" WebuiPort: int = 23467 + WebuiSSLKey: Optional[str] = None + WebuiSSLCert: Optional[str] = None Language: str = "en-US" Theme: str = "default" DpiScaling: bool = True diff --git a/deploy/Windows/template.yaml b/deploy/Windows/template.yaml index 2dab174..c375c97 100644 --- a/deploy/Windows/template.yaml +++ b/deploy/Windows/template.yaml @@ -157,6 +157,14 @@ Deploy: # '["alas"]' specified "alas" config # '["alas","alas2"]' specified "alas" "alas2" configs Run: null + # SSL support + # Only effective when both parameters below are set + # --ssl-key. Path to SSL key file + # [Default] null (no SSL) + WebuiSSLKey: null + # --ssl-cert. Path to SSL cert file + # [Default] null (no SSL) + WebuiSSLCert: null # To update app.asar # [In most cases] true AppAsarUpdate: true diff --git a/gui.py b/gui.py index 776ed9f..89905c9 100644 --- a/gui.py +++ b/gui.py @@ -40,6 +40,12 @@ def func(ev: threading.Event): parser.add_argument( "--electron", action="store_true", help="Runs by electron client." ) + parser.add_argument( + "--ssl-key", dest="ssl_key", type=str, help="SSL key file path for HTTPS support" + ) + parser.add_argument( + "--ssl-cert", type=str, help="SSL certificate file path for HTTPS support" + ) parser.add_argument( "--run", nargs="+", @@ -50,11 +56,15 @@ def func(ev: threading.Event): host = args.host or State.deploy_config.WebuiHost or "0.0.0.0" port = args.port or int(State.deploy_config.WebuiPort) or 23467 + ssl_key = args.ssl_key or State.deploy_config.WebuiSSLKey + ssl_cert = args.ssl_cert or State.deploy_config.WebuiSSLCert + ssl = ssl_key is not None and ssl_cert is not None State.electron = args.electron logger.hr("Launcher config") logger.attr("Host", host) logger.attr("Port", port) + logger.attr("SSL", ssl) logger.attr("Electron", args.electron) logger.attr("Reload", ev is not None) @@ -64,7 +74,16 @@ def func(ev: threading.Event): from module.logger.logger import console_hdlr logger.removeHandler(console_hdlr) - uvicorn.run("module.webui.app:app", host=host, port=port, factory=True) + if ssl_cert is None and ssl_key is not None: + logger.error("SSL key provided without certificate. Please provide both SSL key and certificate.") + elif ssl_key is None and ssl_cert is not None: + logger.error("SSL certificate provided without key. Please provide both SSL key and certificate.") + + if ssl: + uvicorn.run("module.webui.app:app", host=host, port=port, factory=True, ssl_keyfile=ssl_key, + ssl_certfile=ssl_cert) + else: + uvicorn.run("module.webui.app:app", host=host, port=port, factory=True) if __name__ == "__main__": diff --git a/webapp/packages/main/public/deploy.yaml.tpl b/webapp/packages/main/public/deploy.yaml.tpl index 0b823a6..b80b5c4 100644 --- a/webapp/packages/main/public/deploy.yaml.tpl +++ b/webapp/packages/main/public/deploy.yaml.tpl @@ -157,6 +157,14 @@ Deploy: # '["alas"]' specified "alas" config # '["alas","alas2"]' specified "alas" "alas2" configs Run: null + # SSL support + # Only effective when both parameters below are set + # --ssl-key. Path to SSL key file + # [Default] null (no SSL) + WebuiSSLKey: null + # --ssl-cert. Path to SSL cert file + # [Default] null (no SSL) + WebuiSSLCert: null # To update app.asar # [In most cases] true AppAsarUpdate: true