Skip to content

Commit

Permalink
bugfix: Fixed the issue that any user can restart the service. Added …
Browse files Browse the repository at this point in the history
…admin_list parameter.
  • Loading branch information
GaiZhenbiao committed Sep 19, 2024
1 parent ffea5e9 commit 720c23d
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ChuanhuChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def create_greeting(request: gr.Request):
# Invisible elements
updateChuanhuBtn.click(
update_chuanhu,
[],
[user_name],
[status_display],
show_progress=True,
)
Expand Down
1 change: 1 addition & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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, //是否启用检查更新
Expand Down
3 changes: 2 additions & 1 deletion locale/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion locale/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,6 @@
"🗑️ 删除最新对话": "🗑️ 最新の会話削除",
"🗑️ 删除最旧对话": "🗑️ 最古の会話削除",
"🧹 新的对话": "🧹 新しい会話",
"o1_description": "o1シリーズの大規模言語モデルは、複雑な推論を行うために強化学習で訓練されています。o1モデルは回答する前に考え、ユーザーに応答する前に長い内部思考の連鎖を生成します。"
"o1_description": "o1シリーズの大規模言語モデルは、複雑な推論を行うために強化学習で訓練されています。o1モデルは回答する前に考え、ユーザーに応答する前に長い内部思考の連鎖を生成します。",
"no_permission_to_update_description": "アップデートの権限がありません。 管理者に連絡してください。 管理者の設定は、設定ファイルconfig.jsonのadmin_listにユーザー名を追加することで行います。"
}
3 changes: 2 additions & 1 deletion locale/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@
"🔙 恢复默认网络设置": "🔙 네트워크 설정 초기화",
"🗑️ 删除最新对话": "🗑️ 최신 대화 삭제",
"🗑️ 删除最旧对话": "🗑️ 가장 오래된 대화 삭제",
"🧹 新的对话": "🧹 새로운 대화"
"🧹 新的对话": "🧹 새로운 대화",
"no_permission_to_update_description": "업데이트할 수 있는 권한이 없습니다. 관리자에게 문의하세요. 관리자는 구성 파일 config.json의 admin_list에 사용자 아이디를 추가하여 구성합니다."
}
3 changes: 2 additions & 1 deletion locale/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@
"🔙 恢复默认网络设置": "🔙 Восстановить настройки сети по умолчанию",
"🗑️ 删除最新对话": "🗑️ Удалить последний диалог",
"🗑️ 删除最旧对话": "🗑️ Удалить старейший диалог",
"🧹 新的对话": "🧹 Новый диалог"
"🧹 新的对话": "🧹 Новый диалог",
"no_permission_to_update_description": "У вас нет разрешения на обновление. Пожалуйста, свяжитесь с администратором. Администратор настраивается путем добавления имени пользователя в список admin_list в файле config.json."
}
3 changes: 2 additions & 1 deletion locale/sv_SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion locale/vi_VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 2 additions & 1 deletion locale/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 中添加用户名。"
}
1 change: 1 addition & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,优先读环境变量的配置,如果存在则自动装配
Expand Down
6 changes: 4 additions & 2 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...")
Expand Down

0 comments on commit 720c23d

Please sign in to comment.