package main
import (
"bytes"
"encoding/base64"
"fmt"
"html/template"
"log"
"net/http"
"regexp"
"strings"
"gopkg.in/ldap.v2"
)
const (
host = "ldap.example.com"
port = 389
topDn = "dc=example,dc=com"
)
var (
fieldsRegExp = regexp.MustCompile(`[^\s,]+`)
templates = template.New("").Funcs(template.FuncMap(map[string]interface{}{
"attribute": func(a *ldap.EntryAttribute) template.HTML {
h := make([]string, len(a.Values))
switch a.Name {
case "labeledURI":
for i, v := range a.Values {
pair := strings.SplitN(v, " ", 2)
h[i] = fmt.Sprintf(
"%s",
template.HTMLEscapeString(pair[0]),
template.HTMLEscapeString(pair[1]))
}
case "mail":
for i, v := range a.Values {
h[i] = fmt.Sprintf(
"%s",
template.HTMLEscapeString(v),
template.HTMLEscapeString(v))
}
case "jpegPhoto":
for i, v := range a.ByteValues {
h[i] = fmt.Sprintf(
"",
template.HTMLEscapeString(
base64.StdEncoding.EncodeToString(
v)))
}
case "roleOccupant":
for i, v := range a.Values {
h[i] = fmt.Sprintf(
`%s`,
template.HTMLEscapeString(v),
template.HTMLEscapeString(v))
}
default:
for i, v := range a.Values {
h[i] = template.HTMLEscapeString(v)
}
}
return template.HTML(strings.Join(h, "
"))
},
}))
searchResultsTemplate = template.Must(templates.Parse(`
{{.Name}} | {{attribute .}} |