From 23e8e3eb065761f7e9a92e99e9c388384e0a2dca Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 25 Nov 2026 20:33:49 +0000 Subject: [PATCH 1/2] Fix: restore the proxy pool removed in 0.7.0 Restore the multi-proxy egress pool that 0.7.0 dropped (issue #545), bringing back GET /api/settings/proxy-pool (list/add/delete), per-entry enable/disable and active selection, egress-IP testing, and a rotation strategy (none / on_failure / timed), plus a settings UI to manage it. - db: migration 0015_proxy_pool.sql plus schema.sql table (id, address, enabled, active, last_tested, egress_ip, fail_count) - server: Manager methods (ProxyPool, Add/Delete/SetProxyPoolEntry, ProxyPoolRotation, TestProxyPoolEntry), proxy-pool routes and handlers, proxy_pool/proxy_pool_rotation in the settings payload - web: ProxyPoolEntry type, proxy-pool API client, ProxyPoolCard in System settings --- db/migrations/0015_proxy_pool.sql | 18 + db/schema.sql | 17 + server/manager.go | 238 +++++++++++++ server/server.go | 130 +++++++ web/src/app/(main)/system/settings/page.tsx | 3 + .../system/settings/proxy-pool-card.tsx | 322 ++++++++++++++++++ web/src/lib/api.ts | 15 + web/src/lib/types.ts | 15 + 8 files changed, 758 insertions(+) create mode 100644 db/migrations/0015_proxy_pool.sql create mode 100644 web/src/app/(main)/system/settings/proxy-pool-card.tsx diff --git a/db/migrations/0015_proxy_pool.sql b/db/migrations/0015_proxy_pool.sql new file mode 100644 index 000000000..287245e81 --- /dev/null +++ b/db/migrations/0015_proxy_pool.sql @@ -0,0 +1,18 @@ +-- Restores the ARTEX proxy pool (dropped in 0.7.0): a list of egress proxies +-- with enable/disable, active selection, last-test timestamp, detected egress +-- IP and failure count. One entry may be active at a time (enforced in the +-- application layer when activating). +CREATE TABLE IF NOT EXISTS proxy_pool ( + id BIGSERIAL PRIMARY KEY, + address TEXT NOT NULL, + enabled BOOLEAN NOT NULL DEFAULT true, + active BOOLEAN NOT NULL DEFAULT false, + last_tested TIMESTAMPTZ, + egress_ip TEXT, + fail_count INTEGER NOT NULL DEFAULT 0, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_proxy_pool_active ON proxy_pool(active) WHERE active; +CREATE INDEX IF NOT EXISTS idx_proxy_pool_enabled ON proxy_pool(enabled) WHERE enabled; diff --git a/db/schema.sql b/db/schema.sql index 62331a3e9..0ef3bc693 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -367,6 +367,23 @@ CREATE TABLE IF NOT EXISTS settings ( updated_at TIMESTAMPTZ NOT NULL DEFAULT now() ); +-- Proxy pool (restored in 0.7.x): list of egress proxies with enable/disable, +-- active selection, last-test timestamp, detected egress IP and failure count. +CREATE TABLE IF NOT EXISTS proxy_pool ( + id BIGSERIAL PRIMARY KEY, + address TEXT NOT NULL, + enabled BOOLEAN NOT NULL DEFAULT true, + active BOOLEAN NOT NULL DEFAULT false, + last_tested TIMESTAMPTZ, + egress_ip TEXT, + fail_count INTEGER NOT NULL DEFAULT 0, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE INDEX IF NOT EXISTS idx_proxy_pool_active ON proxy_pool(active) WHERE active; +CREATE INDEX IF NOT EXISTS idx_proxy_pool_enabled ON proxy_pool(enabled) WHERE enabled; + CREATE TABLE IF NOT EXISTS llm_profiles ( id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL UNIQUE, diff --git a/server/manager.go b/server/manager.go index 2da3ea942..cff4eb875 100644 --- a/server/manager.go +++ b/server/manager.go @@ -6,7 +6,10 @@ import ( "encoding/json" "errors" "fmt" + "io" "log" + "net" + "net/http" "net/url" "os" "path/filepath" @@ -24,6 +27,7 @@ import ( "github.com/Autumn-27/artex/enrich" "github.com/Autumn-27/artex/guard" "github.com/Autumn-27/artex/intercept" + netproxy "golang.org/x/net/proxy" "github.com/Autumn-27/artex/traffic" "github.com/Autumn-27/artex/traffic/rewrite" actool "github.com/Autumn-27/norma/tool" @@ -987,6 +991,240 @@ func (m *Manager) SetGlobalProxy(raw string) error { return nil } +// ProxyPoolEntry is one egress proxy in the restored pool (0.7.x regression fix). +// Only one entry may be active at a time; activation is handled by +// SetProxyPoolEntry which deactivates every other entry first. +type ProxyPoolEntry struct { + ID int64 `json:"id"` + Address string `json:"address"` + Enabled bool `json:"enabled"` + Active bool `json:"active"` + LastTested int64 `json:"last_tested,omitempty"` // unix seconds, 0 = never tested + EgressIP string `json:"egress_ip,omitempty"` + FailCount int `json:"fail_count,omitempty"` + CreatedAt int64 `json:"created_at,omitempty"` // unix seconds +} + +// ProxyPoolRotation values. +const ( + ProxyPoolRotationNone = "none" // use the active proxy only (or direct if none active) + ProxyPoolRotationOnFailure = "on_failure" // rotate to the next enabled proxy on failure + ProxyPoolRotationTimed = "timed" // rotate on a timer +) + +var proxyPoolRotations = map[string]bool{ + ProxyPoolRotationNone: true, + ProxyPoolRotationOnFailure: true, + ProxyPoolRotationTimed: true, +} + +// settingProxyPoolRotation is the stored rotation strategy key. +const settingProxyPoolRotation = "proxy_pool_rotation" + +// ProxyPool lists every pool entry, newest first. +func (m *Manager) ProxyPool() ([]ProxyPoolEntry, error) { + rows, err := m.pg.Query(` + SELECT id, address, enabled, active, + COALESCE(EXTRACT(EPOCH FROM last_tested)::bigint, 0), + egress_ip, fail_count, + COALESCE(EXTRACT(EPOCH FROM created_at)::bigint, 0) + FROM proxy_pool ORDER BY id DESC`) + if err != nil { + return nil, err + } + defer rows.Close() //nolint:errcheck + var out []ProxyPoolEntry + for rows.Next() { + var e ProxyPoolEntry + if err := rows.Scan(&e.ID, &e.Address, &e.Enabled, &e.Active, &e.LastTested, &e.EgressIP, &e.FailCount, &e.CreatedAt); err != nil { + return nil, err + } + out = append(out, e) + } + if err := rows.Err(); err != nil { + return nil, err + } + if out == nil { + out = []ProxyPoolEntry{} + } + return out, nil +} + +// ProxyPoolRotation returns the stored rotation strategy (default "none"). +func (m *Manager) ProxyPoolRotation() string { + v, _, err := m.pg.GetSetting(settingProxyPoolRotation) + if err != nil || v == "" { + return ProxyPoolRotationNone + } + if !proxyPoolRotations[v] { + return ProxyPoolRotationNone + } + return v +} + +// SetProxyPoolRotation persists the rotation strategy. +func (m *Manager) SetProxyPoolRotation(strategy string) error { + strategy = strings.TrimSpace(strategy) + if strategy == "" { + strategy = ProxyPoolRotationNone + } + if !proxyPoolRotations[strategy] { + return fmt.Errorf("unknown proxy pool rotation %q (use none, on_failure or timed)", strategy) + } + return m.pg.SetSetting(settingProxyPoolRotation, strategy) +} + +// AddProxyPoolEntry validates, persists and returns a new pool entry. An empty +// address is rejected; duplicates (same address) are rejected. +func (m *Manager) AddProxyPoolEntry(address string) (int64, error) { + address = strings.TrimSpace(address) + if address == "" { + return 0, errors.New("proxy address is required") + } + if _, err := traffic.ValidateProxyURL(address); err != nil { + return 0, err + } + // Reject exact duplicates so the pool never holds the same proxy twice. + var exists int + if err := m.pg.QueryRow(`SELECT COUNT(*) FROM proxy_pool WHERE address=$1`, address).Scan(&exists); err != nil { + return 0, err + } + if exists > 0 { + return 0, fmt.Errorf("proxy %q is already in the pool", address) + } + var id int64 + if err := m.pg.QueryRow(` + INSERT INTO proxy_pool(address, enabled, active, created_at, updated_at) + VALUES ($1, true, false, now(), now()) + RETURNING id`, address).Scan(&id); err != nil { + return 0, err + } + return id, nil +} + +// DeleteProxyPoolEntry removes one pool entry by id. It is a no-op (not an +// error) when the id does not exist. +func (m *Manager) DeleteProxyPoolEntry(id int64) error { + res, err := m.pg.Exec(`DELETE FROM proxy_pool WHERE id=$1`, id) + if err != nil { + return err + } + if n, _ := res.RowsAffected(); n == 0 { + return nil + } + return nil +} + +// SetProxyPoolEntry toggles enabled and/or active on one entry. Activating an +// entry deactivates every other entry (only one proxy may be active at a time). +func (m *Manager) SetProxyPoolEntry(id int64, enabled, active *bool) error { + tx, err := m.pg.Begin() + if err != nil { + return err + } + defer tx.Rollback() //nolint:errcheck + if active != nil && *active { + if _, err := tx.Exec(`UPDATE proxy_pool SET active=false, updated_at=now() WHERE active`); err != nil { + return err + } + } + if enabled != nil { + if _, err := tx.Exec(`UPDATE proxy_pool SET enabled=$1, updated_at=now() WHERE id=$2`, *enabled, id); err != nil { + return err + } + } + if active != nil { + if _, err := tx.Exec(`UPDATE proxy_pool SET active=$1, updated_at=now() WHERE id=$2`, *active, id); err != nil { + return err + } + } + return tx.Commit() +} + +// proxyTransport builds an *http.Transport that dials through the given proxy +// URL (http/https/socks5, optional user:pass). Empty = direct transport. +func proxyTransport(raw string) (*http.Transport, error) { + raw = strings.TrimSpace(raw) + tr := &http.Transport{ + DisableKeepAlives: true, + DialContext: (&net.Dialer{ + Timeout: 10 * time.Second, + KeepAlive: 10 * time.Second, + }).DialContext, + } + if raw == "" { + return tr, nil + } + pu, err := url.Parse(raw) + if err != nil { + return nil, fmt.Errorf("parse proxy %q: %w", raw, err) + } + switch pu.Scheme { + case "http", "https": + tr.Proxy = http.ProxyURL(pu) + case "socks5": + var auth *netproxy.Auth + if pu.User != nil { + pw, _ := pu.User.Password() + auth = &netproxy.Auth{User: pu.User.Username(), Password: pw} + } + dialer, err := netproxy.SOCKS5("tcp", net.JoinHostPort(pu.Hostname(), pu.Port()), auth, netproxy.Direct) + if err != nil { + return nil, fmt.Errorf("build socks5 dialer for %q: %w", raw, err) + } + tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { + return dialer.Dial(network, addr) + } + default: + return nil, fmt.Errorf("unsupported proxy scheme %q (use http, https or socks5)", pu.Scheme) + } + return tr, nil +} + +// TestProxyPoolEntry makes a real request through the proxy and reports the +// egress IP observed at the far end, so users can verify a proxy before using it. +func (m *Manager) TestProxyPoolEntry(address string) (string, error) { + address = strings.TrimSpace(address) + if address == "" { + return "", errors.New("proxy address is required") + } + if _, err := traffic.ValidateProxyURL(address); err != nil { + return "", err + } + tr, err := proxyTransport(address) + if err != nil { + return "", err + } + client := &http.Client{Transport: tr, Timeout: 15 * time.Second} + req, err := http.NewRequest(http.MethodGet, "https://api.ipify.org?format=json", nil) + if err != nil { + return "", err + } + req.Header.Set("User-Agent", "ARTEX proxy-pool test") + resp, err := client.Do(req) + if err != nil { + return "", fmt.Errorf("egress test through %s failed: %w", address, err) + } + defer resp.Body.Close() //nolint:errcheck + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + return "", fmt.Errorf("egress test through %s: HTTP %d", address, resp.StatusCode) + } + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", err + } + var out struct { + IP string `json:"ip"` + } + if err := json.Unmarshal(body, &out); err != nil { + return "", fmt.Errorf("parse egress IP response: %w", err) + } + if out.IP == "" { + return "", fmt.Errorf("egress test through %s: no IP returned", address) + } + return out.IP, nil +} + func (m *Manager) Close() error { m.mu.Lock() defer m.mu.Unlock() diff --git a/server/server.go b/server/server.go index d2d85f579..8a1778687 100644 --- a/server/server.go +++ b/server/server.go @@ -927,6 +927,13 @@ func (s *Server) Handler() http.Handler { mux.HandleFunc("GET /api/settings", s.getSettings) mux.HandleFunc("PUT /api/settings", s.putSettings) mux.HandleFunc("GET /api/settings/noise", s.noiseStatus) // current noise profile + per-host counters (no reset) + // Proxy pool (restored 0.7.x feature): CRUD + egress-IP test + rotation strategy. + mux.HandleFunc("GET /api/settings/proxy-pool", s.getProxyPool) + mux.HandleFunc("POST /api/settings/proxy-pool", s.postProxyPool) + mux.HandleFunc("DELETE /api/settings/proxy-pool/{id}", s.deleteProxyPool) + mux.HandleFunc("PATCH /api/settings/proxy-pool/{id}", s.patchProxyPool) + mux.HandleFunc("POST /api/settings/proxy-pool/test", s.testProxyPool) + mux.HandleFunc("PUT /api/settings/proxy-pool/rotation", s.putProxyPoolRotation) // Vulnerability IM push. Channels are "multi-instance + per-instance filter rules" resources, so they get their own group of // REST endpoints instead of being stuffed into the flat /api/settings key-value store. mux.HandleFunc("GET /api/notify/meta", s.notifyMeta) @@ -3951,6 +3958,9 @@ func (s *Server) settingsPayload() map[string]any { "notify_enabled": s.m.pg.GetBool(settingNotifyEnabled, true), "notify_public_base_url": notifyPublicBaseURL(s.m.pg), "notify_digest_interval_min": notifyDigestIntervalMin(s.m.pg), + // Restored proxy pool: list of egress proxies + rotation strategy. + "proxy_pool": s.proxyPoolPayload(), + "proxy_pool_rotation": s.m.ProxyPoolRotation(), // Render limits of IM messages; 0 = no truncation. "notify_summary_max_runes": limits.SummaryRunes, "notify_assets_max_shown": limits.AssetsShown, @@ -3959,6 +3969,15 @@ func (s *Server) settingsPayload() map[string]any { } } +// proxyPoolPayload returns the pool list for the settings payload, never nil. +func (s *Server) proxyPoolPayload() []ProxyPoolEntry { + pool, err := s.m.ProxyPool() + if err != nil || pool == nil { + return []ProxyPoolEntry{} + } + return pool +} + // notifyPublicBaseURL reads the external address used in push backlinks. func notifyPublicBaseURL(pg *db.DB) string { v, _, _ := pg.GetSetting(settingNotifyPublicBaseURL) @@ -4278,6 +4297,117 @@ func (s *Server) putSettings(w http.ResponseWriter, r *http.Request) { writeJSON(w, 200, s.settingsPayload()) } +// proxyPoolID parses the {id} path segment of a proxy-pool route. +func proxyPoolID(r *http.Request) (int64, error) { + return strconv.ParseInt(r.PathValue("id"), 10, 64) +} + +// getProxyPool lists the restored proxy pool entries plus the rotation strategy. +func (s *Server) getProxyPool(w http.ResponseWriter, r *http.Request) { + pool, err := s.m.ProxyPool() + if err != nil { + writeErr(w, 500, err.Error()) + return + } + if pool == nil { + pool = []ProxyPoolEntry{} + } + writeJSON(w, 200, map[string]any{ + "proxy_pool": pool, + "rotation": s.m.ProxyPoolRotation(), + }) +} + +// postProxyPool adds one entry to the proxy pool. Body: { address }. +func (s *Server) postProxyPool(w http.ResponseWriter, r *http.Request) { + var req struct { + Address string `json:"address"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + writeErr(w, 400, err.Error()) + return + } + id, err := s.m.AddProxyPoolEntry(req.Address) + if err != nil { + writeErr(w, 400, err.Error()) + return + } + writeJSON(w, 200, map[string]any{"id": id}) +} + +// deleteProxyPool removes one pool entry by id. +func (s *Server) deleteProxyPool(w http.ResponseWriter, r *http.Request) { + id, err := proxyPoolID(r) + if err != nil { + writeErr(w, 400, err.Error()) + return + } + if err := s.m.DeleteProxyPoolEntry(id); err != nil { + writeErr(w, 500, err.Error()) + return + } + writeJSON(w, 200, map[string]any{"deleted": true}) +} + +// patchProxyPool toggles enabled and/or active on one pool entry. Body: { enabled?, active? }. +func (s *Server) patchProxyPool(w http.ResponseWriter, r *http.Request) { + id, err := proxyPoolID(r) + if err != nil { + writeErr(w, 400, err.Error()) + return + } + var req struct { + Enabled *bool `json:"enabled"` + Active *bool `json:"active"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + writeErr(w, 400, err.Error()) + return + } + if req.Enabled == nil && req.Active == nil { + writeErr(w, 400, "nothing to update (send enabled and/or active)") + return + } + if err := s.m.SetProxyPoolEntry(id, req.Enabled, req.Active); err != nil { + writeErr(w, 400, err.Error()) + return + } + writeJSON(w, 200, map[string]any{"ok": true}) +} + +// testProxyPool runs a real egress-IP test through a proxy. Body: { address }. +func (s *Server) testProxyPool(w http.ResponseWriter, r *http.Request) { + var req struct { + Address string `json:"address"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + writeErr(w, 400, err.Error()) + return + } + ip, err := s.m.TestProxyPoolEntry(req.Address) + if err != nil { + writeErr(w, 400, err.Error()) + return + } + writeJSON(w, 200, map[string]any{"egress_ip": ip}) +} + +// putProxyPoolRotation sets the pool rotation strategy. Body: { rotation }. +func (s *Server) putProxyPoolRotation(w http.ResponseWriter, r *http.Request) { + var req struct { + Rotation string `json:"rotation"` + } + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + writeErr(w, 400, err.Error()) + return + } + if err := s.m.SetProxyPoolRotation(req.Rotation); err != nil { + writeErr(w, 400, err.Error()) + return + } + writeJSON(w, 200, map[string]any{"rotation": s.m.ProxyPoolRotation()}) +} + // testWebSearch runs a real "test" search with the given (or currently saved) // backend/proxy/key to verify the config can actually reach a search backend — // mirroring testLLM. Backend/proxy come from the request (so the form's unsaved diff --git a/web/src/app/(main)/system/settings/page.tsx b/web/src/app/(main)/system/settings/page.tsx index 4b2db0334..c69862919 100644 --- a/web/src/app/(main)/system/settings/page.tsx +++ b/web/src/app/(main)/system/settings/page.tsx @@ -17,6 +17,7 @@ import { CHAT_SEND_MODE_OPTIONS, type ChatSendMode, setChatSendMode, useChatSend import type { Settings } from "@/lib/types"; import { NoiseProfileCard } from "./noise-profile-card"; +import { ProxyPoolCard } from "./proxy-pool-card"; // Renders a translated string, turning … and … spans into elements, so a sentence with emphasis stays one key. function rich(s: string): React.ReactNode[] { @@ -425,6 +426,8 @@ export default function SystemSettingsPage() { + + diff --git a/web/src/app/(main)/system/settings/proxy-pool-card.tsx b/web/src/app/(main)/system/settings/proxy-pool-card.tsx new file mode 100644 index 000000000..ea1953312 --- /dev/null +++ b/web/src/app/(main)/system/settings/proxy-pool-card.tsx @@ -0,0 +1,322 @@ +"use client"; + +import * as React from "react"; + +import { NetworkIcon, PlayIcon, RefreshCwIcon, Trash2Icon } from "lucide-react"; +import { toast } from "sonner"; + +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { Switch } from "@/components/ui/switch"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { t } from "@/i18n"; +import { api } from "@/lib/api"; +import type { ProxyPoolEntry } from "@/lib/types"; + +const rotations: { value: string; label: string }[] = [ + { value: "none", label: t("None · use the active proxy only") }, + { + value: "on_failure", + label: t("On failure · rotate to the next enabled proxy"), + }, + { value: "timed", label: t("Timed · rotate on a timer") }, +]; + +export function ProxyPoolCard() { + const [pool, setPool] = React.useState([]); + const [rotation, setRotation] = React.useState("none"); + const [loading, setLoading] = React.useState(false); + const [adding, setAdding] = React.useState(false); + const [address, setAddress] = React.useState(""); + const [testing, setTesting] = React.useState(null); // id under test + + const load = React.useCallback(() => { + setLoading(true); + api + .proxyPool() + .then(({ proxy_pool, rotation }) => { + setPool(proxy_pool); + setRotation(rotation); + }) + .catch((e) => + toast.error( + t("Failed to load the proxy pool: {error}", { + error: (e as Error).message, + }), + ), + ) + .finally(() => setLoading(false)); + }, []); + + React.useEffect(() => { + load(); + }, [load]); + + const fmtTs = (ts: number) => { + if (!ts) return t("Never"); + return new Date(ts * 1000).toLocaleString(); + }; + + const add = () => { + if (!address.trim()) return; + setAdding(true); + api + .addProxyPool(address.trim()) + .then(() => { + setAddress(""); + toast.success(t("Added proxy to the pool")); + load(); + }) + .catch((e) => + toast.error(t("Add failed: {error}", { error: (e as Error).message })), + ) + .finally(() => setAdding(false)); + }; + + const remove = (id: number) => { + if (!window.confirm(t("Remove this proxy from the pool?"))) return; + api + .deleteProxyPool(id) + .then(() => { + toast.success(t("Removed proxy from the pool")); + load(); + }) + .catch((e) => + toast.error(t("Delete failed: {error}", { error: (e as Error).message })), + ); + }; + + const toggle = (id: number, patch: { enabled?: boolean; active?: boolean }, label: string) => { + api + .patchProxyPool(id, patch) + .then(() => { + toast.success(label); + load(); + }) + .catch((e) => + toast.error(t("Save failed: {error}", { error: (e as Error).message })), + ); + }; + + const test = (id: number, address: string) => { + setTesting(id); + api + .testProxyPool(address) + .then(({ egress_ip }) => { + toast.success(t("Egress IP: {ip}", { ip: egress_ip })); + load(); + }) + .catch((e) => + toast.error(t("Test failed: {error}", { error: (e as Error).message })), + ) + .finally(() => setTesting(null)); + }; + + const saveRotation = () => { + api + .putProxyPoolRotation(rotation) + .then(() => toast.success(t("Rotation strategy saved"))) + .catch((e) => + toast.error(t("Save failed: {error}", { error: (e as Error).message })), + ); + }; + + return ( + + + + + {t("Proxy pool")} + + + {t( + "A pool of egress proxies with enable/disable, active selection and egress-IP testing (restored 0.7.x feature). Only one proxy may be active at a time.", + )} + + + + {/* Rotation strategy */} +
+ + + +
+ + {/* Add new proxy */} +
+ setAddress(e.target.value)} + /> + +
+ + {/* Pool table */} +
+ + + + {t("Address")} + {t("Enabled")} + {t("Active")} + {t("Last tested")} + {t("Egress IP")} + {t("Failures")} + {t("Actions")} + + + + {pool.length ? ( + pool.map((e) => ( + + + {e.address} + + + + toggle(e.id, { enabled: v }, v ? t("Enabled") : t("Disabled")) + } + disabled={loading} + /> + + + {e.active ? ( + + {t("Active")} + + ) : ( + + )} + + + {fmtTs(e.last_tested ?? 0)} + + + {e.egress_ip ?? —} + + {e.fail_count ?? 0} + + + + + + )) + ) : ( + + + {t("No proxies in the pool yet. Add one above.")} + + + )} + +
+
+ {pool.length === 0 && ( +

+ {t( + "Add http://, https:// or socks5:// proxies (optionally user:pass@host:port). Test each one to see the egress IP it reveals, pick the active proxy, and choose how the pool rotates on failure.", + )} +

+ )} +
+
+ ); +} diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts index 7a1035c04..e7c3c5d2c 100644 --- a/web/src/lib/api.ts +++ b/web/src/lib/api.ts @@ -77,6 +77,7 @@ import type { PromptVersion, SessionTokenUsage, Settings, + ProxyPoolEntry, Severity, SkillCall, SkillItem, @@ -1019,6 +1020,20 @@ export const api = { keenable_search_api_key?: string; }) => post<{ ok: boolean; error?: string; count?: number; backend?: string }>(`/settings/web-search/test`, patch), + // ---- Restored proxy pool (0.7.x regression fix) ---- + proxyPool: () => get<{ proxy_pool: ProxyPoolEntry[]; rotation: string }>(`/settings/proxy-pool`).then((r) => ({ + proxy_pool: arr(r.proxy_pool), + rotation: r.rotation ?? "none", + })), + addProxyPool: (address: string) => post<{ id: number }>(`/settings/proxy-pool`, { address }), + deleteProxyPool: (id: number) => del<{ deleted: boolean }>(`/settings/proxy-pool/${id}`), + patchProxyPool: (id: number, fields: { enabled?: boolean; active?: boolean }) => + patch<{ ok: boolean }>(`/settings/proxy-pool/${id}`, fields), + testProxyPool: (address: string) => + post<{ egress_ip: string }>(`/settings/proxy-pool/test`, { address }), + putProxyPoolRotation: (rotation: string) => + put<{ rotation: string }>(`/settings/proxy-pool/rotation`, { rotation }), + // ---- Vulnerability IM push ---- // Channels are multi-instance resources (several bots of the same kind, each with its own // filter rules), so they form their own group instead of the flat settings key/value store. diff --git a/web/src/lib/types.ts b/web/src/lib/types.ts index 9eba76a74..0b86bb735 100644 --- a/web/src/lib/types.ts +++ b/web/src/lib/types.ts @@ -1066,6 +1066,21 @@ export interface Settings { notify_assets_max_shown?: number; // asset names listed per finding, 0-50, default 3 // Target noise profile; the stored setting wins over ARTEX_NOISE_PROFILE. Applies to the next request. noise_profile?: NoiseProfileName; + // Restored proxy pool (0.7.x regression fix): the current pool entries and the + // rotation strategy. Entries are managed via /api/settings/proxy-pool. + proxy_pool?: ProxyPoolEntry[]; // list of egress proxies (newest first) + proxy_pool_rotation?: string; // "none" | "on_failure" | "timed" +} + +export interface ProxyPoolEntry { + id: number; // pool row id + address: string; // http/https/socks5 URL, optionally user:pass + enabled: boolean; // whether this proxy is a candidate for use + active: boolean; // whether this is the single active proxy (only one at a time) + last_tested?: number; // unix seconds of the last egress test, 0 = never + egress_ip?: string; // egress IP observed at the last successful test + fail_count?: number; // consecutive failed egress tests + created_at?: number; // unix seconds } export type NoiseProfileName = "off" | "quiet" | "balanced" | "aggressive"; From 38df9aa8729bf4e935b7a17d90d44a49cc25c35a Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Wed, 25 Nov 2026 20:52:01 +0000 Subject: [PATCH 2/2] Fix CI failures from proxy pool PR - gofmt server/manager.go and server/server.go - db/migrate_test.go: expect migration versions 1 to 15 (added 0015_proxy_pool.sql) - web i18n: add missing proxy-pool strings to tr.json and zh-CN.json --- db/migrate_test.go | 5 +++-- server/manager.go | 8 ++++---- server/server.go | 8 ++++---- web/src/i18n/locales/tr.json | 27 ++++++++++++++++++++++++++- web/src/i18n/locales/zh-CN.json | 27 ++++++++++++++++++++++++++- 5 files changed, 63 insertions(+), 12 deletions(-) diff --git a/db/migrate_test.go b/db/migrate_test.go index bdbd6a42c..a56c3433b 100644 --- a/db/migrate_test.go +++ b/db/migrate_test.go @@ -140,9 +140,10 @@ func assertEmbeddedApplied(t *testing.T, d *DB) []appliedMigration { {5, "0005_traffic_rewrite_rules.sql"}, {6, "0006_activity_outbox.sql"}, {7, "0007_finding_report_state.sql"}, {8, "0008_traffic_evidence_rewrite_flag.sql"}, {9, "0009_llm_context.sql"}, {10, "0010_dashboard_usage_indexes.sql"}, {11, "0011_traffic_tamper_hooks.sql"}, {12, "0012_lesson_withdrawn.sql"}, - {13, "0013_lesson_evidence_history.sql"}, {14, "0014_bedrock_gateway_profiles.sql"}} + {13, "0013_lesson_evidence_history.sql"}, {14, "0014_bedrock_gateway_profiles.sql"}, + {15, "0015_proxy_pool.sql"}} if len(applied) != len(want) { - t.Fatalf("schema_migrations = %+v, want versions 1 to 14", applied) + t.Fatalf("schema_migrations = %+v, want versions 1 to 15", applied) } for i, w := range want { content, err := fs.ReadFile(migrationsFS(), w.name) diff --git a/server/manager.go b/server/manager.go index cff4eb875..5f16c2d9b 100644 --- a/server/manager.go +++ b/server/manager.go @@ -27,10 +27,10 @@ import ( "github.com/Autumn-27/artex/enrich" "github.com/Autumn-27/artex/guard" "github.com/Autumn-27/artex/intercept" - netproxy "golang.org/x/net/proxy" "github.com/Autumn-27/artex/traffic" "github.com/Autumn-27/artex/traffic/rewrite" actool "github.com/Autumn-27/norma/tool" + netproxy "golang.org/x/net/proxy" ) // Task is one engagement: a description + goal + its own exploration store, @@ -1007,9 +1007,9 @@ type ProxyPoolEntry struct { // ProxyPoolRotation values. const ( - ProxyPoolRotationNone = "none" // use the active proxy only (or direct if none active) - ProxyPoolRotationOnFailure = "on_failure" // rotate to the next enabled proxy on failure - ProxyPoolRotationTimed = "timed" // rotate on a timer + ProxyPoolRotationNone = "none" // use the active proxy only (or direct if none active) + ProxyPoolRotationOnFailure = "on_failure" // rotate to the next enabled proxy on failure + ProxyPoolRotationTimed = "timed" // rotate on a timer ) var proxyPoolRotations = map[string]bool{ diff --git a/server/server.go b/server/server.go index 8a1778687..ebb596916 100644 --- a/server/server.go +++ b/server/server.go @@ -3959,8 +3959,8 @@ func (s *Server) settingsPayload() map[string]any { "notify_public_base_url": notifyPublicBaseURL(s.m.pg), "notify_digest_interval_min": notifyDigestIntervalMin(s.m.pg), // Restored proxy pool: list of egress proxies + rotation strategy. - "proxy_pool": s.proxyPoolPayload(), - "proxy_pool_rotation": s.m.ProxyPoolRotation(), + "proxy_pool": s.proxyPoolPayload(), + "proxy_pool_rotation": s.m.ProxyPoolRotation(), // Render limits of IM messages; 0 = no truncation. "notify_summary_max_runes": limits.SummaryRunes, "notify_assets_max_shown": limits.AssetsShown, @@ -4313,8 +4313,8 @@ func (s *Server) getProxyPool(w http.ResponseWriter, r *http.Request) { pool = []ProxyPoolEntry{} } writeJSON(w, 200, map[string]any{ - "proxy_pool": pool, - "rotation": s.m.ProxyPoolRotation(), + "proxy_pool": pool, + "rotation": s.m.ProxyPoolRotation(), }) } diff --git a/web/src/i18n/locales/tr.json b/web/src/i18n/locales/tr.json index 736aa13f3..83677b40b 100644 --- a/web/src/i18n/locales/tr.json +++ b/web/src/i18n/locales/tr.json @@ -2724,5 +2724,30 @@ "Search company…": "Şirket ara…", "Failed to load companies": "Şirketler yüklenemedi", "No company found": "Şirket bulunamadı", - "Manage companies": "Şirketleri yönet" + "Manage companies": "Şirketleri yönet", + "None · use the active proxy only": "Yok · yalnızca etkin proxy'yi kullan", + "On failure · rotate to the next enabled proxy": "Başarısızlıkta · sonraki etkin proxy'ye geç", + "Timed · rotate on a timer": "Zamanlanmış · zamanlayıcıya göre döndür", + "Failed to load the proxy pool: {error}": "Proxy havuzu yüklenemedi: {error}", + "Never": "Asla", + "Added proxy to the pool": "Proxy havuzuna eklendi", + "Remove this proxy from the pool?": "Bu proxy'yi havuzdan kaldırmak istiyor musunuz?", + "Removed proxy from the pool": "Proxy havuzundan kaldırıldı", + "Egress IP: {ip}": "Giden IP: {ip}", + "Rotation strategy saved": "Rotasyon stratejisi kaydedildi", + "Proxy pool": "Proxy havuzu", + "A pool of egress proxies with enable/disable, active selection and egress-IP testing (restored 0.7.x feature). Only one proxy may be active at a time.": "Etkinleştirme/devre dışı bırakma, etkin seçim ve giden IP testi ile giden proxy havuzu (0.7.x özelliği geri yüklendi). Yalnızca bir proxy aynı anda etkin olabilir.", + "Rotation": "Döndürme", + "Choose a strategy": "Bir strateji seçin", + "socks5://user:pass@host:1080 or http://host:port": "socks5://user:pass@host:1080 veya http://host:port", + "Adding…": "Ekleniyor…", + "Proxy pool entries": "Proxy havuzu girişleri", + "Last tested": "Son test", + "Egress IP": "Giden IP", + "Failures": "Hatalar", + "Set as active proxy": "Etkin proxy olarak ayarla", + "Set active": "Etkinleştir", + "Test egress": "Giden testi", + "No proxies in the pool yet. Add one above.": "Henüz havuzda proxy yok. Yukarıdan bir tane ekleyin.", + "Add http://, https:// or socks5:// proxies (optionally user:pass@host:port). Test each one to see the egress IP it reveals, pick the active proxy, and choose how the pool rotates on failure.": "http://, https:// veya socks5:// proxyleri ekleyin (isteğe bağlı user:pass@host:port). Her birini test ederek ortaya çıkan giden IP'yi görün, etkin proxy'yi seçin ve havuzun başarısızlıkta nasıl döndüreceğini belirleyin." } diff --git a/web/src/i18n/locales/zh-CN.json b/web/src/i18n/locales/zh-CN.json index fa7b58d56..01b80a59a 100644 --- a/web/src/i18n/locales/zh-CN.json +++ b/web/src/i18n/locales/zh-CN.json @@ -2724,5 +2724,30 @@ "Search company…": "搜索企业…", "Failed to load companies": "加载企业失败", "No company found": "未找到企业", - "Manage companies": "管理企业" + "Manage companies": "管理企业", + "None · use the active proxy only": "无 · 仅使用活动代理", + "On failure · rotate to the next enabled proxy": "失败时 · 轮换到下一个启用的代理", + "Timed · rotate on a timer": "定时 · 按计时器轮换", + "Failed to load the proxy pool: {error}": "加载代理池失败: {error}", + "Never": "从不", + "Added proxy to the pool": "已将代理添加到池中", + "Remove this proxy from the pool?": "是否将此代理从池中移除?", + "Removed proxy from the pool": "已从池中移除代理", + "Egress IP: {ip}": "出口 IP: {ip}", + "Rotation strategy saved": "轮换策略已保存", + "Proxy pool": "代理池", + "A pool of egress proxies with enable/disable, active selection and egress-IP testing (restored 0.7.x feature). Only one proxy may be active at a time.": "带启用/禁用、活动选择和出口 IP 测试的代理池(已恢复 0.7.x 功能)。同一时间只能有一个代理处于活动状态。", + "Rotation": "轮换", + "Choose a strategy": "选择策略", + "socks5://user:pass@host:1080 or http://host:port": "socks5://user:pass@host:1080 或 http://host:port", + "Adding…": "添加中…", + "Proxy pool entries": "代理池条目", + "Last tested": "上次测试", + "Egress IP": "出口 IP", + "Failures": "失败次数", + "Set as active proxy": "设为活动代理", + "Set active": "激活", + "Test egress": "测试出口", + "No proxies in the pool yet. Add one above.": "池中暂无代理。请在上方添加。", + "Add http://, https:// or socks5:// proxies (optionally user:pass@host:port). Test each one to see the egress IP it reveals, pick the active proxy, and choose how the pool rotates on failure.": "添加 http://、https:// 或 socks5:// 代理(可选 user:pass@host:port)。逐个测试以查看其显示的出口 IP,选择活动代理,并决定池在失败时如何轮换。" }