mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-04-30 21:21:42 +03:00
Show list of addresses
This commit is contained in:
parent
f379d34813
commit
31b855f9ab
9 changed files with 166 additions and 72 deletions
client/src/helpers
|
@ -4,7 +4,7 @@ import subHours from 'date-fns/sub_hours';
|
|||
import addHours from 'date-fns/add_hours';
|
||||
import round from 'lodash/round';
|
||||
|
||||
import { STATS_NAMES } from './constants';
|
||||
import { STATS_NAMES, STANDARD_DNS_PORT } from './constants';
|
||||
|
||||
export const formatTime = (time) => {
|
||||
const parsedTime = dateParse(time);
|
||||
|
@ -85,3 +85,46 @@ export const getPercent = (amount, number) => {
|
|||
};
|
||||
|
||||
export const captitalizeWords = text => text.split(/[ -_]/g).map(str => str.charAt(0).toUpperCase() + str.substr(1)).join(' ');
|
||||
|
||||
export const getInterfaceIp = (option) => {
|
||||
const onlyIPv6 = option.ip_addresses.every(ip => ip.includes(':'));
|
||||
let interfaceIP = option.ip_addresses[0];
|
||||
|
||||
if (!onlyIPv6) {
|
||||
option.ip_addresses.forEach((ip) => {
|
||||
if (!ip.includes(':')) {
|
||||
interfaceIP = ip;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return interfaceIP;
|
||||
};
|
||||
|
||||
export const getIpList = (interfaces) => {
|
||||
let list = [];
|
||||
|
||||
Object.keys(interfaces).forEach((item) => {
|
||||
list = [...list, ...interfaces[item].ip_addresses];
|
||||
});
|
||||
|
||||
return list.sort();
|
||||
};
|
||||
|
||||
export const getAddress = (ip, port = '', isDns = false) => {
|
||||
if (!port) {
|
||||
return isDns ? ip : `http://${ip}`;
|
||||
}
|
||||
|
||||
if (isDns) {
|
||||
if (ip.includes(':') && port !== STANDARD_DNS_PORT) {
|
||||
return `[${ip}]:${port}`;
|
||||
} else if (port !== STANDARD_DNS_PORT) {
|
||||
return `${ip}:${port}`;
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
return ip.includes(':') ? `http://[${ip}]:${port}` : `http://${ip}:${port}`;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue