
Telephone Directory
Telephone Directory for Active Directory

For those who do not want to read the article, immediately the repository on github .
And the rest under the cat is waiting for an incoherent and meaningless story about how I
All my
And away we go ... I began to integrate everything I can reach with AD. Authentication of proxies, database of employees for ACS, Antivirus, etc. And I did not have enough for the happiness of a telephone directory, which would take all the data from the AD database. For six months now I have been tormenting Google on this topic, but the results are not comforting.
Basic requirements for such a directory:
- separate portable application. Every time I stumbled upon a web-based directory, I thought, “If you raise a server for this, then I’ll already make a full-fledged corporate portal, and now I just need a small directory.
- free
- The most simple and convenient to use. It always seemed to me just a table with sorting and searching
From the entire zoo of such software that I found, there are several types:
- Bulky : Any corporate portals jomportal , onlyoffice ...
- Paid : In principle, what is needed from dovestones , from ithicos ...
- Having a fatal flaw : from gourami (dumb, it did not start, also fremium), from dmtsoft (one of the best, about its shortcomings a little lower.), Or a thousand all kinds of VB scripts generating an HTML file.
Concerning the reference from dmsoft
It looks like this

And there is no way at least to make the column width of the phone larger by default. And setting up the interface every time you start is terribly annoying.

And there is no way at least to make the column width of the phone larger by default. And setting up the interface every time you start is terribly annoying.
Nothing boded the

Ability to write a desktop application in a familiar language - what could be better? My joy knew no bounds.
But bad luck ... At home, a small child, constantly requiring attention, and at work, suddenly work. There is no time and place to code categorically.
But fate was favorable to me - on Sunday afternoon the child decided to sleep . The wife, apparently recalling my enthusiastic cries about how node-webkit is cool, and unraveling my secret desires, in response to the question “what do we do while the baby is sleeping?”

Answered “okay ... go already program”
Episode 1: Prototype March
So. I have 1.5 - 2 hours to learn the new technology (even two, since nodejs I also didn’t, in fact) and write software with it that for some reason none of the open source programmers have written yet .
First of all, Google asked about the connection of nodejs with ActiveDirectory. He suggested two modules: node-activedirectory and ldapjs . Understand that by what time was not, so the choice fell on the first.
THE CODE
By the way about
var ActiveDirectory = require('activedirectory');
var ad = new ActiveDirectory('ldap://example.com', 'dc=example,dc=com', 'superadmin', 'pass');
var groupName = 'Employees';
ad.getUsersForGroup(groupName, function(err, users) {
if (err) {
console.log('ERROR: ' +JSON.stringify(err));
return;
}
if (! users) console.log('Group: ' + groupName + ' not found.');
else {
console.log(users);
}
});
By the way about
var groupName = 'Employees';
EMPLOYEES - a group which includes all current employeesRESULT
ERROR: {"dn":"","code":49,"name":"InvalidCredentialsError","message":"80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db0\u0000"}
hmm ....An attempt to poke the second module led to the same result, but for a longer time. Mana smoking, kicking of the familiar nodejs nickname and crazy luck did give the result: for some reason, the domain’s superadmin is not authenticated, but the disenfranchised user created for the guest Internet has worked !
HURRAH
There is no time for legal proceedings - we went further.
- git init
- License
- dirty hack for debugging
require('nw.gui').Window.get().showDevTools();
- copy-paste of old code
Voila
You can start doing magic ... But almost an hour has passed. The baby can wake up at any moment. There is no time for magic - we take everything ready.
Quick googling turned out to be an excellent script for working with the TinyTable table . I copy it entirely with an example to myself.
Bit of code
var ad = new ActiveDirectory(credentials.dn, credentials.dc, credentials.user, credentials.pass, {attributes: {user: [ 'cn', 'telephonenumber', 'mail' ]}}); // поменял эту строчку что бы доставало только ФИО телефон и мыло
function users2table (users) {
tablehtml = '';
for (i in users) {
var user = users[i];
console.log(user);
tablehtml+='';
tablehtml+= ''+user.cn+''
tablehtml+= ''+user.telephoneNumber+''
tablehtml+= ''+user.mail+''
tablehtml+=''
}
console.log(tablehtml);
$('#table tbody').html(tablehtml);
sorter.init();
}
THEREThere was a joyful cry from the crib.
Episode 2: Morning Coffee
At 6:50 , I have about 20 minutes ...
- We remove the address bar and call the windowpackage.json
"window": { "title": "Telephone Directory", "toolbar": false }
- Autofocus on the search fieldusers2table
$('#query').focus();
- add the department to the table, or rather, we’ll take away not just anything, but only the name, phone, email, departmentHidden text
var ad = new ActiveDirectory(credentials.dn, credentials.dc, credentials.user, credentials.pass, {attributes: {user: [ 'cn', 'telephonenumber', 'mail', 'department']}});
tablehtml+= ''+user.department+''
- And open the window to full screen, so as not to bathe about the sizeHidden text
require('nw.gui').Window.get().maximize();
Already quite goodBut it’s already 7:30 and I have to run.
Episode 3: We Drive
During lunch, I returned to the code.
First of all, I added a feature that I was thinking about all the way to work - caching. For every time you wait for a download (albeit just a few seconds) looking at an empty window is annoying.
THE CODE
in the event of receiving a response from ldap changed this:
and also added to empty space in the script a load with localstorage if not empty
users2table(users);
on this: var localusers = localStorage.users;
var ldapusers = JSON.stringify(users);
if (localusers != ldapusers) {localStorage.users = JSON.stringify(users)} else {console.log('users didn\'t changed')};
users2table(JSON.parse(localStorage.users));
and also added to empty space in the script a load with localstorage if not empty
if (localStorage.users) users2table(JSON.parse(localStorage.users));
I fixed a couple of bugs, combed it, added mailto links for emails ... Basically everything.
DONE!Just lunch has ended.
But this functionality already fully covers all my plans, so for now I have stopped.
Installation
- put node-webkit
- download release
- put the private.js filecontent
module.exports = { dn:"ldap://example.com" ,dc:"dc=example,dc=com" ,user:"user" ,pass:"pass" };
- launch
path\to\nodewebkit\nw.exe path\to\telephone-directory
Spread
- Pack the telephone-directory in .zip
- Rename the archive to .nw
- Some magic
copy /b path\to\nodewebkit\nw.exe+path\to\telephone-directory telephone-directory.exe
- Dock all other files from node-webkit except nw.exe to the directory with telephone-directory.exe
It should turn out like this:

Everything - you can upload it to a network drive or distribute as you please