Skip to content

Commit

Permalink
better error message for security policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Aug 18, 2024
1 parent 7538169 commit c4227b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')


Expand Down
31 changes: 17 additions & 14 deletions glob/manager_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down

0 comments on commit c4227b1

Please sign in to comment.