⛳ alerts for any ctfd instance via ntfy
1package main
2
3import (
4 "context"
5 "log"
6 "os"
7
8 "github.com/charmbracelet/fang"
9 "github.com/spf13/cobra"
10 "github.com/taciturnaxolotl/ctfd-alerts/clients"
11 "github.com/taciturnaxolotl/ctfd-alerts/cmd/serve"
12 "github.com/taciturnaxolotl/ctfd-alerts/cmd/status"
13)
14
15var (
16 debugLog *log.Logger
17)
18
19// rootCmd represents the base command
20var cmd = &cobra.Command{
21 Use: "ctfd-alerts",
22 Short: "A tool for monitoring CTFd competitions",
23 Long: ` _ __ _ _ _
24 ___| |_ / _| __| | __ _| | ___ _ __| |_ ___
25 / __| __| |_ / _, |_____ / _ | |/ _ \ '__| __/ __|
26| (__| |_| _| (_| |_____| (_| | | __/ | | |_\__ \
27 \___|\__|_| \__,_| \__,_|_|\___|_| \__|___/
28
29ctfd-alerts is a command-line tool that helps you monitor CTFd-based
30competitions by sending you ntfy notifications when someone bypasses
31you or a new challenge is announced. You can also use the fancy status command :)`,
32 PersistentPreRun: func(cmd *cobra.Command, args []string) {
33 configFile, _ := cmd.Flags().GetString("config")
34 var err error
35 config, err = loadConfig(configFile)
36 if err != nil {
37 log.Fatalf("Error loading config: %v", err)
38 }
39
40 setupLogging(config.Debug)
41
42 // Create a new CTFd client and add it to context
43 ctfdClient := clients.NewCTFdClient(config.CTFdConfig.ApiBase, config.CTFdConfig.ApiKey)
44 ctx := context.WithValue(cmd.Context(), "ctfd_client", ctfdClient)
45 ctx = context.WithValue(ctx, "config", config)
46 cmd.SetContext(ctx)
47 },
48}
49
50func init() {
51 // Add persistent flags that work across all commands
52 cmd.PersistentFlags().StringP("config", "c", "config.toml", "config file path")
53
54 // Add commands
55 cmd.AddCommand(status.StatusCmd)
56 cmd.AddCommand(serve.ServeCmd)
57}
58
59func main() {
60 if err := fang.Execute(
61 context.Background(),
62 cmd,
63 ); err != nil {
64 os.Exit(1)
65 }
66}