/* 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 e = require('fs').readFileSync('/etc/environment').toString(); var tokens = e.split('\\n'); for(var line in tokens) { var val = tokens[line].split('='); if(val.length == 2 && (val[0].trim() == 'http_proxy' || val[0].trim() == 'https_proxy')) { return(val[1].split('//')[1]); } } } // Check profile.d if(require('fs').existsSync('/etc/profile.d/proxy_setup')) { 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/profile.d/proxy_setup | awk '" + '{ split($2, tok, "="); if(tok[1]=="http_proxy") { print tok[2]; }}\'\nexit\n'); child.waitExit(); child.ret = child.stdout.str.trim().split('\n')[0].split('//')[1]; if(child.ret != '') { return(child.ret); } } // Check gsettings if (require('fs').existsSync('/usr/bin/gsettings')) { var setting; var ids = require('user-sessions').loginUids(); for (var i in ids) { setting = require('linux-gnome-helpers').getProxySettings(ids[i]); if (setting.mode == 'manual') { return(setting.host + ':' + setting.port);} } } if (require('fs').existsSync('/etc/apt/apt.conf.d/proxy.conf')) { var child = require('child_process').execFile('/bin/sh', ['sh']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stderr.on('data', function (c) { console.log(c.toString()); }); child.stdin.write("cat /etc/apt/apt.conf.d/proxy.conf | tr '\\n' '`' | awk -F'`' '{"); child.stdin.write('for(n=1;n5 && !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');} } 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); } switch (process.platform) { case 'linux': case 'freebsd': module.exports = { ignoreProxy: posix_proxyCheck, getProxy: linux_getProxy }; break; case 'win32': module.exports = { ignoreProxy: windows_proxyCheck }; break; case 'darwin': break; }