mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 12:56:30 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3acaa607e4 | ||
|
|
d4360c06ba | ||
|
|
2cf786b2d7 | ||
|
|
b784fd8bd7 | ||
|
|
7d272f77ca | ||
|
|
424aa61c46 | ||
|
|
bff179e881 | ||
|
|
65b622d465 | ||
|
|
b7bfdbf62f | ||
|
|
1e2f1dea7e | ||
|
|
5d83e912ac | ||
|
|
b11e8bbcf2 | ||
|
|
d07a4cc398 | ||
|
|
67420b0713 | ||
|
|
ff10d843ad | ||
|
|
0392cf6fea | ||
|
|
804fc29087 | ||
|
|
d29da29018 | ||
|
|
7c5c2105f9 | ||
|
|
b4919f0e82 | ||
|
|
0ee803dc78 | ||
|
|
ed9e9a3af8 | ||
|
|
2668b2951c | ||
|
|
4e131d2870 | ||
|
|
498ecd9a50 | ||
|
|
8f98f1b61c | ||
|
|
ad7524f544 | ||
|
|
0687ce0954 | ||
|
|
ca14abbae9 | ||
|
|
3171d1c1cd | ||
|
|
c1a415e5b0 | ||
|
|
56eaec02c6 | ||
|
|
e4de8f930b | ||
|
|
26a5898e15 | ||
|
|
dd0d1ffe55 | ||
|
|
ff9092bc9f | ||
|
|
279384ee4a | ||
|
|
7e5823c35e | ||
|
|
80e4148b9b | ||
|
|
02fb625230 | ||
|
|
fb984f4514 | ||
|
|
148212b276 | ||
|
|
5cee48d412 | ||
|
|
c7735d32be | ||
|
|
2252be1463 | ||
|
|
edf1a4cd9a | ||
|
|
82b4fbee64 | ||
|
|
404f24d361 | ||
|
|
f83bdb9bdb | ||
|
|
f35d1b3741 | ||
|
|
a0ca7803f1 | ||
|
|
431082f711 | ||
|
|
652ef48dd5 | ||
|
|
b01e5bded4 | ||
|
|
31bc17cb0d | ||
|
|
5a12eaf4cf | ||
|
|
7d17af9b61 | ||
|
|
c6ee5fff06 | ||
|
|
aa1098d472 | ||
|
|
148ee53073 | ||
|
|
408cff1a79 | ||
|
|
22758460ab | ||
|
|
3a90bef48a | ||
|
|
300516c3cd | ||
|
|
9f1955eb82 | ||
|
|
609ef9bd8c | ||
|
|
1e1a26b098 | ||
|
|
22fcad2fed | ||
|
|
b1f3a9eeec | ||
|
|
d6443c1966 | ||
|
|
56ffe7e36f | ||
|
|
14b3d7bd45 | ||
|
|
11644b37ff | ||
|
|
1580227007 | ||
|
|
85067fef40 | ||
|
|
8704ba6972 | ||
|
|
dfe917a4ff | ||
|
|
24b899a83a | ||
|
|
6fecf5a686 | ||
|
|
0e6210f1af | ||
|
|
207a4762b6 | ||
|
|
0f65cd31cb | ||
|
|
988724bac6 | ||
|
|
9802b7498b | ||
|
|
00e0a70ee6 | ||
|
|
7a17df4aa3 | ||
|
|
3d621f5e38 | ||
|
|
4bd44e7b44 | ||
|
|
b17a3ae372 | ||
|
|
51313eb307 | ||
|
|
0afcdbb29b | ||
|
|
cefb91f1f6 | ||
|
|
fc2a6ab22f | ||
|
|
7d5bd76489 | ||
|
|
adcc05f3f4 | ||
|
|
ba89fbeab6 | ||
|
|
fa6d5bc78a | ||
|
|
86b152875e | ||
|
|
e61beb3f94 | ||
|
|
b26a29dd3d | ||
|
|
9f5cf7fd1e | ||
|
|
2012e332f3 | ||
|
|
00ec6417af | ||
|
|
e54fef3d74 | ||
|
|
fc48c1dd21 | ||
|
|
2d55d10d17 | ||
|
|
c2618088c6 | ||
|
|
08689a4013 | ||
|
|
cb5dc659f2 | ||
|
|
b4848b6db6 | ||
|
|
c279711120 | ||
|
|
4092b4f737 | ||
|
|
e31878bd7d | ||
|
|
6b4891a59f | ||
|
|
29c9fb812c | ||
|
|
274aa4fcce | ||
|
|
ed56b26cad | ||
|
|
d3d9b2f764 | ||
|
|
5affff5def | ||
|
|
9e7b6aa61d | ||
|
|
cd78442257 | ||
|
|
95eff67340 | ||
|
|
88b2bb51a3 | ||
|
|
6e4453c773 | ||
|
|
af6600de80 | ||
|
|
c20c8bc349 |
+1
-6
@@ -1,6 +1 @@
|
||||
/mutn
|
||||
/mutn.exe
|
||||
/main
|
||||
/main.exe
|
||||
/version.go
|
||||
1output
|
||||
*
|
||||
|
||||
@@ -1,48 +1,46 @@
|
||||

