Use more appropriate description instead of displayname for everything except users

This commit is contained in:
Alex 2020-02-12 15:54:17 +01:00
parent 3fbbe61a46
commit b3d6854d82
4 changed files with 59 additions and 38 deletions

View file

@ -98,7 +98,7 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
config.GroupBaseDN, config.GroupBaseDN,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=groupOfNames))"), fmt.Sprintf("(&(objectClass=groupOfNames))"),
[]string{config.GroupNameAttr, "dn", "displayname"}, []string{config.GroupNameAttr, "dn", "description"},
nil) nil)
sr, err := login.conn.Search(searchRequest) sr, err := login.conn.Search(searchRequest)
@ -138,13 +138,13 @@ type AdminLDAPTplData struct {
type EntryName struct { type EntryName struct {
DN string DN string
DisplayName string Name string
} }
type Child struct { type Child struct {
DN string DN string
Identifier string Identifier string
DisplayName string Name string
} }
type PathItem struct { type PathItem struct {
@ -337,7 +337,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} }
} }
deletable := true deletable := true
for _, restricted := range []string{"displayname", "objectclass", "structuralobjectclass"} { for _, restricted := range []string{"objectclass", "structuralobjectclass"} {
if strings.EqualFold(attr.Name, restricted) { if strings.EqualFold(attr.Name, restricted) {
deletable = false deletable = false
break break
@ -366,7 +366,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
config.UserBaseDN, config.UserBaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(objectClass=organizationalPerson)"), fmt.Sprintf("(objectClass=organizationalPerson)"),
[]string{"dn", "displayname"}, []string{"dn", "displayname", "description"},
nil) nil)
sr, err := login.conn.Search(searchRequest) sr, err := login.conn.Search(searchRequest)
if err != nil { if err != nil {
@ -375,11 +375,14 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} }
for _, ent := range sr.Entries { for _, ent := range sr.Entries {
mapDnToName[ent.DN] = ent.GetAttributeValue("displayname") mapDnToName[ent.DN] = ent.GetAttributeValue("displayname")
if mapDnToName[ent.DN] == "" {
mapDnToName[ent.DN] = ent.GetAttributeValue("description")
}
} }
for _, memdn := range members_dn { for _, memdn := range members_dn {
members = append(members, EntryName{ members = append(members, EntryName{
DN: memdn, DN: memdn,
DisplayName: mapDnToName[memdn], Name: mapDnToName[memdn],
}) })
} }
} }
@ -397,7 +400,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
config.GroupBaseDN, config.GroupBaseDN,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(objectClass=groupOfNames)"), fmt.Sprintf("(objectClass=groupOfNames)"),
[]string{"dn", "displayname"}, []string{"dn", "description"},
nil) nil)
sr, err := login.conn.Search(searchRequest) sr, err := login.conn.Search(searchRequest)
if err != nil { if err != nil {
@ -405,12 +408,12 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
return return
} }
for _, ent := range sr.Entries { for _, ent := range sr.Entries {
mapDnToName[ent.DN] = ent.GetAttributeValue("displayname") mapDnToName[ent.DN] = ent.GetAttributeValue("description")
} }
for _, grpdn := range groups_dn { for _, grpdn := range groups_dn {
groups = append(groups, EntryName{ groups = append(groups, EntryName{
DN: grpdn, DN: grpdn,
DisplayName: mapDnToName[grpdn], Name: mapDnToName[grpdn],
}) })
} }
} }
@ -420,7 +423,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
dn, dn,
ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false, ldap.ScopeSingleLevel, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(objectclass=*)"), fmt.Sprintf("(objectclass=*)"),
[]string{"dn", "displayname"}, []string{"dn", "displayname", "description"},
nil) nil)
sr, err = login.conn.Search(searchRequest) sr, err = login.conn.Search(searchRequest)
@ -433,10 +436,14 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
children := []Child{} children := []Child{}
for _, item := range sr.Entries { for _, item := range sr.Entries {
name := item.GetAttributeValue("displayname")
if name == "" {
name = item.GetAttributeValue("description")
}
children = append(children, Child{ children = append(children, Child{
DN: item.DN, DN: item.DN,
Identifier: strings.Split(item.DN, ",")[0], Identifier: strings.Split(item.DN, ",")[0],
DisplayName: item.GetAttributeValue("displayname"), Name: name,
}) })
} }
@ -480,13 +487,14 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
type CreateData struct { type CreateData struct {
SuperDN string SuperDN string
Path []PathItem Path []PathItem
Template string
IdType string IdType string
IdValue string IdValue string
DisplayName string DisplayName string
Description string
StructuralObjectClass string StructuralObjectClass string
ObjectClass string ObjectClass string
IsTemplated bool
Error string Error string
} }
@ -543,35 +551,35 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
SuperDN: super_dn, SuperDN: super_dn,
Path: path, Path: path,
} }
data.Template = template
if template == "user" { if template == "user" {
data.IdType = config.UserNameAttr data.IdType = config.UserNameAttr
data.StructuralObjectClass = "inetOrgPerson" data.StructuralObjectClass = "inetOrgPerson"
data.ObjectClass = "inetOrgPerson\norganizationalPerson\nperson\ntop" data.ObjectClass = "inetOrgPerson\norganizationalPerson\nperson\ntop"
data.IsTemplated = true
} else if template == "group" { } else if template == "group" {
data.IdType = config.UserNameAttr data.IdType = config.UserNameAttr
data.StructuralObjectClass = "groupOfNames" data.StructuralObjectClass = "groupOfNames"
data.ObjectClass = "groupOfNames\ntop" data.ObjectClass = "groupOfNames\ntop"
data.IsTemplated = true
} else if template == "ou" { } else if template == "ou" {
data.IdType = "ou" data.IdType = "ou"
data.StructuralObjectClass = "organizationalUnit" data.StructuralObjectClass = "organizationalUnit"
data.ObjectClass = "organizationalUnit\ntop" data.ObjectClass = "organizationalUnit\ntop"
data.IsTemplated = true
} else { } else {
data.IdType = "cn" data.IdType = "cn"
data.ObjectClass = "top" data.ObjectClass = "top"
data.Template = ""
} }
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() r.ParseForm()
if !data.IsTemplated { if data.Template == "" {
data.IdType = strings.TrimSpace(strings.Join(r.Form["idtype"], "")) data.IdType = strings.TrimSpace(strings.Join(r.Form["idtype"], ""))
data.StructuralObjectClass = strings.TrimSpace(strings.Join(r.Form["soc"], "")) data.StructuralObjectClass = strings.TrimSpace(strings.Join(r.Form["soc"], ""))
data.ObjectClass = strings.Join(r.Form["oc"], "") data.ObjectClass = strings.Join(r.Form["oc"], "")
} }
data.IdValue = strings.TrimSpace(strings.Join(r.Form["idvalue"], "")) data.IdValue = strings.TrimSpace(strings.Join(r.Form["idvalue"], ""))
data.DisplayName = strings.TrimSpace(strings.Join(r.Form["displayname"], "")) data.DisplayName = strings.TrimSpace(strings.Join(r.Form["displayname"], ""))
data.Description = strings.TrimSpace(strings.Join(r.Form["description"], ""))
object_class := []string{} object_class := []string{}
for _, oc := range strings.Split(data.ObjectClass, "\n") { for _, oc := range strings.Split(data.ObjectClass, "\n") {
@ -593,11 +601,15 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
dn := data.IdType + "=" + data.IdValue + "," + super_dn dn := data.IdType + "=" + data.IdValue + "," + super_dn
req := ldap.NewAddRequest(dn, nil) req := ldap.NewAddRequest(dn, nil)
req.Attribute("objectClass", object_class) req.Attribute("objectClass", object_class)
req.Attribute("structuralObjectClass", if data.StructuralObjectClass != "" {
[]string{data.StructuralObjectClass}) req.Attribute("structuralObjectClass", []string{data.StructuralObjectClass})
}
if data.DisplayName != "" { if data.DisplayName != "" {
req.Attribute("displayname", []string{data.DisplayName}) req.Attribute("displayname", []string{data.DisplayName})
} }
if data.Description != "" {
req.Attribute("description", []string{data.Description})
}
err := login.conn.Add(req) err := login.conn.Add(req)
if err != nil { if err != nil {

View file

@ -36,19 +36,28 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="idtype">Type d'identifiant:</label> <label for="idtype">Type d'identifiant:</label>
<input type="text" {{if .IsTemplated}}disabled="disabled"{{end}} id="idtype" name="idtype" class="form-control" value="{{ .IdType }}" /> <input type="text" {{if .Template}}disabled="disabled"{{end}} id="idtype" name="idtype" class="form-control" value="{{ .IdType }}" />
</div> </div>
{{ if eq .Template "user" }}
<div class="form-group"> <div class="form-group">
<label for="displayname">Nom:</label> <label for="displayname">Nom:</label>
<input type="text" id="displayname" name="displayname" class="form-control" value="{{ .DisplayName }}" /> <input type="text" id="displayname" name="displayname" class="form-control" value="{{ .DisplayName }}" />
</div> </div>
<input type="hidden" name="description" value="" />
{{ else }}
<div class="form-group">
<label for="description">Description:</label>
<input type="text" id="description" name="description" class="form-control" value="{{ .Description }}" />
</div>
<input type="hidden" name="displayname" value="" />
{{ end }}
<div class="form-group"> <div class="form-group">
<label for="soc">StructuralObjectClass:</label> <label for="soc">StructuralObjectClass:</label>
<input type="text" {{if .IsTemplated}}disabled="disabled"{{end}} id="soc" name="soc" class="form-control" value="{{ .StructuralObjectClass }}" /> <input type="text" {{if .Template}}disabled="disabled"{{end}} id="soc" name="soc" class="form-control" value="{{ .StructuralObjectClass }}" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="oc">ObjectClass:</label> <label for="oc">ObjectClass:</label>
<textarea rows="5" {{if .IsTemplated}}disabled="disabled"{{end}} id="oc" name="oc" class="form-control">{{ .ObjectClass }}</textarea> <textarea rows="5" {{if .Template}}disabled="disabled"{{end}} id="oc" name="oc" class="form-control">{{ .ObjectClass }}</textarea>
</div> </div>
<button type="submit" class="btn btn-primary">Créer l'objet</button> <button type="submit" class="btn btn-primary">Créer l'objet</button>
</form> </form>

View file

@ -22,7 +22,7 @@
{{$group.GetAttributeValue $root.GroupNameAttr}} {{$group.GetAttributeValue $root.GroupNameAttr}}
</a> </a>
</td> </td>
<td>{{$group.GetAttributeValue "displayname"}}</td> <td>{{$group.GetAttributeValue "description"}}</td>
</tr> </tr>
{{end}} {{end}}
{{end}} {{end}}

View file

@ -30,7 +30,7 @@
{{.Identifier}} {{.Identifier}}
</a> </a>
</td> </td>
<td>{{.DisplayName}}</td> <td>{{.Name}}</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>
@ -125,7 +125,7 @@
{{range .Members}} {{range .Members}}
<div class="row mt-4"> <div class="row mt-4">
<div class="col-md-3"> <div class="col-md-3">
<strong>{{.DisplayName}}</strong> <strong>{{.Name}}</strong>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<a href="/admin/ldap/{{.DN}}">{{.DN}}</a> <a href="/admin/ldap/{{.DN}}">{{.DN}}</a>
@ -162,7 +162,7 @@
{{range .Groups}} {{range .Groups}}
<div class="row mt-4"> <div class="row mt-4">
<div class="col-md-3"> <div class="col-md-3">
<strong>{{.DisplayName}}</strong> <strong>{{.Name}}</strong>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<a href="/admin/ldap/{{.DN}}">{{.DN}}</a> <a href="/admin/ldap/{{.DN}}">{{.DN}}</a>