2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2020-03-18 17:13:41 -07:00
|
|
|
set,
|
|
|
|
|
get,
|
|
|
|
|
|
|
|
|
|
// owner only settings
|
2022-01-13 14:34:02 -08:00
|
|
|
setBackupConfig,
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2021-05-14 15:07:29 -07:00
|
|
|
const assert = require('assert'),
|
2019-02-09 18:08:10 -08:00
|
|
|
backups = require('../backups.js'),
|
2019-10-25 15:58:11 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
2018-10-12 17:04:04 -07:00
|
|
|
docker = require('../docker.js'),
|
2019-10-25 15:58:11 -07:00
|
|
|
externalLdap = require('../externalldap.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
|
|
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
2021-08-18 15:40:28 -07:00
|
|
|
safe = require('safetydance'),
|
2019-10-22 11:03:56 -07:00
|
|
|
settings = require('../settings.js');
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getAutoupdatePattern(req, res, next) {
|
|
|
|
|
const [error, pattern] = await safe(settings.getAutoupdatePattern());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2018-02-06 18:57:30 +01:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, { pattern }));
|
2018-02-06 18:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setAutoupdatePattern(req, res, next) {
|
2018-02-06 18:57:30 +01:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.pattern !== 'string') return next(new HttpError(400, 'pattern is required'));
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setAutoupdatePattern(req.body.pattern));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getTimeZone(req, res, next) {
|
|
|
|
|
const [error, timeZone] = await safe(settings.getTimeZone());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2016-06-02 13:00:23 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, { timeZone }));
|
2016-05-03 12:10:16 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setTimeZone(req, res, next) {
|
2016-06-02 13:36:47 -07:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.timeZone !== 'string') return next(new HttpError(400, 'timeZone is required'));
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setTimeZone(req.body.timeZone));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2016-06-02 13:36:47 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2016-06-02 13:36:47 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-18 15:54:53 -07:00
|
|
|
async function getSupportConfig(req, res, next) {
|
2021-08-23 17:47:58 +02:00
|
|
|
const [error, supportConfig] = await safe(settings.getSupportConfig());
|
2021-08-18 15:54:53 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2020-02-05 14:30:56 -08:00
|
|
|
|
2021-08-18 15:54:53 -07:00
|
|
|
next(new HttpSuccess(200, supportConfig));
|
2020-02-05 14:30:56 -08:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getBackupConfig(req, res, next) {
|
|
|
|
|
const [error, backupConfig] = await safe(settings.getBackupConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2015-11-09 20:34:25 -08:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, backups.removePrivateFields(backupConfig)));
|
2015-11-09 20:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setBackupConfig(req, res, next) {
|
2015-11-09 20:34:25 -08:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
2020-07-28 16:19:44 -07:00
|
|
|
if (typeof req.body.schedulePattern !== 'string') return next(new HttpError(400, 'schedulePattern is required'));
|
2022-06-27 09:17:01 -07:00
|
|
|
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be a string'));
|
|
|
|
|
if ('encryptedFilenames' in req.body && typeof req.body.encryptedFilenames !== 'boolean') return next(new HttpError(400, 'encryptedFilenames must be a boolean'));
|
2022-06-26 09:28:21 -07:00
|
|
|
|
2018-03-20 19:18:48 -07:00
|
|
|
if ('syncConcurrency' in req.body) {
|
|
|
|
|
if (typeof req.body.syncConcurrency !== 'number') return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
|
|
|
|
if (req.body.syncConcurrency < 1) return next(new HttpError(400, 'syncConcurrency must be a positive integer'));
|
|
|
|
|
}
|
2020-08-10 21:59:00 -07:00
|
|
|
if ('copyConcurrency' in req.body) {
|
|
|
|
|
if (typeof req.body.copyConcurrency !== 'number') return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
|
|
|
|
if (req.body.copyConcurrency < 1) return next(new HttpError(400, 'copyConcurrency must be a positive integer'));
|
|
|
|
|
}
|
|
|
|
|
if ('downloadConcurrency' in req.body) {
|
|
|
|
|
if (typeof req.body.downloadConcurrency !== 'number') return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
|
|
|
|
if (req.body.downloadConcurrency < 1) return next(new HttpError(400, 'downloadConcurrency must be a positive integer'));
|
|
|
|
|
}
|
2020-08-11 09:14:09 -07:00
|
|
|
if ('deleteConcurrency' in req.body) {
|
|
|
|
|
if (typeof req.body.deleteConcurrency !== 'number') return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
|
|
|
|
if (req.body.deleteConcurrency < 1) return next(new HttpError(400, 'deleteConcurrency must be a positive integer'));
|
|
|
|
|
}
|
2020-08-19 14:38:59 -07:00
|
|
|
if ('uploadPartSize' in req.body) {
|
|
|
|
|
if (typeof req.body.uploadPartSize !== 'number') return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
|
|
|
|
if (req.body.uploadPartSize < 1) return next(new HttpError(400, 'uploadPartSize must be a positive integer'));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 21:59:00 -07:00
|
|
|
if ('memoryLimit' in req.body && typeof req.body.memoryLimit !== 'number') return next(new HttpError(400, 'memoryLimit must be a positive integer'));
|
2017-09-25 23:49:49 -07:00
|
|
|
if (typeof req.body.format !== 'string') return next(new HttpError(400, 'format must be a string'));
|
2017-10-05 10:01:09 -07:00
|
|
|
if ('acceptSelfSignedCerts' in req.body && typeof req.body.acceptSelfSignedCerts !== 'boolean') return next(new HttpError(400, 'format must be a boolean'));
|
2015-11-09 20:34:25 -08:00
|
|
|
|
2020-05-28 19:50:23 +02:00
|
|
|
if (!req.body.retentionPolicy || typeof req.body.retentionPolicy !== 'object') return next(new HttpError(400, 'retentionPolicy is required'));
|
2020-05-14 16:19:35 -07:00
|
|
|
|
2021-05-14 15:07:29 -07:00
|
|
|
if ('mountOptions' in req.body && typeof req.body.mountOptions !== 'object') return next(new HttpError(400, 'mountOptions must be a object'));
|
|
|
|
|
|
2018-08-05 22:29:27 -07:00
|
|
|
// testing the backup using put/del takes a bit of time at times
|
|
|
|
|
req.clearTimeout();
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setBackupConfig(req.body));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2015-11-09 20:34:25 -08:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2015-11-09 20:34:25 -08:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getExternalLdapConfig(req, res, next) {
|
|
|
|
|
const [error, config] = await safe(settings.getExternalLdapConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-08-29 12:25:10 +02:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, externalLdap.removePrivateFields(config)));
|
2019-08-29 12:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setExternalLdapConfig(req, res, next) {
|
2019-08-29 12:25:10 +02:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
2019-10-25 15:40:22 -07:00
|
|
|
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider must be a string'));
|
2019-10-25 15:47:55 -07:00
|
|
|
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'));
|
2020-06-03 21:23:53 +02:00
|
|
|
if ('groupBaseDn' in req.body && typeof req.body.groupBaseDn !== 'string') return next(new HttpError(400, 'groupBaseDn must be a string'));
|
2019-10-25 15:47:55 -07:00
|
|
|
if ('bindDn' in req.body && typeof req.body.bindDn !== 'string') return next(new HttpError(400, 'bindDn must be a non empty string'));
|
2019-08-29 12:25:10 +02:00
|
|
|
if ('bindPassword' in req.body && typeof req.body.bindPassword !== 'string') return next(new HttpError(400, 'bindPassword must be a string'));
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setExternalLdapConfig(req.body));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-08-29 12:25:10 +02:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2019-08-29 12:25:10 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-15 19:14:02 +02:00
|
|
|
async function getDirectoryServerConfig(req, res, next) {
|
|
|
|
|
const [error, config] = await safe(settings.getDirectoryServerConfig());
|
2021-11-23 18:00:07 +01:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 19:14:02 +02:00
|
|
|
async function setDirectoryServerConfig(req, res, next) {
|
2021-11-23 18:00:07 +01:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled must be a boolean'));
|
2022-01-05 14:35:48 +01:00
|
|
|
if (typeof req.body.secret !== 'string') return next(new HttpError(400, 'secret must be a string'));
|
2021-11-26 10:43:50 +01:00
|
|
|
if ('allowlist' in req.body && typeof req.body.allowlist !== 'string') return next(new HttpError(400, 'allowlist must be a string'));
|
2021-11-23 18:00:07 +01:00
|
|
|
|
2022-08-15 19:14:02 +02:00
|
|
|
const [error] = await safe(settings.setDirectoryServerConfig(req.body));
|
2021-11-23 18:00:07 +01:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, {}));
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getDynamicDnsConfig(req, res, next) {
|
|
|
|
|
const [error, enabled] = await safe(settings.getDynamicDnsConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2018-10-31 16:02:51 +01:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, { enabled }));
|
2018-10-31 16:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setDynamicDnsConfig(req, res, next) {
|
2018-10-31 16:02:51 +01:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled boolean is required'));
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setDynamicDnsConfig(req.body.enabled));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2018-10-31 16:02:51 +01:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2018-10-31 16:02:51 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-06 21:42:00 -08:00
|
|
|
async function getIPv6Config(req, res, next) {
|
2022-02-15 13:16:37 -08:00
|
|
|
const [error, ipv6Config] = await safe(settings.getIPv6Config());
|
2022-01-06 21:42:00 -08:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
2022-02-15 12:31:55 -08:00
|
|
|
next(new HttpSuccess(200, ipv6Config));
|
2022-01-06 21:42:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function setIPv6Config(req, res, next) {
|
|
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
2022-02-15 12:31:55 -08:00
|
|
|
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
2022-01-06 21:42:00 -08:00
|
|
|
|
2022-02-15 12:31:55 -08:00
|
|
|
const [error] = await safe(settings.setIPv6Config(req.body));
|
2022-01-06 21:42:00 -08:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(200, {}));
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
async function getUnstableAppsConfig(req, res, next) {
|
|
|
|
|
const [error, enabled] = await safe(settings.getUnstableAppsConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-04-27 22:30:32 +02:00
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
next(new HttpSuccess(200, { enabled }));
|
2019-04-27 22:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
async function setUnstableAppsConfig(req, res, next) {
|
2019-04-27 22:30:32 +02:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled boolean is required'));
|
|
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
const [error] = await safe(settings.setUnstableAppsConfig(req.body.enabled));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-04-27 22:30:32 +02:00
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2019-04-27 22:30:32 +02:00
|
|
|
}
|
2018-10-31 16:02:51 +01:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getRegistryConfig(req, res, next) {
|
|
|
|
|
const [error, registryConfig] = await safe(settings.getRegistryConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-10-22 22:07:44 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, docker.removePrivateFields(registryConfig)));
|
2019-10-22 22:07:44 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setRegistryConfig(req, res, next) {
|
2018-10-12 17:04:04 -07:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
2021-03-02 18:21:35 -08:00
|
|
|
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
|
|
|
|
if (req.body.provider !== 'noop') {
|
|
|
|
|
if (typeof req.body.serverAddress !== 'string') return next(new HttpError(400, 'serverAddress is required'));
|
|
|
|
|
if ('username' in req.body && typeof req.body.username !== 'string') return next(new HttpError(400, 'username is required'));
|
|
|
|
|
if ('email' in req.body && typeof req.body.email !== 'string') return next(new HttpError(400, 'email is required'));
|
|
|
|
|
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password is required'));
|
|
|
|
|
}
|
2018-10-12 17:04:04 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setRegistryConfig(req.body));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2018-10-12 17:04:04 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200));
|
2018-10-12 17:04:04 -07:00
|
|
|
}
|
2019-01-25 16:33:22 -08:00
|
|
|
|
2022-01-13 14:34:02 -08:00
|
|
|
async function getProfileConfig(req, res, next) {
|
|
|
|
|
const [error, directoryConfig] = await safe(settings.getProfileConfig());
|
2021-08-18 15:40:28 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2020-07-09 17:12:04 -07:00
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
next(new HttpSuccess(200, directoryConfig));
|
2020-07-09 17:12:04 -07:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 14:34:02 -08:00
|
|
|
async function setProfileConfig(req, res, next) {
|
2020-07-09 17:12:04 -07:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (typeof req.body.lockUserProfiles !== 'boolean') return next(new HttpError(400, 'lockUserProfiles is required'));
|
2020-07-10 10:00:03 -07:00
|
|
|
if (typeof req.body.mandatory2FA !== 'boolean') return next(new HttpError(400, 'mandatory2FA is required'));
|
2020-07-09 17:12:04 -07:00
|
|
|
|
2022-01-13 14:34:02 -08:00
|
|
|
const [error] = await safe(settings.setProfileConfig(req.body));
|
2021-08-18 15:40:28 -07:00
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2020-07-09 17:12:04 -07:00
|
|
|
|
2021-08-18 15:40:28 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2020-07-09 17:12:04 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function getSysinfoConfig(req, res, next) {
|
|
|
|
|
const [error, sysinfoConfig] = await safe(settings.getSysinfoConfig());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-10-29 20:08:45 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, sysinfoConfig));
|
2019-10-29 20:08:45 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
async function setSysinfoConfig(req, res, next) {
|
2019-10-29 20:08:45 -07:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
|
|
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
const [error] = await safe(settings.setSysinfoConfig(req.body));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2019-10-29 20:08:45 -07:00
|
|
|
|
2021-08-19 13:24:38 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2019-10-29 20:08:45 -07:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
async function getLanguage(req, res, next) {
|
|
|
|
|
const [error, language] = await safe(settings.getLanguage());
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2020-11-17 18:58:43 +01:00
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
next(new HttpSuccess(200, { language }));
|
2020-11-17 18:58:43 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
async function setLanguage(req, res, next) {
|
2020-11-17 18:58:43 +01:00
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
if (!req.body.language || typeof req.body.language !== 'string') return next(new HttpError(400, 'language is required'));
|
|
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
const [error] = await safe(settings.setLanguage(req.body.language));
|
|
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
2020-11-17 18:58:43 +01:00
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
next(new HttpSuccess(200, {}));
|
2020-11-17 18:58:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-25 16:33:22 -08:00
|
|
|
function get(req, res, next) {
|
|
|
|
|
assert.strictEqual(typeof req.params.setting, 'string');
|
|
|
|
|
|
|
|
|
|
switch (req.params.setting) {
|
|
|
|
|
case settings.DYNAMIC_DNS_KEY: return getDynamicDnsConfig(req, res, next);
|
2022-02-15 12:31:55 -08:00
|
|
|
case settings.IPV6_CONFIG_KEY: return getIPv6Config(req, res, next);
|
2019-01-25 16:33:22 -08:00
|
|
|
case settings.BACKUP_CONFIG_KEY: return getBackupConfig(req, res, next);
|
2019-08-29 12:25:10 +02:00
|
|
|
case settings.EXTERNAL_LDAP_KEY: return getExternalLdapConfig(req, res, next);
|
2022-08-15 19:14:02 +02:00
|
|
|
case settings.DIRECTORY_SERVER_KEY: return getDirectoryServerConfig(req, res, next);
|
2019-04-27 22:30:32 +02:00
|
|
|
case settings.UNSTABLE_APPS_KEY: return getUnstableAppsConfig(req, res, next);
|
2019-10-22 22:07:44 -07:00
|
|
|
case settings.REGISTRY_CONFIG_KEY: return getRegistryConfig(req, res, next);
|
2019-10-29 20:08:45 -07:00
|
|
|
case settings.SYSINFO_CONFIG_KEY: return getSysinfoConfig(req, res, next);
|
2020-11-17 18:58:43 +01:00
|
|
|
case settings.LANGUAGE_KEY: return getLanguage(req, res, next);
|
2019-01-25 16:33:22 -08:00
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
case settings.AUTOUPDATE_PATTERN_KEY: return getAutoupdatePattern(req, res, next);
|
2019-01-25 16:33:22 -08:00
|
|
|
case settings.TIME_ZONE_KEY: return getTimeZone(req, res, next);
|
|
|
|
|
|
2022-01-13 14:34:02 -08:00
|
|
|
case settings.PROFILE_CONFIG_KEY: return getProfileConfig(req, res, next);
|
2020-02-05 14:30:56 -08:00
|
|
|
case settings.SUPPORT_CONFIG_KEY: return getSupportConfig(req, res, next);
|
|
|
|
|
|
2019-01-25 16:33:22 -08:00
|
|
|
default: return next(new HttpError(404, 'No such setting'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function set(req, res, next) {
|
|
|
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
|
|
|
|
|
|
switch (req.params.setting) {
|
|
|
|
|
case settings.DYNAMIC_DNS_KEY: return setDynamicDnsConfig(req, res, next);
|
2022-02-15 12:31:55 -08:00
|
|
|
case settings.IPV6_CONFIG_KEY: return setIPv6Config(req, res, next);
|
2019-08-29 12:25:10 +02:00
|
|
|
case settings.EXTERNAL_LDAP_KEY: return setExternalLdapConfig(req, res, next);
|
2022-08-15 19:14:02 +02:00
|
|
|
case settings.DIRECTORY_SERVER_KEY: return setDirectoryServerConfig(req, res, next);
|
2019-04-27 22:30:32 +02:00
|
|
|
case settings.UNSTABLE_APPS_KEY: return setUnstableAppsConfig(req, res, next);
|
2019-10-22 22:07:44 -07:00
|
|
|
case settings.REGISTRY_CONFIG_KEY: return setRegistryConfig(req, res, next);
|
2019-10-29 20:08:45 -07:00
|
|
|
case settings.SYSINFO_CONFIG_KEY: return setSysinfoConfig(req, res, next);
|
2020-11-17 18:58:43 +01:00
|
|
|
case settings.LANGUAGE_KEY: return setLanguage(req, res, next);
|
2019-01-25 16:33:22 -08:00
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
case settings.AUTOUPDATE_PATTERN_KEY: return setAutoupdatePattern(req, res, next);
|
2019-01-25 16:33:22 -08:00
|
|
|
case settings.TIME_ZONE_KEY: return setTimeZone(req, res, next);
|
2019-01-25 14:57:07 -08:00
|
|
|
|
2022-01-13 14:34:02 -08:00
|
|
|
case settings.PROFILE_CONFIG_KEY: return setProfileConfig(req, res, next);
|
2020-07-09 17:12:04 -07:00
|
|
|
|
2019-01-25 16:33:22 -08:00
|
|
|
default: return next(new HttpError(404, 'No such setting'));
|
|
|
|
|
}
|
|
|
|
|
}
|