diff --git a/dashboard/src/views/network.js b/dashboard/src/views/network.js index 00fffec32..50c3cd82a 100644 --- a/dashboard/src/views/network.js +++ b/dashboard/src/views/network.js @@ -96,7 +96,7 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat } $scope.ipv6Configure.provider = result.provider; - $scope.ipv6Configure.ipv6 = result.ipv6 || ''; + $scope.ipv6Configure.ipv6 = result.ip || ''; $scope.ipv6Configure.ifname = result.ifname || ''; if (result.provider === 'noop') return; @@ -106,7 +106,7 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat return console.error(error); } - $scope.ipv6Configure.serverIPv6 = result.ipv6; + $scope.ipv6Configure.serverIPv6 = result.ip; }); }); }, @@ -129,7 +129,7 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat }; if (config.provider === 'fixed') { - config.ipv6 = $scope.ipv6Configure.newIPv6; + config.ip = $scope.ipv6Configure.newIPv6; } else if (config.provider === 'network-interface') { config.ifname = $scope.ipv6Configure.newIfname; } @@ -269,13 +269,13 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat if (error) return console.error(error); $scope.sysinfo.provider = result.provider; - $scope.sysinfo.ipv4 = result.ipv4 || ''; + $scope.sysinfo.ipv4 = result.ip || ''; $scope.sysinfo.ifname = result.ifname || ''; Client.getServerIpv4(function (error, result) { if (error) return console.error(error); - $scope.sysinfo.serverIPv4 = result.ipv4; + $scope.sysinfo.serverIPv4 = result.ip; }); }); }, @@ -298,7 +298,7 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat }; if (config.provider === 'fixed') { - config.ipv4 = $scope.sysinfo.newIPv4; + config.ip = $scope.sysinfo.newIPv4; } else if (config.provider === 'network-interface') { config.ifname = $scope.sysinfo.newIfname; } diff --git a/migrations/20230912143739-network-config-rename-to-ip.js b/migrations/20230912143739-network-config-rename-to-ip.js new file mode 100644 index 000000000..ae5d2d305 --- /dev/null +++ b/migrations/20230912143739-network-config-rename-to-ip.js @@ -0,0 +1,22 @@ +'use strict'; + +exports.up = async function(db) { + let result = await db.runSql('SELECT * FROM settings WHERE name=?', ['ipv4_config']); + if (result.length) { + const ipv4Config = JSON.parse(result[0].value); + ipv4Config.ip = ipv4Config.ipv4; + delete ipv4Config.ipv4; + await db.runSql('UPDATE settings SET value=? WHERE name=?', [ JSON.stringify(ipv4Config), 'ipv4_config']); + } + + result = await db.runSql('SELECT * FROM settings WHERE name=?', ['ipv6_config']); + if (result.length) { + const ipv6Config = JSON.parse(result[0].value); + ipv6Config.ip = ipv6Config.ipv6; + delete ipv6Config.ipv6; + await db.runSql('UPDATE settings SET value=? WHERE name=?', [ JSON.stringify(ipv6Config), 'ipv6_config']); + } +}; + +exports.down = async function(/* db */) { +}; diff --git a/src/network/fixed.js b/src/network/fixed.js index f210a0c3e..78b3a1d4e 100644 --- a/src/network/fixed.js +++ b/src/network/fixed.js @@ -14,13 +14,13 @@ const assert = require('assert'), async function getIPv4(config) { assert.strictEqual(typeof config, 'object'); - return config.ipv4; + return config.ip; } async function getIPv6(config) { assert.strictEqual(typeof config, 'object'); - if ('ipv6' in config) return config.ipv6; + if ('ip' in config) return config.ip; throw new BoxError(BoxError.NETWORK_ERROR, 'No IPv6 configured'); } @@ -28,8 +28,8 @@ async function getIPv6(config) { async function testIPv4Config(config) { assert.strictEqual(typeof config, 'object'); - if (typeof config.ipv4 !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv4 must be a string'); - if (!net.isIPv4(config.ipv4)) return new BoxError(BoxError.BAD_FIELD, 'invalid IPv4'); + 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, 'invalid IPv4'); return null; } @@ -37,8 +37,8 @@ async function testIPv4Config(config) { async function testIPv6Config(config) { assert.strictEqual(typeof config, 'object'); - 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, 'invalid IPv6'); + if (typeof config.ip !== 'string') return new BoxError(BoxError.BAD_FIELD, 'ipv6 must be a string'); + if (!net.isIPv6(config.ip)) return new BoxError(BoxError.BAD_FIELD, 'invalid IPv6'); return null; } diff --git a/src/routes/network.js b/src/routes/network.js index f2043df19..e1846cb9d 100644 --- a/src/routes/network.js +++ b/src/routes/network.js @@ -101,15 +101,15 @@ async function setIPv6Config(req, res, next) { } async function getIPv4(req, res, next) { - const [error, ipv4] = await safe(network.getIPv4()); + const [error, ip] = await safe(network.getIPv4()); if (error) return next(BoxError.toHttpError(error)); - next(new HttpSuccess(200, { ipv4 })); + next(new HttpSuccess(200, { ip })); } async function getIPv6(req, res, next) { - const [error, ipv6] = await safe(network.getIPv6()); // ignore any error + const [error, ip] = await safe(network.getIPv6()); // ignore any error if (error) return next(BoxError.toHttpError(error)); - next(new HttpSuccess(200, { ipv6 })); + next(new HttpSuccess(200, { ip })); }