1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-07 04:14:16 +01:00
ntfy/cmd/web_push.go

64 lines
1.3 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{
2023-05-29 17:57:21 +02:00
Name: "web-push",
Usage: "Generate keys, in the future manage web push subscriptions",
UsageText: "ntfy web-push [generate-keys]",
Category: categoryServer,
2023-05-29 17:57:21 +02:00
Subcommands: []*cli.Command{
{
Action: generateWebPushKeys,
Name: "generate-keys",
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
}
2023-05-29 17:57:21 +02:00
fmt.Fprintf(c.App.ErrWriter, `Keys generated.
VAPID Public Key:
%s
VAPID Private Key:
%s
---
Add the following lines to your config file:
web-push-enabled: true
web-push-public-key: %s
web-push-private-key: %s
web-push-subscriptions-file: <filename>
web-push-email-address: <email address>
2023-05-29 17:57:21 +02:00
Look at the docs for other methods (e.g. command line flags & environment variables).
You will also need to set a base-url.
`, publicKey, privateKey, publicKey, privateKey)
return nil
}