Replace Python launcher with native Go UI
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -74,6 +75,7 @@ func main() {
|
||||
server := flag.String("server", "localhost:64738", "the server to connect to")
|
||||
username := flag.String("username", "", "the username of the client")
|
||||
password := flag.String("password", "", "the password of the server")
|
||||
passwordFile := flag.String("password-file", "", "read the server password from a file")
|
||||
insecure := flag.Bool("insecure", false, "skip server certificate verification")
|
||||
certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
|
||||
cfgfn := flag.String("config", "~/.barnard.toml", "Path to TOML formatted configuration file")
|
||||
@@ -229,7 +231,11 @@ func main() {
|
||||
b.NoiseSuppressor.SetEnabled(enabled)
|
||||
|
||||
b.Config.Username = *username
|
||||
b.Config.Password = *password
|
||||
resolvedPassword, err := resolve_password(*password, *passwordFile)
|
||||
if err != nil {
|
||||
handle_raw_error(err)
|
||||
}
|
||||
b.Config.Password = resolvedPassword
|
||||
|
||||
if *insecure {
|
||||
b.TLSConfig.InsecureSkipVerify = true
|
||||
@@ -255,6 +261,40 @@ func main() {
|
||||
handle_error(&b)
|
||||
}
|
||||
|
||||
func resolve_password(password, passwordFile string) (string, error) {
|
||||
if passwordFile == "" {
|
||||
return password, nil
|
||||
}
|
||||
if password != "" {
|
||||
return "", fmt.Errorf("password and password-file cannot be used together")
|
||||
}
|
||||
file, err := os.Open(passwordFile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read password file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("inspect password file: %w", err)
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
return "", fmt.Errorf("password file must be a regular file")
|
||||
}
|
||||
const maximumPasswordFileSize = 4096
|
||||
contents, err := io.ReadAll(io.LimitReader(file, maximumPasswordFileSize+1))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read password file: %w", err)
|
||||
}
|
||||
if len(contents) > maximumPasswordFileSize {
|
||||
return "", fmt.Errorf("password file is too large")
|
||||
}
|
||||
contents = []byte(strings.TrimSuffix(strings.TrimSuffix(string(contents), "\n"), "\r"))
|
||||
if strings.ContainsAny(string(contents), "\r\n") {
|
||||
return "", fmt.Errorf("password file must contain exactly one line")
|
||||
}
|
||||
return string(contents), nil
|
||||
}
|
||||
|
||||
// audioIntervalDuration converts the packet duration requested at startup to
|
||||
// one of the Opus durations supported by Mumble.
|
||||
func audioIntervalDuration(milliseconds int) (time.Duration, error) {
|
||||
|
||||
Reference in New Issue
Block a user