|
|
@@ -18,7 +18,10 @@ import (
|
|
|
func New() *cli.App {
|
|
|
flags := []cli.Flag{
|
|
|
&cli.StringFlag{Name: "config", Aliases: []string{"c"}, EnvVars: []string{"NTFY_CONFIG_FILE"}, Value: "/etc/ntfy/config.yml", DefaultText: "/etc/ntfy/config.yml", Usage: "config file"},
|
|
|
- altsrc.NewStringFlag(&cli.StringFlag{Name: "listen-http", Aliases: []string{"l"}, EnvVars: []string{"NTFY_LISTEN_HTTP"}, Value: config.DefaultListenHTTP, Usage: "ip:port used to as listen address"}),
|
|
|
+ altsrc.NewStringFlag(&cli.StringFlag{Name: "listen-http", Aliases: []string{"l"}, EnvVars: []string{"NTFY_LISTEN_HTTP"}, Value: config.DefaultListenHTTP, Usage: "ip:port used to as HTTP listen address"}),
|
|
|
+ altsrc.NewStringFlag(&cli.StringFlag{Name: "listen-https", Aliases: []string{"L"}, EnvVars: []string{"NTFY_LISTEN_HTTPS"}, Usage: "ip:port used to as HTTPS listen address"}),
|
|
|
+ altsrc.NewStringFlag(&cli.StringFlag{Name: "key-file", Aliases: []string{"K"}, EnvVars: []string{"NTFY_KEY_FILE"}, Usage: "private key file, if listen-https is set"}),
|
|
|
+ altsrc.NewStringFlag(&cli.StringFlag{Name: "cert-file", Aliases: []string{"E"}, EnvVars: []string{"NTFY_CERT_FILE"}, Usage: "certificate file, if listen-https is set"}),
|
|
|
altsrc.NewStringFlag(&cli.StringFlag{Name: "firebase-key-file", Aliases: []string{"F"}, EnvVars: []string{"NTFY_FIREBASE_KEY_FILE"}, Usage: "Firebase credentials file; if set additionally publish to FCM topic"}),
|
|
|
altsrc.NewStringFlag(&cli.StringFlag{Name: "cache-file", Aliases: []string{"C"}, EnvVars: []string{"NTFY_CACHE_FILE"}, Usage: "cache file used for message caching"}),
|
|
|
altsrc.NewDurationFlag(&cli.DurationFlag{Name: "cache-duration", Aliases: []string{"b"}, EnvVars: []string{"NTFY_CACHE_DURATION"}, Value: config.DefaultCacheDuration, Usage: "buffer messages for this time to allow `since` requests"}),
|
|
|
@@ -50,6 +53,9 @@ func New() *cli.App {
|
|
|
func execRun(c *cli.Context) error {
|
|
|
// Read all the options
|
|
|
listenHTTP := c.String("listen-http")
|
|
|
+ listenHTTPS := c.String("listen-https")
|
|
|
+ keyFile := c.String("key-file")
|
|
|
+ certFile := c.String("cert-file")
|
|
|
firebaseKeyFile := c.String("firebase-key-file")
|
|
|
cacheFile := c.String("cache-file")
|
|
|
cacheDuration := c.Duration("cache-duration")
|
|
|
@@ -70,10 +76,19 @@ func execRun(c *cli.Context) error {
|
|
|
return errors.New("manager interval cannot be lower than five seconds")
|
|
|
} else if cacheDuration < managerInterval {
|
|
|
return errors.New("cache duration cannot be lower than manager interval")
|
|
|
+ } else if keyFile != "" && !util.FileExists(keyFile) {
|
|
|
+ return errors.New("if set, key file must exist")
|
|
|
+ } else if certFile != "" && !util.FileExists(certFile) {
|
|
|
+ return errors.New("if set, certificate file must exist")
|
|
|
+ } else if listenHTTPS != "" && (keyFile == "" || certFile == "") {
|
|
|
+ return errors.New("if listen-https is set, both key-file and cert-file must be set")
|
|
|
}
|
|
|
|
|
|
// Run server
|
|
|
conf := config.New(listenHTTP)
|
|
|
+ conf.ListenHTTPS = listenHTTPS
|
|
|
+ conf.KeyFile = keyFile
|
|
|
+ conf.CertFile = certFile
|
|
|
conf.FirebaseKeyFile = firebaseKeyFile
|
|
|
conf.CacheFile = cacheFile
|
|
|
conf.CacheDuration = cacheDuration
|