V0.1.8 (#20)
* Add split tunneling (#17) * refactor imports * remove bandwidth tests from hooks * add autoclikers for call join * add autoclikers for call join * refactor - split to classes, update namings * display bot api in console * mute audio as a separate js script * fix NUL byte in udp for windows * update readme, collapse call webview, edit tab names * fix ports allocation when target is taken * fix ports allocation when target is taken * increment release version --------- Co-authored-by: senya <76913432+senya-sh@users.noreply.github.com> Co-authored-by: kulikov <user@Mac.lan>
This commit is contained in:
52 files changed
+1193
-629
No files matched your search
@@ -118,6 +118,8 @@ Prebuilt binaries are available on [GitHub Releases](../../releases).
|
||||
|
||||
## Setup
|
||||
|
||||
Step-by-step setup guide (in Russian): [telegra.ph](https://telegra.ph/Rabota-s-whitelist-bypass-03-29)
|
||||
|
||||
### Creator side (free internet, desktop)
|
||||
|
||||
Download and run the Electron app from [GitHub Releases](../../releases). It bundles the Go relay automatically.
|
||||
|
||||
@@ -5,7 +5,7 @@ plugins {
|
||||
|
||||
val versionMajor = 0
|
||||
val versionMinor = 1
|
||||
val versionPatch = 7
|
||||
val versionPatch = 8
|
||||
val versionBuild = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: 0
|
||||
|
||||
android {
|
||||
|
||||
Binary file not shown.
@@ -6,6 +6,7 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
@@ -29,7 +30,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name=".TunnelVpnService"
|
||||
android:name=".tunnel.TunnelVpnService"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE"
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:exported="false">
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
(function() {
|
||||
if (window.__autoclickInstalled) return;
|
||||
window.__autoclickInstalled = true;
|
||||
|
||||
var log = function() {
|
||||
var args = ['[HOOK] [autoclick]'];
|
||||
for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
log('Autoclick installed');
|
||||
|
||||
function scan() {
|
||||
var all = document.querySelectorAll('[data-testid="orb-button"]');
|
||||
log('scan: ' + all.length + ' orb-buttons found');
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var txt = (all[i].textContent || '').trim();
|
||||
log(' btn[' + i + ']: "' + txt + '"');
|
||||
if (txt.indexOf('Продолжить в браузере') !== -1) {
|
||||
log('Clicking: Продолжить в браузере');
|
||||
all[i].click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var joinBtn = document.querySelector('[data-testid="enter-conference-button"]');
|
||||
if (joinBtn) {
|
||||
log('Clicking: Подключиться');
|
||||
joinBtn.click();
|
||||
clearInterval(iv);
|
||||
log('Autoclick done');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var iv = setInterval(scan, 1500);
|
||||
})();
|
||||
@@ -0,0 +1,44 @@
|
||||
(function() {
|
||||
if (window.__autoclickInstalled) return;
|
||||
window.__autoclickInstalled = true;
|
||||
|
||||
var log = function() {
|
||||
var args = ['[HOOK] [autoclick]'];
|
||||
for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
log('Autoclick installed');
|
||||
|
||||
function findNameInput() {
|
||||
var inputs = document.querySelectorAll('input[type="text"]');
|
||||
for (var i = 0; i < inputs.length; i++) {
|
||||
var ph = (inputs[i].placeholder || '').toLowerCase();
|
||||
if (ph.indexOf('name') !== -1 || ph.indexOf('имя') !== -1) return inputs[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function scan() {
|
||||
var inp = findNameInput();
|
||||
if (inp && !inp.value) {
|
||||
log('Filling name');
|
||||
var set = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
|
||||
set.call(inp, 'Hello');
|
||||
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
inp.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
var joinBtn = document.querySelector('[data-testid="calls_preview_join_button_anonym"]');
|
||||
if (joinBtn && inp && inp.value) {
|
||||
log('Clicking: Join');
|
||||
joinBtn.click();
|
||||
clearInterval(iv);
|
||||
log('Autoclick done');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var iv = setInterval(scan, 1500);
|
||||
})();
|
||||
@@ -3,7 +3,7 @@
|
||||
if (window.__hookInstalled) return;
|
||||
window.__hookInstalled = true;
|
||||
|
||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||
const WS_URL = 'ws://127.0.0.1:' + (window.WS_PORT || 9000) + '/ws';
|
||||
const log = (...args) => console.log('[HOOK]', ...args);
|
||||
const peers = [];
|
||||
let activeWS = null;
|
||||
@@ -278,31 +278,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||
var chunkSize = 4096;
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
sendRaw('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
sendRaw(new ArrayBuffer(chunkSize));
|
||||
sent += chunkSize;
|
||||
}
|
||||
sendRaw('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
@@ -3,7 +3,7 @@
|
||||
if (window.__hookInstalled) return;
|
||||
window.__hookInstalled = true;
|
||||
|
||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||
const WS_URL = 'ws://127.0.0.1:' + (window.WS_PORT || 9000) + '/ws';
|
||||
const log = (...args) => console.log('[HOOK]', ...args);
|
||||
const peers = [];
|
||||
let activeWS = null;
|
||||
@@ -60,34 +60,8 @@
|
||||
activeDC = null;
|
||||
};
|
||||
|
||||
let bwRecvBytes = 0;
|
||||
let bwRecvStart = 0;
|
||||
let bwMode = false;
|
||||
|
||||
dc.onmessage = (e) => {
|
||||
if (dc !== activeDC) return;
|
||||
if (bwMode) {
|
||||
if (e.data instanceof ArrayBuffer) {
|
||||
if (bwRecvStart === 0) bwRecvStart = performance.now();
|
||||
bwRecvBytes += e.data.byteLength;
|
||||
return;
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
bwMode = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:start') {
|
||||
bwMode = true;
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
return;
|
||||
}
|
||||
if (activeWS && wsOpen) {
|
||||
activeWS.send(e.data);
|
||||
}
|
||||
@@ -136,32 +110,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||
var chunkSize = 16384;
|
||||
var chunk = new ArrayBuffer(chunkSize);
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
activeDC.send('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
activeDC.send(chunk);
|
||||
sent += chunkSize;
|
||||
}
|
||||
activeDC.send('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
@@ -0,0 +1,14 @@
|
||||
(function() {
|
||||
var oac = window.AudioContext || window.webkitAudioContext;
|
||||
if (oac) {
|
||||
var nac = function() {
|
||||
var c = new oac();
|
||||
c.suspend();
|
||||
c.resume = function() { return Promise.resolve(); };
|
||||
return c;
|
||||
};
|
||||
nac.prototype = oac.prototype;
|
||||
window.AudioContext = nac;
|
||||
if (window.webkitAudioContext) window.webkitAudioContext = nac;
|
||||
}
|
||||
})();
|
||||
@@ -1,10 +1,11 @@
|
||||
package bypass.whitelist
|
||||
|
||||
import android.app.Application
|
||||
import bypass.whitelist.util.Prefs
|
||||
|
||||
class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Prefs.init(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,53 @@
|
||||
package bypass.whitelist
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.VpnService
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.webkit.*
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import bypass.whitelist.tunnel.CallPlatform
|
||||
import bypass.whitelist.tunnel.RelayController
|
||||
import bypass.whitelist.tunnel.TunnelVpnService
|
||||
import bypass.whitelist.tunnel.VpnStatus
|
||||
import bypass.whitelist.ui.LogViewController
|
||||
import bypass.whitelist.ui.SettingsMenuController
|
||||
import bypass.whitelist.ui.StatusBarController
|
||||
import bypass.whitelist.ui.WebViewManager
|
||||
import bypass.whitelist.util.LogWriter
|
||||
import bypass.whitelist.util.Prefs
|
||||
import bypass.whitelist.util.hideKeyboard
|
||||
import bypass.whitelist.util.maskUrl
|
||||
import java.net.Inet4Address
|
||||
import java.net.InetAddress
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private var tunnelMode = TunnelMode.DC
|
||||
private var connected = false
|
||||
private var showLogs = false
|
||||
|
||||
private val logWriter by lazy { LogWriter(cacheDir) }
|
||||
private val relay by lazy {
|
||||
RelayController(
|
||||
nativeLibDir = applicationInfo.nativeLibraryDir,
|
||||
onLog = ::appendLog,
|
||||
onLog = { logCtrl.append(it) },
|
||||
onStatus = ::onVpnStatus,
|
||||
)
|
||||
}
|
||||
|
||||
private lateinit var webView: WebView
|
||||
private lateinit var logView: TextView
|
||||
private lateinit var urlInput: EditText
|
||||
private lateinit var goButton: Button
|
||||
private lateinit var statusBar: TextView
|
||||
private lateinit var logCtrl: LogViewController
|
||||
private lateinit var statusCtrl: StatusBarController
|
||||
private lateinit var settingsCtrl: SettingsMenuController
|
||||
private lateinit var webViewMgr: WebViewManager
|
||||
private lateinit var logContainer: View
|
||||
|
||||
private var previousUrl = ""
|
||||
@@ -55,15 +60,9 @@ class MainActivity : AppCompatActivity() {
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == RESULT_OK) startVpnService()
|
||||
else appendLog("VPN permission denied")
|
||||
else logCtrl.append("VPN permission denied")
|
||||
}
|
||||
|
||||
private val hookVk by lazy { assets.open("dc-joiner-vk.js").bufferedReader().readText() }
|
||||
private val hookTelemost by lazy { assets.open("dc-joiner-telemost.js").bufferedReader().readText() }
|
||||
private val hookPionVk by lazy { assets.open("video-vk.js").bufferedReader().readText() }
|
||||
private val hookPionTelemost by lazy { assets.open("video-telemost.js").bufferedReader().readText() }
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@@ -74,44 +73,63 @@ class MainActivity : AppCompatActivity() {
|
||||
insets
|
||||
}
|
||||
|
||||
logView = findViewById(R.id.logView)
|
||||
urlInput = findViewById(R.id.urlInput)
|
||||
webView = findViewById(R.id.webView)
|
||||
goButton = findViewById(R.id.goButton)
|
||||
statusBar = findViewById(R.id.statusBar)
|
||||
logContainer = findViewById(R.id.logContainer)
|
||||
|
||||
logWriter.reset()
|
||||
logCtrl = LogViewController(this, findViewById(R.id.logView), logWriter)
|
||||
logCtrl.reset()
|
||||
|
||||
statusCtrl = StatusBarController(
|
||||
activity = this,
|
||||
statusBar = findViewById(R.id.statusBar),
|
||||
goButton = findViewById(R.id.goButton),
|
||||
onConnect = ::onGoPressed,
|
||||
onDisconnect = ::fullReset,
|
||||
)
|
||||
|
||||
settingsCtrl = SettingsMenuController(
|
||||
activity = this,
|
||||
onModeChanged = { mode ->
|
||||
statusCtrl.tunnelMode = mode
|
||||
webViewMgr.tunnelMode = mode
|
||||
fullReset()
|
||||
},
|
||||
onShareLogs = { logCtrl.shareLogs() },
|
||||
onReset = ::fullReset,
|
||||
)
|
||||
settingsCtrl.onShowLogsChanged = { visible ->
|
||||
logContainer.visibility = if (visible) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
webViewMgr = WebViewManager(
|
||||
activity = this,
|
||||
webView = findViewById(R.id.webView),
|
||||
toggleButton = findViewById(R.id.toggleWebViewButton),
|
||||
toggleArrow = findViewById(R.id.toggleWebViewArrow),
|
||||
toggleLabel = findViewById(R.id.toggleWebViewLabel),
|
||||
onLog = { logCtrl.append(it) },
|
||||
onStatus = ::onVpnStatus,
|
||||
)
|
||||
webViewMgr.setup(JsBridge())
|
||||
|
||||
previousUrl = Prefs.lastUrl
|
||||
urlInput.setText(previousUrl)
|
||||
tunnelMode = Prefs.tunnelMode
|
||||
statusBar.text = getString(R.string.status_format, tunnelMode.label, getString(R.string.status_idle))
|
||||
showLogs = Prefs.showLogs
|
||||
logContainer.visibility = if (showLogs) View.VISIBLE else View.GONE
|
||||
statusCtrl.tunnelMode = Prefs.tunnelMode
|
||||
webViewMgr.tunnelMode = Prefs.tunnelMode
|
||||
statusCtrl.setIdle()
|
||||
logContainer.visibility = if (Prefs.showLogs) View.VISIBLE else View.GONE
|
||||
|
||||
setupWebView()
|
||||
|
||||
goButton.setOnClickListener { onGoPressed() }
|
||||
|
||||
findViewById<ImageButton>(R.id.shareLogsButton).setOnClickListener {
|
||||
val uri = FileProvider.getUriForFile(this, "$packageName.fileprovider", logWriter.file)
|
||||
val share = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/plain"
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
startActivity(Intent.createChooser(share, getString(R.string.share_logs)))
|
||||
}
|
||||
|
||||
findViewById<ImageButton>(R.id.gearButton).setOnClickListener { showGearMenu(it) }
|
||||
findViewById<Button>(R.id.goButton).setOnClickListener { onGoPressed() }
|
||||
findViewById<ImageButton>(R.id.shareLogsButton).setOnClickListener { logCtrl.shareLogs() }
|
||||
findViewById<ImageButton>(R.id.gearButton).setOnClickListener { settingsCtrl.show(it) }
|
||||
findViewById<View>(R.id.clearButton).setOnClickListener { urlInput.setText("") }
|
||||
|
||||
TunnelVpnService.onDisconnect = { runOnUiThread { resetState() } }
|
||||
|
||||
VpnService.prepare(this)?.let { vpnPrepLauncher.launch(it) }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
||||
checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
requestPermissions(arrayOf(android.Manifest.permission.POST_NOTIFICATIONS), 0)
|
||||
}
|
||||
|
||||
@@ -125,152 +143,39 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onDestroy() {
|
||||
TunnelVpnService.onDisconnect = null
|
||||
stopRelay()
|
||||
relay.stop()
|
||||
TunnelVpnService.instance?.stop()
|
||||
logWriter.close()
|
||||
logCtrl.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun onGoPressed() {
|
||||
val url = urlInput.text.toString().trim()
|
||||
if (url.isEmpty()) return
|
||||
logWriter.reset()
|
||||
logView.text = ""
|
||||
stopRelay()
|
||||
startRelay()
|
||||
logCtrl.reset()
|
||||
relay.stop()
|
||||
relay.start(settingsCtrl.tunnelMode, CallPlatform.fromUrl(url))
|
||||
hideKeyboard()
|
||||
urlInput.clearFocus()
|
||||
setConnected(false)
|
||||
setStatus(VpnStatus.CONNECTING)
|
||||
appendLog("Loading: ${maskUrl(url)}")
|
||||
statusCtrl.setConnected(false)
|
||||
statusCtrl.setStatus(VpnStatus.CONNECTING)
|
||||
logCtrl.append("Loading: ${maskUrl(url)}")
|
||||
if (previousUrl != url) {
|
||||
previousUrl = url
|
||||
Prefs.lastUrl = url
|
||||
}
|
||||
webView.loadUrl(url)
|
||||
}
|
||||
|
||||
private enum class MenuItem(val id: Int, val stringRes: Int) {
|
||||
MODE(99, R.string.menu_mode),
|
||||
RECONNECT_ON_START(100, R.string.menu_reconnect_on_start),
|
||||
SHOW_LOGS(101, R.string.menu_show_logs),
|
||||
SHARE_LOGS(102, R.string.menu_share_logs),
|
||||
RESET(200, R.string.menu_reset),
|
||||
}
|
||||
|
||||
private fun showGearMenu(anchor: View) {
|
||||
val popup = PopupMenu(this, anchor)
|
||||
val menu = popup.menu
|
||||
|
||||
menu.add(0, MenuItem.MODE.id, 0, getString(MenuItem.MODE.stringRes, tunnelMode.label))
|
||||
|
||||
menu.add(0, MenuItem.RECONNECT_ON_START.id, 0, MenuItem.RECONNECT_ON_START.stringRes).apply {
|
||||
isCheckable = true
|
||||
isChecked = Prefs.connectOnStart
|
||||
}
|
||||
menu.add(0, MenuItem.SHOW_LOGS.id, 0, MenuItem.SHOW_LOGS.stringRes).apply {
|
||||
isCheckable = true
|
||||
isChecked = showLogs
|
||||
}
|
||||
menu.add(0, MenuItem.SHARE_LOGS.id, 0, MenuItem.SHARE_LOGS.stringRes)
|
||||
menu.add(0, MenuItem.RESET.id, 0, MenuItem.RESET.stringRes)
|
||||
|
||||
popup.setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
MenuItem.RECONNECT_ON_START.id -> {
|
||||
Prefs.connectOnStart = !item.isChecked
|
||||
true
|
||||
}
|
||||
MenuItem.SHOW_LOGS.id -> {
|
||||
showLogs = !item.isChecked
|
||||
Prefs.showLogs = showLogs
|
||||
logContainer.visibility = if (showLogs) View.VISIBLE else View.GONE
|
||||
true
|
||||
}
|
||||
MenuItem.SHARE_LOGS.id -> {
|
||||
findViewById<ImageButton>(R.id.shareLogsButton).performClick()
|
||||
true
|
||||
}
|
||||
MenuItem.RESET.id -> {
|
||||
resetState()
|
||||
TunnelVpnService.instance?.stop()
|
||||
true
|
||||
}
|
||||
MenuItem.MODE.id -> {
|
||||
showModeDialog()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
popup.show()
|
||||
}
|
||||
|
||||
private fun showModeDialog() {
|
||||
val modes = TunnelMode.entries
|
||||
val labels = modes.map { it.label }.toTypedArray()
|
||||
val current = modes.indexOf(tunnelMode)
|
||||
android.app.AlertDialog.Builder(this)
|
||||
.setSingleChoiceItems(labels, current) { dialog, which ->
|
||||
dialog.dismiss()
|
||||
val mode = modes[which]
|
||||
if (mode != tunnelMode) {
|
||||
tunnelMode = mode
|
||||
Prefs.tunnelMode = mode
|
||||
resetState()
|
||||
TunnelVpnService.instance?.stop()
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setConnected(value: Boolean) {
|
||||
connected = value
|
||||
goButton.setText(if (value) R.string.btn_disconnect else R.string.btn_go)
|
||||
goButton.setOnClickListener {
|
||||
if (connected) {
|
||||
resetState()
|
||||
TunnelVpnService.instance?.stop()
|
||||
} else {
|
||||
onGoPressed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setStatus(status: VpnStatus) {
|
||||
statusBar.text = getString(R.string.status_format, tunnelMode.label, getString(status.labelRes))
|
||||
val colorRes = when (status) {
|
||||
VpnStatus.TUNNEL_ACTIVE -> R.color.status_active
|
||||
VpnStatus.CONNECTING,
|
||||
VpnStatus.CALL_CONNECTED,
|
||||
VpnStatus.DATACHANNEL_OPEN -> R.color.status_connecting
|
||||
VpnStatus.TUNNEL_LOST,
|
||||
VpnStatus.DATACHANNEL_LOST -> R.color.status_warning
|
||||
VpnStatus.CALL_DISCONNECTED,
|
||||
VpnStatus.CALL_FAILED -> R.color.status_error
|
||||
VpnStatus.STARTING -> R.color.status_idle
|
||||
}
|
||||
statusBar.setBackgroundColor(getColor(colorRes))
|
||||
webViewMgr.loadUrl(url)
|
||||
}
|
||||
|
||||
private fun onVpnStatus(status: VpnStatus) {
|
||||
if (!relay.isRunning) return
|
||||
TunnelVpnService.instance?.updateStatus(status)
|
||||
runOnUiThread {
|
||||
setStatus(status)
|
||||
if (status == VpnStatus.TUNNEL_ACTIVE) setConnected(true)
|
||||
statusCtrl.setStatus(status)
|
||||
if (status == VpnStatus.TUNNEL_ACTIVE) statusCtrl.setConnected(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startRelay() {
|
||||
val isTelemost = urlInput.text.toString().contains("telemost")
|
||||
relay.start(tunnelMode, isTelemost)
|
||||
}
|
||||
|
||||
private fun stopRelay() {
|
||||
relay.stop()
|
||||
}
|
||||
|
||||
private fun requestVpn() {
|
||||
val intent = VpnService.prepare(this)
|
||||
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
|
||||
@@ -278,129 +183,27 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun startVpnService() {
|
||||
startService(Intent(this, TunnelVpnService::class.java))
|
||||
appendLog("VPN started")
|
||||
logCtrl.append("VPN started")
|
||||
onVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
}
|
||||
|
||||
private fun hookForUrl(url: String): String {
|
||||
if (tunnelMode.isPion) {
|
||||
return if (url.contains("telemost.yandex")) hookPionTelemost else hookPionVk
|
||||
}
|
||||
return if (url.contains("telemost.yandex")) hookTelemost else hookVk
|
||||
private fun resetState() {
|
||||
relay.stop()
|
||||
webViewMgr.loadBlank()
|
||||
webViewMgr.collapse()
|
||||
logCtrl.reset()
|
||||
statusCtrl.setConnected(false)
|
||||
statusCtrl.setIdle()
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private fun setupWebView() {
|
||||
webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
domStorageEnabled = true
|
||||
mediaPlaybackRequiresUserGesture = false
|
||||
allowContentAccess = true
|
||||
allowFileAccess = true
|
||||
databaseEnabled = true
|
||||
setSupportMultipleWindows(false)
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
builtInZoomControls = true
|
||||
displayZoomControls = false
|
||||
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
webView.addJavascriptInterface(JsBridge(), "AndroidBridge")
|
||||
|
||||
webView.webChromeClient = object : WebChromeClient() {
|
||||
override fun onPermissionRequest(request: PermissionRequest) {
|
||||
runOnUiThread { request.grant(request.resources) }
|
||||
}
|
||||
|
||||
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
||||
val text = msg.message()
|
||||
Log.d("HOOK", text)
|
||||
if (text.contains("[HOOK]")) {
|
||||
appendLog(text)
|
||||
when {
|
||||
//TODO - use js bridge
|
||||
text.contains("CALL CONNECTED") -> onVpnStatus(VpnStatus.CALL_CONNECTED)
|
||||
text.contains("DataChannel open") -> onVpnStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||
text.contains("DataChannel closed") -> onVpnStatus(VpnStatus.DATACHANNEL_LOST)
|
||||
text.contains("WebSocket connected") -> onVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
text.contains("WebSocket disconnected") -> onVpnStatus(VpnStatus.TUNNEL_LOST)
|
||||
text.contains("Connection state: connecting") -> onVpnStatus(VpnStatus.CONNECTING)
|
||||
text.contains("Connection state: disconnected") -> onVpnStatus(VpnStatus.CALL_DISCONNECTED)
|
||||
text.contains("Connection state: failed") -> onVpnStatus(VpnStatus.CALL_FAILED)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
webView.webViewClient = object : WebViewClient() {
|
||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||
val url = request.url.toString()
|
||||
if (!url.contains("telemost.yandex.ru/j/") || request.method != "GET") return null
|
||||
return try {
|
||||
val conn = java.net.URL(url).openConnection() as java.net.HttpURLConnection
|
||||
conn.requestMethod = "GET"
|
||||
request.requestHeaders?.forEach { (k, v) -> conn.setRequestProperty(k, v) }
|
||||
val headers = mutableMapOf<String, String>()
|
||||
conn.headerFields?.forEach { (k, v) ->
|
||||
if (k != null
|
||||
&& !k.equals("content-security-policy", ignoreCase = true)
|
||||
&& !k.equals("content-security-policy-report-only", ignoreCase = true)
|
||||
) {
|
||||
headers[k] = v.joinToString(", ")
|
||||
}
|
||||
}
|
||||
WebResourceResponse(
|
||||
conn.contentType?.split(";")?.firstOrNull() ?: "text/html",
|
||||
"utf-8", conn.responseCode, conn.responseMessage ?: "OK",
|
||||
headers, conn.inputStream
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView, url: String, favicon: android.graphics.Bitmap?) {
|
||||
view.evaluateJavascript("""(function(){
|
||||
var oac=window.AudioContext||window.webkitAudioContext;
|
||||
if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
c.resume=function(){return Promise.resolve()};
|
||||
return c};
|
||||
nac.prototype=oac.prototype;window.AudioContext=nac;
|
||||
if(window.webkitAudioContext)window.webkitAudioContext=nac}
|
||||
})()""", null)
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
view.evaluateJavascript("!!window.__hookInstalled") { result ->
|
||||
if (result == "true") {
|
||||
Log.d("HOOK", "Hook already injected, skipping")
|
||||
return@evaluateJavascript
|
||||
}
|
||||
appendLog("Page loaded, injecting hook for ${maskUrl(url)}")
|
||||
view.evaluateJavascript(hookForUrl(url), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendLog(msg: String) {
|
||||
val (line, evicted) = logWriter.append(msg)
|
||||
runOnUiThread {
|
||||
if (evicted) {
|
||||
logView.text = logWriter.displayText()
|
||||
} else {
|
||||
logView.append("$line\n")
|
||||
}
|
||||
val scrollAmount = logView.layout?.let {
|
||||
it.getLineTop(logView.lineCount) - logView.height
|
||||
} ?: 0
|
||||
if (scrollAmount > 0) logView.scrollTo(0, scrollAmount)
|
||||
}
|
||||
private fun fullReset() {
|
||||
resetState()
|
||||
TunnelVpnService.instance?.stop()
|
||||
}
|
||||
|
||||
private fun getLocalIPAddress(): String {
|
||||
try {
|
||||
val cm = getSystemService(CONNECTIVITY_SERVICE) as android.net.ConnectivityManager
|
||||
val cm = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val network = cm.activeNetwork ?: return ""
|
||||
val props = cm.getLinkProperties(network) ?: return ""
|
||||
for (addr in props.linkAddresses) {
|
||||
@@ -415,21 +218,10 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun resetState() {
|
||||
stopRelay()
|
||||
webView.loadUrl("about:blank")
|
||||
logWriter.reset()
|
||||
logView.text = ""
|
||||
logView.scrollTo(0, 0)
|
||||
setConnected(false)
|
||||
statusBar.text = getString(R.string.status_format, tunnelMode.label, getString(R.string.status_idle))
|
||||
statusBar.setBackgroundColor(getColor(R.color.status_idle))
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
inner class JsBridge {
|
||||
@JavascriptInterface
|
||||
fun log(msg: String) = appendLog(msg)
|
||||
fun log(msg: String) = logCtrl.append(msg)
|
||||
|
||||
@JavascriptInterface
|
||||
fun getLocalIP(): String = getLocalIPAddress()
|
||||
@@ -449,7 +241,7 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
|
||||
@JavascriptInterface
|
||||
fun onTunnelReady() {
|
||||
appendLog("Tunnel ready, starting VPN...")
|
||||
logCtrl.append("Tunnel ready, starting VPN...")
|
||||
onVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
runOnUiThread { requestVpn() }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
enum class CallPlatform(val id: String, val urlMarker: String) {
|
||||
VK("vk", ""),
|
||||
TELEMOST("telemost", "telemost.yandex");
|
||||
|
||||
companion object {
|
||||
fun fromUrl(url: String): CallPlatform =
|
||||
if (url.contains(TELEMOST.urlMarker)) TELEMOST else VK
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
import android.util.Log
|
||||
import bypass.whitelist.util.Ports
|
||||
import mobile.LogCallback
|
||||
import mobile.Mobile
|
||||
import java.io.File
|
||||
@@ -19,10 +20,10 @@ class RelayController(
|
||||
private set
|
||||
|
||||
@Synchronized
|
||||
fun start(mode: TunnelMode, isTelemost: Boolean) {
|
||||
fun start(mode: TunnelMode, platform: CallPlatform) {
|
||||
stop()
|
||||
isRunning = true
|
||||
if (mode.isPion) startPion(mode, isTelemost) else startDc()
|
||||
if (mode.isPion) startPion(mode, platform) else startDc()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -58,13 +59,13 @@ class RelayController(
|
||||
onLog("Relay started DC mode (SOCKS5 :${Ports.SOCKS}, WS :${Ports.DC_WS})")
|
||||
}
|
||||
|
||||
private fun startPion(mode: TunnelMode, isTelemost: Boolean) {
|
||||
private fun startPion(mode: TunnelMode, platform: CallPlatform) {
|
||||
val relayBin = File(nativeLibDir, "librelay.so")
|
||||
if (!relayBin.exists()) {
|
||||
onLog("Pion relay binary not found")
|
||||
return
|
||||
}
|
||||
val relayMode = mode.relayMode(isTelemost)
|
||||
val relayMode = mode.relayMode(platform)
|
||||
pionThread = Thread {
|
||||
try {
|
||||
val pb = ProcessBuilder(
|
||||
@@ -92,4 +93,4 @@ class RelayController(
|
||||
}
|
||||
}.also { it.start() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
enum class SplitTunnelingMode(val label: String) {
|
||||
NONE("Off"),
|
||||
BYPASS("Bypass"),
|
||||
ONLY("Only")
|
||||
}
|
||||
+4
-5
@@ -1,12 +1,11 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
enum class TunnelMode(val label: String, val relayArg: String, val isPion: Boolean) {
|
||||
DC("DC", "dc", false),
|
||||
PION_VIDEO("Video", "video", true);
|
||||
|
||||
fun relayMode(isTelemost: Boolean): String {
|
||||
fun relayMode(platform: CallPlatform): String {
|
||||
if (!isPion) return "dc-joiner"
|
||||
val platform = if (isTelemost) "telemost" else "vk"
|
||||
return "$platform-$relayArg-joiner"
|
||||
return "${platform.id}-$relayArg-joiner"
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-4
@@ -1,4 +1,4 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
@@ -9,6 +9,10 @@ import android.net.VpnService
|
||||
import android.os.Build
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.util.Log
|
||||
import bypass.whitelist.MainActivity
|
||||
import bypass.whitelist.util.Ports
|
||||
import bypass.whitelist.util.Prefs
|
||||
import bypass.whitelist.util.Vpn
|
||||
import mobile.Mobile
|
||||
|
||||
class TunnelVpnService : VpnService() {
|
||||
@@ -18,11 +22,11 @@ class TunnelVpnService : VpnService() {
|
||||
const val CHANNEL_ID = "vpn_channel"
|
||||
const val NOTIFICATION_ID = 1
|
||||
const val ACTION_STOP = "bypass.whitelist.STOP_VPN"
|
||||
var isRunning = false
|
||||
var instance: TunnelVpnService? = null
|
||||
var onDisconnect: (() -> Unit)? = null
|
||||
}
|
||||
|
||||
var isRunning: Boolean = false
|
||||
private var vpnFd: ParcelFileDescriptor? = null
|
||||
private var tun2socksThread: Thread? = null
|
||||
|
||||
@@ -81,9 +85,30 @@ class TunnelVpnService : VpnService() {
|
||||
.setMtu(Vpn.MTU)
|
||||
|
||||
try {
|
||||
builder.addDisallowedApplication(packageName)
|
||||
when (Prefs.splitTunnelingMode) {
|
||||
SplitTunnelingMode.NONE -> {
|
||||
builder.addDisallowedApplication(packageName)
|
||||
}
|
||||
SplitTunnelingMode.BYPASS -> {
|
||||
builder.addDisallowedApplication(packageName)
|
||||
Prefs.splitTunnelingPackages.forEach {
|
||||
try {
|
||||
builder.addDisallowedApplication(it)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
SplitTunnelingMode.ONLY -> {
|
||||
Prefs.splitTunnelingPackages.forEach {
|
||||
try {
|
||||
builder.addAllowedApplication(it)
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Cannot exclude self: ${e.message}")
|
||||
Log.e(TAG, "Split tunneling failed: ${e.message}")
|
||||
}
|
||||
|
||||
vpnFd = builder.establish()
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.tunnel
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import bypass.whitelist.R
|
||||
|
||||
enum class VpnStatus(@StringRes val labelRes: Int) {
|
||||
STARTING(R.string.vpn_starting),
|
||||
@@ -0,0 +1,51 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.FileProvider
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.util.LogWriter
|
||||
|
||||
class LogViewController(
|
||||
private val activity: AppCompatActivity,
|
||||
private val logView: TextView,
|
||||
private val logWriter: LogWriter,
|
||||
) {
|
||||
fun append(msg: String) {
|
||||
val (line, evicted) = logWriter.append(msg)
|
||||
activity.runOnUiThread {
|
||||
if (evicted) {
|
||||
logView.text = logWriter.displayText()
|
||||
} else {
|
||||
logView.append("$line\n")
|
||||
}
|
||||
val scrollAmount = logView.layout?.let {
|
||||
it.getLineTop(logView.lineCount) - logView.height
|
||||
} ?: 0
|
||||
if (scrollAmount > 0) logView.scrollTo(0, scrollAmount)
|
||||
}
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
logWriter.reset()
|
||||
logView.text = ""
|
||||
logView.scrollTo(0, 0)
|
||||
}
|
||||
|
||||
fun shareLogs() {
|
||||
val uri = FileProvider.getUriForFile(
|
||||
activity, "${activity.packageName}.fileprovider", logWriter.file
|
||||
)
|
||||
val share = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/plain"
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
activity.startActivity(Intent.createChooser(share, activity.getString(R.string.share_logs)))
|
||||
}
|
||||
|
||||
fun close() {
|
||||
logWriter.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.view.View
|
||||
import android.widget.CheckBox
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ListView
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.tunnel.SplitTunnelingMode
|
||||
import bypass.whitelist.tunnel.TunnelMode
|
||||
import bypass.whitelist.tunnel.TunnelVpnService
|
||||
import bypass.whitelist.util.Callback
|
||||
import bypass.whitelist.util.ParamCallback
|
||||
import bypass.whitelist.util.Prefs
|
||||
|
||||
class SettingsMenuController(
|
||||
private val activity: AppCompatActivity,
|
||||
private val onModeChanged: ParamCallback<TunnelMode>,
|
||||
private val onShareLogs: Callback,
|
||||
private val onReset: Callback,
|
||||
) {
|
||||
var tunnelMode: TunnelMode = Prefs.tunnelMode
|
||||
var splitTunnelingMode: SplitTunnelingMode = Prefs.splitTunnelingMode
|
||||
var splitTunnelingPackages: MutableSet<String> = Prefs.splitTunnelingPackages.toMutableSet()
|
||||
var showLogs: Boolean = Prefs.showLogs
|
||||
|
||||
var onShowLogsChanged: ParamCallback<Boolean> = {}
|
||||
|
||||
private enum class MenuItem(val id: Int, val stringRes: Int) {
|
||||
MODE(99, R.string.menu_tunnel),
|
||||
SPLIT_TUNNELING(98, R.string.menu_split_tunneling),
|
||||
SPLIT_TUNNELING_APPS(97, R.string.menu_split_tunneling_manage),
|
||||
RECONNECT_ON_START(100, R.string.menu_reconnect_on_start),
|
||||
SHOW_LOGS(101, R.string.menu_show_logs),
|
||||
SHARE_LOGS(102, R.string.menu_share_logs),
|
||||
RESET(200, R.string.menu_reset),
|
||||
}
|
||||
|
||||
fun show(anchor: View) {
|
||||
val popup = PopupMenu(activity, anchor)
|
||||
val menu = popup.menu
|
||||
|
||||
menu.add(0, MenuItem.MODE.id, 0, activity.getString(MenuItem.MODE.stringRes, tunnelMode.label))
|
||||
menu.add(0, MenuItem.SPLIT_TUNNELING.id, 0, activity.getString(MenuItem.SPLIT_TUNNELING.stringRes, splitTunnelingMode.label))
|
||||
menu.add(0, MenuItem.SPLIT_TUNNELING_APPS.id, 0, MenuItem.SPLIT_TUNNELING_APPS.stringRes).apply {
|
||||
isEnabled = splitTunnelingMode != SplitTunnelingMode.NONE
|
||||
}
|
||||
menu.add(0, MenuItem.RECONNECT_ON_START.id, 0, MenuItem.RECONNECT_ON_START.stringRes).apply {
|
||||
isCheckable = true
|
||||
isChecked = Prefs.connectOnStart
|
||||
}
|
||||
menu.add(0, MenuItem.SHOW_LOGS.id, 0, MenuItem.SHOW_LOGS.stringRes).apply {
|
||||
isCheckable = true
|
||||
isChecked = showLogs
|
||||
}
|
||||
menu.add(0, MenuItem.SHARE_LOGS.id, 0, MenuItem.SHARE_LOGS.stringRes)
|
||||
menu.add(0, MenuItem.RESET.id, 0, MenuItem.RESET.stringRes)
|
||||
|
||||
popup.setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
MenuItem.RECONNECT_ON_START.id -> {
|
||||
Prefs.connectOnStart = !item.isChecked
|
||||
true
|
||||
}
|
||||
MenuItem.SPLIT_TUNNELING.id -> {
|
||||
showSplitTunnelingDialog()
|
||||
true
|
||||
}
|
||||
MenuItem.SPLIT_TUNNELING_APPS.id -> {
|
||||
showSplitTunnelingAppSelection()
|
||||
true
|
||||
}
|
||||
MenuItem.SHOW_LOGS.id -> {
|
||||
showLogs = !item.isChecked
|
||||
Prefs.showLogs = showLogs
|
||||
onShowLogsChanged(showLogs)
|
||||
true
|
||||
}
|
||||
MenuItem.SHARE_LOGS.id -> {
|
||||
onShareLogs()
|
||||
true
|
||||
}
|
||||
MenuItem.RESET.id -> {
|
||||
onReset()
|
||||
true
|
||||
}
|
||||
MenuItem.MODE.id -> {
|
||||
showModeDialog()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
popup.show()
|
||||
}
|
||||
|
||||
private fun showModeDialog() {
|
||||
val modes = TunnelMode.entries
|
||||
val labels = modes.map { it.label }.toTypedArray()
|
||||
val current = modes.indexOf(tunnelMode)
|
||||
AlertDialog.Builder(activity)
|
||||
.setSingleChoiceItems(labels, current) { dialog, which ->
|
||||
dialog.dismiss()
|
||||
val mode = modes[which]
|
||||
if (mode != tunnelMode) {
|
||||
tunnelMode = mode
|
||||
Prefs.tunnelMode = mode
|
||||
onModeChanged(mode)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showSplitTunnelingDialog() {
|
||||
val modes = SplitTunnelingMode.entries.toTypedArray()
|
||||
val labels = modes.map { it.label }.toTypedArray()
|
||||
val selectedIndex = modes.indexOf(splitTunnelingMode)
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.split_tunneling_mode_prompt)
|
||||
.setSingleChoiceItems(labels, selectedIndex) { dialog, which ->
|
||||
splitTunnelingMode = modes[which]
|
||||
Prefs.splitTunnelingMode = splitTunnelingMode
|
||||
dialog.dismiss()
|
||||
if (TunnelVpnService.instance?.isRunning == true) {
|
||||
Toast.makeText(activity, R.string.split_tunneling_mode_changed, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun showSplitTunnelingAppSelection() {
|
||||
var includeSystemApps = false
|
||||
val pm = activity.packageManager
|
||||
|
||||
val installedApps = pm.getInstalledApplications(PackageManager.GET_META_DATA)
|
||||
.filter { it.packageName != activity.packageName }
|
||||
.mapNotNull { appInfo ->
|
||||
val pkg = appInfo.packageName
|
||||
if (pkg.isBlank()) return@mapNotNull null
|
||||
val label = appInfo.loadLabel(pm).toString().takeIf { it.isNotBlank() } ?: pkg
|
||||
SplitTunnelingAppItem(
|
||||
pkg, label, pm.getApplicationIcon(pkg),
|
||||
splitTunnelingPackages.contains(pkg),
|
||||
(appInfo.flags and ApplicationInfo.FLAG_SYSTEM) == 0,
|
||||
)
|
||||
}
|
||||
.distinctBy { it.packageName }
|
||||
.sortedWith(compareByDescending<SplitTunnelingAppItem> { it.isSelected }.thenBy { it.label.lowercase() })
|
||||
|
||||
fun buildAppList() = installedApps.filter { includeSystemApps || it.isUserApp }
|
||||
|
||||
val adapter = SplitTunnelingAdapter(activity.layoutInflater, splitTunnelingPackages)
|
||||
adapter.items = buildAppList()
|
||||
|
||||
if (adapter.items.isEmpty()) return
|
||||
|
||||
val listView = ListView(activity).apply {
|
||||
choiceMode = ListView.CHOICE_MODE_MULTIPLE
|
||||
this.adapter = adapter
|
||||
}
|
||||
|
||||
val systemAppsCheckbox = CheckBox(activity).apply {
|
||||
text = activity.getString(R.string.split_tunneling_show_system_apps)
|
||||
isChecked = includeSystemApps
|
||||
setOnCheckedChangeListener { _, checked ->
|
||||
includeSystemApps = checked
|
||||
adapter.items = buildAppList()
|
||||
}
|
||||
}
|
||||
|
||||
val dialogLayout = LinearLayout(activity).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
setPadding(24, 24, 24, 24)
|
||||
addView(systemAppsCheckbox)
|
||||
addView(listView)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.split_tunneling_apps_prompt)
|
||||
.setView(dialogLayout)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
Prefs.splitTunnelingMode = splitTunnelingMode
|
||||
Prefs.splitTunnelingPackages = splitTunnelingPackages
|
||||
if (TunnelVpnService.instance?.isRunning == true) {
|
||||
Toast.makeText(activity, R.string.split_tunneling_mode_changed, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.CheckBox
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import bypass.whitelist.R
|
||||
|
||||
data class SplitTunnelingAppItem(
|
||||
val packageName: String,
|
||||
val label: String,
|
||||
val icon: Drawable,
|
||||
var isSelected: Boolean = false,
|
||||
val isUserApp: Boolean = false,
|
||||
)
|
||||
|
||||
class SplitTunnelingAdapter(
|
||||
private val inflater: LayoutInflater,
|
||||
private val selectedPackages: MutableSet<String>,
|
||||
) : BaseAdapter() {
|
||||
|
||||
var items: List<SplitTunnelingAppItem> = emptyList()
|
||||
set(value) {
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getCount() = items.size
|
||||
override fun getItem(position: Int) = items[position]
|
||||
override fun getItemId(position: Int) = position.toLong()
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val item = getItem(position)
|
||||
val view = convertView ?: inflater.inflate(R.layout.split_tunneling_app_list_item, parent, false)
|
||||
val iconView = view.findViewById<ImageView>(R.id.appIcon)
|
||||
val labelView = view.findViewById<TextView>(R.id.appLabel)
|
||||
val packageView = view.findViewById<TextView>(R.id.appPackage)
|
||||
val checkbox = view.findViewById<CheckBox>(R.id.appCheckbox)
|
||||
|
||||
iconView.setImageDrawable(item.icon)
|
||||
labelView.text = item.label
|
||||
val isDark = (view.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||
labelView.setTextColor(if (isDark) Color.WHITE else Color.BLACK)
|
||||
packageView.text = item.packageName
|
||||
|
||||
val toggle = { checked: Boolean ->
|
||||
item.isSelected = checked
|
||||
if (checked) selectedPackages.add(item.packageName)
|
||||
else selectedPackages.remove(item.packageName)
|
||||
}
|
||||
|
||||
view.setOnClickListener {
|
||||
val newState = !checkbox.isChecked
|
||||
checkbox.isChecked = newState
|
||||
toggle(newState)
|
||||
}
|
||||
checkbox.setOnCheckedChangeListener { _, isChecked -> toggle(isChecked) }
|
||||
checkbox.isChecked = item.isSelected
|
||||
|
||||
return view
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.tunnel.TunnelMode
|
||||
import bypass.whitelist.tunnel.VpnStatus
|
||||
import bypass.whitelist.util.Callback
|
||||
|
||||
class StatusBarController(
|
||||
private val activity: AppCompatActivity,
|
||||
private val statusBar: TextView,
|
||||
private val goButton: Button,
|
||||
private val onConnect: Callback,
|
||||
private val onDisconnect: Callback,
|
||||
) {
|
||||
var connected = false
|
||||
private set
|
||||
|
||||
var tunnelMode: TunnelMode = TunnelMode.DC
|
||||
|
||||
fun setConnected(value: Boolean) {
|
||||
connected = value
|
||||
goButton.setText(if (value) R.string.btn_disconnect else R.string.btn_go)
|
||||
goButton.setOnClickListener {
|
||||
if (connected) onDisconnect() else onConnect()
|
||||
}
|
||||
}
|
||||
|
||||
fun setStatus(status: VpnStatus) {
|
||||
statusBar.text = activity.getString(R.string.status_format, tunnelMode.label, activity.getString(status.labelRes))
|
||||
val colorRes = when (status) {
|
||||
VpnStatus.TUNNEL_ACTIVE -> R.color.status_active
|
||||
VpnStatus.CONNECTING,
|
||||
VpnStatus.CALL_CONNECTED,
|
||||
VpnStatus.DATACHANNEL_OPEN -> R.color.status_connecting
|
||||
VpnStatus.TUNNEL_LOST,
|
||||
VpnStatus.DATACHANNEL_LOST -> R.color.status_warning
|
||||
VpnStatus.CALL_DISCONNECTED,
|
||||
VpnStatus.CALL_FAILED -> R.color.status_error
|
||||
VpnStatus.STARTING -> R.color.status_idle
|
||||
}
|
||||
statusBar.setBackgroundColor(activity.getColor(colorRes))
|
||||
}
|
||||
|
||||
fun setIdle() {
|
||||
statusBar.text = activity.getString(R.string.status_format, tunnelMode.label, activity.getString(R.string.status_idle))
|
||||
statusBar.setBackgroundColor(activity.getColor(R.color.status_idle))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
package bypass.whitelist.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.webkit.ConsoleMessage
|
||||
import android.webkit.PermissionRequest
|
||||
import android.webkit.WebChromeClient
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebResourceResponse
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import bypass.whitelist.R
|
||||
import bypass.whitelist.tunnel.CallPlatform
|
||||
import bypass.whitelist.tunnel.TunnelMode
|
||||
import bypass.whitelist.tunnel.VpnStatus
|
||||
import bypass.whitelist.util.ParamCallback
|
||||
import bypass.whitelist.util.maskUrl
|
||||
|
||||
private data class HookKey(val isPion: Boolean, val platform: CallPlatform)
|
||||
|
||||
class WebViewManager(
|
||||
private val activity: AppCompatActivity,
|
||||
private val webView: WebView,
|
||||
private val toggleButton: View,
|
||||
private val toggleArrow: ImageView,
|
||||
private val toggleLabel: TextView,
|
||||
private val onLog: ParamCallback<String>,
|
||||
private val onStatus: ParamCallback<VpnStatus>,
|
||||
) {
|
||||
var tunnelMode: TunnelMode = TunnelMode.DC
|
||||
private var expanded = false
|
||||
private var callUrl = ""
|
||||
|
||||
private val hooks = mapOf(
|
||||
HookKey(false, CallPlatform.VK) to lazy { loadAsset("dc-joiner-vk.js") },
|
||||
HookKey(false, CallPlatform.TELEMOST) to lazy { loadAsset("dc-joiner-telemost.js") },
|
||||
HookKey(true, CallPlatform.VK) to lazy { loadAsset("video-vk.js") },
|
||||
HookKey(true, CallPlatform.TELEMOST) to lazy { loadAsset("video-telemost.js") },
|
||||
)
|
||||
|
||||
private val autoclickers = mapOf(
|
||||
CallPlatform.VK to lazy { loadAsset("autoclick-vk.js") },
|
||||
CallPlatform.TELEMOST to lazy { loadAsset("autoclick-telemost.js") },
|
||||
)
|
||||
|
||||
private val muteAudioContext by lazy { loadAsset("mute-audio-context.js") }
|
||||
|
||||
private fun loadAsset(name: String): String =
|
||||
activity.assets.open(name).bufferedReader().readText()
|
||||
|
||||
private fun setExpanded(value: Boolean) {
|
||||
expanded = value
|
||||
webView.visibility = if (value) View.VISIBLE else View.GONE
|
||||
toggleArrow.rotation = if (value) 180f else 0f
|
||||
toggleLabel.setText(if (value) R.string.collapse_webview else R.string.expand_webview)
|
||||
}
|
||||
|
||||
fun collapse() {
|
||||
setExpanded(false)
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun setup(jsBridge: Any) {
|
||||
toggleButton.setOnClickListener { setExpanded(!expanded) }
|
||||
webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
domStorageEnabled = true
|
||||
mediaPlaybackRequiresUserGesture = false
|
||||
allowContentAccess = true
|
||||
allowFileAccess = true
|
||||
databaseEnabled = true
|
||||
setSupportMultipleWindows(false)
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
builtInZoomControls = true
|
||||
displayZoomControls = false
|
||||
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
}
|
||||
|
||||
webView.addJavascriptInterface(jsBridge, "AndroidBridge")
|
||||
|
||||
webView.webChromeClient = object : WebChromeClient() {
|
||||
override fun onPermissionRequest(request: PermissionRequest) {
|
||||
activity.runOnUiThread { request.grant(request.resources) }
|
||||
}
|
||||
|
||||
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
||||
val text = msg.message()
|
||||
Log.d("HOOK", text)
|
||||
if (text.contains("[HOOK]")) {
|
||||
onLog(text)
|
||||
when {
|
||||
text.contains("CALL CONNECTED") -> onStatus(VpnStatus.CALL_CONNECTED)
|
||||
text.contains("DataChannel open") -> onStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||
text.contains("DataChannel closed") -> onStatus(VpnStatus.DATACHANNEL_LOST)
|
||||
text.contains("WebSocket connected") -> onStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
text.contains("WebSocket disconnected") -> onStatus(VpnStatus.TUNNEL_LOST)
|
||||
text.contains("Connection state: connecting") -> onStatus(VpnStatus.CONNECTING)
|
||||
text.contains("Connection state: disconnected") -> onStatus(VpnStatus.CALL_DISCONNECTED)
|
||||
text.contains("Connection state: failed") -> onStatus(VpnStatus.CALL_FAILED)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
webView.webViewClient = object : WebViewClient() {
|
||||
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||
val url = request.url.toString()
|
||||
val platform = CallPlatform.fromUrl(url)
|
||||
if (platform != CallPlatform.TELEMOST || !url.contains("/j/") || request.method != "GET") return null
|
||||
return stripCsp(url, request)
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
|
||||
if (url.contains("about:blank")) return
|
||||
view.evaluateJavascript(muteAudioContext, null)
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
if (url.contains("about:blank")) return
|
||||
if (!expanded && url != callUrl) activity.runOnUiThread { setExpanded(true) }
|
||||
view.evaluateJavascript("!!window.__hookInstalled") { result ->
|
||||
if (result == "true") {
|
||||
Log.d("HOOK", "Hook already injected, skipping")
|
||||
return@evaluateJavascript
|
||||
}
|
||||
val platform = CallPlatform.fromUrl(url)
|
||||
onLog("Page loaded, injecting hook for ${maskUrl(url)}")
|
||||
view.evaluateJavascript("window.WS_PORT=${mobile.Mobile.activeWsPort()}", null)
|
||||
view.evaluateJavascript(hookForPlatform(platform), null)
|
||||
onLog("Injecting autoclick for ${maskUrl(url)}")
|
||||
view.evaluateJavascript(autoclickers[platform]!!.value, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadUrl(url: String) {
|
||||
callUrl = url
|
||||
webView.loadUrl(url)
|
||||
}
|
||||
|
||||
fun loadBlank() {
|
||||
callUrl = ""
|
||||
webView.loadUrl("about:blank")
|
||||
}
|
||||
|
||||
private fun hookForPlatform(platform: CallPlatform): String =
|
||||
hooks[HookKey(tunnelMode.isPion, platform)]!!.value
|
||||
|
||||
private fun stripCsp(url: String, request: WebResourceRequest): WebResourceResponse? {
|
||||
return try {
|
||||
val conn = java.net.URL(url).openConnection() as java.net.HttpURLConnection
|
||||
conn.requestMethod = "GET"
|
||||
request.requestHeaders?.forEach { (k, v) -> conn.setRequestProperty(k, v) }
|
||||
val headers = mutableMapOf<String, String>()
|
||||
conn.headerFields?.forEach { (k, v) ->
|
||||
if (k != null
|
||||
&& !k.equals("content-security-policy", ignoreCase = true)
|
||||
&& !k.equals("content-security-policy-report-only", ignoreCase = true)
|
||||
) {
|
||||
headers[k] = v.joinToString(", ")
|
||||
}
|
||||
}
|
||||
WebResourceResponse(
|
||||
conn.contentType?.split(";")?.firstOrNull() ?: "text/html",
|
||||
"utf-8", conn.responseCode, conn.responseMessage ?: "OK",
|
||||
headers, conn.inputStream
|
||||
)
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package bypass.whitelist.util
|
||||
|
||||
typealias Callback = () -> Unit
|
||||
typealias ParamCallback<T> = (T) -> Unit
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.util
|
||||
|
||||
object Ports {
|
||||
const val SOCKS = 1080L
|
||||
@@ -11,6 +11,8 @@ object PrefsKeys {
|
||||
const val URL = "url"
|
||||
const val TUNNEL_MODE = "tunnel_mode"
|
||||
const val SHOW_LOGS = "show_logs"
|
||||
const val SPLIT_TUNNELING_MODE = "split_tunneling_mode"
|
||||
const val SPLIT_TUNNELING_PACKAGES = "split_tunneling_packages"
|
||||
}
|
||||
|
||||
object Vpn {
|
||||
@@ -21,4 +23,4 @@ object Vpn {
|
||||
const val DNS_PRIMARY = "8.8.8.8"
|
||||
const val DNS_SECONDARY = "8.8.4.4"
|
||||
const val SESSION_NAME = "WhitelistBypass"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
@@ -6,4 +6,4 @@ import android.view.inputmethod.InputMethodManager
|
||||
fun Activity.hideKeyboard() {
|
||||
val imm = getSystemService(InputMethodManager::class.java)
|
||||
currentFocus?.let { imm.hideSoftInputFromWindow(it.windowToken, 0) }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.util
|
||||
|
||||
private val reUrl = Regex("(https?://[^/]+/)(.+)")
|
||||
private val reIp4 = Regex("\\d+\\.\\d+\\.\\d+\\.\\d+")
|
||||
+16
-18
@@ -1,42 +1,40 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.util
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.ArrayDeque
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
class LogWriter(cacheDir: File, private val maxDisplayLines: Int = 100) {
|
||||
|
||||
val file: File get() = logFile
|
||||
|
||||
private val logFile = File(cacheDir, "tunnel.log")
|
||||
private val logFile = File(cacheDir, "relay.log")
|
||||
private var writer: FileWriter? = null
|
||||
private val recentLines = ArrayDeque<String>(maxDisplayLines)
|
||||
private val timeFmt = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
|
||||
private val displayLines = ArrayDeque<String>()
|
||||
private val dateFormat = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
|
||||
|
||||
val file: File get() = logFile
|
||||
|
||||
@Synchronized
|
||||
fun reset() {
|
||||
writer?.close()
|
||||
writer = FileWriter(logFile, false)
|
||||
recentLines.clear()
|
||||
displayLines.clear()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun append(msg: String): AppendResult {
|
||||
val line = "${timeFmt.format(System.currentTimeMillis())} ${msg.replace("[HOOK] ", "")}"
|
||||
writer?.appendLine(line)
|
||||
writer?.flush()
|
||||
val evicted = recentLines.size >= maxDisplayLines
|
||||
if (evicted) recentLines.pollFirst()
|
||||
recentLines.addLast(line)
|
||||
val ts = dateFormat.format(Date())
|
||||
val line = "$ts $msg"
|
||||
writer?.apply { write("$line\n"); flush() }
|
||||
displayLines.addLast(line)
|
||||
val evicted = displayLines.size > maxDisplayLines
|
||||
if (evicted) displayLines.removeFirst()
|
||||
return AppendResult(line, evicted)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun displayText(): String {
|
||||
return recentLines.joinToString("\n")
|
||||
}
|
||||
fun displayText(): String = displayLines.joinToString("\n")
|
||||
|
||||
@Synchronized
|
||||
fun close() {
|
||||
@@ -45,4 +43,4 @@ class LogWriter(cacheDir: File, private val maxDisplayLines: Int = 100) {
|
||||
}
|
||||
|
||||
data class AppendResult(val line: String, val evicted: Boolean)
|
||||
}
|
||||
}
|
||||
+19
-2
@@ -1,8 +1,10 @@
|
||||
package bypass.whitelist
|
||||
package bypass.whitelist.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import bypass.whitelist.tunnel.SplitTunnelingMode
|
||||
import bypass.whitelist.tunnel.TunnelMode
|
||||
|
||||
object Prefs {
|
||||
|
||||
@@ -34,4 +36,19 @@ object Prefs {
|
||||
var showLogs: Boolean
|
||||
get() = prefs.getBoolean(PrefsKeys.SHOW_LOGS, false)
|
||||
set(value) = prefs.edit { putBoolean(PrefsKeys.SHOW_LOGS, value) }
|
||||
}
|
||||
|
||||
var splitTunnelingMode: SplitTunnelingMode
|
||||
get() {
|
||||
val title = prefs.getString(PrefsKeys.SPLIT_TUNNELING_MODE, SplitTunnelingMode.NONE.name)!!
|
||||
return try {
|
||||
SplitTunnelingMode.valueOf(title)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
SplitTunnelingMode.NONE
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit { putString(PrefsKeys.SPLIT_TUNNELING_MODE, value.name) }
|
||||
|
||||
var splitTunnelingPackages: Set<String>
|
||||
get() = prefs.getStringSet(PrefsKeys.SPLIT_TUNNELING_PACKAGES, emptySet()) ?: emptySet()
|
||||
set(value) = prefs.edit { putStringSet(PrefsKeys.SPLIT_TUNNELING_PACKAGES, value) }
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="12dp"
|
||||
android:height="8dp"
|
||||
android:viewportWidth="12"
|
||||
android:viewportHeight="8">
|
||||
<path
|
||||
android:pathData="M10.59,0.59L6,5.17L1.41,0.59L0,2L6,8L12,2L10.59,0.59Z"
|
||||
android:fillColor="#000"/>
|
||||
</vector>
|
||||
@@ -97,10 +97,46 @@
|
||||
app:tint="#888888" />
|
||||
</FrameLayout>
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webView"
|
||||
<LinearLayout
|
||||
android:id="@+id/webViewContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/toggleWebViewButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggleWebViewArrow"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:src="@drawable/ic_arrow_down"
|
||||
app:tint="?android:attr/textColorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toggleWebViewLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:text="@string/expand_webview"
|
||||
android:textSize="13sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/appIcon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:contentDescription="app icon" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appPackage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:textColor="@android:color/darker_gray" />
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/appCheckbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
@@ -9,10 +9,18 @@
|
||||
<string name="menu_show_logs">Show logs</string>
|
||||
<string name="menu_share_logs">Share logs</string>
|
||||
<string name="menu_reset">Reset</string>
|
||||
<string name="menu_mode">Mode: %1$s</string>
|
||||
<string name="menu_tunnel">Tunnel: %1$s</string>
|
||||
<string name="menu_split_tunneling">Split tunneling (%1$s)</string>
|
||||
<string name="menu_split_tunneling_manage">Manage split tunneling apps</string>
|
||||
<string name="split_tunneling_mode_prompt">Split tunneling mode</string>
|
||||
<string name="split_tunneling_apps_prompt">Select apps</string>
|
||||
<string name="split_tunneling_show_system_apps">Show system apps</string>
|
||||
<string name="split_tunneling_mode_changed">Reconnect for changes to take effect</string>
|
||||
<string name="hint_call_link">Paste call link</string>
|
||||
<string name="cd_clear">Clear</string>
|
||||
<string name="cd_settings">Settings</string>
|
||||
<string name="expand_webview">Expand WebView</string>
|
||||
<string name="collapse_webview">Collapse WebView</string>
|
||||
<string name="vpn_starting">Starting…</string>
|
||||
<string name="vpn_connecting">Connecting…</string>
|
||||
<string name="vpn_call_connected">Call connected</string>
|
||||
|
||||
@@ -7,4 +7,7 @@ cp "$ROOT/hooks/dc-joiner-vk.js" "$ASSETS/dc-joiner-vk.js"
|
||||
cp "$ROOT/hooks/dc-joiner-telemost.js" "$ASSETS/dc-joiner-telemost.js"
|
||||
cp "$ROOT/hooks/video-vk.js" "$ASSETS/video-vk.js"
|
||||
cp "$ROOT/hooks/video-telemost.js" "$ASSETS/video-telemost.js"
|
||||
cp "$ROOT/hooks/autoclick-telemost.js" "$ASSETS/autoclick-telemost.js"
|
||||
cp "$ROOT/hooks/autoclick-vk.js" "$ASSETS/autoclick-vk.js"
|
||||
cp "$ROOT/hooks/mute-audio-context.js" "$ASSETS/mute-audio-context.js"
|
||||
echo "Hooks copied to assets"
|
||||
@@ -19,7 +19,9 @@ class BotManager {
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error) {
|
||||
throw new Error(data.error.error_msg || 'VK API error');
|
||||
var errMsg = method + ' code: ' + data.error.error_code + ' msg: ' + (data.error.error_msg || 'VK API error') + ' params: ' + JSON.stringify(data.error.request_params || []);
|
||||
console.error('[BOT] API error:', errMsg);
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
return data.response;
|
||||
}
|
||||
@@ -42,6 +44,8 @@ class BotManager {
|
||||
this.pollLoop();
|
||||
} catch (err) {
|
||||
console.error('[BOT] Failed to start:', err.message);
|
||||
this.running = false;
|
||||
if (this.onError) this.onError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+65
-8
@@ -11,6 +11,9 @@ body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0
|
||||
.tab.active { background: #1a1a1a; color: #e0e0e0; }
|
||||
.tab .close { font-size: 14px; opacity: 0.5; cursor: pointer; margin-left: 4px; }
|
||||
.tab .close:hover { opacity: 1; }
|
||||
.tab .edit { width: 12px; height: 12px; opacity: 0; cursor: pointer; filter: invert(1) brightness(2); margin-left: 2px; }
|
||||
.tab:hover .edit { opacity: 0.4; }
|
||||
.tab .edit:hover { opacity: 1; }
|
||||
.tab-add { padding: 0 12px; height: 100%; display: flex; align-items: center; font-size: 16px; cursor: pointer; color: #888; }
|
||||
.tab-add:hover { color: #e0e0e0; }
|
||||
.tab-settings { padding: 0 12px; height: 100%; display: flex; align-items: center; font-size: 14px; cursor: pointer; color: #888; }
|
||||
@@ -105,7 +108,32 @@ body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="popup-overlay" id="errorPopup" onclick="closeError()">
|
||||
<div class="popup" style="padding:16px" onclick="event.stopPropagation()">
|
||||
<h2 style="color:#dc3545;margin-bottom:12px;font-size:15px">Bot error</h2>
|
||||
<pre id="errorText" style="background:#111;padding:10px;border-radius:6px;font-size:11px;color:#e0e0e0;white-space:pre-wrap;word-break:break-all;max-height:200px;overflow-y:auto;user-select:text;cursor:text;margin:0"></pre>
|
||||
<div class="popup-buttons" style="margin-top:12px">
|
||||
<button class="btn-cancel" onclick="closeError()">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function showError(msg) {
|
||||
document.getElementById('errorText').textContent = msg;
|
||||
document.getElementById('errorPopup').classList.add('visible');
|
||||
}
|
||||
function closeError() {
|
||||
document.getElementById('errorPopup').classList.remove('visible');
|
||||
}
|
||||
|
||||
window.bridge.onBotError(function(msg) {
|
||||
showError(msg);
|
||||
botRunning = false;
|
||||
var btn = document.getElementById('tabBot');
|
||||
btn.textContent = 'Bot: Off';
|
||||
btn.classList.remove('running');
|
||||
});
|
||||
|
||||
var tabsState = {}; // tabId -> { wv, mode, relayLogs, hookLogs }
|
||||
var activeTabId = null;
|
||||
var nextTabId = 1;
|
||||
@@ -154,7 +182,7 @@ function toggleBot() {
|
||||
|
||||
function addTab() {
|
||||
var tabId = 'tab-' + (nextTabId++);
|
||||
tabsState[tabId] = { wv: null, url: '', mode: 'dc', relayLogs: '', hookLogs: '' };
|
||||
tabsState[tabId] = { wv: null, url: '', mode: 'dc', relayLogs: '', hookLogs: '', name: '' };
|
||||
window.bridge.startRelay(tabId);
|
||||
renderTabs();
|
||||
selectTab(tabId);
|
||||
@@ -184,23 +212,51 @@ function selectTab(tabId) {
|
||||
renderContent();
|
||||
}
|
||||
|
||||
function getTabLabel(t) {
|
||||
if (t.name) return t.name;
|
||||
if (t.url) {
|
||||
if (t.url.includes('vk.com')) return 'VK';
|
||||
if (t.url.includes('telemost')) return 'Telemost';
|
||||
}
|
||||
return 'New';
|
||||
}
|
||||
|
||||
function renderTabs() {
|
||||
var bar = document.getElementById('tabBar');
|
||||
var html = '';
|
||||
Object.keys(tabsState).forEach(function(id) {
|
||||
var t = tabsState[id];
|
||||
var label = 'New';
|
||||
if (t.url) {
|
||||
if (t.url.includes('vk.com')) label = 'VK';
|
||||
else if (t.url.includes('telemost')) label = 'Telemost';
|
||||
}
|
||||
var label = getTabLabel(t);
|
||||
var cls = id === activeTabId ? 'tab active' : 'tab';
|
||||
html += '<div class="' + cls + '" onclick="selectTab(\'' + id + '\')">' + label + ' <span class="close" onclick="closeTab(\'' + id + '\', event)">✕</span></div>';
|
||||
html += '<div class="' + cls + '" onclick="selectTab(\'' + id + '\')"><span class="tab-label">' + label + '</span><img class="edit" src="resources/icons8-pencil-50.png" onclick="renameTab(\'' + id + '\', event)"> <span class="close" onclick="closeTab(\'' + id + '\', event)">✕</span></div>';
|
||||
});
|
||||
html += '<div class="tab-add" onclick="addTab()" title="New tab">+</div>';
|
||||
bar.innerHTML = html;
|
||||
}
|
||||
|
||||
function renameTab(tabId, e) {
|
||||
e.stopPropagation();
|
||||
var tab = e.target.closest('.tab');
|
||||
var span = tab.querySelector('.tab-label');
|
||||
var inp = document.createElement('input');
|
||||
inp.type = 'text';
|
||||
inp.value = tabsState[tabId].name || '';
|
||||
inp.placeholder = getTabLabel(tabsState[tabId]);
|
||||
inp.style.cssText = 'width:80px;padding:0 4px;border:1px solid #555;border-radius:4px;font-size:12px;background:#111;color:#e0e0e0;outline:none';
|
||||
span.replaceWith(inp);
|
||||
inp.focus();
|
||||
inp.select();
|
||||
var done = function() {
|
||||
tabsState[tabId].name = inp.value.trim();
|
||||
renderTabs();
|
||||
};
|
||||
inp.addEventListener('blur', done);
|
||||
inp.addEventListener('keydown', function(ev) {
|
||||
if (ev.key === 'Enter') inp.blur();
|
||||
if (ev.key === 'Escape') { inp.value = ''; inp.blur(); }
|
||||
});
|
||||
}
|
||||
|
||||
function renderContent() {
|
||||
var content = document.getElementById('content');
|
||||
var welcome = document.getElementById('welcome');
|
||||
@@ -345,7 +401,8 @@ window.bridge.onCreateBotTab(function(data) {
|
||||
var platform = data.platform || 'vk';
|
||||
|
||||
if (!tabsState[tabId]) {
|
||||
tabsState[tabId] = { wv: null, url: '', mode: mode, relayLogs: '', hookLogs: '', isBot: true, peerId: peerId, platform: platform };
|
||||
var botName = platform === 'telemost' ? 'Bot-Telemost' : 'Bot-VK';
|
||||
tabsState[tabId] = { wv: null, url: '', mode: mode, relayLogs: '', hookLogs: '', name: botName, isBot: true, peerId: peerId, platform: platform };
|
||||
}
|
||||
|
||||
selectTab(tabId);
|
||||
|
||||
+31
-13
@@ -20,16 +20,29 @@ var mainWindow = null;
|
||||
var botManager = null;
|
||||
var botTabs = new Set();
|
||||
|
||||
function allocPorts() {
|
||||
var dc = nextPortBase;
|
||||
var pion = nextPortBase + 1;
|
||||
nextPortBase += 2;
|
||||
return { dc: dc, pion: pion };
|
||||
function isPortFree(port) {
|
||||
return new Promise(function(resolve) {
|
||||
var server = require('net').createServer();
|
||||
server.once('error', function() { resolve(false); });
|
||||
server.once('listening', function() { server.close(function() { resolve(true); }); });
|
||||
server.listen(port, '127.0.0.1');
|
||||
});
|
||||
}
|
||||
|
||||
function getTab(tabId) {
|
||||
async function allocPorts() {
|
||||
while (true) {
|
||||
var dc = nextPortBase;
|
||||
var pion = nextPortBase + 1;
|
||||
nextPortBase += 2;
|
||||
var dcFree = await isPortFree(dc);
|
||||
var pionFree = await isPortFree(pion);
|
||||
if (dcFree && pionFree) return { dc: dc, pion: pion };
|
||||
}
|
||||
}
|
||||
|
||||
async function getTab(tabId) {
|
||||
if (!tabs.has(tabId)) {
|
||||
var ports = allocPorts();
|
||||
var ports = await allocPorts();
|
||||
tabs.set(tabId, { relay: null, tunnelMode: 'dc', platform: 'vk', dcPort: ports.dc, pionPort: ports.pion });
|
||||
}
|
||||
return tabs.get(tabId);
|
||||
@@ -200,8 +213,8 @@ function createWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.handle('get-hook-code', function(e, tabId, url) {
|
||||
var tab = getTab(tabId);
|
||||
ipcMain.handle('get-hook-code', async function(e, tabId, url) {
|
||||
var tab = await getTab(tabId);
|
||||
return loadHook(url, tab);
|
||||
});
|
||||
|
||||
@@ -219,8 +232,8 @@ ipcMain.handle('set-tunnel-mode', function(e, tabId, mode) {
|
||||
setTimeout(function() { startRelay(tab); }, 500);
|
||||
});
|
||||
|
||||
ipcMain.handle('start-relay', function(e, tabId) {
|
||||
var tab = getTab(tabId);
|
||||
ipcMain.handle('start-relay', async function(e, tabId) {
|
||||
var tab = await getTab(tabId);
|
||||
startRelay(tab);
|
||||
});
|
||||
|
||||
@@ -238,17 +251,22 @@ ipcMain.handle('start-bot', function(e, settings) {
|
||||
if (botManager) {
|
||||
botManager.stop();
|
||||
}
|
||||
botManager = new BotManager(settings, function(tabConfig) {
|
||||
botManager = new BotManager(settings, async function(tabConfig) {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
|
||||
var tabId = 'bot-tab-' + Date.now();
|
||||
var ports = allocPorts();
|
||||
var ports = await allocPorts();
|
||||
tabs.set(tabId, { relay: null, tunnelMode: tabConfig.mode, platform: tabConfig.platform || 'vk', dcPort: ports.dc, pionPort: ports.pion, peerId: tabConfig.peerId });
|
||||
botTabs.add(tabId);
|
||||
|
||||
mainWindow.webContents.send('create-bot-tab', { tabId: tabId, mode: tabConfig.mode, peerId: tabConfig.peerId, platform: tabConfig.platform || 'vk' });
|
||||
console.log('[BOT] Created tab:', tabId, 'mode:', tabConfig.mode, 'platform:', tabConfig.platform, 'peerId:', tabConfig.peerId);
|
||||
});
|
||||
botManager.onError = function(msg) {
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
mainWindow.webContents.send('bot-error', msg);
|
||||
}
|
||||
};
|
||||
botManager.start();
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "whitelist-bypass-creator",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "whitelist-bypass-creator",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.7.0"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "whitelist-bypass-creator",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
|
||||
@@ -9,5 +9,6 @@ contextBridge.exposeInMainWorld('bridge', {
|
||||
startBot: function(settings) { return ipcRenderer.invoke('start-bot', settings); },
|
||||
stopBot: function() { return ipcRenderer.invoke('stop-bot'); },
|
||||
onCreateBotTab: function(cb) { ipcRenderer.on('create-bot-tab', function(e, data) { cb(data); }); },
|
||||
getCallCreatorCode: function(scriptFile) { return ipcRenderer.invoke('get-call-creator-code', scriptFile); }
|
||||
getCallCreatorCode: function(scriptFile) { return ipcRenderer.invoke('get-call-creator-code', scriptFile); },
|
||||
onBotError: function(cb) { ipcRenderer.on('bot-error', function(e, msg) { cb(msg); }); }
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 513 B |
@@ -0,0 +1,37 @@
|
||||
(function() {
|
||||
if (window.__autoclickInstalled) return;
|
||||
window.__autoclickInstalled = true;
|
||||
|
||||
var log = function() {
|
||||
var args = ['[HOOK] [autoclick]'];
|
||||
for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
log('Autoclick installed');
|
||||
|
||||
function scan() {
|
||||
var all = document.querySelectorAll('[data-testid="orb-button"]');
|
||||
log('scan: ' + all.length + ' orb-buttons found');
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var txt = (all[i].textContent || '').trim();
|
||||
log(' btn[' + i + ']: "' + txt + '"');
|
||||
if (txt.indexOf('Продолжить в браузере') !== -1) {
|
||||
log('Clicking: Продолжить в браузере');
|
||||
all[i].click();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var joinBtn = document.querySelector('[data-testid="enter-conference-button"]');
|
||||
if (joinBtn) {
|
||||
log('Clicking: Подключиться');
|
||||
joinBtn.click();
|
||||
clearInterval(iv);
|
||||
log('Autoclick done');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var iv = setInterval(scan, 1500);
|
||||
})();
|
||||
@@ -0,0 +1,44 @@
|
||||
(function() {
|
||||
if (window.__autoclickInstalled) return;
|
||||
window.__autoclickInstalled = true;
|
||||
|
||||
var log = function() {
|
||||
var args = ['[HOOK] [autoclick]'];
|
||||
for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
log('Autoclick installed');
|
||||
|
||||
function findNameInput() {
|
||||
var inputs = document.querySelectorAll('input[type="text"]');
|
||||
for (var i = 0; i < inputs.length; i++) {
|
||||
var ph = (inputs[i].placeholder || '').toLowerCase();
|
||||
if (ph.indexOf('name') !== -1 || ph.indexOf('имя') !== -1) return inputs[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function scan() {
|
||||
var inp = findNameInput();
|
||||
if (inp && !inp.value) {
|
||||
log('Filling name');
|
||||
var set = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set;
|
||||
set.call(inp, 'Hello');
|
||||
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
inp.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
var joinBtn = document.querySelector('[data-testid="calls_preview_join_button_anonym"]');
|
||||
if (joinBtn && inp && inp.value) {
|
||||
log('Clicking: Join');
|
||||
joinBtn.click();
|
||||
clearInterval(iv);
|
||||
log('Autoclick done');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var iv = setInterval(scan, 1500);
|
||||
})();
|
||||
@@ -235,31 +235,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||
var chunkSize = 4096;
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
sendRaw('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
sendRaw(new ArrayBuffer(chunkSize));
|
||||
sent += chunkSize;
|
||||
}
|
||||
sendRaw('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
@@ -60,34 +60,8 @@
|
||||
activeDC = null;
|
||||
};
|
||||
|
||||
let bwRecvBytes = 0;
|
||||
let bwRecvStart = 0;
|
||||
let bwMode = false;
|
||||
|
||||
dc.onmessage = (e) => {
|
||||
if (dc !== activeDC) return;
|
||||
if (bwMode) {
|
||||
if (e.data instanceof ArrayBuffer) {
|
||||
if (bwRecvStart === 0) bwRecvStart = performance.now();
|
||||
bwRecvBytes += e.data.byteLength;
|
||||
return;
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
bwMode = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:start') {
|
||||
bwMode = true;
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
return;
|
||||
}
|
||||
if (activeWS && wsOpen) {
|
||||
activeWS.send(e.data);
|
||||
}
|
||||
@@ -132,32 +106,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||
var chunkSize = 16384;
|
||||
var chunk = new ArrayBuffer(chunkSize);
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
activeDC.send('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
activeDC.send(chunk);
|
||||
sent += chunkSize;
|
||||
}
|
||||
activeDC.send('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
@@ -3,7 +3,7 @@
|
||||
if (window.__hookInstalled) return;
|
||||
window.__hookInstalled = true;
|
||||
|
||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||
const WS_URL = 'ws://127.0.0.1:' + (window.WS_PORT || 9000) + '/ws';
|
||||
const log = (...args) => console.log('[HOOK]', ...args);
|
||||
const peers = [];
|
||||
let activeWS = null;
|
||||
@@ -278,31 +278,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||
var chunkSize = 4096;
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
sendRaw('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
sendRaw(new ArrayBuffer(chunkSize));
|
||||
sent += chunkSize;
|
||||
}
|
||||
sendRaw('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
+1
-54
@@ -3,7 +3,7 @@
|
||||
if (window.__hookInstalled) return;
|
||||
window.__hookInstalled = true;
|
||||
|
||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||
const WS_URL = 'ws://127.0.0.1:' + (window.WS_PORT || 9000) + '/ws';
|
||||
const log = (...args) => console.log('[HOOK]', ...args);
|
||||
const peers = [];
|
||||
let activeWS = null;
|
||||
@@ -60,34 +60,8 @@
|
||||
activeDC = null;
|
||||
};
|
||||
|
||||
let bwRecvBytes = 0;
|
||||
let bwRecvStart = 0;
|
||||
let bwMode = false;
|
||||
|
||||
dc.onmessage = (e) => {
|
||||
if (dc !== activeDC) return;
|
||||
if (bwMode) {
|
||||
if (e.data instanceof ArrayBuffer) {
|
||||
if (bwRecvStart === 0) bwRecvStart = performance.now();
|
||||
bwRecvBytes += e.data.byteLength;
|
||||
return;
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
bwMode = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (typeof e.data === 'string' && e.data === 'bw:start') {
|
||||
bwMode = true;
|
||||
bwRecvBytes = 0;
|
||||
bwRecvStart = 0;
|
||||
return;
|
||||
}
|
||||
if (activeWS && wsOpen) {
|
||||
activeWS.send(e.data);
|
||||
}
|
||||
@@ -136,32 +110,5 @@
|
||||
}
|
||||
|
||||
window.__hook = { peers: peers, log: log };
|
||||
window.__hook.runBandwidthTest = function(totalMB) {
|
||||
totalMB = totalMB || 1;
|
||||
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||
var chunkSize = 16384;
|
||||
var chunk = new ArrayBuffer(chunkSize);
|
||||
var totalBytes = totalMB * 1024 * 1024;
|
||||
var sent = 0;
|
||||
var start = performance.now();
|
||||
activeDC.send('bw:start');
|
||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||
var sendBatch = function() {
|
||||
while (sent < totalBytes) {
|
||||
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||
setTimeout(sendBatch, 5);
|
||||
return;
|
||||
}
|
||||
activeDC.send(chunk);
|
||||
sent += chunkSize;
|
||||
}
|
||||
activeDC.send('bw:done');
|
||||
var elapsed = (performance.now() - start) / 1000;
|
||||
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||
};
|
||||
sendBatch();
|
||||
};
|
||||
|
||||
log('Hook installed');
|
||||
})();
|
||||
@@ -0,0 +1,14 @@
|
||||
(function() {
|
||||
var oac = window.AudioContext || window.webkitAudioContext;
|
||||
if (oac) {
|
||||
var nac = function() {
|
||||
var c = new oac();
|
||||
c.suspend();
|
||||
c.resume = function() { return Promise.resolve(); };
|
||||
return c;
|
||||
};
|
||||
nac.prototype = oac.prototype;
|
||||
window.AudioContext = nac;
|
||||
if (window.webkitAudioContext) window.webkitAudioContext = nac;
|
||||
}
|
||||
})();
|
||||
Binary file not shown.
+39
-16
@@ -116,11 +116,16 @@ func (w *wsWriter) close() {
|
||||
|
||||
var activeJoiner struct {
|
||||
sync.Mutex
|
||||
j *joinerRelay
|
||||
ws *http.Server
|
||||
socksLn net.Listener
|
||||
j *joinerRelay
|
||||
ws *http.Server
|
||||
socksLn net.Listener
|
||||
wsPort int
|
||||
socksPort int
|
||||
}
|
||||
|
||||
func ActiveWsPort() int { return activeJoiner.wsPort }
|
||||
func ActiveSocksPort() int { return activeJoiner.socksPort }
|
||||
|
||||
func StopJoiner() {
|
||||
activeJoiner.Lock()
|
||||
defer activeJoiner.Unlock()
|
||||
@@ -139,6 +144,17 @@ func StopJoiner() {
|
||||
logMsg("dc-joiner: stopped")
|
||||
}
|
||||
|
||||
func listenWithRetry(port int, maxAttempts int) (net.Listener, int, error) {
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", port+i)
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
if err == nil {
|
||||
return ln, port + i, nil
|
||||
}
|
||||
}
|
||||
return nil, 0, fmt.Errorf("no free port found starting from %d", port)
|
||||
}
|
||||
|
||||
func StartJoiner(wsPort, socksPort int, cb LogCallback) error {
|
||||
StopJoiner()
|
||||
logCb = cb
|
||||
@@ -149,30 +165,34 @@ func StartJoiner(wsPort, socksPort int, cb LogCallback) error {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/ws", j.handleWS)
|
||||
|
||||
wsAddr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
||||
wsSrv := &http.Server{Addr: wsAddr, Handler: mux}
|
||||
wsLn, actualWsPort, err := listenWithRetry(wsPort, 10)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dc-joiner: %w", err)
|
||||
}
|
||||
wsSrv := &http.Server{Handler: mux}
|
||||
go func() {
|
||||
logMsg("dc-joiner: WebSocket on %s", wsAddr)
|
||||
if err := wsSrv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
logMsg("dc-joiner: WebSocket on 127.0.0.1:%d", actualWsPort)
|
||||
if err := wsSrv.Serve(wsLn); err != nil && err != http.ErrServerClosed {
|
||||
logMsg("dc-joiner: ws server error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
socksAddr := fmt.Sprintf("127.0.0.1:%d", socksPort)
|
||||
ln, err := net.Listen("tcp", socksAddr)
|
||||
socksLn, actualSocksPort, err := listenWithRetry(socksPort, 10)
|
||||
if err != nil {
|
||||
wsSrv.Close()
|
||||
return err
|
||||
return fmt.Errorf("dc-joiner: %w", err)
|
||||
}
|
||||
logMsg("dc-joiner: SOCKS5 on %s", socksAddr)
|
||||
logMsg("dc-joiner: SOCKS5 on 127.0.0.1:%d", actualSocksPort)
|
||||
|
||||
activeJoiner.Lock()
|
||||
activeJoiner.j = j
|
||||
activeJoiner.ws = wsSrv
|
||||
activeJoiner.socksLn = ln
|
||||
activeJoiner.socksLn = socksLn
|
||||
activeJoiner.wsPort = actualWsPort
|
||||
activeJoiner.socksPort = actualSocksPort
|
||||
activeJoiner.Unlock()
|
||||
|
||||
return j.listenSOCKS(ln)
|
||||
return j.listenSOCKS(socksLn)
|
||||
}
|
||||
|
||||
func StartCreator(wsPort int, cb LogCallback) error {
|
||||
@@ -183,9 +203,12 @@ func StartCreator(wsPort int, cb LogCallback) error {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/ws", c.handleWS)
|
||||
|
||||
addr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
||||
logMsg("dc-creator: WebSocket on %s", addr)
|
||||
return http.ListenAndServe(addr, mux)
|
||||
ln, actualPort, err := listenWithRetry(wsPort, 10)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dc-creator: %w", err)
|
||||
}
|
||||
logMsg("dc-creator: WebSocket on 127.0.0.1:%d", actualPort)
|
||||
return http.Serve(ln, mux)
|
||||
}
|
||||
|
||||
type joinerRelay struct {
|
||||
|
||||
+5
-1
@@ -1,6 +1,7 @@
|
||||
package pion
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -164,7 +165,10 @@ func (rb *RelayBridge) handleUDP(connID uint32, payload []byte) {
|
||||
return
|
||||
}
|
||||
addrLen := int(payload[0])
|
||||
if len(payload) < 1+addrLen {
|
||||
if addrLen == 0 || len(payload) < 1+addrLen {
|
||||
return
|
||||
}
|
||||
if bytes.IndexByte(payload[1:1+addrLen], 0) != -1 {
|
||||
return
|
||||
}
|
||||
addr := string(payload[1 : 1+addrLen])
|
||||
|
||||
Reference in new issue
Block a user