【调整】1panel网站列表

pull/193/head
wantoper 2025-05-27 15:37:40 +08:00
parent a51a01996f
commit 39f66a981a
5 changed files with 83 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package api package api
import ( import (
"ALLinSSL/backend/app/dto/response"
"ALLinSSL/backend/internal/access" "ALLinSSL/backend/internal/access"
"ALLinSSL/backend/internal/cert/deploy" "ALLinSSL/backend/internal/cert/deploy"
"ALLinSSL/backend/public" "ALLinSSL/backend/public"
@ -353,11 +354,13 @@ func GetSiteList(c *gin.Context) {
public.FailMsg(c, err.Error()) public.FailMsg(c, err.Error())
return return
} }
var siteList []any var siteList []response.AccessSiteList
switch form.Type { switch form.Type {
case "btpanel-site": case "btpanel-site":
siteList, err = deploy.BtPanelSiteList(form.ID) siteList, err = deploy.BtPanelSiteList(form.ID)
case "1panel-site":
siteList, err = deploy.OnePanelSiteList(form.ID)
default: default:
public.FailMsg(c, "不支持的提供商") public.FailMsg(c, "不支持的提供商")
} }

View File

@ -0,0 +1,7 @@
package response
type AccessSiteList struct {
Id string `json:"id"`
SiteName string `json:"siteName"`
Domain []string `json:"domain"`
}

View File

@ -38,3 +38,12 @@ func TestOnePanelAPITest(t *testing.T) {
t.Log("SSHAPITest success") t.Log("SSHAPITest success")
} }
} }
func TestOnePanelSiteList(t *testing.T) {
result, err := OnePanelSiteList("8")
if err != nil {
t.Fatalf("OnePanelSiteList failed: %v", err)
} else {
t.Logf("OnePanelSiteList success: %v", result)
}
}

View File

