换成单集群模式

This commit is contained in:
robin
2026-03-02 20:07:53 +08:00
parent 5d0b7c7e91
commit 2a76d1773d
432 changed files with 5681 additions and 5095 deletions

View File

@@ -1,6 +1,6 @@
package apps
import (
"encoding/json"
"strconv"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
@@ -57,24 +57,61 @@ func (this *AppSettingsAction) RunGet(params struct {
this.ErrorPage(err)
return
}
clusterDomainMap := map[int64]string{}
clusterApiAddressMap := map[int64]string{}
clusterNameMap := map[int64]string{}
for _, cluster := range clusterResp.GetClusters() {
clusterDomainMap[cluster.GetId()] = cluster.GetServiceDomain()
port := "443"
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
apiAddress := "https://" + cluster.GetServiceDomain() + ":" + port
clusterApiAddressMap[cluster.GetId()] = apiAddress
clusterNameMap[cluster.GetId()] = cluster.GetName()
}
// 读取应用绑定的集群列表
var clusterIds []int64
if raw := app.Get("clusterIds"); raw != nil {
if ids, ok := raw.([]int64); ok {
clusterIds = ids
}
}
// 构建服务地址列表
serviceAddresses := make([]maps.Map, 0)
for _, cid := range clusterIds {
addr := clusterApiAddressMap[cid]
name := clusterNameMap[cid]
if len(addr) > 0 {
serviceAddresses = append(serviceAddresses, maps.Map{
"address": addr,
"clusterName": name,
})
}
}
primaryClusterId := app.GetInt64("primaryClusterId")
backupClusterId := app.GetInt64("backupClusterId")
settings := maps.Map{
"appId": app.GetString("appId"),
"appStatus": app.GetBool("isOn"),
"primaryClusterId": primaryClusterId,
"backupClusterId": backupClusterId,
"primaryServiceDomain": clusterDomainMap[primaryClusterId],
"backupServiceDomain": clusterDomainMap[backupClusterId],
"signEnabled": app.GetBool("signEnabled"),
"signSecretPlain": app.GetString("signSecretPlain"),
"signSecretMasked": app.GetString("signSecretMasked"),
"signSecretUpdatedAt": app.GetString("signSecretUpdated"),
"appId": app.GetString("appId"),
"appStatus": app.GetBool("isOn"),
"serviceAddresses": serviceAddresses,
"signEnabled": app.GetBool("signEnabled"),
"signSecretPlain": app.GetString("signSecretPlain"),
"signSecretMasked": app.GetString("signSecretMasked"),
"signSecretUpdatedAt": app.GetString("signSecretUpdated"),
}
this.Data["app"] = app
this.Data["settings"] = settings
@@ -104,12 +141,11 @@ func (this *AppSettingsAction) RunPost(params struct {
}
_, err = this.RPC().HTTPDNSAppRPC().UpdateHTTPDNSApp(this.UserContext(), &pb.UpdateHTTPDNSAppRequest{
AppDbId: params.AppId,
Name: appResp.GetApp().GetName(),
PrimaryClusterId: appResp.GetApp().GetPrimaryClusterId(),
BackupClusterId: appResp.GetApp().GetBackupClusterId(),
IsOn: params.AppStatus,
UserId: appResp.GetApp().GetUserId(),
AppDbId: params.AppId,
Name: appResp.GetApp().GetName(),
ClusterIdsJSON: appResp.GetApp().GetClusterIdsJSON(),
IsOn: params.AppStatus,
UserId: appResp.GetApp().GetUserId(),
})
if err != nil {
this.ErrorPage(err)

View File

@@ -15,7 +15,7 @@ func (this *AppSettingsResetSignSecretAction) RunPost(params struct {
Must *actions.Must
}) {
params.Must.Field("appId", params.AppId).Gt(0, "璇烽€夋嫨搴旂敤")
params.Must.Field("appId", params.AppId).Gt(0, "请选择应用")
_, err := this.RPC().HTTPDNSAppRPC().ResetHTTPDNSAppSignSecret(this.UserContext(), &pb.ResetHTTPDNSAppSignSecretRequest{
AppDbId: params.AppId,

View File

@@ -16,7 +16,7 @@ func (this *AppSettingsToggleSignEnabledAction) RunPost(params struct {
Must *actions.Must
}) {
params.Must.Field("appId", params.AppId).Gt(0, "璇烽€夋嫨搴旂敤")
params.Must.Field("appId", params.AppId).Gt(0, "请选择应用")
_, err := this.RPC().HTTPDNSAppRPC().UpdateHTTPDNSAppSignEnabled(this.UserContext(), &pb.UpdateHTTPDNSAppSignEnabledRequest{
AppDbId: params.AppId,

View File

@@ -30,12 +30,10 @@ func (this *CreateAction) RunPost(params struct {
params.Must.Field("name", params.Name).Require("请输入应用名称")
createResp, err := this.RPC().HTTPDNSAppRPC().CreateHTTPDNSApp(this.UserContext(), &pb.CreateHTTPDNSAppRequest{
Name: params.Name,
AppId: "app" + strconv.FormatInt(time.Now().UnixNano()%1_000_000_000_000, 36),
PrimaryClusterId: 0,
BackupClusterId: 0,
IsOn: true,
SignEnabled: true,
Name: params.Name,
AppId: "app" + strconv.FormatInt(time.Now().UnixNano()%1_000_000_000_000, 36),
IsOn: true,
SignEnabled: true,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -41,14 +41,14 @@ func (this *CustomRecordsCreatePopupAction) RunGet(params struct {
"id": int64(0),
"domain": domain.GetString("name"),
"lineScope": "china",
"lineCarrier": "榛樿",
"lineRegion": "榛樿",
"lineProvince": "榛樿",
"lineContinent": "榛樿",
"lineCountry": "榛樿",
"lineCarrier": "默认",
"lineRegion": "默认",
"lineProvince": "默认",
"lineContinent": "默认",
"lineCountry": "默认",
"ruleName": "",
"weightEnabled": false,
"ttl": 30,
"ttl": 60,
"isOn": true,
"recordItemsJson": `[{"type":"A","value":"","weight":100}]`,
}
@@ -110,7 +110,7 @@ func (this *CustomRecordsCreatePopupAction) RunPost(params struct {
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.Field("appId", params.AppId).Gt(0, "璇烽€夋嫨搴旂敤")
params.Must.Field("appId", params.AppId).Gt(0, "请选择应用")
params.Must.Field("domainId", params.DomainId).Gt(0, "请选择所属域名")
params.LineScope = strings.ToLower(strings.TrimSpace(params.LineScope))
@@ -147,19 +147,19 @@ func (this *CustomRecordsCreatePopupAction) RunPost(params struct {
lineContinent := strings.TrimSpace(params.LineContinent)
lineCountry := strings.TrimSpace(params.LineCountry)
if len(lineCarrier) == 0 {
lineCarrier = "榛樿"
lineCarrier = "默认"
}
if len(lineRegion) == 0 {
lineRegion = "榛樿"
lineRegion = "默认"
}
if len(lineProvince) == 0 {
lineProvince = "榛樿"
lineProvince = "默认"
}
if len(lineContinent) == 0 {
lineContinent = "榛樿"
lineContinent = "默认"
}
if len(lineCountry) == 0 {
lineCountry = "榛樿"
lineCountry = "默认"
}
if params.LineScope == "overseas" {
lineCarrier = ""
@@ -242,7 +242,7 @@ func parseRecordItemsJSON(raw string, weightEnabled bool) ([]maps.Map, error) {
weight = 100
}
if weight < 1 || weight > 100 {
return nil, fmt.Errorf("鏉冮噸鍊煎繀椤诲湪 1-100 涔嬮棿")
return nil, fmt.Errorf("权重值必须在 1-100 之间")
}
result = append(result, maps.Map{

View File

@@ -23,7 +23,6 @@ func (this *DomainsAction) RunGet(params struct {
return
}
// 鏋勫缓椤堕儴 tabbar
httpdnsutils.AddAppTabbar(this.Parent(), app.GetString("name"), params.AppId, "domains")
domains, err := listDomainMaps(this.Parent(), app.GetInt64("id"), "")

View File

@@ -32,7 +32,7 @@ func (this *DomainsCreatePopupAction) RunPost(params struct {
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.Field("appId", params.AppId).Gt(0, "璇烽€夋嫨搴旂敤")
params.Must.Field("appId", params.AppId).Gt(0, "请选择应用")
params.Must.Field("domain", params.Domain).Require("请输入域名")
err := createDomain(this.Parent(), params.AppId, params.Domain)

View File

@@ -47,13 +47,13 @@ func buildLineText(record maps.Map) string {
finalParts := make([]string, 0, len(parts))
for _, part := range parts {
if len(part) == 0 || part == "榛樿" {
if len(part) == 0 || part == "默认" {
continue
}
finalParts = append(finalParts, part)
}
if len(finalParts) == 0 {
return "榛樿"
return "默认"
}
return strings.Join(finalParts, " / ")
}

View File

@@ -1,6 +1,7 @@
package apps
import (
"encoding/json"
"errors"
"strconv"
"strings"
@@ -72,15 +73,14 @@ func findAppMap(parent *actionutils.ParentAction, appDbId int64) (maps.Map, erro
return apps[0], nil
}
func createApp(parent *actionutils.ParentAction, name string, primaryClusterId int64, backupClusterId int64) (int64, error) {
func createApp(parent *actionutils.ParentAction, name string, clusterIdsJSON []byte) (int64, error) {
newAppId := "app" + strconv.FormatInt(time.Now().UnixNano()%1_000_000_000_000, 36)
resp, err := parent.RPC().HTTPDNSAppRPC().CreateHTTPDNSApp(parent.UserContext(), &pb.CreateHTTPDNSAppRequest{
Name: strings.TrimSpace(name),
AppId: newAppId,
PrimaryClusterId: primaryClusterId,
BackupClusterId: backupClusterId,
IsOn: true,
SignEnabled: true,
Name: strings.TrimSpace(name),
AppId: newAppId,
ClusterIdsJSON: clusterIdsJSON,
IsOn: true,
SignEnabled: true,
})
if err != nil {
return 0, err
@@ -95,14 +95,13 @@ func deleteAppByID(parent *actionutils.ParentAction, appDbId int64) error {
return err
}
func updateAppSettings(parent *actionutils.ParentAction, appDbId int64, name string, primaryClusterId int64, backupClusterId int64, isOn bool, userId int64) error {
func updateAppSettings(parent *actionutils.ParentAction, appDbId int64, name string, clusterIdsJSON []byte, isOn bool, userId int64) error {
_, err := parent.RPC().HTTPDNSAppRPC().UpdateHTTPDNSApp(parent.UserContext(), &pb.UpdateHTTPDNSAppRequest{
AppDbId: appDbId,
Name: strings.TrimSpace(name),
PrimaryClusterId: primaryClusterId,
BackupClusterId: backupClusterId,
IsOn: isOn,
UserId: userId,
AppDbId: appDbId,
Name: strings.TrimSpace(name),
ClusterIdsJSON: clusterIdsJSON,
IsOn: isOn,
UserId: userId,
})
return err
}
@@ -264,17 +263,22 @@ func toggleCustomRule(parent *actionutils.ParentAction, ruleId int64, isOn bool)
func appPBToMap(app *pb.HTTPDNSApp, domainCount int64) maps.Map {
signSecret := app.GetSignSecret()
// 读取集群 ID 列表
var clusterIds []int64
if len(app.GetClusterIdsJSON()) > 0 {
_ = json.Unmarshal(app.GetClusterIdsJSON(), &clusterIds)
}
return maps.Map{
"id": app.GetId(),
"name": app.GetName(),
"appId": app.GetAppId(),
"clusterId": app.GetPrimaryClusterId(),
"primaryClusterId": app.GetPrimaryClusterId(),
"backupClusterId": app.GetBackupClusterId(),
"clusterIds": clusterIds,
"userId": app.GetUserId(),
"isOn": app.GetIsOn(),
"domainCount": domainCount,
"sniPolicyText": "闅愬尶 SNI",
"sniPolicyText": "隐匿 SNI",
"signEnabled": app.GetSignEnabled(),
"signSecretPlain": signSecret,
"signSecretMasked": maskSecret(signSecret),
@@ -285,7 +289,7 @@ func appPBToMap(app *pb.HTTPDNSApp, domainCount int64) maps.Map {
func defaultLineField(value string) string {
value = strings.TrimSpace(value)
if len(value) == 0 {
return "榛樿"
return "默认"
}
return value
}

View File

@@ -1,6 +1,7 @@
package resolveLogs
import (
"encoding/json"
"strings"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
@@ -45,8 +46,29 @@ func (this *IndexAction) RunGet(params struct {
clusterDomainMap := map[int64]string{}
for _, cluster := range clusterResp.GetClusters() {
serviceDomain := strings.TrimSpace(cluster.GetServiceDomain())
displayName := serviceDomain
if len(displayName) == 0 {
port := "443"
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
apiAddress := "https://" + serviceDomain + ":" + port
displayName := apiAddress
if len(serviceDomain) == 0 {
displayName = cluster.GetName()
}
@@ -56,7 +78,7 @@ func (this *IndexAction) RunGet(params struct {
"serviceDomain": serviceDomain,
"displayName": displayName,
})
clusterDomainMap[cluster.GetId()] = serviceDomain
clusterDomainMap[cluster.GetId()] = apiAddress
}
this.Data["clusters"] = clusters

View File

@@ -1,6 +1,7 @@
package sandbox
import (
"encoding/json"
"strings"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
@@ -28,8 +29,29 @@ func (this *IndexAction) RunGet(params struct{}) {
clusters := make([]maps.Map, 0, len(clusterResp.GetClusters()))
for _, cluster := range clusterResp.GetClusters() {
serviceDomain := strings.TrimSpace(cluster.GetServiceDomain())
displayName := serviceDomain
if len(displayName) == 0 {
port := "443"
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
apiAddress := "https://" + serviceDomain + ":" + port
displayName := apiAddress
if len(serviceDomain) == 0 {
displayName = cluster.GetName()
}
clusters = append(clusters, maps.Map{
@@ -59,14 +81,18 @@ func (this *IndexAction) RunGet(params struct{}) {
for _, domain := range domainResp.GetDomains() {
domains = append(domains, domain.GetDomain())
}
// 解析集群ID列表
var clusterIds []int64
if len(app.GetClusterIdsJSON()) > 0 {
_ = json.Unmarshal(app.GetClusterIdsJSON(), &clusterIds)
}
apps = append(apps, maps.Map{
"id": app.GetId(),
"name": app.GetName(),
"appId": app.GetAppId(),
"clusterId": app.GetPrimaryClusterId(),
"primaryClusterId": app.GetPrimaryClusterId(),
"backupClusterId": app.GetBackupClusterId(),
"domains": domains,
"id": app.GetId(),
"name": app.GetName(),
"appId": app.GetAppId(),
"clusterIds": clusterIds,
"domains": domains,
})
}
this.Data["apps"] = apps

View File

@@ -3,6 +3,7 @@ package sandbox
import (
"crypto/hmac"
"crypto/sha256"
"encoding/json"
"encoding/hex"
"net/url"
"strconv"
@@ -52,12 +53,30 @@ func (this *TestAction) RunPost(params struct {
}
clusterDomain := ""
port := "443"
if params.ClusterId > 0 {
clusterResp, findErr := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.UserContext(), &pb.FindAllHTTPDNSClustersRequest{})
if findErr == nil {
for _, cluster := range clusterResp.GetClusters() {
if cluster.GetId() == params.ClusterId {
clusterDomain = strings.TrimSpace(cluster.GetServiceDomain())
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
var tlsConfig map[string]interface{}
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
if data, err := json.Marshal(listenRaw); err == nil {
var listenAddresses []map[string]interface{}
if err := json.Unmarshal(data, &listenAddresses); err == nil {
if len(listenAddresses) > 0 {
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
port = portRange
}
}
}
}
}
}
}
break
}
}
@@ -83,7 +102,7 @@ func (this *TestAction) RunPost(params struct {
query.Set("nonce", nonce)
query.Set("sign", sign)
}
requestURL := "https://" + clusterDomain + "/resolve?" + query.Encode()
requestURL := "https://" + clusterDomain + ":" + port + "/resolve?" + query.Encode()
resultCode := 1
if strings.EqualFold(resp.GetCode(), "SUCCESS") {

View File

@@ -430,9 +430,7 @@ func (this *userMustAuth) modules(userId int64, isVerified bool, isIdentified bo
"code": "httpdns",
"name": "HTTPDNS",
"icon": "shield alternate",
"isOn": registerConfig != nil &&
registerConfig.HTTPDNSIsOn &&
lists.ContainsString(featureCodes, userconfigs.UserFeatureCodeHTTPDNS),
"isOn": lists.ContainsString(featureCodes, userconfigs.UserFeatureCodeHTTPDNS),
"subItems": []maps.Map{
{
"name": "应用管理",