From 4404287958ad9b9e1c4311a8d5a72583aa75f77a Mon Sep 17 00:00:00 2001 From: fnetx Date: Fri, 11 Feb 2022 01:31:11 +0100 Subject: [PATCH 1/3] Update 404 Not found page --- html/404.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/html/404.html b/html/404.html index fa17a83..08ab16d 100644 --- a/html/404.html +++ b/html/404.html @@ -21,12 +21,13 @@ - +

- You found a bug! + This page was not found!

- Sorry, this page doesn't exist or is inaccessible for other reasons (%status) + Sorry, this page doesn't exist or is inaccessible for other reasons (%status).
+ We hope this is not our fault ;) - Make sure to check the troubleshooting section in the Docs!
From ac5b19123d873612b7764add6da8632bed555d97 Mon Sep 17 00:00:00 2001 From: Otto Richter Date: Sat, 19 Feb 2022 18:10:40 +0100 Subject: [PATCH 2/3] Update README (#57) I hope this makes it more inviting to collaborate with us on this project. I'd like to promote the software a little more. Co-authored-by: fnetx Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/57 Co-authored-by: Otto Richter Co-committed-by: Otto Richter --- README.md | 102 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 087d7ae..b56239b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,58 @@ -## Environment +# Codeberg Pages + +Gitea lacks the ability to host static pages from Git. +The Codeberg Pages Server addresses this lack by implementing a standalone service +that connects to Gitea via API. +It is suitable to be deployed by other Gitea instances, too, to offer static pages hosting to their users. + +**End user documentation** can mainly be found at the [Wiki](https://codeberg.org/Codeberg/pages-server/wiki/Overview) +and the [Codeberg Documentation](https://docs.codeberg.org/codeberg-pages/). + + +## Quickstart + +This is the new Codeberg Pages server, a solution for serving static pages from Gitea repositories. +Mapping custom domains is not static anymore, but can be done with DNS: + +1) add a `.domains` text file to your repository, containing the allowed domains, separated by new lines. The +first line will be the canonical domain/URL; all other occurrences will be redirected to it. + +2) add a CNAME entry to your domain, pointing to `[[{branch}.]{repo}.]{owner}.codeberg.page` (repo defaults to +"pages", "branch" defaults to the default branch if "repo" is "pages", or to "pages" if "repo" is something else): + `www.example.org. IN CNAME main.pages.example.codeberg.page.` + +3) if a CNAME is set for "www.example.org", you can redirect there from the naked domain by adding an ALIAS record +for "example.org" (if your provider allows ALIAS or similar records, otherwise use A/AAAA), together with a TXT +record that points to your repo (just like the CNAME record): + `example.org IN ALIAS codeberg.page.` + `example.org IN TXT main.pages.example.codeberg.page.` + +Certificates are generated, updated and cleaned up automatically via Let's Encrypt through a TLS challenge. + + +## Deployment + +**Warning: Some Caveats Apply** +> Currently, the deployment requires you to have some knowledge of system administration as well as understanding and building code, +> so you can eventually edit non-configurable and codeberg-specific settings. +> In the future, we'll try to reduce these and make hosting Codeberg Pages as easy as setting up Gitea. +> If you consider using Pages in practice, please consider contacting us first, +> we'll then try to share some basic steps and document the current usage for admins +> (might be changing in the current state). + +Deploying the software itself is very easy. You can grab a current release binary or build yourself, +configure the environment as described below, and you are done. + +The hard part is about adding **custom domain support** if you intend to use it. +SSL certificates (request + renewal) is automatically handled by the Pages Server, +but if you want to run it on a shared IP address (and not a standalone), +you'll need to configure your reverse proxy not to terminate the TLS connections, +but forward the requests on the IP level to the Pages Server. + +You can check out a proof of concept in the `haproxy-sni` folder, +and especially have a look at [this section of the haproxy.cfg](https://codeberg.org/Codeberg/pages-server/src/branch/main/haproxy-sni/haproxy.cfg#L38). + +### Environment - `HOST` & `PORT` (default: `[::]` & `443`): listen address. - `PAGES_DOMAIN` (default: `codeberg.page`): main domain for pages. @@ -17,23 +71,29 @@ See https://go-acme.github.io/lego/dns/ for available values & additional environment variables. - `DEBUG` (default: false): Set this to true to enable debug logging. -``` -// Package main is the new Codeberg Pages server, a solution for serving static pages from Gitea repositories. -// -// Mapping custom domains is not static anymore, but can be done with DNS: -// -// 1) add a ".domains" text file to your repository, containing the allowed domains, separated by new lines. The -// first line will be the canonical domain/URL; all other occurrences will be redirected to it. -// -// 2) add a CNAME entry to your domain, pointing to "[[{branch}.]{repo}.]{owner}.codeberg.page" (repo defaults to -// "pages", "branch" defaults to the default branch if "repo" is "pages", or to "pages" if "repo" is something else): -// www.example.org. IN CNAME main.pages.example.codeberg.page. -// -// 3) if a CNAME is set for "www.example.org", you can redirect there from the naked domain by adding an ALIAS record -// for "example.org" (if your provider allows ALIAS or similar records, otherwise use A/AAAA), together with a TXT -// record that points to your repo (just like the CNAME record): -// example.org IN ALIAS codeberg.page. -// example.org IN TXT main.pages.example.codeberg.page. -// -// Certificates are generated, updated and cleaned up automatically via Let's Encrypt through a TLS challenge. -``` + +## Contributing to the development + +The Codeberg team is very open to your contribution. +Since we are working nicely in a team, it might be hard at times to get started +(still check out the issues, we always aim to have some things to get you started). + +If you have any questions, want to work on a feature or could imagine collaborating with us for some time, +feel free to ping us in an issue or in a general Matrix chatgroup. + +You can also contact the maintainers of this project: + +- [momar](https://codeberg.org/momar) [(Matrix)](https://matrix.to/#/@moritz:wuks.space) +- [6543](https://codeberg.org/6543) [(Matrix)](https://matrix.to/#/@marddl:obermui.de) + +### First steps + +The code of this repository is split in several modules. +While heavy refactoring work is currently undergo, you can easily understand the basic structure: +The `cmd` folder holds the data necessary for interacting with the service via the cli. +If you are considering to deploy the service yourself, make sure to check it out. +The heart of the software lives in the `server` folder and is split in several modules. +After scanning the code, you should quickly be able to understand their function and start hacking on them. + +Again: Feel free to get in touch with us for any questions that might arise. +Thank you very much. From cf9e6d9dc635dd77a2d48cd38e925347c4a60bd3 Mon Sep 17 00:00:00 2001 From: Moritz Marquardt Date: Mon, 28 Feb 2022 21:50:13 +0100 Subject: [PATCH 3/3] Fix certs only being renewed 7 or 30 days *after* they expire instead of before Seems like plus, minus, greater than and less than are the most complex to understand mathematical concepts... --- server/certificates/certificates.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/certificates/certificates.go b/server/certificates/certificates.go index b40c76d..505212f 100644 --- a/server/certificates/certificates.go +++ b/server/certificates/certificates.go @@ -209,7 +209,7 @@ func retrieveCertFromDB(sni, mainDomainSuffix []byte, dnsProvider string, acmeUs } // renew certificates 7 days before they expire - if !tlsCertificate.Leaf.NotAfter.After(time.Now().Add(-7 * 24 * time.Hour)) { + if !tlsCertificate.Leaf.NotAfter.After(time.Now().Add(7 * 24 * time.Hour)) { // TODO: add ValidUntil to custom res struct if res.CSR != nil && len(res.CSR) > 0 { // CSR stores the time when the renewal shall be tried again @@ -503,7 +503,7 @@ func MaintainCertDB(ctx context.Context, interval time.Duration, mainDomainSuffi tlsCertificates, err := certcrypto.ParsePEMBundle(res.Certificate) // renew main certificate 30 days before it expires - if !tlsCertificates[0].NotAfter.After(time.Now().Add(-30 * 24 * time.Hour)) { + if !tlsCertificates[0].NotAfter.After(time.Now().Add(30 * 24 * time.Hour)) { go (func() { _, err = obtainCert(mainDomainAcmeClient, []string{"*" + string(mainDomainSuffix), string(mainDomainSuffix[1:])}, res, "", dnsProvider, mainDomainSuffix, acmeUseRateLimits, certDB) if err != nil {