From 68f7f08ac1b7f9a79e24746a0f3e66f1f3b34b73 Mon Sep 17 00:00:00 2001 From: yanue Date: Sun, 10 Nov 2019 18:33:30 +0800 Subject: [PATCH] Listen host --- V2rayU.xcodeproj/project.pbxproj | 2 + V2rayU/Base.lproj/PreferenceAdvance.xib | 98 +++++++++++++------ V2rayU/Preference/PreferenceAdvance.swift | 15 ++- V2rayU/Util.swift | 4 + V2rayU/en.lproj/PreferenceAdvance.strings | 75 ++++++++++++++ V2rayU/v2ray/V2rayConfig.swift | 92 +++++++++-------- V2rayU/zh-HK.lproj/PreferenceAdvance.strings | 6 ++ .../zh-Hans.lproj/PreferenceAdvance.strings | 6 ++ 8 files changed, 225 insertions(+), 73 deletions(-) create mode 100644 V2rayU/en.lproj/PreferenceAdvance.strings diff --git a/V2rayU.xcodeproj/project.pbxproj b/V2rayU.xcodeproj/project.pbxproj index facb856..70a143e 100644 --- a/V2rayU.xcodeproj/project.pbxproj +++ b/V2rayU.xcodeproj/project.pbxproj @@ -160,6 +160,7 @@ 66A5CE4521706B5A009B08B2 /* Pods_V2rayU.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_V2rayU.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 66ACB19F21757D5B005B5881 /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = ""; }; 66BC2B88228C589E00FBB716 /* V2raySubscribe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V2raySubscribe.swift; sourceTree = ""; }; + 66E7807A23781DC000819DA8 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = ../en.lproj/PreferenceAdvance.strings; sourceTree = ""; }; 66F07CF8236D79540088A4AE /* ping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ping.swift; sourceTree = ""; }; 66F3029922AA9C0900FCA4E2 /* V2rayUTool */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = V2rayUTool; sourceTree = ""; }; 66F3029C22AAA0A600FCA4E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = ""; }; @@ -725,6 +726,7 @@ 6D6DFE1CDFAD9828F2FDE1A5 /* Base */, 66F302A022AAA0A600FCA4E2 /* zh-Hans */, 669A73AB233776B900807CF9 /* zh-HK */, + 66E7807A23781DC000819DA8 /* en */, ); name = PreferenceAdvance.xib; sourceTree = ""; diff --git a/V2rayU/Base.lproj/PreferenceAdvance.xib b/V2rayU/Base.lproj/PreferenceAdvance.xib index 7f2af09..7c8b6e2 100755 --- a/V2rayU/Base.lproj/PreferenceAdvance.xib +++ b/V2rayU/Base.lproj/PreferenceAdvance.xib @@ -1,8 +1,8 @@ - + - + @@ -11,11 +11,13 @@ + + @@ -23,18 +25,18 @@ - + - + - + - + @@ -43,7 +45,7 @@ - + @@ -67,7 +69,7 @@ - + @@ -80,7 +82,7 @@ - + @@ -88,8 +90,17 @@ + + + + + + + + + - + @@ -98,7 +109,7 @@ - + @@ -111,7 +122,7 @@ - + @@ -128,7 +139,7 @@ - + @@ -137,11 +148,11 @@ - + - + @@ -158,7 +169,7 @@ - + @@ -167,7 +178,7 @@ - + @@ -176,7 +187,7 @@ - + @@ -188,9 +199,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + diff --git a/V2rayU/Preference/PreferenceAdvance.swift b/V2rayU/Preference/PreferenceAdvance.swift index 638abe3..a35d994 100644 --- a/V2rayU/Preference/PreferenceAdvance.swift +++ b/V2rayU/Preference/PreferenceAdvance.swift @@ -17,6 +17,8 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane { @IBOutlet weak var saveBtn: NSButtonCell! @IBOutlet weak var sockPort: NSTextField! @IBOutlet weak var httpPort: NSTextField! + @IBOutlet weak var sockHost: NSTextField! + @IBOutlet weak var httpHost: NSTextField! @IBOutlet weak var pacPort: NSTextField! @IBOutlet weak var enableUdp: NSButton! @@ -41,20 +43,23 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane { let enableUdpState = UserDefaults.getBool(forKey: .enableUdp) let localSockPort = UserDefaults.get(forKey: .localSockPort) ?? "1080" + let localSockHost = UserDefaults.get(forKey: .localSockHost) ?? "127.0.0.1" let localHttpPort = UserDefaults.get(forKey: .localHttpPort) ?? "1087" + let localHttpHost = UserDefaults.get(forKey: .localHttpHost) ?? "127.0.0.1" let localPacPort = UserDefaults.get(forKey: .localPacPort) ?? "11085" - let dnsServers = UserDefaults.get(forKey: .dnsServers) ?? "" let muxConcurrent = UserDefaults.get(forKey: .muxConcurrent) ?? "8" // select item - print("logLevel",UserDefaults.get(forKey: .v2rayLogLevel) ?? "info") + print("host",localSockHost,localHttpHost) self.logLevel.selectItem(withTitle: UserDefaults.get(forKey: .v2rayLogLevel) ?? "info") self.enableUdp.state = enableUdpState ? .on : .off self.enableMux.state = enableMuxState ? .on : .off self.sockPort.stringValue = localSockPort + self.sockHost.stringValue = localSockHost self.httpPort.stringValue = localHttpPort + self.httpHost.stringValue = localHttpHost self.pacPort.stringValue = localPacPort self.dnsServers.stringValue = dnsServers self.muxConcurrent.intValue = Int32(muxConcurrent) ?? 8; @@ -82,12 +87,14 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane { UserDefaults.setBool(forKey: .enableMux, value: enableMuxVal) UserDefaults.set(forKey: .localHttpPort, value: httpPortVal) + UserDefaults.set(forKey: .localHttpHost, value: self.httpHost.stringValue) UserDefaults.set(forKey: .localSockPort, value: sockPortVal) + UserDefaults.set(forKey: .localSockHost, value: self.sockHost.stringValue) UserDefaults.set(forKey: .localPacPort, value: pacPortVal) - UserDefaults.set(forKey: .dnsServers, value: dnsServersVal) UserDefaults.set(forKey: .muxConcurrent, value: String(muxConcurrentVal)) - + print("self.sockHost.stringValue",self.sockHost.stringValue) + var logLevelName = "info" if let logLevelVal = self.logLevel.selectedItem { diff --git a/V2rayU/Util.swift b/V2rayU/Util.swift index 786a813..0050ce5 100644 --- a/V2rayU/Util.swift +++ b/V2rayU/Util.swift @@ -37,8 +37,12 @@ extension UserDefaults { case gfwPacListUrl // base settings + // http host + case localHttpHost // http port case localHttpPort + // sock host + case localSockHost // sock port case localSockPort // dns servers diff --git a/V2rayU/en.lproj/PreferenceAdvance.strings b/V2rayU/en.lproj/PreferenceAdvance.strings new file mode 100644 index 0000000..f5e21b6 --- /dev/null +++ b/V2rayU/en.lproj/PreferenceAdvance.strings @@ -0,0 +1,75 @@ + +/* Class = "NSMenuItem"; title = "error"; ObjectID = "12u-HY-IPV"; */ +"12u-HY-IPV.title" = "error"; + +/* Class = "NSTextFieldCell"; title = "V2ray Core Log level:"; ObjectID = "Ctq-lX-cuA"; */ +"Ctq-lX-cuA.title" = "V2ray Core Log level:"; + +/* Class = "NSTextFieldCell"; title = "Label"; ObjectID = "GyI-8o-VH6"; */ +"GyI-8o-VH6.title" = "Label"; + +/* Class = "NSTextFieldCell"; placeholderString = " 1087"; ObjectID = "U2E-Gk-3e0"; */ +"U2E-Gk-3e0.placeholderString" = " 1087"; + +/* Class = "NSButtonCell"; title = "save settings"; ObjectID = "YJf-A4-mgF"; */ +"YJf-A4-mgF.title" = "save settings"; + +/* Class = "NSTextFieldCell"; title = "Local Http Listen Port:"; ObjectID = "Yih-X2-qBl"; */ +"Yih-X2-qBl.title" = "Local Http Listen Port:"; + +/* Class = "NSButtonCell"; title = "Enable UDP"; ObjectID = "afR-MR-aoQ"; */ +"afR-MR-aoQ.title" = "Enable UDP"; + +/* Class = "NSTextFieldCell"; title = "Mux:"; ObjectID = "aux-FG-ubc"; */ +"aux-FG-ubc.title" = "Mux:"; + +/* Class = "NSTextFieldCell"; title = "127.0.0.1"; ObjectID = "az8-jb-B7A"; */ +"az8-jb-B7A.title" = "127.0.0.1"; + +/* Class = "NSTextFieldCell"; title = "Dns:"; ObjectID = "c7W-6e-soa"; */ +"c7W-6e-soa.title" = "Dns:"; + +/* Class = "NSTextFieldCell"; placeholderString = " 1080"; ObjectID = "cEB-VU-kcL"; */ +"cEB-VU-kcL.placeholderString" = " 1080"; + +/* Class = "NSTextFieldCell"; placeholderString = " 1087"; ObjectID = "cs0-w0-4jp"; */ +"cs0-w0-4jp.placeholderString" = " 1087"; + +/* Class = "NSTextFieldCell"; title = "Local Sock Listen Port:"; ObjectID = "dy9-2h-EIe"; */ +"dy9-2h-EIe.title" = "Local Sock Listen Port:"; + +/* Class = "NSTextFieldCell"; placeholderString = " 8"; ObjectID = "gO2-cn-1bj"; */ +"gO2-cn-1bj.placeholderString" = " 8"; + +/* Class = "NSMenuItem"; title = "none"; ObjectID = "hwH-DG-b6w"; */ +"hwH-DG-b6w.title" = "none"; + +/* Class = "NSTextFieldCell"; title = "Local Sock Listen Host:"; ObjectID = "jwm-cF-Zeb"; */ +"jwm-cF-Zeb.title" = "Local Sock Listen Host:"; + +/* Class = "NSButtonCell"; title = "Enable Mux"; ObjectID = "k2J-Q7-yOi"; */ +"k2J-Q7-yOi.title" = "Enable Mux"; + +/* Class = "NSMenuItem"; title = "info"; ObjectID = "kHt-j0-6zV"; */ +"kHt-j0-6zV.title" = "info"; + +/* Class = "NSTextFieldCell"; title = "8.8.8.8,1.1.1.1,114.114.114.114,119.29.29.29"; ObjectID = "lKP-40-S8o"; */ +"lKP-40-S8o.title" = "8.8.8.8,1.1.1.1,114.114.114.114,119.29.29.29"; + +/* Class = "NSTextFieldCell"; title = "127.0.0.1"; ObjectID = "os8-UE-0fP"; */ +"os8-UE-0fP.title" = "127.0.0.1"; + +/* Class = "NSMenuItem"; title = "debug"; ObjectID = "qDP-Eo-IWC"; */ +"qDP-Eo-IWC.title" = "debug"; + +/* Class = "NSBox"; title = "Local"; ObjectID = "tMz-nM-arv"; */ +"tMz-nM-arv.title" = "Local"; + +/* Class = "NSTextFieldCell"; title = "Local Http Listen Host:"; ObjectID = "uWf-ty-nD8"; */ +"uWf-ty-nD8.title" = "Local Http Listen Host:"; + +/* Class = "NSTextFieldCell"; title = "Pac Server Listen Port:"; ObjectID = "you-iw-OS5"; */ +"you-iw-OS5.title" = "Pac Server Listen Port:"; + +/* Class = "NSMenuItem"; title = "warning"; ObjectID = "z4S-wG-fyc"; */ +"z4S-wG-fyc.title" = "warning"; diff --git a/V2rayU/v2ray/V2rayConfig.swift b/V2rayU/v2ray/V2rayConfig.swift index fbd2ffe..b8a00a3 100644 --- a/V2rayU/v2ray/V2rayConfig.swift +++ b/V2rayU/v2ray/V2rayConfig.swift @@ -11,47 +11,47 @@ import SwiftyJSON import JavaScriptCore let jsSourceFormatConfig = - """ - /** - * V2ray Config Format - * @return {string} - */ - var V2rayConfigFormat = function (encodeStr) { - var deStr = decodeURIComponent(encodeStr); - if (!deStr) { - return "error: cannot decode uri" - } - - try { - var obj = JSON.parse(deStr); - if (!obj) { - return "error: cannot parse json" - } + """ + /** + * V2ray Config Format + * @return {string} + */ + var V2rayConfigFormat = function (encodeStr) { + var deStr = decodeURIComponent(encodeStr); + if (!deStr) { + return "error: cannot decode uri" + } - var v2rayConfig = {}; - // ordered keys - v2rayConfig["log"] = obj.log; - v2rayConfig["inbounds"] = obj.inbounds; - v2rayConfig["inbound"] = obj.inbound; - v2rayConfig["inboundDetour"] = obj.inboundDetour; - v2rayConfig["outbounds"] = obj.outbounds; - v2rayConfig["outbound"] = obj.outbound; - v2rayConfig["outboundDetour"] = obj.outboundDetour; - v2rayConfig["api"] = obj.api; - v2rayConfig["dns"] = obj.dns; - v2rayConfig["stats"] = obj.stats; - v2rayConfig["routing"] = obj.routing; - v2rayConfig["policy"] = obj.policy; - v2rayConfig["reverse"] = obj.reverse; - v2rayConfig["transport"] = obj.transport; - - return JSON.stringify(v2rayConfig, null, 2); - } catch (e) { - console.log("error", e); - return "error: " + e.toString() + try { + var obj = JSON.parse(deStr); + if (!obj) { + return "error: cannot parse json" } - }; - """ + + var v2rayConfig = {}; + // ordered keys + v2rayConfig["log"] = obj.log; + v2rayConfig["inbounds"] = obj.inbounds; + v2rayConfig["inbound"] = obj.inbound; + v2rayConfig["inboundDetour"] = obj.inboundDetour; + v2rayConfig["outbounds"] = obj.outbounds; + v2rayConfig["outbound"] = obj.outbound; + v2rayConfig["outboundDetour"] = obj.outboundDetour; + v2rayConfig["api"] = obj.api; + v2rayConfig["dns"] = obj.dns; + v2rayConfig["stats"] = obj.stats; + v2rayConfig["routing"] = obj.routing; + v2rayConfig["policy"] = obj.policy; + v2rayConfig["reverse"] = obj.reverse; + v2rayConfig["transport"] = obj.transport; + + return JSON.stringify(v2rayConfig, null, 2); + } catch (e) { + console.log("error", e); + return "error: " + e.toString() + } + }; + """ class V2rayConfig: NSObject { var v2ray: V2rayStruct = V2rayStruct() @@ -65,7 +65,9 @@ class V2rayConfig: NSObject { // base var logLevel = "info" var socksPort = "1080" + var socksHost = "127.0.0.1" var httpPort = "1087" + var httpHost = "127.0.0.1" var enableUdp = true var enableMux = false var mux = 8 @@ -104,7 +106,9 @@ class V2rayConfig: NSObject { self.enableUdp = UserDefaults.getBool(forKey: .enableUdp) self.httpPort = UserDefaults.get(forKey: .localHttpPort) ?? "1087" + self.httpHost = UserDefaults.get(forKey: .localHttpHost) ?? "127.0.0.1" self.socksPort = UserDefaults.get(forKey: .localSockPort) ?? "1080" + self.socksHost = UserDefaults.get(forKey: .localSockHost) ?? "127.0.0.1" self.dns = UserDefaults.get(forKey: .dnsServers) ?? "" self.mux = Int(UserDefaults.get(forKey: .muxConcurrent) ?? "8") ?? 8 @@ -160,9 +164,11 @@ class V2rayConfig: NSObject { // ------------------------------------- inbound start --------------------------------------------- var inHttp = V2rayInbound() inHttp.port = self.httpPort + inHttp.listen = self.httpHost inHttp.protocol = V2rayProtocolInbound.http var inSocks = V2rayInbound() inSocks.port = self.socksPort + inSocks.listen = self.socksHost inSocks.protocol = V2rayProtocolInbound.socks inSocks.settingSocks.udp = self.enableUdp @@ -177,9 +183,11 @@ class V2rayConfig: NSObject { for var (_, item) in self.v2ray.inbounds!.enumerated() { if item.protocol == V2rayProtocolInbound.http { item.port = self.httpPort.count > 0 ? self.httpPort : "1087" + item.listen = self.httpHost.count > 0 ? self.httpHost : "127.0.0.1" } if item.protocol == V2rayProtocolInbound.socks { item.port = self.socksPort.count > 0 ? self.socksPort : "1080" + item.listen = self.socksHost.count > 0 ? self.socksHost : "127.0.0.1" item.settingSocks.udp = self.enableUdp } inbounds.append(item) @@ -199,10 +207,12 @@ class V2rayConfig: NSObject { if self.v2ray.inbound != nil { if self.v2ray.inbound!.protocol == V2rayProtocolInbound.http { self.v2ray.inbound!.port = self.httpPort + self.v2ray.inbound!.listen = self.httpHost inType = V2rayProtocolInbound.http } if self.v2ray.inbound!.protocol == V2rayProtocolInbound.socks { self.v2ray.inbound!.port = self.socksPort + self.v2ray.inbound!.listen = self.socksHost self.v2ray.inbound!.settingSocks.udp = self.enableUdp } } else { @@ -216,9 +226,11 @@ class V2rayConfig: NSObject { for var (_, item) in self.v2ray.inboundDetour!.enumerated() { if item.protocol == V2rayProtocolInbound.http { item.port = self.httpPort + item.listen = self.httpHost } if item.protocol == V2rayProtocolInbound.socks { item.port = self.socksPort + item.listen = self.socksHost item.settingSocks.udp = self.enableUdp } inboundDetour.append(item) @@ -735,6 +747,7 @@ class V2rayConfig: NSObject { } // use default setting v2rayInbound.port = self.httpPort + v2rayInbound.port = self.httpHost // set into inbound v2rayInbound.settingHttp = settings break @@ -780,6 +793,7 @@ class V2rayConfig: NSObject { // use default setting settings.udp = self.enableUdp v2rayInbound.port = self.socksPort + v2rayInbound.listen = self.socksHost // set into inbound v2rayInbound.settingSocks = settings break diff --git a/V2rayU/zh-HK.lproj/PreferenceAdvance.strings b/V2rayU/zh-HK.lproj/PreferenceAdvance.strings index 76129ab..a4d6a49 100644 --- a/V2rayU/zh-HK.lproj/PreferenceAdvance.strings +++ b/V2rayU/zh-HK.lproj/PreferenceAdvance.strings @@ -58,3 +58,9 @@ /* Class = "NSMenuItem"; title = "warning"; ObjectID = "z4S-wG-fyc"; */ "z4S-wG-fyc.title" = "warning"; + +/* Class = "NSTextFieldCell"; title = "Local Sock Listen Host:"; ObjectID = "jwm-cF-Zeb"; */ +"jwm-cF-Zeb.title" = "本機Sock監聽Host:"; + +/* Class = "NSTextFieldCell"; title = "Local Http Listen Host:"; ObjectID = "uWf-ty-nD8"; */ +"uWf-ty-nD8.title" = "本機http監聽Host:"; \ No newline at end of file diff --git a/V2rayU/zh-Hans.lproj/PreferenceAdvance.strings b/V2rayU/zh-Hans.lproj/PreferenceAdvance.strings index f7ccd5b..962506c 100644 --- a/V2rayU/zh-Hans.lproj/PreferenceAdvance.strings +++ b/V2rayU/zh-Hans.lproj/PreferenceAdvance.strings @@ -58,3 +58,9 @@ /* Class = "NSMenuItem"; title = "warning"; ObjectID = "z4S-wG-fyc"; */ "z4S-wG-fyc.title" = "warning"; + +/* Class = "NSTextFieldCell"; title = "Local Sock Listen Host:"; ObjectID = "jwm-cF-Zeb"; */ +"jwm-cF-Zeb.title" = "本机Sock监听Host:"; + +/* Class = "NSTextFieldCell"; title = "Local Http Listen Host:"; ObjectID = "uWf-ty-nD8"; */ +"uWf-ty-nD8.title" = "本机http监听Host:"; \ No newline at end of file