diff options
author | Alex Auvolat <alex@adnab.me> | 2022-12-01 23:05:59 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-12-01 23:25:26 +0100 |
commit | 5eed8fa506bbd24469ec4d42a183928be89a325b (patch) | |
tree | 3ed0e5f514ec1c628bd6c0bbe634d12f5cb8ada4 | |
parent | 3c846b6a59c1e725b56b7784c30cfbd5a3dc080b (diff) | |
download | guichet-5eed8fa506bbd24469ec4d42a183928be89a325b.tar.gz guichet-5eed8fa506bbd24469ec4d42a183928be89a325b.zip |
Make repo into a Nix flake
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | admin.go | 9 | ||||
-rw-r--r-- | directory.go | 4 | ||||
-rw-r--r-- | flake.lock | 79 | ||||
-rw-r--r-- | flake.nix | 43 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | gomod2nix.toml | 111 | ||||
-rw-r--r-- | invite.go | 8 | ||||
-rw-r--r-- | main.go | 13 | ||||
-rw-r--r-- | picture.go | 2 | ||||
-rw-r--r-- | profile.go | 5 |
11 files changed, 258 insertions, 19 deletions
@@ -1,3 +1,4 @@ guichet guichet.static config.json +result @@ -2,7 +2,6 @@ package main import ( "fmt" - "html/template" "net/http" "regexp" "sort" @@ -48,7 +47,7 @@ type AdminUsersTplData struct { } func handleAdminUsers(w http.ResponseWriter, r *http.Request) { - templateAdminUsers := template.Must(template.ParseFiles("templates/layout.html", "templates/admin_users.html")) + templateAdminUsers := getTemplate("admin_users.html") login := checkAdminLogin(w, r) if login == nil { @@ -87,7 +86,7 @@ type AdminGroupsTplData struct { } func handleAdminGroups(w http.ResponseWriter, r *http.Request) { - templateAdminGroups := template.Must(template.ParseFiles("templates/layout.html", "templates/admin_groups.html")) + templateAdminGroups := getTemplate("admin_groups.html") login := checkAdminLogin(w, r) if login == nil { @@ -165,7 +164,7 @@ type PropValues struct { } func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { - templateAdminLDAP := template.Must(template.ParseFiles("templates/layout.html", "templates/admin_ldap.html")) + templateAdminLDAP := getTemplate("admin_ldap.html") login := checkAdminLogin(w, r) if login == nil { @@ -551,7 +550,7 @@ type CreateData struct { } func handleAdminCreate(w http.ResponseWriter, r *http.Request) { - templateAdminCreate := template.Must(template.ParseFiles("templates/layout.html", "templates/admin_create.html")) + templateAdminCreate := getTemplate("admin_create.html") login := checkAdminLogin(w, r) if login == nil { diff --git a/directory.go b/directory.go index ab5dea3..0b5acd5 100644 --- a/directory.go +++ b/directory.go @@ -13,7 +13,7 @@ const FIELD_NAME_PROFILE_PICTURE = "profilePicture" const FIELD_NAME_DIRECTORY_VISIBILITY = "directoryVisibility" func handleDirectory(w http.ResponseWriter, r *http.Request) { - templateDirectory := template.Must(template.ParseFiles("templates/layout.html", "templates/directory.html")) + templateDirectory := getTemplate("directory.html") login := checkLogin(w, r) if login == nil { @@ -37,7 +37,7 @@ type SearchResults struct { } func handleDirectorySearch(w http.ResponseWriter, r *http.Request) { - templateDirectoryResults := template.Must(template.ParseFiles("templates/directory_results.html")) + templateDirectoryResults := template.Must(template.ParseFiles(templatePath + "/directory_results.html")) //Get input value by user r.ParseMultipartForm(1024) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1c2bd56 --- /dev/null +++ b/flake.lock @@ -0,0 +1,79 @@ +{ + "nodes": { + "gomod2nix": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1655245309, + "narHash": "sha256-d/YPoQ/vFn1+GTmSdvbSBSTOai61FONxB4+Lt6w/IVI=", + "owner": "tweag", + "repo": "gomod2nix", + "rev": "40d32f82fc60d66402eb0972e6e368aeab3faf58", + "type": "github" + }, + "original": { + "owner": "tweag", + "repo": "gomod2nix", + "rev": "40d32f82fc60d66402eb0972e6e368aeab3faf58", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1653581809, + "narHash": "sha256-Uvka0V5MTGbeOfWte25+tfRL3moECDh1VwokWSZUdoY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "83658b28fe638a170a19b8933aa008b30640fbd1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1669764884, + "narHash": "sha256-1qWR/5+WtqxSedrFbUbM3zPMO7Ec2CGWaxtK4z4DdvY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0244e143dc943bcf661fdaf581f01eb0f5000fcf", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0244e143dc943bcf661fdaf581f01eb0f5000fcf", + "type": "github" + } + }, + "root": { + "inputs": { + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs_2" + } + }, + "utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5e2c174 --- /dev/null +++ b/flake.nix @@ -0,0 +1,43 @@ +{ + description = "A simple LDAP web interface for Bottin"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/0244e143dc943bcf661fdaf581f01eb0f5000fcf"; + inputs.gomod2nix.url = "github:tweag/gomod2nix/40d32f82fc60d66402eb0972e6e368aeab3faf58"; + + outputs = { self, nixpkgs, gomod2nix }: + let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ + (self: super: { + gomod = super.callPackage "${gomod2nix}/builder/" { }; + }) + ]; + }; + src = ./.; + bottin = pkgs.gomod.buildGoApplication { + pname = "guichet"; + version = "0.1.0"; + src = src; + modules = ./gomod2nix.toml; + + CGO_ENABLED=0; + + ldflags = [ + "-X main.templatePath=${src + "/templates"}" + "-X main.staticPath=${src + "/static"}" + ]; + + meta = with pkgs.lib; { + description = "A simple LDAP web interface for Bottin"; + homepage = "https://git.deuxfleurs.fr/Deuxfleurs/guichet"; + license = licenses.gpl3Plus; + platforms = platforms.linux; + }; + }; + in + { + packages.x86_64-linux.bottin = bottin; + packages.x86_64-linux.default = self.packages.x86_64-linux.bottin; + }; +} @@ -1,4 +1,4 @@ -module deuxfleurs.fr/Deuxfleurs/guichet +module git.deuxfleurs.fr/Deuxfleurs/guichet go 1.13 diff --git a/gomod2nix.toml b/gomod2nix.toml new file mode 100644 index 0000000..02aa322 --- /dev/null +++ b/gomod2nix.toml @@ -0,0 +1,111 @@ +schema = 3 + +[mod] + [mod."github.com/davecgh/go-spew"] + version = "v1.1.1" + hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI=" + [mod."github.com/dustin/go-humanize"] + version = "v1.0.0" + hash = "sha256-gy4G1PnHD9iw2MitHX6y1y93qr3C9IncmXL7ttUMDs8=" + [mod."github.com/emersion/go-sasl"] + version = "v0.0.0-20191210011802-430746ea8b9b" + hash = "sha256-bADpAn0ZhlTTsEB3MsG8J31cQjTtHTzohX/wkL1aMIc=" + [mod."github.com/emersion/go-smtp"] + version = "v0.12.1" + hash = "sha256-fiss5y7chfHv80vIQ9Xwx3J+3qLMA63EOP4OG3DxAtI=" + [mod."github.com/go-asn1-ber/asn1-ber"] + version = "v1.3.1" + hash = "sha256-Alh6bUq9HoBDhY+n6W7xNBto/dUMxPGvucA6guarrjc=" + [mod."github.com/go-ldap/ldap"] + version = "v3.0.3+incompatible" + hash = "sha256-SQuiphWJcUVdk+GVYfzYpmW4MI1DtK9Ixo6A/PcCmAI=" + [mod."github.com/go-ldap/ldap/v3"] + version = "v3.1.6" + hash = "sha256-UPUdYKOoCQWgl2Onbq1Oql7XU4TeYQA/+j4atwhdKbE=" + [mod."github.com/google/gofuzz"] + version = "v1.0.0" + hash = "sha256-ZvgcSQt4kMwS6nvPp3jrlCHSH3bky1oBD6kytnEa5GM=" + [mod."github.com/google/uuid"] + version = "v1.1.1" + hash = "sha256-66PXC/RCPUyhS9PhkIPQFR3tbM2zZYDNPGXN7JJj3UE=" + [mod."github.com/gopherjs/gopherjs"] + version = "v0.0.0-20181017120253-0766667cb4d1" + hash = "sha256-AuXnjjoLbFZ85Oi8sldH117MBh+yCUB9HU5Y5syJ7Lg=" + [mod."github.com/gorilla/mux"] + version = "v1.7.3" + hash = "sha256-YZSIN7Ua+hPqSIrT+tiRz3aFqJ1EWHvwee+PptpHI28=" + [mod."github.com/gorilla/securecookie"] + version = "v1.1.1" + hash = "sha256-IBBYWfdOuXvQsb01DaA8tBizCfAE1J2KLXIn3W+NeJk=" + [mod."github.com/gorilla/sessions"] + version = "v1.2.0" + hash = "sha256-4V7yd/vf03CEsb3pz5dbLWwv7t9QgKkEhVXtc1/z5s8=" + [mod."github.com/json-iterator/go"] + version = "v1.1.10" + hash = "sha256-jdS2C0WsgsWREBSj+YUzSqdZofMfUMecaOQ/lB9Mu6k=" + [mod."github.com/jtolds/gls"] + version = "v4.20.0+incompatible" + hash = "sha256-Zu5naRjnwOYBzRv0CYhIZTizA0AajzOg7mJrL7Bo/cw=" + [mod."github.com/klauspost/cpuid"] + version = "v1.2.3" + hash = "sha256-1IBlONMxKVgudV/mzNrFZB60z8w4xFjVbEU2DoIAoeg=" + [mod."github.com/konsorten/go-windows-terminal-sequences"] + version = "v1.0.3" + hash = "sha256-9HojTXKv7b3HiEhYaKXDxraEfvU5vrg47FbCjTRpOvs=" + [mod."github.com/minio/md5-simd"] + version = "v1.1.0" + hash = "sha256-jJbDwg7KlLB991wj1U6y+kJKOUxKVGQrDbM3nY+6qxE=" + [mod."github.com/minio/minio-go/v7"] + version = "v7.0.0" + hash = "sha256-xWAELgH6mWVGKFEe2gbzvigJDNk+ELmegJe09KvUqvY=" + [mod."github.com/minio/sha256-simd"] + version = "v0.1.1" + hash = "sha256-HpcuLTnpcyKe0ua2MN/ysK5cXdrwquDjrx4Y2dG6W2s=" + [mod."github.com/mitchellh/go-homedir"] + version = "v1.1.0" + hash = "sha256-oduBKXHAQG8X6aqLEpqZHs5DOKe84u6WkBwi4W6cv3k=" + [mod."github.com/modern-go/concurrent"] + version = "v0.0.0-20180228061459-e0a39a4cb421" + hash = "sha256-+bdeHUArnpkk4eMQIwXm9K249NkpwAjoTrXrGn/4VUE=" + [mod."github.com/modern-go/reflect2"] + version = "v0.0.0-20180701023420-4b7aa43c6742" + hash = "sha256-RyIwgrPwtd4lNjLGkBVxRvu5IdXLDqf5F69QWLm0zLw=" + [mod."github.com/nfnt/resize"] + version = "v0.0.0-20180221191011-83c6a9932646" + hash = "sha256-yvPV+HlDOyJsiwAcVHQkmtw8DHSXyw+cXHkigXm8rAA=" + [mod."github.com/pmezard/go-difflib"] + version = "v1.0.0" + hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA=" + [mod."github.com/sirupsen/logrus"] + version = "v1.6.0" + hash = "sha256-4v27X4yyl52BtZcZEnDe0tfvOaEq+TCcp7R8HBzreDM=" + [mod."github.com/smartystreets/assertions"] + version = "v0.0.0-20180927180507-b2de0cb4f26d" + hash = "sha256-PoE+VQEnzJogI/mDBJ6dTCCR217nFjHfYWXQt9Vr9MQ=" + [mod."github.com/smartystreets/goconvey"] + version = "v0.0.0-20190330032615-68dc04aab96a" + hash = "sha256-HD+AZE1agl1pVbQTFUKLKtjg3XdVSVLwRSu4u+UVV2M=" + [mod."github.com/stretchr/objx"] + version = "v0.1.1" + hash = "sha256-HdGVZCuy7VprC5W9UxGbDmXqsKADMjpEDht7ilGVLco=" + [mod."github.com/stretchr/testify"] + version = "v1.3.0" + hash = "sha256-+mSebBNccNcxbY462iKTNTWmd5ZuUkUqFebccn3EtIA=" + [mod."golang.org/x/crypto"] + version = "v0.0.0-20200214034016-1d94cc7ab1c6" + hash = "sha256-fWTzdDxt/1E8Jx7b6tmYEVqqJs5FoVVya9aEK9gDbdY=" + [mod."golang.org/x/net"] + version = "v0.0.0-20190522155817-f3200d17e092" + hash = "sha256-KkNNFr+wx/pf7lSLN2ygwkQ9oCZQuef+hCtEjEX+gJE=" + [mod."golang.org/x/sys"] + version = "v0.0.0-20200223170610-d5e6a3e2c0ae" + hash = "sha256-IvG2XSER2dyrVfhYieEpHcp28LOz4FrjQqN0SCeFOek=" + [mod."golang.org/x/text"] + version = "v0.3.0" + hash = "sha256-0FFbaxF1ZuAQF3sCcA85e8MO6prFeHint36inija4NY=" + [mod."golang.org/x/tools"] + version = "v0.0.0-20190328211700-ab21143f2384" + hash = "sha256-OcjaTxx6C/cbnUZLN2ArTrOBlBCijWJVUPaMgK67MkY=" + [mod."gopkg.in/ini.v1"] + version = "v1.57.0" + hash = "sha256-WSjX+qHJ1Rf4FRMTs7udQwEBkIo+z8+EK3uB5CebrZ4=" @@ -60,7 +60,7 @@ func handleInvitationCode(w http.ResponseWriter, r *http.Request) { inviteDn := config.InvitationNameAttr + "=" + code_id + "," + config.InvitationBaseDN err := l.Bind(inviteDn, code_pw) if err != nil { - templateInviteInvalidCode := template.Must(template.ParseFiles("templates/layout.html", "templates/invite_invalid_code.html")) + templateInviteInvalidCode := getTemplate("invite_invalid_code.html") templateInviteInvalidCode.Execute(w, nil) return } @@ -110,7 +110,7 @@ type NewAccountData struct { } func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invitedBy string) bool { - templateInviteNewAccount := template.Must(template.ParseFiles("templates/layout.html", "templates/invite_new_account.html")) + templateInviteNewAccount := getTemplate("invite_new_account.html") data := &NewAccountData{} @@ -239,7 +239,7 @@ type CodeMailFields struct { } func handleInviteSendCode(w http.ResponseWriter, r *http.Request) { - templateInviteSendCode := template.Must(template.ParseFiles("templates/layout.html", "templates/invite_send_code.html")) + templateInviteSendCode := getTemplate("invite_send_code.html") login := checkInviterLogin(w, r) if login == nil { @@ -298,7 +298,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod return } - templateMail := template.Must(template.ParseFiles("templates/invite_mail.txt")) + templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt")) buf := bytes.NewBuffer([]byte{}) templateMail.Execute(buf, &CodeMailFields{ To: sendto, @@ -57,6 +57,9 @@ var config *ConfigFile const SESSION_NAME = "guichet_session" +var staticPath = "./static" +var templatePath = "./templates" + var store sessions.Store = nil func readConfig() ConfigFile { @@ -94,6 +97,10 @@ func readConfig() ConfigFile { return config_file } +func getTemplate(name string) *template.Template { + return template.Must(template.ParseFiles(templatePath+"/layout.html", templatePath+"/"+name)) +} + func main() { flag.Parse() @@ -127,7 +134,7 @@ func main() { r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP) r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate) - staticfiles := http.FileServer(http.Dir("static")) + staticfiles := http.FileServer(http.Dir(staticPath)) r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles)) log.Printf("Starting HTTP server on %s", config.HttpBindAddr) @@ -296,7 +303,7 @@ type HomePageData struct { } func handleHome(w http.ResponseWriter, r *http.Request) { - templateHome := template.Must(template.ParseFiles("templates/layout.html", "templates/home.html")) + templateHome := getTemplate("home.html") login := checkLogin(w, r) if login == nil { @@ -338,7 +345,7 @@ type LoginFormData struct { } func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { - templateLogin := template.Must(template.ParseFiles("templates/layout.html", "templates/login.html")) + templateLogin := getTemplate("login.html") if r.Method == "GET" { templateLogin.Execute(w, LoginFormData{}) @@ -43,7 +43,7 @@ func newMinioClient() (*minio.Client, error) { return minioCLient, nil } -//Upload image through guichet server. +// Upload image through guichet server. func uploadProfilePicture(w http.ResponseWriter, r *http.Request, login *LoginStatus) (string, error) { file, _, err := r.FormFile("image") @@ -1,7 +1,6 @@ package main import ( - "html/template" "net/http" "strings" @@ -22,7 +21,7 @@ type ProfileTplData struct { } func handleProfile(w http.ResponseWriter, r *http.Request) { - templateProfile := template.Must(template.ParseFiles("templates/layout.html", "templates/profile.html")) + templateProfile := getTemplate("profile.html") login := checkLogin(w, r) if login == nil { @@ -97,7 +96,7 @@ type PasswdTplData struct { } func handlePasswd(w http.ResponseWriter, r *http.Request) { - templatePasswd := template.Must(template.ParseFiles("templates/layout.html", "templates/passwd.html")) + templatePasswd := getTemplate("passwd.html") login := checkLogin(w, r) if login == nil { |