更新白名单模式

更新白名单模式,现在基于全局模式下使用ACL文件分流
TODO 基于ACL的自动和回国模式
This commit is contained in:
秦宇航
2017-05-07 12:58:18 +08:00
parent 7e045b9d9c
commit c1b37d4482
9 changed files with 3881 additions and 94 deletions
@@ -17,6 +17,7 @@
088EC3991D5F5BA300E40791 /* whiteiplist.pac in Resources */ = {isa = PBXBuildFile; fileRef = 088EC3981D5F5BA300E40791 /* whiteiplist.pac */; };
08BDBB481E2361BD00C4BBC2 /* VersionChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08BDBB471E2361BD00C4BBC2 /* VersionChecker.swift */; };
08CF21461E2A730E008F235D /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 08CF21451E2A730E008F235D /* LICENSE */; };
08F162BE1EBEDF0100C52869 /* chn.acl in Resources */ = {isa = PBXBuildFile; fileRef = 08F162BD1EBEDF0100C52869 /* chn.acl */; };
08FFAC621E437F6E00BDF137 /* PingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08FFAC611E437F6E00BDF137 /* PingTest.swift */; };
258E511BA910B0521B24DAB8 /* Pods_ShadowsocksX_NG.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 283ED1A8E9B711AC65670031 /* Pods_ShadowsocksX_NG.framework */; };
9B07EFA71D048BBB0052D9DF /* ss-local in Resources */ = {isa = PBXBuildFile; fileRef = 9B07EFA61D048BBB0052D9DF /* ss-local */; };
@@ -117,6 +118,7 @@
08AF56C01D6AFA7C00DC4F46 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/PreferencesWindowController.strings"; sourceTree = "<group>"; };
08BDBB471E2361BD00C4BBC2 /* VersionChecker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionChecker.swift; sourceTree = "<group>"; };
08CF21451E2A730E008F235D /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = SOURCE_ROOT; };
08F162BD1EBEDF0100C52869 /* chn.acl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = chn.acl; sourceTree = "<group>"; };
08FFAC611E437F6E00BDF137 /* PingTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PingTest.swift; sourceTree = "<group>"; };
19083CFCED87354F006967FF /* Pods_ShadowsocksX_NGUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ShadowsocksX_NGUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1E7783AEDB4A3BDDC9FF16AC /* libPods-proxy_conf_helper.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-proxy_conf_helper.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -269,6 +271,7 @@
9B3FFF4B1D09D8F70019A709 /* install_helper.sh */,
0880CE3F1D6FE6D900BD39E2 /* example-gui-config.json */,
9B3FFF281D08A1DF0019A709 /* user-rule.txt */,
08F162BD1EBEDF0100C52869 /* chn.acl */,
088EC3961D5F5B8600E40791 /* whitelist.pac */,
088EC3981D5F5BA300E40791 /* whiteiplist.pac */,
9B3FFF261D0898EB0019A709 /* gfwlist.txt */,
@@ -539,6 +542,7 @@
9B2491B71D0ACC3E003BBECC /* AdvPreferencesWindowController.xib in Resources */,
9B3FFF271D0898EB0019A709 /* gfwlist.txt in Resources */,
C6D429931DA75988002A5711 /* install_privoxy.sh in Resources */,
08F162BE1EBEDF0100C52869 /* chn.acl in Resources */,
9BC70EDC1D2E3E3100EDA4CA /* Localizable.strings in Resources */,
088EC3971D5F5B8600E40791 /* whitelist.pac in Resources */,
9B0BFFEE1D0460A70040E62B /* MainMenu.xib in Resources */,
+16 -26
View File
@@ -33,8 +33,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
@IBOutlet weak var globalModeMenuItem: NSMenuItem!
@IBOutlet weak var manualModeMenuItem: NSMenuItem!
@IBOutlet weak var whiteListModeMenuItem: NSMenuItem!
@IBOutlet weak var whiteListDomainMenuItem: NSMenuItem!
@IBOutlet weak var whiteListIPMenuItem: NSMenuItem!
// @IBOutlet weak var whiteListMenuItem: NSMenuItem!
// @IBOutlet weak var whiteListIPMenuItem: NSMenuItem!
@IBOutlet weak var serversMenuItem: NSMenuItem!
@IBOutlet var pingserverMenuItem: NSMenuItem!
@@ -86,7 +86,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
"LocalHTTP.ListenPort": NSNumber(value: 1087 as UInt16),
"LocalHTTPOn": true,
"LocalHTTP.FollowGlobal": true,
"AutoCheckUpdate": false
"AutoCheckUpdate": false,
"ACLPath": "chn.acl"
])
setUpMenu(defaults.bool(forKey: "enable_showSpeed"))
@@ -234,12 +235,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
} else if mode == "manual" {
ProxyConfHelper.disableProxy("hi")
ProxyConfHelper.disableProxy("hi")
} else if mode == "whiteListDomain" {
} else if mode == "whiteList" {
ProxyConfHelper.disableProxy("hi")
ProxyConfHelper.enableWhiteDomainListProxy()
} else if mode == "whiteListIP" {
ProxyConfHelper.disableProxy("hi")
ProxyConfHelper.enableWhiteIPListProxy()
ProxyConfHelper.enableGlobalProxy()//新白名单基于GlobalMode
}
} else {
StopSSLocal()
@@ -365,17 +363,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
updateRunningModeMenu()
applyConfig()
}
@IBAction func selectACLAutoMode(_ sender: NSMenuItem) {
@IBAction func selectWhiteDomainListMode(_ sender: NSMenuItem) {
let defaults = UserDefaults.standard
defaults.setValue("whiteListDomain", forKey: "ShadowsocksRunningMode")
updateRunningModeMenu()
applyConfig()
}
@IBAction func selectWhiteIPListMode(_ sender: NSMenuItem) {
@IBAction func selectACLWhiteListMode(_ sender: NSMenuItem) {
}
@IBAction func selectWhiteListMode(_ sender: NSMenuItem) {
let defaults = UserDefaults.standard
defaults.setValue("whiteListIP", forKey: "ShadowsocksRunningMode")
defaults.setValue("whiteList", forKey: "ShadowsocksRunningMode")
defaults.setValue("ACLPath", forKey: "chn.acl")
updateRunningModeMenu()
applyConfig()
}
@@ -509,8 +506,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
globalModeMenuItem.state = 0
manualModeMenuItem.state = 0
whiteListModeMenuItem.state = 0
whiteListDomainMenuItem.state = 0
whiteListIPMenuItem.state = 0
if mode == "auto" {
proxyMenuItem.title = "Proxy - Auto By PAC".localized
autoModeMenuItem.state = 1
@@ -520,14 +515,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
} else if mode == "manual" {
proxyMenuItem.title = "Proxy - Manual".localized
manualModeMenuItem.state = 1
} else if mode == "whiteListDomain" {
proxyMenuItem.title = "Proxy - White List Domain".localized
} else if mode == "whiteList" {
proxyMenuItem.title = "Proxy - White List".localized
whiteListModeMenuItem.state = 1
whiteListDomainMenuItem.state = 1
} else if mode == "whiteListIP" {
proxyMenuItem.title = "Proxy - White List IP".localized
whiteListModeMenuItem.state = 1
whiteListIPMenuItem.state = 1
}
updateStatusItemUI()
}
@@ -548,7 +538,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
} else if mode == "manual" {
image = NSImage(named: "menu_icon_manual")!
//statusItem?.title = "Manual".localized
} else if mode == "whiteListDomain" || mode == "whiteListIP" {
} else if mode == "whiteList" {
image = NSImage(named: "menu_icon_white")!
}
let titleWidth:CGFloat = 0//statusItem?.title!.size(withAttributes: [NSFontAttributeName: statusItem?.button!.font!]).width//这里不包含IP白名单模式等等,需要重新调整//PS还是给上游加上白名单模式?
+29 -44
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16E144f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12120" systemVersion="16F71b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12120"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -35,8 +35,6 @@
<outlet property="showQRCodeMenuItem" destination="R6A-96-Zcb" id="XHz-pz-nCz"/>
<outlet property="statusMenu" destination="Hob-KD-bx9" id="clA-ZW-0pT"/>
<outlet property="toggleRunningMenuItem" destination="GSu-Tf-StS" id="XHw-pU-nCa"/>
<outlet property="whiteListDomainMenuItem" destination="L27-aH-Wwl" id="h4b-aF-lyt"/>
<outlet property="whiteListIPMenuItem" destination="Xbu-Kq-BSR" id="D9i-Xg-6Gc"/>
<outlet property="whiteListModeMenuItem" destination="RvZ-Zn-29U" id="2v5-Bd-EDj"/>
</connections>
</customObject>
@@ -53,48 +51,34 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="LXP-yK-yQu"/>
<menuItem title="Proxy" id="diI-fB-Rss">
<menuItem title="Auto Mode By PAC" id="r07-Gu-aEz">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Proxy" id="YZp-bf-L40">
<connections>
<action selector="selectPACMode:" target="Voe-Tx-rLC" id="l36-cd-xl7"/>
</connections>
</menuItem>
<menuItem title="White List Mode" id="RvZ-Zn-29U">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectWhiteListMode:" target="Voe-Tx-rLC" id="2Q1-PG-9Yu"/>
</connections>
</menuItem>
<menuItem title="Global Mode" id="Mw3-Jm-eXA">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectGlobalMode:" target="Voe-Tx-rLC" id="7QH-HB-B2e"/>
</connections>
</menuItem>
<menuItem title="Manual Mode" id="8PR-gs-c5N">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectManualMode:" target="Voe-Tx-rLC" id="Xxb-28-6fi"/>
</connections>
</menuItem>
<menuItem title="Proxy Settings" id="diI-fB-Rss">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Proxy Settings" id="YZp-bf-L40">
<items>
<menuItem title="Auto Mode By PAC" id="r07-Gu-aEz">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectPACMode:" target="Voe-Tx-rLC" id="l36-cd-xl7"/>
</connections>
</menuItem>
<menuItem title="Global Mode" id="Mw3-Jm-eXA">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectGlobalMode:" target="Voe-Tx-rLC" id="7QH-HB-B2e"/>
</connections>
</menuItem>
<menuItem title="Manual Mode" id="8PR-gs-c5N">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectManualMode:" target="Voe-Tx-rLC" id="Xxb-28-6fi"/>
</connections>
</menuItem>
<menuItem title="White List Mode" id="RvZ-Zn-29U">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="White List Mode" id="nAe-c2-Q79">
<items>
<menuItem title="White List Domain" id="L27-aH-Wwl">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectWhiteDomainListMode:" target="Voe-Tx-rLC" id="Oge-mM-TtL"/>
</connections>
</menuItem>
<menuItem title="White List IP" id="Xbu-Kq-BSR">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="selectWhiteIPListMode:" target="Voe-Tx-rLC" id="Ahq-h9-jJP"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="V92-VH-Agn"/>
<menuItem title="Update PAC from GFW List" id="TFc-Ec-duM">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
@@ -123,6 +107,7 @@
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="WcX-Th-4eP"/>
<menuItem title="Servers" id="u5M-hQ-VSc">
<modifierMask key="keyEquivalentModifierMask" shift="YES"/>
<menu key="submenu" title="Servers" id="9Y1-db-3HK">
+12 -4
View File
@@ -8,7 +8,7 @@
import Foundation
let SS_LOCAL_VERSION = "2.5.6.4.static"
let SS_LOCAL_VERSION = "2.5.6.5.static"
let PRIVOXY_VERSION = "3.0.26.static"
let APP_SUPPORT_DIR = "/Library/Application Support/ShadowsocksX-NG/"
let LAUNCH_AGENT_DIR = "/Library/LaunchAgents/"
@@ -33,7 +33,7 @@ func generateSSLocalLauchAgentPlist() -> Bool {
let logFilePath = NSHomeDirectory() + "/Library/Logs/ss-local.log"
let launchAgentDirPath = NSHomeDirectory() + LAUNCH_AGENT_DIR
let plistFilepath = launchAgentDirPath + LAUNCH_AGENT_CONF_SSLOCAL_NAME
var ACLPath = ""
// Ensure launch agent directory is existed.
let fileMgr = FileManager.default
if !fileMgr.fileExists(atPath: launchAgentDirPath) {
@@ -45,6 +45,8 @@ func generateSSLocalLauchAgentPlist() -> Bool {
let defaults = UserDefaults.standard
let enableUdpRelay = defaults.bool(forKey: "LocalSocks5.EnableUDPRelay")
let enableVerboseMode = defaults.bool(forKey: "LocalSocks5.EnableVerboseMode")
let enabelWhiteListMode = defaults.value(forKey: "ShadowsocksRunningMode") as! String
print(enabelWhiteListMode )
var arguments = [sslocalPath, "-c", "ss-local-config.json"]
if enableUdpRelay {
@@ -53,6 +55,11 @@ func generateSSLocalLauchAgentPlist() -> Bool {
if enableVerboseMode {
arguments.append("-v")
}
if String(describing: enabelWhiteListMode) == "whiteList" {
ACLPath = defaults.value(forKey: "ACLPath") as! String
arguments.append("--acl")
arguments.append(ACLPath)
}
// For a complete listing of the keys, see the launchd.plist manual page.
let dict: NSMutableDictionary = [
@@ -161,8 +168,9 @@ func SyncSSLocal() {
changed = changed || generateSSLocalLauchAgentPlist()
let mgr = ServerProfileManager.instance
if mgr.activeProfileId != nil {
changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!)
if mgr.getActiveProfile() != nil {
changed = changed || writeSSLocalConfFile((mgr.getActiveProfile()?.toJsonConfig())!)
}
let on = UserDefaults.standard.bool(forKey: "ShadowsocksOn")
if on {
StartSSLocal()
+1 -3
View File
@@ -24,8 +24,6 @@
+ (void)stopPACServer;
+ (void)enableWhiteDomainListProxy;
+ (void)enableWhiteIPListProxy;
+ (void)enableWhiteListProxy;
@end
+13 -16
View File
@@ -146,26 +146,23 @@ GCDWebServer *webServer = nil;
[self stopPACServer];
}
+ (void)enableWhiteDomainListProxy {
// NSString* urlString = [NSString stringWithFormat:@"%@/.ShadowsocksX-NG/whitelist.pac", NSHomeDirectory()];
// NSURL* url = [NSURL fileURLWithPath:urlString];
NSString *PACURLString = [self startPACServer: @"whitelist.pac"];//hi 可以切换成定制pac文件路径来达成使用定制文件路径
NSURL* url = [NSURL URLWithString: PACURLString];
NSMutableArray* args = [@[@"--mode", @"auto", @"--pac-url", [url absoluteString]]mutableCopy];
+ (void)enableWhiteListProxy {
// 基于全局socks5代理下使用ACL文件来进行白名单代理 不需要使用pac文件
NSUInteger port = [[NSUserDefaults standardUserDefaults]integerForKey:@"LocalSocks5.ListenPort"];
[self addArguments4ManualSpecifyNetworkServices:args];
[self callHelper:args];
}
+ (void)enableWhiteIPListProxy {
// NSString* urlString = [NSString stringWithFormat:@"%@/.ShadowsocksX-NG/whiteiplist.pac", NSHomeDirectory()];
// NSURL* url = [NSURL fileURLWithPath:urlString];
NSString *PACURLString = [self startPACServer: @"whiteiplist.pac"];//hi 可以切换成定制pac文件路径来达成使用定制文件路径
NSURL* url = [NSURL URLWithString: PACURLString];
NSMutableArray* args = [@[@"--mode", @"auto", @"--pac-url", [url absoluteString]]mutableCopy];
NSMutableArray* args = [@[@"--mode", @"global", @"--port"
, [NSString stringWithFormat:@"%lu", (unsigned long)port]]mutableCopy];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LocalHTTPOn"] && [[NSUserDefaults standardUserDefaults] boolForKey:@"LocalHTTP.FollowGlobal"]) {
NSUInteger privoxyPort = [[NSUserDefaults standardUserDefaults]integerForKey:@"LocalHTTP.ListenPort"];
[args addObject:@"--privoxy-port"];
[args addObject:[NSString stringWithFormat:@"%lu", (unsigned long)privoxyPort]];
}
[self addArguments4ManualSpecifyNetworkServices:args];
[self callHelper:args];
[self stopPACServer];
}
+ (void)disableProxy:(NSString*) PACFilePath {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -8,7 +8,7 @@
cd `dirname "${BASH_SOURCE[0]}"`
ssLocalVersion=2.5.6.4.static
ssLocalVersion=2.5.6.5.static
mkdir -p "$HOME/Library/Application Support/ShadowsocksX-NG/ss-local-$ssLocalVersion"
cp -f ss-local "$HOME/Library/Application Support/ShadowsocksX-NG/ss-local-$ssLocalVersion/"
rm -f "$HOME/Library/Application Support/ShadowsocksX-NG/ss-local"
Binary file not shown.