45 lines
1.4 KiB
CoffeeScript
45 lines
1.4 KiB
CoffeeScript
ldap = require('ldapjs')
|
|
|
|
userTable = {}
|
|
|
|
window.onload = ->
|
|
document.getElementById('ldapHost').textContent = localStorage.getItem('ldap_hostname')
|
|
userTable = document.getElementById('ldapUserList')
|
|
ldapGetUserList()
|
|
return
|
|
|
|
searchOpts =
|
|
filter: '(objectClass=posixAccount)'
|
|
scope: 'sub'
|
|
attributes: ['uid', 'displayName', 'mail']
|
|
|
|
ldapGetUserList = () ->
|
|
client = ldap.createClient(url: 'ldap://' + localStorage.getItem('ldap_hostname') + '/')
|
|
client.bind(localStorage.getItem('ldap_bind_dn'), localStorage.getItem('ldap_bind_pw'), (err) ->
|
|
if err
|
|
document.querySelector('h1').textContent = 'error'
|
|
return
|
|
else
|
|
client.search('ou=People,' + localStorage.getItem('ldap_base_dn'), searchOpts, (err, res) ->
|
|
if err
|
|
console.log(err)
|
|
return
|
|
else
|
|
res.on('searchEntry', (entry) ->
|
|
userEntry = document.createElement('tr')
|
|
|
|
userUid = document.createElement('td')
|
|
userUid.innerText = entry.object.uid
|
|
userEntry.appendChild(userUid)
|
|
userName = document.createElement('td')
|
|
userName.innerText = entry.object.displayName
|
|
userEntry.appendChild(userName)
|
|
userMail = document.createElement('td')
|
|
userMail.innerText = entry.object.mail
|
|
userEntry.appendChild(userMail)
|
|
|
|
userTable.appendChild(userEntry)
|
|
)
|
|
)
|
|
)
|