forked from milux/ctldap
-
Notifications
You must be signed in to change notification settings - Fork 2
/
changeConfig.js
71 lines (59 loc) · 1.96 KB
/
changeConfig.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var fs = require('fs')
, ini = require('ini');
if (((process.argv.length < 3) && (process.argv[2] !== 'list')) || ((process.argv[2] === 'add') && (process.argv.length < 8))) {
console.log('Usage:');
console.log(' node changeConfig.js add <sitename> <uri> <password> <api-user> <api-password> [<comment>]');
console.log(' node changeConfig.js remove <sitename>');
console.log(' node changeConfig.js show <sitename>');
console.log(' node changeConfig.js list');
return;
}
var command = process.argv[2];
var sitename = process.argv[3];
var uri = process.argv[4];
var password = process.argv[5];
var apiUser = process.argv[6];
var apiPassword = process.argv[7];
var comment = process.argv[8];
var config = ini.parse(fs.readFileSync('./ctldap.config', 'utf-8'));
if (command === 'show') {
if (config.sites[sitename]) {
console.log('Site: ' + sitename);
console.log('URI: ' + config.sites[sitename].ct_uri);
console.log('LDAP root passsword: ' + config.sites[sitename].ldap_password);
if (config.sites[sitename].comment) {
console.log('Comment: '+config.sites[sitename].comment);
}
} else {
console.log('No LDAP config for site '+sitename+' .');
}
return;
}
if (command === 'list') {
console.log('Configured LDAP sites:');
Object.keys(config.sites).forEach(function (key) {
console.log(key);
});
return;
}
if (command === 'remove') {
delete config.sites[sitename];
console.log('Deleting config for site '+sitename+' ...');
}
if (command === 'add') {
config.sites[sitename] = {
ldap_password: password,
ct_uri: uri,
api_user: apiUser,
api_password: apiPassword,
comment: comment
};
if (password.substr(0, 4) === '$2y$') {
config.sites[sitename].ldap_password_bcrypt = true;
} else {
delete config.sites[sitename].ldap_password_bcrypt;
}
console.log('Adding config for site '+sitename+' ...');
}
fs.writeFileSync('./ctldap.config', ini.stringify(config));
console.log('ctldap.config updated.');