From 36d59645d94547b3d9ef7e3dd9e205c4a0ab6317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E5=AE=87=E8=88=AA?= Date: Sun, 14 May 2017 08:32:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BF=9C?= =?UTF-8?q?=E7=AB=AFACL=E6=96=87=E4=BB=B6=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowsocksX-NG/AppDelegate.swift | 7 +- .../AdvPreferencesWindowController.xib | 251 +++++++++++------- ShadowsocksX-NG/PACUtils.swift | 38 +-- .../AdvPreferencesWindowController.strings | 4 +- 4 files changed, 161 insertions(+), 139 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 60b0e7c..f9e982e 100644 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -80,8 +80,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele "LocalSocks5.EnableUDPRelay": NSNumber(value: false as Bool), "LocalSocks5.EnableVerboseMode": NSNumber(value: false as Bool), "GFWListURL": "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt", - "WhiteListURL": "https://raw.githubusercontent.com/breakwa11/gfw_whitelist/master/whitelist.pac", - "WhiteListIPURL": "https://raw.githubusercontent.com/breakwa11/gfw_whitelist/master/whiteiplist.pac", + "ACLWhiteListURL": "https://raw.githubusercontent.com/shadowsocksr/shadowsocksr-libev/master/acl/chn.acl", + "ACLAutoListURL": "https://raw.githubusercontent.com/shadowsocksr/shadowsocksr-libev/master/acl/gfwlist.acl", + "ACLProxyBackCHNURL":"https://raw.githubusercontent.com/shadowsocksr/ShadowsocksX-NG/develop/ShadowsocksX-NG/backchn.acl", "AutoConfigureNetworkServices": NSNumber(value: true as Bool), "LocalHTTP.ListenAddress": "127.0.0.1", "LocalHTTP.ListenPort": NSNumber(value: 1087 as UInt16), @@ -266,7 +267,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } @IBAction func updateWhiteList(_ sender: NSMenuItem) { - UpdatePACFromWhiteList() + UpdateACL() } @IBAction func editUserRulesForPAC(_ sender: NSMenuItem) { diff --git a/ShadowsocksX-NG/Base.lproj/AdvPreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/AdvPreferencesWindowController.xib index 3d7f7ca..fea820e 100644 --- a/ShadowsocksX-NG/Base.lproj/AdvPreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/AdvPreferencesWindowController.xib @@ -1,7 +1,9 @@ - - + + - + + + @@ -14,31 +16,28 @@ - - + + - + - - - - - + + - - + + - + - - + + @@ -55,38 +54,36 @@ - - + + - - - - - + + - - + + - - + + + - - + + @@ -100,16 +97,17 @@ - - + + + - - + + @@ -124,8 +122,12 @@ - - - + + @@ -153,8 +155,8 @@ - - + + @@ -164,8 +166,11 @@ - - - + + + - - + + - - + + @@ -201,8 +207,8 @@ - - + + @@ -212,91 +218,134 @@ - - + + + + + - + - - - + + + - - - + + + - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/ShadowsocksX-NG/PACUtils.swift b/ShadowsocksX-NG/PACUtils.swift index f38bab0..be6603d 100644 --- a/ShadowsocksX-NG/PACUtils.swift +++ b/ShadowsocksX-NG/PACUtils.swift @@ -19,8 +19,6 @@ let GFWListFilePath = PACRulesDirPath + "gfwlist.txt" let ACLWhiteListFilePath = PACRulesDirPath + "chn.acl" let ACLBackCHNFilePath = PACRulesDirPath + "backchn.acl" let ACLGFWListFilePath = PACRulesDirPath + "gfwlist.acl" -let WhiteListDomainPACFilePath = PACRulesDirPath + "whitelist.pac" -let WhiteListIPPACFilePath = PACRulesDirPath + "whiteiplist.pac" // Because of LocalSocks5.ListenPort may be changed func SyncPac() { @@ -144,32 +142,6 @@ func GeneratePACFile() -> Bool { try result.data(using: String.Encoding.utf8)? .write(to: URL(fileURLWithPath: PACFilePath), options: .atomic) - // Setup Pac for White List - let DomainSrc = Bundle.main.path(forResource: "whitelist", ofType: "pac") - let IPSrc = Bundle.main.path(forResource: "whiteiplist", ofType: "pac") - let DomainPacFile = try? Data(contentsOf: URL(fileURLWithPath: DomainSrc!)) - let IPPACFile = try? Data(contentsOf: URL(fileURLWithPath: IPSrc!)) - var DomainPACStr = String(data: DomainPacFile!,encoding: String.Encoding.utf8)! - var IPPACStr = String(data: IPPACFile!,encoding: String.Encoding.utf8)! - if(DomainPACStr.range(of: "SOCKS ") == nil) { - DomainPACStr = DomainPACStr.replacingOccurrences(of: "SOCKS5 127.0.0.1:1080;", with: "SOCKS5 127.0.0.1:\(socks5Port);SOCKS 127.0.0.1:\(socks5Port);") - }else{ - DomainPACStr = DomainPACStr.replacingOccurrences(of: "SOCKS 127.0.0.1:1080;", with: "SOCKS 127.0.0.1:\(socks5Port);") - DomainPACStr = DomainPACStr.replacingOccurrences(of: "SOCKS5 127.0.0.1:1080;", with: "SOCKS5 127.0.0.1:\(socks5Port);") - } - - if(IPPACStr.range(of: "SOCKS ") == nil) { - IPPACStr = IPPACStr.replacingOccurrences(of: "SOCKS5 127.0.0.1:1080;", with: "SOCKS5 127.0.0.1:\(socks5Port);SOCKS 127.0.0.1:\(socks5Port);") - }else{ - IPPACStr = IPPACStr.replacingOccurrences(of: "SOCKS 127.0.0.1:1080;", with: "SOCKS 127.0.0.1:\(socks5Port);") - IPPACStr = IPPACStr.replacingOccurrences(of: "SOCKS5 127.0.0.1:1080;", with: "SOCKS5 127.0.0.1:\(socks5Port);") - } - - try - DomainPACStr.data(using: String.Encoding.utf8)?.write(to: URL(fileURLWithPath: WhiteListDomainPACFilePath), options: .atomic) - try - IPPACStr.data(using: String.Encoding.utf8)?.write(to: URL(fileURLWithPath: WhiteListIPPACFilePath), options: .atomic) - return true } catch { @@ -221,7 +193,7 @@ func UpdatePACFromGFWList() { } } -func UpdatePACFromWhiteList(){ +func UpdateACL(){ if !FileManager.default.fileExists(atPath: PACRulesDirPath) { do { try FileManager.default.createDirectory(atPath: PACRulesDirPath @@ -230,14 +202,14 @@ func UpdatePACFromWhiteList(){ } } - let url = UserDefaults.standard.string(forKey: "WhiteListURL") + let url = UserDefaults.standard.string(forKey: "ACLWhiteListURL") Alamofire.request(url!)// request(.GET, url!) .responseString { response in if response.result.isSuccess { if let v = response.result.value { do { - try v.write(toFile: WhiteListDomainPACFilePath, atomically: true, encoding: String.Encoding.utf8) + try v.write(toFile: ACLWhiteListFilePath, atomically: true, encoding: String.Encoding.utf8) if GeneratePACFile() { // Popup a user notification let notification = NSUserNotification() @@ -258,14 +230,14 @@ func UpdatePACFromWhiteList(){ } } - let IPURL = UserDefaults.standard.string(forKey: "WhiteListIPURL") + let IPURL = UserDefaults.standard.string(forKey: "ACLAutoListURL") Alamofire.request(IPURL!) .responseString { response in if response.result.isSuccess { if let v = response.result.value { do { - try v.write(toFile: WhiteListIPPACFilePath, atomically: true, encoding: String.Encoding.utf8) + try v.write(toFile: ACLGFWListFilePath, atomically: true, encoding: String.Encoding.utf8) if GeneratePACFile() { // Popup a user notification let notification = NSUserNotification() diff --git a/ShadowsocksX-NG/zh-Hans.lproj/AdvPreferencesWindowController.strings b/ShadowsocksX-NG/zh-Hans.lproj/AdvPreferencesWindowController.strings index f01ad9b..e411707 100644 --- a/ShadowsocksX-NG/zh-Hans.lproj/AdvPreferencesWindowController.strings +++ b/ShadowsocksX-NG/zh-Hans.lproj/AdvPreferencesWindowController.strings @@ -33,7 +33,7 @@ "PSg-XK-qhl.title" = "本地 PAC 监听端口:"; /* Class = "NSTextFieldCell"; title = "White List URL:"; ObjectID = "aif-uV-Lxk"; */ -"aif-uV-Lxk.title" = "白名单列表 URL:"; +"aif-uV-Lxk.title" = "ACL 白名单列表 URL:"; /* Class = "NSTextFieldCell"; title = "White IP List URL:"; ObjectID = "qhu-d1-qgq"; */ -"qhu-d1-qgq.title" = "白名单IP列表 URL:"; +"qhu-d1-qgq.title" = "ACL GFW List 列表 URL:";