Files
cloudron-box/src/sysinfo/fixed.js
T

40 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
exports = module.exports = {
2022-01-05 18:07:36 -08:00
getServerIPv4,
getServerIPv6,
2019-10-29 20:08:45 -07:00
testConfig
};
2021-08-27 09:52:24 -07:00
const assert = require('assert'),
2019-10-29 20:08:45 -07:00
BoxError = require('../boxerror.js'),
2022-01-05 18:07:36 -08:00
net = require('net');
2022-01-05 18:07:36 -08:00
async function getServerIPv4(config) {
assert.strictEqual(typeof config, 'object');
2021-08-27 09:52:24 -07:00
return config.ip;
}
2022-01-05 18:07:36 -08:00
async function getServerIPv6(config) {
assert.strictEqual(typeof config, 'object');
2022-01-06 12:22:16 -08:00
if ('ipv6' in config) return config.ipv6;
throw new BoxError(BoxError.NETWORK_ERROR, 'No IPv6 configured');
2022-01-05 18:07:36 -08:00
}
2021-08-27 09:52:24 -07:00
async function testConfig(config) {
2019-10-29 20:08:45 -07:00
assert.strictEqual(typeof config, 'object');
2022-01-05 18:07:36 -08:00
if (typeof config.ip !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv4 must be a string');
if (!net.isIPv4(config.ip)) return new BoxError(BoxError.BAD_FIELD, 'ip is not a valid ipv4');
if ('ipv6' in config) {
if (typeof config.ipv6 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv6 must be a string');
if (!net.isIPv6(config.ipv6)) return new BoxError(BoxError.BAD_FIELD, 'ipv6 is not a valid ipv6');
}
2019-10-29 20:08:45 -07:00
2021-08-27 09:52:24 -07:00
return null;
2019-10-29 20:08:45 -07:00
}