Manage external site-prober actions va API and Dashboard
This commit is contained in:
1 parent
f22ad569b6
commit
42f584dd3c
28 files changed
+717
-32
No files matched your search
@@ -4,16 +4,22 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type settingsPageData struct {
|
||||
PageData
|
||||
Settings orchestratorSettingsDTO
|
||||
Inbound inboundChecksDTO
|
||||
}
|
||||
|
||||
func (s *Server) handleSettingsPage(w http.ResponseWriter, r *http.Request) {
|
||||
settings, err := s.CA.GetOrchestratorSettings(r.Context())
|
||||
data := settingsPageData{Settings: settings}
|
||||
inbound, inboundErr := s.CA.GetInboundChecks(r.Context())
|
||||
if err == nil {
|
||||
err = inboundErr
|
||||
}
|
||||
data := settingsPageData{Settings: settings, Inbound: inbound}
|
||||
data.ActiveNav = "settings"
|
||||
data.Banner = bannerFor(err)
|
||||
s.renderPage(w, "settings_page", data)
|
||||
@@ -28,7 +34,11 @@ func (s *Server) renderSettingsForm(w http.ResponseWriter, r *http.Request, acti
|
||||
if actionErr == nil {
|
||||
actionErr = getErr
|
||||
}
|
||||
s.renderFragment(w, "settings_form", settingsPageData{Settings: settings}, actionErr)
|
||||
inbound, inboundErr := s.CA.GetInboundChecks(r.Context())
|
||||
if actionErr == nil {
|
||||
actionErr = inboundErr
|
||||
}
|
||||
s.renderFragment(w, "settings_form", settingsPageData{Settings: settings, Inbound: inbound}, actionErr)
|
||||
}
|
||||
|
||||
func (s *Server) handleSettingsPut(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -44,3 +54,34 @@ func (s *Server) handleSettingsPut(w http.ResponseWriter, r *http.Request) {
|
||||
_, err = s.CA.PutOrchestratorSettings(r.Context(), seconds)
|
||||
s.renderSettingsForm(w, r, err)
|
||||
}
|
||||
|
||||
// handleInboundChecksPut parses the comma-separated ports field of the
|
||||
// second form on /settings and saves it via PUT
|
||||
// /api/v1/admin/config/inbound-checks. A separate form/handler from
|
||||
// fip_settle_seconds above — the two settings are unrelated and shouldn't
|
||||
// share one submit.
|
||||
func (s *Server) handleInboundChecksPut(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
s.renderSettingsForm(w, r, fmt.Errorf("invalid form: %w", err))
|
||||
return
|
||||
}
|
||||
raw := strings.TrimSpace(r.PostFormValue("ports"))
|
||||
var ports []int
|
||||
if raw != "" {
|
||||
for _, part := range strings.Split(raw, ",") {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
p, err := strconv.Atoi(part)
|
||||
if err != nil {
|
||||
s.renderSettingsForm(w, r, &apiErr{Status: http.StatusBadRequest, Message: "порты должны быть целыми числами через запятую"})
|
||||
return
|
||||
}
|
||||
ports = append(ports, p)
|
||||
}
|
||||
}
|
||||
icmp := r.PostFormValue("icmp") == "on"
|
||||
_, err := s.CA.PutInboundChecks(r.Context(), ports, icmp)
|
||||
s.renderSettingsForm(w, r, err)
|
||||
}
|
||||
Reference in new issue
Block a user