Browse Source

Detect admin users

merge-requests/1/head
meskio 5 years ago
parent
commit
7a4e311b78
  1. 3
      README.md
  2. 26
      examples/data.ldif
  3. 10
      server/server.go
  4. 10
      tmpl/index.html

3
README.md

@ -13,3 +13,6 @@ make all
Now go to your browser, open http://localhost:8080 and you can login as:
* Usuaria: user
* Contraseña: foobar
Or as admin:
* Usuaria: superuser
* Contraseña: foobar

26
examples/data.ldif

@ -23,3 +23,29 @@ uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/sindominio/user
gecos: User,,,,Madrid
dn: uid=superuser,ou=People,dc=nodomain
uid: superuser
cn: SuperUser
objectClass: account
objectClass: posixAccount
userPassword: {SSHA}FHqod3gytvH9MDGhpMV1DKjyU7eO1EDG
loginShell: /bin/bash
uidNumber: 1000
gidNumber: 1000
homeDirectory: /home/sindominio/superuser
gecos: SuperUser,,,,Calanda
dn: ou=Group,dc=nodomain
objectClass: top
objectClass: organizationalUnit
ou: Group
structuralObjectClass: organizationalUnit
dn: cn=adm,ou=Group,dc=nodomain
objectClass: top
objectClass: posixGroup
cn: adm
gidNumber: 1
structuralObjectClass: posixGroup
memberUid: superuser

10
server/server.go

@ -46,7 +46,11 @@ func (s *server) homeHandler(w http.ResponseWriter, r *http.Request) {
if session == nil {
tmpl.ExecuteTemplate(w, "login.html", false)
} else {
tmpl.ExecuteTemplate(w, "index.html", session.user)
data := struct {
User string
Admin bool
}{session.user, s.isAdmin(session.user)}
tmpl.ExecuteTemplate(w, "index.html", data)
}
}
@ -96,3 +100,7 @@ func (s *server) passwordHandler(w http.ResponseWriter, r *http.Request) {
tmpl.ExecuteTemplate(w, "password.html", "PassChanged")
}
}
func (s *server) isAdmin(user string) bool {
return s.ldap.InGroup(user, "adm")
}

10
tmpl/index.html

@ -4,8 +4,16 @@
<div class="container">
<br />
<div class="row justify-content-center">
<h1 class="col-4">Hola {{.}}!!</h1>
<h1 class="col-4">Hola {{.User}}!!</h1>
</div>
{{if .Admin}}
<br />
<div class="row justify-content-center">
<p>Parece que eres una admin.<br />
<br />
<em>Un gran poder conlleva una gran responsabilidad</em></p>
</div>
{{end}}
</div>
{{template "footer.html"}}

Loading…
Cancel
Save