From 03177eb4d9fb4ac857793f3a9ab896d12bcbb48e Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Sat, 12 Oct 2024 22:33:34 +0000 Subject: [PATCH] add mail attribute to user, bump API version to 1.0.3 --- app/app.go | 10 ++++++++-- app/ldap.go | 12 ++++++++---- app/utils.go | 2 ++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index 892fe2d..b22f0ef 100644 --- a/app/app.go +++ b/app/app.go @@ -15,16 +15,18 @@ import ( ) var LDAPSessions map[string]*LDAPClient -var APIVersion = "1.0.2" +var APIVersion = "1.0.3" func Run() { gob.Register(LDAPClient{}) + log.Printf("Starting ProxmoxAAS-LDAP version %s\n", APIVersion) + configPath := flag.String("config", "config.json", "path to config.json file") flag.Parse() config := GetConfig(*configPath) - log.Println("Initialized config from " + *configPath) + log.Printf("Read in config from %s\n", *configPath) gin.SetMode(gin.ReleaseMode) router := gin.Default() @@ -37,6 +39,8 @@ func Run() { }) router.Use(sessions.Sessions(config.SessionCookieName, store)) + log.Printf("Started API router and cookie store (Name: %s Params: %+v)\n", config.SessionCookieName, config.SessionCookie) + LDAPSessions = make(map[string]*LDAPClient) router.GET("/version", func(c *gin.Context) { @@ -300,5 +304,7 @@ func Run() { c.JSON(status, res) }) + log.Printf("Starting LDAP API on port %s\n", strconv.Itoa(config.ListenPort)) + router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort)) } diff --git a/app/ldap.go b/app/ldap.go index adafb3c..8c9bec2 100644 --- a/app/ldap.go +++ b/app/ldap.go @@ -94,10 +94,10 @@ func (l LDAPClient) GetUser(uid string) (int, gin.H) { } func (l LDAPClient) AddUser(uid string, user UserRequired) (int, gin.H) { - if user.CN == "" || user.SN == "" || user.UserPassword == "" { + if user.CN == "" || user.SN == "" || user.UserPassword == "" || user.Mail == "" { return http.StatusBadRequest, gin.H{ "ok": false, - "error": "Missing one of required fields: cn, sn, userpassword", + "error": "Missing one of required fields: cn, sn, mail, userpassword", } } @@ -107,6 +107,7 @@ func (l LDAPClient) AddUser(uid string, user UserRequired) (int, gin.H) { ) addRequest.Attribute("sn", []string{user.SN}) addRequest.Attribute("cn", []string{user.CN}) + addRequest.Attribute("mail", []string{user.Mail}) addRequest.Attribute("userPassword", []string{user.UserPassword}) addRequest.Attribute("objectClass", []string{"inetOrgPerson"}) @@ -125,10 +126,10 @@ func (l LDAPClient) AddUser(uid string, user UserRequired) (int, gin.H) { } func (l LDAPClient) ModUser(uid string, user UserOptional) (int, gin.H) { - if user.CN == "" && user.SN == "" && user.UserPassword == "" { + if user.CN == "" && user.SN == "" && user.UserPassword == "" && user.Mail == "" { return http.StatusBadRequest, gin.H{ "ok": false, - "error": "Requires one of fields: cn, sn, userpassword", + "error": "Requires one of fields: cn, sn, mail, userpassword", } } @@ -142,6 +143,9 @@ func (l LDAPClient) ModUser(uid string, user UserOptional) (int, gin.H) { if user.SN != "" { modifyRequest.Replace("sn", []string{user.SN}) } + if user.Mail != "" { + modifyRequest.Replace("mail", []string{user.Mail}) + } if user.UserPassword != "" { modifyRequest.Replace("userPassword", []string{user.UserPassword}) } diff --git a/app/utils.go b/app/utils.go index 1bca7fb..c4e139a 100644 --- a/app/utils.go +++ b/app/utils.go @@ -113,12 +113,14 @@ func LDAPGroupToGin(group LDAPGroup) gin.H { type UserOptional struct { // add or modify user body struct CN string `form:"cn"` SN string `form:"sn"` + Mail string `form:"mail"` UserPassword string `form:"userpassword"` } type UserRequired struct { // add or modify user body struct CN string `form:"cn" binding:"required"` SN string `form:"sn" binding:"required"` + Mail string `form:"mail" binding:"required"` UserPassword string `form:"userpassword" binding:"required"` }