consolidate package and config import,
fix ldap auth template, add start script and systemd service
This commit is contained in:
parent
8edfbe1ace
commit
c0fc119dc2
@ -9,7 +9,7 @@ olcAccess: {0}to attrs=userPassword
|
|||||||
by self write
|
by self write
|
||||||
by anonymous auth
|
by anonymous auth
|
||||||
by * none
|
by * none
|
||||||
olcAccess: {1}to attrs=shadowLastChange
|
olcAccess: {1}to attrs=shadowLastChange,cn,sn
|
||||||
by self write
|
by self write
|
||||||
by * read
|
by * read
|
||||||
olcAccess: {2}to dn.subtree="$BASE_DN"
|
olcAccess: {2}to dn.subtree="$BASE_DN"
|
||||||
|
11
service/proxmoxaas-ldap.service
Normal file
11
service/proxmoxaas-ldap.service
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=proxmoxaas-ldap
|
||||||
|
After=network.target
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/<path to dir>/ProxmoxAAS-LDAP/
|
||||||
|
ExecStart=/<path to dir>/ProxmoxAAS-LDAP/start.sh
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
Type=simple
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
@ -1,11 +0,0 @@
|
|||||||
import { readFileSync } from "fs";
|
|
||||||
import { exit } from "process";
|
|
||||||
export default () => {
|
|
||||||
try {
|
|
||||||
return JSON.parse(readFileSync(global.argv.configPath));
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.log(`Error: ${global.argv.configPath} was not found. Please follow the directions in the README to initialize localdb.json.`);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
23
src/main.js
23
src/main.js
@ -3,24 +3,21 @@ import bodyParser from "body-parser";
|
|||||||
import cookieParser from "cookie-parser";
|
import cookieParser from "cookie-parser";
|
||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import session from "express-session";
|
import session from "express-session";
|
||||||
|
|
||||||
import LDAP from "./ldap.js";
|
|
||||||
import _config from "./config.js";
|
|
||||||
import _package from "./package.js";
|
|
||||||
|
|
||||||
import parseArgs from "minimist";
|
import parseArgs from "minimist";
|
||||||
|
|
||||||
|
import * as utils from "./utils.js"
|
||||||
|
import LDAP from "./ldap.js";
|
||||||
|
|
||||||
global.argv = parseArgs(process.argv.slice(2), {
|
global.argv = parseArgs(process.argv.slice(2), {
|
||||||
default: {
|
default: {
|
||||||
package: "package.json",
|
package: "package.json",
|
||||||
listenPort: 8082,
|
config: "config/config.json"
|
||||||
ldapURL: "ldap://localhost",
|
|
||||||
configPath: "config/config.json"
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
global.package = _package(global.argv.package);
|
global.utils = utils;
|
||||||
global.config = _config(global.argv.configPath);
|
global.package = global.utils.readJSONFile(global.argv.package);
|
||||||
|
global.config = global.utils.readJSONFile(global.argv.config);
|
||||||
|
|
||||||
const LDAPSessions = {};
|
const LDAPSessions = {};
|
||||||
|
|
||||||
@ -36,8 +33,8 @@ app.use(session({
|
|||||||
saveUninitialized: true
|
saveUninitialized: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.listen(global.argv.listenPort, () => {
|
app.listen(global.config.listenPort, () => {
|
||||||
console.log(`proxmoxaas-api v${global.package.version} listening on port ${global.argv.listenPort}`);
|
console.log(`proxmoxaas-ldap v${global.package.version} listening on port ${global.config.listenPort}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +63,7 @@ app.post("/ticket", async (req, res) => {
|
|||||||
uid: req.body.uid,
|
uid: req.body.uid,
|
||||||
password: req.body.password
|
password: req.body.password
|
||||||
};
|
};
|
||||||
const newLDAPSession = new LDAP(global.argv.ldapURL, global.config.basedn);
|
const newLDAPSession = new LDAP(global.config.ldapURL, global.config.basedn);
|
||||||
const bindResult = await newLDAPSession.bindUser(params.uid, params.password);
|
const bindResult = await newLDAPSession.bindUser(params.uid, params.password);
|
||||||
if (bindResult.ok) {
|
if (bindResult.ok) {
|
||||||
LDAPSessions[req.session.id] = newLDAPSession;
|
LDAPSessions[req.session.id] = newLDAPSession;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { exit } from "process";
|
import { exit } from "process";
|
||||||
export default (path) => {
|
|
||||||
|
export function readJSONFile (path) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(readFileSync(path));
|
return JSON.parse(readFileSync(path));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.log(`Error: ${path} was not found.`);
|
console.log(`error: ${path} was not found.`);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user