const isTargetReachable = async target => { const url = new URL(prependHttp(target)); if (!url.port) { url.port = url.protocol === 'http:' ? 80 : 443; } let address; try { address = await getAddress(url.hostname); } catch (_) { return false; } if (!address || routerIps.has(address)) { return false; } if ([80, 443].includes(url.port)) { return checkHttp(url.toString()); } return isPortReachable(url.port, {host: address}); }
const replacePhonebooksVars = (config, phonebooks) => { phonebooks.forEach((element, id) => { const maskUrl = '{{' + ( ['phonebook', id + 1, 'url'].join('_') ) + '}}'; // console.log('mask url', maskUrl); const pbUrl = url(element.url); config = config.replace(maskUrl, pbUrl['host'] + pbUrl['pathname'] + pbUrl['query'] + pbUrl['hash']); const maskProtocol = '{{' + ( ['phonebook', id + 1, 'protocol'].join('_') ) + '}}'; const protocol = url(element.url).protocol === 'https:' ? '3' : '1'; config = config.replace(maskProtocol, protocol); const maskFullUrl = '{{' + ( ['phonebook', id + 1, 'fullurl'].join('_') ) + '}}'; config = config.replace(maskFullUrl, element.url); const maskName = '{{' + ( ['phonebook', id + 1, 'name'].join('_') ) + '}}'; config = config.replace(maskName, element.name); }); return config; }