fc7dbb0ac0
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat tool notify, auto-switch and schedule notices), the chat push outbox (its table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*. The app_notifications stream, subscribe/clear and kinds are unchanged. Notification settings keep run_finished/chat_needs_you/chat_reply_finished; ntfy_enabled is accepted and ignored and its stored row is never read. Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to the Pipelines apps — use the stage notify hook". The notify hook remains. Installer: no ntfy build, accounts, config or supervisor child; manifest gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log, with a note in logs/install.log); uninstall cleans leftovers. App: ntfy settings section replaced by "Notification events"; texts updated. Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli, author skill references updated; security review M1 marked resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.9 KiB
Go
83 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"sort"
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
func networkAddresses() []protocol.NetworkAddress {
|
|
result := []protocol.NetworkAddress{}
|
|
interfaces, _ := net.Interfaces()
|
|
for _, iface := range interfaces {
|
|
if iface.Flags&net.FlagUp == 0 {
|
|
continue
|
|
}
|
|
addresses, _ := iface.Addrs()
|
|
for _, address := range addresses {
|
|
ip, _, err := net.ParseCIDR(address.String())
|
|
if err != nil || ip.IsUnspecified() {
|
|
continue
|
|
}
|
|
text := ip.String()
|
|
if ip.IsLinkLocalUnicast() && ip.To4() == nil {
|
|
text += "%" + iface.Name
|
|
}
|
|
result = append(result, protocol.NetworkAddress{Interface: iface.Name, IP: text})
|
|
}
|
|
}
|
|
sort.Slice(result, func(i, j int) bool {
|
|
if result[i].Interface != result[j].Interface {
|
|
return result[i].Interface < result[j].Interface
|
|
}
|
|
return result[i].IP < result[j].IP
|
|
})
|
|
return result
|
|
}
|
|
|
|
func candidateURLs(addresses []protocol.NetworkAddress, scheme, port, path string) []string {
|
|
result := []string{}
|
|
for _, address := range addresses {
|
|
u := url.URL{Scheme: scheme, Host: net.JoinHostPort(address.IP, port), Path: path}
|
|
result = append(result, u.String())
|
|
}
|
|
return result
|
|
}
|
|
|
|
func systemStatus(r *http.Request, started time.Time, runErr error) *protocol.SystemStatus {
|
|
hostname, _ := os.Hostname()
|
|
s := &protocol.SystemStatus{Hostname: hostname, StartedAt: started.UTC().Format(time.RFC3339), Uptime: time.Since(started).Round(time.Second).String(), Addresses: networkAddresses(), Server: protocol.ServiceStatus{Health: "healthy"}, Note: "Addresses belong to the server computer (or container). Candidate URLs are not reachability checks; binding, firewalls, port mapping and TLS may differ."}
|
|
if runErr != nil {
|
|
s.Server.Health = "execution unavailable"
|
|
}
|
|
if address, ok := r.Context().Value(http.LocalAddrContextKey).(net.Addr); ok {
|
|
_, port, err := net.SplitHostPort(address.String())
|
|
if err == nil {
|
|
scheme := "ws"
|
|
if r.TLS != nil {
|
|
scheme = "wss"
|
|
}
|
|
s.Server.URL = (&url.URL{Scheme: scheme, Host: address.String(), Path: "/connect"}).String()
|
|
s.Server.Port = port
|
|
s.Server.Candidates = candidateURLs(s.Addresses, scheme, port, "/connect")
|
|
}
|
|
}
|
|
// Docker interface addresses are not the host's connection addresses. The
|
|
// installer publishes the detected host LAN IP and actual mapped host port.
|
|
if ip := net.ParseIP(os.Getenv("PIPELINES_HOST_IP")); ip != nil && !ip.IsLoopback() && !ip.IsUnspecified() {
|
|
if port, err := strconv.Atoi(os.Getenv("PIPELINES_PUBLIC_PORT")); err == nil && port > 0 && port <= 65535 {
|
|
s.Server.Port = strconv.Itoa(port)
|
|
s.Server.URL = (&url.URL{Scheme: "ws", Host: net.JoinHostPort(ip.String(), s.Server.Port), Path: "/connect"}).String()
|
|
s.Addresses = []protocol.NetworkAddress{{Interface: "LAN", IP: ip.String()}}
|
|
s.Server.Candidates = []string{s.Server.URL}
|
|
}
|
|
}
|
|
return s
|
|
}
|