Flesh out Cobalt, LDAP groups, &c.

This commit is contained in:
garrettmills
2020-05-11 20:26:09 -05:00
parent c389e151b5
commit 6f621f5891
34 changed files with 1508 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
const Unit = require('libflitter/Unit')
const LDAP = require('ldapjs')
const Validator = require('email-validator')
const net = require('net')
// TODO support logging ALL ldap requests when in DEBUG, not just routed ones
// TODO need to support LDAP server auto-discovery/detection features
@@ -89,11 +90,27 @@ class LDAPServerUnit extends Unit {
}
this.output.info(`Will listen on ${this.config.interface}:${this.config.port}`)
await new Promise((res, rej) => {
this.server.listen(this.config.port, this.config.interface, () => {
this.output.success(`LDAP server listening on port ${this.config.port}...`)
if ( await this.port_free() ) {
await new Promise((res, rej) => {
this.server.listen(this.config.port, this.config.interface, (err) => {
this.output.success(`LDAP server listening on port ${this.config.port}...`)
res()
})
})
} else {
this.output.error(`LDAP server port ${this.config.port} is not available. The LDAP server was not started.`)
}
}
async port_free() {
return new Promise((res, rej) => {
const server = net.createServer()
server.once('error', rej)
server.once('listening', () => {
server.close()
res()
})
server.listen(this.config.port)
})
}