mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-02-13 10:25:36 +08:00
优化代码
This commit is contained in:
@@ -36,5 +36,5 @@ func (this *DownloadCertAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"cert-"+strconv.FormatInt(params.CertId, 10)+".pem\";")
|
||||
this.Write(certConfig.CertData)
|
||||
_, _ = this.Write(certConfig.CertData)
|
||||
}
|
||||
|
||||
@@ -36,5 +36,5 @@ func (this *DownloadKeyAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"key-"+strconv.FormatInt(params.CertId, 10)+".pem\";")
|
||||
this.Write(certConfig.KeyData)
|
||||
_, _ = this.Write(certConfig.KeyData)
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
this.Data["user"] = userMap
|
||||
|
||||
var countAll = int64(0)
|
||||
var countCA = int64(0)
|
||||
var countAvailable = int64(0)
|
||||
var countExpired = int64(0)
|
||||
var count7Days = int64(0)
|
||||
var count30Days = int64(0)
|
||||
var countAll int64
|
||||
var countCA int64
|
||||
var countAvailable int64
|
||||
var countExpired int64
|
||||
var count7Days int64
|
||||
var count30Days int64
|
||||
|
||||
// 计算数量
|
||||
{
|
||||
|
||||
@@ -172,6 +172,11 @@ func (this *SelectPopupAction) RunGet(params struct {
|
||||
})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
if listResp == nil {
|
||||
this.ErrorPage(errors.New("'listResp' should not be nil"))
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package certs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -120,7 +121,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
|
||||
// 校验
|
||||
certConfig.IsCA = params.IsCA
|
||||
err = certConfig.Init(nil)
|
||||
err = certConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
if params.IsCA {
|
||||
this.Fail("证书校验错误:" + err.Error())
|
||||
|
||||
@@ -4,6 +4,7 @@ package certs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -156,7 +157,7 @@ func (this *UploadBatchPopupAction) RunPost(params struct {
|
||||
CertData: certData,
|
||||
KeyData: keyData,
|
||||
}
|
||||
err := certConfig.Init(nil)
|
||||
err := certConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("证书验证失败:" + err.Error())
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package certs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -60,8 +61,8 @@ func (this *UploadPopupAction) RunPost(params struct {
|
||||
Field("name", params.Name).
|
||||
Require("请输入证书说明")
|
||||
|
||||
var certData = []byte{}
|
||||
var keyData = []byte{}
|
||||
var certData []byte
|
||||
var keyData []byte
|
||||
|
||||
if params.TextMode {
|
||||
if len(params.CertText) == 0 {
|
||||
@@ -104,7 +105,7 @@ func (this *UploadPopupAction) RunPost(params struct {
|
||||
CertData: certData,
|
||||
KeyData: keyData,
|
||||
}
|
||||
err := certConfig.Init(nil)
|
||||
err := certConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
if params.IsCA {
|
||||
this.Fail("证书校验错误:" + err.Error())
|
||||
|
||||
@@ -35,5 +35,5 @@ func (this *ViewCertAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Write(certConfig.CertData)
|
||||
_, _ = this.Write(certConfig.CertData)
|
||||
}
|
||||
|
||||
@@ -30,5 +30,5 @@ func (this *ViewKeyAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Write(certConfig.KeyData)
|
||||
_, _ = this.Write(certConfig.KeyData)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/cache/cacheutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Helper struct {
|
||||
@@ -27,11 +26,11 @@ func (this *Helper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||
cachePolicyId := action.ParamInt64("cachePolicyId")
|
||||
action.Data["cachePolicyId"] = cachePolicyId
|
||||
|
||||
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
||||
if parentActionValue.IsValid() {
|
||||
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
||||
if isOk {
|
||||
action.Data["cachePolicyName"] = cacheutils.FindCachePolicyNameWithoutError(&parentAction, cachePolicyId)
|
||||
}
|
||||
parentActionObj, ok := actionPtr.(interface {
|
||||
Parent() *actionutils.ParentAction
|
||||
})
|
||||
if ok {
|
||||
var parentAction = parentActionObj.Parent()
|
||||
action.Data["cachePolicyName"] = cacheutils.FindCachePolicyNameWithoutError(parentAction, cachePolicyId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,14 +76,6 @@ func (this *IndexAction) RunPost(params struct {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 允许不匹配的域名
|
||||
allowMismatchDomains := []string{}
|
||||
for _, domain := range params.AllowMismatchDomains {
|
||||
if len(domain) > 0 {
|
||||
allowMismatchDomains = append(allowMismatchDomains, domain)
|
||||
}
|
||||
}
|
||||
|
||||
// TCP端口范围
|
||||
if params.TcpAllPortRangeMin < 1024 {
|
||||
params.TcpAllPortRangeMin = 1024
|
||||
|
||||
@@ -31,7 +31,7 @@ func (this *ExportDownloadAction) RunGet(params struct {
|
||||
if ok {
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"WAF-"+types.String(params.PolicyId)+".json\";")
|
||||
this.AddHeader("Content-Length", strconv.Itoa(len(data)))
|
||||
this.Write(data)
|
||||
_, _ = this.Write(data)
|
||||
} else {
|
||||
this.WriteString("找不到要导出的内容")
|
||||
return
|
||||
|
||||
@@ -52,6 +52,10 @@ func (this *SortSetsAction) RunPost(params struct {
|
||||
FirewallRuleGroupId: params.GroupId,
|
||||
FirewallRuleSetsJSON: newRefsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package httpReverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
@@ -73,7 +74,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tcpReverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
@@ -73,7 +74,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package udpReverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/groups/group/servergrouputils"
|
||||
@@ -73,7 +74,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ func (this *IndexAction) RunPost(params struct {
|
||||
RequestSameOrigin: websocketConfig.RequestSameOrigin,
|
||||
RequestOrigin: websocketConfig.RequestOrigin,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
websocketRef.WebsocketId = websocketConfig.Id
|
||||
|
||||
@@ -31,7 +31,7 @@ func (this *ExportDataAction) RunGet(params struct {
|
||||
defer this.CreateLogInfo(codes.IPList_LogExportIPList, params.ListId)
|
||||
|
||||
var err error
|
||||
var ext = ""
|
||||
var ext string
|
||||
var jsonMaps = []maps.Map{}
|
||||
var xlsxFile *xlsx.File
|
||||
var xlsxSheet *xlsx.Sheet
|
||||
@@ -146,5 +146,5 @@ func (this *ExportDataAction) RunGet(params struct {
|
||||
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"ip-list-"+numberutils.FormatInt64(params.ListId)+ext+"\";")
|
||||
this.AddHeader("Content-Length", strconv.Itoa(len(data)))
|
||||
this.Write(data)
|
||||
_, _ = this.Write(data)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
@@ -53,7 +54,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
_ = httpsConfig.Init(nil)
|
||||
_ = httpsConfig.Init(context.TODO())
|
||||
for _, port := range httpsConfig.AllPorts() {
|
||||
if lists.ContainsInt(httpPorts, port) {
|
||||
conflictingPorts = append(conflictingPorts, port)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package https
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
@@ -43,7 +44,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
httpsConfig.IsOn = true
|
||||
}
|
||||
|
||||
_ = httpsConfig.Init(nil)
|
||||
_ = httpsConfig.Init(context.TODO())
|
||||
var httpsPorts = httpsConfig.AllPorts()
|
||||
|
||||
// 检查http和https端口冲突
|
||||
|
||||
@@ -32,18 +32,18 @@ func (this *RequestCertPopupAction) RunGet(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
serverNameConfigs := []*serverconfigs.ServerNameConfig{}
|
||||
var serverNameConfigs = []*serverconfigs.ServerNameConfig{}
|
||||
err = json.Unmarshal(serverNamesResp.ServerNamesJSON, &serverNameConfigs)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
excludeServerNames := []string{}
|
||||
var excludeServerNames = []string{}
|
||||
if len(params.ExcludeServerNames) > 0 {
|
||||
excludeServerNames = strings.Split(params.ExcludeServerNames, ",")
|
||||
}
|
||||
serverNames := []string{}
|
||||
var serverNames = []string{}
|
||||
for _, c := range serverNameConfigs {
|
||||
if len(c.SubNames) == 0 {
|
||||
if domainutils.ValidateDomainFormat(c.Name) && !lists.ContainsString(excludeServerNames, c.Name) {
|
||||
@@ -64,7 +64,12 @@ func (this *RequestCertPopupAction) RunGet(params struct {
|
||||
AdminId: this.AdminId(),
|
||||
UserId: 0,
|
||||
})
|
||||
userMaps := []maps.Map{}
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var userMaps = []maps.Map{}
|
||||
for _, user := range acmeUsersResp.AcmeUsers {
|
||||
description := user.Description
|
||||
if len(description) > 0 {
|
||||
|
||||
@@ -52,6 +52,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
HttpWebId: webId,
|
||||
HeaderJSON: refJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isChanged = true
|
||||
}
|
||||
if webConfig.ResponseHeaderPolicy == nil {
|
||||
@@ -75,6 +79,10 @@ func (this *IndexAction) RunGet(params struct {
|
||||
HttpWebId: webId,
|
||||
HeaderJSON: refJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
isChanged = true
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type LocationHelper struct {
|
||||
@@ -35,19 +34,19 @@ func (this *LocationHelper) BeforeAction(actionPtr actions.ActionWrapper) {
|
||||
|
||||
// 路径信息
|
||||
var currentLocationConfig *serverconfigs.HTTPLocationConfig = nil
|
||||
parentActionValue := reflect.ValueOf(actionPtr).Elem().FieldByName("ParentAction")
|
||||
if parentActionValue.IsValid() {
|
||||
parentAction, isOk := parentActionValue.Interface().(actionutils.ParentAction)
|
||||
if isOk {
|
||||
var locationId = action.ParamInt64("locationId")
|
||||
locationConfig, isOk := FindLocationConfig(&parentAction, locationId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
action.Data["locationId"] = locationId
|
||||
action.Data["locationConfig"] = locationConfig
|
||||
currentLocationConfig = locationConfig
|
||||
parentActionValue, ok := actionPtr.(interface {
|
||||
Parent() *actionutils.ParentAction
|
||||
})
|
||||
if ok {
|
||||
var parentAction = parentActionValue.Parent()
|
||||
var locationId = action.ParamInt64("locationId")
|
||||
locationConfig, isOk := FindLocationConfig(parentAction, locationId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
action.Data["locationId"] = locationId
|
||||
action.Data["locationConfig"] = locationConfig
|
||||
currentLocationConfig = locationConfig
|
||||
}
|
||||
|
||||
// 左侧菜单
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package locationutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||
@@ -30,7 +31,7 @@ func FindLocationConfig(parentAction *actionutils.ParentAction, locationId int64
|
||||
return
|
||||
}
|
||||
|
||||
err = locationConfig.Init(nil)
|
||||
err = locationConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
parentAction.ErrorPage(err)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -64,7 +65,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -94,6 +94,10 @@ func (this *IndexAction) RunPost(params struct {
|
||||
RequestSameOrigin: websocketConfig.RequestSameOrigin,
|
||||
RequestOrigin: websocketConfig.RequestOrigin,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
websocketRef.WebsocketId = websocketConfig.Id
|
||||
|
||||
@@ -31,7 +31,7 @@ func (this *AddPopupAction) RunGet(params struct {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originType"] = params.OriginType
|
||||
|
||||
var serverType = ""
|
||||
var serverType string
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{ServerId: params.ServerId})
|
||||
if err != nil {
|
||||
|
||||
@@ -37,7 +37,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
|
||||
this.Data["reverseProxyId"] = params.ReverseProxyId
|
||||
this.Data["originId"] = params.OriginId
|
||||
|
||||
var serverType = ""
|
||||
var serverType string
|
||||
if params.ServerId > 0 {
|
||||
serverTypeResp, err := this.RPC().ServerRPC().FindEnabledServerType(this.AdminContext(), &pb.FindEnabledServerTypeRequest{
|
||||
ServerId: params.ServerId,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package reverseProxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
@@ -63,7 +64,7 @@ func (this *SettingAction) RunPost(params struct {
|
||||
return
|
||||
}
|
||||
|
||||
err = reverseProxyConfig.Init(nil)
|
||||
err = reverseProxyConfig.Init(context.TODO())
|
||||
if err != nil {
|
||||
this.Fail("配置校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -107,6 +107,10 @@ func (this *IndexAction) RunPost(params struct {
|
||||
RequestSameOrigin: websocketConfig.RequestSameOrigin,
|
||||
RequestOrigin: websocketConfig.RequestOrigin,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
websocketRef.WebsocketId = websocketConfig.Id
|
||||
|
||||
@@ -43,8 +43,8 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
action.Data["leftMenuItemIsDisabled"] = false
|
||||
}
|
||||
action.Data["leftMenuItems"] = []maps.Map{}
|
||||
mainTab, _ := action.Data["mainTab"]
|
||||
secondMenuItem, _ := action.Data["secondMenuItem"]
|
||||
var mainTab = action.Data["mainTab"]
|
||||
var secondMenuItem = action.Data["secondMenuItem"]
|
||||
|
||||
serverId := action.ParamInt64("serverId")
|
||||
if serverId == 0 {
|
||||
@@ -108,7 +108,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
action.Data["serverFamily"] = family
|
||||
|
||||
// TABBAR
|
||||
selectedTabbar, _ := action.Data["mainTab"]
|
||||
var selectedTabbar = action.Data["mainTab"]
|
||||
var tabbar = actionutils.NewTabbar()
|
||||
tabbar.Add("", "", "/servers", "left arrow", false)
|
||||
if len(serverConfig.Name) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user