New Branch: Full project rewrite (Beta)
This commit is contained in:
commit
188bc459b1
25 changed files with 1496 additions and 0 deletions
33
app/src/main/AndroidManifest.xml
Normal file
33
app/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- Разрешение на интернет -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- Разрешение на сеть для проверки состояния -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="Vedroid SSH Client"
|
||||
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||
|
||||
<!-- Главный экран -->
|
||||
<activity
|
||||
android:name=".SshActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Терминал - ДОБАВЛЯЕМ ЭТУ АКТИВНОСТЬ -->
|
||||
<activity
|
||||
android:name=".TerminalActivity"
|
||||
android:exported="false"
|
||||
android:screenOrientation="landscape" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
11
app/src/main/java/com/example/vedroid/MainActivity.kt
Normal file
11
app/src/main/java/com/example/vedroid/MainActivity.kt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package com.example.vedroid
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
}
|
||||
}
|
||||
333
app/src/main/java/com/example/vedroid/SshActivity.kt
Normal file
333
app/src/main/java/com/example/vedroid/SshActivity.kt
Normal file
|
|
@ -0,0 +1,333 @@
|
|||
package com.example.vedroid
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.content.Intent // ✅ Добавляем этот импорт
|
||||
import android.os.Bundle
|
||||
import android.widget.*
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import com.jcraft.jsch.ChannelExec
|
||||
import com.jcraft.jsch.JSch
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import com.example.vedroid.model.SshProfile
|
||||
|
||||
class SshActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var hostInput: EditText
|
||||
private lateinit var portInput: EditText
|
||||
private lateinit var usernameInput: EditText
|
||||
private lateinit var passwordInput: EditText
|
||||
private lateinit var connectButton: Button
|
||||
private lateinit var executeButton: Button
|
||||
private lateinit var outputText: TextView
|
||||
private lateinit var profilesSpinner: Spinner
|
||||
private lateinit var saveProfileButton: Button
|
||||
private lateinit var deleteProfileButton: Button
|
||||
private lateinit var terminalButton: Button // ✅ Добавляем terminalButton
|
||||
|
||||
private val jsch = JSch()
|
||||
private lateinit var prefs: SharedPreferences
|
||||
private val profiles = mutableListOf<SshProfile>()
|
||||
private lateinit var adapter: ArrayAdapter<String>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_ssh)
|
||||
|
||||
prefs = getSharedPreferences("ssh_profiles", MODE_PRIVATE)
|
||||
initViews()
|
||||
loadProfiles()
|
||||
setupClickListeners()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
hostInput = findViewById(R.id.hostInput)
|
||||
portInput = findViewById(R.id.portInput)
|
||||
usernameInput = findViewById(R.id.usernameInput)
|
||||
passwordInput = findViewById(R.id.passwordInput)
|
||||
connectButton = findViewById(R.id.connectButton)
|
||||
executeButton = findViewById(R.id.executeButton)
|
||||
outputText = findViewById(R.id.outputText)
|
||||
profilesSpinner = findViewById(R.id.profilesSpinner)
|
||||
saveProfileButton = findViewById(R.id.saveProfileButton)
|
||||
deleteProfileButton = findViewById(R.id.deleteProfileButton)
|
||||
terminalButton = findViewById(R.id.terminalButton) // ✅ Инициализируем terminalButton
|
||||
|
||||
executeButton.isEnabled = false
|
||||
|
||||
// Настройка спиннера профилей
|
||||
adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, mutableListOf<String>())
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
profilesSpinner.adapter = adapter
|
||||
}
|
||||
|
||||
private fun openTerminal(profile: SshProfile) {
|
||||
val intent = Intent(this, TerminalActivity::class.java).apply {
|
||||
// Передаем отдельные поля вместо всего объекта
|
||||
putExtra("profile_name", profile.name)
|
||||
putExtra("host", profile.host)
|
||||
putExtra("port", profile.port)
|
||||
putExtra("username", profile.username)
|
||||
putExtra("password", profile.password)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun setupClickListeners() {
|
||||
connectButton.setOnClickListener {
|
||||
connectSsh()
|
||||
}
|
||||
|
||||
executeButton.setOnClickListener {
|
||||
executeCommand("ls -la")
|
||||
}
|
||||
|
||||
saveProfileButton.setOnClickListener {
|
||||
showSaveProfileDialog()
|
||||
}
|
||||
|
||||
deleteProfileButton.setOnClickListener {
|
||||
deleteCurrentProfile()
|
||||
}
|
||||
|
||||
terminalButton.setOnClickListener { // ✅ Добавляем обработчик для terminalButton
|
||||
val position = profilesSpinner.selectedItemPosition
|
||||
if (position > 0) {
|
||||
val profile = profiles[position - 1]
|
||||
openTerminal(profile)
|
||||
} else {
|
||||
// Создаем временный профиль из текущих данных
|
||||
val tempProfile = SshProfile(
|
||||
name = "Temp Terminal",
|
||||
host = hostInput.text.toString(),
|
||||
port = portInput.text.toString().toIntOrNull() ?: 22,
|
||||
username = usernameInput.text.toString(),
|
||||
password = passwordInput.text.toString()
|
||||
)
|
||||
openTerminal(tempProfile)
|
||||
}
|
||||
}
|
||||
|
||||
profilesSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: android.view.View?, position: Int, id: Long) {
|
||||
if (position > 0) { // position 0 is "New Profile"
|
||||
loadProfile(profiles[position - 1])
|
||||
}
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadProfiles() {
|
||||
val profilesJson = prefs.getString("profiles", "[]") ?: "[]"
|
||||
val jsonArray = JSONArray(profilesJson)
|
||||
|
||||
profiles.clear()
|
||||
val profileNames = mutableListOf("New Profile")
|
||||
|
||||
for (i in 0 until jsonArray.length()) {
|
||||
val json = jsonArray.getJSONObject(i)
|
||||
val profile = SshProfile(
|
||||
name = json.getString("name"),
|
||||
host = json.getString("host"),
|
||||
port = json.getInt("port"),
|
||||
username = json.getString("username"),
|
||||
password = json.getString("password")
|
||||
)
|
||||
profiles.add(profile)
|
||||
profileNames.add(profile.name)
|
||||
}
|
||||
|
||||
adapter.clear()
|
||||
adapter.addAll(profileNames)
|
||||
}
|
||||
|
||||
private fun saveProfiles() {
|
||||
val jsonArray = JSONArray()
|
||||
profiles.forEach { profile ->
|
||||
val json = JSONObject().apply {
|
||||
put("name", profile.name)
|
||||
put("host", profile.host)
|
||||
put("port", profile.port)
|
||||
put("username", profile.username)
|
||||
put("password", profile.password)
|
||||
}
|
||||
jsonArray.put(json)
|
||||
}
|
||||
|
||||
prefs.edit().putString("profiles", jsonArray.toString()).apply()
|
||||
loadProfiles() // Reload to update spinner
|
||||
}
|
||||
|
||||
private fun showSaveProfileDialog() {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_save_profile, null)
|
||||
val nameInput = dialogView.findViewById<EditText>(R.id.profileNameInput)
|
||||
|
||||
// Pre-fill with current connection details
|
||||
nameInput.setText("${usernameInput.text}@${hostInput.text}")
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Save Profile")
|
||||
.setView(dialogView)
|
||||
.setPositiveButton("Save") { _, _ ->
|
||||
val profileName = nameInput.text.toString()
|
||||
if (profileName.isNotEmpty()) {
|
||||
saveProfile(profileName)
|
||||
}
|
||||
}
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun saveProfile(name: String) {
|
||||
val profile = SshProfile(
|
||||
name = name,
|
||||
host = hostInput.text.toString(),
|
||||
port = portInput.text.toString().toIntOrNull() ?: 22,
|
||||
username = usernameInput.text.toString(),
|
||||
password = passwordInput.text.toString()
|
||||
)
|
||||
|
||||
profiles.removeAll { it.name == name } // Remove existing with same name
|
||||
profiles.add(profile)
|
||||
saveProfiles()
|
||||
|
||||
// Select the newly saved profile
|
||||
profilesSpinner.setSelection(adapter.getPosition(name))
|
||||
|
||||
appendOutput("✅ Profile '$name' saved")
|
||||
}
|
||||
|
||||
private fun deleteCurrentProfile() {
|
||||
val position = profilesSpinner.selectedItemPosition
|
||||
if (position > 0) {
|
||||
val profile = profiles[position - 1]
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("Delete Profile")
|
||||
.setMessage("Delete profile '${profile.name}'?")
|
||||
.setPositiveButton("Delete") { _, _ ->
|
||||
profiles.removeAt(position - 1)
|
||||
saveProfiles()
|
||||
profilesSpinner.setSelection(0) // Select "New Profile"
|
||||
appendOutput("🗑️ Profile '${profile.name}' deleted")
|
||||
}
|
||||
.setNegativeButton("Cancel", null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadProfile(profile: SshProfile) {
|
||||
hostInput.setText(profile.host)
|
||||
portInput.setText(profile.port.toString())
|
||||
usernameInput.setText(profile.username)
|
||||
passwordInput.setText(profile.password)
|
||||
|
||||
appendOutput("📁 Loaded profile: ${profile.name}")
|
||||
}
|
||||
|
||||
private fun connectSsh() {
|
||||
val host = hostInput.text.toString()
|
||||
val port = portInput.text.toString().toIntOrNull() ?: 22
|
||||
val username = usernameInput.text.toString()
|
||||
val password = passwordInput.text.toString()
|
||||
|
||||
if (host.isEmpty() || username.isEmpty() || password.isEmpty()) {
|
||||
appendOutput("❌ Please fill all fields")
|
||||
return
|
||||
}
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
appendOutput("🔌 Connecting to $host:$port...")
|
||||
|
||||
val session = jsch.getSession(username, host, port).apply {
|
||||
setPassword(password)
|
||||
setConfig("StrictHostKeyChecking", "no") // ⚠️ Only for testing!
|
||||
connect(30000) // 30 second timeout
|
||||
}
|
||||
|
||||
appendOutput("✅ Connected successfully!")
|
||||
|
||||
runOnUiThread {
|
||||
executeButton.isEnabled = true
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
appendOutput("❌ Connection failed: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun executeCommand(command: String) {
|
||||
val host = hostInput.text.toString()
|
||||
val port = portInput.text.toString().toIntOrNull() ?: 22
|
||||
val username = usernameInput.text.toString()
|
||||
val password = passwordInput.text.toString()
|
||||
|
||||
if (host.isEmpty() || username.isEmpty() || password.isEmpty()) {
|
||||
appendOutput("❌ Please fill all fields")
|
||||
return
|
||||
}
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
appendOutput("💻 Executing: $command")
|
||||
|
||||
val session = jsch.getSession(username, host, port).apply {
|
||||
setPassword(password)
|
||||
setConfig("StrictHostKeyChecking", "no")
|
||||
connect(30000)
|
||||
}
|
||||
|
||||
val channel = session.openChannel("exec") as ChannelExec
|
||||
channel.setCommand(command)
|
||||
|
||||
val inputStream = channel.inputStream
|
||||
val errorStream = channel.errStream
|
||||
|
||||
channel.connect()
|
||||
|
||||
val output = inputStream.bufferedReader().readText()
|
||||
val error = errorStream.bufferedReader().readText()
|
||||
|
||||
channel.disconnect()
|
||||
session.disconnect()
|
||||
|
||||
runOnUiThread {
|
||||
if (output.isNotEmpty()) {
|
||||
appendOutput("📄 Output:\n$output")
|
||||
}
|
||||
if (error.isNotEmpty()) {
|
||||
appendOutput("⚠️ Error:\n$error")
|
||||
}
|
||||
appendOutput("🔚 Command completed")
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
appendOutput("❌ SSH operation failed: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendOutput(text: String) {
|
||||
runOnUiThread {
|
||||
val current = outputText.text.toString()
|
||||
outputText.text = if (current.isEmpty()) text else "$current\n$text"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Простой data class для профилей
|
||||
data class SshProfile(
|
||||
val name: String,
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val username: String,
|
||||
val password: String
|
||||
)
|
||||
312
app/src/main/java/com/example/vedroid/TerminalActivity.kt
Normal file
312
app/src/main/java/com/example/vedroid/TerminalActivity.kt
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
package com.example.vedroid
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.view.KeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.*
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.jcraft.jsch.ChannelShell
|
||||
import com.jcraft.jsch.JSch
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
class TerminalActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var terminalView: TextView
|
||||
private lateinit var inputEditText: EditText
|
||||
private lateinit var terminalScrollView: ScrollView
|
||||
private lateinit var ctrlCButton: Button
|
||||
private lateinit var ctrlDButton: Button
|
||||
private lateinit var clearButton: Button
|
||||
private lateinit var sendButton: Button
|
||||
|
||||
private val jsch = JSch()
|
||||
private var channel: ChannelShell? = null
|
||||
private var inputStream: InputStream? = null
|
||||
private var outputStream: OutputStream? = null
|
||||
|
||||
private var isConnected = false
|
||||
private val terminalScope = CoroutineScope(Dispatchers.Main + Job())
|
||||
private val commandHistory = mutableListOf<String>()
|
||||
private var historyIndex = -1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_terminal)
|
||||
|
||||
val host = intent.getStringExtra("host") ?: ""
|
||||
val port = intent.getIntExtra("port", 22)
|
||||
val username = intent.getStringExtra("username") ?: ""
|
||||
val password = intent.getStringExtra("password") ?: ""
|
||||
|
||||
if (host.isEmpty() || username.isEmpty() || password.isEmpty()) {
|
||||
showError("Invalid connection data")
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
initViews()
|
||||
setupClickListeners()
|
||||
connectToTerminal(host, port, username, password)
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
terminalView = findViewById(R.id.terminalView)
|
||||
inputEditText = findViewById(R.id.inputEditText)
|
||||
terminalScrollView = findViewById(R.id.terminalScrollView)
|
||||
ctrlCButton = findViewById(R.id.ctrlCButton)
|
||||
ctrlDButton = findViewById(R.id.ctrlDButton)
|
||||
clearButton = findViewById(R.id.clearButton)
|
||||
sendButton = findViewById(R.id.sendButton)
|
||||
|
||||
terminalView.movementMethod = ScrollingMovementMethod()
|
||||
terminalView.text = ""
|
||||
|
||||
// Настройка истории команд
|
||||
inputEditText.setOnKeyListener { _, keyCode, event ->
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP -> {
|
||||
showPreviousCommand()
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> {
|
||||
showNextCommand()
|
||||
return@setOnKeyListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupClickListeners() {
|
||||
sendButton.setOnClickListener {
|
||||
sendCommand()
|
||||
}
|
||||
|
||||
inputEditText.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
sendCommand()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
ctrlCButton.setOnClickListener {
|
||||
sendControlC()
|
||||
}
|
||||
|
||||
ctrlDButton.setOnClickListener {
|
||||
sendControlD()
|
||||
}
|
||||
|
||||
clearButton.setOnClickListener {
|
||||
clearTerminal()
|
||||
}
|
||||
}
|
||||
|
||||
private fun connectToTerminal(host: String, port: Int, username: String, password: String) {
|
||||
terminalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
appendToTerminal("🔌 Connecting to $host:$port...\n")
|
||||
|
||||
val session = jsch.getSession(username, host, port).apply {
|
||||
setPassword(password)
|
||||
setConfig("StrictHostKeyChecking", "no")
|
||||
setConfig("PreferredAuthentications", "password")
|
||||
|
||||
// Важные настройки для терминала
|
||||
setConfig("compression.s2c", "none")
|
||||
setConfig("compression.c2s", "none")
|
||||
setConfig("StrictHostKeyChecking", "no")
|
||||
|
||||
connect(30000)
|
||||
}
|
||||
|
||||
channel = session.openChannel("shell") as ChannelShell
|
||||
channel?.apply {
|
||||
// Упрощенные настройки терминала
|
||||
setPtyType("vt100") // Простой терминал вместо xterm
|
||||
setPtySize(80, 24, 0, 0)
|
||||
|
||||
// Минимальные настройки окружения
|
||||
setEnv("TERM", "vt100")
|
||||
setEnv("LANG", "C") // Простая локаль
|
||||
|
||||
connect(5000)
|
||||
}
|
||||
|
||||
inputStream = channel?.inputStream
|
||||
outputStream = channel?.outputStream
|
||||
|
||||
isConnected = true
|
||||
|
||||
appendToTerminal("✅ Connected to SSH terminal\n")
|
||||
appendToTerminal("💡 Type commands in the input field below\n\n")
|
||||
|
||||
// Запускаем чтение вывода
|
||||
launch(Dispatchers.IO) {
|
||||
readTerminalOutput()
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
appendToTerminal("❌ Connection failed: ${e.message}\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readTerminalOutput() {
|
||||
val buffer = ByteArray(1024)
|
||||
try {
|
||||
while (isConnected && channel?.isConnected == true) {
|
||||
val length = inputStream?.read(buffer) ?: -1
|
||||
if (length > 0) {
|
||||
val output = String(buffer, 0, length, StandardCharsets.UTF_8)
|
||||
val cleanedOutput = cleanTerminalOutput(output)
|
||||
appendToTerminal(cleanedOutput)
|
||||
} else if (length < 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (isConnected) {
|
||||
appendToTerminal("\n❌ Connection lost\n")
|
||||
}
|
||||
} finally {
|
||||
disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
private fun cleanTerminalOutput(output: String): String {
|
||||
return output
|
||||
.replace("\u001B\\[[?]?[0-9;]*[A-Za-z]".toRegex(), "") // ANSI escape sequences
|
||||
.replace("\u001B\\].*?\u0007".toRegex(), "") // OSC sequences
|
||||
.replace("\u0007", "") // Bell character
|
||||
.replace("\u0008", "") // Backspace
|
||||
.replace("\r\n", "\n") // Normalize line endings
|
||||
.replace("\r", "\n")
|
||||
}
|
||||
|
||||
private fun sendCommand() {
|
||||
val command = inputEditText.text.toString().trim()
|
||||
if (command.isNotEmpty() && isConnected) {
|
||||
// Добавляем в историю
|
||||
if (commandHistory.isEmpty() || commandHistory.last() != command) {
|
||||
commandHistory.add(command)
|
||||
if (commandHistory.size > 50) {
|
||||
commandHistory.removeAt(0)
|
||||
}
|
||||
}
|
||||
historyIndex = commandHistory.size
|
||||
|
||||
// Показываем команду в терминале
|
||||
appendToTerminal("$ ${command}\n")
|
||||
|
||||
// Отправляем команду
|
||||
terminalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
outputStream?.write("$command\n".toByteArray(StandardCharsets.UTF_8))
|
||||
outputStream?.flush()
|
||||
} catch (e: Exception) {
|
||||
appendToTerminal("❌ Error sending command\n")
|
||||
}
|
||||
}
|
||||
|
||||
inputEditText.text.clear()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPreviousCommand() {
|
||||
if (commandHistory.isNotEmpty()) {
|
||||
if (historyIndex > 0) historyIndex--
|
||||
if (historyIndex in commandHistory.indices) {
|
||||
inputEditText.setText(commandHistory[historyIndex])
|
||||
inputEditText.setSelection(inputEditText.text.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNextCommand() {
|
||||
if (commandHistory.isNotEmpty()) {
|
||||
if (historyIndex < commandHistory.size - 1) {
|
||||
historyIndex++
|
||||
inputEditText.setText(commandHistory[historyIndex])
|
||||
inputEditText.setSelection(inputEditText.text.length)
|
||||
} else {
|
||||
historyIndex = commandHistory.size
|
||||
inputEditText.text.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendControlC() {
|
||||
if (isConnected) {
|
||||
terminalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
outputStream?.write(3) // Ctrl+C
|
||||
outputStream?.flush()
|
||||
appendToTerminal("^C\n")
|
||||
} catch (e: Exception) {
|
||||
appendToTerminal("❌ Error sending Ctrl+C\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendControlD() {
|
||||
if (isConnected) {
|
||||
terminalScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
outputStream?.write(4) // Ctrl+D
|
||||
outputStream?.flush()
|
||||
appendToTerminal("^D\n")
|
||||
} catch (e: Exception) {
|
||||
appendToTerminal("❌ Error sending Ctrl+D\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendToTerminal(text: String) {
|
||||
runOnUiThread {
|
||||
val current = terminalView.text.toString()
|
||||
terminalView.text = current + text
|
||||
|
||||
terminalScrollView.post {
|
||||
terminalScrollView.fullScroll(android.view.View.FOCUS_DOWN)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearTerminal() {
|
||||
runOnUiThread {
|
||||
terminalView.text = ""
|
||||
appendToTerminal("Terminal cleared\n")
|
||||
}
|
||||
}
|
||||
|
||||
private fun showError(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
private fun disconnect() {
|
||||
isConnected = false
|
||||
try {
|
||||
channel?.disconnect()
|
||||
} catch (e: Exception) {
|
||||
// Ignore
|
||||
}
|
||||
appendToTerminal("\n🔌 Disconnected\n")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
disconnect()
|
||||
terminalScope.cancel()
|
||||
}
|
||||
}
|
||||
10
app/src/main/java/com/example/vedroid/model/SshProfile.kt
Normal file
10
app/src/main/java/com/example/vedroid/model/SshProfile.kt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package com.example.vedroid.model
|
||||
|
||||
// Теперь не нужно Serializable
|
||||
data class SshProfile(
|
||||
val name: String,
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val username: String,
|
||||
val password: String
|
||||
)
|
||||
10
app/src/main/res/drawable/ic_launcher.xml
Normal file
10
app/src/main/res/drawable/ic_launcher.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#3F51B5"
|
||||
android:pathData="M12,2L2,7L12,12L22,7L12,2Z" />
|
||||
</vector>
|
||||
20
app/src/main/res/layout/activity_main.xml
Normal file
20
app/src/main/res/layout/activity_main.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hello_world"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
118
app/src/main/res/layout/activity_ssh.xml
Normal file
118
app/src/main/res/layout/activity_ssh.xml
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?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="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SSH Client with Profiles"
|
||||
android:textSize="24sp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="20dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginBottom="16dp">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/profilesSpinner"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:layout_marginEnd="8dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveProfileButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="💾"
|
||||
android:layout_marginEnd="4dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/deleteProfileButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="🗑️"
|
||||
android:layout_marginStart="4dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/hostInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Host (e.g., 192.168.1.1)"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/portInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Port (default: 22)"
|
||||
android:inputType="number"
|
||||
android:text="22"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/usernameInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Username"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/passwordInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Password"
|
||||
android:inputType="textPassword"
|
||||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/connectButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Connect SSH"
|
||||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/outputText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SSH output will appear here..."
|
||||
android:background="#f5f5f5"
|
||||
android:padding="8dp"
|
||||
android:textIsSelectable="true"
|
||||
android:fontFamily="monospace" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/executeButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Execute: ls -la"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<!-- Добавляем после executeButton -->
|
||||
<Button
|
||||
android:id="@+id/terminalButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="🖥️ Open Interactive Terminal"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:backgroundTint="#4CAF50" />
|
||||
|
||||
</LinearLayout>
|
||||
121
app/src/main/res/layout/activity_terminal.xml
Normal file
121
app/src/main/res/layout/activity_terminal.xml
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?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="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp"
|
||||
android:background="#000000">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SSH Terminal"
|
||||
android:textSize="18sp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="#333333"
|
||||
android:padding="8dp" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/terminalScrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#000000"
|
||||
android:padding="4dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/terminalView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#00FF00"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="monospace"
|
||||
android:background="#000000"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/inputEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="Type command here..."
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="14sp"
|
||||
android:background="#333333"
|
||||
android:imeOptions="actionDone"
|
||||
android:maxLines="1"
|
||||
android:layout_marginEnd="8dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/sendButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Send"
|
||||
android:textColor="#FFFFFF"
|
||||
android:backgroundTint="#4CAF50" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="#333333"
|
||||
android:padding="8dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/ctrlCButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Ctrl+C"
|
||||
android:textColor="#FFFFFF"
|
||||
android:backgroundTint="#FF5722"
|
||||
android:layout_marginEnd="4dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/ctrlDButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Ctrl+D"
|
||||
android:textColor="#FFFFFF"
|
||||
android:backgroundTint="#FF9800"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="4dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/clearButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Clear"
|
||||
android:textColor="#FFFFFF"
|
||||
android:backgroundTint="#2196F3"
|
||||
android:layout_marginStart="4dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="💡 Use ↑↓ for command history"
|
||||
android:textSize="12sp"
|
||||
android:textColor="#AAAAAA"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="8dp"
|
||||
android:padding="4dp" />
|
||||
|
||||
</LinearLayout>
|
||||
21
app/src/main/res/layout/dialog_save_profile.xml
Normal file
21
app/src/main/res/layout/dialog_save_profile.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?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="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enter profile name:"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/profileNameInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="My Server"
|
||||
android:inputType="text" />
|
||||
|
||||
</LinearLayout>
|
||||
9
app/src/main/res/values/colors.xml
Normal file
9
app/src/main/res/values/colors.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
4
app/src/main/res/values/strings.xml
Normal file
4
app/src/main/res/values/strings.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<resources>
|
||||
<string name="app_name">Vedroid</string>
|
||||
<string name="hello_world">Hello World!</string>
|
||||
</resources>
|
||||
18
app/src/main/res/values/themes.xml
Normal file
18
app/src/main/res/values/themes.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Vedroid" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">#3F51B5</item>
|
||||
<item name="colorPrimaryVariant">#303F9F</item>
|
||||
<item name="colorOnPrimary">#FFFFFF</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">#FF4081</item>
|
||||
<item name="colorSecondaryVariant">#FF4081</item>
|
||||
<item name="colorOnSecondary">#FFFFFF</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.AppCompat.DayNight.NoActionBar" parent="Theme.AppCompat.DayNight">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
6
app/src/main/res/xml/backup_rules.xml
Normal file
6
app/src/main/res/xml/backup_rules.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
<include domain="sharedpref" path="."/>
|
||||
<include domain="database" path="."/>
|
||||
<include domain="file" path="."/>
|
||||
</full-backup-content>
|
||||
8
app/src/main/res/xml/data_extraction_rules.xml
Normal file
8
app/src/main/res/xml/data_extraction_rules.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<include domain="sharedpref" path="."/>
|
||||
<include domain="database" path="."/>
|
||||
<include domain="file" path="."/>
|
||||
</cloud-backup>
|
||||
</data-extraction-rules>
|
||||
Loading…
Add table
Add a link
Reference in a new issue