guichet/cli.go

45 lines
707 B
Go
Raw Permalink Normal View History

2023-09-25 08:27:49 +00:00
package main
import (
"flag"
"fmt"
"golang.org/x/term"
2023-09-26 06:40:41 +00:00
"os"
"syscall"
2023-09-25 08:27:49 +00:00
)
var fsCli = flag.NewFlagSet("cli", flag.ContinueOnError)
var passFlag = fsCli.Bool("passwd", false, "Tool to generate a guichet-compatible password hash")
func cliMain(args []string) {
if err := fsCli.Parse(args); err != nil {
fmt.Println(err)
os.Exit(1)
}
if *passFlag {
cliPasswd()
} else {
fsCli.PrintDefaults()
os.Exit(1)
}
}
func cliPasswd() {
fmt.Print("Password: ")
2023-09-26 06:40:41 +00:00
bytepw, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
2023-09-25 08:27:49 +00:00
fmt.Println(err)
2023-09-26 06:40:41 +00:00
os.Exit(1)
}
pass := string(bytepw)
2023-09-25 08:27:49 +00:00
hash, err := SSHAEncode(pass)
2023-09-26 06:40:41 +00:00
if err != nil {
2023-09-25 08:27:49 +00:00
fmt.Println(err)
2023-09-26 06:40:41 +00:00
os.Exit(1)
}
2023-09-25 08:27:49 +00:00
fmt.Println(hash)
}