Trying to refactor

This commit is contained in:
Chris Mann 2023-07-20 11:20:46 +02:00
parent f8ee897d2a
commit 7a7fd592e4
2 changed files with 110 additions and 69 deletions

View file

@ -6,6 +6,7 @@ import (
"regexp"
"sort"
"strings"
"github.com/go-ldap/ldap/v3"
"github.com/gorilla/mux"
)
@ -73,6 +74,13 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
}
sort.Sort(data.Users)
addNewUser(NewUser{CN: "newuser@lesgv.com",
GivenName: "New",
SN: "User",
DisplayName: "New User",
Mail: "newuser@lesgv.com",
})
templateAdminUsers.Execute(w, data)
}
@ -221,7 +229,7 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
req := ldap.NewAddRequest(guestDn, nil)
//req.Attribute("objectclass", []string{"inetOrgPerson", "organizationalPerson", "person", "top"})
req.Attribute("objectclass", []string{"inetOrgPerson"})
req.Attribute("mail", []string{fmt.Sprintf("%s",mail)})
req.Attribute("mail", []string{fmt.Sprintf("%s", mail)})
if givenname != "" {
req.Attribute("givenname", []string{givenname})
}
@ -442,7 +450,6 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
}
// log.Printf(fmt.Sprintf("446: %v",path))
// Handle modification operation
if r.Method == "POST" {
r.ParseForm()
@ -696,7 +703,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
searchRequest = ldap.NewSearchRequest(
config.GroupBaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=groupOfNames)(member=%s))",dn),
fmt.Sprintf("(&(objectClass=groupOfNames)(member=%s))", dn),
[]string{"dn", "displayName", "cn", "description"},
nil)
// log.Printf(fmt.Sprintf("708: %v",searchRequest))
@ -715,7 +722,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
searchRequest = ldap.NewSearchRequest(
config.GroupBaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=groupOfNames)(!(member=%s)))",dn),
fmt.Sprintf("(&(objectClass=groupOfNames)(!(member=%s)))", dn),
[]string{"dn", "displayName", "cn", "description"},
nil)
// log.Printf(fmt.Sprintf("724: %v",searchRequest))

34
utils.go Normal file
View file

@ -0,0 +1,34 @@
package main
import (
"fmt"
"log"
// "bytes"
// "crypto/rand"
// "encoding/binary"
// "encoding/hex"
// "fmt"
// "html/template"
// "log"
// "net/http"
// "regexp"
// "strings"
// "github.com/emersion/go-sasl"
// "github.com/emersion/go-smtp"
// "github.com/gorilla/mux"
// "golang.org/x/crypto/argon2"
)
type NewUser struct {
DN string
CN string
GivenName string
DisplayName string
Mail string
SN string
UID string
}
func addNewUser(newUser NewUser) {
log.Printf(fmt.Sprint("Adding New User"))
}