aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-09 22:06:33 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-09 22:06:33 +0100
commit43825b1bbc02e9b1697b965a1621a936c5ae0334 (patch)
tree19945695086a20c8f8aedda7c90e171b61638b41 /main.go
parentf929ca7297905e4233aa32fe2d80dd4cc3fcda30 (diff)
downloadguichet-43825b1bbc02e9b1697b965a1621a936c5ae0334.tar.gz
guichet-43825b1bbc02e9b1697b965a1621a936c5ae0334.zip
LDAP modification form
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/main.go b/main.go
index 29da525..a0d5b07 100644
--- a/main.go
+++ b/main.go
@@ -16,6 +16,7 @@ import (
"github.com/go-ldap/ldap/v3"
"github.com/gorilla/sessions"
+ "github.com/gorilla/mux"
)
type ConfigFile struct {
@@ -24,6 +25,7 @@ type ConfigFile struct {
LdapServerAddr string `json:"ldap_server_addr"`
LdapTLS bool `json:"ldap_tls"`
+ BaseDN string `json:"base_dn"`
UserBaseDN string `json:"user_base_dn"`
UserNameAttr string `json:"user_name_attr"`
GroupBaseDN string `json:"group_base_dn"`
@@ -53,6 +55,7 @@ func readConfig() ConfigFile {
SessionKey: base64.StdEncoding.EncodeToString(key_bytes),
LdapServerAddr: "ldap://127.0.0.1:389",
LdapTLS: false,
+ BaseDN: "dc=example,dc=com",
UserBaseDN: "ou=users,dc=example,dc=com",
UserNameAttr: "uid",
GroupBaseDN: "ou=groups,dc=example,dc=com",
@@ -103,19 +106,20 @@ func main() {
config = &config_file
store = sessions.NewFilesystemStore("", []byte(config.SessionKey))
- http.HandleFunc("/", handleHome)
- http.HandleFunc("/logout", handleLogout)
- http.HandleFunc("/profile", handleProfile)
- http.HandleFunc("/passwd", handlePasswd)
+ r := mux.NewRouter()
+ r.HandleFunc("/", handleHome)
+ r.HandleFunc("/logout", handleLogout)
+ r.HandleFunc("/profile", handleProfile)
+ r.HandleFunc("/passwd", handlePasswd)
- http.HandleFunc("/admin/users", handleAdminUsers)
- //http.HandleFunc("/admin/groups", handleAdminGroups)
- //http.HandleFunc("/admin/ldap", handleAdminLDAP)
+ r.HandleFunc("/admin/users", handleAdminUsers)
+ r.HandleFunc("/admin/groups", handleAdminGroups)
+ r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP)
staticfiles := http.FileServer(http.Dir("static"))
- http.Handle("/static/", http.StripPrefix("/static/", staticfiles))
+ r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles))
- err := http.ListenAndServe(config.HttpBindAddr, logRequest(http.DefaultServeMux))
+ err := http.ListenAndServe(config.HttpBindAddr, logRequest(r))
if err != nil {
log.Fatal("Cannot start http server: ", err)
}
@@ -233,6 +237,7 @@ type HomePageData struct {
Login *LoginStatus
CanAdmin bool
CanInvite bool
+ BaseDN string
}
func handleHome(w http.ResponseWriter, r *http.Request) {
@@ -258,6 +263,7 @@ func handleHome(w http.ResponseWriter, r *http.Request) {
Login: login,
CanAdmin: can_admin,
CanInvite: can_invite,
+ BaseDN: config.BaseDN,
})
}