2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2020-08-19 21:39:58 -07:00
|
|
|
getAutoupdatePattern,
|
|
|
|
|
setAutoupdatePattern,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getTimeZone,
|
|
|
|
|
setTimeZone,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getCloudronName,
|
|
|
|
|
setCloudronName,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getCloudronAvatar,
|
|
|
|
|
setCloudronAvatar,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getDynamicDnsConfig,
|
|
|
|
|
setDynamicDnsConfig,
|
2017-01-02 13:05:48 +01:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getUnstableAppsConfig,
|
|
|
|
|
setUnstableAppsConfig,
|
2019-04-27 22:30:32 +02:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getBackupConfig,
|
|
|
|
|
setBackupConfig,
|
|
|
|
|
setBackupCredentials,
|
2015-11-07 18:02:45 -08:00
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
getServicesConfig,
|
|
|
|
|
setServicesConfig,
|
2018-05-16 17:31:32 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getExternalLdapConfig,
|
|
|
|
|
setExternalLdapConfig,
|
2019-08-28 18:22:07 +02:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getRegistryConfig,
|
|
|
|
|
setRegistryConfig,
|
2019-10-22 22:07:44 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getLicenseKey,
|
|
|
|
|
setLicenseKey,
|
2019-05-03 16:27:47 -07:00
|
|
|
|
2020-11-17 18:58:43 +01:00
|
|
|
getLanguage,
|
|
|
|
|
setLanguage,
|
|
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getCloudronId,
|
|
|
|
|
setCloudronId,
|
2019-05-03 16:27:47 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getCloudronToken,
|
|
|
|
|
setCloudronToken,
|
2019-04-30 22:57:43 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getSysinfoConfig,
|
|
|
|
|
setSysinfoConfig,
|
2019-10-29 15:46:33 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getFooter,
|
|
|
|
|
setFooter,
|
2020-02-04 13:09:54 -08:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getDirectoryConfig,
|
|
|
|
|
setDirectoryConfig,
|
2020-07-09 14:35:34 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getAppstoreListingConfig,
|
|
|
|
|
setAppstoreListingConfig,
|
2020-03-15 17:07:07 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
getSupportConfig,
|
|
|
|
|
provider,
|
|
|
|
|
getAll,
|
|
|
|
|
initCache,
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
// these values come from the cache
|
2020-08-15 18:19:01 -07:00
|
|
|
apiServerOrigin,
|
|
|
|
|
webServerOrigin,
|
|
|
|
|
adminDomain,
|
2020-08-15 19:24:32 -07:00
|
|
|
setAdminLocation,
|
2020-08-15 23:17:47 -07:00
|
|
|
setMailLocation,
|
|
|
|
|
|
|
|
|
|
mailFqdn,
|
|
|
|
|
mailDomain,
|
|
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
adminOrigin,
|
|
|
|
|
adminFqdn,
|
2019-07-26 10:49:29 -07:00
|
|
|
|
2020-08-15 18:19:01 -07:00
|
|
|
isDemo,
|
2019-07-26 10:49:29 -07:00
|
|
|
|
2017-07-18 13:31:43 -07:00
|
|
|
// booleans. if you add an entry here, be sure to fix getAll
|
2017-01-02 13:05:48 +01:00
|
|
|
DYNAMIC_DNS_KEY: 'dynamic_dns',
|
2019-04-27 22:30:32 +02:00
|
|
|
UNSTABLE_APPS_KEY: 'unstable_apps',
|
2019-07-25 11:16:52 -07:00
|
|
|
DEMO_KEY: 'demo',
|
2017-07-18 13:31:43 -07:00
|
|
|
|
|
|
|
|
// json. if you add an entry here, be sure to fix getAll
|
2015-11-07 18:02:45 -08:00
|
|
|
BACKUP_CONFIG_KEY: 'backup_config',
|
2021-01-21 12:18:11 -08:00
|
|
|
SERVICES_CONFIG_KEY: 'services_config',
|
2019-08-28 18:22:07 +02:00
|
|
|
EXTERNAL_LDAP_KEY: 'external_ldap_config',
|
2019-10-22 22:07:44 -07:00
|
|
|
REGISTRY_CONFIG_KEY: 'registry_config',
|
2019-10-29 15:46:33 -07:00
|
|
|
SYSINFO_CONFIG_KEY: 'sysinfo_config',
|
2020-02-05 11:58:10 -08:00
|
|
|
APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config',
|
2020-02-05 14:30:56 -08:00
|
|
|
SUPPORT_CONFIG_KEY: 'support_config',
|
2020-07-09 14:35:34 -07:00
|
|
|
DIRECTORY_CONFIG_KEY: 'directory_config',
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2017-07-18 13:31:43 -07:00
|
|
|
// strings
|
2020-08-19 21:39:58 -07:00
|
|
|
AUTOUPDATE_PATTERN_KEY: 'autoupdate_pattern',
|
2017-07-18 13:31:43 -07:00
|
|
|
TIME_ZONE_KEY: 'time_zone',
|
|
|
|
|
CLOUDRON_NAME_KEY: 'cloudron_name',
|
2019-04-30 22:57:43 -07:00
|
|
|
LICENSE_KEY: 'license_key',
|
2020-11-17 18:58:43 +01:00
|
|
|
LANGUAGE_KEY: 'language',
|
2019-04-30 22:57:43 -07:00
|
|
|
CLOUDRON_ID_KEY: 'cloudron_id',
|
2019-05-03 16:01:20 -07:00
|
|
|
CLOUDRON_TOKEN_KEY: 'cloudron_token',
|
2017-07-18 13:31:43 -07:00
|
|
|
|
2019-07-25 11:16:52 -07:00
|
|
|
API_SERVER_ORIGIN_KEY: 'api_server_origin',
|
|
|
|
|
WEB_SERVER_ORIGIN_KEY: 'web_server_origin',
|
|
|
|
|
ADMIN_DOMAIN_KEY: 'admin_domain',
|
|
|
|
|
ADMIN_FQDN_KEY: 'admin_fqdn',
|
2020-08-15 23:17:47 -07:00
|
|
|
MAIL_DOMAIN_KEY: 'mail_domain',
|
|
|
|
|
MAIL_FQDN_KEY: 'mail_fqdn',
|
2019-07-25 11:16:52 -07:00
|
|
|
PROVIDER_KEY: 'provider',
|
|
|
|
|
|
2020-02-04 13:09:54 -08:00
|
|
|
FOOTER_KEY: 'footer',
|
|
|
|
|
|
2019-01-25 16:33:22 -08:00
|
|
|
// blobs
|
2019-01-25 14:57:07 -08:00
|
|
|
CLOUDRON_AVATAR_KEY: 'cloudron_avatar', // not stored in db but can be used for locked flag
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
// testing
|
|
|
|
|
_setApiServerOrigin: setApiServerOrigin
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2021-01-20 11:10:17 -08:00
|
|
|
const assert = require('assert'),
|
2016-10-11 11:36:25 +02:00
|
|
|
backups = require('./backups.js'),
|
2019-10-22 11:03:56 -07:00
|
|
|
BoxError = require('./boxerror.js'),
|
2016-12-14 14:54:17 +01:00
|
|
|
constants = require('./constants.js'),
|
2019-03-04 10:25:18 -08:00
|
|
|
cron = require('./cron.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
CronJob = require('cron').CronJob,
|
2019-07-26 10:49:29 -07:00
|
|
|
debug = require('debug')('box:settings'),
|
2019-10-22 22:07:44 -07:00
|
|
|
docker = require('./docker.js'),
|
2019-10-25 15:58:11 -07:00
|
|
|
externalLdap = require('./externalldap.js'),
|
2016-06-02 13:36:47 -07:00
|
|
|
moment = require('moment-timezone'),
|
2015-07-20 00:09:47 -07:00
|
|
|
paths = require('./paths.js'),
|
|
|
|
|
safe = require('safetydance'),
|
|
|
|
|
settingsdb = require('./settingsdb.js'),
|
2019-10-29 20:08:45 -07:00
|
|
|
sysinfo = require('./sysinfo.js'),
|
2020-11-19 23:38:59 +01:00
|
|
|
translation = require('./translation.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
util = require('util'),
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
let gDefaults = (function () {
|
2015-07-20 00:09:47 -07:00
|
|
|
var result = { };
|
2020-08-19 21:39:58 -07:00
|
|
|
result[exports.AUTOUPDATE_PATTERN_KEY] = cron.DEFAULT_AUTOUPDATE_PATTERN;
|
2015-09-18 12:02:19 -07:00
|
|
|
result[exports.TIME_ZONE_KEY] = 'America/Los_Angeles';
|
2015-07-20 00:09:47 -07:00
|
|
|
result[exports.CLOUDRON_NAME_KEY] = 'Cloudron';
|
2017-01-02 13:05:48 +01:00
|
|
|
result[exports.DYNAMIC_DNS_KEY] = false;
|
2019-11-11 08:42:00 -08:00
|
|
|
result[exports.UNSTABLE_APPS_KEY] = true;
|
2019-04-30 22:57:43 -07:00
|
|
|
result[exports.LICENSE_KEY] = '';
|
2020-11-17 18:58:43 +01:00
|
|
|
result[exports.LANGUAGE_KEY] = 'en';
|
2019-04-30 22:57:43 -07:00
|
|
|
result[exports.CLOUDRON_ID_KEY] = '';
|
2019-05-03 16:01:20 -07:00
|
|
|
result[exports.CLOUDRON_TOKEN_KEY] = '';
|
2016-10-21 12:48:48 +02:00
|
|
|
result[exports.BACKUP_CONFIG_KEY] = {
|
|
|
|
|
provider: 'filesystem',
|
2017-04-22 20:27:52 -07:00
|
|
|
backupFolder: '/var/backups',
|
2018-11-16 13:52:36 -08:00
|
|
|
format: 'tgz',
|
2020-05-14 20:22:10 +02:00
|
|
|
encryption: null,
|
2020-05-14 20:05:27 -07:00
|
|
|
retentionPolicy: { keepWithinSecs: 2 * 24 * 60 * 60 }, // 2 days
|
2020-07-29 09:34:23 -07:00
|
|
|
schedulePattern: '00 00 23 * * *' // every day at 11pm
|
2016-10-21 12:48:48 +02:00
|
|
|
};
|
2021-01-21 12:18:11 -08:00
|
|
|
result[exports.SERVICES_CONFIG_KEY] = {};
|
2019-10-25 15:40:22 -07:00
|
|
|
result[exports.EXTERNAL_LDAP_KEY] = {
|
2019-11-20 10:38:24 +01:00
|
|
|
provider: 'noop',
|
|
|
|
|
autoCreate: false
|
2019-10-25 15:40:22 -07:00
|
|
|
};
|
2019-10-22 22:07:44 -07:00
|
|
|
result[exports.REGISTRY_CONFIG_KEY] = {};
|
2019-10-29 15:46:33 -07:00
|
|
|
result[exports.SYSINFO_CONFIG_KEY] = {
|
|
|
|
|
provider: 'generic'
|
|
|
|
|
};
|
2020-07-09 14:35:34 -07:00
|
|
|
result[exports.DIRECTORY_CONFIG_KEY] = {
|
2020-07-10 10:00:03 -07:00
|
|
|
lockUserProfiles: false,
|
|
|
|
|
mandatory2FA: false
|
2020-07-09 14:35:34 -07:00
|
|
|
};
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
result[exports.ADMIN_DOMAIN_KEY] = '';
|
|
|
|
|
result[exports.ADMIN_FQDN_KEY] = '';
|
2020-08-15 23:17:47 -07:00
|
|
|
result[exports.MAIL_DOMAIN_KEY] = '';
|
|
|
|
|
result[exports.MAIL_FQDN_KEY] = '';
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
result[exports.API_SERVER_ORIGIN_KEY] = 'https://api.cloudron.io';
|
|
|
|
|
result[exports.WEB_SERVER_ORIGIN_KEY] = 'https://cloudron.io';
|
|
|
|
|
result[exports.DEMO_KEY] = false;
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-02-05 11:58:10 -08:00
|
|
|
result[exports.APPSTORE_LISTING_CONFIG_KEY] = {
|
|
|
|
|
blacklist: [],
|
2020-02-26 09:01:22 -08:00
|
|
|
whitelist: null // null imples nothing is whitelisted. this is an array
|
2020-02-05 11:58:10 -08:00
|
|
|
};
|
|
|
|
|
|
2020-02-05 14:30:56 -08:00
|
|
|
result[exports.SUPPORT_CONFIG_KEY] = {
|
|
|
|
|
email: 'support@cloudron.io',
|
|
|
|
|
remoteSupport: true,
|
|
|
|
|
ticketFormBody:
|
|
|
|
|
'Use this form to open support tickets. You can also write directly to [support@cloudron.io](mailto:support@cloudron.io).\n\n'
|
2020-09-15 14:46:22 -07:00
|
|
|
+ '* [Knowledge Base & App Docs](https://docs.cloudron.io/apps/?support_view)\n'
|
|
|
|
|
+ '* [Custom App Packaging & API](https://docs.cloudron.io/custom-apps/tutorial/?support_view)\n'
|
2020-02-05 14:30:56 -08:00
|
|
|
+ '* [Forum](https://forum.cloudron.io/)\n\n',
|
|
|
|
|
submitTickets: true
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-06 18:08:26 -08:00
|
|
|
result[exports.FOOTER_KEY] = '';
|
2020-02-04 13:09:54 -08:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
return result;
|
|
|
|
|
})();
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
let gCache = {};
|
|
|
|
|
|
2019-03-04 10:25:18 -08:00
|
|
|
function notifyChange(key, value) {
|
2019-03-04 15:45:04 -08:00
|
|
|
assert.strictEqual(typeof key, 'string');
|
|
|
|
|
// value is a variant
|
2019-03-04 10:25:18 -08:00
|
|
|
cron.handleSettingsChanged(key, value);
|
2017-02-07 10:30:52 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
function setAutoupdatePattern(pattern, callback) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof pattern, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2017-01-26 15:36:24 -08:00
|
|
|
if (pattern !== constants.AUTOUPDATE_PATTERN_NEVER) { // check if pattern is valid
|
2015-07-20 00:09:47 -07:00
|
|
|
var job = safe.safeCall(function () { return new CronJob(pattern); });
|
2019-10-22 11:03:56 -07:00
|
|
|
if (!job) return callback(new BoxError(BoxError.BAD_FIELD, 'Invalid pattern', { field: 'pattern' }));
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
settingsdb.set(exports.AUTOUPDATE_PATTERN_KEY, pattern, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
notifyChange(exports.AUTOUPDATE_PATTERN_KEY, pattern);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
function getAutoupdatePattern(callback) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2020-08-19 21:39:58 -07:00
|
|
|
settingsdb.get(exports.AUTOUPDATE_PATTERN_KEY, function (error, pattern) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.AUTOUPDATE_PATTERN_KEY]);
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
callback(null, pattern);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setTimeZone(tz, callback) {
|
|
|
|
|
assert.strictEqual(typeof tz, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-10-22 11:03:56 -07:00
|
|
|
if (moment.tz.names().indexOf(tz) === -1) return callback(new BoxError(BoxError.BAD_FIELD, 'Bad timeZone', { field: 'timezone' }));
|
2016-06-02 13:36:47 -07:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
settingsdb.set(exports.TIME_ZONE_KEY, tz, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-03-04 10:25:18 -08:00
|
|
|
notifyChange(exports.TIME_ZONE_KEY, tz);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTimeZone(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.TIME_ZONE_KEY, function (error, tz) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.TIME_ZONE_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
callback(null, tz);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCloudronName(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.CLOUDRON_NAME_KEY, function (error, name) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.CLOUDRON_NAME_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
callback(null, name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setCloudronName(name, callback) {
|
|
|
|
|
assert.strictEqual(typeof name, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-10-22 11:03:56 -07:00
|
|
|
if (!name) return callback(new BoxError(BoxError.BAD_FIELD, 'name is empty', { field: 'name' }));
|
2016-06-02 12:51:39 -07:00
|
|
|
|
|
|
|
|
// some arbitrary restrictions (for sake of ui layout)
|
2021-01-07 22:49:52 +01:00
|
|
|
// if this is changed, adjust dashboard/branding.html
|
|
|
|
|
if (name.length > 64) return callback(new BoxError(BoxError.BAD_FIELD, 'name cannot exceed 64 characters', { field: 'name' }));
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
settingsdb.set(exports.CLOUDRON_NAME_KEY, name, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-03-04 10:25:18 -08:00
|
|
|
notifyChange(exports.CLOUDRON_NAME_KEY, name);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCloudronAvatar(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
var avatar = safe.fs.readFileSync(paths.CLOUDRON_AVATAR_FILE);
|
|
|
|
|
if (avatar) return callback(null, avatar);
|
|
|
|
|
|
|
|
|
|
// try default fallback
|
|
|
|
|
avatar = safe.fs.readFileSync(paths.CLOUDRON_DEFAULT_AVATAR_FILE);
|
|
|
|
|
if (avatar) return callback(null, avatar);
|
|
|
|
|
|
2019-10-24 11:13:48 -07:00
|
|
|
callback(new BoxError(BoxError.FS_ERROR, safe.error));
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setCloudronAvatar(avatar, callback) {
|
|
|
|
|
assert(util.isBuffer(avatar));
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
if (!safe.fs.writeFileSync(paths.CLOUDRON_AVATAR_FILE, avatar)) {
|
2019-10-24 11:13:48 -07:00
|
|
|
return callback(new BoxError(BoxError.FS_ERROR, safe.error));
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-02 13:05:48 +01:00
|
|
|
function getDynamicDnsConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.DYNAMIC_DNS_KEY, function (error, enabled) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.DYNAMIC_DNS_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2017-01-02 13:05:48 +01:00
|
|
|
|
2017-07-18 16:58:37 -07:00
|
|
|
callback(null, !!enabled); // settingsdb holds string values only
|
2017-01-02 13:05:48 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setDynamicDnsConfig(enabled, callback) {
|
|
|
|
|
assert.strictEqual(typeof enabled, 'boolean');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
// settingsdb takes string values only
|
|
|
|
|
settingsdb.set(exports.DYNAMIC_DNS_KEY, enabled ? 'enabled' : '', function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2017-01-02 13:05:48 +01:00
|
|
|
|
2019-03-04 10:25:18 -08:00
|
|
|
notifyChange(exports.DYNAMIC_DNS_KEY, enabled);
|
2017-01-02 13:05:48 +01:00
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-27 22:30:32 +02:00
|
|
|
function getUnstableAppsConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.UNSTABLE_APPS_KEY, function (error, enabled) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.UNSTABLE_APPS_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-04-27 22:30:32 +02:00
|
|
|
|
|
|
|
|
callback(null, !!enabled); // settingsdb holds string values only
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setUnstableAppsConfig(enabled, callback) {
|
|
|
|
|
assert.strictEqual(typeof enabled, 'boolean');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
// settingsdb takes string values only
|
|
|
|
|
settingsdb.set(exports.UNSTABLE_APPS_KEY, enabled ? 'enabled' : '', function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-04-27 22:30:32 +02:00
|
|
|
|
|
|
|
|
notifyChange(exports.UNSTABLE_APPS_KEY, enabled);
|
|
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-07 18:02:45 -08:00
|
|
|
function getBackupConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.BACKUP_CONFIG_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.BACKUP_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2015-11-07 18:02:45 -08:00
|
|
|
|
2020-05-28 19:50:23 +02:00
|
|
|
callback(null, JSON.parse(value)); // provider, token, password, region, prefix, bucket
|
2015-11-07 18:02:45 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setBackupConfig(backupConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof backupConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2020-05-11 11:58:11 -07:00
|
|
|
getBackupConfig(function (error, currentConfig) {
|
2019-02-08 22:21:17 -08:00
|
|
|
if (error) return callback(error);
|
2017-09-27 20:52:36 -07:00
|
|
|
|
2020-05-11 11:58:11 -07:00
|
|
|
backups.injectPrivateFields(backupConfig, currentConfig);
|
2019-02-09 18:08:10 -08:00
|
|
|
|
|
|
|
|
backups.testConfig(backupConfig, function (error) {
|
2019-10-22 20:36:20 -07:00
|
|
|
if (error) return callback(error);
|
2016-10-11 15:56:07 +02:00
|
|
|
|
2020-05-14 11:18:41 -07:00
|
|
|
if ('password' in backupConfig) { // user set password
|
|
|
|
|
backupConfig.encryption = backups.generateEncryptionKeysSync(backupConfig.password);
|
|
|
|
|
delete backupConfig.password;
|
2020-05-12 14:00:05 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 14:01:15 -07:00
|
|
|
// if any of these changes, we have to clear the cache
|
|
|
|
|
if ([ 'format', 'provider', 'prefix', 'bucket', 'region', 'endpoint', 'backupFolder', 'mountPoint', 'encryption' ].some(p => backupConfig[p] !== currentConfig[p])) {
|
|
|
|
|
debug('setBackupConfig: clearing backup cache');
|
|
|
|
|
backups.cleanupCacheFilesSync();
|
|
|
|
|
}
|
2019-02-08 22:21:17 -08:00
|
|
|
|
|
|
|
|
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-02-08 22:21:17 -08:00
|
|
|
|
2019-03-04 10:25:18 -08:00
|
|
|
notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig);
|
2016-10-11 15:56:07 +02:00
|
|
|
|
2020-01-31 13:37:07 -08:00
|
|
|
backups.configureCollectd(backupConfig, callback);
|
2019-02-08 22:21:17 -08:00
|
|
|
});
|
2016-10-11 11:36:25 +02:00
|
|
|
});
|
2015-11-07 18:02:45 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-27 12:38:17 -08:00
|
|
|
function setBackupCredentials(credentials, callback) {
|
|
|
|
|
assert.strictEqual(typeof credentials, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
getBackupConfig(function (error, currentConfig) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
// preserve these fields
|
2020-08-19 14:38:59 -07:00
|
|
|
const extra = _.pick(currentConfig, 'retentionPolicy', 'schedulePattern', 'copyConcurrency', 'syncConcurrency', 'memoryLimit', 'downloadConcurrency', 'deleteConcurrency', 'uploadPartSize');
|
2020-02-27 12:38:17 -08:00
|
|
|
|
|
|
|
|
const backupConfig = _.extend({}, credentials, extra);
|
|
|
|
|
|
|
|
|
|
backups.cleanupCacheFilesSync();
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig);
|
|
|
|
|
|
|
|
|
|
backups.configureCollectd(backupConfig, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
function getServicesConfig(callback) {
|
2018-05-16 17:31:32 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
settingsdb.get(exports.SERVICES_CONFIG_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.SERVICES_CONFIG_KEY]);
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2018-05-16 17:31:32 -07:00
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
function setServicesConfig(platformConfig, callback) {
|
2018-05-16 17:31:32 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
settingsdb.set(exports.SERVICES_CONFIG_KEY, JSON.stringify(platformConfig), function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2018-05-16 17:31:32 -07:00
|
|
|
|
2021-01-21 12:18:11 -08:00
|
|
|
notifyChange(exports.SERVICES_CONFIG_KEY, platformConfig);
|
2020-09-22 21:42:47 -07:00
|
|
|
|
2021-01-20 11:10:17 -08:00
|
|
|
callback(null);
|
2018-05-16 17:31:32 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 18:22:07 +02:00
|
|
|
function getExternalLdapConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.EXTERNAL_LDAP_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.EXTERNAL_LDAP_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-08-28 18:22:07 +02:00
|
|
|
|
2019-11-20 10:38:24 +01:00
|
|
|
let config = JSON.parse(value);
|
|
|
|
|
|
|
|
|
|
// ensure new keys
|
|
|
|
|
if (!config.autoCreate) config.autoCreate = false;
|
|
|
|
|
|
|
|
|
|
callback(null, config);
|
2019-08-28 18:22:07 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setExternalLdapConfig(externalLdapConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof externalLdapConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2020-07-22 17:53:04 -07:00
|
|
|
if (isDemo()) return callback(new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode'));
|
2020-07-22 16:18:22 -07:00
|
|
|
|
2020-02-27 12:38:17 -08:00
|
|
|
getExternalLdapConfig(function (error, currentConfig) {
|
2019-10-24 13:41:41 -07:00
|
|
|
if (error) return callback(error);
|
2019-08-28 18:22:07 +02:00
|
|
|
|
2020-02-27 12:38:17 -08:00
|
|
|
externalLdap.injectPrivateFields(externalLdapConfig, currentConfig);
|
2019-10-25 15:58:11 -07:00
|
|
|
|
|
|
|
|
externalLdap.testConfig(externalLdapConfig, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-08-28 18:22:07 +02:00
|
|
|
|
2019-10-25 15:58:11 -07:00
|
|
|
settingsdb.set(exports.EXTERNAL_LDAP_KEY, JSON.stringify(externalLdapConfig), function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.EXTERNAL_LDAP_KEY, externalLdapConfig);
|
2019-08-28 18:22:07 +02:00
|
|
|
|
2019-10-25 15:58:11 -07:00
|
|
|
callback(null);
|
|
|
|
|
});
|
2019-08-28 18:22:07 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 22:07:44 -07:00
|
|
|
function getRegistryConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.REGISTRY_CONFIG_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.REGISTRY_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-10-22 22:07:44 -07:00
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setRegistryConfig(registryConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof registryConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
getRegistryConfig(function (error, curentConfig) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
docker.injectPrivateFields(registryConfig, curentConfig);
|
|
|
|
|
|
|
|
|
|
docker.testRegistryConfig(registryConfig, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.REGISTRY_CONFIG_KEY, JSON.stringify(registryConfig), function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-10-22 22:07:44 -07:00
|
|
|
|
|
|
|
|
notifyChange(exports.REGISTRY_CONFIG_KEY, registryConfig);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
function getSysinfoConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.SYSINFO_CONFIG_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.SYSINFO_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setSysinfoConfig(sysinfoConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof sysinfoConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-12-05 16:06:21 +01:00
|
|
|
if (isDemo()) return callback(new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode'));
|
|
|
|
|
|
2019-10-29 20:08:45 -07:00
|
|
|
sysinfo.testConfig(sysinfoConfig, function (error) {
|
2019-10-29 15:46:33 -07:00
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
2019-10-29 20:08:45 -07:00
|
|
|
settingsdb.set(exports.SYSINFO_CONFIG_KEY, JSON.stringify(sysinfoConfig), function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.SYSINFO_CONFIG_KEY, sysinfoConfig);
|
2019-10-29 15:46:33 -07:00
|
|
|
|
2019-10-29 20:08:45 -07:00
|
|
|
callback(null);
|
|
|
|
|
});
|
2019-10-29 15:46:33 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 14:35:34 -07:00
|
|
|
function getDirectoryConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.DIRECTORY_CONFIG_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.DIRECTORY_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setDirectoryConfig(directoryConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof directoryConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2020-07-22 17:53:04 -07:00
|
|
|
if (isDemo()) return callback(new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode'));
|
2020-07-22 16:18:22 -07:00
|
|
|
|
2020-07-09 14:35:34 -07:00
|
|
|
settingsdb.set(exports.DIRECTORY_CONFIG_KEY, JSON.stringify(directoryConfig), function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.DIRECTORY_CONFIG_KEY, directoryConfig);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 11:58:10 -08:00
|
|
|
function getAppstoreListingConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.APPSTORE_LISTING_CONFIG_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.APPSTORE_LISTING_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-15 17:07:07 -07:00
|
|
|
function setAppstoreListingConfig(listingConfig, callback) {
|
|
|
|
|
assert.strictEqual(typeof listingConfig, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.APPSTORE_LISTING_CONFIG_KEY, JSON.stringify(listingConfig), function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.APPSTORE_LISTING_CONFIG_KEY, listingConfig);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-02-05 14:30:56 -08:00
|
|
|
function getSupportConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.SUPPORT_CONFIG_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.SUPPORT_CONFIG_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, JSON.parse(value));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 22:57:43 -07:00
|
|
|
function getLicenseKey(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.LICENSE_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.LICENSE_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-04-30 22:57:43 -07:00
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
function setLicenseKey(licenseKey, callback) {
|
|
|
|
|
assert.strictEqual(typeof licenseKey, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.LICENSE_KEY, licenseKey, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-05-03 16:27:47 -07:00
|
|
|
|
|
|
|
|
notifyChange(exports.LICENSE_KEY, licenseKey);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 18:58:43 +01:00
|
|
|
function getLanguage(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.LANGUAGE_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.LANGUAGE_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setLanguage(language, callback) {
|
|
|
|
|
assert.strictEqual(typeof language, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2020-11-19 23:38:59 +01:00
|
|
|
translation.getLanguages(function (error, languages) {
|
2020-11-17 18:58:43 +01:00
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
2020-11-18 00:10:06 +01:00
|
|
|
if (languages.indexOf(language) === -1) return callback(new BoxError(BoxError.NOT_FOUND));
|
2020-11-17 18:58:43 +01:00
|
|
|
|
2020-11-18 00:10:06 +01:00
|
|
|
settingsdb.set(exports.LANGUAGE_KEY, language, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.LANGUAGE_KEY, language);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
2020-11-17 18:58:43 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-30 22:57:43 -07:00
|
|
|
function getCloudronId(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.CLOUDRON_ID_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.CLOUDRON_ID_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-04-30 22:57:43 -07:00
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
function setCloudronId(cid, callback) {
|
|
|
|
|
assert.strictEqual(typeof cid, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.CLOUDRON_ID_KEY, cid, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-05-03 16:27:47 -07:00
|
|
|
|
|
|
|
|
notifyChange(exports.CLOUDRON_ID_KEY, cid);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 16:01:20 -07:00
|
|
|
function getCloudronToken(callback) {
|
2019-04-30 22:57:43 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-05-03 16:01:20 -07:00
|
|
|
settingsdb.get(exports.CLOUDRON_TOKEN_KEY, function (error, value) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.CLOUDRON_TOKEN_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
2019-04-30 22:57:43 -07:00
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
function setCloudronToken(token, callback) {
|
|
|
|
|
assert.strictEqual(typeof token, 'string');
|
2016-07-26 14:31:07 +02:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
settingsdb.set(exports.CLOUDRON_TOKEN_KEY, token, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2018-11-05 17:12:04 -08:00
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
notifyChange(exports.CLOUDRON_TOKEN_KEY, token);
|
2016-08-01 15:10:45 +02:00
|
|
|
|
2019-05-03 16:27:47 -07:00
|
|
|
callback(null);
|
2016-07-26 14:31:07 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
function getAll(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.getAll(function (error, settings) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
var result = _.extend({ }, gDefaults);
|
|
|
|
|
settings.forEach(function (setting) { result[setting.name] = setting.value; });
|
|
|
|
|
|
2017-01-02 13:47:49 +01:00
|
|
|
// convert booleans
|
2017-01-02 14:15:20 +01:00
|
|
|
result[exports.DYNAMIC_DNS_KEY] = !!result[exports.DYNAMIC_DNS_KEY];
|
2019-04-27 22:30:32 +02:00
|
|
|
result[exports.UNSTABLE_APPS_KEY] = !!result[exports.UNSTABLE_APPS_KEY];
|
2019-07-25 11:16:52 -07:00
|
|
|
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
|
2017-01-02 13:47:49 +01:00
|
|
|
|
2017-01-10 15:18:43 +01:00
|
|
|
// convert JSON objects
|
2021-01-21 12:18:11 -08:00
|
|
|
[exports.BACKUP_CONFIG_KEY, exports.DIRECTORY_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY ].forEach(function (key) {
|
2017-01-10 15:18:43 +01:00
|
|
|
result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]);
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
callback(null, result);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
function initCache(callback) {
|
|
|
|
|
debug('initCache: pre-load settings');
|
|
|
|
|
|
|
|
|
|
getAll(function (error, allSettings) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
2020-02-07 09:13:33 -08:00
|
|
|
const provider = safe.fs.readFileSync(paths.PROVIDER_FILE, 'utf8');
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
gCache = {
|
|
|
|
|
apiServerOrigin: allSettings[exports.API_SERVER_ORIGIN_KEY],
|
|
|
|
|
webServerOrigin: allSettings[exports.WEB_SERVER_ORIGIN_KEY],
|
|
|
|
|
adminDomain: allSettings[exports.ADMIN_DOMAIN_KEY],
|
|
|
|
|
adminFqdn: allSettings[exports.ADMIN_FQDN_KEY],
|
2020-08-15 23:17:47 -07:00
|
|
|
mailDomain: allSettings[exports.MAIL_DOMAIN_KEY],
|
|
|
|
|
mailFqdn: allSettings[exports.MAIL_FQDN_KEY],
|
2019-10-29 15:46:33 -07:00
|
|
|
isDemo: allSettings[exports.DEMO_KEY],
|
2020-02-07 09:13:33 -08:00
|
|
|
provider: provider ? provider.trim() : 'generic'
|
2019-07-26 10:49:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this is together so we can do this in a transaction later
|
2020-08-15 19:24:32 -07:00
|
|
|
function setAdminLocation(adminDomain, adminFqdn, callback) {
|
2019-07-26 10:49:29 -07:00
|
|
|
assert.strictEqual(typeof adminDomain, 'string');
|
|
|
|
|
assert.strictEqual(typeof adminFqdn, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.ADMIN_DOMAIN_KEY, adminDomain, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
settingsdb.set(exports.ADMIN_FQDN_KEY, adminFqdn, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
gCache.adminDomain = adminDomain;
|
|
|
|
|
gCache.adminFqdn = adminFqdn;
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 23:17:47 -07:00
|
|
|
function setMailLocation(mailDomain, mailFqdn, callback) {
|
|
|
|
|
assert.strictEqual(typeof mailDomain, 'string');
|
|
|
|
|
assert.strictEqual(typeof mailFqdn, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.MAIL_DOMAIN_KEY, mailDomain, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.MAIL_FQDN_KEY, mailFqdn, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
gCache.mailDomain = mailDomain;
|
|
|
|
|
gCache.mailFqdn = mailFqdn;
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 10:49:29 -07:00
|
|
|
function setApiServerOrigin(origin, callback) {
|
|
|
|
|
assert.strictEqual(typeof origin, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.API_SERVER_ORIGIN_KEY, origin, function (error) {
|
2019-10-24 11:13:48 -07:00
|
|
|
if (error) return callback(error);
|
2019-07-26 10:49:29 -07:00
|
|
|
|
|
|
|
|
gCache.apiServerOrigin = origin;
|
|
|
|
|
notifyChange(exports.API_SERVER_ORIGIN_KEY, origin);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 13:09:54 -08:00
|
|
|
function getFooter(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.get(exports.FOOTER_KEY, function (error, value) {
|
|
|
|
|
if (error && error.reason === BoxError.NOT_FOUND) return callback(null, gDefaults[exports.FOOTER_KEY]);
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setFooter(footer, callback) {
|
|
|
|
|
assert.strictEqual(typeof footer, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
settingsdb.set(exports.FOOTER_KEY, footer, function (error) {
|
|
|
|
|
if (error) return callback(error);
|
|
|
|
|
|
|
|
|
|
notifyChange(exports.FOOTER_KEY, footer);
|
|
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 15:46:33 -07:00
|
|
|
function provider() { return gCache.provider; }
|
2019-07-26 10:49:29 -07:00
|
|
|
function apiServerOrigin() { return gCache.apiServerOrigin; }
|
|
|
|
|
function webServerOrigin() { return gCache.webServerOrigin; }
|
|
|
|
|
function adminDomain() { return gCache.adminDomain; }
|
|
|
|
|
function adminFqdn() { return gCache.adminFqdn; }
|
|
|
|
|
function isDemo() { return gCache.isDemo; }
|
2020-08-15 23:17:47 -07:00
|
|
|
function mailDomain() { return gCache.mailDomain; }
|
|
|
|
|
function mailFqdn() { return gCache.mailFqdn; }
|
2019-07-26 10:49:29 -07:00
|
|
|
function adminOrigin() { return 'https://' + adminFqdn(); }
|