mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 04:46:42 -04:00
Add support for the RCW daemon
This commit is contained in:
+3
-7
@@ -1,7 +1,6 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -59,14 +58,11 @@ func CopyArgument(targetLocation string, field int, passphrase []byte) {
|
|||||||
|
|
||||||
// ClipClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess.
|
// ClipClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess.
|
||||||
func ClipClearArgument() {
|
func ClipClearArgument() {
|
||||||
// read previous clipboard contents from stdin
|
assignedContents := readFromStdin()
|
||||||
clipScanner := bufio.NewScanner(os.Stdin)
|
if assignedContents == "" {
|
||||||
if clipScanner.Scan() {
|
|
||||||
assignedContents := clipScanner.Text()
|
|
||||||
clipClearProcess(assignedContents)
|
|
||||||
} else {
|
|
||||||
os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||||
}
|
}
|
||||||
|
clipClearProcess(assignedContents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP).
|
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP).
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import (
|
|||||||
// LaunchClipClearProcess launches the timed clipboard clearing process.
|
// LaunchClipClearProcess launches the timed clipboard clearing process.
|
||||||
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
|
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
|
||||||
func LaunchClipClearProcess(copySubject string) {
|
func LaunchClipClearProcess(copySubject string) {
|
||||||
executableName := os.Args[0]
|
cmd := exec.Command(os.Args[0], "clipclear")
|
||||||
cmd := exec.Command(executableName, "clipclear")
|
|
||||||
writeToStdin(cmd, copySubject)
|
writeToStdin(cmd, copySubject)
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ import (
|
|||||||
// LaunchClipClearProcess launches the timed clipboard clearing process.
|
// LaunchClipClearProcess launches the timed clipboard clearing process.
|
||||||
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
|
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
|
||||||
func LaunchClipClearProcess(copySubject string, isWayland bool) {
|
func LaunchClipClearProcess(copySubject string, isWayland bool) {
|
||||||
executableName := os.Args[0]
|
cmd := exec.Command(os.Args[0], "clipclear", strconv.FormatBool(isWayland))
|
||||||
cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland))
|
|
||||||
writeToStdin(cmd, copySubject)
|
writeToStdin(cmd, copySubject)
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+21
@@ -2,8 +2,10 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rwinkhart/rcw/daemon"
|
||||||
"github.com/rwinkhart/rcw/wrappers"
|
"github.com/rwinkhart/rcw/wrappers"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,3 +27,22 @@ func EncryptBytes(decBytes []byte, passphrase []byte) []byte {
|
|||||||
encBytes := wrappers.Encrypt(decBytes, passphrase)
|
encBytes := wrappers.Encrypt(decBytes, passphrase)
|
||||||
return encBytes
|
return encBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LaunchRCWDProcess launches an RCW daemon to serve the given passphrase.
|
||||||
|
func LaunchRCWDProcess(passphrase string) {
|
||||||
|
cmd := exec.Command(os.Args[0], "startrcwd")
|
||||||
|
writeToStdin(cmd, passphrase)
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
PrintError("Failed to launch RCW daemon - Does this libmutton implementation support the \"startrcwd\" argument?", ErrorOther, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RCWDArgument reads the passphrase from stdin and serves it via an RCW daemon.
|
||||||
|
func RCWDArgument() {
|
||||||
|
passphrase := readFromStdin()
|
||||||
|
if passphrase == "" {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
daemon.Start(string(passphrase))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -59,6 +60,15 @@ func writeToStdin(cmd *exec.Cmd, input string) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readFromStdin is a utility function that reads a string from stdin.
|
||||||
|
func readFromStdin() string {
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
if scanner.Scan() {
|
||||||
|
return scanner.Text()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// CreateTempFile creates a temporary file and returns a pointer to it.
|
// CreateTempFile creates a temporary file and returns a pointer to it.
|
||||||
func CreateTempFile() *os.File {
|
func CreateTempFile() *os.File {
|
||||||
tempFile, err := os.CreateTemp("", "*.markdown")
|
tempFile, err := os.CreateTemp("", "*.markdown")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ require (
|
|||||||
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727
|
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727
|
||||||
github.com/pkg/sftp v1.13.9
|
github.com/pkg/sftp v1.13.9
|
||||||
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481
|
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481
|
||||||
github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5
|
github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b
|
||||||
golang.design/x/clipboard v0.7.0 // only for Android builds
|
golang.design/x/clipboard v0.7.0 // only for Android builds
|
||||||
golang.org/x/crypto v0.37.0
|
golang.org/x/crypto v0.37.0
|
||||||
gopkg.in/ini.v1 v1.67.0
|
gopkg.in/ini.v1 v1.67.0
|
||||||
@@ -21,6 +21,11 @@ require (
|
|||||||
golang.org/x/sys v0.32.0 // indirect
|
golang.org/x/sys v0.32.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
|
github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea // indirect
|
||||||
|
)
|
||||||
|
|
||||||
replace golang.org/x/sys => github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0
|
replace golang.org/x/sys => github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0
|
||||||
|
|
||||||
replace github.com/Microsoft/go-winio => github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410
|
replace github.com/Microsoft/go-winio => github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410
|
||||||
|
|||||||
@@ -15,8 +15,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 h1:FkxbO331O7mS5EJkP+MCi0o2gswh/Aezs+//NmefrR8=
|
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 h1:FkxbO331O7mS5EJkP+MCi0o2gswh/Aezs+//NmefrR8=
|
||||||
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||||
github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5 h1:BX31d76TLGZqeukYECLFPkLD+SS/CAV12Lkdlc6UuGM=
|
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE=
|
||||||
github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM=
|
github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||||
|
github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea h1:VE2ti/AE4Y3kgnyK+J5c5hpddE+dKHpsFch3K2R6puQ=
|
||||||
|
github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea/go.mod h1:t+YkvAdnTKTrg4d469tw3K+GCUzX/Bja4h8yKjSIsGs=
|
||||||
|
github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b h1:eWN9ogSzNE8KcFcoIBgrdgMCOUhxnV7m+SJ9Z3SCnPU=
|
||||||
|
github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM=
|
||||||
github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0 h1:KRbqimv9Eexf3VB2FrRAQ4v2fGGu7gt3ayMgdT0FNao=
|
github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0 h1:KRbqimv9Eexf3VB2FrRAQ4v2fGGu7gt3ayMgdT0FNao=
|
||||||
github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|||||||
Reference in New Issue
Block a user