-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentries.js
More file actions
36 lines (28 loc) · 874 Bytes
/
entries.js
File metadata and controls
36 lines (28 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var ldap = require('ldapjs');
var http = require('http');
var fs = require('fs');
var conf = JSON.parse(
fs.readFileSync('config.json', 'utf8')
);
http.createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': conf.origin
});
var client = ldap.createClient(conf.connection);
var result =[];
client.search(conf.base, conf.searchOptions, function(err, response) {
response.on('searchEntry', function(entry) {
result.push(entry.object.displayName);
});
response.on('error', function(err) {
console.error('error: ' + err.message);
});
response.on('end', function(response) {
result.sort();
res.write(JSON.stringify(result));
res.end();
});
});
}).listen(conf.port);
console.log('Server running port ' + conf.port.toString() + '\n');