Windows functionality! with sshfs-win

This commit is contained in:
nelle 2024-02-16 21:31:41 -07:00
parent 1e164d8239
commit af7739ed60
7 changed files with 133 additions and 15 deletions

View file

@ -0,0 +1,10 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View file

@ -5,7 +5,7 @@
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="" /> <option name="gradleJvm" value="temurin-19" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View file

@ -7,8 +7,8 @@ Built in Kotlin, and utilizes [Jexer](https://git.ouroboros.group/limepotato/jex
## Installation Instructions: ## Installation Instructions:
### Linux: ### Linux:
1. install `sshpass` && `sshfs` (TODO://Automated script? annoying) 1. install `openssh-askpass` && `sshfs`
2. download and run and enjoy wowzises 2. download and run and enjoy wowzises
### Windows: ### Windows:
1. install [sshfs-win](https://github.com/winfsp/sshfs-win) && [this?](https://github.com/PowerShell/Win32-OpenSSH/issues/1943) 1. install [sshfs-win](https://github.com/winfsp/sshfs-win)
2. run and enjoy wowwoww 2. run and enjoy wowwoww

View file

@ -26,6 +26,14 @@ fun getOS(): OS? {
} }
} }
val osName =
when (getOS())
{
OS.WINDOWS -> "WINDOWS"
OS.MAC -> "MAC"
OS.LINUX -> "LINUX"
else -> throw Exception("Operating System could not be detected!")
}
// Set Jexer backend type // Set Jexer backend type
// Possible answers: SWING, XTERM, ECMA48 // Possible answers: SWING, XTERM, ECMA48
@ -46,6 +54,5 @@ val backendType =
class Application : TApplication(backendType, 80, 40, 18) { class Application : TApplication(backendType, 80, 40, 18) {
init { init {
WelcomeWindow(this) WelcomeWindow(this)
} }
} }

View file

@ -1,9 +1,43 @@
package org.bm00.DataAccessor.windows package org.bm00.DataAccessor.windows
import jexer.* import jexer.TAction
import jexer.TWindow.CENTERED import jexer.TApplication
import jexer.TWindow
import jexer.layout.StretchLayoutManager import jexer.layout.StretchLayoutManager
import java.awt.SystemColor.text import org.bm00.DataAccessor.osName
import java.util.*
enum class OS {
WINDOWS, LINUX, MAC
}
fun getOS(): OS? {
val isJexer = System.getProperty("jexer.Swing")
val os = System.getProperty("os.name").lowercase(Locale.getDefault())
return when {
os.contains("win") -> {
OS.WINDOWS
}
os.contains("nix") || os.contains("nux") || os.contains("aix") -> {
OS.LINUX
}
os.contains("mac") -> {
OS.MAC
}
else -> null
}
}
val osName =
when (getOS())
{
OS.WINDOWS -> "WINDOWS"
OS.MAC -> "MAC"
OS.LINUX -> "LINUX"
else -> throw Exception("Operating System could not be detected!")
}
class LoginWindow private constructor(parent: TApplication, flags: Int) : class LoginWindow private constructor(parent: TApplication, flags: Int) :
TWindow(parent, "Login", 0, 0, 36, 19, flags) { TWindow(parent, "Login", 0, 0, 36, 19, flags) {
@ -13,7 +47,15 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
// enterAction - function to call when enter key is pressed // enterAction - function to call when enter key is pressed
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
loginActivity() if (osName == "LINUX") {
loginActivityLinux()
}
else if (osName == "WINDOWS") {
loginActivityWindows()
}
else {
TODO()
}
} }
}, },
// updateAction - function to call when the text is updated // updateAction - function to call when the text is updated
@ -28,7 +70,15 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
// enterAction - function to call when enter key is pressed // enterAction - function to call when enter key is pressed
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
loginActivity() if (osName == "LINUX") {
loginActivityLinux()
}
else if (osName == "WINDOWS") {
loginActivityWindows()
}
else {
TODO()
}
} }
}, },
// updateAction - function to call when the text is updated // updateAction - function to call when the text is updated
@ -39,11 +89,9 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
} }
); );
fun loginActivity() { fun loginActivityLinux() {
var usernameDetail = loginField.text var usernameDetail = loginField.text
var serverDetail = serverField.text var serverDetail = serverField.text
//TODO: https://github.com/winfsp/sshfs-win for sshfs?
// and https://microsoft.github.io/Git-Credential-Manager-for-Windows/Docs/Askpass.html for askpass????
//openssh-askpass as well //openssh-askpass as well
val createMntPnt = val createMntPnt =
ProcessBuilder("mkdir", "/tmp/osda_mount") ProcessBuilder("mkdir", "/tmp/osda_mount")
@ -62,6 +110,34 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
.start() .start()
.waitFor() .waitFor()
} }
fun loginActivityWindows() {
var usernameDetail = loginField.text
var serverDetail = serverField.text
var passwordBox = inputBox("Password", "Please enter your remote password")
var passwordDetail = passwordBox.text
//TODO: https://github.com/winfsp/sshfs-win for sshfs?
// and https://github.com/git-ecosystem/git-credential-manager/ for askpass????
// `net use X: \\sshfs\username@servername`
val remoteMount =
ProcessBuilder(
"net",
"use",
"O:",
"\\\\sshfs\\$usernameDetail@$serverDetail",
"$passwordDetail"
/*
"net",
"use",
"X:",
"\\\\sshfs\\$usernameDetail@$serverDetail:/home/$usernameDetail"*/
)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
}
init { init {
setLayoutManager( setLayoutManager(
StretchLayoutManager( StretchLayoutManager(
@ -75,7 +151,15 @@ class LoginWindow private constructor(parent: TApplication, flags: Int) :
addButton("Login", CENTERED + 9, CENTERED + 8, addButton("Login", CENTERED + 9, CENTERED + 8,
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
loginActivity() if (osName == "LINUX") {
loginActivityLinux()
}
else if (osName == "WINDOWS") {
loginActivityWindows()
}
else {
TODO()
}
} }
} }
) )

View file

@ -29,13 +29,25 @@ class WelcomeWindow private constructor(parent: TApplication, flags: Int) :
addButton("Exit...", CENTERED + 28, CENTERED, addButton("Exit...", CENTERED + 28, CENTERED,
object : TAction() { object : TAction() {
override fun DO() { override fun DO() {
val unmount = if (org.bm00.DataAccessor.osName == "LINUX") {
ProcessBuilder("umount", "/tmp/osda_mount") ProcessBuilder("umount", "/tmp/osda_mount")
.redirectOutput(ProcessBuilder.Redirect.INHERIT) .redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT) .redirectError(ProcessBuilder.Redirect.INHERIT)
.start() .start()
.waitFor() .waitFor()
System.exit(0) System.exit(0)
}
else if (org.bm00.DataAccessor.osName == "WINDOWS") {
ProcessBuilder("net", "use", "O:", "/delete")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
System.exit(0)
}
else {
System.exit(0)
}
} }
} }
) )