style: 修改website的API和model

This commit is contained in:
zhengkunwang223 2022-12-13 17:20:13 +08:00 committed by zhengkunwang223
parent 2a0f2dcd6a
commit 09ef0ebc80
53 changed files with 520 additions and 548 deletions

View File

@ -37,9 +37,9 @@ var (
websiteGroupService = service.ServiceGroupApp.WebsiteGroupService
websiteService = service.ServiceGroupApp.WebsiteService
websiteDnsAccountService = service.ServiceGroupApp.WebSiteDnsAccountService
websiteSSLService = service.ServiceGroupApp.WebSiteSSLService
websiteAcmeAccountService = service.ServiceGroupApp.WebSiteAcmeAccountService
websiteDnsAccountService = service.ServiceGroupApp.WebsiteDnsAccountService
websiteSSLService = service.ServiceGroupApp.WebsiteSSLService
websiteAcmeAccountService = service.ServiceGroupApp.WebsiteAcmeAccountService
nginxService = service.ServiceGroupApp.NginxService

View File

@ -3,7 +3,7 @@ package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)

View File

@ -4,19 +4,19 @@ import (
"errors"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/gin-gonic/gin"
)
func (b *BaseApi) PageWebsite(c *gin.Context) {
var req dto.WebSiteReq
var req request.WebsiteSearch
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
total, websites, err := websiteService.PageWebSite(req)
total, websites, err := websiteService.PageWebsite(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
@ -37,7 +37,7 @@ func (b *BaseApi) GetWebsiteOptions(c *gin.Context) {
}
func (b *BaseApi) CreateWebsite(c *gin.Context) {
var req dto.WebSiteCreate
var req request.WebsiteCreate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -64,7 +64,7 @@ func (b *BaseApi) BackupWebsite(c *gin.Context) {
}
func (b *BaseApi) RecoverWebsiteByUpload(c *gin.Context) {
var req dto.WebSiteRecoverByFile
var req request.WebsiteRecoverByFile
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -82,7 +82,7 @@ func (b *BaseApi) RecoverWebsiteByUpload(c *gin.Context) {
}
func (b *BaseApi) RecoverWebsite(c *gin.Context) {
var req dto.WebSiteRecover
var req request.WebsiteRecover
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -99,13 +99,13 @@ func (b *BaseApi) RecoverWebsite(c *gin.Context) {
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) DeleteWebSite(c *gin.Context) {
var req request.WebSiteDel
func (b *BaseApi) DeleteWebsite(c *gin.Context) {
var req request.WebsiteDelete
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
err := websiteService.DeleteWebSite(req)
err := websiteService.DeleteWebsite(req)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
@ -113,8 +113,8 @@ func (b *BaseApi) DeleteWebSite(c *gin.Context) {
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) UpdateWebSite(c *gin.Context) {
var req dto.WebSiteUpdate
func (b *BaseApi) UpdateWebsite(c *gin.Context) {
var req request.WebsiteUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -126,8 +126,7 @@ func (b *BaseApi) UpdateWebSite(c *gin.Context) {
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) GetWebSite(c *gin.Context) {
func (b *BaseApi) GetWebsite(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
@ -141,8 +140,7 @@ func (b *BaseApi) GetWebSite(c *gin.Context) {
helper.SuccessWithData(c, website)
}
func (b *BaseApi) GetWebSiteNginx(c *gin.Context) {
func (b *BaseApi) GetWebsiteNginx(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
@ -157,13 +155,11 @@ func (b *BaseApi) GetWebSiteNginx(c *gin.Context) {
}
func (b *BaseApi) GetWebDomains(c *gin.Context) {
websiteId, err := helper.GetIntParamByKey(c, "websiteId")
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
return
}
list, err := websiteService.GetWebsiteDomain(websiteId)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
@ -173,14 +169,13 @@ func (b *BaseApi) GetWebDomains(c *gin.Context) {
}
func (b *BaseApi) DeleteWebDomain(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
var req request.WebsiteDomainDelete
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteService.DeleteWebsiteDomain(id); err != nil {
if err := websiteService.DeleteWebsiteDomain(req.ID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
@ -188,7 +183,7 @@ func (b *BaseApi) DeleteWebDomain(c *gin.Context) {
}
func (b *BaseApi) CreateWebDomain(c *gin.Context) {
var req dto.WebSiteDomainCreate
var req request.WebsiteDomainCreate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -243,7 +238,7 @@ func (b *BaseApi) GetHTTPSConfig(c *gin.Context) {
}
func (b *BaseApi) UpdateHTTPSConfig(c *gin.Context) {
var req dto.WebsiteHTTPSOp
var req request.WebsiteHTTPSOp
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -257,7 +252,7 @@ func (b *BaseApi) UpdateHTTPSConfig(c *gin.Context) {
}
func (b *BaseApi) CreateWebsiteCheck(c *gin.Context) {
var req dto.WebsiteInstallCheckReq
var req request.WebsiteInstallCheckReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return

View File

@ -2,7 +2,7 @@ package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
@ -17,7 +17,7 @@ func (b *BaseApi) GetWebGroups(c *gin.Context) {
}
func (b *BaseApi) CreateWebGroup(c *gin.Context) {
var req dto.WebSiteGroupCreate
var req request.WebsiteGroupCreate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -30,7 +30,7 @@ func (b *BaseApi) CreateWebGroup(c *gin.Context) {
}
func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
var req dto.WebSiteGroupUpdate
var req request.WebsiteGroupUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
@ -43,13 +43,11 @@ func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
}
func (b *BaseApi) DeleteWebGroup(c *gin.Context) {
groupId, err := helper.GetIntParamByKey(c, "groupId")
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
return
}
if err := websiteGroupService.DeleteGroup(groupId); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return

View File

@ -7,7 +7,7 @@ import (
type NginxFull struct {
Install model.AppInstall
Website model.WebSite
Website model.Website
ConfigDir string
ConfigFile string
SiteDir string
@ -25,7 +25,7 @@ type NginxConfig struct {
type NginxConfigReq struct {
Scope NginxKey `json:"scope"`
Operate NginxOp `json:"operate"`
WebSiteID uint `json:"webSiteId"`
WebsiteID uint `json:"webSiteId"`
Params interface{} `json:"params"`
}

View File

@ -0,0 +1,100 @@
package request
import "github.com/1Panel-dev/1Panel/backend/app/dto"
type WebsiteSearch struct {
dto.PageInfo
}
type WebsiteCreate struct {
PrimaryDomain string `json:"primaryDomain" validate:"required"`
Type string `json:"type" validate:"required"`
Alias string `json:"alias" validate:"required"`
Remark string `json:"remark"`
OtherDomains string `json:"otherDomains"`
Proxy string `json:"proxy"`
WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"`
AppType string `json:"appType" validate:"oneof=new installed"`
AppInstall NewAppInstall `json:"appInstall"`
AppID uint `json:"appID"`
AppInstallID uint `json:"appInstallID"`
}
type NewAppInstall struct {
Name string `json:"name"`
AppDetailId uint `json:"appDetailID"`
Params map[string]interface{} `json:"params"`
}
type WebsiteInstallCheckReq struct {
InstallIds []uint `json:"InstallIds" validate:"required"`
}
type WebsiteUpdate struct {
ID uint `json:"id" validate:"required"`
PrimaryDomain string `json:"primaryDomain" validate:"required"`
Remark string `json:"remark"`
WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"`
}
type WebsiteDelete struct {
ID uint `json:"id" validate:"required"`
DeleteApp bool `json:"deleteApp"`
DeleteBackup bool `json:"deleteBackup"`
ForceDelete bool `json:"forceDelete"`
}
type WebsiteWafReq struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Key string `json:"key" validate:"required"`
Rule string `json:"rule" validate:"required"`
}
type WebsiteWafUpdate struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Key string `json:"key" validate:"required"`
Enable bool `json:"enable" validate:"required"`
}
type WebsiteRecover struct {
WebsiteName string `json:"websiteName" validate:"required"`
Type string `json:"type" validate:"required"`
BackupName string `json:"backupName" validate:"required"`
}
type WebsiteRecoverByFile struct {
WebsiteName string `json:"websiteName" validate:"required"`
Type string `json:"type" validate:"required"`
FileDir string `json:"fileDir" validate:"required"`
FileName string `json:"fileName" validate:"required"`
}
type WebsiteGroupCreate struct {
Name string `json:"name" validate:"required"`
}
type WebsiteGroupUpdate struct {
ID uint `json:"id" validate:"required"`
Name string `json:"name"`
Default bool `json:"default"`
}
type WebsiteDomainCreate struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Port int `json:"port" validate:"required"`
Domain string `json:"domain" validate:"required"`
}
type WebsiteDomainDelete struct {
ID uint `json:"id" validate:"required"`
}
type WebsiteHTTPSOp struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Enable bool `json:"enable" validate:"required"`
WebsiteSSLID uint `json:"websiteSSLId"`
Type string `json:"type" validate:"oneof=existed auto manual"`
PrivateKey string `json:"privateKey"`
Certificate string `json:"certificate"`
}

View File

@ -0,0 +1,33 @@
package response
import (
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteDTO struct {
model.Website
}
type WebsitePreInstallCheck struct {
Name string `json:"name"`
Status string `json:"status"`
Version string `json:"version"`
AppName string `json:"appName"`
}
type WebsiteNginxConfig struct {
Enable bool `json:"enable"`
Params []dto.NginxParam `json:"params"`
}
type WebsiteWafConfig struct {
Enable bool `json:"enable"`
FilePath string `json:"filePath"`
Content string `json:"content"`
}
type WebsiteHTTPS struct {
Enable bool `json:"enable"`
SSL model.WebsiteSSL `json:"SSL"`
}

View File

@ -1,124 +1 @@
package dto
import (
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebSiteReq struct {
PageInfo
}
type AppType string
const (
NewApp AppType = "new"
InstalledApp AppType = "installed"
)
type WebSiteCreate struct {
PrimaryDomain string `json:"primaryDomain" validate:"required"`
Type string `json:"type" validate:"required"`
Alias string `json:"alias" validate:"required"`
Remark string `json:"remark"`
OtherDomains string `json:"otherDomains"`
Proxy string `json:"proxy"`
AppType AppType `json:"appType"`
AppInstall NewAppInstall `json:"appInstall"`
AppID uint `json:"appID"`
AppInstallID uint `json:"appInstallID"`
WebSiteGroupID uint `json:"webSiteGroupID" validate:"required"`
}
type WebsiteDTO struct {
model.WebSite
}
type WebSiteUpdate struct {
ID uint `json:"id" validate:"required"`
PrimaryDomain string `json:"primaryDomain" validate:"required"`
Remark string `json:"remark"`
WebSiteGroupID uint `json:"webSiteGroupID" validate:"required"`
}
type NewAppInstall struct {
Name string `json:"name"`
AppDetailId uint `json:"appDetailID"`
Params map[string]interface{} `json:"params"`
}
type WebSiteRecover struct {
WebsiteName string `json:"websiteName" validate:"required"`
Type string `json:"type" validate:"required"`
BackupName string `json:"backupName" validate:"required"`
}
type WebSiteRecoverByFile struct {
WebsiteName string `json:"websiteName" validate:"required"`
Type string `json:"type" validate:"required"`
FileDir string `json:"fileDir" validate:"required"`
FileName string `json:"fileName" validate:"required"`
}
type WebSiteDTO struct {
model.WebSite
}
type WebSiteGroupCreate struct {
Name string `json:"name"`
}
type WebSiteGroupUpdate struct {
ID uint `json:"id"`
Name string `json:"name"`
Default bool `json:"default"`
}
type WebSiteDomainCreate struct {
WebSiteID uint `json:"webSiteId"`
Port int `json:"port"`
Domain string `json:"domain"`
}
type WebsiteHTTPS struct {
Enable bool `json:"enable"`
SSL model.WebSiteSSL `json:"SSL"`
}
type SSlType string
const (
SSLExisted SSlType = "existed"
SSLAuto SSlType = "auto"
SSLManual SSlType = "manual"
)
type WebsiteHTTPSOp struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Enable bool `json:"enable" validate:"required"`
WebsiteSSLID uint `json:"websiteSSLId"`
Type SSlType `json:"type"`
PrivateKey string `json:"privateKey"`
Certificate string `json:"certificate"`
}
type WebsiteNginxConfig struct {
Enable bool `json:"enable"`
Params []NginxParam `json:"params"`
}
type WebsitePreInstallCheck struct {
Name string `json:"name"`
Status string `json:"status"`
Version string `json:"version"`
AppName string `json:"appName"`
}
type WebsiteInstallCheckReq struct {
InstallIds []uint `json:"InstallIds"`
}
type WebsiteWafConfig struct {
Enable bool `json:"enable"`
FilePath string `json:"filePath"`
Content string `json:"content"`
}

View File

@ -3,7 +3,7 @@ package dto
import "github.com/1Panel-dev/1Panel/backend/app/model"
type WebsiteSSLDTO struct {
model.WebSiteSSL
model.WebsiteSSL
}
type SSLProvider string

View File

@ -2,7 +2,7 @@ package model
import "time"
type WebSite struct {
type Website struct {
BaseModel
Protocol string `gorm:"type:varchar(64);not null" json:"protocol"`
PrimaryDomain string `gorm:"type:varchar(128);not null" json:"primaryDomain"`
@ -12,13 +12,13 @@ type WebSite struct {
Status string `gorm:"type:varchar(64);not null" json:"status"`
ExpireDate time.Time `json:"expireDate"`
AppInstallID uint `gorm:"type:integer" json:"appInstallId"`
WebSiteGroupID uint `gorm:"type:integer" json:"webSiteGroupId"`
WebSiteSSLID uint `gorm:"type:integer" json:"webSiteSSLId"`
WebsiteGroupID uint `gorm:"type:integer" json:"webSiteGroupId"`
WebsiteSSLID uint `gorm:"type:integer" json:"webSiteSSLId"`
Proxy string `gorm:"type:varchar(128);not null" json:"proxy"`
Domains []WebSiteDomain `json:"domains"`
WebSiteSSL WebSiteSSL `json:"webSiteSSL"`
Domains []WebsiteDomain `json:"domains"`
WebsiteSSL WebsiteSSL `json:"webSiteSSL"`
}
func (w WebSite) TableName() string {
func (w Website) TableName() string {
return "websites"
}

View File

@ -1,12 +1,12 @@
package model
type WebSiteDomain struct {
type WebsiteDomain struct {
BaseModel
WebSiteID uint `gorm:"type:varchar(64);not null" json:"web_site_id"`
WebsiteID uint `gorm:"column:website_id;type:varchar(64);not null;" json:"websiteId"`
Domain string `gorm:"type:varchar(256);not null" json:"domain"`
Port int `gorm:"type:integer" json:"port"`
}
func (w WebSiteDomain) TableName() string {
func (w WebsiteDomain) TableName() string {
return "website_domains"
}

View File

@ -1,11 +1,11 @@
package model
type WebSiteGroup struct {
type WebsiteGroup struct {
BaseModel
Name string `gorm:"type:varchar(64);not null" json:"name"`
Default bool `json:"default"`
}
func (w WebSiteGroup) TableName() string {
func (w WebsiteGroup) TableName() string {
return "website_groups"
}

View File

@ -2,7 +2,7 @@ package model
import "time"
type WebSiteSSL struct {
type WebsiteSSL struct {
BaseModel
PrimaryDomain string `gorm:"type:varchar(256);not null" json:"primaryDomain"`
PrivateKey string `gorm:"type:longtext;not null" json:"privateKey"`
@ -19,6 +19,6 @@ type WebSiteSSL struct {
StartDate time.Time `json:"startDate"`
}
func (w WebSiteSSL) TableName() string {
func (w WebsiteSSL) TableName() string {
return "website_ssls"
}

View File

@ -18,9 +18,9 @@ type RepoGroup struct {
GroupRepo
SettingRepo
BackupRepo
WebSiteRepo
WebSiteDomainRepo
WebSiteGroupRepo
WebsiteRepo
WebsiteDomainRepo
WebsiteGroupRepo
WebsiteDnsAccountRepo
WebsiteSSLRepo
WebsiteAcmeAccountRepo

View File

@ -13,80 +13,80 @@ type IWebsiteRepo interface {
WithDomain(domain string) DBOption
WithAlias(alias string) DBOption
WithWebsiteSSLID(sslId uint) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.WebSite, error)
GetFirst(opts ...DBOption) (model.WebSite, error)
GetBy(opts ...DBOption) ([]model.WebSite, error)
Save(ctx context.Context, app *model.WebSite) error
Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
GetFirst(opts ...DBOption) (model.Website, error)
GetBy(opts ...DBOption) ([]model.Website, error)
Save(ctx context.Context, app *model.Website) error
DeleteBy(ctx context.Context, opts ...DBOption) error
Create(ctx context.Context, app *model.WebSite) error
Create(ctx context.Context, app *model.Website) error
}
func NewIWebsiteRepo() IWebsiteRepo {
return &WebSiteRepo{}
return &WebsiteRepo{}
}
type WebSiteRepo struct {
type WebsiteRepo struct {
}
func (w *WebSiteRepo) WithAppInstallId(appInstallId uint) DBOption {
func (w *WebsiteRepo) WithAppInstallId(appInstallId uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("app_install_id = ?", appInstallId)
}
}
func (w *WebSiteRepo) WithDomain(domain string) DBOption {
func (w *WebsiteRepo) WithDomain(domain string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("primary_domain = ?", domain)
}
}
func (w *WebSiteRepo) WithAlias(alias string) DBOption {
func (w *WebsiteRepo) WithAlias(alias string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("alias = ?", alias)
}
}
func (w *WebSiteRepo) WithWebsiteSSLID(sslId uint) DBOption {
func (w *WebsiteRepo) WithWebsiteSSLID(sslId uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("web_site_ssl_id = ?", sslId)
}
}
func (w *WebSiteRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSite, error) {
var websites []model.WebSite
db := getDb(opts...).Model(&model.WebSite{})
func (w *WebsiteRepo) Page(page, size int, opts ...DBOption) (int64, []model.Website, error) {
var websites []model.Website
db := getDb(opts...).Model(&model.Website{})
count := int64(0)
db = db.Count(&count)
err := db.Debug().Limit(size).Offset(size * (page - 1)).Preload("WebSiteSSL").Find(&websites).Error
err := db.Debug().Limit(size).Offset(size * (page - 1)).Preload("WebsiteSSL").Find(&websites).Error
return count, websites, err
}
func (w *WebSiteRepo) GetFirst(opts ...DBOption) (model.WebSite, error) {
var website model.WebSite
db := getDb(opts...).Model(&model.WebSite{})
func (w *WebsiteRepo) GetFirst(opts ...DBOption) (model.Website, error) {
var website model.Website
db := getDb(opts...).Model(&model.Website{})
if err := db.Preload("Domains").First(&website).Error; err != nil {
return website, err
}
return website, nil
}
func (w *WebSiteRepo) GetBy(opts ...DBOption) ([]model.WebSite, error) {
var websites []model.WebSite
db := getDb(opts...).Model(&model.WebSite{})
func (w *WebsiteRepo) GetBy(opts ...DBOption) ([]model.Website, error) {
var websites []model.Website
db := getDb(opts...).Model(&model.Website{})
if err := db.Find(&websites).Error; err != nil {
return websites, err
}
return websites, nil
}
func (w *WebSiteRepo) Create(ctx context.Context, app *model.WebSite) error {
func (w *WebsiteRepo) Create(ctx context.Context, app *model.Website) error {
return getTx(ctx).Omit(clause.Associations).Create(app).Error
}
func (w *WebSiteRepo) Save(ctx context.Context, app *model.WebSite) error {
func (w *WebsiteRepo) Save(ctx context.Context, app *model.Website) error {
return getTx(ctx).Omit(clause.Associations).Save(app).Error
}
func (w *WebSiteRepo) DeleteBy(ctx context.Context, opts ...DBOption) error {
return getTx(ctx, opts...).Delete(&model.WebSite{}).Error
func (w *WebsiteRepo) DeleteBy(ctx context.Context, opts ...DBOption) error {
return getTx(ctx, opts...).Delete(&model.Website{}).Error
}

View File

@ -7,64 +7,64 @@ import (
"gorm.io/gorm/clause"
)
type WebSiteDomainRepo struct {
type WebsiteDomainRepo struct {
}
func (w WebSiteDomainRepo) WithWebSiteId(websiteId uint) DBOption {
func (w WebsiteDomainRepo) WithWebsiteId(websiteId uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("web_site_id = ?", websiteId)
return db.Where("website_id = ?", websiteId)
}
}
func (w WebSiteDomainRepo) WithPort(port int) DBOption {
func (w WebsiteDomainRepo) WithPort(port int) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("port = ?", port)
}
}
func (w WebSiteDomainRepo) WithDomain(domain string) DBOption {
func (w WebsiteDomainRepo) WithDomain(domain string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("domain = ?", domain)
}
}
func (w WebSiteDomainRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSiteDomain, error) {
var domains []model.WebSiteDomain
db := getDb(opts...).Model(&model.WebSiteDomain{})
func (w WebsiteDomainRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteDomain, error) {
var domains []model.WebsiteDomain
db := getDb(opts...).Model(&model.WebsiteDomain{})
count := int64(0)
db = db.Count(&count)
err := db.Debug().Limit(size).Offset(size * (page - 1)).Find(&domains).Error
return count, domains, err
}
func (w WebSiteDomainRepo) GetFirst(opts ...DBOption) (model.WebSiteDomain, error) {
var domain model.WebSiteDomain
db := getDb(opts...).Model(&model.WebSiteDomain{})
func (w WebsiteDomainRepo) GetFirst(opts ...DBOption) (model.WebsiteDomain, error) {
var domain model.WebsiteDomain
db := getDb(opts...).Model(&model.WebsiteDomain{})
if err := db.First(&domain).Error; err != nil {
return domain, err
}
return domain, nil
}
func (w WebSiteDomainRepo) GetBy(opts ...DBOption) ([]model.WebSiteDomain, error) {
var domains []model.WebSiteDomain
db := getDb(opts...).Model(&model.WebSiteDomain{})
func (w WebsiteDomainRepo) GetBy(opts ...DBOption) ([]model.WebsiteDomain, error) {
var domains []model.WebsiteDomain
db := getDb(opts...).Model(&model.WebsiteDomain{})
if err := db.Find(&domains).Error; err != nil {
return domains, err
}
return domains, nil
}
func (w WebSiteDomainRepo) BatchCreate(ctx context.Context, domains []model.WebSiteDomain) error {
return getTx(ctx).Model(&model.WebSiteDomain{}).Create(&domains).Error
func (w WebsiteDomainRepo) BatchCreate(ctx context.Context, domains []model.WebsiteDomain) error {
return getTx(ctx).Model(&model.WebsiteDomain{}).Create(&domains).Error
}
func (w WebSiteDomainRepo) Create(ctx context.Context, app *model.WebSiteDomain) error {
func (w WebsiteDomainRepo) Create(ctx context.Context, app *model.WebsiteDomain) error {
return getTx(ctx).Omit(clause.Associations).Create(app).Error
}
func (w WebSiteDomainRepo) Save(ctx context.Context, app *model.WebSiteDomain) error {
func (w WebsiteDomainRepo) Save(ctx context.Context, app *model.WebsiteDomain) error {
return getTx(ctx).Omit(clause.Associations).Save(app).Error
}
func (w WebSiteDomainRepo) DeleteBy(ctx context.Context, opts ...DBOption) error {
return getTx(ctx, opts...).Delete(&model.WebSiteDomain{}).Error
func (w WebsiteDomainRepo) DeleteBy(ctx context.Context, opts ...DBOption) error {
return getTx(ctx, opts...).Delete(&model.WebsiteDomain{}).Error
}

View File

@ -6,39 +6,39 @@ import (
"gorm.io/gorm/clause"
)
type WebSiteGroupRepo struct {
type WebsiteGroupRepo struct {
}
func (w WebSiteGroupRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSiteGroup, error) {
var groups []model.WebSiteGroup
db := getDb(opts...).Model(&model.WebSiteGroup{})
func (w WebsiteGroupRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteGroup, error) {
var groups []model.WebsiteGroup
db := getDb(opts...).Model(&model.WebsiteGroup{})
count := int64(0)
db = db.Count(&count)
err := db.Limit(size).Offset(size * (page - 1)).Order("`default` desc").Find(&groups).Error
return count, groups, err
}
func (w WebSiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebSiteGroup, error) {
var groups []model.WebSiteGroup
db := getDb(opts...).Model(&model.WebSiteGroup{})
func (w WebsiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebsiteGroup, error) {
var groups []model.WebsiteGroup
db := getDb(opts...).Model(&model.WebsiteGroup{})
if err := db.Order("`default` desc").Find(&groups).Error; err != nil {
return groups, err
}
return groups, nil
}
func (w WebSiteGroupRepo) Create(app *model.WebSiteGroup) error {
func (w WebsiteGroupRepo) Create(app *model.WebsiteGroup) error {
return getDb().Omit(clause.Associations).Create(app).Error
}
func (w WebSiteGroupRepo) Save(app *model.WebSiteGroup) error {
func (w WebsiteGroupRepo) Save(app *model.WebsiteGroup) error {
return getDb().Omit(clause.Associations).Save(app).Error
}
func (w WebSiteGroupRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.WebSiteGroup{}).Error
func (w WebsiteGroupRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.WebsiteGroup{}).Error
}
func (w WebSiteGroupRepo) CancelDefault() error {
return global.DB.Model(&model.WebSiteGroup{}).Where("`default` = 1").Updates(map[string]interface{}{"default": 0}).Error
func (w WebsiteGroupRepo) CancelDefault() error {
return global.DB.Model(&model.WebsiteGroup{}).Where("`default` = 1").Updates(map[string]interface{}{"default": 0}).Error
}

View File

@ -14,11 +14,11 @@ type ISSLRepo interface {
WithByAlias(alias string) DBOption
WithByAcmeAccountId(acmeAccountId uint) DBOption
WithByDnsAccountId(dnsAccountId uint) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.WebSiteSSL, error)
GetFirst(opts ...DBOption) (model.WebSiteSSL, error)
List(opts ...DBOption) ([]model.WebSiteSSL, error)
Create(ctx context.Context, ssl *model.WebSiteSSL) error
Save(ssl model.WebSiteSSL) error
Page(page, size int, opts ...DBOption) (int64, []model.WebsiteSSL, error)
GetFirst(opts ...DBOption) (model.WebsiteSSL, error)
List(opts ...DBOption) ([]model.WebsiteSSL, error)
Create(ctx context.Context, ssl *model.WebsiteSSL) error
Save(ssl model.WebsiteSSL) error
DeleteBy(opts ...DBOption) error
}
@ -43,41 +43,41 @@ func (w WebsiteSSLRepo) WithByDnsAccountId(dnsAccountId uint) DBOption {
}
}
func (w WebsiteSSLRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebSiteSSL, error) {
var sslList []model.WebSiteSSL
db := getDb(opts...).Model(&model.WebSiteSSL{})
func (w WebsiteSSLRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteSSL, error) {
var sslList []model.WebsiteSSL
db := getDb(opts...).Model(&model.WebsiteSSL{})
count := int64(0)
db = db.Count(&count)
err := db.Limit(size).Offset(size * (page - 1)).Preload("AcmeAccount").Find(&sslList).Error
return count, sslList, err
}
func (w WebsiteSSLRepo) GetFirst(opts ...DBOption) (model.WebSiteSSL, error) {
var website model.WebSiteSSL
db := getDb(opts...).Model(&model.WebSiteSSL{})
func (w WebsiteSSLRepo) GetFirst(opts ...DBOption) (model.WebsiteSSL, error) {
var website model.WebsiteSSL
db := getDb(opts...).Model(&model.WebsiteSSL{})
if err := db.Preload("AcmeAccount").First(&website).Error; err != nil {
return website, err
}
return website, nil
}
func (w WebsiteSSLRepo) List(opts ...DBOption) ([]model.WebSiteSSL, error) {
var websites []model.WebSiteSSL
db := getDb(opts...).Model(&model.WebSiteSSL{})
func (w WebsiteSSLRepo) List(opts ...DBOption) ([]model.WebsiteSSL, error) {
var websites []model.WebsiteSSL
db := getDb(opts...).Model(&model.WebsiteSSL{})
if err := db.Preload("AcmeAccount").Find(&websites).Error; err != nil {
return websites, err
}
return websites, nil
}
func (w WebsiteSSLRepo) Create(ctx context.Context, ssl *model.WebSiteSSL) error {
func (w WebsiteSSLRepo) Create(ctx context.Context, ssl *model.WebsiteSSL) error {
return getTx(ctx).Create(ssl).Error
}
func (w WebsiteSSLRepo) Save(ssl model.WebSiteSSL) error {
func (w WebsiteSSLRepo) Save(ssl model.WebsiteSSL) error {
return getDb().Save(&ssl).Error
}
func (w WebsiteSSLRepo) DeleteBy(opts ...DBOption) error {
return getDb(opts...).Delete(&model.WebSiteSSL{}).Error
return getDb(opts...).Delete(&model.WebsiteSSL{}).Error
}

View File

@ -1,20 +0,0 @@
package request
type WebsiteWafReq struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Key string `json:"key" validate:"required"`
Rule string `json:"rule" validate:"required"`
}
type WebsiteWafUpdate struct {
WebsiteID uint `json:"websiteId" validate:"required"`
Key string `json:"key" validate:"required"`
Enable bool `json:"enable" validate:"required"`
}
type WebSiteDel struct {
ID uint `json:"id" validate:"required"`
DeleteApp bool `json:"deleteApp"`
DeleteBackup bool `json:"deleteBackup"`
ForceDelete bool `json:"forceDelete"`
}

View File

@ -30,9 +30,9 @@ type ServiceGroup struct {
WebsiteGroupService
WebsiteService
WebSiteDnsAccountService
WebSiteSSLService
WebSiteAcmeAccountService
WebsiteDnsAccountService
WebsiteSSLService
WebsiteAcmeAccountService
NginxService
@ -67,8 +67,8 @@ var (
backupRepo = repo.RepoGroupApp.BackupRepo
websiteRepo = repo.NewIWebsiteRepo()
websiteGroupRepo = repo.RepoGroupApp.WebSiteGroupRepo
websiteDomainRepo = repo.RepoGroupApp.WebSiteDomainRepo
websiteGroupRepo = repo.RepoGroupApp.WebsiteGroupRepo
websiteDomainRepo = repo.RepoGroupApp.WebsiteDomainRepo
websiteDnsRepo = repo.RepoGroupApp.WebsiteDnsAccountRepo
websiteSSLRepo = repo.NewISSLRepo()
websiteAcmeRepo = repo.NewIAcmeAccountRepo()

View File

@ -1,7 +1,7 @@
package service
import (
"github.com/1Panel-dev/1Panel/backend/app/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"io/ioutil"
"net/http"
"os"

View File

@ -17,7 +17,7 @@ import (
"strings"
)
func getNginxFull(website *model.WebSite) (dto.NginxFull, error) {
func getNginxFull(website *model.Website) (dto.NginxFull, error) {
var nginxFull dto.NginxFull
nginxInstall, err := getAppInstallByKey("nginx")
if err != nil {
@ -62,7 +62,7 @@ func getNginxFull(website *model.WebSite) (dto.NginxFull, error) {
return nginxFull, nil
}
func getNginxParamsByKeys(scope string, keys []string, website *model.WebSite) ([]dto.NginxParam, error) {
func getNginxParamsByKeys(scope string, keys []string, website *model.Website) ([]dto.NginxParam, error) {
nginxFull, err := getNginxFull(website)
if err != nil {
return nil, err
@ -94,7 +94,7 @@ func getNginxParamsByKeys(scope string, keys []string, website *model.WebSite) (
return res, nil
}
func updateNginxConfig(scope string, params []dto.NginxParam, website *model.WebSite) error {
func updateNginxConfig(scope string, params []dto.NginxParam, website *model.Website) error {
nginxFull, err := getNginxFull(website)
if err != nil {
@ -126,7 +126,7 @@ func updateNginxConfig(scope string, params []dto.NginxParam, website *model.Web
return nginxCheckAndReload(config.OldContent, config.FilePath, nginxFull.Install.ContainerName)
}
func deleteNginxConfig(scope string, keys []string, website *model.WebSite) error {
func deleteNginxConfig(scope string, keys []string, website *model.Website) error {
nginxFull, err := getNginxFull(website)
if err != nil {
return err

View File

@ -6,7 +6,8 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"github.com/1Panel-dev/1Panel/backend/app/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/buserr"
"os"
"path"
@ -26,25 +27,25 @@ type WebsiteService struct {
}
type IWebsiteService interface {
PageWebSite(req dto.WebSiteReq) (int64, []dto.WebSiteDTO, error)
CreateWebsite(create dto.WebSiteCreate) error
PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error)
CreateWebsite(create request.WebsiteCreate) error
GetWebsiteOptions() ([]string, error)
Backup(domain string) error
Recover(req dto.WebSiteRecover) error
RecoverByUpload(req dto.WebSiteRecoverByFile) error
UpdateWebsite(req dto.WebSiteUpdate) error
DeleteWebSite(req request.WebSiteDel) error
GetWebsite(id uint) (dto.WebsiteDTO, error)
CreateWebsiteDomain(create dto.WebSiteDomainCreate) (model.WebSiteDomain, error)
GetWebsiteDomain(websiteId uint) ([]model.WebSiteDomain, error)
Recover(req request.WebsiteRecover) error
RecoverByUpload(req request.WebsiteRecoverByFile) error
UpdateWebsite(req request.WebsiteUpdate) error
DeleteWebsite(req request.WebsiteDelete) error
GetWebsite(id uint) (response.WebsiteDTO, error)
CreateWebsiteDomain(create request.WebsiteDomainCreate) (model.WebsiteDomain, error)
GetWebsiteDomain(websiteId uint) ([]model.WebsiteDomain, error)
DeleteWebsiteDomain(domainId uint) error
GetNginxConfigByScope(req dto.NginxConfigReq) (*dto.WebsiteNginxConfig, error)
GetNginxConfigByScope(req dto.NginxConfigReq) (*response.WebsiteNginxConfig, error)
UpdateNginxConfigByScope(req dto.NginxConfigReq) error
GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, error)
GetWebsiteHTTPS(websiteId uint) (dto.WebsiteHTTPS, error)
OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS, error)
PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.WebsitePreInstallCheck, error)
GetWafConfig(req request.WebsiteWafReq) (dto.WebsiteWafConfig, error)
GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error)
OpWebsiteHTTPS(req request.WebsiteHTTPSOp) (response.WebsiteHTTPS, error)
PreInstallCheck(req request.WebsiteInstallCheckReq) ([]response.WebsitePreInstallCheck, error)
GetWafConfig(req request.WebsiteWafReq) (response.WebsiteWafConfig, error)
UpdateWafConfig(req request.WebsiteWafUpdate) error
}
@ -52,21 +53,21 @@ func NewWebsiteService() IWebsiteService {
return &WebsiteService{}
}
func (w WebsiteService) PageWebSite(req dto.WebSiteReq) (int64, []dto.WebSiteDTO, error) {
var websiteDTOs []dto.WebSiteDTO
func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []response.WebsiteDTO, error) {
var websiteDTOs []response.WebsiteDTO
total, websites, err := websiteRepo.Page(req.Page, req.PageSize)
if err != nil {
return 0, nil, err
}
for _, web := range websites {
websiteDTOs = append(websiteDTOs, dto.WebSiteDTO{
WebSite: web,
websiteDTOs = append(websiteDTOs, response.WebsiteDTO{
Website: web,
})
}
return total, websiteDTOs, nil
}
func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) error {
if exist, _ := websiteRepo.GetBy(websiteRepo.WithDomain(create.PrimaryDomain)); len(exist) > 0 {
return buserr.New(constant.ErrNameIsExist)
}
@ -78,7 +79,7 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
}
defaultDate, _ := time.Parse(constant.DateLayout, constant.DefaultDate)
website := &model.WebSite{
website := &model.Website{
PrimaryDomain: create.PrimaryDomain,
Type: create.Type,
Alias: create.Alias,
@ -86,14 +87,14 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
Status: constant.WebRunning,
ExpireDate: defaultDate,
AppInstallID: create.AppInstallID,
WebSiteGroupID: create.WebSiteGroupID,
WebsiteGroupID: create.WebsiteGroupID,
Protocol: constant.ProtocolHTTP,
Proxy: create.Proxy,
}
switch create.Type {
case constant.Deployment:
if create.AppType == dto.NewApp {
if create.AppType == constant.NewApp {
install, err := ServiceGroupApp.Install(create.AppInstall.Name, create.AppInstall.AppDetailId, create.AppInstall.Params)
if err != nil {
return err
@ -110,8 +111,8 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
if err := websiteRepo.Create(ctx, website); err != nil {
return err
}
var domains []model.WebSiteDomain
domains = append(domains, model.WebSiteDomain{Domain: website.PrimaryDomain, WebSiteID: website.ID, Port: 80})
var domains []model.WebsiteDomain
domains = append(domains, model.WebsiteDomain{Domain: website.PrimaryDomain, WebsiteID: website.ID, Port: 80})
otherDomainArray := strings.Split(create.OtherDomains, "\n")
for _, domain := range otherDomainArray {
@ -123,7 +124,7 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
tx.Rollback()
return err
}
if reflect.DeepEqual(domainModel, model.WebSiteDomain{}) {
if reflect.DeepEqual(domainModel, model.WebsiteDomain{}) {
continue
}
domains = append(domains, domainModel)
@ -170,7 +171,7 @@ func (w WebsiteService) Backup(domain string) error {
return nil
}
func (w WebsiteService) RecoverByUpload(req dto.WebSiteRecoverByFile) error {
func (w WebsiteService) RecoverByUpload(req request.WebsiteRecoverByFile) error {
if err := handleUnTar(fmt.Sprintf("%s/%s", req.FileDir, req.FileName), req.FileDir); err != nil {
return err
}
@ -179,7 +180,7 @@ func (w WebsiteService) RecoverByUpload(req dto.WebSiteRecoverByFile) error {
if err != nil {
return err
}
var websiteInfo WebSiteInfo
var websiteInfo WebsiteInfo
if err := json.Unmarshal(webJson, &websiteInfo); err != nil {
return err
}
@ -198,7 +199,7 @@ func (w WebsiteService) RecoverByUpload(req dto.WebSiteRecoverByFile) error {
return nil
}
func (w WebsiteService) Recover(req dto.WebSiteRecover) error {
func (w WebsiteService) Recover(req request.WebsiteRecover) error {
website, err := websiteRepo.GetFirst(websiteRepo.WithDomain(req.WebsiteName))
if err != nil {
return err
@ -220,29 +221,29 @@ func (w WebsiteService) Recover(req dto.WebSiteRecover) error {
return nil
}
func (w WebsiteService) UpdateWebsite(req dto.WebSiteUpdate) error {
func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))
if err != nil {
return err
}
website.PrimaryDomain = req.PrimaryDomain
website.WebSiteGroupID = req.WebSiteGroupID
website.WebsiteGroupID = req.WebsiteGroupID
website.Remark = req.Remark
return websiteRepo.Save(context.TODO(), &website)
}
func (w WebsiteService) GetWebsite(id uint) (dto.WebsiteDTO, error) {
var res dto.WebsiteDTO
func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) {
var res response.WebsiteDTO
website, err := websiteRepo.GetFirst(commonRepo.WithByID(id))
if err != nil {
return res, err
}
res.WebSite = website
res.Website = website
return res, nil
}
func (w WebsiteService) DeleteWebSite(req request.WebSiteDel) error {
func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))
if err != nil {
return err
@ -272,7 +273,7 @@ func (w WebsiteService) DeleteWebSite(req request.WebSiteDel) error {
tx.Rollback()
return err
}
if err := websiteDomainRepo.DeleteBy(ctx, websiteDomainRepo.WithWebSiteId(req.ID)); err != nil {
if err := websiteDomainRepo.DeleteBy(ctx, websiteDomainRepo.WithWebsiteId(req.ID)); err != nil {
tx.Rollback()
return err
}
@ -280,32 +281,32 @@ func (w WebsiteService) DeleteWebSite(req request.WebSiteDel) error {
return nil
}
func (w WebsiteService) CreateWebsiteDomain(create dto.WebSiteDomainCreate) (model.WebSiteDomain, error) {
var domainModel model.WebSiteDomain
func (w WebsiteService) CreateWebsiteDomain(create request.WebsiteDomainCreate) (model.WebsiteDomain, error) {
var domainModel model.WebsiteDomain
var ports []int
var domains []string
website, err := websiteRepo.GetFirst(commonRepo.WithByID(create.WebSiteID))
website, err := websiteRepo.GetFirst(commonRepo.WithByID(create.WebsiteID))
if err != nil {
return domainModel, err
}
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebSiteId(create.WebSiteID), websiteDomainRepo.WithPort(create.Port)); len(oldDomains) == 0 {
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(create.WebsiteID), websiteDomainRepo.WithPort(create.Port)); len(oldDomains) == 0 {
ports = append(ports, create.Port)
}
domains = append(domains, create.Domain)
if err := addListenAndServerName(website, ports, domains); err != nil {
return domainModel, err
}
domainModel = model.WebSiteDomain{
domainModel = model.WebsiteDomain{
Domain: create.Domain,
Port: create.Port,
WebSiteID: create.WebSiteID,
WebsiteID: create.WebsiteID,
}
return domainModel, websiteDomainRepo.Create(context.TODO(), &domainModel)
}
func (w WebsiteService) GetWebsiteDomain(websiteId uint) ([]model.WebSiteDomain, error) {
return websiteDomainRepo.GetBy(websiteDomainRepo.WithWebSiteId(websiteId))
func (w WebsiteService) GetWebsiteDomain(websiteId uint) ([]model.WebsiteDomain, error) {
return websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(websiteId))
}
func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error {
@ -314,20 +315,20 @@ func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error {
return err
}
if websiteDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebSiteId(webSiteDomain.WebSiteID)); len(websiteDomains) == 1 {
if websiteDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(webSiteDomain.WebsiteID)); len(websiteDomains) == 1 {
return fmt.Errorf("can not delete last domain")
}
website, err := websiteRepo.GetFirst(commonRepo.WithByID(webSiteDomain.WebSiteID))
website, err := websiteRepo.GetFirst(commonRepo.WithByID(webSiteDomain.WebsiteID))
if err != nil {
return err
}
var ports []int
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebSiteId(webSiteDomain.WebSiteID), websiteDomainRepo.WithPort(webSiteDomain.Port)); len(oldDomains) == 1 {
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(webSiteDomain.WebsiteID), websiteDomainRepo.WithPort(webSiteDomain.Port)); len(oldDomains) == 1 {
ports = append(ports, webSiteDomain.Port)
}
var domains []string
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebSiteId(webSiteDomain.WebSiteID), websiteDomainRepo.WithDomain(webSiteDomain.Domain)); len(oldDomains) == 1 {
if oldDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(webSiteDomain.WebsiteID), websiteDomainRepo.WithDomain(webSiteDomain.Domain)); len(oldDomains) == 1 {
domains = append(domains, webSiteDomain.Domain)
}
if len(ports) > 0 || len(domains) > 0 {
@ -339,17 +340,17 @@ func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error {
return websiteDomainRepo.DeleteBy(context.TODO(), commonRepo.WithByID(domainId))
}
func (w WebsiteService) GetNginxConfigByScope(req dto.NginxConfigReq) (*dto.WebsiteNginxConfig, error) {
func (w WebsiteService) GetNginxConfigByScope(req dto.NginxConfigReq) (*response.WebsiteNginxConfig, error) {
keys, ok := dto.ScopeKeyMap[req.Scope]
if !ok || len(keys) == 0 {
return nil, nil
}
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebSiteID))
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
if err != nil {
return nil, err
}
var config dto.WebsiteNginxConfig
var config response.WebsiteNginxConfig
params, err := getNginxParamsByKeys(constant.NginxScopeServer, keys, &website)
if err != nil {
return nil, err
@ -365,7 +366,7 @@ func (w WebsiteService) UpdateNginxConfigByScope(req dto.NginxConfigReq) error {
if !ok || len(keys) == 0 {
return nil
}
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebSiteID))
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
if err != nil {
return err
}
@ -408,54 +409,54 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteId uint) (dto.FileInfo, err
return dto.FileInfo{FileInfo: *info}, nil
}
func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (dto.WebsiteHTTPS, error) {
func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId))
if err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
var res dto.WebsiteHTTPS
if website.WebSiteSSLID == 0 {
var res response.WebsiteHTTPS
if website.WebsiteSSLID == 0 {
res.Enable = false
return res, nil
}
websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebSiteSSLID))
websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebsiteSSLID))
if err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
res.SSL = websiteSSL
res.Enable = true
return res, nil
}
func (w WebsiteService) OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS, error) {
func (w WebsiteService) OpWebsiteHTTPS(req request.WebsiteHTTPSOp) (response.WebsiteHTTPS, error) {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
if err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
var (
res dto.WebsiteHTTPS
websiteSSL model.WebSiteSSL
res response.WebsiteHTTPS
websiteSSL model.WebsiteSSL
)
res.Enable = req.Enable
if req.Type == dto.SSLExisted {
if req.Type == constant.SSLExisted {
websiteSSL, err = websiteSSLRepo.GetFirst(commonRepo.WithByID(req.WebsiteSSLID))
if err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
website.WebSiteSSLID = websiteSSL.ID
website.WebsiteSSLID = websiteSSL.ID
if err := websiteRepo.Save(context.TODO(), &website); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
res.SSL = websiteSSL
}
if req.Type == dto.Manual {
if req.Type == constant.SSLManual {
certBlock, _ := pem.Decode([]byte(req.Certificate))
cert, err := x509.ParseCertificate(certBlock.Bytes)
if err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
websiteSSL.ExpireDate = cert.NotAfter
websiteSSL.StartDate = cert.NotBefore
@ -486,39 +487,39 @@ func (w WebsiteService) OpWebsiteHTTPS(req dto.WebsiteHTTPSOp) (dto.WebsiteHTTPS
if req.Enable {
website.Protocol = constant.ProtocolHTTPS
if err := applySSL(website, websiteSSL); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
} else {
website.Protocol = constant.ProtocolHTTP
website.WebSiteSSLID = 0
website.WebsiteSSLID = 0
if err := deleteListenAndServerName(website, []int{443}, []string{}); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
if err := deleteNginxConfig(constant.NginxScopeServer, getKeysFromStaticFile(dto.SSL), &website); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
}
tx, ctx := getTxAndContext()
if websiteSSL.ID == 0 {
if err := websiteSSLRepo.Create(ctx, &websiteSSL); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
website.WebSiteSSLID = websiteSSL.ID
website.WebsiteSSLID = websiteSSL.ID
}
if err := websiteRepo.Save(ctx, &website); err != nil {
return dto.WebsiteHTTPS{}, err
return response.WebsiteHTTPS{}, err
}
tx.Commit()
return res, nil
}
func (w WebsiteService) PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.WebsitePreInstallCheck, error) {
func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]response.WebsitePreInstallCheck, error) {
var (
res []dto.WebsitePreInstallCheck
res []response.WebsitePreInstallCheck
checkIds []uint
showErr = false
)
@ -529,7 +530,7 @@ func (w WebsiteService) PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.W
}
appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID))
if reflect.DeepEqual(appInstall, model.AppInstall{}) {
res = append(res, dto.WebsitePreInstallCheck{
res = append(res, response.WebsitePreInstallCheck{
Name: appInstall.Name,
AppName: app.Name,
Status: buserr.WithMessage(constant.ErrNotInstall, app.Name, nil).Error(),
@ -547,7 +548,7 @@ func (w WebsiteService) PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.W
if len(checkIds) > 0 {
installList, _ := appInstallRepo.GetBy(commonRepo.WithIdsIn(checkIds))
for _, install := range installList {
res = append(res, dto.WebsitePreInstallCheck{
res = append(res, response.WebsitePreInstallCheck{
Name: install.Name,
Status: install.Status,
Version: install.Version,
@ -565,8 +566,8 @@ func (w WebsiteService) PreInstallCheck(req dto.WebsiteInstallCheckReq) ([]dto.W
}
}
func (w WebsiteService) GetWafConfig(req request.WebsiteWafReq) (dto.WebsiteWafConfig, error) {
var res dto.WebsiteWafConfig
func (w WebsiteService) GetWafConfig(req request.WebsiteWafReq) (response.WebsiteWafConfig, error) {
var res response.WebsiteWafConfig
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
if err != nil {
return res, nil

View File

@ -8,10 +8,10 @@ import (
"github.com/1Panel-dev/1Panel/backend/utils/ssl"
)
type WebSiteAcmeAccountService struct {
type WebsiteAcmeAccountService struct {
}
func (w WebSiteAcmeAccountService) Page(search dto.PageInfo) (int64, []dto.WebsiteAcmeAccountDTO, error) {
func (w WebsiteAcmeAccountService) Page(search dto.PageInfo) (int64, []dto.WebsiteAcmeAccountDTO, error) {
total, accounts, err := websiteAcmeRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc"))
var accountDTOs []dto.WebsiteAcmeAccountDTO
for _, account := range accounts {
@ -22,7 +22,7 @@ func (w WebSiteAcmeAccountService) Page(search dto.PageInfo) (int64, []dto.Websi
return total, accountDTOs, err
}
func (w WebSiteAcmeAccountService) Create(create dto.WebsiteAcmeAccountCreate) (dto.WebsiteAcmeAccountDTO, error) {
func (w WebsiteAcmeAccountService) Create(create dto.WebsiteAcmeAccountCreate) (dto.WebsiteAcmeAccountDTO, error) {
client, err := ssl.NewAcmeClient(create.Email, "")
if err != nil {
return dto.WebsiteAcmeAccountDTO{}, err
@ -38,7 +38,7 @@ func (w WebSiteAcmeAccountService) Create(create dto.WebsiteAcmeAccountCreate) (
return dto.WebsiteAcmeAccountDTO{WebsiteAcmeAccount: acmeAccount}, nil
}
func (w WebSiteAcmeAccountService) Delete(id uint) error {
func (w WebsiteAcmeAccountService) Delete(id uint) error {
if ssls, _ := websiteSSLRepo.List(websiteSSLRepo.WithByAcmeAccountId(id)); len(ssls) > 0 {
return buserr.New(constant.ErrAccountCannotDelete)
}

View File

@ -8,10 +8,10 @@ import (
"gopkg.in/square/go-jose.v2/json"
)
type WebSiteDnsAccountService struct {
type WebsiteDnsAccountService struct {
}
func (w WebSiteDnsAccountService) Page(search dto.PageInfo) (int64, []dto.WebsiteDnsAccountDTO, error) {
func (w WebsiteDnsAccountService) Page(search dto.PageInfo) (int64, []dto.WebsiteDnsAccountDTO, error) {
total, accounts, err := websiteDnsRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc"))
var accountDTOs []dto.WebsiteDnsAccountDTO
for _, account := range accounts {
@ -25,7 +25,7 @@ func (w WebSiteDnsAccountService) Page(search dto.PageInfo) (int64, []dto.Websit
return total, accountDTOs, err
}
func (w WebSiteDnsAccountService) Create(create dto.WebsiteDnsAccountCreate) (dto.WebsiteDnsAccountCreate, error) {
func (w WebsiteDnsAccountService) Create(create dto.WebsiteDnsAccountCreate) (dto.WebsiteDnsAccountCreate, error) {
authorization, err := json.Marshal(create.Authorization)
if err != nil {
return dto.WebsiteDnsAccountCreate{}, err
@ -42,7 +42,7 @@ func (w WebSiteDnsAccountService) Create(create dto.WebsiteDnsAccountCreate) (dt
return create, nil
}
func (w WebSiteDnsAccountService) Update(update dto.WebsiteDnsAccountUpdate) (dto.WebsiteDnsAccountUpdate, error) {
func (w WebsiteDnsAccountService) Update(update dto.WebsiteDnsAccountUpdate) (dto.WebsiteDnsAccountUpdate, error) {
authorization, err := json.Marshal(update.Authorization)
if err != nil {
return dto.WebsiteDnsAccountUpdate{}, err
@ -62,7 +62,7 @@ func (w WebSiteDnsAccountService) Update(update dto.WebsiteDnsAccountUpdate) (dt
return update, nil
}
func (w WebSiteDnsAccountService) Delete(id uint) error {
func (w WebsiteDnsAccountService) Delete(id uint) error {
if ssls, _ := websiteSSLRepo.List(websiteSSLRepo.WithByDnsAccountId(id)); len(ssls) > 0 {
return buserr.New(constant.ErrAccountCannotDelete)
}

View File

@ -1,30 +1,30 @@
package service
import (
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/model"
)
type WebsiteGroupService struct {
}
func (w WebsiteGroupService) CreateGroup(create dto.WebSiteGroupCreate) error {
return websiteGroupRepo.Create(&model.WebSiteGroup{
func (w WebsiteGroupService) CreateGroup(create request.WebsiteGroupCreate) error {
return websiteGroupRepo.Create(&model.WebsiteGroup{
Name: create.Name,
})
}
func (w WebsiteGroupService) GetGroups() ([]model.WebSiteGroup, error) {
func (w WebsiteGroupService) GetGroups() ([]model.WebsiteGroup, error) {
return websiteGroupRepo.GetBy()
}
func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error {
func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) error {
if update.Default {
if err := websiteGroupRepo.CancelDefault(); err != nil {
return err
}
return websiteGroupRepo.Save(&model.WebSiteGroup{
return websiteGroupRepo.Save(&model.WebsiteGroup{
BaseModel: model.BaseModel{
ID: update.ID,
},
@ -32,7 +32,7 @@ func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error {
Default: true,
})
} else {
return websiteGroupRepo.Save(&model.WebSiteGroup{
return websiteGroupRepo.Save(&model.WebsiteGroup{
BaseModel: model.BaseModel{
ID: update.ID,
},

View File

@ -13,10 +13,10 @@ import (
"strings"
)
type WebSiteSSLService struct {
type WebsiteSSLService struct {
}
func (w WebSiteSSLService) Page(search dto.WebsiteSSLSearch) (int64, []dto.WebsiteSSLDTO, error) {
func (w WebsiteSSLService) Page(search dto.WebsiteSSLSearch) (int64, []dto.WebsiteSSLDTO, error) {
total, sslList, err := websiteSSLRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc"))
if err != nil {
return 0, nil, err
@ -24,13 +24,13 @@ func (w WebSiteSSLService) Page(search dto.WebsiteSSLSearch) (int64, []dto.Websi
var sslDTOs []dto.WebsiteSSLDTO
for _, ssl := range sslList {
sslDTOs = append(sslDTOs, dto.WebsiteSSLDTO{
WebSiteSSL: ssl,
WebsiteSSL: ssl,
})
}
return total, sslDTOs, err
}
func (w WebSiteSSLService) Search() ([]dto.WebsiteSSLDTO, error) {
func (w WebsiteSSLService) Search() ([]dto.WebsiteSSLDTO, error) {
sslList, err := websiteSSLRepo.List()
if err != nil {
return nil, err
@ -38,13 +38,13 @@ func (w WebSiteSSLService) Search() ([]dto.WebsiteSSLDTO, error) {
var sslDTOs []dto.WebsiteSSLDTO
for _, ssl := range sslList {
sslDTOs = append(sslDTOs, dto.WebsiteSSLDTO{
WebSiteSSL: ssl,
WebsiteSSL: ssl,
})
}
return sslDTOs, err
}
func (w WebSiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCreate, error) {
func (w WebsiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCreate, error) {
var res dto.WebsiteSSLCreate
acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(create.AcmeAccountID))
@ -87,7 +87,7 @@ func (w WebSiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCr
if err != nil {
return res, err
}
var websiteSSL model.WebSiteSSL
var websiteSSL model.WebsiteSSL
websiteSSL.DnsAccountID = create.DnsAccountID
websiteSSL.AcmeAccountID = acmeAccount.ID
websiteSSL.Provider = string(create.Provider)
@ -113,7 +113,7 @@ func (w WebSiteSSLService) Create(create dto.WebsiteSSLCreate) (dto.WebsiteSSLCr
return create, nil
}
func (w WebSiteSSLService) Renew(sslId uint) error {
func (w WebsiteSSLService) Renew(sslId uint) error {
websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(sslId))
if err != nil {
@ -169,7 +169,7 @@ func (w WebSiteSSLService) Renew(sslId uint) error {
return websiteSSLRepo.Save(websiteSSL)
}
func (w WebSiteSSLService) GetDNSResolve(req dto.WebsiteDNSReq) ([]dto.WebsiteDNSRes, error) {
func (w WebsiteSSLService) GetDNSResolve(req dto.WebsiteDNSReq) ([]dto.WebsiteDNSRes, error) {
acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(req.AcmeAccountID))
if err != nil {
return nil, err
@ -195,21 +195,21 @@ func (w WebSiteSSLService) GetDNSResolve(req dto.WebsiteDNSReq) ([]dto.WebsiteDN
return res, nil
}
func (w WebSiteSSLService) GetWebsiteSSL(websiteId uint) (dto.WebsiteSSLDTO, error) {
func (w WebsiteSSLService) GetWebsiteSSL(websiteId uint) (dto.WebsiteSSLDTO, error) {
var res dto.WebsiteSSLDTO
website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId))
if err != nil {
return res, err
}
websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebSiteSSLID))
websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebsiteSSLID))
if err != nil {
return res, err
}
res.WebSiteSSL = websiteSSL
res.WebsiteSSL = websiteSSL
return res, nil
}
func (w WebSiteSSLService) Delete(id uint) error {
func (w WebsiteSSLService) Delete(id uint) error {
if websites, _ := websiteRepo.GetBy(websiteRepo.WithWebsiteSSLID(id)); len(websites) > 0 {
return buserr.New(constant.ErrSSLCannotDelete)
}

View File

@ -24,9 +24,9 @@ import (
"strings"
)
func getDomain(domainStr string, websiteID uint) (model.WebSiteDomain, error) {
domain := model.WebSiteDomain{
WebSiteID: websiteID,
func getDomain(domainStr string, websiteID uint) (model.WebsiteDomain, error) {
domain := model.WebsiteDomain{
WebsiteID: websiteID,
}
domainArray := strings.Split(domainStr, ":")
if len(domainArray) == 1 {
@ -39,15 +39,15 @@ func getDomain(domainStr string, websiteID uint) (model.WebSiteDomain, error) {
portStr := domainArray[1]
portN, err := strconv.Atoi(portStr)
if err != nil {
return model.WebSiteDomain{}, err
return model.WebsiteDomain{}, err
}
domain.Port = portN
return domain, nil
}
return model.WebSiteDomain{}, nil
return model.WebsiteDomain{}, nil
}
func createStaticHtml(website *model.WebSite) error {
func createStaticHtml(website *model.Website) error {
nginxInstall, err := getAppInstallByKey("nginx")
if err != nil {
return err
@ -73,7 +73,7 @@ func createStaticHtml(website *model.WebSite) error {
return nil
}
func createWebsiteFolder(nginxInstall model.AppInstall, website *model.WebSite) error {
func createWebsiteFolder(nginxInstall model.AppInstall, website *model.Website) error {
nginxFolder := path.Join(constant.AppInstallDir, "nginx", nginxInstall.Name)
siteFolder := path.Join(nginxFolder, "www", "sites", website.Alias)
fileOp := files.NewFileOp()
@ -97,7 +97,7 @@ func createWebsiteFolder(nginxInstall model.AppInstall, website *model.WebSite)
return fileOp.CopyDir(path.Join(nginxFolder, "www", "common", "waf", "rules"), path.Join(siteFolder, "waf"))
}
func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) error {
func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain) error {
nginxInstall, err := getAppInstallByKey("nginx")
if err != nil {
return err
@ -155,7 +155,7 @@ func configDefaultNginx(website *model.WebSite, domains []model.WebSiteDomain) e
return opNginx(nginxInstall.ContainerName, constant.NginxReload)
}
func delNginxConfig(website model.WebSite, force bool) error {
func delNginxConfig(website model.Website, force bool) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
if err != nil {
return err
@ -187,7 +187,7 @@ func delNginxConfig(website model.WebSite, force bool) error {
return nil
}
func addListenAndServerName(website model.WebSite, ports []int, domains []string) error {
func addListenAndServerName(website model.Website, ports []int, domains []string) error {
nginxFull, err := getNginxFull(&website)
if err != nil {
return nil
@ -207,7 +207,7 @@ func addListenAndServerName(website model.WebSite, ports []int, domains []string
return nginxCheckAndReload(nginxConfig.OldContent, nginxConfig.FilePath, nginxFull.Install.ContainerName)
}
func deleteListenAndServerName(website model.WebSite, ports []int, domains []string) error {
func deleteListenAndServerName(website model.Website, ports []int, domains []string) error {
nginxFull, err := getNginxFull(&website)
if err != nil {
return nil
@ -241,7 +241,7 @@ func getKeysFromStaticFile(scope dto.NginxKey) []string {
return res
}
func createPemFile(website model.WebSite, websiteSSL model.WebSiteSSL) error {
func createPemFile(website model.Website, websiteSSL model.WebsiteSSL) error {
nginxApp, err := appRepo.GetFirst(appRepo.WithKey("nginx"))
if err != nil {
return err
@ -283,7 +283,7 @@ func createPemFile(website model.WebSite, websiteSSL model.WebSiteSSL) error {
return nil
}
func applySSL(website model.WebSite, websiteSSL model.WebSiteSSL) error {
func applySSL(website model.Website, websiteSSL model.WebsiteSSL) error {
nginxFull, err := getNginxFull(&website)
if err != nil {
return nil
@ -369,7 +369,7 @@ func toMapStr(m map[string]interface{}) map[string]string {
return ret
}
type WebSiteInfo struct {
type WebsiteInfo struct {
WebsiteName string `json:"websiteName"`
WebsiteType string `json:"websiteType"`
}
@ -444,7 +444,7 @@ func handleWebsiteBackup(backupType, baseDir, backupDir, domain, backupName stri
return nil
}
func handleWebsiteRecover(website *model.WebSite, fileDir string) error {
func handleWebsiteRecover(website *model.Website, fileDir string) error {
nginxInfo, err := appInstallRepo.LoadBaseInfoByKey("nginx")
if err != nil {
return err
@ -486,7 +486,7 @@ func handleWebsiteRecover(website *model.WebSite, fileDir string) error {
return nil
}
func mysqlOpration(website *model.WebSite, operation, filePath string) error {
func mysqlOpration(website *model.Website, operation, filePath string) error {
mysqlInfo, err := appInstallRepo.LoadBaseInfoByKey("mysql")
if err != nil {
return err
@ -523,11 +523,11 @@ func mysqlOpration(website *model.WebSite, operation, filePath string) error {
return nil
}
func saveWebsiteJson(website *model.WebSite, tmpDir string) error {
var WebSiteInfo WebSiteInfo
WebSiteInfo.WebsiteType = website.Type
WebSiteInfo.WebsiteName = website.PrimaryDomain
remarkInfo, _ := json.Marshal(WebSiteInfo)
func saveWebsiteJson(website *model.Website, tmpDir string) error {
var websiteInfo WebsiteInfo
websiteInfo.WebsiteType = website.Type
websiteInfo.WebsiteName = website.PrimaryDomain
remarkInfo, _ := json.Marshal(websiteInfo)
path := fmt.Sprintf("%s/website.json", tmpDir)
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {

View File

@ -6,13 +6,9 @@ const (
Error = "Error"
Stopped = "Stopped"
Installing = "Installing"
)
const (
ContainerPrefix = "1Panel-"
)
const (
AppNormal = "Normal"
AppTakeDown = "TakeDown"
)

View File

@ -3,20 +3,21 @@ package constant
const (
WebRunning = "Running"
WebStopped = "Stopped"
)
const (
DateLayout = "2006-01-02"
DefaultDate = "1970-01-01"
)
const (
ProtocolHTTP = "HTTP"
ProtocolHTTPS = "HTTPS"
)
const (
NewApp = "new"
InstalledApp = "installed"
Deployment = "deployment"
Static = "static"
Proxy = "proxy"
SSLExisted = "existed"
SSLAuto = "auto"
SSLManual = "manual"
)

View File

@ -185,10 +185,10 @@ var AddTableDatabaseMysql = &gormigrate.Migration{
var AddTableWebsite = &gormigrate.Migration{
ID: "20201009-add-table-website",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.WebSite{}, &model.WebSiteDomain{}, &model.WebSiteGroup{}, &model.WebsiteDnsAccount{}, &model.WebSiteSSL{}, &model.WebsiteAcmeAccount{}); err != nil {
if err := tx.AutoMigrate(&model.Website{}, &model.WebsiteDomain{}, &model.WebsiteGroup{}, &model.WebsiteDnsAccount{}, &model.WebsiteSSL{}, &model.WebsiteAcmeAccount{}); err != nil {
return err
}
item := &model.WebSiteGroup{
item := &model.WebsiteGroup{
Name: "默认分组",
Default: true,
}

View File

@ -15,20 +15,22 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
baseApi := v1.ApiGroupApp.BaseApi
{
groupRouter.POST("/search", baseApi.PageWebsite)
groupRouter.POST("", baseApi.CreateWebsite)
groupRouter.POST("/check", baseApi.CreateWebsiteCheck)
groupRouter.GET("/options", baseApi.GetWebsiteOptions)
groupRouter.POST("/update", baseApi.UpdateWebsite)
groupRouter.GET("/:id", baseApi.GetWebsite)
groupRouter.POST("/del", baseApi.DeleteWebsite)
groupRouter.POST("/backup/:domain", baseApi.BackupWebsite)
groupRouter.POST("/recover", baseApi.RecoverWebsite)
groupRouter.POST("/recover/byupload", baseApi.RecoverWebsiteByUpload)
groupRouter.POST("/update", baseApi.UpdateWebSite)
groupRouter.GET("/:id", baseApi.GetWebSite)
groupRouter.GET("/:id/nginx", baseApi.GetWebSiteNginx)
groupRouter.POST("/search", baseApi.PageWebsite)
groupRouter.POST("/del", baseApi.DeleteWebSite)
groupRouter.GET("/domains/:websiteId", baseApi.GetWebDomains)
groupRouter.DELETE("/domains/:id", baseApi.DeleteWebDomain)
groupRouter.POST("/domains/del", baseApi.DeleteWebDomain)
groupRouter.POST("/domains", baseApi.CreateWebDomain)
groupRouter.GET("/:id/nginx", baseApi.GetWebsiteNginx)
groupRouter.POST("/config", baseApi.GetNginxConfig)
groupRouter.POST("/config/update", baseApi.UpdateNginxConfig)
groupRouter.GET("/:id/https", baseApi.GetHTTPSConfig)

View File

@ -1,7 +1,7 @@
import { CommonModel, ReqPage } from '.';
export namespace WebSite {
export interface WebSite extends CommonModel {
export namespace Website {
export interface Website extends CommonModel {
primaryDomain: string;
type: string;
alias: string;
@ -15,19 +15,6 @@ export namespace WebSite {
webSiteSSL: SSL;
}
export interface WebSiteDTO extends CommonModel {
primaryDomain: string;
type: string;
alias: string;
remark: string;
domains: WebSite.Domain[];
appType: string;
appInstallId?: number;
webSiteGroupId: number;
otherDomains: string;
appinstall?: NewAppInstall;
}
export interface NewAppInstall {
name: string;
appDetailId: number;
@ -100,6 +87,10 @@ export namespace WebSite {
domain: string;
}
export interface DomainDelete {
id: number;
}
export interface NginxConfigReq {
operate: string;
websiteId: number;

View File

@ -1,32 +1,34 @@
import http from '@/api';
import { ReqPage, ResPage } from '../interface';
import { WebSite } from '../interface/website';
import { Website } from '../interface/Website';
import { File } from '../interface/file';
export const SearchWebSites = (req: WebSite.WebSiteSearch) => {
return http.post<ResPage<WebSite.WebSite>>(`/websites/search`, req);
export const SearchWebsites = (req: Website.WebSiteSearch) => {
return http.post<ResPage<Website.Website>>(`/websites/search`, req);
};
export const CreateWebsite = (req: WebSite.WebSiteCreateReq) => {
export const CreateWebsite = (req: Website.WebSiteCreateReq) => {
return http.post<any>(`/websites`, req);
};
export const BackupWebsite = (id: number) => {
return http.post(`/websites/backup/${id}`);
};
export const RecoverWebsite = (req: WebSite.WebSiteRecover) => {
export const RecoverWebsite = (req: Website.WebSiteRecover) => {
return http.post(`/websites/recover`, req);
};
export const RecoverWebsiteByUpload = (req: WebSite.WebsiteRecoverByUpload) => {
export const RecoverWebsiteByUpload = (req: Website.WebsiteRecoverByUpload) => {
return http.post(`/websites/recover/byupload`, req);
};
export const UpdateWebsite = (req: WebSite.WebSiteUpdateReq) => {
export const UpdateWebsite = (req: Website.WebSiteUpdateReq) => {
return http.post<any>(`/websites/update`, req);
};
export const GetWebsite = (id: number) => {
return http.get<WebSite.WebSiteDTO>(`/websites/${id}`);
return http.get<Website.Website>(`/websites/${id}`);
};
export const GetWebsiteOptions = () => {
@ -37,19 +39,19 @@ export const GetWebsiteNginx = (id: number) => {
return http.get<File.File>(`/websites/${id}/nginx`);
};
export const DeleteWebsite = (req: WebSite.WebSiteDel) => {
export const DeleteWebsite = (req: Website.WebSiteDel) => {
return http.post<any>(`/websites/del`, req);
};
export const ListGroups = () => {
return http.get<WebSite.Group[]>(`/websites/groups`);
return http.get<Website.Group[]>(`/websites/groups`);
};
export const CreateGroup = (req: WebSite.GroupOp) => {
export const CreateGroup = (req: Website.GroupOp) => {
return http.post<any>(`/websites/groups`, req);
};
export const UpdateGroup = (req: WebSite.GroupOp) => {
export const UpdateGroup = (req: Website.GroupOp) => {
return http.put<any>(`/websites/groups`, req);
};
@ -58,34 +60,34 @@ export const DeleteGroup = (id: number) => {
};
export const ListDomains = (id: number) => {
return http.get<WebSite.Domain[]>(`/websites/domains/${id}`);
return http.get<Website.Domain[]>(`/websites/domains/${id}`);
};
export const DeleteDomain = (id: number) => {
return http.delete<any>(`/websites/domains/${id}`);
export const DeleteDomain = (req: Website.DomainDelete) => {
return http.post<any>(`/websites/domains/del/`, req);
};
export const CreateDomain = (req: WebSite.DomainCreate) => {
export const CreateDomain = (req: Website.DomainCreate) => {
return http.post<any>(`/websites/domains`, req);
};
export const GetNginxConfig = (req: WebSite.NginxConfigReq) => {
return http.post<WebSite.NginxScopeConfig>(`/websites/config`, req);
export const GetNginxConfig = (req: Website.NginxConfigReq) => {
return http.post<Website.NginxScopeConfig>(`/websites/config`, req);
};
export const UpdateNginxConfig = (req: WebSite.NginxConfigReq) => {
export const UpdateNginxConfig = (req: Website.NginxConfigReq) => {
return http.post<any>(`/websites/config/update`, req);
};
export const SearchDnsAccount = (req: ReqPage) => {
return http.post<ResPage<WebSite.DnsAccount>>(`/websites/dns/search`, req);
return http.post<ResPage<Website.DnsAccount>>(`/websites/dns/search`, req);
};
export const CreateDnsAccount = (req: WebSite.DnsAccountCreate) => {
export const CreateDnsAccount = (req: Website.DnsAccountCreate) => {
return http.post<any>(`/websites/dns`, req);
};
export const UpdateDnsAccount = (req: WebSite.DnsAccountUpdate) => {
export const UpdateDnsAccount = (req: Website.DnsAccountUpdate) => {
return http.post<any>(`/websites/dns/update`, req);
};
@ -94,11 +96,11 @@ export const DeleteDnsAccount = (id: number) => {
};
export const SearchAcmeAccount = (req: ReqPage) => {
return http.post<ResPage<WebSite.AcmeAccount>>(`/websites/acme/search`, req);
return http.post<ResPage<Website.AcmeAccount>>(`/websites/acme/search`, req);
};
export const CreateAcmeAccount = (req: WebSite.AcmeAccountCreate) => {
return http.post<WebSite.AcmeAccount>(`/websites/acme`, req);
export const CreateAcmeAccount = (req: Website.AcmeAccountCreate) => {
return http.post<Website.AcmeAccount>(`/websites/acme`, req);
};
export const DeleteAcmeAccount = (id: number) => {
@ -106,15 +108,15 @@ export const DeleteAcmeAccount = (id: number) => {
};
export const SearchSSL = (req: ReqPage) => {
return http.post<ResPage<WebSite.SSL>>(`/websites/ssl/search`, req);
return http.post<ResPage<Website.SSL>>(`/websites/ssl/search`, req);
};
export const ListSSL = (req: WebSite.SSLReq) => {
return http.post<WebSite.SSL[]>(`/websites/ssl/search`, req);
export const ListSSL = (req: Website.SSLReq) => {
return http.post<Website.SSL[]>(`/websites/ssl/search`, req);
};
export const CreateSSL = (req: WebSite.SSLCreate) => {
return http.post<WebSite.SSLCreate>(`/websites/ssl`, req);
export const CreateSSL = (req: Website.SSLCreate) => {
return http.post<Website.SSLCreate>(`/websites/ssl`, req);
};
export const DeleteSSL = (id: number) => {
@ -122,37 +124,37 @@ export const DeleteSSL = (id: number) => {
};
export const GetWebsiteSSL = (websiteId: number) => {
return http.get<WebSite.SSL>(`/websites/ssl/${websiteId}`);
return http.get<Website.SSL>(`/websites/ssl/${websiteId}`);
};
export const ApplySSL = (req: WebSite.SSLApply) => {
return http.post<WebSite.SSLApply>(`/websites/ssl/apply`, req);
export const ApplySSL = (req: Website.SSLApply) => {
return http.post<Website.SSLApply>(`/websites/ssl/apply`, req);
};
export const RenewSSL = (req: WebSite.SSLRenew) => {
export const RenewSSL = (req: Website.SSLRenew) => {
return http.post<any>(`/websites/ssl/renew`, req);
};
export const GetDnsResolve = (req: WebSite.DNSResolveReq) => {
return http.post<WebSite.DNSResolve[]>(`/websites/ssl/resolve`, req);
export const GetDnsResolve = (req: Website.DNSResolveReq) => {
return http.post<Website.DNSResolve[]>(`/websites/ssl/resolve`, req);
};
export const GetHTTPSConfig = (id: number) => {
return http.get<WebSite.HTTPSConfig>(`/websites/${id}/https`);
return http.get<Website.HTTPSConfig>(`/websites/${id}/https`);
};
export const UpdateHTTPSConfig = (req: WebSite.HTTPSReq) => {
return http.post<WebSite.HTTPSConfig>(`/websites/${req.websiteId}/https`, req);
export const UpdateHTTPSConfig = (req: Website.HTTPSReq) => {
return http.post<Website.HTTPSConfig>(`/websites/${req.websiteId}/https`, req);
};
export const PreCheck = (req: WebSite.CheckReq) => {
return http.post<WebSite.CheckRes[]>(`/websites/check`, req);
export const PreCheck = (req: Website.CheckReq) => {
return http.post<Website.CheckRes[]>(`/websites/check`, req);
};
export const GetWafConfig = (req: WebSite.WafReq) => {
return http.post<WebSite.WafRes>(`/websites/waf/config`, req);
export const GetWafConfig = (req: Website.WafReq) => {
return http.post<Website.WafRes>(`/websites/waf/config`, req);
};
export const UpdateWafEnable = (req: WebSite.WafUpdate) => {
export const UpdateWafEnable = (req: Website.WafUpdate) => {
return http.post<any>(`/websites/waf/update`, req);
};

View File

@ -23,7 +23,7 @@
</el-dialog>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { DeleteAcmeAccount, SearchAcmeAccount } from '@/api/modules/website';
import ComplexTable from '@/components/complex-table/index.vue';
import { useDeleteData } from '@/hooks/use-delete-data';
@ -44,7 +44,7 @@ const paginationConfig = reactive({
const buttons = [
{
label: i18n.global.t('app.delete'),
click: function (row: WebSite.AcmeAccount) {
click: function (row: Website.AcmeAccount) {
deleteAccount(row.id);
},
},

View File

@ -76,7 +76,7 @@
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { CreateSSL, GetDnsResolve, SearchAcmeAccount, SearchDnsAccount } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
@ -104,9 +104,9 @@ let acmeReq = reactive({
page: 1,
pageSize: 20,
});
let dnsAccounts = ref<WebSite.DnsAccount[]>();
let acmeAccounts = ref<WebSite.AcmeAccount[]>();
// let domains = ref<WebSite.Domain[]>([]);
let dnsAccounts = ref<Website.DnsAccount[]>();
let acmeAccounts = ref<Website.AcmeAccount[]>();
// let domains = ref<Website.Domain[]>([]);
let sslForm = ref<FormInstance>();
let rules = ref({
primaryDomain: [Rules.requiredInput],
@ -122,7 +122,7 @@ let ssl = ref({
acmeAccountId: undefined,
dnsAccountId: undefined,
});
let dnsResolve = ref<WebSite.DNSResolve[]>([]);
let dnsResolve = ref<Website.DNSResolve[]>([]);
let hasResolve = ref(false);
const em = defineEmits(['close']);
@ -168,10 +168,6 @@ const getDnsAccounts = async () => {
}
};
// const getWebsite = async (id: number) => {
// domains.value = (await GetWebsite(id)).data.domains || [];
// };
const getDnsResolve = async (acmeAccountId: number, domains: string[]) => {
hasResolve.value = false;
loading.value = true;

View File

@ -36,7 +36,7 @@
<script lang="ts" setup>
import ComplexTable from '@/components/complex-table/index.vue';
import Create from './create/index.vue';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { DeleteDnsAccount, SearchDnsAccount } from '@/api/modules/website';
import { onMounted, reactive, ref } from 'vue';
import i18n from '@/lang';
@ -47,7 +47,7 @@ const paginationConfig = reactive({
pageSize: 20,
total: 0,
});
let data = ref<WebSite.DnsAccount[]>();
let data = ref<Website.DnsAccount[]>();
let createRef = ref();
let loading = ref(false);
let open = ref(false);
@ -55,7 +55,7 @@ let open = ref(false);
const buttons = [
{
label: i18n.global.t('app.delete'),
click: function (row: WebSite.WebSite) {
click: function (row: Website.Website) {
deleteAccount(row.id);
},
},
@ -81,7 +81,7 @@ const openCreate = () => {
createRef.value.acceptParams({ mode: 'add' });
};
const openEdit = (form: WebSite.DnsAccount) => {
const openEdit = (form: Website.DnsAccount) => {
createRef.value.acceptParams({ mode: 'edit', form: form });
};

View File

@ -68,7 +68,7 @@ import Renew from './renew/index.vue';
import Create from './create/index.vue';
import { dateFromat } from '@/utils/util';
import i18n from '@/lang';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { useDeleteData } from '@/hooks/use-delete-data';
const paginationConfig = reactive({
@ -86,13 +86,13 @@ let loading = ref(false);
const buttons = [
{
label: i18n.global.t('website.renewSSL'),
click: function (row: WebSite.WebSite) {
click: function (row: Website.Website) {
openRenewSSL(row.id);
},
},
{
label: i18n.global.t('app.delete'),
click: function (row: WebSite.WebSite) {
click: function (row: Website.Website) {
deleteSSL(row.id);
},
},

View File

@ -29,13 +29,13 @@
</el-dialog>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
interface InstallRrops {
items: WebSite.CheckRes[];
items: Website.CheckRes[];
}
let open = ref(false);

View File

@ -18,7 +18,7 @@
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetNginxConfig, UpdateNginxConfig } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import { ElMessage, FormInstance } from 'element-plus';
@ -69,7 +69,7 @@ const submit = async (formEl: FormInstance | undefined) => {
});
};
const search = (req: WebSite.NginxConfigReq) => {
const search = (req: Website.NginxConfigReq) => {
loading.value = true;
GetNginxConfig(req)
.then((res) => {

View File

@ -1,7 +1,6 @@
<template>
<el-dialog
v-model="open"
:destroy-on-close="true"
:close-on-click-modal="false"
:title="$t('website.create')"
width="40%"
@ -36,7 +35,7 @@ import { ref } from 'vue';
const domainForm = ref<FormInstance>();
let rules = ref({
domain: [Rules.requiredInput],
domain: [Rules.requiredInput, Rules.domain],
port: [Rules.requiredInput],
});
@ -50,6 +49,7 @@ let domain = ref({
const em = defineEmits(['close']);
const handleClose = () => {
domainForm.value?.resetFields();
open.value = false;
em('close', false);
};

View File

@ -13,7 +13,7 @@
<script lang="ts" setup>
import ComplexTable from '@/components/complex-table/index.vue';
import Domain from './create/index.vue';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { DeleteDomain, ListDomains } from '@/api/modules/website';
import { computed, onMounted, ref } from 'vue';
import i18n from '@/lang';
@ -29,13 +29,13 @@ const id = computed(() => {
return props.id;
});
let loading = ref(false);
const data = ref<WebSite.Domain[]>([]);
const data = ref<Website.Domain[]>([]);
const domainRef = ref();
const buttons = [
{
label: i18n.global.t('app.delete'),
click: function (row: WebSite.Domain) {
click: function (row: Website.Domain) {
deleteDoamin(row.id);
},
disabled: () => {
@ -49,7 +49,7 @@ const openCreate = () => {
};
const deleteDoamin = async (domainId: number) => {
await useDeleteData(DeleteDomain, domainId, 'commons.msg.delete');
await useDeleteData(DeleteDomain, { id: domainId }, 'commons.msg.delete');
search(id.value);
};

View File

@ -62,7 +62,7 @@
</el-row>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetHTTPSConfig, ListSSL, UpdateHTTPSConfig } from '@/api/modules/website';
import { ElMessage, FormInstance } from 'element-plus';
import { computed, onMounted, reactive, ref } from 'vue';
@ -104,7 +104,7 @@ const listSSL = () => {
};
const changeSSl = (sslid: number) => {
const res = ssls.value.filter((element: WebSite.SSL) => {
const res = ssls.value.filter((element: Website.SSL) => {
return element.id == sslid;
});
websiteSSL.value = res[0];

View File

@ -25,7 +25,7 @@
<script lang="ts" setup>
import { Rules } from '@/global/form-rules';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetNginxConfig, UpdateNginxConfig } from '@/api/modules/website';
import { ElMessage, FormInstance } from 'element-plus';
import { computed, onMounted, reactive, ref } from 'vue';
@ -60,7 +60,7 @@ let req = reactive({
let enable = ref(false);
let loading = ref(false);
const search = (req: WebSite.NginxConfigReq) => {
const search = (req: Website.NginxConfigReq) => {
loading.value = true;
GetNginxConfig(req)
.then((res) => {

View File

@ -36,7 +36,7 @@
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetWebsite, UpdateWebsite } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import { computed, onMounted, reactive, ref } from 'vue';
@ -65,7 +65,7 @@ let rules = ref({
primaryDomain: [Rules.requiredInput],
webSiteGroupId: [Rules.requiredSelect],
});
let groups = ref<WebSite.Group[]>([]);
let groups = ref<Website.Group[]>([]);
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;

View File

@ -39,7 +39,7 @@
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { SaveFileContent } from '@/api/modules/files';
import { GetWafConfig, UpdateWafEnable } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
@ -57,19 +57,19 @@ const id = computed(() => {
return props.id;
});
let data = ref<WebSite.WafRes>();
let data = ref<Website.WafRes>();
let loading = ref(false);
let form = reactive({
enable: false,
cycle: 60,
frequency: 120,
});
let req = ref<WebSite.WafReq>({
let req = ref<Website.WafReq>({
websiteId: 0,
key: '$CCDeny',
rule: 'ccrate',
});
let enableUpdate = ref<WebSite.WafUpdate>({
let enableUpdate = ref<Website.WafUpdate>({
websiteId: 0,
key: '$CCDeny',
enable: false,

View File

@ -37,7 +37,7 @@
</el-row>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetWafConfig, UpdateWafEnable } from '@/api/modules/website';
import { computed, onMounted, reactive, ref } from 'vue';
import ComplexTable from '@/components/complex-table/index.vue';
@ -57,7 +57,7 @@ const id = computed(() => {
let loading = ref(false);
let data = ref([]);
let req = ref<WebSite.WafReq>({
let req = ref<Website.WafReq>({
websiteId: 0,
key: '$fileExtDeny',
rule: 'fileExtBlockList',
@ -66,7 +66,7 @@ let fileUpdate = reactive({
path: '',
content: '',
});
let enableUpdate = ref<WebSite.WafUpdate>({
let enableUpdate = ref<Website.WafUpdate>({
websiteId: 0,
key: '$fileExtDeny',
enable: false,

View File

@ -37,7 +37,7 @@
</el-row>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetWafConfig, UpdateWafEnable } from '@/api/modules/website';
import { computed, onMounted, reactive, ref } from 'vue';
import ComplexTable from '@/components/complex-table/index.vue';
@ -72,7 +72,7 @@ const key = computed(() => {
let loading = ref(false);
let data = ref([]);
let req = ref<WebSite.WafReq>({
let req = ref<Website.WafReq>({
websiteId: 0,
key: '$ipWhiteAllow',
rule: 'ipWhitelist',
@ -81,7 +81,7 @@ let fileUpdate = reactive({
path: '',
content: '',
});
let enableUpdate = ref<WebSite.WafUpdate>({
let enableUpdate = ref<Website.WafUpdate>({
websiteId: 0,
key: '$ipWhiteAllow',
enable: false,

View File

@ -42,7 +42,7 @@
</el-row>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetWafConfig, UpdateWafEnable } from '@/api/modules/website';
import { computed, onMounted, reactive, ref } from 'vue';
import ComplexTable from '@/components/complex-table/index.vue';
@ -76,7 +76,7 @@ const key = computed(() => {
let loading = ref(false);
let data = ref([]);
let req = ref<WebSite.WafReq>({
let req = ref<Website.WafReq>({
websiteId: 0,
key: '',
rule: 'url',
@ -85,7 +85,7 @@ let fileUpdate = reactive({
path: '',
content: '',
});
let enableUpdate = ref<WebSite.WafUpdate>({
let enableUpdate = ref<Website.WafUpdate>({
websiteId: 0,
key: '$UrlDeny',
enable: false,

View File

@ -131,7 +131,7 @@
<script lang="ts" setup name="CreateWebSite">
import { App } from '@/api/interface/app';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
import { GetApp, GetAppDetail, SearchApp, GetAppInstalled } from '@/api/modules/app';
import { CreateWebsite, ListGroups, PreCheck } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
@ -177,7 +177,7 @@ let rules = reactive({
let open = ref(false);
let loading = ref(false);
let groups = ref<WebSite.Group[]>([]);
let groups = ref<Website.Group[]>([]);
let appInstalles = ref<App.AppInstalled[]>([]);
let appReq = reactive({
type: 'website',

View File

@ -27,7 +27,7 @@ import { DeleteWebsite } from '@/api/modules/website';
import i18n from '@/lang';
import { ElMessage } from 'element-plus';
import { ref } from 'vue';
import { WebSite } from '@/api/interface/website';
import { Website } from '@/api/interface/website';
let key = 1;
let open = ref(false);
@ -46,7 +46,7 @@ const handleClose = () => {
em('close', false);
};
const acceptParams = async (website: WebSite.WebSite) => {
const acceptParams = async (website: Website.Website) => {
deleteReq.value = {
id: 0,
deleteApp: false,

View File

@ -86,8 +86,8 @@ import { onMounted, reactive, ref } from '@vue/runtime-core';
import CreateWebSite from './create/index.vue';
import DeleteWebsite from './delete/index.vue';
import WebSiteGroup from './group/index.vue';
import { SearchWebSites } from '@/api/modules/website';
import { WebSite } from '@/api/interface/website';
import { SearchWebsites } from '@/api/modules/website';
import { Website } from '@/api/interface/website';
import AppStatus from '@/components/app-status/index.vue';
import NginxConfig from './nginx/index.vue';
import { dateFromat } from '@/utils/util';
@ -121,7 +121,7 @@ const search = async () => {
pageSize: paginationConfig.pageSize,
};
SearchWebSites(req).then((res) => {
SearchWebsites(req).then((res) => {
data.value = res.data.items;
paginationConfig.total = res.data.total;
});
@ -140,13 +140,13 @@ const dialogBackupRef = ref();
const buttons = [
{
label: i18n.global.t('website.config'),
click: function (row: WebSite.WebSite) {
click: function (row: Website.Website) {
openConfig(row.id);
},
},
{
label: i18n.global.t('database.backupList'),
click: (row: WebSite.WebSite) => {
click: (row: Website.Website) => {
let params = {
id: row.id,
type: row.type,
@ -157,7 +157,7 @@ const buttons = [
},
{
label: i18n.global.t('database.loadBackup'),
click: (row: WebSite.WebSite) => {
click: (row: Website.Website) => {
let params = {
websiteName: row.primaryDomain,
websiteType: row.type,
@ -167,13 +167,13 @@ const buttons = [
},
{
label: i18n.global.t('app.delete'),
click: function (row: WebSite.WebSite) {
click: function (row: Website.Website) {
openDelete(row);
},
},
];
const openDelete = (website: WebSite.WebSite) => {
const openDelete = (website: Website.Website) => {
deleteRef.value.acceptParams(website);
};