diff --git a/backend/app/dto/request/website.go b/backend/app/dto/request/website.go index 63ad359cb..037592055 100644 --- a/backend/app/dto/request/website.go +++ b/backend/app/dto/request/website.go @@ -18,6 +18,7 @@ type WebsiteCreate struct { OtherDomains string `json:"otherDomains"` Proxy string `json:"proxy"` WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"` + IPV6 bool `json:"IPV6"` AppType string `json:"appType" validate:"oneof=new installed"` AppInstall NewAppInstall `json:"appInstall"` @@ -51,6 +52,7 @@ type WebsiteUpdate struct { Remark string `json:"remark"` WebsiteGroupID uint `json:"webSiteGroupID" validate:"required"` ExpireDate string `json:"expireDate"` + IPV6 bool `json:"IPV6"` } type WebsiteDelete struct { diff --git a/backend/app/model/website.go b/backend/app/model/website.go index 08d2754c4..0c21e5782 100644 --- a/backend/app/model/website.go +++ b/backend/app/model/website.go @@ -19,6 +19,7 @@ type Website struct { ErrorLog bool `json:"errorLog"` AccessLog bool `json:"accessLog"` DefaultServer bool `json:"defaultServer"` + IPV6 bool `json:"IPV6"` Rewrite string `gorm:"type:varchar" json:"rewrite"` WebsiteGroupID uint `gorm:"type:integer" json:"webSiteGroupId"` diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 4814aa044..a2eaa4d61 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -176,6 +176,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) SiteDir: "/", AccessLog: true, ErrorLog: true, + IPV6: create.IPV6, } var ( @@ -340,6 +341,8 @@ func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error { website.PrimaryDomain = req.PrimaryDomain website.WebsiteGroupID = req.WebsiteGroupID website.Remark = req.Remark + website.IPV6 = req.IPV6 + if req.ExpireDate != "" { expireDate, err := time.Parse(constant.DateLayout, req.ExpireDate) if err != nil { diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go index 1193b22cf..d12bda327 100644 --- a/backend/app/service/website_utils.go +++ b/backend/app/service/website_utils.go @@ -190,6 +190,9 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a for _, domain := range domains { serverNames = append(serverNames, domain.Domain) server.UpdateListen(strconv.Itoa(domain.Port), false) + if website.IPV6 { + server.UpdateListen("[::]:"+strconv.Itoa(domain.Port), false) + } } server.UpdateServerName(serverNames) @@ -291,6 +294,9 @@ func addListenAndServerName(website model.Website, ports []int, domains []string server := config.FindServers()[0] for _, port := range ports { server.AddListen(strconv.Itoa(port), false) + if website.IPV6 { + server.UpdateListen("[::]:"+strconv.Itoa(port), false) + } } for _, domain := range domains { server.AddServerName(domain) @@ -311,6 +317,9 @@ func deleteListenAndServerName(website model.Website, binds []string, domains [] server := config.FindServers()[0] for _, bind := range binds { server.DeleteListen(bind) + if website.IPV6 { + server.DeleteListen("[::]:" + bind) + } } for _, domain := range domains { server.DeleteServerName(domain) @@ -372,6 +381,9 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We config := nginxFull.SiteConfig.Config server := config.FindServers()[0] server.UpdateListen("443", website.DefaultServer, "ssl") + if website.IPV6 { + server.UpdateListen("[::]:443", website.DefaultServer, "ssl") + } switch req.HttpConfig { case constant.HTTPSOnly: @@ -380,10 +392,16 @@ func applySSL(website model.Website, websiteSSL model.WebsiteSSL, req request.We server.RemoveDirective("if", []string{"($scheme"}) case constant.HTTPToHTTPS: server.UpdateListen("80", website.DefaultServer) + if website.IPV6 { + server.UpdateListen("[::]:80", website.DefaultServer) + } server.AddHTTP2HTTPS() case constant.HTTPAlso: server.UpdateListen("80", website.DefaultServer) server.RemoveDirective("if", []string{"($scheme"}) + if website.IPV6 { + server.UpdateListen("[::]:80", website.DefaultServer) + } } if err := nginx.WriteConfig(config, nginx.IndentedStyle); err != nil { diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 90c37b843..12eb5a027 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -30,6 +30,7 @@ func Init() { migrations.UpdateTableAppDetail, migrations.AddBindAndAllowIPs, migrations.UpdateCronjobWithSecond, + migrations.UpdateWebsite, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 055d8d16c..11edc6bd6 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -367,3 +367,13 @@ var UpdateCronjobWithSecond = &gormigrate.Migration{ return nil }, } + +var UpdateWebsite = &gormigrate.Migration{ + ID: "20200530-update-table-website", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.Website{}); err != nil { + return err + } + return nil + }, +} diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 0ae59f045..c2dc69fc8 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -20,6 +20,7 @@ export namespace Website { rewrite: string; user: string; group: string; + IPV6: boolean; } export interface WebsiteDTO extends Website { @@ -67,6 +68,7 @@ export namespace Website { remark: string; webSiteGroupId: number; expireDate?: string; + IPV6: boolean; } export interface WebSiteOp { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 7eadf155f..3317d3795 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1391,6 +1391,7 @@ const message = { disable: 'not enabled', disableLeechHelper: 'Whether to disable the anti-leech', disableLeech: 'Disable anti-leech', + ipv6: 'Listen IPV6', }, php: { short_open_tag: 'Short tag support', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6ea5f307a..2b8a46a42 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1370,6 +1370,7 @@ const message = { disable: '未启用', disableLeechHelper: '是否禁用防盗链', disableLeech: '禁用防盗链', + ipv6: '监听 IPV6 端口', }, php: { short_open_tag: '短标签支持', diff --git a/frontend/src/views/log/website/index.vue b/frontend/src/views/log/website/index.vue index 2e022efb5..8e65dabda 100644 --- a/frontend/src/views/log/website/index.vue +++ b/frontend/src/views/log/website/index.vue @@ -166,3 +166,14 @@ onMounted(() => { getWebsites(); }); + + diff --git a/frontend/src/views/website/website/config/basic/https/index.vue b/frontend/src/views/website/website/config/basic/https/index.vue index 5e77fa0e4..4974de465 100644 --- a/frontend/src/views/website/website/config/basic/https/index.vue +++ b/frontend/src/views/website/website/config/basic/https/index.vue @@ -1,7 +1,7 @@