add local proxy addr configuration
This commit is contained in:
1 parent
5b98351e58
commit
3d7e96acad
28 files changed
+76
-26
No files matched your search
@@ -29,6 +29,7 @@ import bypass.whitelist.ui.MainActivityHost
|
||||
import bypass.whitelist.ui.MainFragment
|
||||
import bypass.whitelist.ui.SettingsScreenFragment
|
||||
import bypass.whitelist.util.LogWriter
|
||||
import bypass.whitelist.util.Net
|
||||
import bypass.whitelist.util.Prefs
|
||||
import bypass.whitelist.util.SocksAuth
|
||||
import bypass.whitelist.util.maskUrl
|
||||
@@ -256,7 +257,7 @@ class MainActivity :
|
||||
|
||||
private fun probeViaSocks5(host: String, port: Int): Boolean {
|
||||
Socket().use { socket ->
|
||||
socket.connect(InetSocketAddress("127.0.0.1", Prefs.socksPort.toInt()), 5000)
|
||||
socket.connect(InetSocketAddress(Net.LOCALHOST, Prefs.socksPort.toInt()), 5000)
|
||||
socket.soTimeout = 15000
|
||||
val output = socket.getOutputStream()
|
||||
val input = socket.getInputStream()
|
||||
|
||||
@@ -51,6 +51,7 @@ class HeadlessRelayController(
|
||||
relayBin.absolutePath,
|
||||
"--mode", relayMode,
|
||||
"--ws-port", "${Ports.PION_SIGNALING}",
|
||||
"--socks-host", Prefs.socksHost,
|
||||
"--socks-port", "${Prefs.socksPort}",
|
||||
"--socks-user", SocksAuth.user,
|
||||
"--socks-pass", SocksAuth.pass
|
||||
@@ -63,7 +64,7 @@ class HeadlessRelayController(
|
||||
pendingCommands.forEach { writeStdin(it) }
|
||||
pendingCommands.clear()
|
||||
}
|
||||
onLog("Headless relay started (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@127.0.0.1:${Prefs.socksPort})")
|
||||
onLog("Headless relay started (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort})")
|
||||
|
||||
proc.inputStream.bufferedReader().forEachLine { line ->
|
||||
if (line.startsWith("RESOLVE:")) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package bypass.whitelist.tunnel
|
||||
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import bypass.whitelist.util.Prefs
|
||||
import java.io.File
|
||||
import java.net.InetAddress
|
||||
import java.net.ServerSocket
|
||||
@@ -27,7 +28,7 @@ object PortGuard {
|
||||
|
||||
private fun tryBind(port: Long): Boolean {
|
||||
return try {
|
||||
ServerSocket(port.toInt(), 1, InetAddress.getByName("127.0.0.1")).use { true }
|
||||
ServerSocket(port.toInt(), 1, InetAddress.getByName(Prefs.socksHost)).use { true }
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -59,12 +59,12 @@ class RelayController(
|
||||
dcThread = Thread {
|
||||
if (!checkPortOrAbort()) return@Thread
|
||||
try {
|
||||
Androidbind.startJoiner(Ports.DC_WS, Prefs.socksPort, SocksAuth.user, SocksAuth.pass, cb)
|
||||
Androidbind.startJoiner(Ports.DC_WS, Prefs.socksPort, Prefs.socksHost, SocksAuth.user, SocksAuth.pass, cb)
|
||||
} catch (e: Exception) {
|
||||
if (isRunning) onLog("Relay error: ${e.message}")
|
||||
}
|
||||
}.also { it.start() }
|
||||
onLog("Relay started DC mode (SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@127.0.0.1:${Prefs.socksPort}, WS :${Ports.DC_WS})")
|
||||
onLog("Relay started DC mode (SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort}, WS :${Ports.DC_WS})")
|
||||
}
|
||||
|
||||
private fun startPion(mode: TunnelMode, platform: CallPlatform) {
|
||||
@@ -81,6 +81,7 @@ class RelayController(
|
||||
relayBin.absolutePath,
|
||||
"--mode", relayMode,
|
||||
"--ws-port", "${Ports.PION_SIGNALING}",
|
||||
"--socks-host", Prefs.socksHost,
|
||||
"--socks-port", "${Prefs.socksPort}",
|
||||
"--socks-user", SocksAuth.user,
|
||||
"--socks-pass", SocksAuth.pass
|
||||
@@ -88,7 +89,7 @@ class RelayController(
|
||||
pb.redirectErrorStream(true)
|
||||
val proc = pb.start()
|
||||
synchronized(this) { pionProcess = proc }
|
||||
onLog("Pion relay started mode=$relayMode (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@127.0.0.1:${Prefs.socksPort})")
|
||||
onLog("Pion relay started mode=$relayMode (signaling :${Ports.PION_SIGNALING}, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort})")
|
||||
val stdinWriter = BufferedWriter(OutputStreamWriter(proc.outputStream))
|
||||
proc.inputStream.bufferedReader().forEachLine { line ->
|
||||
if (line.startsWith("RESOLVE:")) {
|
||||
|
||||
@@ -149,7 +149,7 @@ class TunnelVpnService : VpnService() {
|
||||
isRunning = true
|
||||
val fd = vpnFd!!.detachFd()
|
||||
vpnFd = null
|
||||
Log.i(TAG, "VPN established, fd=$fd, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@127.0.0.1:${Prefs.socksPort}")
|
||||
Log.i(TAG, "VPN established, fd=$fd, SOCKS5 ${SocksAuth.user}:${SocksAuth.pass}@${Prefs.socksHost}:${Prefs.socksPort}")
|
||||
updateStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
|
||||
tun2socksThread = Thread {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.util.Callback
|
||||
import bypass.whitelist.util.Net
|
||||
import bypass.whitelist.util.Prefs
|
||||
import bypass.whitelist.util.SocksAuthMode
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
@@ -32,6 +33,7 @@ class ProxyActionSheet : BottomSheetDialogFragment() {
|
||||
selectedAuth = Prefs.socksAuthMode
|
||||
view.findViewById<View>(R.id.proxyPortCard).clipToOutline = true
|
||||
val portInput = view.findViewById<EditText>(R.id.proxyPortInput)
|
||||
val hostInput = view.findViewById<EditText>(R.id.proxyHostInput)
|
||||
val authContainer = view.findViewById<LinearLayout>(R.id.proxyAuthContainer)
|
||||
val manualContainer = view.findViewById<LinearLayout>(R.id.proxyManualContainer)
|
||||
val userInput = view.findViewById<EditText>(R.id.proxyUserInput)
|
||||
@@ -39,6 +41,7 @@ class ProxyActionSheet : BottomSheetDialogFragment() {
|
||||
val proxyOnly = view.findViewById<MaterialSwitch>(R.id.proxyOnlySwitch)
|
||||
|
||||
portInput.setText(Prefs.socksPort.toString())
|
||||
hostInput.setText(Prefs.socksHost)
|
||||
userInput.setText(Prefs.socksUser)
|
||||
passInput.setText(Prefs.socksPass)
|
||||
proxyOnly.isChecked = Prefs.proxyOnly
|
||||
@@ -76,6 +79,7 @@ class ProxyActionSheet : BottomSheetDialogFragment() {
|
||||
view.findViewById<MaterialButton>(R.id.proxyCancelButton).setOnClickListener { dismiss() }
|
||||
view.findViewById<MaterialButton>(R.id.proxySaveButton).setOnClickListener {
|
||||
portInput.text.toString().toLongOrNull()?.takeIf { it in 1L..65535L }?.let { Prefs.socksPort = it }
|
||||
Prefs.socksHost = hostInput.text.toString().trim().ifEmpty { Net.LOCALHOST }
|
||||
Prefs.socksAuthMode = selectedAuth
|
||||
if (selectedAuth == SocksAuthMode.MANUAL) {
|
||||
Prefs.socksUser = userInput.text.toString().trim()
|
||||
|
||||
@@ -2,6 +2,10 @@ package bypass.whitelist.util
|
||||
|
||||
import java.security.SecureRandom
|
||||
|
||||
object Net {
|
||||
const val LOCALHOST = "127.0.0.1"
|
||||
}
|
||||
|
||||
object Ports {
|
||||
const val DEFAULT_SOCKS = 1080L
|
||||
const val DC_WS = 9000L
|
||||
@@ -51,6 +55,7 @@ object PrefsKeys {
|
||||
const val AUTOFILL_ENABLED = "autofill_enabled"
|
||||
const val AUTOFILL_NAME = "autofill_name"
|
||||
const val HEADLESS = "headless"
|
||||
const val SOCKS_HOST = "socks_host"
|
||||
const val SOCKS_PORT = "socks_port"
|
||||
const val SOCKS_AUTH_MODE = "socks_auth_mode"
|
||||
const val SOCKS_USER = "socks_user"
|
||||
|
||||
@@ -61,6 +61,10 @@ object Prefs {
|
||||
get() = prefs.getBoolean(PrefsKeys.HEADLESS, true)
|
||||
set(value) = prefs.edit { putBoolean(PrefsKeys.HEADLESS, value) }
|
||||
|
||||
var socksHost: String
|
||||
get() = prefs.getString(PrefsKeys.SOCKS_HOST, Net.LOCALHOST) ?: Net.LOCALHOST
|
||||
set(value) = prefs.edit { putString(PrefsKeys.SOCKS_HOST, value) }
|
||||
|
||||
var socksPort: Long
|
||||
get() = prefs.getLong(PrefsKeys.SOCKS_PORT, Ports.DEFAULT_SOCKS)
|
||||
set(value) = prefs.edit { putLong(PrefsKeys.SOCKS_PORT, value) }
|
||||
|
||||
Reference in new issue
Block a user