From 917c10737d02a53cc369a07d34f1c84ebc54aae2 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 20 Mar 2025 23:34:10 +0100 Subject: [PATCH 1/5] improve readme and nix file --- Makefile | 19 ------------------- README.md | 18 ++++++++++++++++-- flake.nix | 11 ++++++++++- 3 files changed, 26 insertions(+), 22 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index e42acb7..0000000 --- a/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -BIN=guichet -SRC=main.go ssha.go profile.go admin.go invite.go directory.go picture.go -DOCKER=lxpz/guichet_amd64 - -all: $(BIN) - -$(BIN): $(SRC) - go get -d -v - go build -v -o $(BIN) - -$(BIN).static: $(SRC) - go get -d -v - CGO_ENABLED=0 GOOS=linux go build -a -v -o $(BIN).static - -docker: $(BIN).static - docker build -t $(DOCKER):$(TAG) . - docker push $(DOCKER):$(TAG) - docker tag $(DOCKER):$(TAG) $(DOCKER):latest - docker push $(DOCKER):latest diff --git a/README.md b/README.md index 483ea71..a21ca32 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,23 @@ Guichet is licensed under the terms of the GPLv3. Guichet requires go 1.13 or later. -To build Guichet, clone this repository outside of your `$GOPATH`. -Then, run `make` in the root of the repo. +Development build: +``` +go build +``` + +Production build: + +``` +nix build +``` + +Production container: + +``` +docker run .#docker +``` ## Configuration of Guichet diff --git a/flake.nix b/flake.nix index 3b6ad3b..20b42b1 100644 --- a/flake.nix +++ b/flake.nix @@ -47,11 +47,20 @@ Entrypoint = "/bin/guichet"; }; }; + + docker = pkgs.writeScriptBin "guichet-docker" '' + #!/usr/bin/env bash + + set -euxo pipefail + docker load <$(nix build --print-out-paths .#container) + ''; + in { packages.x86_64-linux.guichet = guichet; packages.x86_64-linux.container = container; + packages.x86_64-linux.docker = docker; packages.x86_64-linux.default = guichet; - + devShell.x86_64-linux = pkgs.mkShell { nativeBuildInputs = [ pkgs.go pkgs.gomod2nix ]; }; }; } From 371c46e0ed25e11efd99c7a51ca54793cb14ccbf Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 20 Mar 2025 23:57:49 +0100 Subject: [PATCH 2/5] simplify invitations --- go.sum | 2 -- integration/docker-compose.yml | 2 +- invite.go | 56 +++------------------------------- templates/home.html | 3 +- 4 files changed, 6 insertions(+), 57 deletions(-) diff --git a/go.sum b/go.sum index 6543905..33f35c3 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20230131081355-c965fe7f7dc9 h1:ERg8KCpIKym98EOKa8Gq0NSBxsasD3sqb/R0gg1wOzU= -git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20230131081355-c965fe7f7dc9/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e h1:h89CAh0qmUcGJykss/utXIw+yRGa3Gr6VyrZ5ZWN0kY= git.deuxfleurs.fr/garage-sdk/garage-admin-sdk-golang v0.0.0-20231128153612-8b81fae65e5e/go.mod h1:TlSL6QVxozmdRaSgP6Akspi0HCJv4HAkkq3Dldru4GM= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/integration/docker-compose.yml b/integration/docker-compose.yml index e44a723..13b39b6 100644 --- a/integration/docker-compose.yml +++ b/integration/docker-compose.yml @@ -21,7 +21,7 @@ services: garage: # sync with deuxfleurs/nixcfg/cluster/prod/app/garage/deploy/garage.hcl # to ensure compatibility with prod - image: superboum/garage:v1.0.0-rc1-hotfix-red-ftr-wquorum + image: dxflrs/garage:v1.99.1-internal ports: - "3900:3900" - "3902:3902" diff --git a/invite.go b/invite.go index 24e5fbe..cf67596 100644 --- a/invite.go +++ b/invite.go @@ -1,19 +1,15 @@ package main import ( - "bytes" "crypto/rand" "encoding/binary" "encoding/hex" "fmt" - "html/template" "log" "net/http" "regexp" "strings" - "github.com/emersion/go-sasl" - "github.com/emersion/go-smtp" "github.com/go-ldap/ldap/v3" "github.com/gorilla/mux" "golang.org/x/crypto/argon2" @@ -251,21 +247,11 @@ func handleInviteSendCode(w http.ResponseWriter, r *http.Request) { WebBaseAddress: config.WebAddress, } - if r.Method == "POST" { - r.ParseForm() - - choice := strings.Join(r.Form["choice"], "") - sendto := strings.Join(r.Form["sendto"], "") - - if choice == "display" || choice == "send" { - trySendCode(user, choice, sendto, data) - } - } - + tryGenerateInvitation(user, data) templateInviteSendCode.Execute(w, data) } -func trySendCode(user *LoggedUser, choice string, sendto string, data *SendCodeData) { +func tryGenerateInvitation(user *LoggedUser, data *SendCodeData) { // Generate code code, code_id, code_pw := genCode() @@ -286,43 +272,9 @@ func trySendCode(user *LoggedUser, choice string, sendto string, data *SendCodeD return } - // If we want to display it, do so - if choice == "display" { - data.Success = true - data.CodeDisplay = code - return - } - - // Otherwise, we are sending a mail - if !EMAIL_REGEXP.MatchString(sendto) { - data.ErrorInvalidEmail = true - return - } - - templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt")) - buf := bytes.NewBuffer([]byte{}) - templateMail.Execute(buf, &CodeMailFields{ - To: sendto, - From: config.MailFrom, - InviteFrom: user.WelcomeName(), - Code: code, - WebBaseAddress: config.WebAddress, - }) - - log.Printf("Sending mail to: %s", sendto) - var auth sasl.Client = nil - if config.SMTPUsername != "" { - auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword) - } - err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{sendto}, buf) - if err != nil { - data.ErrorMessage = err.Error() - return - } - log.Printf("Mail sent.") - data.Success = true - data.CodeSentTo = sendto + data.CodeDisplay = code + return } func genCode() (code string, code_id string, code_pw string) { diff --git a/templates/home.html b/templates/home.html index 3210a13..e556da1 100644 --- a/templates/home.html +++ b/templates/home.html @@ -38,8 +38,7 @@ Inviter des gens sur Deuxfleurs {{end}} From e3512bf3f19c6429105c55e83858ac856babd0eb Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 20 Mar 2025 23:59:05 +0100 Subject: [PATCH 3/5] switch to global.site.deuxfleurs.fr --- templates/garage_website_edit.html | 4 ++-- templates/garage_website_new.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/garage_website_edit.html b/templates/garage_website_edit.html index 880721f..8b58f1f 100644 --- a/templates/garage_website_edit.html +++ b/templates/garage_website_edit.html @@ -57,9 +57,9 @@

