From e0fbd16f926e250e8aa2ecb1ce4ec780638946c4 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 17 Oct 2023 15:56:50 +0200 Subject: typo --- templates/garage_website_inspect.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/garage_website_inspect.html b/templates/garage_website_inspect.html index 37142df..c047b18 100644 --- a/templates/garage_website_inspect.html +++ b/templates/garage_website_inspect.html @@ -48,7 +48,7 @@
Quotas
- {{ .View.Size.Ratio }}% + {{ .View.Size.Percent }}%
-- cgit v1.2.3 From 4f7cbdd8252f0064729f22929c7ca0e63a10d284 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 17 Oct 2023 18:33:11 +0200 Subject: ajout de la modification du ndd --- garage.go | 53 +++++++++++++++++++++++++- main.go | 1 + templates/garage_website_edit.html | 72 +++++++++++++++++++++++++++++++++++ templates/garage_website_inspect.html | 2 +- website.go | 17 ++++++++- 5 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 templates/garage_website_edit.html diff --git a/garage.go b/garage.go index c43fd5f..7cd879b 100644 --- a/garage.go +++ b/garage.go @@ -270,8 +270,9 @@ func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) { _, processErr = ctrl.Patch(bucketName, &WebsitePatch{Size: &user.Quota.WebsiteSizeBursted}) case "delete_bucket": processErr = ctrl.Delete(bucketName) - http.Redirect(w, r, "/website", http.StatusFound) - return + if processErr == nil { + http.Redirect(w, r, "/website", http.StatusFound) + } default: processErr = fmt.Errorf("Unknown action") } @@ -295,3 +296,51 @@ func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) { tWebsiteInspect := getTemplate("garage_website_inspect.html") tWebsiteInspect.Execute(w, &tpl) } + +func handleWebsiteVhost(w http.ResponseWriter, r *http.Request) { + var processErr error + + user := RequireUserHtml(w, r) + if user == nil { + return + } + + ctrl, err := NewWebsiteController(user) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + bucketName := mux.Vars(r)["bucket"] + + if r.Method == "POST" { + r.ParseForm() + + bucket := strings.Join(r.Form["bucket"], "") + if bucket == "" { + bucket = strings.Join(r.Form["bucket2"], "") + } + + view, processErr := ctrl.Patch(bucketName, &WebsitePatch{Vhost: &bucket}) + if processErr == nil { + http.Redirect(w, r, "/website/inspect/"+view.Name.Pretty, http.StatusFound) + return + } + } + + view, err := ctrl.Inspect(bucketName) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + describe, err := ctrl.Describe() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + tpl := &WebsiteInspectTpl{describe, view, processErr} + tWebsiteEdit := getTemplate("garage_website_edit.html") + tWebsiteEdit.Execute(w, &tpl) +} diff --git a/main.go b/main.go index 6553bef..39c7f08 100644 --- a/main.go +++ b/main.go @@ -161,6 +161,7 @@ func server(args []string) { r.HandleFunc("/website/new", handleWebsiteNew) r.HandleFunc("/website/configure", handleWebsiteConfigure) r.HandleFunc("/website/inspect/{bucket}", handleWebsiteInspect) + r.HandleFunc("/website/vhost/{bucket}", handleWebsiteVhost) r.HandleFunc("/invite/new_account", handleInviteNewAccount) r.HandleFunc("/invite/send_code", handleInviteSendCode) diff --git a/templates/garage_website_edit.html b/templates/garage_website_edit.html new file mode 100644 index 0000000..f41d30b --- /dev/null +++ b/templates/garage_website_edit.html @@ -0,0 +1,72 @@ +{{define "title"}}Créer un site web |{{end}} + +{{define "body"}} +
+

Modifier le nom de domaine

+ Mes identifiants + Mes sites webs +
+ +
+
+ {{if .Err}} +
{{ .Err.Error }}
+ {{end}} +
+
+ + + +
+ +
+
+
+
+ + +
+
+ + +
+
+
+

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.

+
+ +
+
+
+
+
+
+ + +
+
+ + +
+
+
+

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.
+

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.
+

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.

+
+
+ + + +
+
+{{end}} diff --git a/templates/garage_website_inspect.html b/templates/garage_website_inspect.html index c047b18..a8f463d 100644 --- a/templates/garage_website_inspect.html +++ b/templates/garage_website_inspect.html @@ -63,7 +63,7 @@
- Changer le nom de domaine + Changer le nom de domaine
diff --git a/website.go b/website.go index 2cad12c..74daf89 100644 --- a/website.go +++ b/website.go @@ -17,6 +17,8 @@ var ( ErrCantConfigureBucket = fmt.Errorf("Unable to configure the bucket (activating website, adding quotas, etc.)") ErrBucketDeleteNotEmpty = fmt.Errorf("You must remove all the files before deleting a bucket") ErrBucketDeleteUnfinishedUpload = fmt.Errorf("You must remove all the unfinished multipart uploads before deleting a bucket") + ErrCantChangeVhost = fmt.Errorf("Can't change the vhost to the desired value. Maybe it's already used by someone else or an internal error occured") + ErrCantRemoveOldVhost = fmt.Errorf("The new vhost is bound to the bucket but the old one can't be removed, this is an internal error") ) type WebsiteId struct { @@ -141,12 +143,24 @@ func (w *WebsiteController) Patch(pretty string, patch *WebsitePatch) (*WebsiteV ur := garage.NewUpdateBucketRequest() ur.SetQuotas(*urQuota) - // Call garage + // Call garage "update bucket" function binfo, err = grgUpdateBucket(website.Internal, ur) if err != nil { return nil, ErrCantConfigureBucket } + // Update the alias if the vhost field is set and different + if patch.Vhost != nil && *patch.Vhost != "" && *patch.Vhost != pretty { + binfo, err = grgAddGlobalAlias(website.Internal, *patch.Vhost) + if err != nil { + return nil, ErrCantChangeVhost + } + binfo, err = grgDelGlobalAlias(website.Internal, pretty) + if err != nil { + return nil, ErrCantRemoveOldVhost + } + } + return NewWebsiteView(binfo), nil } @@ -233,4 +247,5 @@ func NewWebsiteView(binfo *garage.BucketInfo) *WebsiteView { type WebsitePatch struct { Size *int64 `json:"quota_size"` + Vhost *string `json:"vhost"` } -- cgit v1.2.3