make ipv4 and ipv6 settings separate

This commit is contained in:
Girish Ramakrishnan
2022-02-15 12:31:55 -08:00
parent 0dbe8ee8f2
commit c6da8c8167
14 changed files with 102 additions and 68 deletions

View File

@@ -93,7 +93,6 @@ exports = module.exports = {
// booleans. if you add an entry here, be sure to fix list()
DYNAMIC_DNS_KEY: 'dynamic_dns',
UNSTABLE_APPS_KEY: 'unstable_apps',
IPV6_KEY: 'ipv6',
DEMO_KEY: 'demo',
// json. if you add an entry here, be sure to fix list()
@@ -102,12 +101,13 @@ exports = module.exports = {
EXTERNAL_LDAP_KEY: 'external_ldap_config',
USER_DIRECTORY_KEY: 'user_directory_config',
REGISTRY_CONFIG_KEY: 'registry_config',
SYSINFO_CONFIG_KEY: 'sysinfo_config',
SYSINFO_CONFIG_KEY: 'sysinfo_config', // misnomer: ipv4 config
APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config',
SUPPORT_CONFIG_KEY: 'support_config',
PROFILE_CONFIG_KEY: 'profile_config',
GHOSTS_CONFIG_KEY: 'ghosts_config',
REVERSE_PROXY_CONFIG_KEY: 'reverseproxy_config',
IPV6_CONFIG_KEY: 'ipv6',
// strings
AUTOUPDATE_PATTERN_KEY: 'autoupdate_pattern',
@@ -171,7 +171,9 @@ const gDefaults = (function () {
result[exports.TIME_ZONE_KEY] = 'America/Los_Angeles';
result[exports.CLOUDRON_NAME_KEY] = 'Cloudron';
result[exports.DYNAMIC_DNS_KEY] = false;
result[exports.IPV6_KEY] = false;
result[exports.IPV6_CONFIG_KEY] = {
provider: 'noop'
};
result[exports.UNSTABLE_APPS_KEY] = true;
result[exports.LICENSE_KEY] = '';
result[exports.LANGUAGE_KEY] = 'en';
@@ -370,18 +372,21 @@ async function setDynamicDnsConfig(enabled) {
}
async function getIPv6Config() {
const enabled = await get(exports.IPV6_KEY);
if (enabled === null) return gDefaults[exports.IPV6_KEY];
return !!enabled; // db holds string values only
const value = await get(exports.IPV6_CONFIG_KEY);
if (value === null) return gDefaults[exports.IPV6_CONFIG_KEY];
return JSON.parse(value);
}
async function setIPv6Config(enabled) {
assert.strictEqual(typeof enabled, 'boolean');
async function setIPv6Config(ipv6Config) {
assert.strictEqual(typeof ipv6Config, 'object');
// we don't validate if server has IPv6 intentionally. our api server could be down, maybe user assigns
// ipv6 later, fixed/static address is not defined yet etc
await set(exports.IPV6_KEY, enabled ? 'enabled' : ''); // db holds string values only
notifyChange(exports.IPV6_KEY, enabled);
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
const error = await sysinfo.testIPv6Config(ipv6Config);
if (error) throw error;
await set(exports.IPV6_CONFIG_KEY, JSON.stringify(ipv6Config));
notifyChange(exports.IPV6_CONFIG_KEY, ipv6Config);
}
async function getUnstableAppsConfig() {
@@ -603,7 +608,7 @@ async function setSysinfoConfig(sysinfoConfig) {
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
const error = await sysinfo.testConfig(sysinfoConfig);
const error = await sysinfo.testIPv4Config(sysinfoConfig);
if (error) throw error;
await set(exports.SYSINFO_CONFIG_KEY, JSON.stringify(sysinfoConfig));
@@ -756,12 +761,11 @@ async function list() {
// convert booleans
result[exports.DYNAMIC_DNS_KEY] = !!result[exports.DYNAMIC_DNS_KEY];
result[exports.IPV6_KEY] = !!result[exports.IPV6_KEY];
result[exports.UNSTABLE_APPS_KEY] = !!result[exports.UNSTABLE_APPS_KEY];
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
// convert JSON objects
[exports.BACKUP_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) {
[exports.BACKUP_CONFIG_KEY, exports.IPV6_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) {
result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]);
});