fix: ручной ввод капчи
This commit is contained in:
1 parent
77ce450896
commit
bdf229a849
9 files changed
+192
No files matched your search
@@ -23,6 +23,7 @@
|
|||||||
android:label="FreeTurn"
|
android:label="FreeTurn"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:theme="@style/Theme.FreeTurn"
|
android:theme="@style/Theme.FreeTurn"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.io.InputStreamReader
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
import java.util.regex.Pattern
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -38,6 +39,7 @@ class ProxyService : Service() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MAX_RESTARTS = 8
|
const val MAX_RESTARTS = 8
|
||||||
|
private val CAPTCHA_URL_REGEX = Pattern.compile("""(https?://localhost:\d+/not_robot_captcha\S+)""")
|
||||||
}
|
}
|
||||||
|
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
@@ -130,6 +132,7 @@ class ProxyService : Service() {
|
|||||||
val startedAt = System.currentTimeMillis()
|
val startedAt = System.currentTimeMillis()
|
||||||
var startupEmitted = false
|
var startupEmitted = false
|
||||||
var startupFailed = false
|
var startupFailed = false
|
||||||
|
var captchaActive = false
|
||||||
try {
|
try {
|
||||||
ProxyServiceState.addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
ProxyServiceState.addLog("Команда: ${cmdArgs.joinToString(" ")}")
|
||||||
|
|
||||||
@@ -146,6 +149,20 @@ class ProxyService : Service() {
|
|||||||
val l = line ?: continue
|
val l = line ?: continue
|
||||||
ProxyServiceState.addLog(l)
|
ProxyServiceState.addLog(l)
|
||||||
|
|
||||||
|
// Детекция капчи: ищем URL localhost с not_robot_captcha
|
||||||
|
val captchaMatcher = CAPTCHA_URL_REGEX.matcher(l)
|
||||||
|
if (captchaMatcher.find()) {
|
||||||
|
val url = captchaMatcher.group(1)!!
|
||||||
|
ProxyServiceState.setCaptchaUrl(url)
|
||||||
|
captchaActive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Капча решена — ядро продолжает работу
|
||||||
|
if (captchaActive && l.contains("[Captcha] Manual captcha solved") || l.contains("Captcha Solved Successfully")) {
|
||||||
|
ProxyServiceState.setCaptchaUrl(null)
|
||||||
|
captchaActive = false
|
||||||
|
}
|
||||||
|
|
||||||
if (!startupEmitted) {
|
if (!startupEmitted) {
|
||||||
val lower = l.lowercase()
|
val lower = l.lowercase()
|
||||||
if (lower.contains("panic") || lower.contains("fatal") ||
|
if (lower.contains("panic") || lower.contains("fatal") ||
|
||||||
@@ -193,6 +210,7 @@ class ProxyService : Service() {
|
|||||||
ProxyServiceState.addLog("КРИТИЧЕСКАЯ ОШИБКА: ${e.message}")
|
ProxyServiceState.addLog("КРИТИЧЕСКАЯ ОШИБКА: ${e.message}")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
ProxyServiceState.setCaptchaUrl(null)
|
||||||
process.set(null)
|
process.set(null)
|
||||||
when {
|
when {
|
||||||
userStopped.get() -> {
|
userStopped.get() -> {
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ object ProxyServiceState {
|
|||||||
private val _startupResult = MutableStateFlow<StartupResult?>(null)
|
private val _startupResult = MutableStateFlow<StartupResult?>(null)
|
||||||
val startupResult: StateFlow<StartupResult?> = _startupResult.asStateFlow()
|
val startupResult: StateFlow<StartupResult?> = _startupResult.asStateFlow()
|
||||||
|
|
||||||
|
private val _captchaUrl = MutableStateFlow<String?>(null)
|
||||||
|
val captchaUrl: StateFlow<String?> = _captchaUrl.asStateFlow()
|
||||||
|
|
||||||
fun setRunning(value: Boolean) {
|
fun setRunning(value: Boolean) {
|
||||||
_isRunning.value = value
|
_isRunning.value = value
|
||||||
}
|
}
|
||||||
@@ -47,6 +50,10 @@ object ProxyServiceState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setCaptchaUrl(url: String?) {
|
||||||
|
_captchaUrl.value = url
|
||||||
|
}
|
||||||
|
|
||||||
fun clearLogs() {
|
fun clearLogs() {
|
||||||
_logs.value = emptyList()
|
_logs.value = emptyList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,17 @@ class LocalProxyManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun observeCaptchaEvents() {
|
||||||
|
ProxyServiceState.captchaUrl.collect { url ->
|
||||||
|
if (url != null) {
|
||||||
|
_proxyState.value = ProxyState.CaptchaRequired(url)
|
||||||
|
} else if (_proxyState.value is ProxyState.CaptchaRequired) {
|
||||||
|
// Капча решена — возвращаемся в Running (ядро продолжает работу)
|
||||||
|
_proxyState.value = ProxyState.Running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun observeProxyServiceStatus() {
|
suspend fun observeProxyServiceStatus() {
|
||||||
ProxyServiceState.isRunning.collect { running ->
|
ProxyServiceState.isRunning.collect { running ->
|
||||||
if (running && _proxyState.value !is ProxyState.Running && _proxyState.value !is ProxyState.Starting) {
|
if (running && _proxyState.value !is ProxyState.Running && _proxyState.value !is ProxyState.Starting) {
|
||||||
@@ -99,6 +110,13 @@ class LocalProxyManager(private val context: Context) {
|
|||||||
_proxyState.value = ProxyState.Idle
|
_proxyState.value = ProxyState.Idle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dismissCaptcha() {
|
||||||
|
ProxyServiceState.setCaptchaUrl(null)
|
||||||
|
if (_proxyState.value is ProxyState.CaptchaRequired) {
|
||||||
|
_proxyState.value = ProxyState.Running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setErrorWithAutoReset(message: String) {
|
fun setErrorWithAutoReset(message: String) {
|
||||||
resetJob?.cancel()
|
resetJob?.cancel()
|
||||||
_proxyState.value = ProxyState.Error(message)
|
_proxyState.value = ProxyState.Error(message)
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
@file:OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)
|
||||||
|
|
||||||
|
package com.freeturn.app.ui.screens
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
|
import android.webkit.WebSettings
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.webkit.WebViewClient
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.TopAppBar
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
|
||||||
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
|
@Composable
|
||||||
|
fun CaptchaWebViewDialog(
|
||||||
|
captchaUrl: String,
|
||||||
|
onDismiss: () -> Unit
|
||||||
|
) {
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
|
Dialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
properties = DialogProperties(
|
||||||
|
usePlatformDefaultWidth = false,
|
||||||
|
dismissOnBackPress = true,
|
||||||
|
dismissOnClickOutside = false
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = {
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
"Проверка VK",
|
||||||
|
style = MaterialTheme.typography.titleMedium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"Пройдите проверку для продолжения",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Закрыть")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { padding ->
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(padding)
|
||||||
|
) {
|
||||||
|
AndroidView(
|
||||||
|
factory = { ctx ->
|
||||||
|
WebView(ctx).apply {
|
||||||
|
layoutParams = ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
)
|
||||||
|
|
||||||
|
settings.apply {
|
||||||
|
javaScriptEnabled = true
|
||||||
|
domStorageEnabled = true
|
||||||
|
useWideViewPort = true
|
||||||
|
loadWithOverviewMode = true
|
||||||
|
setSupportZoom(true)
|
||||||
|
builtInZoomControls = true
|
||||||
|
displayZoomControls = false
|
||||||
|
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
||||||
|
userAgentString = "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36"
|
||||||
|
}
|
||||||
|
|
||||||
|
webViewClient = object : WebViewClient() {
|
||||||
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||||
|
super.onPageStarted(view, url, favicon)
|
||||||
|
isLoading = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPageFinished(view: WebView?, url: String?) {
|
||||||
|
super.onPageFinished(view, url)
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadUrl(captchaUrl)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -201,12 +201,14 @@ fun HomeScreen(
|
|||||||
is ProxyState.Running -> stringResource(R.string.proxy_active)
|
is ProxyState.Running -> stringResource(R.string.proxy_active)
|
||||||
is ProxyState.Starting -> stringResource(R.string.proxy_connecting)
|
is ProxyState.Starting -> stringResource(R.string.proxy_connecting)
|
||||||
is ProxyState.Error -> (proxyState as ProxyState.Error).message
|
is ProxyState.Error -> (proxyState as ProxyState.Error).message
|
||||||
|
is ProxyState.CaptchaRequired -> "Требуется прохождение капчи"
|
||||||
else -> stringResource(R.string.proxy_press_to_start)
|
else -> stringResource(R.string.proxy_press_to_start)
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
color = when (proxyState) {
|
color = when (proxyState) {
|
||||||
is ProxyState.Running -> StatusGreen
|
is ProxyState.Running -> StatusGreen
|
||||||
is ProxyState.Error -> MaterialTheme.colorScheme.error
|
is ProxyState.Error -> MaterialTheme.colorScheme.error
|
||||||
|
is ProxyState.CaptchaRequired -> MaterialTheme.colorScheme.error
|
||||||
else -> MaterialTheme.colorScheme.onBackground.copy(alpha = 0.65f)
|
else -> MaterialTheme.colorScheme.onBackground.copy(alpha = 0.65f)
|
||||||
},
|
},
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center
|
||||||
@@ -300,6 +302,13 @@ fun HomeScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateDialogs(viewModel)
|
UpdateDialogs(viewModel)
|
||||||
|
|
||||||
|
if (proxyState is ProxyState.CaptchaRequired) {
|
||||||
|
CaptchaWebViewDialog(
|
||||||
|
captchaUrl = (proxyState as ProxyState.CaptchaRequired).url,
|
||||||
|
onDismiss = { viewModel.dismissCaptcha() }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Диалоги обновления ────────────────────────────────────────────────────
|
// ── Диалоги обновления ────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ sealed class ProxyState {
|
|||||||
object Starting : ProxyState()
|
object Starting : ProxyState()
|
||||||
object Running : ProxyState()
|
object Running : ProxyState()
|
||||||
data class Error(val message: String) : ProxyState()
|
data class Error(val message: String) : ProxyState()
|
||||||
|
data class CaptchaRequired(val url: String) : ProxyState()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── App update states ──────────────────────────────────────────────────────
|
// ── App update states ──────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
proxyManager.observeProxyServiceStatus()
|
proxyManager.observeProxyServiceStatus()
|
||||||
}
|
}
|
||||||
|
viewModelScope.launch {
|
||||||
|
proxyManager.observeCaptchaEvents()
|
||||||
|
}
|
||||||
proxyManager.syncInitialState()
|
proxyManager.syncInitialState()
|
||||||
|
|
||||||
// Автоматическая проверка обновлений при холодном запуске (silent — без ошибок)
|
// Автоматическая проверка обновлений при холодном запуске (silent — без ошибок)
|
||||||
@@ -170,6 +173,10 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
proxyManager.stopProxy()
|
proxyManager.stopProxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dismissCaptcha() {
|
||||||
|
proxyManager.dismissCaptcha()
|
||||||
|
}
|
||||||
|
|
||||||
fun clearLogs() {
|
fun clearLogs() {
|
||||||
ProxyServiceState.clearLogs()
|
ProxyServiceState.clearLogs()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<network-security-config>
|
||||||
|
<domain-config cleartextTrafficPermitted="true">
|
||||||
|
<domain includeSubdomains="false">localhost</domain>
|
||||||
|
<domain includeSubdomains="false">127.0.0.1</domain>
|
||||||
|
</domain-config>
|
||||||
|
</network-security-config>
|
||||||
Reference in new issue
Block a user