From 720c23d755a4a955dcb0a54e8c200a2247a27f8b Mon Sep 17 00:00:00 2001 From: Tuchuanhuhuhu Date: Thu, 19 Sep 2024 19:21:55 +0800 Subject: [PATCH] bugfix: Fixed the issue that any user can restart the service. Added admin_list parameter. --- ChuanhuChatbot.py | 2 +- config_example.json | 1 + locale/en_US.json | 3 ++- locale/ja_JP.json | 3 ++- locale/ko_KR.json | 3 ++- locale/ru_RU.json | 3 ++- locale/sv_SE.json | 3 ++- locale/vi_VN.json | 3 ++- locale/zh_CN.json | 3 ++- modules/config.py | 1 + modules/utils.py | 6 ++++-- 11 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChuanhuChatbot.py b/ChuanhuChatbot.py index 3fdc2bba..8ea2abd8 100644 --- a/ChuanhuChatbot.py +++ b/ChuanhuChatbot.py @@ -781,7 +781,7 @@ def create_greeting(request: gr.Request): # Invisible elements updateChuanhuBtn.click( update_chuanhu, - [], + [user_name], [status_display], show_progress=True, ) diff --git a/config_example.json b/config_example.json index b6eb8edd..43df4663 100644 --- a/config_example.json +++ b/config_example.json @@ -33,6 +33,7 @@ //== 基础配置 == "language": "auto", // 界面语言,可选"auto", "zh_CN", "en_US", "ja_JP", "ko_KR", "sv_SE", "ru_RU", "vi_VN" "users": [], // 用户列表,[["用户名1", "密码1"], ["用户名2", "密码2"], ...] + "admin_list": [], // 管理员列表,["用户名1", "用户名2", ...] 只有管理员可以重启服务 "local_embedding": false, //是否在本地编制索引 "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史 "check_update": true, //是否启用检查更新 diff --git a/locale/en_US.json b/locale/en_US.json index c314cf3b..c8c62897 100644 --- a/locale/en_US.json +++ b/locale/en_US.json @@ -280,5 +280,6 @@ "chuanhu_question_4": "Any new trends on TikTok?", "gpt4o_description": "OpenAI's most advanced, multimodal flagship model that’s cheaper and faster than GPT-4 Turbo.", "gpt4omini_description": "OpenAI's affordable and intelligent small model for fast, lightweight tasks.", - "o1_description": "The o1 series of large language models are trained with reinforcement learning to perform complex reasoning. o1 models think before they answer, producing a long internal chain of thought before responding to the user." + "o1_description": "The o1 series of large language models are trained with reinforcement learning to perform complex reasoning. o1 models think before they answer, producing a long internal chain of thought before responding to the user.", + "no_permission_to_update_description": "You do not have permission to update. Please contact the administrator. The administrator's configuration method is to add the username to the admin_list in the configuration file config.json." } \ No newline at end of file diff --git a/locale/ja_JP.json b/locale/ja_JP.json index a891b363..7bcea7df 100644 --- a/locale/ja_JP.json +++ b/locale/ja_JP.json @@ -194,5 +194,6 @@ "🗑️ 删除最新对话": "🗑️ 最新の会話削除", "🗑️ 删除最旧对话": "🗑️ 最古の会話削除", "🧹 新的对话": "🧹 新しい会話", - "o1_description": "o1シリーズの大規模言語モデルは、複雑な推論を行うために強化学習で訓練されています。o1モデルは回答する前に考え、ユーザーに応答する前に長い内部思考の連鎖を生成します。" + "o1_description": "o1シリーズの大規模言語モデルは、複雑な推論を行うために強化学習で訓練されています。o1モデルは回答する前に考え、ユーザーに応答する前に長い内部思考の連鎖を生成します。", + "no_permission_to_update_description": "アップデートの権限がありません。 管理者に連絡してください。 管理者の設定は、設定ファイルconfig.jsonのadmin_listにユーザー名を追加することで行います。" } \ No newline at end of file diff --git a/locale/ko_KR.json b/locale/ko_KR.json index 2b8a13e4..0c5aaa3a 100644 --- a/locale/ko_KR.json +++ b/locale/ko_KR.json @@ -193,5 +193,6 @@ "🔙 恢复默认网络设置": "🔙 네트워크 설정 초기화", "🗑️ 删除最新对话": "🗑️ 최신 대화 삭제", "🗑️ 删除最旧对话": "🗑️ 가장 오래된 대화 삭제", - "🧹 新的对话": "🧹 새로운 대화" + "🧹 新的对话": "🧹 새로운 대화", + "no_permission_to_update_description": "업데이트할 수 있는 권한이 없습니다. 관리자에게 문의하세요. 관리자는 구성 파일 config.json의 admin_list에 사용자 아이디를 추가하여 구성합니다." } \ No newline at end of file diff --git a/locale/ru_RU.json b/locale/ru_RU.json index af343cd6..b8db1825 100644 --- a/locale/ru_RU.json +++ b/locale/ru_RU.json @@ -193,5 +193,6 @@ "🔙 恢复默认网络设置": "🔙 Восстановить настройки сети по умолчанию", "🗑️ 删除最新对话": "🗑️ Удалить последний диалог", "🗑️ 删除最旧对话": "🗑️ Удалить старейший диалог", - "🧹 新的对话": "🧹 Новый диалог" + "🧹 新的对话": "🧹 Новый диалог", + "no_permission_to_update_description": "У вас нет разрешения на обновление. Пожалуйста, свяжитесь с администратором. Администратор настраивается путем добавления имени пользователя в список admin_list в файле config.json." } \ No newline at end of file diff --git a/locale/sv_SE.json b/locale/sv_SE.json index 134bef39..36ae7c59 100644 --- a/locale/sv_SE.json +++ b/locale/sv_SE.json @@ -193,5 +193,6 @@ "🔙 恢复默认网络设置": "🔙 Återställ standardnätverksinställningar+", "🗑️ 删除最新对话": "🗑️ Ta bort senaste dialogen", "🗑️ 删除最旧对话": "🗑️ Ta bort äldsta dialogen", - "🧹 新的对话": "🧹 Ny Dialog" + "🧹 新的对话": "🧹 Ny Dialog", + "no_permission_to_update_description": "Du har inte behörighet att uppdatera. Vänligen kontakta administratören. Administratören konfigureras genom att lägga till användarnamnet i admin_list i konfigurationsfilen config.json." } \ No newline at end of file diff --git a/locale/vi_VN.json b/locale/vi_VN.json index fa9c68a7..152925a8 100644 --- a/locale/vi_VN.json +++ b/locale/vi_VN.json @@ -193,5 +193,6 @@ "🔙 恢复默认网络设置": "🔙 Khôi phục cài đặt mạng mặc định", "🗑️ 删除最新对话": "🗑️ Xóa cuộc trò chuyện mới nhất", "🗑️ 删除最旧对话": "🗑️ Xóa cuộc trò chuyện cũ nhất", - "🧹 新的对话": "🧹 Cuộc trò chuyện mới" + "🧹 新的对话": "🧹 Cuộc trò chuyện mới", + "no_permission_to_update_description": "Bạn không có quyền cập nhật. Vui lòng liên hệ với quản trị viên. Cách cấu hình của quản trị viên là thêm tên người dùng vào danh sách admin_list trong tệp cấu hình config.json." } \ No newline at end of file diff --git a/locale/zh_CN.json b/locale/zh_CN.json index 4c2432a9..b5b6b6a2 100644 --- a/locale/zh_CN.json +++ b/locale/zh_CN.json @@ -22,5 +22,6 @@ "chuanhu_question_4": "TikTok 上有什么新梗?", "gpt4o_description": "OpenAI 的最先进的多模态旗舰模型,比 GPT-4 Turbo 更便宜、更快。", "gpt4omini_description": "OpenAI 的经济实惠且智能的小型模型,适用于快速、轻量级任务。", - "o1_description": "o1 系列的大型语言模型通过强化学习训练,能够执行复杂的推理任务。o1 模型在回答之前会进行思考,产生一长串内部思维链,然后再回应用户。" + "o1_description": "o1 系列的大型语言模型通过强化学习训练,能够执行复杂的推理任务。o1 模型在回答之前会进行思考,产生一长串内部思维链,然后再回应用户。", + "no_permission_to_update_description": "你没有权限更新。请联系管理员。管理员的配置方式为在配置文件 config.json 中的 admin_list 中添加用户名。" } \ No newline at end of file diff --git a/modules/config.py b/modules/config.py index f93fad59..b0945fff 100644 --- a/modules/config.py +++ b/modules/config.py @@ -190,6 +190,7 @@ def load_config_to_environ(key_list): shared.state.set_api_key_queue(api_key_list) auth_list = config.get("users", []) # 实际上是使用者的列表 +admin_list = config.get("admin_list", []) # 管理员列表 authflag = len(auth_list) > 0 # 是否开启认证的状态值,改为判断auth_list长度 # 处理自定义的api_host,优先读环境变量的配置,如果存在则自动装配 diff --git a/modules/utils.py b/modules/utils.py index f2baefad..e6b12b01 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -27,7 +27,7 @@ from modules.presets import * from . import shared -from modules.config import retrieve_proxy, hide_history_when_not_logged_in +from modules.config import retrieve_proxy, hide_history_when_not_logged_in, admin_list if TYPE_CHECKING: from typing import TypedDict @@ -741,7 +741,9 @@ def transfer_input(inputs): ) -def update_chuanhu(): +def update_chuanhu(username): + if username not in admin_list: + return gr.Markdown(value=i18n("no_permission_to_update_description")) from .repo import background_update print("[Updater] Trying to update...")