增加 HTTP代理 跟随全局设置
This commit is contained in:
@ -22,9 +22,10 @@ int main(int argc, const char * argv[])
|
||||
NSString* mode;
|
||||
NSString* pacURL;
|
||||
NSString* portString;
|
||||
NSString* privoxyPortString;
|
||||
|
||||
BRLOptionParser *options = [BRLOptionParser new];
|
||||
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>]", argv[0]];
|
||||
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>] [-r <port>]", argv[0]];
|
||||
|
||||
// Version
|
||||
[options addOption:"version" flag:'v' description:@"Print the version number." block:^{
|
||||
@ -40,11 +41,13 @@ int main(int argc, const char * argv[])
|
||||
}];
|
||||
|
||||
// Mode
|
||||
[options addOption:"mode" flag:'m' description:@"Proxy mode, may be: auto,blobal,off" argument:&mode];
|
||||
[options addOption:"mode" flag:'m' description:@"Proxy mode, may be: auto,global,off" argument:&mode];
|
||||
|
||||
[options addOption:"pac-url" flag:'u' description:@"PAC file url for auto mode." argument:&pacURL];
|
||||
[options addOption:"port" flag:'p' description:@"Listen port for global mode." argument:&portString];
|
||||
|
||||
[options addOption:"privoxy-port" flag:'r' description:@"Privoxy Port for global mode." argument:&privoxyPortString];
|
||||
|
||||
NSMutableSet* networkServiceKeys = [NSMutableSet set];
|
||||
[options addOption:"network-service" flag:'n' description:@"Manual specify the network profile need to set proxy." blockWithArgument:^(NSString* value){
|
||||
[networkServiceKeys addObject:value];
|
||||
@ -57,7 +60,6 @@ int main(int argc, const char * argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NSInteger port = 0;
|
||||
if (mode) {
|
||||
if ([@"auto" isEqualToString:mode]) {
|
||||
if (!pacURL) {
|
||||
@ -75,6 +77,7 @@ int main(int argc, const char * argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSInteger port = 0;
|
||||
if (portString) {
|
||||
port = [portString integerValue];
|
||||
if (0 == port) {
|
||||
@ -82,6 +85,14 @@ int main(int argc, const char * argv[])
|
||||
}
|
||||
}
|
||||
|
||||
NSInteger privoxyPort = 0;
|
||||
if (privoxyPortString) {
|
||||
privoxyPort = [privoxyPortString integerValue];
|
||||
if (0 == privoxyPort) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static AuthorizationRef authRef;
|
||||
static AuthorizationFlags authFlags;
|
||||
authFlags = kAuthorizationFlagDefaults
|
||||
@ -149,6 +160,22 @@ int main(int argc, const char * argv[])
|
||||
kCFNetworkProxiesSOCKSEnable];
|
||||
[proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
|
||||
|
||||
if (privoxyPort != 0) {
|
||||
[proxies setObject:@"127.0.0.1" forKey:(NSString *)
|
||||
kCFNetworkProxiesHTTPProxy];
|
||||
[proxies setObject:[NSNumber numberWithInteger:privoxyPort] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPPort];
|
||||
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPEnable];
|
||||
|
||||
[proxies setObject:@"127.0.0.1" forKey:(NSString *)
|
||||
kCFNetworkProxiesHTTPSProxy];
|
||||
[proxies setObject:[NSNumber numberWithInteger:privoxyPort] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPSPort];
|
||||
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPSEnable];
|
||||
}
|
||||
|
||||
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||
, (__bridge CFDictionaryRef)proxies);
|
||||
} else if ([mode isEqualToString:@"off"]) {
|
||||
|
Reference in New Issue
Block a user