Skip to content

Commit

Permalink
添加忽略代理配置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
wzdnzd committed May 7, 2020
1 parent c0625f5 commit 911ae23
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 32 deletions.
77 changes: 51 additions & 26 deletions ShadowsocksX-NG/Base.lproj/AdvPreferencesWindowController.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ShadowsocksX-NG/Configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ static NSString * const USERDEFAULTS_TIME_INTERAVAL_DALAY_TEST_ENABLE = @"TimeIn
static NSString * const USERDEFAULTS_TIME_INTERAVAL_SUBSCRIBE_UPDATE_ENABLE = @"TimeInteraval.SubscribeUpdateEnable";
static NSString * const USERDEFAULTS_TIME_INTERAVAL_DALAY_TEST_TIME = @"TimeInteraval.DelayTestTime";
static NSString * const USERDEFAULTS_TIME_INTERAVAL_SUBSCRIBE_UPDATE_TIME = @"TimeInteraval.SubscribeUpdateTime";
static NSString * const USERDEFAULTS_PROXY_EXCEPTIONS = @"ProxyExceptions";

#endif /* Configure_h */
2 changes: 1 addition & 1 deletion ShadowsocksX-NG/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
5 changes: 4 additions & 1 deletion ShadowsocksX-NG/MainMenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class MainMenuManager: NSObject, NSUserNotificationCenterDelegate {
USERDEFAULTS_TIME_INTERAVAL_DALAY_TEST_ENABLE: true,
USERDEFAULTS_TIME_INTERAVAL_SUBSCRIBE_UPDATE_ENABLE: true,
USERDEFAULTS_TIME_INTERAVAL_DALAY_TEST_TIME: NSNumber(value: 30 as UInt16),
USERDEFAULTS_TIME_INTERAVAL_SUBSCRIBE_UPDATE_TIME: NSNumber(value: 3 as UInt16)
USERDEFAULTS_TIME_INTERAVAL_SUBSCRIBE_UPDATE_TIME: NSNumber(value: 3 as UInt16),
USERDEFAULTS_PROXY_EXCEPTIONS: "127.0.0.1,localhost"
])

let notifyCenter = NotificationCenter.default
Expand Down Expand Up @@ -845,13 +846,15 @@ class MainMenuManager: NSObject, NSUserNotificationCenterDelegate {
speedMonitor = NetSpeedMonitor()
}
statusItem?.length = 85
if speedTimer == nil {
speedTimer = Timer(timeInterval: repeatTimeinterval, repeats: true) {[weak self] (timer) in
guard let w = self else {return}
w.speedMonitor?.timeInterval(w.repeatTimeinterval, downloadAndUploadSpeed: { (down, up) in
w.statusItemView.setRateData(up: Float(up), down: Float(down))
})
}
RunLoop.main.add(speedTimer!, forMode: RunLoop.Mode.common)
}
}else{
speedTimer?.invalidate()
speedTimer = nil
Expand Down
23 changes: 23 additions & 0 deletions ShadowsocksX-NG/ProxyConfHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ + (void)addArguments4ManualSpecifyNetworkServices:(NSMutableArray*) args {
}
}

+ (void)addArguments4ManualSpecifyProxyExceptions:(NSMutableArray*) args {
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];

NSString* rawExceptions = [defaults stringForKey:USERDEFAULTS_PROXY_EXCEPTIONS];
if (rawExceptions) {
NSCharacterSet* whites = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSMutableCharacterSet* seps = [NSMutableCharacterSet characterSetWithCharactersInString:@",、"];
[seps formUnionWithCharacterSet:whites];

NSArray* exceptions = [rawExceptions componentsSeparatedByCharactersInSet:seps];
for (NSString* domainOrHost in exceptions) {
if ([domainOrHost length] > 0) {
[args addObject:@"-x"];
[args addObject:domainOrHost];
}
}
}
}

+ (void)enablePACProxy:(NSString*) PACFilePath {
//start server here and then using the string next line
//next two lines can open gcdwebserver and work around pac file
Expand All @@ -126,6 +145,7 @@ + (void)enablePACProxy:(NSString*) PACFilePath {
NSMutableArray* args = [@[@"--mode", @"auto", @"--pac-url", [url absoluteString]]mutableCopy];

[self addArguments4ManualSpecifyNetworkServices:args];
[self addArguments4ManualSpecifyProxyExceptions:args];
[self callHelper:args];
}

Expand All @@ -143,6 +163,7 @@ + (void)enableGlobalProxy {
}

[self addArguments4ManualSpecifyNetworkServices:args];
[self addArguments4ManualSpecifyProxyExceptions:args];
[self callHelper:args];
[self stopPACServer];
}
Expand All @@ -162,13 +183,15 @@ + (void)enableWhiteListProxy {
}

[self addArguments4ManualSpecifyNetworkServices:args];
[self addArguments4ManualSpecifyProxyExceptions:args];
[self callHelper:args];
[self stopPACServer];
}

+ (void)disableProxy:(NSString*) PACFilePath {
NSMutableArray* args = [@[@"--mode", @"off"]mutableCopy];
[self addArguments4ManualSpecifyNetworkServices:args];
[self addArguments4ManualSpecifyProxyExceptions:args];
[self callHelper:args];
[self stopPACServer];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@

/* Class = "NSButtonCell"; title = "Enable Verbose Mode"; ObjectID = "dCD-gg-I2i"; */
"dCD-gg-I2i.title" = "启用 Verbose 模式";

"xcB-yu-ghf.title" = "忽略代理"
12 changes: 8 additions & 4 deletions proxy_conf_helper/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, const char * argv[])
NSString* privoxyPortString;

BRLOptionParser *options = [BRLOptionParser new];
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>] [-r <port>]", argv[0]];
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>] [-l <socks5-listen-address>] [-r <port>] [-p <privoxy-listen-address>] [-x <exception>]", argv[0]];

// Version
[options addOption:"version" flag:'v' description:@"Print the version number." block:^{
Expand Down Expand Up @@ -53,6 +53,11 @@ int main(int argc, const char * argv[])
[networkServiceKeys addObject:value];
}];

NSMutableSet* proxyExceptions = [NSMutableSet set];
[options addOption:"proxy-exception" flag:'x' description:@"Bypass proxy settings for this Host / Domain" blockWithArgument:^(NSString *value) {
[proxyExceptions addObject:value];
}];

NSError *error = nil;
if (![options parseArgc:argc argv:argv error:&error]) {
const char * message = error.localizedDescription.UTF8String;
Expand Down Expand Up @@ -149,15 +154,14 @@ int main(int argc, const char * argv[])
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
, (__bridge CFDictionaryRef)proxies);
} else if ([mode isEqualToString:@"global"]) {


[proxies setObject:@"127.0.0.1" forKey:(NSString *)
kCFNetworkProxiesSOCKSProxy];
[proxies setObject:[NSNumber numberWithInteger:port] forKey:(NSString*)
kCFNetworkProxiesSOCKSPort];
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*)
kCFNetworkProxiesSOCKSEnable];
[proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
// [proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
[proxies setObject:[proxyExceptions allObjects] forKey:(NSString *)kCFNetworkProxiesExceptionsList];

if (privoxyPort != 0) {
[proxies setObject:@"127.0.0.1" forKey:(NSString *)
Expand Down

0 comments on commit 911ae23

Please sign in to comment.