diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/openldap/auth.template.ldif b/openldap/auth.template.ldif index 7f388b7..9eab252 100644 --- a/openldap/auth.template.ldif +++ b/openldap/auth.template.ldif @@ -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" diff --git a/service/proxmoxaas-ldap.service b/service/proxmoxaas-ldap.service new file mode 100644 index 0000000..d875bd0 --- /dev/null +++ b/service/proxmoxaas-ldap.service @@ -0,0 +1,11 @@ +[Unit] +Description=proxmoxaas-ldap +After=network.target +[Service] +WorkingDirectory=//ProxmoxAAS-LDAP/ +ExecStart=//ProxmoxAAS-LDAP/start.sh +Restart=always +RestartSec=10 +Type=simple +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/src/config.js b/src/config.js deleted file mode 100644 index d9158a1..0000000 --- a/src/config.js +++ /dev/null @@ -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); - } -}; diff --git a/src/main.js b/src/main.js index fe719d2..6029b07 100644 --- a/src/main.js +++ b/src/main.js @@ -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; diff --git a/src/package.js b/src/utils.js similarity index 61% rename from src/package.js rename to src/utils.js index fa00582..bf5173b 100644 --- a/src/package.js +++ b/src/utils.js @@ -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); } -}; +}; \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..c224329 --- /dev/null +++ b/start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +node . \ No newline at end of file