1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package main
import (
"fmt"
"io"
"log/slog"
"net/netip"
"within.website/x/internal/key2hex"
)
type IRC struct {
Server string `json:"server"`
Password string `json:"password"`
Channel string `json:"channel"`
Regex string `json:"regex"`
Nick string `json:"nick"`
User string `json:"user"`
Real string `json:"real"`
}
type Show struct {
Title string `json:"title"`
DiskPath string `json:"diskPath"`
Quality string `json:"quality"`
}
func (s Show) LogValue() slog.Value {
return slog.GroupValue(
slog.String("title", s.Title),
slog.String("disk_path", s.DiskPath),
slog.String("quality", s.Quality),
)
}
type Transmission struct {
URL string `json:"url"`
User string `json:"user"`
Password string `json:"password"`
}
type Tailscale struct {
Hostname string `json:"hostname"`
Authkey string `json:"authkey"`
DataDir *string `json:"dataDir,omitempty"`
}
type Telegram struct {
Token string `json:"token"`
MentionUser int64 `json:"mentionUser"`
}
type WireGuard struct {
PrivateKey string `json:"privateKey"`
Address []netip.Addr `json:"address"`
DNS netip.Addr `json:"dns"`
Peers []WireGuardPeer `json:"peers"`
}
type WireGuardPeer struct {
PublicKey string `json:"publicKey"`
AllowedIPs []string `json:"allowedIPs"`
Endpoint string `json:"endpoint"`
}
func (w WireGuard) UAPI(out io.Writer) error {
pkey, err := key2hex.Convert(w.PrivateKey)
if err != nil {
return err
}
fmt.Fprintf(out, "private_key=%s\n", pkey)
fmt.Fprintln(out, "listen_port=0")
fmt.Fprintln(out, "replace_peers=true")
for _, peer := range w.Peers {
pkey, err := key2hex.Convert(peer.PublicKey)
if err != nil {
return err
}
fmt.Fprintf(out, "public_key=%s\n", pkey)
fmt.Fprintf(out, "endpoint=%s\n", peer.Endpoint)
for _, ip := range peer.AllowedIPs {
fmt.Fprintf(out, "allowed_ip=%s\n", ip)
}
fmt.Fprintln(out, "persistent_keepalive_interval=25")
}
return nil
}
type Config struct {
IRC IRC `json:"irc"`
XDCC IRC `json:"xdcc"`
Transmission Transmission `json:"transmission"`
Shows []Show `json:"shows"`
RSSKey string `json:"rssKey"`
Tailscale Tailscale `json:"tailscale"`
BaseDiskPath string `json:"baseDiskPath"`
Telegram Telegram `json:"telegram"`
WireGuard WireGuard `json:"wireguard"`
}
|