mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 03:02:07 +03:00
f84ff2bd05
Merge in DNS/adguard-home from AG-25263-dns-config to master Squashed commit of the following: commit 478b607526391af65de67d6d7f1d904198610cdf Merge: b944d12fa51340adb3
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Sep 4 18:04:56 2023 +0400 Merge remote-tracking branch 'origin/master' into AG-25263-dns-config commit b944d12fa812b05b9d9f22d2287425ca36630329 Merge: b474f712f0182b9ec1
Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Sep 1 09:13:36 2023 +0400 Merge remote-tracking branch 'origin/master' into AG-25263-dns-config # Conflicts: # internal/dnsforward/dnsforward.go commit b474f712f64daa1a7d7e32d89edc901d2f273c9a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Sep 1 09:11:17 2023 +0400 all: imp code commit 635a316b8244f13d90a8fe2209f1673c0765aaa9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 16:18:25 2023 +0300 all: dnsfilter rm config embed commit 5aa6212e89bc38e3d283b8d6b1a78726d10b3f3a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Aug 30 12:45:01 2023 +0300 all: dnsfilter rm config embed
72 lines
1.7 KiB
Go
72 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.ConfigModified()
|
|
}
|
|
|
|
// 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.ConfigModified()
|
|
}
|
|
|
|
// 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) {
|
|
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(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.ConfigModified()
|
|
|
|
aghhttp.OK(w)
|
|
}
|