Add last login info to the user record

merge-requests/6/head
meskio 5 years ago
parent 8ba4cc65d2
commit 1abb3c1905
Signed by: meskio
GPG Key ID: 52B8F5AC97A2DA86
  1. 38
      ldap/user.go
  2. 1
      tmpl/user.html
  3. 2
      tmpl/users.html

@ -5,19 +5,23 @@ import (
"fmt"
"log"
"strconv"
"time"
"github.com/go-ldap/ldap"
)
var searchAttributes = []string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory", "mail", "authTimestamp"}
//User has the ldap data of the user
type User struct {
DN string
Name string
Shell string
Home string
Mail string
UID int
GID int
DN string
Name string
Shell string
Home string
Mail string
UID int
GID int
LastLogin time.Time
}
// ValidateUser in the ldap
@ -91,7 +95,7 @@ func (l Ldap) ListUsers() ([]User, error) {
"ou=people,"+l.DC,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
"(&(objectClass=posixAccount))",
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory", "mail"},
searchAttributes,
nil,
)
sr, err := conn.Search(searchRequest)
@ -191,7 +195,7 @@ func (l Ldap) searchUser(user string, conn *ldap.Conn) (entry *ldap.Entry, err e
"ou=people,"+l.DC,
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=posixAccount)(uid=%s))", ldap.EscapeFilter(user)),
[]string{"dn", "uid", "uidNumber", "gidNumber", "loginShell", "homeDirectory", "mail"},
searchAttributes,
nil,
)
sr, err := conn.Search(searchRequest)
@ -213,13 +217,15 @@ func (l Ldap) searchUser(user string, conn *ldap.Conn) (entry *ldap.Entry, err e
func newUser(entry *ldap.Entry) User {
uid, _ := strconv.Atoi(entry.GetAttributeValue("uidNumber"))
gid, _ := strconv.Atoi(entry.GetAttributeValue("gidNumber"))
lastLogin, _ := time.Parse("20060102150405Z", entry.GetAttributeValue("authTimestamp"))
return User{
DN: entry.DN,
Name: entry.GetAttributeValue("uid"),
Shell: entry.GetAttributeValue("loginShell"),
Home: entry.GetAttributeValue("homeDirectory"),
Mail: entry.GetAttributeValue("mail"),
UID: uid,
GID: gid,
DN: entry.DN,
Name: entry.GetAttributeValue("uid"),
Shell: entry.GetAttributeValue("loginShell"),
Home: entry.GetAttributeValue("homeDirectory"),
Mail: entry.GetAttributeValue("mail"),
UID: uid,
GID: gid,
LastLogin: lastLogin,
}
}

@ -16,6 +16,7 @@
{{end}}
</dd>
{{end}}
<dt>Ultimo login</dt><dd>{{.User.LastLogin}}</dd>
<dt>UID</dt><dd>{{.User.UID}}</dd>
{{with .MainGroup}}
<dt>GID</dt><dd><a href="/groups/{{.Name}}">{{.Name}} ({{.GID}})</a></dd>

@ -8,6 +8,7 @@
<th scope="col">Shell</th>
<th scope="col">Home</th>
<th scope="col">Mail</th>
<th scope="col">Login</th>
<th scope="col">UID</th>
<th scope="col">GID</th>
</tr>
@ -19,6 +20,7 @@
<td>{{.Shell}}</td>
<td>{{.Home}}</td>
<td>{{.Mail}}</td>
<td>{{.LastLogin}}</td>
<td>{{.UID}}</td>
<td>{{.GID}}</td>
</tr>

Loading…
Cancel
Save