mirror of
https://github.com/anotherhadi/iknowyou.git
synced 2026-04-12 00:47:26 +02:00
add proxy settings
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -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 == '-') {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user