mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-08-03 21:59:35 +00:00
Merge in DNS/adguard-home from AGDNS-3061-config-modifier to master Squashed commit of the following: commit a0068547bd0209d12e8dbf98ddd5e4ed2545cdd0 Merge: 97b798af6451255675Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 5 17:39:31 2025 +0300 Merge branch 'master' into AGDNS-3061-config-modifier commit 97b798af6a50ee27ee5ed2bcf1c4c3670f5afc5d Merge: 96d21efc9b8043e4f0Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jul 30 20:27:41 2025 +0300 Merge branch 'master' into AGDNS-3061-config-modifier commit 96d21efc984073adef5026de8a03b5bf94542648 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Jul 30 20:18:43 2025 +0300 all: imp code commit 67c5608b4be3bd712a0ab5980f25ecea1ed21d65 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jul 29 20:31:19 2025 +0300 all: imp code commit 52f45a9f70f57d8e7f7fc0e9e8291ff0dde74343 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jul 28 20:32:13 2025 +0300 all: use config modifier commit d389ffd286460d8ff1964bd2ee8dabdafb832b9b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jul 25 14:20:31 2025 +0300 bamboo-specs: fix ci commit 3f303ac9131a07e4af5783696b237436fd93d65c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jul 25 14:18:42 2025 +0300 home: config modifier
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package filtering
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
|
)
|
|
|
|
// handleSafeSearchEnable is the handler for POST /control/safesearch/enable
|
|
// HTTP API.
|
|
//
|
|
// Deprecated: Use handleSafeSearchSettings.
|
|
func (d *DNSFilter) handleSafeSearchEnable(w http.ResponseWriter, r *http.Request) {
|
|
setProtectedBool(d.confMu, &d.conf.SafeSearchConf.Enabled, true)
|
|
d.conf.ConfModifier.Apply(r.Context())
|
|
}
|
|
|
|
// handleSafeSearchDisable is the handler for POST /control/safesearch/disable
|
|
// HTTP API.
|
|
//
|
|
// Deprecated: Use handleSafeSearchSettings.
|
|
func (d *DNSFilter) handleSafeSearchDisable(w http.ResponseWriter, r *http.Request) {
|
|
setProtectedBool(d.confMu, &d.conf.SafeSearchConf.Enabled, false)
|
|
d.conf.ConfModifier.Apply(r.Context())
|
|
}
|
|
|
|
// handleSafeSearchStatus is the handler for GET /control/safesearch/status
|
|
// HTTP API.
|
|
func (d *DNSFilter) handleSafeSearchStatus(w http.ResponseWriter, r *http.Request) {
|
|
var resp SafeSearchConfig
|
|
func() {
|
|
d.confMu.RLock()
|
|
defer d.confMu.RUnlock()
|
|
|
|
resp = d.conf.SafeSearchConf
|
|
}()
|
|
|
|
aghhttp.WriteJSONResponseOK(w, r, resp)
|
|
}
|
|
|
|
// handleSafeSearchSettings is the handler for PUT /control/safesearch/settings
|
|
// HTTP API.
|
|
func (d *DNSFilter) handleSafeSearchSettings(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
req := &SafeSearchConfig{}
|
|
err := json.NewDecoder(r.Body).Decode(req)
|
|
if err != nil {
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err)
|
|
|
|
return
|
|
}
|
|
|
|
conf := *req
|
|
err = d.safeSearch.Update(ctx, conf)
|
|
if err != nil {
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "updating: %s", err)
|
|
|
|
return
|
|
}
|
|
|
|
func() {
|
|
d.confMu.Lock()
|
|
defer d.confMu.Unlock()
|
|
|
|
d.conf.SafeSearchConf = conf
|
|
}()
|
|
|
|
d.conf.ConfModifier.Apply(ctx)
|
|
|
|
aghhttp.OK(w)
|
|
}
|