fix: capture SSH stderr, switch install to curl, check DONE marker
This commit is contained in:
1 parent
6c7675e25c
commit
c54b594c75
2 files changed
+36
-7
No files matched your search
@@ -8,6 +8,7 @@ import com.jcraft.jsch.Session
|
|||||||
import com.jcraft.jsch.UserInfo
|
import com.jcraft.jsch.UserInfo
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlin.concurrent.thread
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.util.Base64
|
import java.util.Base64
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
@@ -49,12 +50,18 @@ class SSHManager {
|
|||||||
val channel = tempSession.openChannel("exec") as ChannelExec
|
val channel = tempSession.openChannel("exec") as ChannelExec
|
||||||
channel.setCommand(command)
|
channel.setCommand(command)
|
||||||
channel.inputStream = null // не подключать stdin
|
channel.inputStream = null // не подключать stdin
|
||||||
channel.setErrStream(null)
|
|
||||||
|
|
||||||
val inStream = channel.inputStream
|
val inStream = channel.inputStream
|
||||||
|
val errStream = channel.errStream
|
||||||
channel.connect()
|
channel.connect()
|
||||||
|
|
||||||
val output = inStream.bufferedReader().use { reader ->
|
// Читаем stderr в отдельном потоке чтобы не было дедлока
|
||||||
|
val errBuilder = StringBuilder()
|
||||||
|
val errThread = thread {
|
||||||
|
errStream.bufferedReader().forEachLine { errBuilder.appendLine(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val stdout = inStream.bufferedReader().use { reader ->
|
||||||
buildString {
|
buildString {
|
||||||
var line: String?
|
var line: String?
|
||||||
while (reader.readLine().also { line = it } != null) {
|
while (reader.readLine().also { line = it } != null) {
|
||||||
@@ -62,8 +69,17 @@ class SSHManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errThread.join(3_000)
|
||||||
channel.disconnect()
|
channel.disconnect()
|
||||||
output.trim()
|
|
||||||
|
val stderr = errBuilder.toString().trim()
|
||||||
|
buildString {
|
||||||
|
append(stdout.trim())
|
||||||
|
if (stderr.isNotEmpty()) {
|
||||||
|
if (stdout.isNotBlank()) append("\n")
|
||||||
|
append(stderr)
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Если отпечаток изменился — конкретное сообщение об угрозе
|
// Если отпечаток изменился — конкретное сообщение об угрозе
|
||||||
val isMitm = tofu.capturedFingerprint != null
|
val isMitm = tofu.capturedFingerprint != null
|
||||||
|
|||||||
@@ -213,17 +213,30 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
pkill -9 -f "server-linux-" 2>/dev/null;
|
pkill -9 -f "server-linux-" 2>/dev/null;
|
||||||
ARCH=${'$'}(uname -m);
|
ARCH=${'$'}(uname -m);
|
||||||
if [ "${'$'}ARCH" = "x86_64" ]; then BIN="server-linux-amd64"; else BIN="server-linux-arm64"; fi;
|
if [ "${'$'}ARCH" = "x86_64" ]; then BIN="server-linux-amd64"; else BIN="server-linux-arm64"; fi;
|
||||||
wget -qO ${'$'}BIN https://github.com/cacggghp/vk-turn-proxy/releases/latest/download/${'$'}BIN &&
|
URL="https://github.com/cacggghp/vk-turn-proxy/releases/latest/download/${'$'}BIN";
|
||||||
chmod +x ${'$'}BIN && echo "DONE"
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
curl -fsSL -o "${'$'}BIN" "${'$'}URL"
|
||||||
|
elif command -v wget >/dev/null 2>&1; then
|
||||||
|
wget -qO "${'$'}BIN" "${'$'}URL"
|
||||||
|
else
|
||||||
|
echo "ERROR: curl и wget не найдены на сервере"; exit 1
|
||||||
|
fi &&
|
||||||
|
chmod +x "${'$'}BIN" && echo "DONE"
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
sshManager.executeSilentCommand(cfg.ip, cfg.port, cfg.username, cfg.password, script,
|
val result = sshManager.executeSilentCommand(cfg.ip, cfg.port, cfg.username, cfg.password, script,
|
||||||
knownFingerprint = cfg.fp)
|
knownFingerprint = cfg.fp)
|
||||||
delay(1000)
|
if (!result.contains("DONE")) {
|
||||||
|
_serverState.value = ServerState.Error(
|
||||||
|
result.lines().lastOrNull { it.isNotBlank() } ?: "Ошибка установки"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
delay(500)
|
||||||
checkServerState(cfg)
|
checkServerState(cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun startServer() {
|
fun startServer() {
|
||||||
val cfg = sshConfig.value
|
val cfg = sshConfig.value
|
||||||
|
|||||||
Reference in new issue
Block a user