@ -136,7 +136,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (void)disableProxy {
|
+ (void)disableProxy {
|
||||||
NSMutableArray* args = [@[@"--mode", @"off"]mutableCopy];
|
// 带上所有参数是为了判断是否原有代理设置是否由ssx-ng设置的。如果是用户手工设置的其他配置,则不进行清空。
|
||||||
|
NSString* urlString = [NSString stringWithFormat:@"%@/.ShadowsocksX-NG/gfwlist.js", NSHomeDirectory()];
|
||||||
|
NSURL* url = [NSURL fileURLWithPath:urlString];
|
||||||
|
NSUInteger port = [[NSUserDefaults standardUserDefaults]integerForKey:@"LocalSocks5.ListenPort"];
|
||||||
|
|
||||||
|
NSMutableArray* args = [@[@"--mode", @"off"
|
||||||
|
, @"--port", [NSString stringWithFormat:@"%lu", (unsigned long)port]
|
||||||
|
, @"--pac-url", [url absoluteString]
|
||||||
|
]mutableCopy];
|
||||||
[self addArguments4ManualSpecifyNetworkServices:args];
|
[self addArguments4ManualSpecifyNetworkServices:args];
|
||||||
[self callHelper:args];
|
[self callHelper:args];
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
#ifndef proxy_conf_helper_version_h
|
#ifndef proxy_conf_helper_version_h
|
||||||
#define proxy_conf_helper_version_h
|
#define proxy_conf_helper_version_h
|
||||||
|
|
||||||
#define kProxyConfHelperVersion @"1.2.0"
|
#define kProxyConfHelperVersion @"1.3.1"
|
||||||
|
|
||||||
#endif /* proxy_conf_helper_version_h */
|
#endif /* proxy_conf_helper_version_h */
|
||||||
|
@ -67,10 +67,6 @@ int main(int argc, const char * argv[])
|
|||||||
if (!portString) {
|
if (!portString) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
port = [portString integerValue];
|
|
||||||
if (0 == port) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else if (![@"off" isEqualToString:mode]) {
|
} else if (![@"off" isEqualToString:mode]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -79,6 +75,12 @@ int main(int argc, const char * argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (portString) {
|
||||||
|
port = [portString integerValue];
|
||||||
|
if (0 == port) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static AuthorizationRef authRef;
|
static AuthorizationRef authRef;
|
||||||
static AuthorizationFlags authFlags;
|
static AuthorizationFlags authFlags;
|
||||||
@ -126,11 +128,16 @@ int main(int argc, const char * argv[])
|
|||||||
|
|
||||||
if (modify) {
|
if (modify) {
|
||||||
|
|
||||||
|
NSString* prefPath = [NSString stringWithFormat:@"/%@/%@/%@", kSCPrefNetworkServices
|
||||||
|
, key, kSCEntNetProxies];
|
||||||
|
|
||||||
if ([mode isEqualToString:@"auto"]) {
|
if ([mode isEqualToString:@"auto"]) {
|
||||||
|
|
||||||
[proxies setObject:pacURL forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigURLString];
|
[proxies setObject:pacURL forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigURLString];
|
||||||
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigEnable];
|
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigEnable];
|
||||||
|
|
||||||
|
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||||
|
, (__bridge CFDictionaryRef)proxies);
|
||||||
} else if ([mode isEqualToString:@"global"]) {
|
} else if ([mode isEqualToString:@"global"]) {
|
||||||
|
|
||||||
|
|
||||||
@ -142,9 +149,29 @@ int main(int argc, const char * argv[])
|
|||||||
kCFNetworkProxiesSOCKSEnable];
|
kCFNetworkProxiesSOCKSEnable];
|
||||||
[proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
|
[proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
|
||||||
|
|
||||||
|
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||||
|
, (__bridge CFDictionaryRef)proxies);
|
||||||
|
} else if ([mode isEqualToString:@"off"]) {
|
||||||
|
if (pacURL != nil && portString != nil) {
|
||||||
|
// 取原来的配置,判断是否为shadowsocksX-NG设置的
|
||||||
|
NSDictionary* oldProxies
|
||||||
|
= (__bridge NSDictionary*)SCPreferencesPathGetValue(prefRef
|
||||||
|
, (__bridge CFStringRef)prefPath);
|
||||||
|
|
||||||
|
if (([oldProxies[(NSString *)kCFNetworkProxiesProxyAutoConfigURLString] isEqualToString:pacURL]
|
||||||
|
&&[oldProxies[(NSString *)kCFNetworkProxiesProxyAutoConfigEnable] isEqual:[NSNumber numberWithInt:1]])
|
||||||
|
||([oldProxies[(NSString*)kCFNetworkProxiesSOCKSProxy] isEqualToString:@"127.0.0.1"]
|
||||||
|
&&[oldProxies[(NSString*)kCFNetworkProxiesSOCKSPort] isEqualTo:[NSNumber numberWithInteger:port]]
|
||||||
|
&&[oldProxies[(NSString*)kCFNetworkProxiesSOCKSEnable] isEqual:[NSNumber numberWithInt:1]])
|
||||||
|
) {
|
||||||
|
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||||
|
, (__bridge CFDictionaryRef)proxies);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||||
|
, (__bridge CFDictionaryRef)proxies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)[NSString stringWithFormat:@"/%@/%@/%@", kSCPrefNetworkServices, key, kSCEntNetProxies], (__bridge CFDictionaryRef)proxies);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user