We can login with ssh and do remote commands!

This commit is contained in:
nelle 2024-02-16 15:19:24 -07:00
parent 52254997df
commit 5865ae7a13
2 changed files with 71 additions and 40 deletions

View file

@ -15,7 +15,6 @@ class Application : TApplication(backendType, 80, 40, 18) {
// This creates a Jexer application (and calls the "backend type" which is how its rendered) // This creates a Jexer application (and calls the "backend type" which is how its rendered)
@Throws(Exception::class) @Throws(Exception::class)
fun main(args: Array<String>) { fun main(args: Array<String>) {
Runtime.getRuntime().exec("echo Hello-World")
Config() Config()
val app = Application() val app = Application()
app.run() app.run()

View file

@ -1,15 +1,73 @@
package org.bm00.DataAccessor.windows package org.bm00.DataAccessor.windows
import jexer.TAction import jexer.*
import jexer.TApplication import jexer.TWindow.CENTERED
import jexer.TPasswordField
import jexer.TWindow
import jexer.layout.StretchLayoutManager import jexer.layout.StretchLayoutManager
import java.awt.SystemColor.text
class LoginWindow private constructor(parent: TApplication, flags: Int) : class LoginWindow private constructor(parent: TApplication, flags: Int) :
TWindow(parent, "Login", 0, 0, 36, 16, flags) { TWindow(parent, "Login", 0, 0, 36, 19, flags) {
constructor(parent: TApplication) : this(parent, CENTERED) constructor(parent: TApplication) : this(parent, CENTERED)
var loginField = addPasswordField(CENTERED + 5, CENTERED - 1, 16, false, "",
// enterAction - function to call when enter key is pressed
object : TAction() {
override fun DO() {
loginActivity()
}
},
// updateAction - function to call when the text is updated
object : TAction() {
override fun DO() {
return
}
}
);
var passField = addPasswordField(CENTERED + 5, CENTERED + 3, 16, false, "",
// enterAction - function to call when enter key is pressed
object : TAction() {
override fun DO() {
loginActivity()
}
},
// updateAction - function to call when the text is updated
object : TAction() {
override fun DO() {
return
}
}
);
var serverField = addPasswordField(CENTERED + 5, CENTERED + 7, 16, false, "",
// enterAction - function to call when enter key is pressed
object : TAction() {
override fun DO() {
loginActivity()
}
},
// updateAction - function to call when the text is updated
object : TAction() {
override fun DO() {
return
}
}
);
fun loginActivity() {
var usernameDetail = loginField.text
var passwordDetail = passField.text
var serverDetail = serverField.text
var remoteCommand = "echo hello"
// For windows, instead of ssh pass?? https://github.com/PowerShell/Win32-OpenSSH/issues/1943
val loginProcess = ProcessBuilder(
"sshpass", "-p", "$passwordDetail", "ssh", "$usernameDetail@$serverDetail", remoteCommand)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
}
init { init {
setLayoutManager( setLayoutManager(
StretchLayoutManager( StretchLayoutManager(
@ -18,7 +76,7 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
) )
) )
addButton("Back...", CENTERED + 8, CENTERED + 8, addButton("Back...", CENTERED + 8, CENTERED + 11,
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
TODO("Instead of full program exit, make it close the login window") TODO("Instead of full program exit, make it close the login window")
@ -26,47 +84,21 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
} }
) )
addButton("Login", CENTERED + 9, CENTERED + 6, addButton("Login", CENTERED + 9, CENTERED + 9,
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
TODO("Once activated, start SSH login process") loginActivity()
} }
} }
) )
//Password //Password
addLabel("Password", CENTERED + 9, CENTERED + 1) addLabel("Password", CENTERED + 9, CENTERED + 1)
//TODO: Once enter is pressed, getText and save as var, then activate login process.
var passField = addPasswordField(CENTERED + 5, CENTERED + 3, 16, false, "",
// enterAction - function to call when enter key is pressed
object : TAction() {
override fun DO() {
TODO("get all the text entered and save as variables")
}
},
// updateAction - function to call when the text is updated
object : TAction() {
override fun DO() {
TODO("Not yet implemented")
}
}
);
//Login //Login
addLabel("Username", CENTERED + 9, CENTERED - 3) addLabel("Username", CENTERED + 9, CENTERED - 3)
//TODO: Once enter is pressed, getText and save as var, then activate login process.
addPasswordField(CENTERED + 5, CENTERED - 1, 16, false, "", // Server
// enterAction - function to call when enter key is pressed addLabel("Server", CENTERED + 10, CENTERED + 5)
object : TAction() {
override fun DO() {
TODO("get all the text entered and save as variables")
} }
}, }
// updateAction - function to call when the text is updated
object : TAction() {
override fun DO() {
TODO("Not yet implemented")
}
}
);
}}