From c4227b17e525ae5e949212e13bb8741e9650a099 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Sun, 18 Aug 2024 12:36:02 +0900 Subject: [PATCH] better error message for security policy https://github.com/ltdrdata/ComfyUI-Manager/issues/975#issuecomment-2294810500 --- glob/manager_core.py | 2 +- glob/manager_server.py | 31 +++++++++++++++++-------------- pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/glob/manager_core.py b/glob/manager_core.py index 2076e581..c1f6a10a 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -23,7 +23,7 @@ import cm_global from manager_util import * -version = [2, 50] +version = [2, 50, 1] version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') diff --git a/glob/manager_server.py b/glob/manager_server.py index 648eaaa8..e2f8989e 100644 --- a/glob/manager_server.py +++ b/glob/manager_server.py @@ -20,6 +20,9 @@ comfy_ui_hash = "-" +SECURITY_MESSAGE_MIDDLE_OR_BELOW = f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy" +SECURITY_MESSAGE_NORMAL_MINUS = f"ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy" +SECURITY_MESSAGE_GENERAL = f"ERROR: This installation is not allowed in this security_level. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy" def handle_stream(stream, prefix): stream.reconfigure(encoding=locale.getpreferredencoding(), errors='replace') @@ -390,7 +393,7 @@ async def fetch_updates(request): @PromptServer.instance.routes.get("/customnode/update_all") async def update_all(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) try: @@ -592,7 +595,7 @@ async def get_snapshot_list(request): @PromptServer.instance.routes.get("/snapshot/remove") async def remove_snapshot(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) try: @@ -610,7 +613,7 @@ async def remove_snapshot(request): @PromptServer.instance.routes.get("/snapshot/restore") async def remove_snapshot(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) try: @@ -779,14 +782,14 @@ def copy_set_active(files, is_disable, js_path_name='.'): @PromptServer.instance.routes.post("/customnode/install") async def install_custom_node(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) json_data = await request.json() risky_level = await get_risky_level(json_data['files']) if not is_allowed_security_level(risky_level): - print(f"ERROR: This installation is not allowed in this security_level. Please contact the administrator.") + print(SECURITY_MESSAGE_GENERAL) return web.Response(status=404) install_type = json_data['install_type'] @@ -826,7 +829,7 @@ async def install_custom_node(request): @PromptServer.instance.routes.post("/customnode/fix") async def fix_custom_node(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) json_data = await request.json() @@ -864,7 +867,7 @@ async def fix_custom_node(request): @PromptServer.instance.routes.post("/customnode/install/git_url") async def install_custom_node_git_url(request): if not is_allowed_security_level('high'): - print(f"ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.") + print(SECURITY_MESSAGE_NORMAL_MINUS) return web.Response(status=403) url = await request.text() @@ -880,7 +883,7 @@ async def install_custom_node_git_url(request): @PromptServer.instance.routes.post("/customnode/install/pip") async def install_custom_node_git_url(request): if not is_allowed_security_level('high'): - print(f"ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.") + print(SECURITY_MESSAGE_NORMAL_MINUS) return web.Response(status=403) packages = await request.text() @@ -892,7 +895,7 @@ async def install_custom_node_git_url(request): @PromptServer.instance.routes.post("/customnode/uninstall") async def uninstall_custom_node(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) json_data = await request.json() @@ -920,7 +923,7 @@ async def uninstall_custom_node(request): @PromptServer.instance.routes.post("/customnode/update") async def update_custom_node(request): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) json_data = await request.json() @@ -992,7 +995,7 @@ async def install_model(request): model_path = get_model_path(json_data) if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) if not json_data['filename'].endswith('.safetensors') and not is_allowed_security_level('high'): @@ -1005,7 +1008,7 @@ async def install_model(request): break if not is_belongs_to_whitelist: - print(f"ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.") + print(SECURITY_MESSAGE_NORMAL_MINUS) return web.Response(status=403) res = False @@ -1055,7 +1058,7 @@ def write_stdout(self, msg): @PromptServer.instance.routes.get("/manager/terminal") async def terminal_mode(request): if not is_allowed_security_level('high'): - print(f"ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.") + print(SECURITY_MESSAGE_NORMAL_MINUS) return web.Response(status=403) if "mode" in request.rel_url.query: @@ -1197,7 +1200,7 @@ async def get_notice(request): @PromptServer.instance.routes.get("/manager/reboot") def restart(self): if not is_allowed_security_level('middle'): - print(f"ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.") + print(SECURITY_MESSAGE_MIDDLE_OR_BELOW) return web.Response(status=403) try: diff --git a/pyproject.toml b/pyproject.toml index 7f6fad79..9f8c7a8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-manager" description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." -version = "2.50" +version = "2.50.1" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]