diff --git a/README.md b/README.md index fdea14b..fb5caa7 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,5 @@ * move conf: `sudo mv reverse-proxy.conf /etc/nginx/sites-available/` * Enable site: `sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf` * restart nginx: `sudo systemctl restart nginx` -* Run the server: `pm2 start index.js --name bde-liste -i max` +* edit the ldap-conf file with your LDAP bind user cred. +* Run the server: `pm2 start index.js --name bde-list -i 1` diff --git a/index.js b/index.js index 0b1d96f..b68b217 100644 --- a/index.js +++ b/index.js @@ -2,19 +2,29 @@ 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)) { fs.writeFileSync(prankPath, "{}"); } -let PrankData = JSON.parse(fs.readFileSync("prankdata.txt")); +let PrankData = JSON.parse(fs.readFileSync(prankPath)); let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy", "remi", "pierre", "", "", "", ""]; let UsersToken = {}; let TokenDurationSecond = 3600; -var LDAP; +var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json")); +var LDAP = new LdapAuth({ + url: 'ldap://10.5.0.44', + bindDN: 'cn='+ ldapConf.bindUser +',ou=service-users,dc=ldap,dc=rezo-rm,dc=fr', + bindCredentials: ldapConf.bindPassword, + searchBase: 'dc=ldap,dc=rezo-rm,dc=fr', + searchFilter: '(uid={{username}})', + reconnect: true, +}); +LDAP.on('error', function (err) { + console.error('LdapAuth: ', err); +}); fastify.addContentTypeParser('application/json', { parseAs: 'string' @@ -342,17 +352,6 @@ 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/ldap-conf.json b/ldap-conf.json new file mode 100644 index 0000000..10f9d35 --- /dev/null +++ b/ldap-conf.json @@ -0,0 +1,4 @@ +{ + bindUser: "bindUser", + bindPassword: "bindPassword" +} diff --git a/package.json b/package.json index fe68369..7edcd5b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "dependencies": { "@fastify/static": "^6.6.0", "fastify": "^4.10.2", - "ldapauth-fork": "^5.0.5", - "password-prompt": "^1.1.2" + "ldapauth-fork": "^5.0.5" } }