package server import ( "fmt" "net/http" "net/url" "prism/service/notification" "prism/service/signal" "prism/service/util" ) func (s *Server) handleFragmentHealth(w http.ResponseWriter, r *http.Request) { linked := s.getLinkedAccount() signalOk := s.signalDaemon.IsRunning() hasProton := s.cfg.IsProtonEnabled() w.Header().Set("Content-Type", "text/html") statusClass := "status-error" statusText := "Disconnected and Unlinked" var tooltip string if signalOk && linked != nil { statusClass = "status-ok" statusText = "Connected and Linked" tooltip = fmt.Sprintf(`%s`, util.FormatPhoneNumber(linked.Number)) } else if signalOk { statusText = "Connected and Unlinked" } html := fmt.Sprintf(`
Signal: %s%s
`, statusClass, statusText, tooltip) if hasProton { protonStatus := "Disconnected" protonClass := "status-error" if s.protonMonitor.IsConnected() { protonStatus = "Connected" protonClass = "status-ok" } html += fmt.Sprintf(`
Proton Mail: %s
`, protonClass, protonStatus) } html += `
` html += s.getSignalInfoHTML() html += `
` _, _ = fmt.Fprint(w, html) //nolint:errcheck // Error writing to ResponseWriter is handled by HTTP server } func (s *Server) handleFragmentSignalInfo(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") _, _ = fmt.Fprint(w, s.getSignalInfoHTML()) //nolint:errcheck } func (s *Server) getSignalInfoHTML() string { if s.getLinkedAccount() != nil { return fmt.Sprintf(`
`, s.cfg.DeviceName) } return fmt.Sprintf(`
%s
`, s.getQRCodeHTML()) } func (s *Server) getLinkedAccount() *signal.AccountInfo { client := signal.NewClient(s.cfg.SignalCLISocketPath) account, _ := client.GetLinkedAccount() //nolint:errcheck // Nil account is valid, indicates not linked return account } func (s *Server) getQRCodeHTML() string { if s.getLinkedAccount() != nil { return `

Account already linked

` } qrCode, err := s.linkDevice.GenerateQR() if err != nil { s.logger.Error("Failed to generate QR code", "error", err) return `

Signal daemon is starting up, please refresh in a few seconds...

` } return fmt.Sprintf(`

Scan this QR code with your Signal app:

Settings → Linked Devices → Link New Device

QR Code
`, qrCode) } func (s *Server) handleFragmentEndpoints(w http.ResponseWriter, r *http.Request) { mappings, err := s.store.GetAllMappings() if err != nil { s.logger.Error("Failed to get mappings", "error", err) http.Error(w, "Internal server error", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "text/html") if len(mappings) == 0 { _, _ = fmt.Fprint(w, `

No endpoints registered

`) //nolint:errcheck return } _, _ = fmt.Fprint(w, ``) //nolint:errcheck }