settings: move externaldap setting
This commit is contained in:
@@ -24,7 +24,6 @@ exports = module.exports = {
|
||||
getServerIpv4,
|
||||
getServerIpv6,
|
||||
getLanguages,
|
||||
syncExternalLdap,
|
||||
syncDnsRecords,
|
||||
getSystemGraphs,
|
||||
getPlatformStatus,
|
||||
@@ -38,7 +37,6 @@ const assert = require('assert'),
|
||||
constants = require('../constants.js'),
|
||||
debug = require('debug')('box:routes/cloudron'),
|
||||
eventlog = require('../eventlog.js'),
|
||||
externalLdap = require('../externalldap.js'),
|
||||
graphs = require('../graphs.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
@@ -311,13 +309,6 @@ async function renewCerts(req, res, next) {
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
}
|
||||
|
||||
async function syncExternalLdap(req, res, next) {
|
||||
const [error, taskId] = await safe(externalLdap.startSyncer());
|
||||
if (error) return next(new HttpError(500, error.message));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
}
|
||||
|
||||
async function getServerIpv4(req, res, next) {
|
||||
const [error, ipv4] = await safe(sysinfo.getServerIPv4());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
46
src/routes/externalldap.js
Normal file
46
src/routes/externalldap.js
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
getConfig,
|
||||
setConfig,
|
||||
sync
|
||||
};
|
||||
|
||||
const assert = require('assert'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
externalLdap = require('../externalldap.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance');
|
||||
|
||||
async function sync(req, res, next) {
|
||||
const [error, taskId] = await safe(externalLdap.startSyncer());
|
||||
if (error) return next(new HttpError(500, error.message));
|
||||
|
||||
next(new HttpSuccess(202, { taskId }));
|
||||
}
|
||||
|
||||
async function getConfig(req, res, next) {
|
||||
const [error, config] = await safe(externalLdap.getConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, externalLdap.removePrivateFields(config)));
|
||||
}
|
||||
|
||||
async function setConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider must be a string'));
|
||||
if ('url' in req.body && typeof req.body.url !== 'string') return next(new HttpError(400, 'url must be a string'));
|
||||
if ('baseDn' in req.body && typeof req.body.baseDn !== 'string') return next(new HttpError(400, 'baseDn must be a string'));
|
||||
if ('usernameField' in req.body && typeof req.body.usernameField !== 'string') return next(new HttpError(400, 'usernameField must be a string'));
|
||||
if ('filter' in req.body && typeof req.body.filter !== 'string') return next(new HttpError(400, 'filter must be a string'));
|
||||
if ('groupBaseDn' in req.body && typeof req.body.groupBaseDn !== 'string') return next(new HttpError(400, 'groupBaseDn must be a string'));
|
||||
if ('bindDn' in req.body && typeof req.body.bindDn !== 'string') return next(new HttpError(400, 'bindDn must be a non empty string'));
|
||||
if ('bindPassword' in req.body && typeof req.body.bindPassword !== 'string') return next(new HttpError(400, 'bindPassword must be a string'));
|
||||
|
||||
const [error] = await safe(externalLdap.setConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
@@ -11,6 +11,7 @@ exports = module.exports = {
|
||||
cloudron: require('./cloudron.js'),
|
||||
domains: require('./domains.js'),
|
||||
eventlog: require('./eventlog.js'),
|
||||
externalLdap: require('./externalldap.js'),
|
||||
filemanager: require('./filemanager.js'),
|
||||
groups: require('./groups.js'),
|
||||
mail: require('./mail.js'),
|
||||
|
||||
@@ -12,7 +12,6 @@ const assert = require('assert'),
|
||||
backups = require('../backups.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
docker = require('../docker.js'),
|
||||
externalLdap = require('../externalldap.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance'),
|
||||
@@ -110,31 +109,6 @@ async function setBackupConfig(req, res, next) {
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getExternalLdapConfig(req, res, next) {
|
||||
const [error, config] = await safe(settings.getExternalLdapConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, externalLdap.removePrivateFields(config)));
|
||||
}
|
||||
|
||||
async function setExternalLdapConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider must be a string'));
|
||||
if ('url' in req.body && typeof req.body.url !== 'string') return next(new HttpError(400, 'url must be a string'));
|
||||
if ('baseDn' in req.body && typeof req.body.baseDn !== 'string') return next(new HttpError(400, 'baseDn must be a string'));
|
||||
if ('usernameField' in req.body && typeof req.body.usernameField !== 'string') return next(new HttpError(400, 'usernameField must be a string'));
|
||||
if ('filter' in req.body && typeof req.body.filter !== 'string') return next(new HttpError(400, 'filter must be a string'));
|
||||
if ('groupBaseDn' in req.body && typeof req.body.groupBaseDn !== 'string') return next(new HttpError(400, 'groupBaseDn must be a string'));
|
||||
if ('bindDn' in req.body && typeof req.body.bindDn !== 'string') return next(new HttpError(400, 'bindDn must be a non empty string'));
|
||||
if ('bindPassword' in req.body && typeof req.body.bindPassword !== 'string') return next(new HttpError(400, 'bindPassword must be a string'));
|
||||
|
||||
const [error] = await safe(settings.setExternalLdapConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
async function getDirectoryServerConfig(req, res, next) {
|
||||
const [error, config] = await safe(settings.getDirectoryServerConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
@@ -278,7 +252,6 @@ function get(req, res, next) {
|
||||
case settings.BACKUP_POLICY_KEY: return getBackupPolicy(req, res, next);
|
||||
case settings.IPV6_CONFIG_KEY: return getIPv6Config(req, res, next);
|
||||
case settings.BACKUP_CONFIG_KEY: return getBackupConfig(req, res, next);
|
||||
case settings.EXTERNAL_LDAP_KEY: return getExternalLdapConfig(req, res, next);
|
||||
case settings.DIRECTORY_SERVER_KEY: return getDirectoryServerConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(req, res, next);
|
||||
@@ -299,7 +272,6 @@ function set(req, res, next) {
|
||||
switch (req.params.setting) {
|
||||
case settings.BACKUP_POLICY_KEY: return setBackupPolicy(req, res, next);
|
||||
case settings.IPV6_CONFIG_KEY: return setIPv6Config(req, res, next);
|
||||
case settings.EXTERNAL_LDAP_KEY: return setExternalLdapConfig(req, res, next);
|
||||
case settings.DIRECTORY_SERVER_KEY: return setDirectoryServerConfig(req, res, next);
|
||||
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
||||
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(req, res, next);
|
||||
|
||||
Reference in New Issue
Block a user