add mail attribute to user,
bump API version to 1.0.3
This commit is contained in:
parent
95ad75b20d
commit
03177eb4d9
10
app/app.go
10
app/app.go
@ -15,16 +15,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var LDAPSessions map[string]*LDAPClient
|
var LDAPSessions map[string]*LDAPClient
|
||||||
var APIVersion = "1.0.2"
|
var APIVersion = "1.0.3"
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
gob.Register(LDAPClient{})
|
gob.Register(LDAPClient{})
|
||||||
|
|
||||||
|
log.Printf("Starting ProxmoxAAS-LDAP version %s\n", APIVersion)
|
||||||
|
|
||||||
configPath := flag.String("config", "config.json", "path to config.json file")
|
configPath := flag.String("config", "config.json", "path to config.json file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config := GetConfig(*configPath)
|
config := GetConfig(*configPath)
|
||||||
log.Println("Initialized config from " + *configPath)
|
log.Printf("Read in config from %s\n", *configPath)
|
||||||
|
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
@ -37,6 +39,8 @@ func Run() {
|
|||||||
})
|
})
|
||||||
router.Use(sessions.Sessions(config.SessionCookieName, store))
|
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)
|
LDAPSessions = make(map[string]*LDAPClient)
|
||||||
|
|
||||||
router.GET("/version", func(c *gin.Context) {
|
router.GET("/version", func(c *gin.Context) {
|
||||||
@ -300,5 +304,7 @@ func Run() {
|
|||||||
c.JSON(status, res)
|
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))
|
router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
|
||||||
}
|
}
|
||||||
|
12
app/ldap.go
12
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) {
|
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{
|
return http.StatusBadRequest, gin.H{
|
||||||
"ok": false,
|
"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("sn", []string{user.SN})
|
||||||
addRequest.Attribute("cn", []string{user.CN})
|
addRequest.Attribute("cn", []string{user.CN})
|
||||||
|
addRequest.Attribute("mail", []string{user.Mail})
|
||||||
addRequest.Attribute("userPassword", []string{user.UserPassword})
|
addRequest.Attribute("userPassword", []string{user.UserPassword})
|
||||||
addRequest.Attribute("objectClass", []string{"inetOrgPerson"})
|
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) {
|
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{
|
return http.StatusBadRequest, gin.H{
|
||||||
"ok": false,
|
"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 != "" {
|
if user.SN != "" {
|
||||||
modifyRequest.Replace("sn", []string{user.SN})
|
modifyRequest.Replace("sn", []string{user.SN})
|
||||||
}
|
}
|
||||||
|
if user.Mail != "" {
|
||||||
|
modifyRequest.Replace("mail", []string{user.Mail})
|
||||||
|
}
|
||||||
if user.UserPassword != "" {
|
if user.UserPassword != "" {
|
||||||
modifyRequest.Replace("userPassword", []string{user.UserPassword})
|
modifyRequest.Replace("userPassword", []string{user.UserPassword})
|
||||||
}
|
}
|
||||||
|
@ -113,12 +113,14 @@ func LDAPGroupToGin(group LDAPGroup) gin.H {
|
|||||||
type UserOptional struct { // add or modify user body struct
|
type UserOptional struct { // add or modify user body struct
|
||||||
CN string `form:"cn"`
|
CN string `form:"cn"`
|
||||||
SN string `form:"sn"`
|
SN string `form:"sn"`
|
||||||
|
Mail string `form:"mail"`
|
||||||
UserPassword string `form:"userpassword"`
|
UserPassword string `form:"userpassword"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserRequired struct { // add or modify user body struct
|
type UserRequired struct { // add or modify user body struct
|
||||||
CN string `form:"cn" binding:"required"`
|
CN string `form:"cn" binding:"required"`
|
||||||
SN string `form:"sn" binding:"required"`
|
SN string `form:"sn" binding:"required"`
|
||||||
|
Mail string `form:"mail" binding:"required"`
|
||||||
UserPassword string `form:"userpassword" binding:"required"`
|
UserPassword string `form:"userpassword" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user