/* Dethnote is a web app that stores secure encrypted notes which can only be unlocked 72 hours after the correct passphrase has been entered. */ package main import ( "flag" "fmt" "os" dethnote "git.kirsle.net/apps/dethnote/src" "git.kirsle.net/go/log" ) // Version of the app. var ( Version = "0.1.0" Build = "n/a" ) // CLI flags. var ( // -debug: enable debug mode for local dev debug bool // -root : directory on disk where the secure notes will be stored. // -r The default is to write to a directory called "notes" // in the current working directory. root string rootDefault = "./notes" // -smtp : mail server settings, like "user:password@localhost:25" smtpURL string // -listen
: listen on an HTTP port at this address. // -l
listen string listenDefault = ":1987" // -open: directly open a note via the server local command line. // The passphrase can be provided as CLI arguments. cmdOpen bool // -delete: delete a note via the server local command line, looking the // note up by its passphrase. The CLI arguments are the passphrase. cmdDelete bool // deleting a document via the CLI. ) // Log is a pretty ANSI color logger. var Log *log.Logger func init() { Log = log.GetLogger("dethnote") Log.Configure(&log.Config{ Level: log.InfoLevel, Colors: log.ExtendedColor, Theme: log.DarkTheme, }) flag.BoolVar(&debug, "debug", false, "Enable debug mode for local dev") flag.StringVar(&root, "root", rootDefault, "Directory to store the secure notes on disk") flag.StringVar(&root, "r", rootDefault, "Directory to store the secure notes on disk (shorthand)") flag.StringVar(&listen, "listen", listenDefault, "HTTP address to listen on") flag.StringVar(&listen, "l", listenDefault, "HTTP address to listen on (shorthand)") flag.StringVar(&smtpURL, "smtp", "localhost:22", "SMTP address for sending mail, in the format `[login:password@]server:port`") flag.BoolVar(&cmdOpen, "open", false, "Immediately open and print a secure note. The passphrase is provided via CLI arguments.") flag.BoolVar(&cmdDelete, "delete", false, "Immediately delete a secure note. The passphrase is provided via CLI arguments.") flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: dethnote [options] [-r rootdir] [passphrase]\n\n"+ "By default the web server will be started. However, there are options\n"+ "to interact with the encrypted message storage directly, via the\n"+ "server local command line, as a last resort option to open a note\n"+ "when access to e-mail sending is down or it's a time-sensitive matter.\n\n"+ "Examples:\n\n"+ " To run the web server and provide a directory where the notes\n"+ " are to be stored on disk:\n"+ " $ dethnote -root /var/lib/dethnote/notes\n"+ " $ dethnote -r /var/lib/dethnote/notes\n\n"+ " To immediately decrypt and open a note with its passphrase:\n"+ " $ dethnote -open \n"+ " $ dethnote -open correct horse battery staple\n"+ " $ dethnote -open \"correct horse battery staple\"\n\n"+ " To delete a secure note using its passphrase:\n"+ " $ dethnote -delete \n"+ " $ dethnote -delete correct horse battery staple\n\n"+ "Options:\n\n", ) flag.PrintDefaults() } } func main() { flag.Parse() if debug { Log.Config.Level = log.DebugLevel } if cmdOpen && cmdDelete { Log.Error("-open and -delete are mutually exclusive options.") os.Exit(1) } app := dethnote.NewServer(root, debug) if err := app.SetSMTP(smtpURL); err != nil { panic(err) } app.SetupHTTP() app.Run(listen) }