避免清空不是由ShadowsocksX-NG设置代理配置。
This commit is contained in:
Charlie Qiu
2016-08-04 00:41:00 +08:00
parent f096ed2b23
commit 245770afcf
3 changed files with 43 additions and 8 deletions
+9 -1
View File
@@ -136,7 +136,15 @@
}
+ (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 callHelper:args];
}
+1 -1
View File
@@ -9,6 +9,6 @@
#ifndef 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 */
+33 -6
View File
@@ -67,10 +67,6 @@ int main(int argc, const char * argv[])
if (!portString) {
return 1;
}
port = [portString integerValue];
if (0 == port) {
return 1;
}
} else if (![@"off" isEqualToString:mode]) {
return 1;
}
@@ -79,6 +75,12 @@ int main(int argc, const char * argv[])
return 0;
}
if (portString) {
port = [portString integerValue];
if (0 == port) {
return 1;
}
}
static AuthorizationRef authRef;
static AuthorizationFlags authFlags;
@@ -126,11 +128,16 @@ int main(int argc, const char * argv[])
if (modify) {
NSString* prefPath = [NSString stringWithFormat:@"/%@/%@/%@", kSCPrefNetworkServices
, key, kSCEntNetProxies];
if ([mode isEqualToString:@"auto"]) {
[proxies setObject:pacURL forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigURLString];
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString *)kCFNetworkProxiesProxyAutoConfigEnable];
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
, (__bridge CFDictionaryRef)proxies);
} else if ([mode isEqualToString:@"global"]) {
@@ -142,9 +149,29 @@ int main(int argc, const char * argv[])
kCFNetworkProxiesSOCKSEnable];
[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);
}
}