Vous devez éditer votre zone DNS, souvent gérée par votre bureau d'enregistrement, comme Gandi, pour la faire pointer vers Deuxfleurs. Si vous utilisez un sous domaine (eg. site.example.com), une entrée CNAME est appropriée :

-
site   CNAME    3600    garage.deuxfleurs.fr.
+
site   CNAME    3600    global.site.deuxfleurs.fr.

Si vous utilisez la racine de votre nom de domaine (eg. example.com, aussi appelée APEX), la solution dépend de votre fournisseur DNS, il vous faudra au choix une entrée ALIAS ou CNAME en fonction de ce que votre fournisseur supporte :

-
@      ALIAS    3600    garage.deuxfleurs.fr.
+
@      ALIAS    3600    global.site.deuxfleurs.fr.

La première fois que vous chargerez votre site web, une erreur de certificat sera renvoyée. C'est normal, il faudra patienter quelques minutes le temps que le certificat se génère.

diff --git a/templates/garage_website_new.html b/templates/garage_website_new.html index c7de741..4135791 100644 --- a/templates/garage_website_new.html +++ b/templates/garage_website_new.html @@ -57,9 +57,9 @@

Vous devez éditer votre zone DNS, souvent gérée par votre bureau d'enregistrement, comme Gandi, pour la faire pointer vers Deuxfleurs. Si vous utilisez un sous domaine (eg. site.example.com), une entrée CNAME est appropriée :

