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)
@Throws(Exception::class)
fun main(args: Array<String>) {
Runtime.getRuntime().exec("echo Hello-World")
Config()
val app = Application()
app.run()

View file

@ -1,15 +1,73 @@
package org.bm00.DataAccessor.windows
import jexer.TAction
import jexer.TApplication
import jexer.TPasswordField
import jexer.TWindow
import jexer.*
import jexer.TWindow.CENTERED
import jexer.layout.StretchLayoutManager
import java.awt.SystemColor.text
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)
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 {
setLayoutManager(
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() {
override fun DO() {
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() {
override fun DO() {
TODO("Once activated, start SSH login process")
loginActivity()
}
}
)
//Password
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
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, "",
// 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")
}
}
);
}}
// Server
addLabel("Server", CENTERED + 10, CENTERED + 5)
}
}