feat: sync-toggle, журнал сервера, systemd runtime
- ClientConfig.syncServerSwitches: разделить клиентские флаги VLESS/bond/WRAP от серверного процесса. При выкл сервер не рестартится при тогле. - ServerManagementScreen: журнал через journalctl/server.log, refresh + clear, баннер sync-off с AnimatedVisibility. - vk-turn-control.sh: dual runtime systemd/nohup, авто-генерация unit + launcher, миграция legacy nohup при takeover, journalctl для логов. - MD3: cardElevation 4dp -> 1dp в SshSetupScreen, magic 14dp -> shapes.medium в EasterEgg.
This commit is contained in:
1 parent
46e72217a6
commit
4615edee66
12 files changed
+502
-90
No files matched your search
@@ -47,7 +47,13 @@ data class ClientConfig(
|
||||
// Если true — добавляется флаг -debug для расширенного вывода в логах.
|
||||
val debugMode: Boolean = false,
|
||||
// Если true — в argv передаётся -dns-servers с DNS активной сети (оператор связи).
|
||||
val useCarrierDns: Boolean = false
|
||||
val useCarrierDns: Boolean = false,
|
||||
/**
|
||||
* Если true — изменения vlessMode/vlessBond/wrapEnabled на клиенте дёргают
|
||||
* рестарт сервера (текущее поведение). Если false — флаги меняются только
|
||||
* у клиента, серверный процесс не трогается.
|
||||
*/
|
||||
val syncServerSwitches: Boolean = true
|
||||
)
|
||||
|
||||
class AppPreferences(context: Context) {
|
||||
@@ -75,6 +81,7 @@ class AppPreferences(context: Context) {
|
||||
val CLIENT_CAPTCHA_SOLVER = stringPreferencesKey("client_captcha_solver")
|
||||
val CLIENT_DEBUG = booleanPreferencesKey("client_debug")
|
||||
val CLIENT_USE_CARRIER_DNS = booleanPreferencesKey("client_use_carrier_dns")
|
||||
val CLIENT_SYNC_SERVER = booleanPreferencesKey("client_sync_server")
|
||||
// Устаревшие ключи — не пишутся, но молча удаляются при saveClientConfig.
|
||||
private val CLIENT_DNS_MODE_LEGACY = stringPreferencesKey("client_dns_mode")
|
||||
private val CLIENT_ALLOCS_PER_STREAM_LEGACY = intPreferencesKey("client_allocs_per_stream")
|
||||
@@ -154,7 +161,8 @@ class AppPreferences(context: Context) {
|
||||
if (it == "v1" || it == "v2") it else "v2"
|
||||
},
|
||||
debugMode = prefs[CLIENT_DEBUG] ?: false,
|
||||
useCarrierDns = prefs[CLIENT_USE_CARRIER_DNS] ?: false
|
||||
useCarrierDns = prefs[CLIENT_USE_CARRIER_DNS] ?: false,
|
||||
syncServerSwitches = prefs[CLIENT_SYNC_SERVER] ?: true
|
||||
)
|
||||
}
|
||||
|
||||
@@ -270,6 +278,7 @@ class AppPreferences(context: Context) {
|
||||
prefs[CLIENT_CAPTCHA_SOLVER] = config.captchaSolver
|
||||
prefs[CLIENT_DEBUG] = config.debugMode
|
||||
prefs[CLIENT_USE_CARRIER_DNS] = config.useCarrierDns
|
||||
prefs[CLIENT_SYNC_SERVER] = config.syncServerSwitches
|
||||
// Удаляем устаревшие ключи, которые больше не использует ядро.
|
||||
prefs.remove(CLIENT_FORCE_PORT_443_LEGACY)
|
||||
prefs.remove(CLIENT_TURN_PORT_443_LEGACY)
|
||||
|
||||
@@ -70,6 +70,7 @@ internal object ProfileJson {
|
||||
put("captchaSolver", p.client.captchaSolver)
|
||||
put("debugMode", p.client.debugMode)
|
||||
put("useCarrierDns", p.client.useCarrierDns)
|
||||
put("syncServerSwitches", p.client.syncServerSwitches)
|
||||
})
|
||||
put("proxyListen", p.proxyListen)
|
||||
put("proxyConnect", p.proxyConnect)
|
||||
@@ -105,7 +106,8 @@ internal object ProfileJson {
|
||||
if (it == "v1" || it == "v2") it else "v2"
|
||||
},
|
||||
debugMode = cliO.optBoolean("debugMode", false),
|
||||
useCarrierDns = cliO.optBoolean("useCarrierDns", false)
|
||||
useCarrierDns = cliO.optBoolean("useCarrierDns", false),
|
||||
syncServerSwitches = cliO.optBoolean("syncServerSwitches", true)
|
||||
),
|
||||
proxyListen = o.optString("proxyListen").ifBlank { "0.0.0.0:56000" },
|
||||
proxyConnect = o.optString("proxyConnect").ifBlank { "127.0.0.1:40537" }
|
||||
|
||||
@@ -215,11 +215,15 @@ class SshRepository(
|
||||
checkServerState(cfg)
|
||||
}
|
||||
|
||||
suspend fun fetchServerLogs() {
|
||||
fun clearServerLogs() {
|
||||
_serverLogs.value = null
|
||||
}
|
||||
|
||||
suspend fun fetchServerLogs(lines: Int = 200) {
|
||||
val cfg = activeSshConfig ?: return
|
||||
if (cfg.ip.isEmpty()) return
|
||||
_serverLogs.value = "…"
|
||||
when (val r = runCmd(cfg, "server.log", ServerCommand.FetchLogs())) {
|
||||
when (val r = runCmd(cfg, "server.log", ServerCommand.FetchLogs(lines))) {
|
||||
is CmdResult.Err -> _serverLogs.value = "ERROR: ${r.message}"
|
||||
is CmdResult.Ok ->
|
||||
_serverLogs.value = r.logs.joinToString("\n").ifEmpty { "(лог пуст)" }
|
||||
|
||||
@@ -80,11 +80,13 @@ fun ClientSetupScreen(
|
||||
|
||||
val isSshConnected = sshState is SshConnectionState.Connected
|
||||
val serverKnown = serverState as? com.freeturn.app.viewmodel.ServerState.Known
|
||||
// Эффективное значение sync-флага: если сервер запущен — реальное состояние
|
||||
// из probe; иначе — последнее сохранённое (frozen).
|
||||
val effectiveVlessMode = serverKnown?.vlessMode ?: saved.vlessMode
|
||||
val effectiveVlessBond = serverKnown?.vlessBond ?: serverOpts.vlessBond
|
||||
val effectiveWrap = serverKnown?.wrap ?: serverOpts.wrapEnabled
|
||||
// В sync-режиме эффективное значение — реальное состояние сервера из probe
|
||||
// (если запущен), иначе сохранённое. В !sync режиме — всегда сохранённое:
|
||||
// серверная и клиентская стороны могут различаться, и UI отражает клиента.
|
||||
val syncOn = saved.syncServerSwitches
|
||||
val effectiveVlessMode = if (syncOn) serverKnown?.vlessMode ?: saved.vlessMode else saved.vlessMode
|
||||
val effectiveVlessBond = if (syncOn) serverKnown?.vlessBond ?: serverOpts.vlessBond else serverOpts.vlessBond
|
||||
val effectiveWrap = if (syncOn) serverKnown?.wrap ?: serverOpts.wrapEnabled else serverOpts.wrapEnabled
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -125,7 +127,8 @@ fun ClientSetupScreen(
|
||||
vlessMode = saved.vlessMode,
|
||||
captchaSolver = captchaSolver,
|
||||
debugMode = debugMode,
|
||||
useCarrierDns = useCarrierDns
|
||||
useCarrierDns = useCarrierDns,
|
||||
syncServerSwitches = saved.syncServerSwitches
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -342,16 +345,28 @@ fun ClientSetupScreen(
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
|
||||
// VLESS-режим — sync с сервером (-vless на обеих сторонах).
|
||||
// Без SSH-подключения замораживается на последнем известном значении.
|
||||
SwitchRow(
|
||||
label = stringResource(R.string.sync_server_switches),
|
||||
description = stringResource(R.string.sync_server_switches_desc),
|
||||
checked = syncOn,
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
viewModel.setSyncServerSwitches(it)
|
||||
}
|
||||
)
|
||||
|
||||
// В sync-режиме менять эти флаги без SSH опасно (рассинхрон).
|
||||
// В !sync — клиентские, SSH не нужен.
|
||||
val controlsEnabled = if (syncOn) isSshConnected else true
|
||||
val lockedHint = if (syncOn)
|
||||
stringResource(R.string.locked_disconnect_hint) else null
|
||||
|
||||
SwitchRow(
|
||||
label = stringResource(R.string.vless_mode),
|
||||
description = if (isSshConnected)
|
||||
stringResource(R.string.vless_mode_desc)
|
||||
else
|
||||
stringResource(R.string.locked_disconnect_hint),
|
||||
description = lockedHint?.takeIf { !isSshConnected }
|
||||
?: stringResource(R.string.vless_mode_desc),
|
||||
checked = effectiveVlessMode,
|
||||
enabled = isSshConnected,
|
||||
enabled = controlsEnabled,
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
viewModel.setVlessMode(it)
|
||||
@@ -360,12 +375,10 @@ fun ClientSetupScreen(
|
||||
|
||||
SwitchRow(
|
||||
label = stringResource(R.string.client_vless_bond),
|
||||
description = if (isSshConnected)
|
||||
stringResource(R.string.client_vless_bond_desc)
|
||||
else
|
||||
stringResource(R.string.locked_disconnect_hint),
|
||||
description = lockedHint?.takeIf { !isSshConnected }
|
||||
?: stringResource(R.string.client_vless_bond_desc),
|
||||
checked = effectiveVlessBond,
|
||||
enabled = isSshConnected && effectiveVlessMode,
|
||||
enabled = controlsEnabled && effectiveVlessMode,
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
viewModel.setServerVlessBond(it)
|
||||
@@ -374,12 +387,10 @@ fun ClientSetupScreen(
|
||||
|
||||
SwitchRow(
|
||||
label = stringResource(R.string.client_wrap_enabled),
|
||||
description = if (isSshConnected)
|
||||
stringResource(R.string.client_wrap_desc)
|
||||
else
|
||||
stringResource(R.string.locked_disconnect_hint),
|
||||
description = lockedHint?.takeIf { !isSshConnected }
|
||||
?: stringResource(R.string.client_wrap_desc),
|
||||
checked = effectiveWrap,
|
||||
enabled = isSshConnected,
|
||||
enabled = controlsEnabled,
|
||||
onCheckedChange = {
|
||||
HapticUtil.perform(context, if (it) HapticUtil.Pattern.TOGGLE_ON else HapticUtil.Pattern.TOGGLE_OFF)
|
||||
viewModel.setServerWrapEnabled(it)
|
||||
|
||||
@@ -605,8 +605,8 @@ private fun InfoBottomSheet(
|
||||
item {
|
||||
RepoLinkItem(
|
||||
title = stringResource(R.string.proxy_core),
|
||||
subtitle = "cacggghp/vk-turn-proxy",
|
||||
url = "https://github.com/cacggghp/vk-turn-proxy",
|
||||
subtitle = "moroka8/vk-turn-proxy",
|
||||
url = "https://github.com/moroka8/vk-turn-proxy",
|
||||
containerColor = containerColor,
|
||||
onHaptic = { HapticUtil.perform(context, HapticUtil.Pattern.SELECTION) },
|
||||
onOpen = { uriHandler.openUri(it) }
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
package com.freeturn.app.ui.screens
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -79,6 +84,8 @@ fun ServerManagementScreen(
|
||||
val sshLog by viewModel.sshLog.collectAsStateWithLifecycle()
|
||||
val privacyMode by viewModel.privacyMode.collectAsStateWithLifecycle()
|
||||
val installStage by viewModel.serverInstallStage.collectAsStateWithLifecycle()
|
||||
val clientCfg by viewModel.clientConfig.collectAsStateWithLifecycle()
|
||||
val serverLogs by viewModel.serverLogs.collectAsStateWithLifecycle()
|
||||
|
||||
var proxyListenPort by rememberSaveable(savedListen) { mutableStateOf(savedListen.substringAfterLast(":", "56000")) }
|
||||
var proxyConnect by rememberSaveable(savedConnect) { mutableStateOf(savedConnect) }
|
||||
@@ -126,6 +133,26 @@ fun ServerManagementScreen(
|
||||
) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = !clientCfg.syncServerSwitches,
|
||||
enter = fadeIn() + expandVertically(),
|
||||
exit = fadeOut() + shrinkVertically()
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.errorContainer
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.sync_off_banner),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||
modifier = Modifier.padding(16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Status card
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.padding(20.dp)) {
|
||||
@@ -291,6 +318,77 @@ fun ServerManagementScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Журнал сервера (journalctl/server.log через SSH).
|
||||
// Скрываем без SSH-подключения — симметрично с SSH-логом ниже.
|
||||
if (isConnected) {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.padding(20.dp)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.server_journal_title),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
androidx.compose.material3.IconButton(
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.fetchServerLogs()
|
||||
},
|
||||
enabled = isConnected && serverLogs != "…"
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.refresh_24px),
|
||||
contentDescription = stringResource(R.string.server_journal_refresh)
|
||||
)
|
||||
}
|
||||
if (serverLogs != null) {
|
||||
androidx.compose.material3.IconButton(
|
||||
onClick = {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.CLICK)
|
||||
viewModel.clearServerLogs()
|
||||
},
|
||||
enabled = serverLogs != "…"
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.delete_24px),
|
||||
contentDescription = stringResource(R.string.server_journal_clear)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (serverLogs != null) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||
)
|
||||
) {
|
||||
val text = when (serverLogs) {
|
||||
"…" -> stringResource(R.string.server_journal_loading)
|
||||
"(лог пуст)" -> stringResource(R.string.server_journal_empty)
|
||||
else -> serverLogs ?: ""
|
||||
}
|
||||
Text(
|
||||
text = text,
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontFamily = FontFamily.Monospace
|
||||
),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 400.dp)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(10.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SSH-лог (вывод всех команд)
|
||||
if (sshLog.isNotEmpty()) {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
|
||||
@@ -307,7 +307,7 @@ private fun ConnectionProgressCard(step: String) {
|
||||
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
elevation = CardDefaults.cardElevation(4.dp)
|
||||
elevation = CardDefaults.cardElevation(1.dp)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(24.dp),
|
||||
|
||||
@@ -431,9 +431,9 @@ private fun EasterEggScreen() {
|
||||
tooltip?.let { (m, _) ->
|
||||
Surface(
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh.copy(alpha = 0.94f),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
modifier = Modifier.padding(32.dp),
|
||||
tonalElevation = 4.dp,
|
||||
tonalElevation = 3.dp,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(
|
||||
|
||||
@@ -36,6 +36,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val sshState: StateFlow<SshConnectionState> = sshRepository.sshState
|
||||
val serverState: StateFlow<ServerState> = sshRepository.serverState
|
||||
val sshLog: StateFlow<List<String>> = sshRepository.sshLog
|
||||
val serverLogs: StateFlow<String?> = sshRepository.serverLogs
|
||||
|
||||
val proxyState: StateFlow<ProxyState> = proxyManager.proxyState
|
||||
val connectedSince: StateFlow<Long?> = ProxyServiceState.connectedSince
|
||||
@@ -342,7 +343,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val current = prefs.serverOptsFlow.first()
|
||||
if (current.vlessBond == enabled) return@launch
|
||||
prefs.saveServerOpts(current.copy(vlessBond = enabled))
|
||||
restartServerIfRunning()
|
||||
if (clientConfig.value.syncServerSwitches) restartServerIfRunning()
|
||||
restartProxyIfRunning()
|
||||
}
|
||||
}
|
||||
@@ -351,18 +352,38 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
viewModelScope.launch {
|
||||
val current = prefs.serverOptsFlow.first()
|
||||
if (current.wrapEnabled == enabled) return@launch
|
||||
// При первом включении wrap, если ключа ещё нет — пробуем взять с сервера.
|
||||
val sync = clientConfig.value.syncServerSwitches
|
||||
var next = current.copy(wrapEnabled = enabled)
|
||||
if (enabled && next.wrapKey.isBlank()) {
|
||||
// При первом включении wrap, если ключа ещё нет и sync включён —
|
||||
// пробуем взять с сервера. В !sync режиме сервер не трогаем.
|
||||
if (enabled && next.wrapKey.isBlank() && sync) {
|
||||
val key = sshRepository.generateWrapKey()
|
||||
if (!key.isNullOrBlank()) next = next.copy(wrapKey = key)
|
||||
}
|
||||
prefs.saveServerOpts(next)
|
||||
restartServerIfRunning()
|
||||
if (sync) restartServerIfRunning()
|
||||
restartProxyIfRunning()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Глобальный sync-флаг. При включении (false→true) выравниваем сервер с
|
||||
* клиентскими свитчами разовым рестартом, иначе разъехавшиеся ключ/флаги
|
||||
* провалят DTLS handshake.
|
||||
*/
|
||||
fun setSyncServerSwitches(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
val current = prefs.clientConfigFlow.first()
|
||||
if (current.syncServerSwitches == enabled) return@launch
|
||||
prefs.saveClientConfig(current.copy(syncServerSwitches = enabled))
|
||||
mirrorActiveProfile()
|
||||
if (enabled) {
|
||||
restartServerIfRunning()
|
||||
restartProxyIfRunning()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun regenerateWrapKey() {
|
||||
viewModelScope.launch {
|
||||
if (_isRegeneratingWrapKey.value) return@launch
|
||||
@@ -371,7 +392,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val key = sshRepository.generateWrapKey() ?: return@launch
|
||||
val current = prefs.serverOptsFlow.first()
|
||||
prefs.saveServerOpts(current.copy(wrapKey = key))
|
||||
restartServerIfRunning()
|
||||
if (clientConfig.value.syncServerSwitches) restartServerIfRunning()
|
||||
restartProxyIfRunning()
|
||||
} finally {
|
||||
_isRegeneratingWrapKey.value = false
|
||||
@@ -417,17 +438,27 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
viewModelScope.launch { sshRepository.stopServer() }
|
||||
}
|
||||
|
||||
/** Переключает VLESS-режим. Если SSH подключён и сервер запущен — автоперезапуск. */
|
||||
fun fetchServerLogs(lines: Int = 200) {
|
||||
viewModelScope.launch { sshRepository.fetchServerLogs(lines) }
|
||||
}
|
||||
|
||||
fun clearServerLogs() {
|
||||
sshRepository.clearServerLogs()
|
||||
}
|
||||
|
||||
/** Переключает VLESS-режим. Если sync ON и сервер запущен — автоперезапуск. */
|
||||
fun setVlessMode(enabled: Boolean) {
|
||||
val current = clientConfig.value
|
||||
if (current.vlessMode == enabled) return
|
||||
viewModelScope.launch {
|
||||
prefs.saveClientConfig(current.copy(vlessMode = enabled))
|
||||
mirrorActiveProfile()
|
||||
val serverRunning = (serverState.value as? ServerState.Known)?.running == true
|
||||
if (serverRunning) {
|
||||
sshRepository.stopServer()
|
||||
startServer()
|
||||
if (current.syncServerSwitches) {
|
||||
val serverRunning = (serverState.value as? ServerState.Known)?.running == true
|
||||
if (serverRunning) {
|
||||
sshRepository.stopServer()
|
||||
startServer()
|
||||
}
|
||||
}
|
||||
restartProxyIfRunning()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user