Update a lot of thing

This commit is contained in:
asyncnomi 2022-12-11 18:59:41 +01:00
parent bd5b5b224d
commit 4bf4e689be
4 changed files with 20 additions and 17 deletions

View file

@ -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`

View file

@ -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)

4
ldap-conf.json Normal file
View file

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

View file

@ -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"
}
}