add proxy settings

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-04-11 22:27:13 +02:00
parent fa58485712
commit 86988d9afe
20 changed files with 1276 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os/exec"
"sort"
"sync"
@@ -40,11 +41,18 @@ func (h *ConfigHandler) Get(w http.ResponseWriter, r *http.Request) {
toolConfigs[toolName] = m
}
}
proxies := cfg.Proxies
if proxies == nil {
proxies = []config.ProxyEntry{}
}
_, pcErr := exec.LookPath("proxychains4")
respond.JSON(w, http.StatusOK, map[string]any{
"tools": toolConfigs,
"profiles": cfg.Profiles,
"readonly": h.demo || config.IsReadonly(h.configPath),
"demo": h.demo,
"tools": toolConfigs,
"profiles": cfg.Profiles,
"proxies": proxies,
"proxychains_available": pcErr == nil,
"readonly": h.demo || config.IsReadonly(h.configPath),
"demo": h.demo,
})
}
@@ -512,6 +520,39 @@ func (h *ConfigHandler) DeleteProfileToolConfig(w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusNoContent)
}
// PUT /api/config/proxies
func (h *ConfigHandler) UpdateProxies(w http.ResponseWriter, r *http.Request) {
if h.demo {
respond.Error(w, http.StatusForbidden, "demo mode: modifications are disabled")
return
}
if config.IsReadonly(h.configPath) {
respond.Error(w, http.StatusForbidden, "config is read-only")
return
}
var proxies []config.ProxyEntry
if err := json.NewDecoder(r.Body).Decode(&proxies); err != nil {
respond.Error(w, http.StatusBadRequest, "invalid JSON: "+err.Error())
return
}
h.mu.Lock()
defer h.mu.Unlock()
cfg, err := config.Load(h.configPath)
if err != nil {
respond.Error(w, http.StatusInternalServerError, err.Error())
return
}
cfg.Proxies = proxies
if err := config.Save(h.configPath, cfg); err != nil {
respond.Error(w, http.StatusInternalServerError, err.Error())
return
}
respond.JSON(w, http.StatusOK, proxies)
}
func validateProfileName(name string) error {
for _, c := range name {
if !((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-') {

View File

@@ -55,6 +55,7 @@ func NewRouter(
r.Route("/config", func(r chi.Router) {
r.Get("/", configHandler.Get)
r.Put("/proxies", configHandler.UpdateProxies)
r.Route("/tools", func(r chi.Router) {
r.Patch("/{toolName}", configHandler.UpdateToolConfig)