- Add streamd serve start|stop|restart|status|update with auto-written streamd.yaml - Panel modules: STREAMD_MODULES_DIR for describe, YAML channel fallback, textarea value fix - Per-stream WireGuard/SOCKS egress profiles + Settings UI - Drop drm-* from release builds; track streamd-bg.sh / streamd-update.sh wrappers - Docs: streamd-server-setup lifecycle and update flow
80 lines
2 KiB
Go
80 lines
2 KiB
Go
package egress
|
|
|
|
import (
|
|
"bufio"
|
|
"strings"
|
|
)
|
|
|
|
// wgInterfaceAddrs extracts Address= values from the [Interface] section of a
|
|
// wg-quick style conf. Private keys are never returned or logged.
|
|
func wgInterfaceAddrs(conf string) []string {
|
|
var addrs []string
|
|
section := ""
|
|
sc := bufio.NewScanner(strings.NewReader(conf))
|
|
for sc.Scan() {
|
|
line := strings.TrimSpace(sc.Text())
|
|
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
|
|
section = strings.ToLower(strings.TrimSpace(line[1 : len(line)-1]))
|
|
continue
|
|
}
|
|
if section != "interface" {
|
|
continue
|
|
}
|
|
key, val, ok := strings.Cut(line, "=")
|
|
if !ok {
|
|
continue
|
|
}
|
|
if strings.EqualFold(strings.TrimSpace(key), "Address") {
|
|
for _, part := range strings.Split(val, ",") {
|
|
if a := strings.TrimSpace(part); a != "" {
|
|
addrs = append(addrs, a)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return addrs
|
|
}
|
|
|
|
// wgSetconfBody strips wg-quick-only keys so the result is valid for `wg setconf`.
|
|
func wgSetconfBody(conf string) string {
|
|
var b strings.Builder
|
|
section := ""
|
|
sc := bufio.NewScanner(strings.NewReader(conf))
|
|
for sc.Scan() {
|
|
raw := sc.Text()
|
|
line := strings.TrimSpace(raw)
|
|
if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
|
|
continue
|
|
}
|
|
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
|
|
section = strings.ToLower(strings.TrimSpace(line[1 : len(line)-1]))
|
|
b.WriteString(line)
|
|
b.WriteByte('\n')
|
|
continue
|
|
}
|
|
key, _, ok := strings.Cut(line, "=")
|
|
if !ok {
|
|
continue
|
|
}
|
|
k := strings.ToLower(strings.TrimSpace(key))
|
|
if section == "interface" {
|
|
switch k {
|
|
case "privatekey", "listenport", "fwmark":
|
|
b.WriteString(line)
|
|
b.WriteByte('\n')
|
|
}
|
|
continue
|
|
}
|
|
if section == "peer" {
|
|
switch k {
|
|
case "publickey", "presharedkey", "allowedips", "endpoint", "persistentkeepalive":
|
|
b.WriteString(line)
|
|
b.WriteByte('\n')
|
|
}
|
|
}
|
|
}
|
|
return b.String()
|
|
}
|