Skip to content

Commit

Permalink
Listen host
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Nov 10, 2019
1 parent 58b94de commit 68f7f08
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 73 deletions.
2 changes: 2 additions & 0 deletions V2rayU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
66BC2B88228C589E00FBB716 /* V2raySubscribe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = V2raySubscribe.swift; sourceTree = "<group>"; };
66E7807A23781DC000819DA8 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = ../en.lproj/PreferenceAdvance.strings; sourceTree = "<group>"; };
66F07CF8236D79540088A4AE /* ping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ping.swift; sourceTree = "<group>"; };
66F3029922AA9C0900FCA4E2 /* V2rayUTool */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = V2rayUTool; sourceTree = "<group>"; };
66F3029C22AAA0A600FCA4E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/MainMenu.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -725,6 +726,7 @@
6D6DFE1CDFAD9828F2FDE1A5 /* Base */,
66F302A022AAA0A600FCA4E2 /* zh-Hans */,
669A73AB233776B900807CF9 /* zh-HK */,
66E7807A23781DC000819DA8 /* en */,
);
name = PreferenceAdvance.xib;
sourceTree = "<group>";
Expand Down
98 changes: 68 additions & 30 deletions V2rayU/Base.lproj/PreferenceAdvance.xib

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions V2rayU/Preference/PreferenceAdvance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions V2rayU/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions V2rayU/en.lproj/PreferenceAdvance.strings
Original file line number Diff line number Diff line change
@@ -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";
92 changes: 53 additions & 39 deletions V2rayU/v2ray/V2rayConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions V2rayU/zh-HK.lproj/PreferenceAdvance.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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:";
6 changes: 6 additions & 0 deletions V2rayU/zh-Hans.lproj/PreferenceAdvance.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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:";

0 comments on commit 68f7f08

Please sign in to comment.