前端页面
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
package sandbox
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -17,22 +14,14 @@ type TestAction struct {
|
||||
}
|
||||
|
||||
func (this *TestAction) RunPost(params struct {
|
||||
AppId string
|
||||
Domain string
|
||||
ClientIp string
|
||||
Qtype string
|
||||
SDNSParamsJSON string
|
||||
AppId string
|
||||
Domain string
|
||||
ClientIp string
|
||||
Qtype string
|
||||
}) {
|
||||
if len(params.ClientIp) == 0 {
|
||||
params.ClientIp = "203.0.113.100"
|
||||
}
|
||||
params.SDNSParamsJSON = strings.TrimSpace(params.SDNSParamsJSON)
|
||||
|
||||
sdnsParams, err := parseSDNSParamsJSON(params.SDNSParamsJSON)
|
||||
if err != nil {
|
||||
this.Fail(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
clientSubnet := this.maskSubnet(params.ClientIp, 24, 56)
|
||||
if len(clientSubnet) == 0 {
|
||||
@@ -51,9 +40,6 @@ func (this *TestAction) RunPost(params struct {
|
||||
query.Set("dn", params.Domain)
|
||||
query.Set("cip", params.ClientIp)
|
||||
query.Set("qtype", params.Qtype)
|
||||
for _, item := range sdnsParams {
|
||||
query.Add("sdns_"+item.GetString("name"), item.GetString("value"))
|
||||
}
|
||||
requestURL := "https://api.httpdns.example.com/resolve?" + query.Encode()
|
||||
|
||||
this.Data["result"] = maps.Map{
|
||||
@@ -61,12 +47,11 @@ func (this *TestAction) RunPost(params struct {
|
||||
"message": "ok (mock)",
|
||||
"requestId": "mock-rid-20260221-001",
|
||||
"data": maps.Map{
|
||||
"request_url": requestURL,
|
||||
"client_ip": params.ClientIp,
|
||||
"client_region": "中国, 上海, 上海",
|
||||
"line_name": "默认线路",
|
||||
"sdns_params": sdnsParams,
|
||||
"ips": []string{"203.0.113.10", "203.0.113.11"},
|
||||
"request_url": requestURL,
|
||||
"client_ip": params.ClientIp,
|
||||
"client_region": "中国, 上海, 上海",
|
||||
"line_name": "默认线路",
|
||||
"ips": []string{"203.0.113.10", "203.0.113.11"},
|
||||
"records": []maps.Map{
|
||||
{
|
||||
"domain": params.Domain,
|
||||
@@ -108,44 +93,6 @@ func (this *TestAction) RunPost(params struct {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
func parseSDNSParamsJSON(raw string) ([]maps.Map, error) {
|
||||
if len(raw) == 0 {
|
||||
return []maps.Map{}, nil
|
||||
}
|
||||
|
||||
list := []maps.Map{}
|
||||
if err := json.Unmarshal([]byte(raw), &list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(list) > 10 {
|
||||
return nil, fmt.Errorf("sdns params should be <= 10")
|
||||
}
|
||||
|
||||
result := make([]maps.Map, 0, len(list))
|
||||
for _, item := range list {
|
||||
name := strings.TrimSpace(item.GetString("name"))
|
||||
value := strings.TrimSpace(item.GetString("value"))
|
||||
if len(name) == 0 && len(value) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(name) == 0 || len(name) > 64 {
|
||||
return nil, fmt.Errorf("sdns param name should be in 1-64")
|
||||
}
|
||||
if len(value) == 0 || len(value) > 64 {
|
||||
return nil, fmt.Errorf("sdns param value should be in 1-64")
|
||||
}
|
||||
result = append(result, maps.Map{
|
||||
"name": name,
|
||||
"value": value,
|
||||
})
|
||||
}
|
||||
|
||||
if len(result) > 10 {
|
||||
return nil, fmt.Errorf("sdns params should be <= 10")
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (this *TestAction) maskSubnet(ip string, ipv4Prefix int, ipv6Prefix int) string {
|
||||
parsed := net.ParseIP(ip)
|
||||
if parsed == nil {
|
||||
|
||||
Reference in New Issue
Block a user