diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2ac45e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +password.txt diff --git a/fafomo.go b/fafomo.go index 2c519c8..1dda2a9 100644 --- a/fafomo.go +++ b/fafomo.go @@ -122,17 +122,17 @@ func update(ctx context.Context) (string, error) { } var ( - flagMatrixHomeserver = "matrix.org" - flagMatrixUsername = "@fafomo:matrix.org" - flagMatrixPassword string - flagMatrixRoom string - flagBackendURL string + flagMatrixHomeserver = "matrix.org" + flagMatrixUsername = "@fafomo:matrix.org" + flagMatrixPasswordFile = "password.txt" + flagMatrixRoom string + flagBackendURL string ) func main() { flag.StringVar(&flagMatrixHomeserver, "matrix_homeserver", flagMatrixHomeserver, "Address of Matrix homeserver") flag.StringVar(&flagMatrixUsername, "matrix_username", flagMatrixUsername, "Matrix login username") - flag.StringVar(&flagMatrixPassword, "matrix_password", flagMatrixPassword, "Matrix login password") + flag.StringVar(&flagMatrixPasswordFile, "matrix_password_file", flagMatrixPasswordFile, "Path to file containing matrix login password") flag.StringVar(&flagMatrixRoom, "matrix_room", flagMatrixRoom, "Matrix room MXID") flag.StringVar(&flagBackendURL, "backend_url", flagBackendURL, "Checkinator (backend) addresss") flag.Parse() @@ -143,7 +143,7 @@ func main() { }{ {flagMatrixHomeserver, "matrix_homeserver"}, {flagMatrixUsername, "matrix_username"}, - {flagMatrixPassword, "matrix_password"}, + {flagMatrixPasswordFile, "matrix_password_file"}, {flagMatrixRoom, "matrix_room"}, {flagBackendURL, "backend_url"}, } { @@ -164,12 +164,18 @@ func main() { klog.Exitf("NewClient failed: %v", err) } + passwordBytes, err := os.ReadFile(flagMatrixPasswordFile) + if err != nil { + klog.Exitf("Could not read password file: %v", err) + } + password := strings.TrimSpace(string(passwordBytes)) + klog.Infof("Logging in...") login, err := client.Login(startCtx, &mautrix.ReqLogin{ Type: mautrix.AuthTypePassword, Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: flagMatrixUsername}, - Password: flagMatrixPassword, + Password: password, }) if err != nil { klog.Exitf("Failed to log in: %v", err)