-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·67 lines (52 loc) · 1.75 KB
/
server.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
var user_store_json = require('musterroll-userstore-json');
var musterroll_ldap = require('musterroll-ldap');
var musterroll_api = require('musterroll-api');
var http = require('http');
var express = require('express');
var request = require('request');
var argv = require('minimist')(process.argv.slice(2));
var ejs = require('ejs');
var fs = require('fs');
var userStoragePath = argv["user-storage-path"] || "/opt/cloudfleet/data";
var userStore = user_store_json.createUserStore({config_file_location: userStoragePath});
var domain = argv["domain"] || "example.com";
var testing_mode = argv["testing"] == "true";
var port_offset = testing_mode ? 1000 : 0;
var skip_message_bus = testing_mode;
if(testing_mode){
console.log("Starting in TESTING mode");
}
console.log("Starting LDAP server with base domain " + domain);
var ldapServer = musterroll_ldap.createServer(
{
userStore: userStore,
rootDN: domain.split(".").map(function(part){return "dc=" + part;}).join(", "),
domain: domain
}
);
try{
ldapServer.listen(389 + port_offset, function() {
console.log('LDAP server listening at ' + ldapServer.url);
});
}
catch(error)
{
console.log(error);
}
var webServer = musterroll_api.createServer({
userStore: userStore,
user_store_initializer: function(username, password, userStore, callback, error_callback){
var user = {
"id":username,
"isAdmin":true
};
userStore.updateUser(user);
userStore.setPassword(user["id"], password);
callback(user);
}
});
webServer.use("/", express.static(__dirname + '/public'));
webServer.listen(80 + port_offset, function(){
"use strict";
console.log('API server listening on port ' + (80 + port_offset));
});