/* Copyright 2019 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ function linux_getProxy() { // Check Environment Variabels if(require('fs').existsSync('/etc/environment')) { var child = require('child_process').execFile('/bin/sh', ['sh']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stdin.write('cat /etc/environment | grep = | ' + "tr '\\n' '`' | awk -F'`' '"); child.stdin.write('{'); child.stdin.write(' host=""; port=""; username=""; password=""; ') child.stdin.write(' for(i=1;i1 && split($i, dummy4, "#")==1)'); child.stdin.write(' {'); child.stdin.write(' if(split($i,key1,"=")==1)'); child.stdin.write(' {'); child.stdin.write(' split($i,key2,":");'); child.stdin.write(' if(key2[2]!="\\\\")'); child.stdin.write(' {'); child.stdin.write(' printf "%s\\"%s\\": null",(firstprop==0?",":""),key2[2];'); child.stdin.write(' firstprop=0;') child.stdin.write(' }'); child.stdin.write(' }'); child.stdin.write(' else'); child.stdin.write(' {'); child.stdin.write(' tmp = substr($i,2+length(key1[1]));'); child.stdin.write(' split(tmp,dummy,"\\\\");'); child.stdin.write(' tmp=substr(tmp,0,length(tmp)-2);'); child.stdin.write(' split(key1[1],keyname,":");'); child.stdin.write(' printf "%s\\"%s\\": \\"%s\\"", (firstprop==0?",":""), keyname[2], tmp;'); child.stdin.write(' firstprop=0;'); child.stdin.write(' }'); child.stdin.write(' }'); child.stdin.write(' }'); child.stdin.write(' }'); child.stdin.write(' if(group!="") { printf "}"; }') child.stdin.write(' printf "}";'); child.stdin.write("}'"); child.stdin.write('\nexit\n'); child.waitExit(); if (child.stdout.str.trim() != '') { var config = null; try { config = JSON.parse(child.stdout.str); } catch (e) { } if(config) { // check root if(config.root && config.root.setenv) { var i, tokens; var items = config.root.setenv.split(','); for(i=0;i 5 && !entries.subkeys[i].endsWith('_Classes')) { key = entries.subkeys[i]; break; } } } } } else { // We are a logged in user key = require('win-registry').usernameToUserKey(i.name); } if (!key) { throw ('Could not determine which user proxy setting to query'); } return (key); } function windows_proxyCheck(key, checkAddr) { if (!key) { key = windows_getUserRegistryKey(); } var proxyOverride = require('win-registry').QueryKey(require('win-registry').HKEY.Users, key + '\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride').split(';'); for(var i in proxyOverride) { proxyOverride[i] = proxyOverride[i].trim(); if ((checkAddr == '127.0.0.1' || checkAddr == '::1') && proxyOverride[i] == '') { return (true); } if (checkAddr == proxyOverride[i]) { return (true); } // Exact Match if (proxyOverride[i].startsWith('*.') && checkAddr.endsWith(proxyOverride[i].substring(1))) { return (true); } if (proxyOverride[i].endsWith('.*') && checkAddr.startsWith(proxyOverride[i].substring(0, proxyOverride[i].length - 1))) { return (true); } } return (false); } function macos_getProxy() { var child = require('child_process').execFile('/bin/sh', ['sh']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); child.stdin.write("scutil --proxy | tr '\\n' '`' | awk -F'`' '"); child.stdin.write('{'); child.stdin.write(' pstart=0;') child.stdin.write(' for(i=1;i1)'); child.stdin.write(" {"); child.stdin.write(' printf "{ \\"exceptions\\": [";'); child.stdin.write(' ++i;'); child.stdin.write(' fstart=1; pstart=1;'); child.stdin.write(' for(;i1) { break; } '); child.stdin.write(' split($i, val, " : ");'); child.stdin.write(' printf "%s\\"%s\\"", (fstart==0?",":""), val[2];'); child.stdin.write(' fstart=0;'); child.stdin.write(' }'); child.stdin.write(' printf "]";'); child.stdin.write(' continue;'); child.stdin.write(" }"); child.stdin.write(' else'); child.stdin.write(' {'); child.stdin.write(' if(pstart==1 && split($i,dummy,"}")==1)'); child.stdin.write(' {'); child.stdin.write(' split($i,tok," : ");'); child.stdin.write(' split(tok[1],key," ");'); child.stdin.write(' printf ",\\"%s\\": \\"%s\\"", key[1], tok[2];'); child.stdin.write(' }'); child.stdin.write(' }') child.stdin.write(" }"); child.stdin.write(' printf "}";'); child.stdin.write("}'\nexit\n"); child.waitExit(); if(child.stdout.str != '') { try { var p = JSON.parse(child.stdout.str); if(p.HTTPEnable == "1") { return('http://' + p.HTTPProxy + ':' + p.HTTPPort); } } catch(e) { console.log(e); } } throw ('No Proxies'); } function windows_getProxy() { var isroot = false; var key, value; key = windows_getUserRegistryKey(); try { if (require('win-registry').QueryKey(require('win-registry').HKEY.Users, key + '\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable') == 1) { // Proxy is enabled return (require('win-registry').QueryKey(require('win-registry').HKEY.Users, key + '\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer')); } } catch(e) { throw ('No proxies'); } } switch (process.platform) { case 'linux': case 'freebsd': module.exports = { ignoreProxy: posix_proxyCheck, getProxy: linux_getProxy }; break; case 'win32': module.exports = { ignoreProxy: windows_proxyCheck, getProxy: windows_getProxy }; break; case 'darwin': module.exports = { getProxy: macos_getProxy }; break; }