|
||||
---
|
||||
# MUTN Password Manager
|
||||
Pronounced as: "mutton", "muh·tn"
|
||||
|
||||
MUTN is a simple, self-hosted, SSH-synchronized password and note manager based on [libmutton](https://github.com/rwinkhart/libmutton). It is the successor to [sshyp](https://github.com/rwinkhart/sshyp).
|
||||
MUTN is a simple, self-hosted, SSH-synchronized password manager based on libmutton.
|
||||
|
||||
> [!WARNING]
|
||||
>It is your responsibility to assess the security and stability of MUTN and to ensure it meets your needs before using it.
|
||||
>I am not responsible for any data loss or breaches of your information resulting from the use of MUTN.
|
||||
>MUTN is a new project that is constantly being updated, and though safety and security are priorities, they cannot be guaranteed.
|
||||
MUTN is an expanded re-implementation of [sshyp](https://github.com/rwinkhart/sshyp) written in Go.
|
||||
|
||||
# Demo Tape
|
||||

|
||||
Though MUTN will feel very familiar to users of sshyp, it is intended to differ and will break entry compatibility before reaching a stable release.
|
||||
# WARNING
|
||||
It is your responsibility to assess the security and stability of MUTN and to ensure it meets your needs before using it.
|
||||
I am not responsible for any data loss or breaches of your information resulting from the use of MUTN.
|
||||
MUTN is a new project that is constantly being updated, and though safety and security are priorities, they cannot be guaranteed.
|
||||
|
||||
# Mission Statement
|
||||
MUTN aims to make it as easy as possible to manage passwords and notes via CLI across multiple devices in a secure, self-hosted fashion.
|
||||
MUTN aims to make it as simple as possible to manage passwords and notes via CLI across multiple devices in a secure, self-hosted fashion.
|
||||
|
||||
# Installation/Building
|
||||
See the [installation guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md).
|
||||
# Building
|
||||
MUTN is currently in early development and does not yet have online synchronization functionality (offline only).
|
||||
|
||||
Additionally, MUTN is available as a source package ("[mutn](https://aur.archlinux.org/packages/mutn)") on the AUR.
|
||||
|
||||
After installing, please review the [usage guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/usage.md).
|
||||
To build the current version of MUTN, simply clone this repository and run `go build` in its root directory.
|
||||
|
||||
# Roadmap
|
||||
#### Release v0.3.0
|
||||
- [ ] Replace Glamour with a more minimal Markdown renderer (likely custom)
|
||||
#### Release v0.4.0
|
||||
- [ ] libmutton v0.3.0
|
||||
- [ ] Swap to native (cascade) encryption (custom)
|
||||
- [ ] Implement "netpin" (quick-unlock) with new encryption
|
||||
#### Release v0.5.0
|
||||
- [ ] libmutton v0.4.0
|
||||
- [ ] Password aging support
|
||||
#### Release v0.6.0
|
||||
- [ ] libmutton v0.5.0
|
||||
- [ ] Add refresh/re-encrypt functionality
|
||||
- [ ] Re-implement init menu
|
||||
- [ ] Implement tweak menu
|
||||
#### Release v1.0.0
|
||||
- [ ] Create packaging scripts
|
||||
- [x] Stable source PKGBUILD
|
||||
- [ ] Stable source APKBUILD
|
||||
- [ ] Debian/Ubuntu
|
||||
- [ ] Fedora
|
||||
- [ ] FreeBSD
|
||||
- [ ] Windows installer
|
||||
- Hunt for polishing opportunities and bugs
|
||||
- Release v0.2.0 - No binaries
|
||||
- Crete server software
|
||||
- Add native sync (based on golang.org/x/crypto/ssh)
|
||||
- Update entry format with reserved space for TOTP
|
||||
- Release v0.2.1 - No binaries
|
||||
- Replace init with interactive ttyPod-based menu
|
||||
- Release v0.3.0 - Make repo public - x86_64_v1 binary
|
||||
- Swap to native encryption, consider making GPG optional or removing entirely
|
||||
- Release v0.4.0 - x86_64_v1 binary
|
||||
- Password aging support
|
||||
- Add password aging info to entry names
|
||||
- Make constant character count to easily trim for user interaction
|
||||
- Release v1.0.0 - Distribution packages (from here on out)
|
||||
- Perform extensive testing, fixing, and optimizing
|
||||
- Create artwork
|
||||
- Create manpage
|
||||
- Create packaging script
|
||||
- Release v1.1.0
|
||||
- Cascading encryption support
|
||||
- Release v1.2.0
|
||||
- Custom color scheme support
|
||||
- Release v1.3.0
|
||||
- Add build option for breaking markdown support and menus into separate binaries
|
||||
- Greatly reduces startup time
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/bin/sh
|
||||
gofmt -l -w -s ./src/cli/*.go ./mutn.go
|
||||
git commit -am "$1"
|
||||
gofmt -l -w -s ./src/cli/*.go
|
||||
gofmt -l -w -s ./src/backend/*.go
|
||||
git add -f extra src .gitignore commit.sh go.mod go.sum LICENSE main.go README.md
|
||||
git commit -m "$1"
|
||||
git push
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#compdef mutn
|
||||
|
||||
libmuttonEntryRoot="$HOME/.local/share/libmutton"
|
||||
libmuttonFullPaths=("$libmuttonEntryRoot"/**/*)
|
||||
libmuttonTrimmedPaths=()
|
||||
for scanPath in "${libmuttonFullPaths[@]}"; do
|
||||
# exclude directories
|
||||
[ -f "$scanPath" ] && libmuttonTrimmedPaths+=("${scanPath#$libmuttonEntryRoot}")
|
||||
done
|
||||
[[ -z $libmuttonTrimmedPaths ]] && libmuttonTrimmedPaths=(help)
|
||||
|
||||
case ${words[-2]} in
|
||||
mutn )
|
||||
compadd $libmuttonTrimmedPaths
|
||||
;;
|
||||
/* )
|
||||
compadd {copy,edit,gen,add,shear}
|
||||
;;
|
||||
add )
|
||||
compadd {password,note,folder}
|
||||
;;
|
||||
copy )
|
||||
compadd {password,username,totp,url,note}
|
||||
;;
|
||||
edit )
|
||||
compadd {password,username,totp,url,note,rename}
|
||||
;;
|
||||
gen )
|
||||
compadd update
|
||||
;;
|
||||
esac
|
||||
@@ -1,173 +0,0 @@
|
||||
.TH MUTN 1 "20 August 2024" "v0.2.2" "MUTN man page"
|
||||
|
||||
.SH NAME
|
||||
\fBmutn\fR - Simple, self-hosted, SSH-synchronized password and note management based on libmutton. It is the successor to sshyp.
|
||||
|
||||
.SH SYNOPSIS
|
||||
Usage: mutn [/<entry name> [argument] [option]] | [argument]
|
||||
|
||||
.SH DESCRIPTION
|
||||
mutn is a lightweight password, TOTP, and note management program for the CLI. MUTN is self-hosted with a client-server model and expects that you have access to a personal server with a properly configured SSH server.
|
||||
|
||||
.SH EXAMPLES
|
||||
Setting up MUTN for the first time:
|
||||
mutn init
|
||||
|
||||
Viewing the entry database:
|
||||
mutn
|
||||
|
||||
Reading an existing entry saved as '~/.local/share/libmutton/development/github':
|
||||
mutn /development/github
|
||||
|
||||
Reading the same entry without hiding the password:
|
||||
mutn /development/github show
|
||||
|
||||
Removing an existing folder saved as '~/.local/share/libmutton/social':
|
||||
mutn /social shear
|
||||
|
||||
Copying the password of an existing entry saved as '~/.local/share/libmutton/financial/bank':
|
||||
mutn /financial/bank copy
|
||||
|
||||
Copying the TOTP token of an existing entry saved as '~/.local/share/libmutton/financial/bank':
|
||||
mutn /financial/bank copy -t
|
||||
|
||||
Editing the username of an existing entry saved as '~/.local/share/libmutton/game':
|
||||
mutn /game edit -u
|
||||
|
||||
Making a new entry saved as '~/.local/share/libmutton/school/university' using the built-in password generator:
|
||||
mutn /school/university gen
|
||||
|
||||
Creating a note-only entry saved as '~/.local/share/libmutton/notes/test note':
|
||||
mutn /notes/test\ note add -n
|
||||
|
||||
Manually synchronizing entries with the server:
|
||||
mutn sync
|
||||
|
||||
.SH ARGUMENTS
|
||||
help Bring up the help menu
|
||||
version Display version and license information
|
||||
init Set up MUTN (generates libmutton.ini)
|
||||
copy Copy details of an entry to your clipboard
|
||||
edit Edit an existing entry
|
||||
gen Generate a new password
|
||||
add Add a new entry
|
||||
shear Delete an existing entry
|
||||
sync Manually sync the entry directory
|
||||
|
||||
.SH OPTIONS
|
||||
|
||||
copy:
|
||||
password|-pw|<blank> Copy the password in an entry to your clipboard
|
||||
username|-u Copy the username in an entry to your clipboard
|
||||
totp|-t Generate and copy the TOTP token for an entry to your clipboard
|
||||
url|-l Copy the URL in an entry to your clipboard
|
||||
note|-n Copy the first note line in an entry to your clipboard
|
||||
|
||||
edit:
|
||||
password|-pw Change the password in an entry
|
||||
username|-u Change the username in an entry
|
||||
totp|-t Change the TOTP secret in an entry
|
||||
url|-l Change the URL in an entry
|
||||
note|-n Change the note in an entry
|
||||
rename|-r Rename or relocate an entry
|
||||
|
||||
gen:
|
||||
update|-u Generate a password for an existing entry
|
||||
|
||||
add:
|
||||
password|-pw Add a password entry
|
||||
note|-n Add a note entry
|
||||
folder|-f Add a new folder for entries
|
||||
|
||||
.SH TIPS
|
||||
1. You can quickly read an entry with "mutn /<entry name>"
|
||||
|
||||
2. Type "mutn" (no arguments/options) to view a list of saved entries
|
||||
|
||||
3. Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help
|
||||
|
||||
4. Using "add", "edit", or "copy" without specifying an option (field) will default to "password"
|
||||
|
||||
.SH SETUP
|
||||
libmutton operates on a client-server model, and thus sync support requires you to have access to your own server (whether it be a physical home server or a cloud rental) with remote access via SSH.
|
||||
|
||||
For security reasons, libmutton deliberately does not support password-based SSH authentication; you must use key-based authentication to connect to your server (password-protected keys are also supported). You are responsible for setting up SSH connectivity on your own.
|
||||
|
||||
The libmutton server software is shipped as its own dedicated binary and must be installed on the server and configured with "libmuttonserver init".
|
||||
|
||||
Once this has been done, you may proceed with the client setup:
|
||||
1. Install MUTN
|
||||
2. Run "mutn init" and follow the prompts
|
||||
3. If you already have entries on the server, sync them using "mutn sync"
|
||||
4. Optionally, shell completions (Bash, ZSH, and PowerShell 7+) can be enabled with your shell's respective method
|
||||
|
||||
.SH TROUBLESHOOTING
|
||||
.B Clipboard not clearing:
|
||||
|
||||
The intended way for libmutton to interact with the system clipboard is for it to clear it 30 seconds after copying a field. Unfortunately, this does not work by default on all systems due to the prevalence of clipboard managers.
|
||||
|
||||
Clipboard managers save a history of what has been copied to the clipboard, which is already a big enough issue on its own for people who copy sensitive information to their clipboard. Some clipboard managers simply will not allow the clipboard to be empty and will replace its contents with the last copied item if you attempt to clear it. One such naughty clipboard manager is KDE Klipper, which comes packaged into KDE Plasma and is typically enabled by default on most distributions. Due to this behavior, KDE Klipper breaks libmutton's clipboard clearing functionality and should not be left enabled.
|
||||
|
||||
It is likely other popular clipboard managers exhibit this behavior.
|
||||
|
||||
.B Shell completions not working:
|
||||
ZSH:
|
||||
Make sure your ~/.zshrc contains the following (if sourcing from default completions location, usually /usr/share/zsh/functions/Completion/Unix/_mutn):
|
||||
|
||||
autoload -Uz compinit && compinit
|
||||
|
||||
...and then restart your shell.
|
||||
|
||||
Bash:
|
||||
Install your distribution's "bash-completion" package
|
||||
|
||||
OR
|
||||
|
||||
Source the completion script manually by adding the following to your ~/.bashrc (then restart your shell):
|
||||
|
||||
Linux:
|
||||
|
||||
source /usr/share/bash-completion/completions/mutn
|
||||
|
||||
FreeBSD:
|
||||
|
||||
source /usr/local/share/bash-completion/completions/mutn
|
||||
|
||||
...and then restart your shell.
|
||||
|
||||
Please note that Bash completions are slightly more limited than ZSH completions, and as such, new entries will not be auto-completed until the completions script is re-sourced.
|
||||
|
||||
PowerShell 7+:
|
||||
Currently, completions must be manually installed and sourced in your PowerShell profile as such:
|
||||
|
||||
. /path/to/mutn.ps1
|
||||
|
||||
...and then restart your shell.
|
||||
|
||||
.SH EXIT CODES (defined by libmutton)
|
||||
0: no error
|
||||
|
||||
101: read error
|
||||
|
||||
102: write error
|
||||
|
||||
103: sync process error
|
||||
|
||||
104: server connection error
|
||||
|
||||
105: target not found
|
||||
|
||||
106: target already exists
|
||||
|
||||
107: target wrong type (file/directory)
|
||||
|
||||
108: decryption error
|
||||
|
||||
109: encryption error
|
||||
|
||||
110: clipboard error
|
||||
|
||||
111: other error
|
||||
|
||||
.SH AUTHOR
|
||||
Randall Winkhart (https://github.com/rwinkhart)
|
||||
@@ -1,135 +0,0 @@
|
||||
**WARNING: AS LIBMUTTON HAS NOT YET REACHED v1.0.0, [BREAKING CHANGES](https://github.com/rwinkhart/libmutton/blob/main/wiki/breaking.md) IN FUTURE UPDATES ARE PLANNED**
|
||||
|
||||
**MUTN v0.2.2**
|
||||
Built with libmutton v0.2.2
|
||||
August 20, 2024
|
||||
|
||||
# The Tripe Transmission Update - Patch 2
|
||||
|
||||
This release updates libmutton to v0.2.2 to address a regression from v0.2.1. Additionally, a Windows-only entry adding bug has been fixed.
|
||||
|
||||
## Fixes
|
||||
- From libmutton v0.2.1:
|
||||
- Edited entries are no longer improperly synced if their line count is reduced
|
||||
- (8c1b986e20bf8e02b4b27e18748f7677be2b2743) Adding new entries from Windows now works as intended
|
||||
|
||||
## Dependencies
|
||||
- Bumps (direct and indirect)
|
||||
- github.com/rwinkhart/libmutton: v0.2.1 => v0.2.2
|
||||
|
||||
---
|
||||
|
||||
**MUTN v0.2.1**
|
||||
Built with libmutton v0.2.1
|
||||
August 13, 2024
|
||||
|
||||
# The Tripe Transmission Update - Patch 1
|
||||
|
||||
This release marks the completion of splitting MUTN and [libmutton](https://github.com/rwinkhart/libmutton) into separate repositories. The server binary must now be downloaded from the [libmutton releases page](https://github.com/rwinkhart/libmutton/releases).
|
||||
|
||||
Please see the [installation guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md) for updated instructions.
|
||||
|
||||
## Breaking Changes
|
||||
- The server binary must also be updated to v0.2.1 (grab it [here](https://github.com/rwinkhart/libmutton/releases/tag/v0.2.1))
|
||||
|
||||
## Features
|
||||
- From libmutton v0.2.1:
|
||||
- MUTN will now remove the previous device ID from the server when creating a new one
|
||||
- Exit codes are now specific to the type of error encountered
|
||||
|
||||
## Fixes
|
||||
- From libmutton v0.2.1:
|
||||
- The user is no longer prompted for their ssh keyfile passphrase multiple times during synchronization
|
||||
- Config/entry files are now created with 0600 permissions
|
||||
- The TOTP copy message is no longer unnecessarily verbose
|
||||
- Function documentation is now properly formatted for display on pkg.go.dev
|
||||
|
||||
## Dependencies
|
||||
- Bumps (direct and indirect)
|
||||
- golang.org/x/sys: v0.23.0 => v0.24.0
|
||||
- New (direct)
|
||||
- github.com/rwinkhart/libmutton: v0.2.1
|
||||
- Was previously included in this repo
|
||||
|
||||
---
|
||||
|
||||
**MUTN v0.2.0**
|
||||
August 06, 2024
|
||||
|
||||
# The Tripe Transmission Update
|
||||
|
||||
This release marks the public debut of MUTN and its underlying library, libmutton.
|
||||
|
||||
Compared to v0.1.0, this version adds fully native SSH synchronization with self-hosted servers. It also makes tweaks to the entry format to better integrate TOTP support. The full patch notes are below.
|
||||
|
||||
## Breaking Changes
|
||||
#### Given MUTN was not public prior to this release, these should not affect anyone and are listed purely for historical documentation
|
||||
- (67bf6e42b9c623f24d9547d822ea4d2fd45002d1) TOTP secrets now have their own dedicated entry field, meaning entries from v0.1.0 are not compatible
|
||||
- Various changes have been made to libmutton.ini (re-generating it with `mutn init` is needed)
|
||||
|
||||
## Features
|
||||
- Native SSH sync support with self-hosted servers
|
||||
- Replaces sshyp-based partial sync implementation, requires libmuttonserver)
|
||||
- (ea34f644f31ff871d8766d3971dac5eed5bb2c3b) MUTN/libmutton can now be built for WSL with working clipboard support
|
||||
- Build tag: `wsl`
|
||||
- (356d1eab4e4cd0c68db9bd9aa0d3164c13cd254f) libmutton can now be built to allow functions to exit the program (desirable for CLI) or return (desirable for GUI/TUI)
|
||||
- Build tag: `returnOnExit`
|
||||
- (cbf625b2d3b8a18d1f7e3214e065b5baa1dc0829) MUTN can now be built without Markdown support
|
||||
- Build tag: `noMarkdown`
|
||||
- Reduces the binary size by more than half and greatly reduces startup time (because of this, Glamour is likely to be replaced with a different Markdown renderer in the future)
|
||||
- (f0cdd217d958109f36a0e8a7048a5d73b7f68a96) PowerShell completions now also work on non-Windows platforms
|
||||
- (2ae4fe19e84d9beacfc616c9aa4fe9c166d28003) (e81bfa935a1f461edf2171f99f37ac2794a928e8) It is now possible for third-party clients to store and retrieve data from arbitrary section headers in libmutton.ini
|
||||
|
||||
## Fixes
|
||||
- Several previously unhandled errors are not handled properly
|
||||
- sync/client.go is the last to have not received this treatment (coming in v0.2.1)
|
||||
- PowerShell completions can now complete after directories containing spaces
|
||||
- (0fc0a2cfc09289271bc90a292fa7f40289a35294) Bash and ZSH completions no longer declare generically named global variables that could conflict with other software
|
||||
- (43d87a5b464b997b7f719b71626d62840e385333) "-v" and "-h" shortcuts (for "version" and "help", respectively) have been removed to prevent ambiguity in PowerShell
|
||||
- (df5f10d188b80a17eeed48961c4e64c90166f7e6) ANSI escapes are no longer intermittently dumped to the terminal on Windows
|
||||
- (35192fa568010a72f49536197115081b00b4f0da) MUTN will no longer wait for you to fill out the contents of a new entry before telling you its location is invalid
|
||||
- (b7a470116ab90b327d16e96e9576f002eeea2902) MUTN no longer announces the copying of TOTP codes until the entry has been successfully decrypted
|
||||
|
||||
## Dependencies
|
||||
- Bumps (direct and indirect)
|
||||
- Go: v1.22.2 => v1.22.6
|
||||
- golang.org/x/crypto: v0.22.0 => v0.26.0
|
||||
- golang.org/x/term: v0.19.0 => v0.23.0
|
||||
- github.com/alecthomas/chroma/v2: v2.13.0 => v2.14.0
|
||||
- github.com/boombuler/barcode: v1.0.1 => v1.0.2
|
||||
- github.com/dlclark/regexp2: v1.11.0 => v1.11.4
|
||||
- github.com/mattn/go-runewidth: v0.0.15 => v0.0.16
|
||||
- github.com/microcosm-cc/bluemonday: v1.0.26 => v1.0.27
|
||||
- github.com/yuin/goldmark: v1.7.1 => v1.7.4
|
||||
- github.com/yuin/goldmark-emoji: v1.0.2 => v1.0.3
|
||||
- golang.org/x/net: v0.24.0 => v0.28.0
|
||||
- golang.org/x/sys: v0.19.0 => v0.23.0
|
||||
- New (direct)
|
||||
- github.com/pkg/sftp: v1.13.6
|
||||
|
||||
## Installation Notes
|
||||
Though this is the initial public debut, it is still an overall early release of MUTN/libmutton. Because of this, no distribution packages are provided as of yet. MUTN is, however, available as a source package from the AUR as "mutn". Please see the [install guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/install.md) for help installing or building MUTN in its current state (as well as getting started).
|
||||
|
||||
Note that libmuttonserver, libmutton, and MUTN have not yet been separated into their own respective repos (this will be done for v0.2.1). As such, libmuttonserver is built with the `noMarkdown` build tag to avoid pulling in Glamour and its dependencies.
|
||||
|
||||
It is highly recommended to also install the relevant [shell completions](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md).
|
||||
|
||||
---
|
||||
|
||||
**MUTN v0.1.0**
|
||||
April 16, 2024
|
||||
|
||||
# The Butchered Update
|
||||
|
||||
This is the first tagged release of MUTN.
|
||||
|
||||
It is a mostly complete implementation of MUTN's offline functionality.
|
||||
|
||||
It supports basic online synchronization if [sshyp](https://github.com/rwinkhart/sshyp) is also installed and configured (UNIX-based systems only).
|
||||
|
||||
**Breaking changes will be made after this release, including, but not limited to:**
|
||||
- GPG will be replaced as the default encryption method
|
||||
- The entry format will be adjusted to contain a dedicated field for TOTP secrets
|
||||
- sshyp-based synchronization will be replaced with a native implementation
|
||||
|
||||
**No pre-compiled binaries or distribution packages will be published for this release.**
|
||||
@@ -1,16 +1,16 @@
|
||||
# mutn(1) completion
|
||||
|
||||
_path_gen() {
|
||||
local entryRoot="$HOME/.local/share/libmutton"
|
||||
local mutnPath="$HOME/.local/share/libmutton"
|
||||
local globStatus=$(shopt -p globstar)
|
||||
[ -z "${globStatus##*u*}" ] && shopt -s globstar # if recursive globbing is disabled, enable it
|
||||
local fullPaths=("$entryRoot"/**/*)
|
||||
local fullPaths=("$mutnPath"/**/*)
|
||||
$globStatus # set recursive globbing to user default
|
||||
for scanPath in "${fullPaths[@]}"; do
|
||||
# exclude directories
|
||||
[ -f "$scanPath" ] && libmuttonTrimmedPaths+=("${scanPath#$entryRoot}")
|
||||
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
|
||||
done
|
||||
if [ "${libmuttonTrimmedPaths[0]}" == '' ]; then libmuttonTrimmedPaths[0]=help; fi
|
||||
if [ "${trimmedPaths[0]}" == '' ]; then trimmedPaths[0]=help; fi
|
||||
} &&
|
||||
|
||||
_mutnCompletions() {
|
||||
@@ -19,7 +19,7 @@ _mutnCompletions() {
|
||||
|
||||
case $prev in
|
||||
mutn )
|
||||
while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${libmuttonTrimmedPaths[@]}")" -- "$cur" )
|
||||
while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${trimmedPaths[@]}")" -- "$cur" )
|
||||
;;
|
||||
/* )
|
||||
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "copy edit gen add shear" -- "$cur" )
|
||||
@@ -31,7 +31,7 @@ _mutnCompletions() {
|
||||
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password username totp url note" -- "$cur" )
|
||||
;;
|
||||
edit )
|
||||
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password username totp url note rename" -- "$cur" )
|
||||
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password username url note rename" -- "$cur" )
|
||||
;;
|
||||
gen )
|
||||
while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "update" -- "$cur" )
|
||||
@@ -1,23 +1,15 @@
|
||||
if (!$IsWindows) {
|
||||
# since the executable has the same name as the completion function (on non-Windows platforms), its path must be stored before the function is registered
|
||||
$MUTNExecutablePath = (Get-Command mutn).Path
|
||||
}
|
||||
|
||||
function cliMUTNEntryCompleter {
|
||||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
|
||||
if ($IsWindows) {
|
||||
$entryRoot = (Resolve-Path '~\AppData\Local\libmutton\entries').Path
|
||||
} else {
|
||||
$entryRoot = (Resolve-Path '~/.local/share/libmutton').Path
|
||||
}
|
||||
#$mutnPath = (Resolve-Path '~/.local/share/libmutton').Path # UNIX testing
|
||||
$mutnPath = (Resolve-Path '~/AppData/Local/libmutton/entries').Path
|
||||
try {
|
||||
$trimmedPaths = If (Test-Path $entryRoot) {
|
||||
(Get-ChildItem -Path $entryRoot -Recurse -File).FullName.Substring($entryRoot.Length) -replace '\\', '/' -replace ' ', [char]0x259d
|
||||
$trimmedPaths = If (Test-Path $mutnPath) {
|
||||
(Get-ChildItem -Path $mutnPath -Recurse -File).FullName.Substring($mutnPath.Length) -replace '\\', '/' -replace ' ', '` '
|
||||
}
|
||||
} catch {
|
||||
$trimmedPaths = $null # if any errors occur (especially, "You cannot call a method on a null-valued expression", set $trimmedPaths to $null
|
||||
$trimmedPaths = $null # If any errors occur (especially, "You cannot call a method on a null-valued expression", set $trimmedPaths to $null
|
||||
}
|
||||
if ($null -eq $trimmedPaths) { # if no entries are found, add 'help' to $trimmedPaths
|
||||
if ($null -eq $trimmedPaths) { # If no entries are found, add 'help' to $trimmedPaths
|
||||
$trimmedPaths = 'help'
|
||||
}
|
||||
$trimmedPaths | Where-Object { $_ -like "$wordToComplete*" }
|
||||
@@ -29,7 +21,7 @@ function cliMUTNOptionCompleter {
|
||||
$possibleValues = @{
|
||||
add = @('password', 'note', 'folder')
|
||||
copy = @('password', 'username', 'totp', 'url', 'note')
|
||||
edit = @('password', 'username', 'totp', 'url', 'note', 'rename')
|
||||
edit = @('password', 'username', 'url', 'note', 'rename')
|
||||
gen = @('update')
|
||||
}
|
||||
|
||||
@@ -58,9 +50,6 @@ function mutn {
|
||||
[string]$option
|
||||
)
|
||||
|
||||
if ($IsWindows) {
|
||||
Invoke-Expression -Command ('mutn.exe ' + ($entry -replace ' ', '` ' -replace [char]0x259d, '` '), $argument, $option).Trim()
|
||||
} else {
|
||||
Invoke-Expression -Command ($MUTNExecutablePath + ' ' + ($entry -replace ' ', '` ' -replace [char]0x259d, '` '), $argument, $option).Trim()
|
||||
}
|
||||
#Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, $option).Trim() # UNIX testing
|
||||
Invoke-Expression -Command ('./mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option).Trim()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#compdef mutn
|
||||
|
||||
mutnPath="$HOME/.local/share/libmutton"
|
||||
fullPaths=("$mutnPath"/**/*)
|
||||
trimmedPaths=()
|
||||
for scanPath in "${fullPaths[@]}"; do
|
||||
# exclude directories
|
||||
[ -f "$scanPath" ] && trimmedPaths+=("${scanPath#$mutnPath}")
|
||||
done
|
||||
[[ -z $trimmedPaths ]] && trimmedPaths=(help)
|
||||
|
||||
case ${words[-2]} in
|
||||
mutn )
|
||||
compadd $trimmedPaths
|
||||
;;
|
||||
/* )
|
||||
compadd {copy,edit,gen,add,shear}
|
||||
;;
|
||||
add )
|
||||
compadd {password,note,folder}
|
||||
;;
|
||||
copy )
|
||||
compadd {password,username,totp,url,note}
|
||||
;;
|
||||
edit )
|
||||
compadd {password,username,url,note,rename}
|
||||
;;
|
||||
gen )
|
||||
compadd update
|
||||
;;
|
||||
esac
|
||||
@@ -1,37 +1,34 @@
|
||||
module github.com/rwinkhart/MUTN
|
||||
|
||||
go 1.22.6
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/glamour v0.7.0
|
||||
github.com/rwinkhart/libmutton v0.2.2
|
||||
golang.org/x/term v0.23.0
|
||||
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727
|
||||
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481
|
||||
golang.org/x/crypto v0.22.0
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 // indirect
|
||||
github.com/alecthomas/chroma/v2 v2.13.0 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/aymerick/douceur v0.2.0 // indirect
|
||||
github.com/boombuler/barcode v1.0.2 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
||||
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 // indirect
|
||||
github.com/boombuler/barcode v1.0.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.0 // indirect
|
||||
github.com/gorilla/css v1.0.1 // indirect
|
||||
github.com/kr/fs v0.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
|
||||
github.com/muesli/reflow v0.3.0 // indirect
|
||||
github.com/muesli/termenv v0.15.2 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/pkg/sftp v1.13.6 // indirect
|
||||
github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
github.com/yuin/goldmark v1.7.4 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.3 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
github.com/yuin/goldmark v1.7.1 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.2 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/term v0.19.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE=
|
||||
github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
|
||||
github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I=
|
||||
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
|
||||
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||
github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI=
|
||||
github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk=
|
||||
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
|
||||
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
@@ -9,41 +9,37 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boombuler/barcode v1.0.2 h1:79yrbttoZrLGkL/oOI8hBrUKucwOL0oOjUgEguGMcJ4=
|
||||
github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
|
||||
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
|
||||
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
|
||||
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 h1:1RkPJqfzrncAuh9xgoslr9OplZskm+VRA9lkucHPQZ4=
|
||||
github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727/go.mod h1:wRAWHbTlpt0C4kwnKoa42L2Phrv6uIq+c50P2uKpb7I=
|
||||
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
|
||||
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
|
||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
|
||||
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
|
||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
|
||||
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
|
||||
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pkg/sftp v1.13.6 h1:JFZT4XbOU7l77xGSpOdW+pwIMqP044IyjXX6FGyEKFo=
|
||||
github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Qk=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
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=
|
||||
@@ -52,60 +48,25 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rwinkhart/libmutton v0.2.2 h1:PN3VaM8IiKy6Ea2dfyTQxwyNeIu00CZ2vsgVZESrcvU=
|
||||
github.com/rwinkhart/libmutton v0.2.2/go.mod h1:W4xYquN2Hz5rNyaaIUZCMTLvTNcAx804f1Y4vaUBmiw=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
|
||||
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
|
||||
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhbIQY4=
|
||||
github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s=
|
||||
github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
|
||||
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
|
||||
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
+27
-25
@@ -2,12 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"github.com/rwinkhart/MUTN/src/cli"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/MUTN/src/cli"
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -25,20 +23,20 @@ func main() {
|
||||
if strings.HasPrefix(args[1], "/") {
|
||||
|
||||
// store location of target entry
|
||||
targetLocation := core.TargetLocationFormat(args[1])
|
||||
targetLocation := backend.TargetLocationFormat(args[1][1:])
|
||||
|
||||
// entry reader shortcut (if no other arguments are supplied)
|
||||
if argsCount == 2 {
|
||||
cli.EntryReaderDecrypt(targetLocation, true)
|
||||
cli.EntryReaderDecrypt(targetLocation, true, false)
|
||||
|
||||
// perform other operations on the entry (if other arguments are supplied)
|
||||
} else if argsCount == 3 || (argsCount == 4 && (args[3] == "show" || args[3] == "-s")) {
|
||||
if argsCount == 3 { // default to "password" if no field is specified (for copy, edit, and add)
|
||||
switch args[2] {
|
||||
case "show", "-s":
|
||||
cli.EntryReaderDecrypt(targetLocation, false)
|
||||
cli.EntryReaderDecrypt(targetLocation, false, false)
|
||||
case "copy":
|
||||
core.CopyArgument(args[0], targetLocation, 0)
|
||||
backend.CopyArgument(targetLocation, 0, args[0])
|
||||
case "edit":
|
||||
cli.EditEntryField(targetLocation, true, 0)
|
||||
case "gen":
|
||||
@@ -46,7 +44,7 @@ func main() {
|
||||
case "add":
|
||||
cli.AddEntry(targetLocation, true, 0)
|
||||
case "shear":
|
||||
sync.ShearRemoteFromClient(args[1]) // pass the incomplete path as the server and all clients (reading from the deletions directory) will have a different home directory
|
||||
backend.Shear(targetLocation)
|
||||
default:
|
||||
cli.HelpMain()
|
||||
}
|
||||
@@ -73,16 +71,17 @@ func main() {
|
||||
field = 0
|
||||
case "username", "-u":
|
||||
field = 1
|
||||
case "totp", "-t":
|
||||
field = 2
|
||||
case "url", "-l":
|
||||
field = 3
|
||||
field = 2
|
||||
case "note", "-n":
|
||||
field = 4
|
||||
field = 3
|
||||
case "totp", "-t":
|
||||
fmt.Println("TOTP code will be copied to clipboard - your clipboard will be kept up to date with the current TOTP code until this process is closed")
|
||||
field = 5 // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||
default:
|
||||
cli.HelpCopy()
|
||||
}
|
||||
core.CopyArgument(args[0], targetLocation, field)
|
||||
backend.CopyArgument(targetLocation, field, args[0])
|
||||
case "edit":
|
||||
var field int // indicates which (numbered) field to edit
|
||||
switch args[3] {
|
||||
@@ -90,15 +89,12 @@ func main() {
|
||||
field = 0
|
||||
case "username", "-u":
|
||||
field = 1
|
||||
case "totp", "-t":
|
||||
field = 2
|
||||
case "url", "-l":
|
||||
field = 3
|
||||
field = 2
|
||||
case "note", "-n":
|
||||
field = 4
|
||||
field = 3
|
||||
case "rename", "-r":
|
||||
core.TargetIsFile(targetLocation, true, 0) // ensure location exists before prompting for new location
|
||||
cli.RenameCli(args[1]) // pass the incomplete path as the server and all clients (reading from the deletions directory) will have a different home directory
|
||||
cli.RenameCli(targetLocation)
|
||||
default:
|
||||
cli.HelpEdit()
|
||||
}
|
||||
@@ -145,7 +141,7 @@ func main() {
|
||||
case "note", "-n":
|
||||
cli.AddEntry(targetLocation, true, 2)
|
||||
case "folder", "-f":
|
||||
sync.AddFolderRemoteFromClient(args[1]) // pass the incomplete path as the server will have a different home directory
|
||||
backend.AddFolder(targetLocation)
|
||||
default:
|
||||
cli.HelpAdd()
|
||||
}
|
||||
@@ -158,14 +154,20 @@ func main() {
|
||||
} else {
|
||||
switch args[1] {
|
||||
case "clipclear":
|
||||
core.ClipClearArgument()
|
||||
backend.ClipClearArgument()
|
||||
case "sync":
|
||||
sync.RunJob(true)
|
||||
if !backend.Windows {
|
||||
cli.SshypSync() // TODO Remove after native sync is implemented
|
||||
} else {
|
||||
fmt.Println(backend.AnsiError + "\"sync\" is not yet implemented" + backend.AnsiReset)
|
||||
}
|
||||
os.Exit(0)
|
||||
case "init":
|
||||
cli.TempInitCli()
|
||||
case "tweak":
|
||||
fmt.Println(core.AnsiError + "\"tweak\" is not yet implemented" + core.AnsiReset)
|
||||
fmt.Println(backend.AnsiError + "\"tweak\" is not yet implemented" + backend.AnsiReset)
|
||||
os.Exit(0)
|
||||
// TODO backend.Tweak()
|
||||
case "copy":
|
||||
cli.HelpCopy()
|
||||
case "edit":
|
||||
@@ -174,7 +176,7 @@ func main() {
|
||||
cli.HelpGen()
|
||||
case "add":
|
||||
cli.HelpAdd()
|
||||
case "version":
|
||||
case "version", "-v":
|
||||
cli.Version()
|
||||
default:
|
||||
cli.HelpMain()
|
||||
@@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# get version number from cli package
|
||||
cd ..
|
||||
printf 'package main\nimport (\n"fmt"\n"github.com/rwinkhart/MUTN/src/cli"\n)\nfunc main() {\nfmt.Println(cli.MUTNVersion)\n}' > ./version.go
|
||||
version=$(go run -ldflags="-s -w" -tags noMarkdown ./version.go)
|
||||
rm ./version.go
|
||||
cd ./packaging
|
||||
|
||||
# get revision number from user input, fallback to 1 if not provided
|
||||
if [ -z "$2" ]; then
|
||||
revision=1
|
||||
else
|
||||
revision="$2"
|
||||
fi
|
||||
|
||||
# ensure output directory exists
|
||||
mkdir -p ./1output
|
||||
|
||||
case "$1" in
|
||||
release-binaries)
|
||||
. ./resources/release-binaries.sh
|
||||
create_release_binaries
|
||||
;;
|
||||
pkgbuild-git-stable)
|
||||
. ./resources/pkgbuild-git-stable.sh
|
||||
create_pkgbuild_git_stable
|
||||
;;
|
||||
*)
|
||||
printf '\nusage: package.sh [target] <revision>\n\ntargets: release-binaries pkgbuild-git-stable\n\n'
|
||||
;;
|
||||
esac
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
create_pkgbuild_git_stable() {
|
||||
printf '\nGenerating PKGBUILD...\n'
|
||||
local source="git+https://github.com/rwinkhart/MUTN.git#tag=v\${pkgver}"
|
||||
printf "# Maintainer: Randall Winkhart <idgr at tutanota dot com>
|
||||
pkgname=mutn
|
||||
pkgver="$version"
|
||||
pkgrel="$revision"
|
||||
pkgdesc='A simple, self-hosted, SSH-synchronized password/note manager for the CLI (based on libmutton)'
|
||||
arch=('x86_64' 'i686' 'i486' 'pentium4' 'aarch64' 'armv7h' 'riscv64')
|
||||
url='https://github.com/rwinkhart/MUTN'
|
||||
license=('MIT')
|
||||
makedepends=(go util-linux gzip)
|
||||
optdepends=(
|
||||
'wl-clipboard: Wayland clipboard support'
|
||||
'xclip: X11 clipboard support'
|
||||
'bash-completion: Bash completion support'
|
||||
)
|
||||
source=(\""$source"\")
|
||||
sha512sums=(SKIP)
|
||||
|
||||
build() {
|
||||
cd \${srcdir}/MUTN
|
||||
|
||||
# compress man page
|
||||
gzip -kf ./docs/man
|
||||
|
||||
# determine microarchitecture feature level
|
||||
case \$CARCH in
|
||||
'x86_64')
|
||||
lscpuOutput=\$(lscpu | grep Flags)
|
||||
if [ ! -z \"\$(echo \$lscpuOutput | grep avx512f)\" ]; then
|
||||
export GOAMD64=v4
|
||||
elif [ ! -z \"\$(echo \$lscpuOutput | grep avx2)\" ]; then
|
||||
export GOAMD64=v3
|
||||
elif [ ! -z \"\$(echo \$lscpuOutput | grep sse4_2)\" ]; then
|
||||
export GOAMD64=v2
|
||||
else
|
||||
export GOAMD64=v1
|
||||
fi
|
||||
;;
|
||||
# TODO check aarch64 feature level
|
||||
esac
|
||||
|
||||
# compile binary
|
||||
CGO_ENABLED=1 go build -ldflags=\"-s -w\" -trimpath ./mutn.go
|
||||
}
|
||||
|
||||
package() {
|
||||
cd \${srcdir}/MUTN
|
||||
install -Dm755 ./mutn \${pkgdir}/usr/bin/mutn
|
||||
install -Dm644 ./LICENSE \${pkgdir}/usr/share/licenses/mutn/LICENSE
|
||||
install -Dm644 ./completions/zsh/_mutn \${pkgdir}/usr/share/zsh/site-functions/_mutn
|
||||
install -Dm644 ./completions/bash/mutn \${pkgdir}/usr/share/bash-completion/completions/mutn
|
||||
install -Dm644 ./docs/man.gz \${pkgdir}/usr/share/man/man1/mutn.1.gz
|
||||
}
|
||||
" > 1output/PKGBUILD
|
||||
printf '\nPKGBUILD generated\n\n'
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
create_release_binaries() {
|
||||
printf '\nGenerating release binaries...\n'
|
||||
cd ..
|
||||
GOOS=linux CGO_ENABLED=0 GOAMD64=v1 go build -o ./packaging/1output/mutn-linux-x86_64_v1 -ldflags="-s -w" -trimpath ./mutn.go
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o ./packaging/1output/mutn-linux-aarch64 -ldflags="-s -w" -trimpath ./mutn.go
|
||||
GOOS=windows CGO_ENABLED=0 GOAMD64=v1 go build -o ./packaging/1output/mutn-windows-x86_64_v1.exe -ldflags="-s -w" -trimpath ./mutn.go
|
||||
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -o ./packaging/1output/mutn-windows-aarch64.exe -ldflags="-s -w" -trimpath ./mutn.go
|
||||
cd ./packaging
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// global variables used across multiple files
|
||||
var (
|
||||
home, _ = os.UserHomeDir()
|
||||
)
|
||||
|
||||
// global constants used across multiple files
|
||||
const (
|
||||
AnsiError = "\033[38;5;9m"
|
||||
AnsiReset = "\033[0m"
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
//go:build !windows
|
||||
|
||||
package backend
|
||||
|
||||
// EntryRoot path to libmutton entry directory
|
||||
var EntryRoot = home + "/.local/share/libmutton"
|
||||
var ConfigDir = home + "/.config/libmutton"
|
||||
var ConfigPath = ConfigDir + "/libmutton.ini"
|
||||
|
||||
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
||||
const (
|
||||
PathSeparator = "/"
|
||||
Windows = false // TODO temporary, remove after native sync is implemented
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
//go:build windows
|
||||
|
||||
package backend
|
||||
|
||||
// EntryRoot path to libmutton entry directory
|
||||
var EntryRoot = home + "\\AppData\\Local\\libmutton\\entries"
|
||||
var ConfigDir = home + "\\AppData\\Local\\libmutton"
|
||||
var ConfigPath = ConfigDir + "\\libmutton.ini"
|
||||
|
||||
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
||||
const (
|
||||
PathSeparator = "\\"
|
||||
Windows = true // TODO temporary, remove after native sync is implemented
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// AddFolder creates a new directory at targetLocation
|
||||
func AddFolder(targetLocation string) {
|
||||
// create the directory specified by targetLocation
|
||||
err := os.Mkdir(targetLocation, 0700)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
fmt.Println(AnsiError + "Directory already exists" + AnsiReset)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Println(AnsiError + "Failed to create directory: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
// TODO If in online mode, create the directory on the server
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/ini.v1"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ReadConfig reads the libmutton.ini file and returns a map of the requested values
|
||||
// requires readMap: a map of section names to key names (indicates requested values)
|
||||
// returns configMap: a map of key names to values (sections are irrelevant)
|
||||
func ReadConfig(readKeys []string) []string {
|
||||
cfg, err := ini.Load(ConfigPath)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to load libmutton.ini" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var config []string
|
||||
|
||||
for _, key := range readKeys {
|
||||
keyConfig := cfg.Section("LIBMUTTON").Key(key).String()
|
||||
|
||||
// ensure specified key has a value
|
||||
if keyConfig == "" {
|
||||
fmt.Println(AnsiError + "Failed to find value for key \"" + key + "\" in section \"[LIBMUTTON]\" in libmutton.ini" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
config = append(config, keyConfig)
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
// libmuttn.ini layout
|
||||
// [LIBMUTTON]
|
||||
// gpgID = <gpg key id>
|
||||
// textEditor = <editor command>
|
||||
// onlineMode = <true/false>
|
||||
// sshError = <true/false>
|
||||
// netPinEnabled = <true/false>
|
||||
// remoteUser = <ssh user>
|
||||
// remoteIP = <ssh ip>
|
||||
// remotePort = <ssh port>
|
||||
// identityFile = <path to private key>
|
||||
@@ -0,0 +1,88 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
steamtotp "github.com/fortis/go-steam-totp"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CopyArgument copies a field from an entry to the clipboard
|
||||
func CopyArgument(targetLocation string, field int, executableName string) {
|
||||
if isFile, _ := TargetIsFile(targetLocation, true, 2); isFile {
|
||||
|
||||
decryptedEntry := DecryptGPG(targetLocation)
|
||||
var copySubject string // will store data to be copied
|
||||
|
||||
// ensure field exists in entry
|
||||
if len(decryptedEntry) > field {
|
||||
|
||||
// ensure field is not empty
|
||||
if decryptedEntry[field] == "" {
|
||||
fmt.Println(AnsiError + "Field is empty" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if field != 5 { // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||
copySubject = decryptedEntry[field]
|
||||
} else { // TOTP mode
|
||||
var secret string // stores secret for TOTP generation
|
||||
var forSteam bool // indicates whether to generate TOTP in Steam format
|
||||
|
||||
if strings.HasPrefix(decryptedEntry[5], "steam@") {
|
||||
secret = decryptedEntry[5][6:]
|
||||
forSteam = true
|
||||
} else {
|
||||
secret = decryptedEntry[5]
|
||||
}
|
||||
|
||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
||||
currentTime := time.Now()
|
||||
copyField(GenTOTP(secret, currentTime, forSteam), "")
|
||||
// sleep until next 30-second interval
|
||||
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println(AnsiError + "Field does not exist in entry" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// copy field to clipboard, launch clipboard clearing process
|
||||
copyField(copySubject, executableName)
|
||||
}
|
||||
}
|
||||
|
||||
// ClipClearArgument is called to clear the clipboard after 30 seconds if the contents have not been modified
|
||||
func ClipClearArgument() {
|
||||
// read previous clipboard contents from stdin
|
||||
clipScanner := bufio.NewScanner(os.Stdin)
|
||||
if clipScanner.Scan() {
|
||||
oldContents := clipScanner.Text()
|
||||
clipClear(oldContents)
|
||||
} else {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP)
|
||||
func GenTOTP(secret string, time time.Time, forSteam bool) string {
|
||||
var totpToken string
|
||||
var err error
|
||||
|
||||
if forSteam {
|
||||
totpToken, err = steamtotp.GenerateAuthCode(secret, time)
|
||||
} else {
|
||||
totpToken, err = totp.GenerateCode(secret, time)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return totpToken
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//go:build darwin
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO MacOS support is entirely untested - I would appreciate feedback on this implementation
|
||||
|
||||
// copyField copies a field from an entry to the clipboard
|
||||
func copyField(copySubject string, executableName string) {
|
||||
cmd := exec.Command("pbcopy")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// launch clipboard clearing process if executableName is provided
|
||||
if executableName != "" {
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
// clipClear is called in a separate process to clear the clipboard after 30 seconds
|
||||
func clipClear(oldContents string) {
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
cmd := exec.Command("pbpaste")
|
||||
newContents, _ := cmd.Output()
|
||||
|
||||
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
cmd = exec.Command("pbcopy")
|
||||
writeToStdin(cmd, "")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//go:build termux
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// copyField copies a field from an entry to the clipboard
|
||||
func copyField(copySubject string, executableName string) {
|
||||
cmd := exec.Command("termux-clipboard-set")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// launch clipboard clearing process if executableName is provided
|
||||
if executableName != "" {
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
// clipClear is called in a separate process to clear the clipboard after 30 seconds
|
||||
func clipClear(oldContents string) {
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
cmd := exec.Command("termux-clipboard-get")
|
||||
newContents, _ := cmd.Output()
|
||||
|
||||
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
cmd = exec.Command("termux-clipboard-set")
|
||||
writeToStdin(cmd, "")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//go:build !windows && !darwin && !termux
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// copyField copies a field from an entry to the clipboard
|
||||
func copyField(copySubject string, executableName string) {
|
||||
var envSet bool // track whether environment variables are set
|
||||
var cmd *exec.Cmd
|
||||
// determine whether to use wl-copy (Wayland) or xclip (X11)
|
||||
if _, envSet = os.LookupEnv("WAYLAND_DISPLAY"); envSet {
|
||||
cmd = exec.Command("wl-copy")
|
||||
} else if _, envSet = os.LookupEnv("DISPLAY"); envSet {
|
||||
cmd = exec.Command("xclip", "-sel", "c")
|
||||
} else {
|
||||
fmt.Println(AnsiError + "Clipboard platform could not be determined - note that the clipboard does not function in a raw TTY" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
writeToStdin(cmd, copySubject)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// launch clipboard clearing process if executableName is provided
|
||||
if executableName != "" {
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
// clipClear is called in a separate process to clear the clipboard after 30 seconds
|
||||
func clipClear(oldContents string) {
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
var envSet bool // track whether environment variables are set
|
||||
var platform bool // track clipboard platform, false for Wayland, true for X11
|
||||
var cmd *exec.Cmd
|
||||
// determine whether to use wl-copy (Wayland) or xclip (X11)
|
||||
if _, envSet = os.LookupEnv("WAYLAND_DISPLAY"); envSet {
|
||||
cmd = exec.Command("wl-paste")
|
||||
} else if _, envSet = os.LookupEnv("DISPLAY"); envSet {
|
||||
cmd = exec.Command("xclip", "-o", "-sel", "c")
|
||||
platform = true
|
||||
}
|
||||
newContents, _ := cmd.Output()
|
||||
|
||||
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
switch platform {
|
||||
case false:
|
||||
cmd = exec.Command("wl-copy", "-c")
|
||||
case true:
|
||||
cmd = exec.Command("xclip", "-i", "/dev/null", "-sel", "c")
|
||||
}
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//go:build windows
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// copyField copies a field from an entry to the clipboard
|
||||
func copyField(copySubject string, executableName string) {
|
||||
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to copy to clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// launch clipboard clearing process if executableName is provided
|
||||
if executableName != "" {
|
||||
cmd = exec.Command(executableName, "clipclear")
|
||||
writeToStdin(cmd, copySubject)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to launch automated clipboard clearing process - does this libmutton implementation support the \"clipclear\" argument?" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0) // only exit if clipboard clearing process is launched, otherwise assume continuous clipboard refresh
|
||||
}
|
||||
}
|
||||
|
||||
// clipClear is called in a separate process to clear the clipboard after 30 seconds
|
||||
func clipClear(oldContents string) {
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
cmd := exec.Command("powershell.exe", "-c", "Get-Clipboard")
|
||||
newContents, _ := cmd.Output()
|
||||
|
||||
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
cmd = exec.Command("powershell.exe", "-c", "Set-Clipboard")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// GetOldEntryData decrypts and returns old entry data (with all required lines present)
|
||||
func GetOldEntryData(targetLocation string, field int) []string {
|
||||
// ensure targetLocation exists
|
||||
TargetIsFile(targetLocation, true, 2)
|
||||
|
||||
// read old entry data
|
||||
unencryptedEntry := DecryptGPG(targetLocation)
|
||||
|
||||
// return the old entry data with all required lines present
|
||||
if field > 0 {
|
||||
return EnsureSliceLength(unencryptedEntry, field)
|
||||
} else {
|
||||
return unencryptedEntry
|
||||
}
|
||||
}
|
||||
|
||||
// Rename renames oldLocation to newLocation
|
||||
func Rename(oldLocation string, newLocation string) {
|
||||
// ensure newLocation does not exist
|
||||
_, isAccessible := TargetIsFile(newLocation, false, 0)
|
||||
if isAccessible {
|
||||
fmt.Println(AnsiError + "\"" + newLocation + "\" already exists" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// rename oldLocation to newLocation
|
||||
err := os.Rename(oldLocation, newLocation)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to rename - does the target containing directory exists?" + AnsiReset)
|
||||
}
|
||||
|
||||
// TODO If in online mode, check if oldLocation is a directory and rename it on the server
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// EnsureSliceLength ensures slice is long enough to contain the specified index
|
||||
func EnsureSliceLength(slice []string, index int) []string {
|
||||
for len(slice) <= index {
|
||||
slice = append(slice, "")
|
||||
}
|
||||
return slice
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TODO GPG support is a temporary feature - it will be replaced with a different encryption scheme in the future
|
||||
// TODO These functions may continue to exist after that point, but consider them deprecated
|
||||
|
||||
// DecryptGPG decrypts a GPG-encrypted file and returns the contents as a slice of (trimmed) strings
|
||||
func DecryptGPG(targetLocation string) []string {
|
||||
cmd := exec.Command("gpg", "--pinentry-mode", "loopback", "-q", "-d", targetLocation)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to decrypt \"" + targetLocation + "\" - ensure it is a valid GPG-encrypted file and that you entered your passphrase correctly" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
outputSlice := strings.Split(string(output), "\n")
|
||||
return outputSlice
|
||||
}
|
||||
|
||||
// EncryptGPG encrypts a slice of strings using GPG and returns the encrypted data as a byte slice
|
||||
func EncryptGPG(input []string) []byte {
|
||||
cmd := exec.Command("gpg", "-q", "-r", ReadConfig([]string{"gpgID"})[0], "-e")
|
||||
writeToStdin(cmd, strings.Join(input, "\n"))
|
||||
encryptedBytes, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to encrypt data - ensure that your GPG key is valid and that you have a valid GPG ID set in libmutton.ini" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return encryptedBytes
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TempInit ensures libmutton directories exist and writes the libmutton configuration file
|
||||
func TempInit(configFileMap map[string]string) {
|
||||
// create EntryRoot and ConfigDir
|
||||
dirInit()
|
||||
|
||||
// remove existing config file
|
||||
removeFile(ConfigPath)
|
||||
|
||||
if configFileMap["textEditor"] == "" {
|
||||
configFileMap["textEditor"] = textEditorFallback()
|
||||
}
|
||||
|
||||
// create and write config file
|
||||
configFile, _ := os.OpenFile(ConfigPath, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
defer configFile.Close()
|
||||
configFile.WriteString("[LIBMUTTON]\n")
|
||||
for key, value := range configFileMap {
|
||||
configFile.WriteString(key + " = " + value + "\n")
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// GpgUIDListGen generates a list of all GPG key IDs on the system and returns them as a slice of strings
|
||||
func GpgUIDListGen() []string {
|
||||
cmd := exec.Command("gpg", "-k", "--with-colons")
|
||||
gpgOutputBytes, _ := cmd.Output()
|
||||
gpgOutputLines := strings.Split(string(gpgOutputBytes), "\n")
|
||||
var uidSlice []string
|
||||
for _, line := range gpgOutputLines {
|
||||
if strings.HasPrefix(line, "uid") {
|
||||
uid := strings.Split(line, ":")[9]
|
||||
uidSlice = append(uidSlice, uid)
|
||||
}
|
||||
}
|
||||
return uidSlice
|
||||
}
|
||||
|
||||
// GpgKeyGen generates a new GPG key and returns the key ID
|
||||
func GpgKeyGen() string {
|
||||
gpgGenTempFile := CreateTempFile()
|
||||
defer os.Remove(gpgGenTempFile.Name())
|
||||
|
||||
// create and write gpg-gen file
|
||||
unixTime := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
gpgGenTempFile.WriteString(strings.Join([]string{"Key-Type: eddsa", "Key-Curve: ed25519", "Key-Usage: sign", "Subkey-Type: ecdh", "Subkey-Curve: cv25519", "Subkey-Usage: encrypt", "Name-Real: libmutton-" + unixTime, "Name-Comment: gpg-libmutton", "Name-Email: github.com/rwinkhart/libmutton", "Expire-Date: 0"}, "\n"))
|
||||
|
||||
// close gpg-gen file
|
||||
gpgGenTempFile.Close()
|
||||
|
||||
// generate GPG key based on gpg-gen file
|
||||
cmd := exec.Command("gpg", "-q", "--batch", "--generate-key", gpgGenTempFile.Name())
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Run()
|
||||
|
||||
return "libmutton-" + unixTime + " (gpg-libmutton) <github.com/rwinkhart/libmutton>"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//go:build !windows
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
const FallbackEditor = "vi" // vi is pre-installed on most UNIX systems
|
||||
|
||||
// dirInit creates the libmutton directories
|
||||
func dirInit() {
|
||||
// create EntryRoot
|
||||
err := os.MkdirAll(EntryRoot, 0700)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// create config directory
|
||||
err = os.MkdirAll(ConfigDir, 0700)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\":" + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// textEditorFallback returns the value of the $EDITOR environment variable, or FallbackEditor if it is not set
|
||||
func textEditorFallback() string {
|
||||
// ensure textEditor is set
|
||||
textEditor := os.Getenv("EDITOR")
|
||||
if textEditor == "" {
|
||||
textEditor = FallbackEditor
|
||||
}
|
||||
return textEditor
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//go:build windows
|
||||
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
const FallbackEditor = "nvim" // since there is no pre-installed CLI editor on Windows, default to the most popular one
|
||||
|
||||
// dirInit creates the libmutton directories
|
||||
func dirInit() {
|
||||
// create EntryRoot (includes config directory on Windows)
|
||||
err := os.MkdirAll(EntryRoot, 0700)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// textEditorFallback returns FallbackEditor
|
||||
func textEditorFallback() string {
|
||||
return FallbackEditor
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Shear(targetLocation string) {
|
||||
// TODO If in online mode, remove from server and add to shear list
|
||||
TargetIsFile(targetLocation, true, 0) // needed because os.RemoveAll does not return an error if target does not exist
|
||||
err := os.RemoveAll(targetLocation)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to remove target: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build !windows
|
||||
|
||||
package backend
|
||||
|
||||
// TargetLocationFormat returns the target location of an entry formatted for the current platform
|
||||
func TargetLocationFormat(entryName string) string {
|
||||
return EntryRoot + PathSeparator + entryName
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//go:build windows
|
||||
|
||||
package backend
|
||||
|
||||
import "strings"
|
||||
|
||||
// TargetLocationFormat returns the target location of an entry formatted for the current platform
|
||||
func TargetLocationFormat(entryName string) string {
|
||||
return EntryRoot + PathSeparator + strings.ReplaceAll(entryName, "/", PathSeparator)
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const extendedCharset = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
|
||||
|
||||
// TargetIsFile TargetStatusCheck checks if the targetLocation is a file, directory, or is inaccessible
|
||||
// failCondition: 0 = fail on inaccessible, 1 = fail on inaccessible/file, 2 = fail on inaccessible/directory
|
||||
// returns: isFile, isAccessible
|
||||
func TargetIsFile(targetLocation string, errorOnFail bool, failCondition uint8) (bool, bool) {
|
||||
targetInfo, err := os.Stat(targetLocation)
|
||||
if err != nil {
|
||||
if errorOnFail {
|
||||
fmt.Println(AnsiError + "Failed to access \"" + targetLocation + "\" - ensure it exists and has the correct permissions" + AnsiReset)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
if targetInfo.IsDir() {
|
||||
if errorOnFail && failCondition == 2 {
|
||||
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a directory" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return false, true
|
||||
} else {
|
||||
if errorOnFail && failCondition == 1 {
|
||||
fmt.Println(AnsiError + "\"" + targetLocation + "\" is a file" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
|
||||
// WriteEntry writes entryData to an encrypted file at targetLocation
|
||||
func WriteEntry(targetLocation string, entryData []string) {
|
||||
encryptedBytes := EncryptGPG(entryData)
|
||||
err := os.WriteFile(targetLocation, encryptedBytes, 0600)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to write to file: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// writeToStdin writes a string to a command's stdin
|
||||
func writeToStdin(cmd *exec.Cmd, input string) {
|
||||
stdin, _ := cmd.StdinPipe()
|
||||
go func() {
|
||||
defer stdin.Close()
|
||||
io.WriteString(stdin, input)
|
||||
}()
|
||||
}
|
||||
|
||||
// CreateTempFile creates a temporary file and returns a pointer to it
|
||||
func CreateTempFile() *os.File {
|
||||
tempFile, err := os.CreateTemp("", "*.markdown")
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to create temporary file: " + err.Error() + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
return tempFile
|
||||
}
|
||||
|
||||
// removeFile removes a file at targetLocation and does not error if the file does not exist
|
||||
func removeFile(targetLocation string) {
|
||||
// remove existing config file
|
||||
err := os.Remove(targetLocation)
|
||||
if err != nil {
|
||||
// ignore error if file does not exist
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Println(AnsiError + "Failed to remove \"" + targetLocation + "\":" + err.Error() + AnsiReset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveTrailingEmptyStrings removes empty strings from the end of a slice
|
||||
func RemoveTrailingEmptyStrings(slice []string) []string {
|
||||
for i := len(slice) - 1; i >= 0; i-- {
|
||||
if slice[i] != "" {
|
||||
return slice[:i+1]
|
||||
}
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// StringGen generates a random string of a specified length and complexity
|
||||
// complexity: minimum percentage of special characters to be returned in the generated string (only impacts complex strings)
|
||||
func StringGen(length int, complex bool, complexity float64) string {
|
||||
var actualSpecialChars int // track the number of special characters in the generated string
|
||||
var minSpecialChars int // track the minimum number of special characters to accept
|
||||
|
||||
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // default character set used for all strings
|
||||
if complex {
|
||||
minSpecialChars = int(math.Round(float64(length) * complexity)) // determine minimum number of special characters to accept
|
||||
charset = charset + extendedCharset
|
||||
}
|
||||
|
||||
// loop until a string of the desired complexity is generated
|
||||
for {
|
||||
// generate a random string
|
||||
result := make([]byte, length)
|
||||
for i := range result {
|
||||
val, _ := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
|
||||
result[i] = charset[val.Int64()]
|
||||
}
|
||||
|
||||
// return early if the string is not complex
|
||||
if !complex {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
// count the number of special characters in the generated string
|
||||
for _, char := range string(result) {
|
||||
if strings.ContainsRune(extendedCharset, char) {
|
||||
actualSpecialChars++
|
||||
}
|
||||
}
|
||||
|
||||
// return the generated string if it contains enough special characters
|
||||
if actualSpecialChars >= minSpecialChars {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
// reset special character counter
|
||||
fmt.Println("Regenerating string until desired complexity is achieved...")
|
||||
actualSpecialChars = 0
|
||||
}
|
||||
}
|
||||
|
||||
// EntryIsNotEmpty iterates through entryData and returns true if any line is not empty
|
||||
func EntryIsNotEmpty(entryData []string) bool {
|
||||
for _, line := range entryData {
|
||||
if line != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
+7
-6
@@ -1,18 +1,19 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
termy "golang.org/x/crypto/ssh/terminal"
|
||||
"os"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// global variables used across multiple files
|
||||
var (
|
||||
width, _, _ = term.GetSize(int(os.Stdout.Fd()))
|
||||
rootLength = len(backend.EntryRoot)
|
||||
width, _, _ = termy.GetSize(int(os.Stdout.Fd()))
|
||||
)
|
||||
|
||||
// global constants used across multiple files
|
||||
const (
|
||||
MUTNVersion = "0.2.2" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1"
|
||||
|
||||
AnsiBold = "\033[1m"
|
||||
ansiBold = "\033[1m"
|
||||
ansiBlackOnWhite = "\033[38;5;0;48;5;15m"
|
||||
)
|
||||
|
||||
+12
-19
@@ -2,25 +2,19 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
)
|
||||
|
||||
// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts.
|
||||
// Requires: entryType (0 = standard password entry, 1 = auto-generated password entry, 2 = note-only entry).
|
||||
func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
|
||||
// ensure target location does not already exist
|
||||
_, isAccessible := core.TargetIsFile(targetLocation, false, 0)
|
||||
// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts
|
||||
// entryType: 0 = standard (password), 1 = auto-generated password, 2 = note
|
||||
func AddEntry(targetLocation string, hidePassword bool, entryType uint8) {
|
||||
_, isAccessible := backend.TargetIsFile(targetLocation, false, 0)
|
||||
if isAccessible {
|
||||
fmt.Println(core.AnsiError + "Target location already exists" + core.AnsiReset)
|
||||
os.Exit(core.ErrorTargetExists)
|
||||
fmt.Println(backend.AnsiError + "Target location already exists" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// ensure target containing directory exists and is a directory (not a file)
|
||||
core.TargetIsFile(targetLocation[:strings.LastIndex(targetLocation, core.PathSeparator)], true, 1)
|
||||
|
||||
var unencryptedEntry []string
|
||||
|
||||
if entryType < 2 {
|
||||
@@ -31,22 +25,21 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) {
|
||||
if entryType == 0 {
|
||||
password = inputHidden("Password:")
|
||||
} else {
|
||||
password = core.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
|
||||
password = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2)
|
||||
}
|
||||
|
||||
totp := inputHidden("TOTP secret:")
|
||||
url := input("URL:")
|
||||
if inputBinary("Add a note to this entry?") {
|
||||
note, _ := editNote([]string{})
|
||||
unencryptedEntry = append([]string{password, username, totp, url}, note...)
|
||||
unencryptedEntry = append([]string{password, username, url}, note...)
|
||||
} else {
|
||||
unencryptedEntry = []string{password, username, totp, url}
|
||||
unencryptedEntry = []string{password, username, url}
|
||||
}
|
||||
} else {
|
||||
note, _ := editNote([]string{})
|
||||
unencryptedEntry = append([]string{"", "", "", ""}, note...)
|
||||
unencryptedEntry = append([]string{"", "", ""}, note...)
|
||||
}
|
||||
|
||||
// write and preview the new entry
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)
|
||||
}
|
||||
|
||||
+35
-40
@@ -3,28 +3,29 @@ package cli
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"os"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
|
||||
// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server.
|
||||
func RenameCli(oldLocationIncomplete string) {
|
||||
// prompt user for new location and rename
|
||||
newLocationIncomplete := input("New location:")
|
||||
sync.RenameRemoteFromClient(oldLocationIncomplete, newLocationIncomplete)
|
||||
// RenameCli renames an entry at oldLocation to a new location (user input)
|
||||
func RenameCli(oldLocation string) {
|
||||
// ensure targetLocation exists
|
||||
backend.TargetIsFile(oldLocation, true, 0)
|
||||
|
||||
// exit is done from sync.RenameRemoteFromClient
|
||||
// prompt user for new location and rename
|
||||
newLocation := backend.EntryRoot + backend.PathSeparator + input("New location:")
|
||||
backend.Rename(oldLocation, newLocation)
|
||||
|
||||
// exit is done from backend.Rename
|
||||
}
|
||||
|
||||
// EditEntryField edits a field of an entry at targetLocation (user input).
|
||||
func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// EditEntryField edits a field of an entry at targetLocation (user input)
|
||||
func EditEntryField(targetLocation string, hidePassword bool, field int) {
|
||||
// fetch old entry data (with all required lines present)
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, field)
|
||||
unencryptedEntry := backend.GetOldEntryData(targetLocation, field)
|
||||
|
||||
// edit the field
|
||||
switch field {
|
||||
@@ -33,49 +34,43 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
case 1:
|
||||
unencryptedEntry[field] = input("Username:")
|
||||
case 2:
|
||||
unencryptedEntry[field] = inputHidden("TOTP secret:")
|
||||
case 3:
|
||||
unencryptedEntry[field] = input("URL:")
|
||||
case 4: // edit notes fields
|
||||
case 3: // edit notes fields
|
||||
// store note and non-note data separately
|
||||
nonNoteData := unencryptedEntry[:4]
|
||||
noteData := unencryptedEntry[4:]
|
||||
nonNoteData := unencryptedEntry[:3]
|
||||
noteData := unencryptedEntry[3:]
|
||||
|
||||
// edit the note
|
||||
editedNote, noteEdited := editNote(noteData)
|
||||
if !noteEdited { // exit early if the note was not edited
|
||||
fmt.Println(core.AnsiError + "Entry is unchanged" + core.AnsiReset)
|
||||
os.Exit(0)
|
||||
fmt.Println(backend.AnsiError + "Entry is unchanged" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
unencryptedEntry = append(nonNoteData, editedNote...)
|
||||
}
|
||||
|
||||
// write and preview the modified entry
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)
|
||||
}
|
||||
|
||||
// GenUpdate generates a new password for an entry at targetLocation (user input).
|
||||
func GenUpdate(targetLocation string, hideSecrets bool) {
|
||||
// GenUpdate generates a new password for an entry at targetLocation (user input)
|
||||
func GenUpdate(targetLocation string, hidePassword bool) {
|
||||
// fetch old entry data
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, 0)
|
||||
unencryptedEntry := backend.GetOldEntryData(targetLocation, 0)
|
||||
|
||||
// generate a new password
|
||||
unencryptedEntry[0] = core.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
|
||||
unencryptedEntry[0] = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2)
|
||||
|
||||
// write and preview the modified entry
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hidePassword)
|
||||
}
|
||||
|
||||
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty).
|
||||
// Returns the edited note and a boolean indicating whether the note was edited.
|
||||
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty)
|
||||
// returns the edited note and a boolean indicating whether the note was edited
|
||||
func editNote(baseNote []string) ([]string, bool) {
|
||||
tempFile := core.CreateTempFile()
|
||||
defer func(name string) {
|
||||
_ = os.Remove(name) // error ignored; if the file could be created, it can probably be removed
|
||||
}(tempFile.Name())
|
||||
|
||||
// fetch the user's text editor
|
||||
editor := core.ParseConfig([][2]string{{"MUTN", "textEditor"}}, "")[0]
|
||||
tempFile := backend.CreateTempFile()
|
||||
defer os.Remove(tempFile.Name())
|
||||
editor := backend.ReadConfig([]string{"textEditor"})[0]
|
||||
|
||||
// write baseNote to tempFile (if it is not empty)
|
||||
if len(baseNote) > 0 {
|
||||
@@ -84,8 +79,8 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// close tempFile to allow it to be modified by the user's text editor
|
||||
_ = tempFile.Close() // error ignored; if the file could be created, it can probably be closed
|
||||
// close tempFile
|
||||
tempFile.Close()
|
||||
|
||||
// edit the tempFile (note) with the user's text editor
|
||||
cmd := exec.Command(editor, tempFile.Name())
|
||||
@@ -94,13 +89,13 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
panic(core.AnsiError + "Failed to write note with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(backend.AnsiError + "Failed to write note with " + editor + backend.AnsiReset)
|
||||
}
|
||||
|
||||
// open the tempFile for reading
|
||||
tempFile, err = os.Open(tempFile.Name())
|
||||
if err != nil {
|
||||
panic(core.AnsiError + "Failed to read note written with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(backend.AnsiError + "Failed to write note with " + editor + backend.AnsiReset)
|
||||
}
|
||||
|
||||
// read the edited note from the tempFile
|
||||
@@ -111,10 +106,10 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
}
|
||||
|
||||
// close tempFile
|
||||
_ = tempFile.Close() // error ignored; if the file could be opened, it can probably be closed
|
||||
tempFile.Close()
|
||||
|
||||
// remove trailing empty strings from the edited note
|
||||
note = core.RemoveTrailingEmptyStrings(note)
|
||||
note = backend.RemoveTrailingEmptyStrings(note)
|
||||
|
||||
// trim trailing whitespace from each note line
|
||||
for i, line := range note {
|
||||
|
||||
+50
-20
@@ -2,31 +2,31 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
|
||||
// ANSI color constants used only in this file
|
||||
// global constants used only in this file
|
||||
const (
|
||||
ansiAlternateEntryColor = "\033[38;5;8m"
|
||||
ansiDirectoryHeader = "\033[38;5;7;48;5;8m"
|
||||
ansiEmptyDirectoryWarning = "\033[38;5;11m"
|
||||
)
|
||||
|
||||
// determineIndentation calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories); also subtracts "old" text from directory header.
|
||||
// calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories) - also subtracts "old" text from directory header
|
||||
func determineIndentation(skippedDirList []bool, dirList []string, currentDirIndex int) (int, string) {
|
||||
var subtractor int // tracks how much to subtract from expected indentation multiplier
|
||||
var lastPrefixIndex int // tracks the index (in both skippedDirList and dirList) of the last displayed parent directory
|
||||
var trimmedDirectory = dirList[currentDirIndex]
|
||||
|
||||
// determine initial indentation multiplier based on "/" occurrences
|
||||
indent := strings.Count(trimmedDirectory, "/") - 1 // subtract 1 to avoid indenting root-level directories
|
||||
// determine initial indentation multiplier based on PathSeparator occurrences
|
||||
indent := strings.Count(trimmedDirectory, backend.PathSeparator) - 1 // subtract 1 to avoid indenting root-level directories
|
||||
|
||||
for i, skipped := range skippedDirList[:currentDirIndex] { // checks each skipped directory to determine if it is a parent to the current directory
|
||||
if strings.HasPrefix(trimmedDirectory, dirList[i]+"/") { // if the current directory is the child of this iteration's directory...
|
||||
if strings.HasPrefix(trimmedDirectory, dirList[i]+backend.PathSeparator) { // if the current directory is the child of this iteration's directory...
|
||||
if skipped { // ...and this iteration's directory was skipped...
|
||||
subtractor++ // increment the subtractor to indicate that the visual indentation should be reduced
|
||||
} else {
|
||||
@@ -46,8 +46,8 @@ func determineIndentation(skippedDirList []bool, dirList []string, currentDirInd
|
||||
return indent, trimmedDirectory
|
||||
}
|
||||
|
||||
// printFileEntry handles processing for printing file entries (determines color, wraps lines, and prints).
|
||||
func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlternator int8) (int, int8) {
|
||||
// processing for printing file entries (determines color, line wrapping, and prints)
|
||||
func printFileEntry(entry string, lastSlash int, charCounter int, colorAlternator int8, indent int) (int, int8) {
|
||||
// determine color to print fileEntryName (alternate each time function is run)
|
||||
var colorCode string
|
||||
if colorAlternator > 0 {
|
||||
@@ -72,17 +72,47 @@ func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlter
|
||||
}
|
||||
|
||||
// print fileEntryName to screen
|
||||
fmt.Printf("%s%s%s ", colorCode, fileEntryName, core.AnsiReset)
|
||||
fmt.Printf("%s%s%s ", colorCode, fileEntryName, backend.AnsiReset)
|
||||
|
||||
return charCounter, colorAlternator
|
||||
}
|
||||
|
||||
// EntryListGen generates and displays the full libmutton entry list.
|
||||
// EntryListGen generates and displays full libmutton entry list
|
||||
func EntryListGen() {
|
||||
fileList, dirList := sync.WalkEntryDir()
|
||||
// define file/directory containing slices so that they may be accessed by the anonymous WalkDir function
|
||||
var fileList []string
|
||||
var dirList []string
|
||||
|
||||
// walk entry directory
|
||||
_ = filepath.WalkDir(backend.EntryRoot,
|
||||
func(fullPath string, entry fs.DirEntry, err error) error {
|
||||
|
||||
// check for errors encountered while walking directory
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
fmt.Println(backend.AnsiError + "\nThe entry directory does not exist - run \"mutn init\" to create it" + backend.AnsiReset)
|
||||
} else {
|
||||
// otherwise, print the source of the error
|
||||
fmt.Println(backend.AnsiError + "\nAn unexpected error occurred while generating the entry list: " + err.Error() + backend.AnsiReset)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// trim root path from each path before storing
|
||||
trimmedPath := fullPath[rootLength:]
|
||||
|
||||
// create separate slices for entries and directories
|
||||
if !entry.IsDir() {
|
||||
fileList = append(fileList, trimmedPath)
|
||||
} else {
|
||||
dirList = append(dirList, trimmedPath)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// print header bar w/total entry count
|
||||
fmt.Print("\n"+ansiBlackOnWhite, len(fileList), " libmutton entries:"+core.AnsiReset)
|
||||
fmt.Print("\n"+ansiBlackOnWhite, len(fileList), " libmutton entries:"+backend.AnsiReset)
|
||||
|
||||
// dirList iteration
|
||||
dirListLength := len(dirList) // save length for multiple references below
|
||||
@@ -107,7 +137,7 @@ func EntryListGen() {
|
||||
|
||||
// check if next directory is within the current one
|
||||
if dirListLength > i+1 {
|
||||
if nextDir := dirList[i+1]; directory == nextDir[:strings.LastIndex(nextDir, "/")] {
|
||||
if nextDir := dirList[i+1]; directory == nextDir[:strings.LastIndex(nextDir, backend.PathSeparator)] {
|
||||
containsSubdirectory = true
|
||||
} else {
|
||||
containsSubdirectory = false
|
||||
@@ -121,17 +151,17 @@ func EntryListGen() {
|
||||
for _, file := range fileList {
|
||||
|
||||
// print the current file if it belongs in the current directory - otherwise, break the loop and move on to the next directory
|
||||
if lastSlash := strings.LastIndex(file, "/") + 1; file[:lastSlash-1] == directory {
|
||||
if lastSlash := strings.LastIndex(file, backend.PathSeparator) + 1; file[:lastSlash-1] == directory {
|
||||
|
||||
// print directory header if this is the first run of the loop
|
||||
if !containsFiles {
|
||||
containsFiles = true
|
||||
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
||||
indent, vanityDirectory = determineIndentation(skippedDirList, dirList, i) // calculate the final indentation multiplier
|
||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+core.AnsiReset+"\n", vanityDirectory)
|
||||
printDirectoryHeader(vanityDirectory, indent)
|
||||
}
|
||||
|
||||
charCounter, colorAlternator = printFileEntry(file, lastSlash, charCounter, indent, colorAlternator)
|
||||
charCounter, colorAlternator = printFileEntry(file, lastSlash, charCounter, colorAlternator, indent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,8 +170,8 @@ func EntryListGen() {
|
||||
if dirListLength > 1 { // and directories besides the root-level exist... display directory header and empty directory warning
|
||||
skippedDirList[i] = false // the directory header is being printed, indicate that it is not being skipped
|
||||
indent, vanityDirectory = determineIndentation(skippedDirList, dirList, i) // calculate the final indentation multiplier
|
||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+core.AnsiReset+"\n", vanityDirectory)
|
||||
fmt.Print(strings.Repeat(" ", indent*2) + ansiEmptyDirectoryWarning + "-empty directory-" + core.AnsiReset)
|
||||
printDirectoryHeader(vanityDirectory, indent)
|
||||
fmt.Print(strings.Repeat(" ", indent*2) + ansiEmptyDirectoryWarning + "-empty directory-" + backend.AnsiReset)
|
||||
} else { // warn if the only thing that exists is the root-level directory
|
||||
fmt.Print("\n\nNothing's here! For help creating your first entry, run \"mutn help\".")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//go:build !windows
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func printDirectoryHeader(vanityDirectory string, indent int) {
|
||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+backend.AnsiReset+"\n", vanityDirectory)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//go:build windows
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func printDirectoryHeader(vanityDirectory string, indent int) {
|
||||
fmt.Printf("\n\n"+strings.Repeat(" ", indent*2)+ansiDirectoryHeader+"%s/"+backend.AnsiReset+"\n", strings.ReplaceAll(vanityDirectory, backend.PathSeparator, "/"))
|
||||
}
|
||||
+29
-36
@@ -5,76 +5,69 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
|
||||
"github.com/charmbracelet/glamour"
|
||||
)
|
||||
|
||||
const ansiShownPassword = "\033[38;5;10m"
|
||||
|
||||
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format.
|
||||
func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
|
||||
// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format
|
||||
func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) {
|
||||
fmt.Println()
|
||||
|
||||
for field := range decryptedEntry {
|
||||
switch field {
|
||||
for i := range decryptedEntry {
|
||||
switch i {
|
||||
case 0:
|
||||
// if the first field (password) is not empty, print it
|
||||
if decryptedEntry[0] != "" {
|
||||
if !hideSecrets {
|
||||
fmt.Print(ansiDirectoryHeader + "Password:" + core.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + core.AnsiReset + "\n\n")
|
||||
if !hidePassword {
|
||||
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + backend.AnsiReset + "\n\n")
|
||||
} else {
|
||||
fmt.Print(ansiDirectoryHeader + "Password:" + core.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + core.AnsiReset + "\n\n")
|
||||
fmt.Print(ansiDirectoryHeader + "Password:" + backend.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + backend.AnsiReset + "\n\n")
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
// if the second field (username) is not empty, print it
|
||||
if decryptedEntry[1] != "" {
|
||||
fmt.Print(ansiDirectoryHeader + "Username:" + core.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
|
||||
fmt.Print(ansiDirectoryHeader + "Username:" + backend.AnsiReset + "\n" + decryptedEntry[1] + "\n\n")
|
||||
}
|
||||
case 2:
|
||||
// if the third field (TOTP secret) is not empty, print it
|
||||
// if the third field (url) is not empty, print it
|
||||
if decryptedEntry[2] != "" {
|
||||
if !hideSecrets {
|
||||
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + core.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[2] + core.AnsiReset + "\n\n")
|
||||
} else {
|
||||
fmt.Print(ansiDirectoryHeader + "TOTP Secret:" + core.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + core.AnsiReset + "\n\n")
|
||||
}
|
||||
fmt.Print(ansiDirectoryHeader + "URL:" + backend.AnsiReset + "\n" + decryptedEntry[2] + "\n\n")
|
||||
}
|
||||
case 3:
|
||||
// if the fourth field (url) is not empty, print it
|
||||
if decryptedEntry[3] != "" {
|
||||
fmt.Print(ansiDirectoryHeader + "URL:" + core.AnsiReset + "\n" + decryptedEntry[3] + "\n\n")
|
||||
}
|
||||
case 4:
|
||||
// print the notes header
|
||||
fmt.Println(ansiDirectoryHeader + "Notes:" + core.AnsiReset)
|
||||
fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset)
|
||||
|
||||
// combine remaining fields into a single string (to support Markdown rendering)
|
||||
var notesSlice []string
|
||||
for ; field < len(decryptedEntry); field++ {
|
||||
notesSlice = append(notesSlice, decryptedEntry[field])
|
||||
// combine remaining fields into a single string (for markdown rendering)
|
||||
var markdownNotes []string
|
||||
for field := 3; field < len(decryptedEntry); field++ {
|
||||
markdownNotes = append(markdownNotes, decryptedEntry[field])
|
||||
}
|
||||
joinedString := strings.Join(notesSlice, "\n")
|
||||
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width))
|
||||
markdownNotesString, _ := r.Render(strings.Join(markdownNotes, "\n"))
|
||||
|
||||
// print notes to stdout
|
||||
renderNote(&joinedString)
|
||||
// print markdown-rendered notes
|
||||
fmt.Print(markdownNotesString)
|
||||
|
||||
// break after notes have been printed
|
||||
// break after all lines have been printed
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if syncEnabled {
|
||||
sync.RunJob(false)
|
||||
if sync && !backend.Windows {
|
||||
SshypSync() // TODO Remove after native sync is implemented
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader.
|
||||
func EntryReaderDecrypt(targetLocation string, hideSecrets bool) {
|
||||
if isFile, _ := core.TargetIsFile(targetLocation, true, 2); isFile {
|
||||
EntryReader(core.DecryptGPG(targetLocation), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified
|
||||
// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader
|
||||
func EntryReaderDecrypt(targetLocation string, hidePassword bool, sync bool) {
|
||||
if isFile, _ := backend.TargetIsFile(targetLocation, true, 2); isFile {
|
||||
EntryReader(backend.DecryptGPG(targetLocation), hidePassword, sync)
|
||||
}
|
||||
// do not exit, as this is the job of EntryReader
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
//go:build !noMarkdown
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/charmbracelet/glamour"
|
||||
)
|
||||
|
||||
// renderNote renders the notes section of an entry (in Markdown) to stdout.
|
||||
func renderNote(note *string) {
|
||||
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width))
|
||||
markdownNotesString, _ := r.Render(*note)
|
||||
|
||||
// print markdown-rendered notes
|
||||
fmt.Print(markdownNotesString)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
//go:build noMarkdown
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled).
|
||||
func renderNote(note *string) {
|
||||
fmt.Print("\n" + *note + "\n\n")
|
||||
}
|
||||
+8
-52
@@ -1,74 +1,30 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
|
||||
// TempInitCli initializes the MUTN environment based on user input.
|
||||
// TempInitCli initializes the MUTN environment based on user input
|
||||
func TempInitCli() {
|
||||
// gpgID
|
||||
var gpgID string
|
||||
if inputBinary("Auto-generate GPG key?") {
|
||||
gpgID = core.GpgKeyGen()
|
||||
gpgID = backend.GpgKeyGen()
|
||||
} else {
|
||||
// select GPG key from menu
|
||||
uidSlice := core.GpgUIDListGen()
|
||||
uidSlice := backend.GpgUIDListGen()
|
||||
gpgIDInt := inputMenuGen("Select GPG key:", uidSlice)
|
||||
if gpgIDInt == 0 {
|
||||
fmt.Println(core.AnsiError + "No GPG keys found - please generate one" + core.AnsiReset)
|
||||
os.Exit(core.ErrorTargetNotFound)
|
||||
fmt.Println(backend.AnsiError + "No GPG keys found - please generate one" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
gpgID = uidSlice[gpgIDInt-1]
|
||||
}
|
||||
|
||||
// textEditor
|
||||
textEditor := cmp.Or(input("Text editor (leave blank for $EDITOR, falls back to \""+fallbackEditor+"\"):"), os.Getenv("EDITOR"), fallbackEditor)
|
||||
textEditor := input("Text editor (leave blank for $EDITOR, falls back to \"" + backend.FallbackEditor + "\"):")
|
||||
|
||||
// SSH info
|
||||
configSSH := inputBinary("Configure SSH settings (for synchronization)?")
|
||||
if configSSH {
|
||||
// necessary SSH info
|
||||
fmt.Println(AnsiBold + "\nNote:" + core.AnsiReset + " Only key-based authentication is supported (keys may optionally be passphrase-protected).\nThe remote server must already be in your ~" + core.PathSeparator + ".ssh" + core.PathSeparator + "known_hosts file.")
|
||||
sshUser := input("Remote SSH username:")
|
||||
sshPort := input("Remote SSH port:")
|
||||
sshIP := input("Remote SSH IP/domain:")
|
||||
|
||||
// prompt for and ensure existence of SSH identity file
|
||||
var sshKey string
|
||||
var sshKeyIsFile bool
|
||||
for !sshKeyIsFile {
|
||||
fallbackSSHKey := core.Home + core.PathSeparator + ".ssh" + core.PathSeparator + "id_ed25519"
|
||||
sshKey = cmp.Or(expandPathWithHome(input("SSH private identity file path (falls back to \""+fallbackSSHKey+"\"):")), fallbackSSHKey)
|
||||
sshKeyIsFile, _ = core.TargetIsFile(sshKey, false, 0)
|
||||
if !sshKeyIsFile {
|
||||
fmt.Println(core.AnsiError+"SSH identity file not found:", sshKey+core.AnsiReset)
|
||||
}
|
||||
}
|
||||
|
||||
sshKeyProtected := inputBinary("Is the identity file password-protected?")
|
||||
|
||||
// initialize libmutton directories
|
||||
oldDeviceID := core.DirInit(false)
|
||||
|
||||
// write config file (temporarily assigns sshEntryRoot and sshIsWindows to null to pass initial device ID registration)
|
||||
core.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}, {"LIBMUTTON", "sshUser", sshUser}, {"LIBMUTTON", "sshIP", sshIP}, {"LIBMUTTON", "sshPort", sshPort}, {"LIBMUTTON", "sshKey", sshKey}, {"LIBMUTTON", "sshKeyProtected", strconv.FormatBool(sshKeyProtected)}, {"LIBMUTTON", "sshEntryRoot", "null"}, {"LIBMUTTON", "sshIsWindows", "false"}}, false)
|
||||
|
||||
// generate and register device ID
|
||||
sshEntryRoot, sshIsWindows := sync.DeviceIDGen(oldDeviceID)
|
||||
|
||||
// update config file with sshEntryRoot and sshIsWindows
|
||||
core.WriteConfig([][3]string{{"LIBMUTTON", "sshEntryRoot", sshEntryRoot}, {"LIBMUTTON", "sshIsWindows", sshIsWindows}}, true)
|
||||
} else {
|
||||
// initialize libmutton directories
|
||||
core.DirInit(false)
|
||||
|
||||
// write config file
|
||||
core.WriteConfig([][3]string{{"MUTN", "textEditor", textEditor}, {"LIBMUTTON", "gpgID", gpgID}}, false)
|
||||
}
|
||||
backend.TempInit(map[string]string{"textEditor": textEditor, "gpgID": gpgID})
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
//go:build !windows
|
||||
|
||||
package cli
|
||||
|
||||
const fallbackEditor = "vi" // vi is pre-installed on most UNIX-like systems
|
||||
@@ -1,5 +0,0 @@
|
||||
//go:build windows
|
||||
|
||||
package cli
|
||||
|
||||
const fallbackEditor = "nvim" // since there is no pre-installed CLI editor on Windows, default to the most popular one
|
||||
+54
-61
@@ -4,46 +4,46 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
)
|
||||
|
||||
// ANSI color constants used only in this file
|
||||
// global constants used only in this file
|
||||
const (
|
||||
ansiVersionMeat = "\033[38;2;157;0;6m"
|
||||
ansiVersionOutline = "\033[38;2;131;165;152m"
|
||||
)
|
||||
|
||||
func HelpMain() {
|
||||
fmt.Print(AnsiBold + "\nMUTN | Copyright (c) 2024 Randall Winkhart\n" + core.AnsiReset + `
|
||||
fmt.Print(ansiBold + "\nMUTN | Copyright (c) 2024 Randall Winkhart\n" + backend.AnsiReset + `
|
||||
This software exists under the MIT license; you may redistribute it under certain conditions.
|
||||
This program comes with absolutely no warranty; type "mutn version" for details.
|
||||
|
||||
` + AnsiBold + "Usage:" + core.AnsiReset + ` mutn [/<entry name> [argument] [option]] | [argument]
|
||||
` + ansiBold + "Usage:" + backend.AnsiReset + ` mutn [/<entry name> [argument] [option]] | [argument]
|
||||
|
||||
` + AnsiBold + "Arguments:" + core.AnsiReset + `
|
||||
help Bring up this menu
|
||||
version Display version and license information
|
||||
` + ansiBold + "Arguments:" + backend.AnsiReset + `
|
||||
help|-h Bring up this menu
|
||||
version|-v Display version and license information
|
||||
init Set up MUTN (generates libmutton.ini)
|
||||
tweak Change configuration options
|
||||
copy Copy details of an entry to your clipboard
|
||||
edit Edit an existing entry
|
||||
gen Generate a new password
|
||||
add Add a new entry
|
||||
add Add an entry
|
||||
shear Delete an existing entry
|
||||
sync Manually sync the entry directory
|
||||
|
||||
` + AnsiBold + "Options:" + core.AnsiReset + `
|
||||
` + ansiBold + "Options:" + backend.AnsiReset + `
|
||||
copy:
|
||||
password|-pw|<blank> Copy the password in an entry to your clipboard
|
||||
username|-u Copy the username in an entry to your clipboard
|
||||
totp|-t Generate and copy the TOTP token for an entry to your clipboard
|
||||
url|-l Copy the URL in an entry to your clipboard
|
||||
note|-n Copy the first note line in an entry to your clipboard
|
||||
password|-pw|<blank> Copy the password of an entry to your clipboard
|
||||
username|-u Copy the username of an entry to your clipboard
|
||||
totp|-t Copy the TOTP code of an entry to your clipboard
|
||||
url|-l Copy the url of an entry to your clipboard
|
||||
note|-n Copy the note of an entry to your clipboard
|
||||
edit:
|
||||
password|-pw|<blank> Change the password in an entry
|
||||
username|-u Change the username in an entry
|
||||
totp|-t Change the TOTP secret in an entry
|
||||
url|-l Change the URL in an entry
|
||||
note|-n Change the note in an entry
|
||||
password|-pw|<blank> Change the password of an entry
|
||||
username|-u Change the username of an entry
|
||||
url|-l Change the url attached to an entry
|
||||
note|-n Change the note attached to an entry
|
||||
rename|-r Rename or relocate an entry
|
||||
gen:
|
||||
update|-u Generate a password for an existing entry
|
||||
@@ -52,17 +52,17 @@ This program comes with absolutely no warranty; type "mutn version" for details.
|
||||
note|-n Add a note entry
|
||||
folder|-f Add a new folder for entries
|
||||
|
||||
` + AnsiBold + "Tip 1:" + core.AnsiReset + ` You can quickly read an entry with "mutn /<entry name>"
|
||||
` + AnsiBold + "Tip 2:" + core.AnsiReset + ` Type "mutn" (no arguments/options) to view a list of saved entries
|
||||
` + AnsiBold + "Tip 3:" + core.AnsiReset + ` Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help
|
||||
` + AnsiBold + "Tip 4:" + core.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n")
|
||||
` + ansiBold + "Tip 1:" + backend.AnsiReset + ` You can quickly read an entry with "mutn /<entry name>"
|
||||
` + ansiBold + "Tip 2:" + backend.AnsiReset + ` Type "mutn" (no arguments/options) to view a list of saved entries
|
||||
` + ansiBold + "Tip 3:" + backend.AnsiReset + ` Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help
|
||||
` + ansiBold + "Tip 4:" + backend.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func HelpAdd() {
|
||||
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> add <option>
|
||||
fmt.Print(ansiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> add <option>
|
||||
|
||||
` + AnsiBold + "Options:" + core.AnsiReset + `
|
||||
` + ansiBold + "Options:" + backend.AnsiReset + `
|
||||
add:
|
||||
password|-pw|<blank> Add a password entry
|
||||
note|-n Add a note entry
|
||||
@@ -71,45 +71,44 @@ func HelpAdd() {
|
||||
}
|
||||
|
||||
func HelpEdit() {
|
||||
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> edit <option>
|
||||
fmt.Print(ansiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> edit <option>
|
||||
|
||||
` + AnsiBold + "Options:" + core.AnsiReset + `
|
||||
` + ansiBold + "Options:" + backend.AnsiReset + `
|
||||
edit:
|
||||
password|-pw|<blank> Change the password in an entry
|
||||
username|-u Change the username in an entry
|
||||
totp|-t Change the TOTP secret in an entry
|
||||
url|-l Change the URL in an entry
|
||||
note|-n Change the note in an entry
|
||||
password|-pw|<blank> Change the password of an entry
|
||||
username|-u Change the username of an entry
|
||||
url|-l Change the url attached to an entry
|
||||
note|-n Change the note attached to an entry
|
||||
rename|-r Rename or relocate an entry` + "\n\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func HelpCopy() {
|
||||
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> copy <option>
|
||||
fmt.Print(ansiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> copy <option>
|
||||
|
||||
` + AnsiBold + "Options:" + core.AnsiReset + `
|
||||
` + ansiBold + "Options:" + backend.AnsiReset + `
|
||||
copy:
|
||||
password|-pw|<blank> Copy the password in an entry to your clipboard
|
||||
username|-u Copy the username in an entry to your clipboard
|
||||
totp|-t Generate and copy the TOTP token for an entry to your clipboard
|
||||
url|-l Copy the URL in an entry to your clipboard
|
||||
totp|-t Copy the TOTP code of an entry to your clipboard
|
||||
url|-l Copy the url in an entry to your clipboard
|
||||
note|-n Copy the first note line in an entry to your clipboard` + "\n\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func HelpGen() {
|
||||
fmt.Print(AnsiBold + "\nUsage:" + core.AnsiReset + ` mutn /<entry name> gen [option]
|
||||
fmt.Print(ansiBold + "\nUsage:" + backend.AnsiReset + ` mutn /<entry name> gen [option]
|
||||
|
||||
` + AnsiBold + "Options:" + core.AnsiReset + `
|
||||
` + ansiBold + "Options:" + backend.AnsiReset + `
|
||||
gen:
|
||||
update|-u Generate a password for an existing entry
|
||||
|
||||
` + AnsiBold + "Tip:" + core.AnsiReset + " If no options are provided, a new password entry is generated\n\n")
|
||||
` + ansiBold + "Tip:" + backend.AnsiReset + " If no options are provided, a new password entry is generated\n\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func MITLicense() {
|
||||
fmt.Print(AnsiBold + "\n MIT License" + core.AnsiReset + `
|
||||
func Version() {
|
||||
fmt.Print(ansiBold + "\n MIT License" + backend.AnsiReset + `
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
@@ -133,28 +132,22 @@ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.` + "\n\n---------------------------------------------------------")
|
||||
// do not exit, as this is meant to be followed by other information
|
||||
}
|
||||
|
||||
func Version() {
|
||||
MITLicense()
|
||||
fmt.Print("\n\n MUTN is a simple, self-hosted,\n SSH-synchronized password manager based on libmutton\n\n" +
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.` +
|
||||
"\n\n---------------------------------------------------------" +
|
||||
"\n\n MUTN is a simple, self-hosted,\n SSH-synchronized password manager based on libmutton\n\n" +
|
||||
" .. ..\n" +
|
||||
" /()\\''.''. " + ansiVersionMeat + "♥♥♥♥" + core.AnsiReset + " .''.''/()\\ _)\n" +
|
||||
" _. : * " + ansiVersionMeat + "♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥" + core.AnsiReset + " * : <[◎]|_|=\n" +
|
||||
" }-}-*] `..'..' " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥♥♥♥♥" + core.AnsiReset + " `..'..' |\n" +
|
||||
" ◎-◎ // \\\\ " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥" + core.AnsiReset + " // \\\\ /|\\\n" +
|
||||
" /()\\''.''. " + ansiVersionMeat + "♥♥♥♥" + backend.AnsiReset + " .''.''/()\\ _)\n" +
|
||||
" _. : * " + ansiVersionMeat + "♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥" + backend.AnsiReset + " * : <[◎]|_|=\n" +
|
||||
" }-}-*] `..'..' " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥♥♥♥♥" + backend.AnsiReset + " `..'..' |\n" +
|
||||
" ◎-◎ // \\\\ " + ansiVersionMeat + "♥♥♥♥♥♥♥♥♥" + backend.AnsiReset + " // \\\\ /|\\\n" +
|
||||
ansiVersionOutline + "<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " MUTN v" + MUTNVersion + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " The Tripe Transmission Update " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " Built with libmutton v" + core.LibmuttonVersion + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " Copyright (c) 2024 Randall Winkhart " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + core.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" + core.AnsiReset +
|
||||
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " MUTN Version 0.1.0 " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " The Butchered Update " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " Copyright (c) 2024 Randall Winkhart " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"\\" + ansiBlackOnWhite + " " + backend.AnsiReset + ansiVersionOutline + "/\n" +
|
||||
"<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" + backend.AnsiReset +
|
||||
"\n For more information, see:\n\n" +
|
||||
" https://github.com/rwinkhart/MUTN\n" +
|
||||
" https://github.com/rwinkhart/libmutton\n\n")
|
||||
|
||||
+25
-23
@@ -3,14 +3,21 @@ package cli
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
// input prompts the user for input and returns the input as a string.
|
||||
// TODO remove after native sync is implemented
|
||||
func SshypSync() {
|
||||
cmd := exec.Command("sshyp", "sync")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Run()
|
||||
}
|
||||
|
||||
// input prompts the user for input and returns the input as a string
|
||||
func input(prompt string) string {
|
||||
fmt.Print("\n" + prompt + " ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
@@ -18,17 +25,17 @@ func input(prompt string) string {
|
||||
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
|
||||
}
|
||||
|
||||
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal.
|
||||
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal
|
||||
func inputHidden(prompt string) string {
|
||||
fmt.Print("\n" + prompt + " ")
|
||||
byteInput, _ := term.ReadPassword(int(os.Stdin.Fd()))
|
||||
byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
password := string(byteInput)
|
||||
fmt.Println()
|
||||
return password
|
||||
}
|
||||
|
||||
// inputInt prompts the user for input and returns the input as an integer.
|
||||
// A maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check.
|
||||
// inputInt prompts the user for input and returns the input as an integer
|
||||
// a maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check
|
||||
func inputInt(prompt string, maxValue int) int {
|
||||
if maxValue == 0 {
|
||||
return 0
|
||||
@@ -45,7 +52,7 @@ func inputInt(prompt string, maxValue int) int {
|
||||
}
|
||||
}
|
||||
|
||||
// inputBinary prompts the user with a yes/no question and returns the response as a boolean.
|
||||
// inputBinary prompts the user with a yes/no question and returns the response as a boolean
|
||||
func inputBinary(prompt string) bool {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Print("\n" + prompt + " (y/N) ")
|
||||
@@ -56,7 +63,7 @@ func inputBinary(prompt string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// inputMenuGen prompts the user with a menu and returns the user's choice as an integer.
|
||||
// inputMenuGen prompts the user with a menu and returns the user's choice as an integer
|
||||
func inputMenuGen(prompt string, options []string) int {
|
||||
for i, option := range options {
|
||||
fmt.Printf("%d. %s\n", i+1, option)
|
||||
@@ -64,21 +71,16 @@ func inputMenuGen(prompt string, options []string) int {
|
||||
return inputInt(prompt, len(options))
|
||||
}
|
||||
|
||||
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied).
|
||||
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets, verifyEntryDoesNotExist bool) {
|
||||
if core.EntryIsNotEmpty(unencryptedEntry) {
|
||||
// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied)
|
||||
func writeEntryCLI(targetLocation string, unencryptedEntry []string, hidePassword bool) {
|
||||
if backend.EntryIsNotEmpty(unencryptedEntry) {
|
||||
// write the entry to the target location
|
||||
core.WriteEntry(targetLocation, unencryptedEntry, verifyEntryDoesNotExist)
|
||||
backend.WriteEntry(targetLocation, unencryptedEntry)
|
||||
// preview the entry
|
||||
fmt.Println(AnsiBold + "\nEntry Preview:" + core.AnsiReset)
|
||||
EntryReader(unencryptedEntry, hideSecrets, true)
|
||||
fmt.Println(ansiBold + "\nEntry Preview:" + backend.AnsiReset)
|
||||
EntryReader(unencryptedEntry, hidePassword, true)
|
||||
} else {
|
||||
fmt.Println(core.AnsiError + "No data supplied for entry" + core.AnsiReset)
|
||||
os.Exit(core.ErrorTargetNotFound)
|
||||
fmt.Println(backend.AnsiError + "No data supplied for entry" + backend.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// expandPathWithHome, given a path (as a string) containing "~", returns the path with "~" expanded to the user's home directory.
|
||||
func expandPathWithHome(path string) string {
|
||||
return strings.Replace(path, "~", core.Home, 1)
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
## Known Bugs - MUTN CLI
|
||||
- Various Markdown issues resulting from the use of [Glamour](https://github.com/charmbracelet/glamour)
|
||||
- Note that MUTN is currently using the older Glamour v0.7.0, as v0.8.0 introduced a [line-wrapping regression](https://github.com/charmbracelet/glamour/issues/331)
|
||||
- [Odd handling of line breaks](https://github.com/charmbracelet/glamour/issues/84)
|
||||
- [Broken quotes](https://github.com/charmbracelet/glamour/issues/172) (seems related to line break issue)
|
||||
- [Extra blank lines after nested list items](https://github.com/charmbracelet/glamour/issues/102)
|
||||
- [Incorrect wrapping of text in lists](https://github.com/charmbracelet/glamour/issues/56)
|
||||
- [Excessive binary size and increased program startup time](https://github.com/charmbracelet/glamour/issues/288)
|
||||
- Relevant [libmutton bugs](https://github.com/rwinkhart/libmutton/blob/main/wiki/bugs.md)
|
||||
@@ -1,10 +0,0 @@
|
||||
## Building
|
||||
Official binaries are stripped of debug info for size and built without CGO (except for distribution packages) for portability, as follows:
|
||||
```
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./mutn.go
|
||||
```
|
||||
|
||||
Additionally, some custom build tags can be used to create different binaries. The following tags are not used in official builds:
|
||||
- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time)
|
||||
- `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL)
|
||||
- `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)
|
||||
@@ -1,35 +0,0 @@
|
||||
## Shell Completions Troubleshooting
|
||||
[Shell completions are provided for ZSH, Bash, and PowerShell 7+](https://github.com/rwinkhart/MUTN/tree/main/completions).
|
||||
### ZSH completions not working?
|
||||
Make sure your ~/.zshrc contains the following (if sourcing from default completions location, usually `/usr/share/zsh/site-functions/_mutn`):
|
||||
```shell
|
||||
autoload -Uz compinit && compinit
|
||||
```
|
||||
...and then restart your shell.
|
||||
***
|
||||
### Bash completions not working?
|
||||
Install your distribution's `bash-completion` package or source the completion script manually.
|
||||
|
||||
For most environments, manual sourcing means adding the following to your ~/.bashrc:
|
||||
```shell
|
||||
source /usr/share/bash-completion/completions/mutn
|
||||
```
|
||||
Note that this directory is different on FreeBSD.
|
||||
|
||||
FreeBSD:
|
||||
```shell
|
||||
source /usr/local/share/bash-completion/completions/mutn
|
||||
```
|
||||
...and then restart your shell.
|
||||
|
||||
*Please note that Bash completions are slightly more limited than ZSH completions, and as such, new entries will not be auto-completed until the completions script is re-sourced.*
|
||||
***
|
||||
### PowerShell completions not working?
|
||||
Ensure you are using modern PowerShell (7+) as opposed to the built-in Windows PowerShell.
|
||||
|
||||
Currently, completions must be manually installed and sourced in your PowerShell profile as such:
|
||||
```shell
|
||||
Set-PSReadlineKeyHandler -Key Tab -Function Complete # this line is optional; it makes tab completion function more similarly to Bash/ZSH
|
||||
. <drive letter>:\path\to\mutn.ps1
|
||||
```
|
||||
...and then restart your shell.
|
||||
@@ -1,17 +0,0 @@
|
||||
## Installation
|
||||
MUTN is still in early development and thus no installation packages are officially distributed.
|
||||
|
||||
For now, please manually install the binaries from the [latest release](https://github.com/rwinkhart/MUTN/releases) or [compile from source](https://github.com/rwinkhart/MUTN/blob/main/wiki/build.md). All pre-built binaries were compiled with CGO disabled and thus are libc-independent.
|
||||
|
||||
Additionally, MUTN is available as a source package ("[mutn](https://aur.archlinux.org/packages/mutn)") on the AUR.
|
||||
|
||||
Please note that the server binary (available in [libmutton releases](https://github.com/rwinkhart/libmutton/releases)) must be called "libmuttonserver" in order for clients to successfully reach it.
|
||||
|
||||
After placing the binaries in your $PATH, it is highly recommended to also download and correctly place/source the relevant [shell completions scripts](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md).
|
||||
|
||||
Please see the [usage guide](https://github.com/rwinkhart/MUTN/blob/main/wiki/usage.md) for help getting started.
|
||||
|
||||
### Dependencies (required for all installations)
|
||||
- GnuPG command-line utility (`gpg` command; will not be required in the future) for encryption/decryption
|
||||
- A text editor (preferably CLI-based) for writing entry notes
|
||||
- A private key for SSH key-based authentication is required to use MUTN/libmutton in online/synced mode
|
||||
@@ -1,24 +0,0 @@
|
||||
## Setup/Usage Tips - MUTN CLI
|
||||
Most information relevant to the usage of MUTN can be viewed with `mutn help`, in [the man page](https://raw.githubusercontent.com/rwinkhart/MUTN/main/docs/man), and in the demo animation from the README.
|
||||
|
||||
Because of this, this wiki page will focus on initial setup as well as some tips that may not be immediately obvious.
|
||||
|
||||
### Initial Setup
|
||||
libmutton operates on a client-server model, and thus sync support requires you to have access to your own server (whether it be a physical home server or a cloud rental) with remote access via SSH.
|
||||
|
||||
For security reasons, libmutton deliberately does not support password-based SSH authentication; you must use key-based authentication to connect to your server (password-protected keys are also supported). You are responsible for setting up SSH connectivity on your own.
|
||||
|
||||
The libmutton server software is shipped as its own dedicated binary (in [libmutton releases](https://github.com/rwinkhart/libmutton/releases)) and must be installed on the server and configured with `libmuttonserver init`. The server binary _**MUST**_ be in your $PATH and _**MUST**_ be named "libmuttonserver" for clients to successfully reach it.
|
||||
|
||||
Once this has been done, you may proceed with the client setup:
|
||||
1. Install MUTN
|
||||
2. Run `mutn init` and follow the prompts
|
||||
3. If you already have entries on the server, sync them using `mutn sync`
|
||||
4. Optionally, shell completions (Bash, ZSH, and PowerShell 7+) can be [enabled with your shell's respective method](https://github.com/rwinkhart/MUTN/blob/main/wiki/completions.md)
|
||||
|
||||
### Tips
|
||||
#### Operating on Passwords
|
||||
Any action that operates on the password attached to an entry (copying, editing, adding a new password-focused entry) does not require the user to specify the `password` or `-pw` options. In all cases, `password` is the assumed target when no other option is specified.
|
||||
|
||||
#### Granular Help
|
||||
Argument-specific help can be obtained by running `mutn <argument>` without an entry name or any options. For example, `mutn edit` will display help for the `edit` argument.
|
||||
Reference in New Issue
Block a user