Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ curl --location 'http://127.0.0.1:5005/v1/chat/completions' \

## 官网原生镜像

1. 配置环境变量 `ENABLE_GATEWAY` 为 `true`,然后运行程序, 注意开启后别人也可以直接通过域名访问你的网关。
1. 配置环境变量 `ENABLE_GATEWAY` 为 `true`,然后运行程序, 注意开启后别人也可以直接通过域名访问你的网关,镜像站可以设置 SITE_PASSWORD 参数进行密码访问

2. 在 Tokens 管理页面上传 `RefreshToken` 或 `AccessToken`

Expand All @@ -127,6 +127,7 @@ curl --location 'http://127.0.0.1:5005/v1/chat/completions' \
| 安全相关 | API_PREFIX | `your_prefix` | `None` | API 前缀密码,不设置容易被人访问,设置后需请求 `/your_prefix/v1/chat/completions` |
| | AUTHORIZATION | `your_first_authorization`,<br/>`your_second_authorization` | `[]` | 你自己为使用多账号轮询 Tokens 设置的授权码,英文逗号分隔 |
| | AUTH_KEY | `your_auth_key` | `None` | 私人网关需要加`auth_key`请求头才设置该项 |
| | SITE_PASSWORD | `your_site_password` | `None` | 镜像站可以设置密码访问 |
| 请求相关 | CHATGPT_BASE_URL | `https://chatgpt.com` | `https://chatgpt.com` | ChatGPT 网关地址,设置后会改变请求的网站,多个网关用逗号分隔 |
| | PROXY_URL | `http://ip:port`,<br/>`http://username:password@ip:port` | `[]` | 全局代理 URL,出 403 时启用,多个代理用逗号分隔 |
| | EXPORT_PROXY_URL | `http://ip:port`或<br/>`http://username:password@ip:port` | `None` | 出口代理 URL,防止请求图片和文件时泄漏源站 ip |
Expand Down
8 changes: 6 additions & 2 deletions gateway/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from fastapi import Request
from fastapi.responses import HTMLResponse

Expand All @@ -6,5 +7,8 @@

@app.get("/login", response_class=HTMLResponse)
async def login_html(request: Request):
response = templates.TemplateResponse("login.html", {"request": request})
return response
site_password = os.environ.get('SITE_PASSWORD', '')
return templates.TemplateResponse("login.html", {
"request": request,
"site_password": site_password
})
17 changes: 17 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录</title>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.18/layui.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.18/css/layui.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
#popup {
display: none;
}
#site_password {
display: none;
}
</style>
</head>
<body class="bg-gradient-to-br from-blue-300 via-indigo-300 to-purple-400 min-h-screen flex items-center justify-center">
<div class="bg-white p-8 rounded-xl shadow-2xl w-96 max-w-md">
<h2 class="text-3xl font-bold text-center text-gray-800 mb-4">登录</h2>
<!-- 新增密码输入框 -->
<input type="password" id="site_password" class="w-full p-2 mb-4 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-400" placeholder="请输入密码">
<button
type="button"
onclick="openPopup()"
Expand Down Expand Up @@ -64,7 +71,17 @@ <h2 class="text-3xl font-bold text-center text-gray-800 mb-4">登录</h2>
</div>

<script>
const site_password = "{{ site_password }}";
if (!!site_password) {
document.getElementById('site_password').style.display = 'block';
}

function openPopup() {
const inputPwd = document.getElementById('site_password').value;
if (!!site_password && inputPwd !== site_password) {
window.layer.msg("啊噢...密码错误!", {icon: 2, time: 1500, offset: '20px'});
return;
}
document.getElementById('popup').style.display = 'flex';
}

Expand Down