ntfy/cmd/webpush.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.1 KiB
Go
Raw Normal View History

//go:build !noserver
package cmd
import (
"fmt"
"github.com/SherClockHolmes/webpush-go"
"github.com/urfave/cli/v2"
)
func init() {
commands = append(commands, cmdWebPush)
}
var cmdWebPush = &cli.Command{
Name: "webpush",
2023-05-29 18:57:21 +03:00
Usage: "Generate keys, in the future manage web push subscriptions",
UsageText: "ntfy web-push [generate-keys]",
Category: categoryServer,
2023-05-29 18:57:21 +03:00
Subcommands: []*cli.Command{
{
Action: generateWebPushKeys,
Name: "keys",
2023-05-29 18:57:21 +03:00
Usage: "Generate VAPID keys to enable browser background push notifications",
UsageText: "ntfy web-push generate-keys",
Category: categoryServer,
},
},
}
func generateWebPushKeys(c *cli.Context) error {
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
if err != nil {
return err
}
fmt.Fprintf(c.App.ErrWriter, `Web Push keys generated. Add the following lines to your config file:
2023-05-29 18:57:21 +03:00
web-push-public-key: %s
web-push-private-key: %s
web-push-subscriptions-file: /var/cache/ntfy/webpush.db # or similar
web-push-email-address: <email address>
2023-05-29 18:57:21 +03:00
See https://ntfy.sh/docs/config/#web-push for details.
`, publicKey, privateKey)
return nil
}