@ -1,6 +1,7 @@
package deploy package deploy
import ( import (
"ALLinSSL/backend/app/dto/response"
"ALLinSSL/backend/internal/access" "ALLinSSL/backend/internal/access"
"bytes" "bytes"
"crypto/md5" "crypto/md5"
@ -88,11 +89,11 @@ func Request1panel(data *map[string]any, method, providerID, requestUrl string)
var res map[string]interface{} var res map[string]interface{}
err = json.Unmarshal(body, &res) err = json.Unmarshal(body, &res)
if err != nil { if err != nil {
return nil, fmt.Errorf("证书部署失败: %v", err) return nil, fmt.Errorf("解析返回值失败: %v", err)
} }
code, ok := res["code"].(float64) code, ok := res["code"].(float64)
if !ok { if !ok {
return nil, fmt.Errorf("证书部署失败") return nil, fmt.Errorf("请求失败")
} }
if code != 200 { if code != 200 {
msg, ok := res["message"].(string) msg, ok := res["message"].(string)
@ -184,18 +185,20 @@ func Deploy1panelSite(cfg map[string]any) error {
if !ok { if !ok {
return fmt.Errorf("获取网站参数失败: data") return fmt.Errorf("获取网站参数失败: data")
} }
SSLProtocol, ok := siteData["SSLProtocol"].([]any)
if !ok { var SSLProtocol []any
return fmt.Errorf("获取网站参数失败: data.SSLProtocol") if siteData["SSLProtocol"] == nil {
SSLProtocol = []any{"TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1"}
} else {
SSLProtocol, ok = siteData["SSLProtocol"].([]any)
if !ok {
return fmt.Errorf("获取网站参数失败: data.SSLProtocol")
}
} }
algorithm, ok := siteData["algorithm"].(string) algorithm, ok := siteData["algorithm"].(string)
if !ok { if !ok {
return fmt.Errorf("获取网站参数失败: data.algorithm") return fmt.Errorf("获取网站参数失败: data.algorithm")
} }
enable, ok := siteData["enable"].(bool)
if !ok {
return fmt.Errorf("获取网站参数失败: data.enable")
}
hsts, ok := siteData["hsts"].(bool) hsts, ok := siteData["hsts"].(bool)
if !ok { if !ok {
return fmt.Errorf("获取网站参数失败: data.hsts") return fmt.Errorf("获取网站参数失败: data.hsts")
@ -204,6 +207,9 @@ func Deploy1panelSite(cfg map[string]any) error {
if !ok { if !ok {
return fmt.Errorf("获取网站参数失败: data.httpConfig") return fmt.Errorf("获取网站参数失败: data.httpConfig")
} }
if httpConfig == "" {
httpConfig = "HTTPToHTTPS"
}
data := map[string]any{ data := map[string]any{
"SSLProtocol": SSLProtocol, "SSLProtocol": SSLProtocol,
@ -213,7 +219,7 @@ func Deploy1panelSite(cfg map[string]any) error {
"privateKey": keyPem, "privateKey": keyPem,
// "certificatePath": "", // "certificatePath": "",
// "privateKeyPath": "", // "privateKeyPath": "",
"enable": enable, "enable": true,
"hsts": hsts, "hsts": hsts,
"httpConfig": httpConfig, "httpConfig": httpConfig,
"importType": "paste", "importType": "paste",
@ -231,4 +237,36 @@ func OnePanelAPITest(providerID string) error {
return fmt.Errorf("测试请求失败: %v", err) return fmt.Errorf("测试请求失败: %v", err)
} }
return nil return nil
}
func OnePanelSiteList(providerID string) ([]response.AccessSiteList, error) {
data := map[string]any{
"name": "",
"order": "null",
"orderBy": "created_at",
"page": 1,
"pageSize": 1000,
"websiteGroupId": 0,
}
siteList, err := Request1panel(&data, "POST", providerID, "api/v1/websites/search")
if err != nil {
return nil, fmt.Errorf("获取网站列表失败 %v", err)
}
var result []response.AccessSiteList
sites, ok := siteList["data"].(map[string]any)["items"].([]any)
if !ok {
return nil, fmt.Errorf("获取网站列表失败: data.items")
}
for _, site := range sites {
siteMap, ok := site.(map[string]any)
if !ok {
return nil, fmt.Errorf("获取网站列表失败: site")
}
siteId := strconv.FormatFloat(siteMap["id"].(float64), 'f', -1, 64)
result = append(result, response.AccessSiteList{Id: siteId, SiteName: siteMap["alias"].(string), Domain: []string{}})
}
return result, nil
} }

View File

@ -1,6 +1,7 @@
package deploy package deploy
import ( import (
"ALLinSSL/backend/app/dto/response"
"ALLinSSL/backend/internal/access" "ALLinSSL/backend/internal/access"
"crypto/md5" "crypto/md5"
"crypto/tls" "crypto/tls"
@ -237,7 +238,7 @@ func BtPanelAPITest(providerID string) error {
return nil return nil
} }
func BtPanelSiteList(providerID string) ([]any, error) { func BtPanelSiteList(providerID string) ([]response.AccessSiteList, error) {
data := url.Values{} data := url.Values{}
data.Set("cert_list", "") data.Set("cert_list", "")
siteList, err := RequestBt(&data, "POST", providerID, "ssl?action=GetSiteDomain") siteList, err := RequestBt(&data, "POST", providerID, "ssl?action=GetSiteDomain")
@ -246,6 +247,16 @@ func BtPanelSiteList(providerID string) ([]any, error) {
return nil, err return nil, err
} }
fmt.Printf("siteList:%#v\n", siteList["all"].([]any)) var result []response.AccessSiteList
return siteList["all"].([]any), nil sites, ok := siteList["all"].([]any)
if !ok {
return nil, fmt.Errorf("获取网站列表失败: 数据格式错误")
}
for _, site := range sites {
result = append(result, response.AccessSiteList{Id: "", SiteName: site.(string), Domain: []string{}})
}
//fmt.Printf("siteList:%#v\n", result)
return result, nil
} }