From 684e4d0dac523d020bf50273d65882e506da75d2 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Sun, 11 Jan 2026 00:35:58 +0100 Subject: [PATCH] feat: Add SSL external option for Pages custom domains - Add checkbox to mark SSL as handled externally (e.g., Cloudflare) - Add Activate SSL button for verified domains with pending SSL - Add SSLExternal option to API - Useful when using CDN/reverse proxy that handles SSL certificates --- models/repo/pages.go | 6 ++++++ modules/structs/repo_pages.go | 2 ++ options/locale/locale_en-US.json | 4 ++++ routers/api/v1/repo/pages.go | 2 +- routers/web/repo/setting/pages.go | 11 ++++++++++- services/pages/pages.go | 8 +++++++- templates/repo/settings/pages.tmpl | 23 ++++++++++++++++++++++- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/models/repo/pages.go b/models/repo/pages.go index 35277f5250..a1bc1b9993 100644 --- a/models/repo/pages.go +++ b/models/repo/pages.go @@ -142,6 +142,12 @@ func UpdatePagesDomain(ctx context.Context, domain *PagesDomain) error { return err } +// ActivatePagesDomainSSL sets SSL status to active for a domain +func ActivatePagesDomainSSL(ctx context.Context, id int64) error { + _, err := db.GetEngine(ctx).ID(id).Cols("ssl_status").Update(&PagesDomain{SSLStatus: SSLStatusActive}) + return err +} + // DeletePagesDomain deletes a pages domain func DeletePagesDomain(ctx context.Context, id int64) error { _, err := db.GetEngine(ctx).ID(id).Delete(new(PagesDomain)) diff --git a/modules/structs/repo_pages.go b/modules/structs/repo_pages.go index 75d6dde967..90ecb32e2b 100644 --- a/modules/structs/repo_pages.go +++ b/modules/structs/repo_pages.go @@ -38,6 +38,8 @@ type AddPagesDomainOption struct { // The custom domain to add // required: true Domain string `json:"domain" binding:"Required"` + // Mark SSL as handled externally (e.g., by Cloudflare) + SSLExternal bool `json:"ssl_external"` } // PagesInfo represents the full pages information for a repository diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 87392645c4..ace51ec22c 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -2536,6 +2536,10 @@ "repo.settings.pages.pending": "Pending", "repo.settings.pages.ssl_active": "Active", "repo.settings.pages.ssl_pending": "Pending", + "repo.settings.pages.ssl_external": "SSL handled externally (e.g., Cloudflare)", + "repo.settings.pages.ssl_external_desc": "Check this if SSL is managed by a CDN or reverse proxy like Cloudflare", + "repo.settings.pages.activate_ssl": "Activate SSL", + "repo.settings.pages.ssl_activated": "SSL has been activated for this domain", "repo.settings.pages.ssl_none": "None", "repo.settings.pages.verify": "Verify", "repo.settings.pages.verify_dns_hint": "Add the following TXT record to your DNS to verify domain ownership:", diff --git a/routers/api/v1/repo/pages.go b/routers/api/v1/repo/pages.go index e47aba2039..43aa3f57ff 100644 --- a/routers/api/v1/repo/pages.go +++ b/routers/api/v1/repo/pages.go @@ -219,7 +219,7 @@ func AddPagesDomain(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.AddPagesDomainOption) - domain, err := pages_service.AddPagesDomain(ctx, ctx.Repo.Repository.ID, form.Domain) + domain, err := pages_service.AddPagesDomain(ctx, ctx.Repo.Repository.ID, form.Domain, form.SSLExternal) if err != nil { if repo_model.IsErrPagesDomainAlreadyExist(err) { ctx.APIError(http.StatusUnprocessableEntity, "Domain already exists") diff --git a/routers/web/repo/setting/pages.go b/routers/web/repo/setting/pages.go index 5609cf4140..2eece73754 100644 --- a/routers/web/repo/setting/pages.go +++ b/routers/web/repo/setting/pages.go @@ -92,7 +92,8 @@ func PagesPost(ctx *context.Context) { ctx.Redirect(ctx.Repo.Repository.Link() + "/settings/pages") return } - _, err := pages_service.AddPagesDomain(ctx, ctx.Repo.Repository.ID, domain) + sslExternal := ctx.FormBool("ssl_external") + _, err := pages_service.AddPagesDomain(ctx, ctx.Repo.Repository.ID, domain, sslExternal) if err != nil { if repo_model.IsErrPagesDomainAlreadyExist(err) { ctx.Flash.Error(ctx.Tr("repo.settings.pages.domain_exists")) @@ -112,6 +113,14 @@ func PagesPost(ctx *context.Context) { } ctx.Flash.Success(ctx.Tr("repo.settings.pages.domain_deleted")) + case "activate_ssl": + domainID := ctx.FormInt64("domain_id") + if err := repo_model.ActivatePagesDomainSSL(ctx, domainID); err != nil { + ctx.ServerError("ActivatePagesDomainSSL", err) + return + } + ctx.Flash.Success(ctx.Tr("repo.settings.pages.ssl_activated")) + case "verify_domain": domainID := ctx.FormInt64("domain_id") if err := pages_service.VerifyDomain(ctx, domainID); err != nil { diff --git a/services/pages/pages.go b/services/pages/pages.go index 3be750ea92..f10580353d 100644 --- a/services/pages/pages.go +++ b/services/pages/pages.go @@ -190,7 +190,7 @@ func GetPagesDomains(ctx context.Context, repoID int64) ([]*repo_model.PagesDoma } // AddPagesDomain adds a custom domain for pages -func AddPagesDomain(ctx context.Context, repoID int64, domain string) (*repo_model.PagesDomain, error) { +func AddPagesDomain(ctx context.Context, repoID int64, domain string, sslExternal bool) (*repo_model.PagesDomain, error) { // Normalize domain domain = strings.ToLower(strings.TrimSpace(domain)) @@ -200,9 +200,15 @@ func AddPagesDomain(ctx context.Context, repoID int64, domain string) (*repo_mod return nil, repo_model.ErrPagesDomainAlreadyExist{Domain: domain} } + sslStatus := repo_model.SSLStatusPending + if sslExternal { + sslStatus = repo_model.SSLStatusActive + } + pagesDomain := &repo_model.PagesDomain{ RepoID: repoID, Domain: domain, + SSLStatus: sslStatus, } if err := repo_model.CreatePagesDomain(ctx, pagesDomain); err != nil { diff --git a/templates/repo/settings/pages.tmpl b/templates/repo/settings/pages.tmpl index fca07b47e9..9fa8fb0f7a 100644 --- a/templates/repo/settings/pages.tmpl +++ b/templates/repo/settings/pages.tmpl @@ -104,6 +104,13 @@ {{end}} + {{if and .Verified (eq .SSLStatus "pending")}} +
+ + + +
+ {{end}} {{if not .Verified}}
@@ -118,7 +125,14 @@
- {{if not .Verified}} + {{if and .Verified (eq .SSLStatus "pending")}} +
+ + + +
+ {{end}} + {{if not .Verified}}
@@ -138,6 +152,13 @@
+
+
+ + +
+

{{ctx.Locale.Tr "repo.settings.pages.ssl_external_desc"}}

+