2017-03-22 20:29:08 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-10-17 21:01:28 -04:00
|
|
|
"golang.org/x/term"
|
|
|
|
"os"
|
2017-03-22 20:29:08 -04:00
|
|
|
)
|
|
|
|
|
2017-04-16 20:50:06 -04:00
|
|
|
type command struct {
|
2017-03-22 20:29:08 -04:00
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Flags *flag.FlagSet
|
|
|
|
CheckFlags func() bool // Check the flag values after they're parsed, printing errors and returning false if they're incorrect
|
|
|
|
Do func() // Run the command (only called if CheckFlags returns true)
|
|
|
|
}
|
|
|
|
|
2017-04-16 20:50:06 -04:00
|
|
|
func (c *command) usage() {
|
2017-03-22 20:29:08 -04:00
|
|
|
fmt.Printf("Usage of %s:\n", c.Name)
|
|
|
|
c.Flags.PrintDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
// flags common to all server transactions
|
2017-04-12 21:40:42 -04:00
|
|
|
var serverURL, username, password, org, fid, appID, appVer, ofxVersion, clientUID string
|
2017-03-22 20:29:08 -04:00
|
|
|
var noIndentRequests bool
|
2020-11-17 09:20:27 -05:00
|
|
|
var carriageReturn bool
|
2020-12-07 13:37:43 -05:00
|
|
|
var dryrun bool
|
2021-03-16 15:24:36 -04:00
|
|
|
var userAgent string
|
2017-03-22 20:29:08 -04:00
|
|
|
|
|
|
|
func defineServerFlags(f *flag.FlagSet) {
|
|
|
|
f.StringVar(&serverURL, "url", "", "Financial institution's OFX Server URL (see ofxhome.com if you don't know it)")
|
|
|
|
f.StringVar(&username, "username", "", "Your username at financial institution")
|
|
|
|
f.StringVar(&password, "password", "", "Your password at financial institution")
|
|
|
|
f.StringVar(&org, "org", "", "'ORG' for your financial institution")
|
|
|
|
f.StringVar(&fid, "fid", "", "'FID' for your financial institution")
|
2017-04-12 21:40:42 -04:00
|
|
|
f.StringVar(&appID, "appid", "QWIN", "'APPID' to pretend to be")
|
2017-03-22 20:29:08 -04:00
|
|
|
f.StringVar(&appVer, "appver", "2400", "'APPVER' to pretend to be")
|
|
|
|
f.StringVar(&ofxVersion, "ofxversion", "203", "OFX version to use")
|
|
|
|
f.StringVar(&clientUID, "clientuid", "", "Client UID (only required by a few FIs, like Chase)")
|
|
|
|
f.BoolVar(&noIndentRequests, "noindent", false, "Don't indent OFX requests")
|
2020-11-17 09:20:27 -05:00
|
|
|
f.BoolVar(&carriageReturn, "carriagereturn", false, "Use carriage return as line separator")
|
2021-03-16 15:24:36 -04:00
|
|
|
f.StringVar(&userAgent, "useragent", "", "Use string as User-Agent header when sending request")
|
2020-12-07 13:37:43 -05:00
|
|
|
f.BoolVar(&dryrun, "dryrun", false, "Don't send request - print content of request instead")
|
2017-03-22 20:29:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkServerFlags() bool {
|
|
|
|
var ret bool = true
|
|
|
|
if len(serverURL) == 0 {
|
|
|
|
fmt.Println("Error: Server URL empty")
|
|
|
|
ret = false
|
|
|
|
}
|
|
|
|
if len(username) == 0 {
|
|
|
|
fmt.Println("Error: Username empty")
|
|
|
|
ret = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if ret && len(password) == 0 {
|
|
|
|
fmt.Printf("Password for %s: ", username)
|
2021-10-17 21:01:28 -04:00
|
|
|
pass, err := term.ReadPassword(int(os.Stdin.Fd()))
|
2017-03-22 20:29:08 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error reading password: %s\n", err)
|
|
|
|
ret = false
|
|
|
|
} else {
|
|
|
|
password = string(pass)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|