feat: Implement system configuration page for site settings and proxy management, and add team registration functionality.
This commit is contained in:
@@ -160,6 +160,7 @@ func startServer(cfg *config.Config) {
|
||||
mux.HandleFunc("/api/team-reg/status", api.CORS(api.HandleTeamRegStatus))
|
||||
mux.HandleFunc("/api/team-reg/logs", api.HandleTeamRegLogs) // SSE
|
||||
mux.HandleFunc("/api/team-reg/import", api.CORS(api.HandleTeamRegImport))
|
||||
mux.HandleFunc("/api/team-reg/clear-logs", api.CORS(api.HandleTeamRegClearLogs))
|
||||
|
||||
// 嵌入的前端静态文件
|
||||
if web.IsEmbedded() {
|
||||
@@ -216,21 +217,23 @@ func handleConfig(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
api.Success(w, map[string]interface{}{
|
||||
"port": config.Global.Port,
|
||||
"s2a_api_base": config.Global.S2AApiBase,
|
||||
"s2a_admin_key": config.Global.S2AAdminKey,
|
||||
"has_admin_key": config.Global.S2AAdminKey != "",
|
||||
"concurrency": config.Global.Concurrency,
|
||||
"priority": config.Global.Priority,
|
||||
"group_ids": config.Global.GroupIDs,
|
||||
"proxy_enabled": config.Global.ProxyEnabled,
|
||||
"default_proxy": config.Global.DefaultProxy,
|
||||
"team_reg_proxy": config.Global.TeamRegProxy,
|
||||
"proxy_test_status": getProxyTestStatus(),
|
||||
"proxy_test_ip": getProxyTestIP(),
|
||||
"site_name": config.Global.SiteName,
|
||||
"mail_services_count": len(config.Global.MailServices),
|
||||
"mail_services": config.Global.MailServices,
|
||||
"port": config.Global.Port,
|
||||
"s2a_api_base": config.Global.S2AApiBase,
|
||||
"s2a_admin_key": config.Global.S2AAdminKey,
|
||||
"has_admin_key": config.Global.S2AAdminKey != "",
|
||||
"concurrency": config.Global.Concurrency,
|
||||
"priority": config.Global.Priority,
|
||||
"group_ids": config.Global.GroupIDs,
|
||||
"proxy_enabled": config.Global.ProxyEnabled,
|
||||
"default_proxy": config.Global.DefaultProxy,
|
||||
"team_reg_proxy": config.Global.TeamRegProxy,
|
||||
"proxy_test_status": getProxyTestStatus(),
|
||||
"proxy_test_ip": getProxyTestIP(),
|
||||
"team_reg_proxy_test_status": getTeamRegProxyTestStatus(),
|
||||
"team_reg_proxy_test_ip": getTeamRegProxyTestIP(),
|
||||
"site_name": config.Global.SiteName,
|
||||
"mail_services_count": len(config.Global.MailServices),
|
||||
"mail_services": config.Global.MailServices,
|
||||
})
|
||||
|
||||
case http.MethodPut:
|
||||
@@ -1007,7 +1010,8 @@ func handleProxyTest(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var req struct {
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
ProxyType string `json:"proxy_type"` // "default" 或 "team_reg"
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
api.Error(w, http.StatusBadRequest, "请求格式错误")
|
||||
@@ -1020,6 +1024,14 @@ func handleProxyTest(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// 确定保存状态的 key 前缀
|
||||
statusKey := "proxy_test_status"
|
||||
ipKey := "proxy_test_ip"
|
||||
if req.ProxyType == "team_reg" {
|
||||
statusKey = "team_reg_proxy_test_status"
|
||||
ipKey = "team_reg_proxy_test_ip"
|
||||
}
|
||||
|
||||
logger.Info(fmt.Sprintf("测试代理连接: %s", proxyURL), "", "proxy")
|
||||
|
||||
// 解析代理 URL
|
||||
@@ -1052,8 +1064,8 @@ func handleProxyTest(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Error(fmt.Sprintf("代理测试失败: HTTP %d", resp.StatusCode), "", "proxy")
|
||||
// 保存失败状态
|
||||
if database.Instance != nil {
|
||||
database.Instance.SetConfig("proxy_test_status", "error")
|
||||
database.Instance.SetConfig("proxy_test_ip", "")
|
||||
database.Instance.SetConfig(statusKey, "error")
|
||||
database.Instance.SetConfig(ipKey, "")
|
||||
}
|
||||
api.Error(w, http.StatusBadGateway, fmt.Sprintf("代理测试失败: HTTP %d", resp.StatusCode))
|
||||
return
|
||||
@@ -1071,8 +1083,8 @@ func handleProxyTest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 保存成功状态到数据库
|
||||
if database.Instance != nil {
|
||||
database.Instance.SetConfig("proxy_test_status", "success")
|
||||
database.Instance.SetConfig("proxy_test_ip", ipResp.Origin)
|
||||
database.Instance.SetConfig(statusKey, "success")
|
||||
database.Instance.SetConfig(ipKey, ipResp.Origin)
|
||||
}
|
||||
|
||||
api.Success(w, map[string]interface{}{
|
||||
@@ -1102,6 +1114,26 @@ func getProxyTestIP() string {
|
||||
return val
|
||||
}
|
||||
|
||||
// getTeamRegProxyTestStatus 获取注册代理测试状态
|
||||
func getTeamRegProxyTestStatus() string {
|
||||
if database.Instance == nil {
|
||||
return "unknown"
|
||||
}
|
||||
if val, _ := database.Instance.GetConfig("team_reg_proxy_test_status"); val != "" {
|
||||
return val
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// getTeamRegProxyTestIP 获取注册代理测试出口IP
|
||||
func getTeamRegProxyTestIP() string {
|
||||
if database.Instance == nil {
|
||||
return ""
|
||||
}
|
||||
val, _ := database.Instance.GetConfig("team_reg_proxy_test_ip")
|
||||
return val
|
||||
}
|
||||
|
||||
// parseProxyURL 解析代理 URL
|
||||
func parseProxyURL(proxyURL string) (*url.URL, error) {
|
||||
// 如果没有协议前缀,默认添加 http://
|
||||
|
||||
Reference in New Issue
Block a user