Browse Source

Update a lot of thing

pull/1/head
asyncnomi 3 years ago
parent
commit
4bf4e689be
  1. 3
      README.md
  2. 27
      index.js
  3. 4
      ldap-conf.json
  4. 3
      package.json

3
README.md

@ -18,4 +18,5 @@
* move conf: `sudo mv reverse-proxy.conf /etc/nginx/sites-available/` * 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` * 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` * 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`

27
index.js

@ -2,19 +2,29 @@ const fastify = require('fastify')({ logger: true })
const fs = require('fs'); const fs = require('fs');
const path = require('path') const path = require('path')
var LdapAuth = require('ldapauth-fork'); var LdapAuth = require('ldapauth-fork');
let prompt = require('password-prompt')
var prankPath = "prankdata.txt"; var prankPath = "prankdata.txt";
if (!fs.existsSync(prankPath)) { if (!fs.existsSync(prankPath)) {
fs.writeFileSync(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 AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy", "remi", "pierre", "", "", "", ""];
let UsersToken = {}; let UsersToken = {};
let TokenDurationSecond = 3600; 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', { fastify.addContentTypeParser('application/json', {
parseAs: 'string' parseAs: 'string'
@ -342,17 +352,6 @@ function makeid(length) {
const start = async () => { const start = async () => {
try { 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',}) await fastify.listen({ port: 3000 , host: '127.0.0.1',})
} catch (err) { } catch (err) {
fastify.log.error(err) fastify.log.error(err)

4
ldap-conf.json

@ -0,0 +1,4 @@
{
bindUser: "bindUser",
bindPassword: "bindPassword"
}

3
package.json

@ -11,7 +11,6 @@
"dependencies": { "dependencies": {
"@fastify/static": "^6.6.0", "@fastify/static": "^6.6.0",
"fastify": "^4.10.2", "fastify": "^4.10.2",
"ldapauth-fork": "^5.0.5", "ldapauth-fork": "^5.0.5"
"password-prompt": "^1.1.2"
} }
} }

Loading…
Cancel
Save