settings: move ipv6/ipv4 config into network

this also rename sysinfo_config to ipv4_config
This commit is contained in:
Girish Ramakrishnan
2023-08-03 06:05:29 +05:30
parent f2e56cbdd8
commit 92a103d635
14 changed files with 144 additions and 139 deletions
+43 -1
View File
@@ -8,7 +8,13 @@ exports = module.exports = {
setTrustedIps,
getDynamicDns,
setDynamicDns
setDynamicDns,
getIPv4Config,
setIPv4Config,
getIPv6Config,
setIPv6Config
};
const assert = require('assert'),
@@ -75,3 +81,39 @@ async function setDynamicDns(req, res, next) {
next(new HttpSuccess(200, {}));
}
async function getIPv4Config(req, res, next) {
const [error, ipv4Config] = await safe(network.getIPv4Config());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, ipv4Config));
}
async function setIPv4Config(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
const [error] = await safe(network.setIPv4Config(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
}
async function getIPv6Config(req, res, next) {
const [error, ipv6Config] = await safe(network.getIPv6Config());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, ipv6Config));
}
async function setIPv6Config(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.provider || typeof req.body.provider !== 'string') return next(new HttpError(400, 'provider is required'));
const [error] = await safe(network.setIPv6Config(req.body));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
}