diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 9d0a575..d3fbabd 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -9,14 +9,20 @@ android {
defaultConfig {
applicationId = "com.vkturn.proxy"
- minSdk = 26
+ minSdk = 23
targetSdk = 28
- versionCode = 1
- versionName = "1.0"
+ versionCode = 2
+ versionName = "1.1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
+ packaging {
+ resources.excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF"
+ jniLibs.useLegacyPackaging = true
+ }
+ // ---------------------------------
+
buildTypes {
release {
isMinifyEnabled = false
@@ -44,6 +50,11 @@ android {
}
dependencies {
+ // SSH и Корутины
+ implementation("com.github.mwiede:jsch:0.2.17")
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
+
+ // Стандартные библиотеки Android
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
@@ -52,4 +63,4 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
-}
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 84adbd4..85c63c8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -30,6 +30,8 @@
+
+
(R.id.btnSettings)
+ btnSettings.setOnClickListener {
+ val intent = Intent(this, SettingsActivity::class.java)
+ startActivity(intent)
+ }
+ // ----------------------------------------------
+
btnToggle.setOnClickListener {
if (!ProxyService.isRunning) {
// Сохранение перед стартом
diff --git a/app/src/main/java/com/vkturn/proxy/SSHManager.kt b/app/src/main/java/com/vkturn/proxy/SSHManager.kt
new file mode 100644
index 0000000..f2479e9
--- /dev/null
+++ b/app/src/main/java/com/vkturn/proxy/SSHManager.kt
@@ -0,0 +1,135 @@
+package com.vkturn.proxy
+
+import com.jcraft.jsch.ChannelExec
+import com.jcraft.jsch.ChannelShell
+import com.jcraft.jsch.JSch
+import com.jcraft.jsch.Session
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import java.io.InputStream
+import java.io.OutputStream
+import java.util.Properties
+
+class SSHManager {
+ private var session: Session? = null
+ private var shellChannel: ChannelShell? = null
+ private var shellOutputStream: OutputStream? = null
+ @Volatile private var isShellRunning = false
+
+ fun startShell(ip: String, port: Int, user: String, pass: String, onLogReceived: (String) -> Unit) {
+ Thread {
+ try {
+ if (session == null || !session!!.isConnected) {
+ val jsch = JSch()
+ session = jsch.getSession(user, ip, port)
+ session?.setPassword(pass)
+
+ val config = Properties()
+ config.put("StrictHostKeyChecking", "no")
+ session?.setConfig(config)
+ session?.connect(10000)
+ }
+
+ if (shellChannel != null && shellChannel!!.isConnected) {
+ return@Thread
+ }
+
+ shellChannel = session?.openChannel("shell") as ChannelShell
+ shellChannel?.setPty(true)
+
+ val inStream: InputStream = shellChannel!!.inputStream
+ shellOutputStream = shellChannel!!.outputStream
+
+ shellChannel?.connect(5000)
+ isShellRunning = true
+
+ val reader = inStream.bufferedReader()
+ val buffer = CharArray(1024)
+ var read = 0
+
+ while (isShellRunning && reader.read(buffer).also { read = it } != -1) {
+ val output = String(buffer, 0, read)
+ onLogReceived(output)
+ }
+ } catch (e: Exception) {
+ onLogReceived("\n[ОШИБКА SHELL]: ${e.message}\n")
+ }
+ }.start()
+ }
+
+ fun sendShellCommand(command: String) {
+ Thread {
+ try {
+ if (shellOutputStream != null) {
+ shellOutputStream?.write((command + "\r").toByteArray())
+ shellOutputStream?.flush()
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ }.start()
+ }
+
+ // НОВАЯ ФУНКЦИЯ: Эмуляция Ctrl+C (прерывание процесса)
+ fun sendCtrlC() {
+ Thread {
+ try {
+ if (shellOutputStream != null) {
+ shellOutputStream?.write(3) // Байт 3 = ASCII символ ETX (End of Text) = Ctrl+C
+ shellOutputStream?.flush()
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ }
+ }.start()
+ }
+
+ suspend fun executeSilentCommand(ip: String, port: Int, user: String, pass: String, command: String): String = withContext(Dispatchers.IO) {
+ var tempSession: Session? = null
+ try {
+ val jsch = JSch()
+ tempSession = jsch.getSession(user, ip, port)
+ tempSession.setPassword(pass)
+
+ val config = Properties()
+ config.put("StrictHostKeyChecking", "no")
+ tempSession.setConfig(config)
+ tempSession.connect(5000)
+
+ val channel = tempSession.openChannel("exec") as ChannelExec
+ channel.setCommand(command)
+ channel.inputStream = null
+ channel.setErrStream(null)
+
+ val inStream: InputStream = channel.inputStream
+ channel.connect()
+
+ val output = StringBuilder()
+ val reader = inStream.bufferedReader()
+
+ var line: String? = null
+ while (reader.readLine().also { line = it } != null) {
+ output.append(line).append("\n")
+ }
+
+ channel.disconnect()
+ output.toString().trim()
+ } catch (e: Exception) {
+ "ERROR: ${e.message}"
+ } finally {
+ tempSession?.disconnect()
+ }
+ }
+
+ fun disconnect() {
+ isShellRunning = false
+ try {
+ shellOutputStream?.close()
+ } catch (e: Exception) {}
+ shellChannel?.disconnect()
+ session?.disconnect()
+ shellChannel = null
+ session = null
+ shellOutputStream = null
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/vkturn/proxy/SettingsActivity.kt b/app/src/main/java/com/vkturn/proxy/SettingsActivity.kt
new file mode 100644
index 0000000..90b83d2
--- /dev/null
+++ b/app/src/main/java/com/vkturn/proxy/SettingsActivity.kt
@@ -0,0 +1,189 @@
+package com.vkturn.proxy
+
+import android.content.ClipData
+import android.content.ClipboardManager
+import android.content.Context
+import android.os.Bundle
+import android.widget.*
+import androidx.appcompat.app.AppCompatActivity
+import kotlinx.coroutines.*
+
+class SettingsActivity : AppCompatActivity() {
+
+ private val sshManager = SSHManager()
+ private lateinit var tvSshLog: TextView
+ private lateinit var scrollSshLog: ScrollView
+ private lateinit var btnInstallServer: Button
+ private lateinit var btnStartProxy: Button
+ private lateinit var btnStopProxy: Button
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_settings)
+
+ val editIp = findViewById(R.id.editSshIp)
+ val editPort = findViewById(R.id.editSshPort)
+ val editUser = findViewById(R.id.editSshUser)
+ val editPass = findViewById(R.id.editSshPass)
+ val editProxyListen = findViewById(R.id.editProxyListen)
+ val editProxyConnect = findViewById(R.id.editProxyConnect)
+ val editCustomCmd = findViewById(R.id.editCustomCmd)
+ val btnSendCmd = findViewById