mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-10 14:58:27 +00:00
tweak
This commit is contained in:
parent
052a75f120
commit
bdca110890
@ -3,19 +3,19 @@ var child_process = require('child_process');
|
|||||||
var networkTypes = ['Ethernet', 'Thunderbolt Ethernet', 'Wi-Fi'];
|
var networkTypes = ['Ethernet', 'Thunderbolt Ethernet', 'Wi-Fi'];
|
||||||
|
|
||||||
function execSync(cmd) {
|
function execSync(cmd) {
|
||||||
var stdout, status = 0;
|
var stdout, status = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stdout = child_process.execSync(cmd);
|
stdout = child_process.execSync(cmd);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
stdout = err.stdout;
|
stdout = err.stdout;
|
||||||
status = err.status;
|
status = err.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stdout: stdout.toString(),
|
stdout: stdout.toString(),
|
||||||
status: status
|
status: status
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -54,68 +54,68 @@ var macProxyManager = {};
|
|||||||
|
|
||||||
macProxyManager.getNetworkType = function() {
|
macProxyManager.getNetworkType = function() {
|
||||||
|
|
||||||
for (var i = 0; i < networkTypes.length; i++) {
|
for (var i = 0; i < networkTypes.length; i++) {
|
||||||
|
|
||||||
var
|
var
|
||||||
type = networkTypes[i],
|
type = networkTypes[i],
|
||||||
result = execSync('networksetup -getwebproxy ' + type);
|
result = execSync('networksetup -getwebproxy ' + type);
|
||||||
|
|
||||||
if (result.status === 0) {
|
if (result.status === 0) {
|
||||||
macProxyManager.networkType = type;
|
macProxyManager.networkType = type;
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Unknown network type');
|
throw new Error('Unknown network type');
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.enableGlobalProxy = function(ip, port) {
|
macProxyManager.enableGlobalProxy = function(ip, port) {
|
||||||
|
|
||||||
if (!ip && !port) {
|
if (!ip && !port) {
|
||||||
console.log('proxy server\'s ip and port is required');
|
console.log('proxy server\'s ip and port is required');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
var result = execSync(
|
||||||
|
|
||||||
// set http proxy
|
// set http proxy
|
||||||
'sudo networksetup -setwebproxy ${networkType} ${ip} ${port}; '
|
'sudo networksetup -setwebproxy ${networkType} ${ip} ${port}; '
|
||||||
.replace("${networkType}", networkType)
|
.replace("${networkType}", networkType)
|
||||||
.replace("${ip}", ip)
|
.replace("${ip}", ip)
|
||||||
.replace("${port}", port) +
|
.replace("${port}", port) +
|
||||||
|
|
||||||
// set https proxy
|
// set https proxy
|
||||||
'sudo networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
'sudo networksetup -setsecurewebproxy ${networkType} ${ip} ${port}'
|
||||||
.replace("${networkType}", networkType)
|
.replace("${networkType}", networkType)
|
||||||
.replace("${ip}", ip)
|
.replace("${ip}", ip)
|
||||||
.replace("${port}", port));
|
.replace("${port}", port));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.disableGlobalProxy = function() {
|
macProxyManager.disableGlobalProxy = function() {
|
||||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
|
|
||||||
var result = execSync(
|
var result = execSync(
|
||||||
|
|
||||||
// disable http proxy
|
// disable http proxy
|
||||||
'sudo networksetup -setwebproxystate ${networkType} off; '
|
'sudo networksetup -setwebproxystate ${networkType} off; '
|
||||||
.replace(/\$\{networkType\}/g, networkType) +
|
.replace(/\$\{networkType\}/g, networkType) +
|
||||||
|
|
||||||
// disable https proxy
|
// disable https proxy
|
||||||
'sudo networksetup -setsecurewebproxystate ${networkType} off'
|
'sudo networksetup -setsecurewebproxystate ${networkType} off'
|
||||||
.replace(/\$\{networkType\}/g, networkType));
|
.replace(/\$\{networkType\}/g, networkType));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
macProxyManager.getProxyState = function() {
|
macProxyManager.getProxyState = function() {
|
||||||
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
var networkType = macProxyManager.networkType || macProxyManager.getNetworkType();
|
||||||
var result = execSync('networksetup -getwebproxy ${networkType}'.replace('${networkType}', networkType));
|
var result = execSync('networksetup -getwebproxy ${networkType}'.replace('${networkType}', networkType));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -123,6 +123,8 @@ macProxyManager.getProxyState = function() {
|
|||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
* windows proxy manager
|
* windows proxy manager
|
||||||
|
*
|
||||||
|
* netsh does not alter the settings for IE
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -130,33 +132,33 @@ var winProxyManager = {};
|
|||||||
|
|
||||||
winProxyManager.enableGlobalProxy = function(ip, port) {
|
winProxyManager.enableGlobalProxy = function(ip, port) {
|
||||||
|
|
||||||
if (!ip && !port) {
|
if (!ip && !port) {
|
||||||
console.log('proxy server\'s ip and port is required');
|
console.log('proxy server\'s ip and port is required');
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
return execSync(
|
return execSync(
|
||||||
|
|
||||||
// set proxy
|
// set proxy
|
||||||
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer /t REG_SZ /d ${ip}:${port} /f & '
|
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyServer /t REG_SZ /d ${ip}:${port} /f & '
|
||||||
.replace("${ip}", ip)
|
.replace("${ip}", ip)
|
||||||
.replace("${port}", port) +
|
.replace("${port}", port) +
|
||||||
|
|
||||||
// enable proxy
|
// enable proxy
|
||||||
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f');
|
'reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f');
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
winProxyManager.disableGlobalProxy = function() {
|
winProxyManager.disableGlobalProxy = function() {
|
||||||
return execSync('reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f');
|
return execSync('reg add "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f');
|
||||||
};
|
};
|
||||||
|
|
||||||
winProxyManager.getProxyState = function() {
|
winProxyManager.getProxyState = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
winProxyManager.getNetworkType = function() {
|
winProxyManager.getNetworkType = function() {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = /^win/.test(process.platform) ? winProxyManager : macProxyManager;
|
module.exports = /^win/.test(process.platform) ? winProxyManager : macProxyManager;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user