consolidate package and config import,

fix ldap auth template,
add start script and systemd service
This commit is contained in:
Arthur Lu 2024-01-11 00:07:35 +00:00
parent 8edfbe1ace
commit c0fc119dc2
7 changed files with 28 additions and 28 deletions

0
README.md Normal file
View File

View File

@ -9,7 +9,7 @@ olcAccess: {0}to attrs=userPassword
by self write
by anonymous auth
by * none
olcAccess: {1}to attrs=shadowLastChange
olcAccess: {1}to attrs=shadowLastChange,cn,sn
by self write
by * read
olcAccess: {2}to dn.subtree="$BASE_DN"

View 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

View File

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

View File

@ -3,24 +3,21 @@ import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import morgan from "morgan";
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 * as utils from "./utils.js"
import LDAP from "./ldap.js";
global.argv = parseArgs(process.argv.slice(2), {
default: {
package: "package.json",
listenPort: 8082,
ldapURL: "ldap://localhost",
configPath: "config/config.json"
config: "config/config.json"
}
});
global.package = _package(global.argv.package);
global.config = _config(global.argv.configPath);
global.utils = utils;
global.package = global.utils.readJSONFile(global.argv.package);
global.config = global.utils.readJSONFile(global.argv.config);
const LDAPSessions = {};
@ -36,8 +33,8 @@ app.use(session({
saveUninitialized: true
}));
app.listen(global.argv.listenPort, () => {
console.log(`proxmoxaas-api v${global.package.version} listening on port ${global.argv.listenPort}`);
app.listen(global.config.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,
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);
if (bindResult.ok) {
LDAPSessions[req.session.id] = newLDAPSession;

View File

@ -1,11 +1,12 @@
import { readFileSync } from "fs";
import { exit } from "process";
export default (path) => {
export function readJSONFile (path) {
try {
return JSON.parse(readFileSync(path));
}
catch (e) {
console.log(`Error: ${path} was not found.`);
console.log(`error: ${path} was not found.`);
exit(1);
}
};

2
start.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
node .