add mail attribute to user,

bump API version to 1.0.3
This commit is contained in:
Arthur Lu 2024-10-12 22:33:34 +00:00
parent 95ad75b20d
commit 03177eb4d9
3 changed files with 18 additions and 6 deletions

View File

@ -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))
}

View File

@ -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})
}

View File

@ -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"`
}