diff --git a/index.js b/index.js index d861013..0b1d96f 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const fastify = require('fastify')({ logger: true }) const fs = require('fs'); const path = require('path') var LdapAuth = require('ldapauth-fork'); +let prompt = require('password-prompt') var prankPath = "prankdata.txt"; if (!fs.existsSync(prankPath)) { @@ -13,17 +14,7 @@ let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy" let UsersToken = {}; let TokenDurationSecond = 3600; -var LDAP = new LdapAuth({ - url: 'ldap://10.5.0.44', - bindDN: 'cn=zammad,ou=service-users,dc=ldap,dc=rezo-rm,dc=fr', - bindCredentials: 'fenfkjnelnfcsqzjkBZKBDZKclZJdzm', - searchBase: 'dc=ldap,dc=rezo-rm,dc=fr', - searchFilter: '(uid={{username}})', - reconnect: true, -}); -LDAP.on('error', function (err) { - console.error('LdapAuth: ', err); -}); +var LDAP; fastify.addContentTypeParser('application/json', { parseAs: 'string' @@ -351,6 +342,17 @@ function makeid(length) { const start = async () => { try { + LDAP = new LdapAuth({ + url: 'ldap://10.5.0.44', + bindDN: 'cn='+ await prompt("LDAP Bind User: ") +',ou=service-users,dc=ldap,dc=rezo-rm,dc=fr', + bindCredentials: await prompt("LDAP Bind Password: "), + searchBase: 'dc=ldap,dc=rezo-rm,dc=fr', + searchFilter: '(uid={{username}})', + reconnect: true, + }); + LDAP.on('error', function (err) { + console.error('LdapAuth: ', err); + }); await fastify.listen({ port: 3000 , host: '127.0.0.1',}) } catch (err) { fastify.log.error(err) diff --git a/package.json b/package.json index 7edcd5b..fe68369 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@fastify/static": "^6.6.0", "fastify": "^4.10.2", - "ldapauth-fork": "^5.0.5" + "ldapauth-fork": "^5.0.5", + "password-prompt": "^1.1.2" } }