-
site   CNAME    3600    garage.deuxfleurs.fr.
+
site   CNAME    3600    global.site.deuxfleurs.fr.

Si vous utilisez la racine de votre nom de domaine (eg. example.com, aussi appelée APEX), la solution dépend de votre fournisseur DNS, il vous faudra au choix une entrée ALIAS ou CNAME en fonction de ce que votre fournisseur supporte :

-
@      ALIAS    3600    garage.deuxfleurs.fr.
+
@      ALIAS    3600    global.site.deuxfleurs.fr.

La première fois que vous chargerez votre site web, une erreur de certificat sera renvoyée. C'est normal, il faudra patienter quelques minutes le temps que le certificat se génère.

From 057f84e6639d204d485ae9d7aa7566ee23cfb5ca Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 21 Mar 2025 00:10:21 +0100 Subject: [PATCH 4/5] advertise dxfl --- templates/garage_website_inspect.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/templates/garage_website_inspect.html b/templates/garage_website_inspect.html index 9396614..c0e0a89 100644 --- a/templates/garage_website_inspect.html +++ b/templates/garage_website_inspect.html @@ -76,7 +76,10 @@
Informations de connexion
-
+
+

Première configuration :

+ +
+sudo npm install -g dxfl
+dxfl login
+				
+ +

Pour déployer votre site contenu dans le dossier public :

+
+dxfl deploy {{ .View.Name.Pretty }} ./public
+				
+
+
From f53b10075293b37de8af2d74ffdbb35383e48c03 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 21 Mar 2025 00:16:19 +0100 Subject: [PATCH 5/5] fix hugo --- templates/garage_website_inspect.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/garage_website_inspect.html b/templates/garage_website_inspect.html index c0e0a89..026d5d8 100644 --- a/templates/garage_website_inspect.html +++ b/templates/garage_website_inspect.html @@ -112,7 +112,7 @@ dxfl deploy {{ .View.Name.Pretty }} ./public @@ -153,7 +153,7 @@ dxfl deploy {{ .View.Name.Pretty }} ./public

Entrez les informations suivantes quand elles vous sont demandées :

AWS Access Key ID [None]:
{{ .View.AccessKeyId }}
-
AWS Secret Access Key [None]:
[Afficher la clé secrète]
+
AWS Secret Access Key [None]:
[Afficher la clé secrète]
Default region name [None]:
garage
Default output format [None]:
(laissez vide et appuyez sur entrée)
@@ -187,7 +187,7 @@ mc alias set \ {{ .View.Name.Pretty }} \ https://garage.deuxfleurs.fr \ {{ .View.AccessKeyId }} \ - [Afficher la clé secrète] \ + [Afficher la clé secrète] \ --api S3v4

Et ensuite copiez votre site web avec la sous-commande mirror de Minio CLI :

@@ -211,12 +211,12 @@ mc mirror --overwrite ./public/ {{ .View.Name.Pretty }}/

Créez un fichier nommé .deployment.secrets (ne commitez pas ce fichier dans votre dépôt !) :

 export AWS_ACCESS_KEY_ID={{ .View.AccessKeyId }}
-export AWS_SECRET_ACCESS_KEY=[Afficher la clé secrète]
+export AWS_SECRET_ACCESS_KEY=[Afficher la clé secrète]
 								

Dans votre fichier de configuration Hugo config.toml (que vous pouvez commiter), rajoutez :

 [[deployment.targets]]
- URL = "s3://bucket?endpoint=garage.deuxfleurs.fr&s3ForcePathStyle=true&region=garage"
+ URL = "s3://{{ .View.Name.Pretty }}?endpoint=https://garage.deuxfleurs.fr&awssdk=v2&use_path_style=true&region=garage&disable_https=false
 								

Pour déployer, sourcez le fichier de configuration et laissez hugo faire :

Clé secrète - [Afficher la clé secrète] + [Afficher la clé secrète]