Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
03177eb4d9 | |||
95ad75b20d | |||
8cefdb0b01 |
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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
go.mod
26
go.mod
@@ -1,6 +1,8 @@
|
|||||||
module proxmoxaas-ldap
|
module proxmoxaas-ldap
|
||||||
|
|
||||||
go 1.22.4
|
go 1.23
|
||||||
|
|
||||||
|
toolchain go1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-contrib/sessions v1.0.1
|
github.com/gin-contrib/sessions v1.0.1
|
||||||
@@ -11,35 +13,35 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
|
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
|
||||||
github.com/bytedance/sonic v1.11.8 // indirect
|
github.com/bytedance/sonic v1.12.3 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
|
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
github.com/go-playground/validator/v10 v10.22.1 // indirect
|
||||||
github.com/goccy/go-json v0.10.3 // indirect
|
github.com/goccy/go-json v0.10.3 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gorilla/context v1.1.2 // indirect
|
github.com/gorilla/context v1.1.2 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
github.com/gorilla/sessions v1.3.0 // indirect
|
github.com/gorilla/sessions v1.4.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
golang.org/x/arch v0.8.0 // indirect
|
golang.org/x/arch v0.11.0 // indirect
|
||||||
golang.org/x/crypto v0.24.0 // indirect
|
golang.org/x/crypto v0.28.0 // indirect
|
||||||
golang.org/x/net v0.26.0 // indirect
|
golang.org/x/net v0.30.0 // indirect
|
||||||
golang.org/x/sys v0.21.0 // indirect
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.19.0 // indirect
|
||||||
google.golang.org/protobuf v1.34.2 // indirect
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user