feat(server): команды шаринга и авторизация по Client ID
Сабкоманды share-info/share-list/peer-add/peer-conf/peer-remove/client-add/ client-remove в free-turn-control.sh. Allowlist clients.json с флагом -clients-file (hot-reload). Сборка команды и парсинг вывода ушли на IO.
This commit is contained in:
1 parent
3ba285dbff
commit
a49c59103f
3 files changed
+525
-16
No files matched your search
@@ -23,6 +23,39 @@ sealed class ServerCommand {
|
||||
data object Stop : ServerCommand()
|
||||
data class FetchLogs(val lines: Int = 80) : ServerCommand()
|
||||
|
||||
/** Фактические параметры запущенного сервера (run.args) — для share-ссылки. */
|
||||
data object ShareInfo : ServerCommand()
|
||||
|
||||
/**
|
||||
* Новый именованный WG-пир для выдачи доступа. [nameB64] — base64(UTF-8 имени):
|
||||
* юникод/кавычки не доходят до shell. [endpoint] — локальный прокси устройства
|
||||
* получателя (рантайм подменит при подъёме туннеля). [clientId] — свежий cid
|
||||
* гостя: скрипт сажает его в allowlist (comment = имя) и хранит маппинг к пиру.
|
||||
*/
|
||||
data class PeerAdd(
|
||||
val nameB64: String,
|
||||
val endpoint: String,
|
||||
val clientId: String
|
||||
) : ServerCommand()
|
||||
|
||||
/** WG-пиры + allowlist-гости одним вызовом (одна SSH-сессия на вкладку). */
|
||||
data object ShareList : ServerCommand()
|
||||
|
||||
/**
|
||||
* Сохранённый клиентский conf пира — повторная выдача ссылки. [clientId] —
|
||||
* кандидат для backfill: пир без cid-маппинга (выдан до allowlist) получит его.
|
||||
*/
|
||||
data class PeerConf(
|
||||
val pubkey: String,
|
||||
val clientId: String,
|
||||
val nameB64: String
|
||||
) : ServerCommand()
|
||||
data class PeerRemove(val pubkey: String) : ServerCommand()
|
||||
|
||||
/** Гость без WG-пира (tcp/Xray-бэкенд): только Client ID в allowlist. */
|
||||
data class ClientAdd(val nameB64: String, val clientId: String) : ServerCommand()
|
||||
data class ClientRemove(val clientId: String) : ServerCommand()
|
||||
|
||||
fun toArgv(): List<String> = when (this) {
|
||||
is Probe -> listOf("probe")
|
||||
is Install -> listOf("install")
|
||||
@@ -44,9 +77,28 @@ sealed class ServerCommand {
|
||||
add("--obf-profile=${opts.obfProfile}")
|
||||
add("--obf-key=${opts.obfKey}")
|
||||
}
|
||||
// cid владельца: скрипт сидит его в allowlist и включает -clients-file.
|
||||
if (opts.clientId.isNotBlank()) add("--client-id=${opts.clientId}")
|
||||
}
|
||||
is Stop -> listOf("stop")
|
||||
is FetchLogs -> listOf("logs", "--tail=$lines")
|
||||
is ShareInfo -> listOf("share-info")
|
||||
is PeerAdd -> buildList {
|
||||
add("peer-add")
|
||||
add("--name-b64=$nameB64")
|
||||
add("--endpoint=$endpoint")
|
||||
if (clientId.isNotBlank()) add("--client-id=$clientId")
|
||||
}
|
||||
is ShareList -> listOf("share-list")
|
||||
is PeerConf -> buildList {
|
||||
add("peer-conf")
|
||||
add("--pubkey=$pubkey")
|
||||
if (clientId.isNotBlank()) add("--client-id=$clientId")
|
||||
if (nameB64.isNotBlank()) add("--name-b64=$nameB64")
|
||||
}
|
||||
is PeerRemove -> listOf("peer-remove", "--pubkey=$pubkey")
|
||||
is ClientAdd -> listOf("client-add", "--name-b64=$nameB64", "--client-id=$clientId")
|
||||
is ClientRemove -> listOf("client-remove", "--client-id=$clientId")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,5 +110,10 @@ data class ServerOptions(
|
||||
/** Wire-профиль обфускации: none | rtpopus. */
|
||||
val obfProfile: String = "none",
|
||||
/** 64-hex obf-ключ. Пустая строка → запуск без обфускации. */
|
||||
val obfKey: String = ""
|
||||
val obfKey: String = "",
|
||||
/**
|
||||
* Client ID владельца (32 hex). Непустой → скрипт сажает его в clients.json
|
||||
* и запускает сервер с -clients-file (авторизация по allowlist).
|
||||
*/
|
||||
val clientId: String = ""
|
||||
)
|
||||
@@ -3,6 +3,8 @@ package com.freeturn.app.domain.server
|
||||
import android.content.Context
|
||||
import com.freeturn.app.SSHManager
|
||||
import com.freeturn.app.data.SshConfig
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* Запускает [ServerCommand] на удалённом хосте, стримя `free-turn-control.sh`
|
||||
@@ -27,8 +29,10 @@ class ServerControl(
|
||||
return "bash -s -- $quoted"
|
||||
}
|
||||
|
||||
suspend fun run(cfg: SshConfig, cmd: ServerCommand): CmdResult {
|
||||
if (cfg.ip.isBlank()) return CmdResult.Err("no SSH config", emptyList())
|
||||
suspend fun run(cfg: SshConfig, cmd: ServerCommand): CmdResult = withContext(Dispatchers.IO) {
|
||||
if (cfg.ip.isBlank()) return@withContext CmdResult.Err("no SSH config", emptyList())
|
||||
// Сборка команды + ленивое чтение 52KB-скрипта (assets) и парсинг вывода —
|
||||
// всё на IO: первый SSH-вызов не блокирует главный поток (фриз при открытии).
|
||||
val output = ssh.executeWithStdin(
|
||||
ip = cfg.ip,
|
||||
port = cfg.port,
|
||||
@@ -39,7 +43,7 @@ class ServerControl(
|
||||
knownFingerprint = cfg.hostFingerprint.ifEmpty { null },
|
||||
sshKey = if (cfg.authType == SshConfig.AUTH_SSH_KEY) cfg.sshKey else ""
|
||||
)
|
||||
return ServerOutputParser.parse(output)
|
||||
ServerOutputParser.parse(output)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user