mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-21 12:35:33 +03:00
all: ecosia safesearch
This commit is contained in:
parent
bf1101b460
commit
5ad88d914c
12 changed files with 122 additions and 1 deletions
|
@ -2,4 +2,4 @@
|
|||
package configmigrate
|
||||
|
||||
// LastSchemaVersion is the most recent schema version.
|
||||
const LastSchemaVersion uint = 28
|
||||
const LastSchemaVersion uint = 29
|
||||
|
|
|
@ -1728,3 +1728,63 @@ func TestUpgradeSchema27to28(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpgradeSchema28to29(t *testing.T) {
|
||||
const newSchemaVer = 29
|
||||
|
||||
testCases := []struct {
|
||||
in yobj
|
||||
want yobj
|
||||
name string
|
||||
}{{
|
||||
name: "empty",
|
||||
in: yobj{},
|
||||
want: yobj{
|
||||
"schema_version": newSchemaVer,
|
||||
},
|
||||
}, {
|
||||
name: "disabled",
|
||||
in: yobj{
|
||||
"dns": yobj{
|
||||
"safe_search": yobj{
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: yobj{
|
||||
"schema_version": newSchemaVer,
|
||||
"dns": yobj{
|
||||
"safe_search": yobj{
|
||||
"enabled": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "enabled",
|
||||
in: yobj{
|
||||
"dns": yobj{
|
||||
"safe_search": yobj{
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: yobj{
|
||||
"schema_version": newSchemaVer,
|
||||
"dns": yobj{
|
||||
"safe_search": yobj{
|
||||
"ecosia": true,
|
||||
"enabled": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := migrateTo29(tc.in)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, tc.want, tc.in)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ func (m *Migrator) upgradeConfigSchema(current, target uint, diskConf yobj) (err
|
|||
25: migrateTo26,
|
||||
26: migrateTo27,
|
||||
27: migrateTo28,
|
||||
28: migrateTo29,
|
||||
}
|
||||
|
||||
for i, migrate := range upgrades[current:target] {
|
||||
|
|
47
internal/configmigrate/v29.go
Normal file
47
internal/configmigrate/v29.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package configmigrate
|
||||
|
||||
// migrateTo29 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
// 'dns':
|
||||
// 'safe_search':
|
||||
// 'enabled': true
|
||||
// 'bing': true
|
||||
// 'duckduckgo': true
|
||||
// 'google': true
|
||||
// 'pixabay': true
|
||||
// 'yandex': true
|
||||
// 'youtube': true
|
||||
// # …
|
||||
// # …
|
||||
//
|
||||
// # AFTER:
|
||||
// 'dns':
|
||||
// 'safe_search':
|
||||
// 'enabled': true
|
||||
// 'bing': true
|
||||
// 'duckduckgo': true
|
||||
// 'ecosia': true
|
||||
// 'google': true
|
||||
// 'pixabay': true
|
||||
// 'yandex': true
|
||||
// 'youtube': true
|
||||
// # …
|
||||
// # …
|
||||
func migrateTo29(diskConf yobj) (err error) {
|
||||
diskConf["schema_version"] = 29
|
||||
|
||||
dns, ok, err := fieldVal[yobj](diskConf, "dns")
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
safeSearch, _, _ := fieldVal[yobj](dns, "safe_search")
|
||||
if safeSearch["enabled"] == true {
|
||||
safeSearch["ecosia"] = true
|
||||
}
|
||||
|
||||
dns["safe_search"] = safeSearch
|
||||
|
||||
return nil
|
||||
}
|
|
@ -22,6 +22,7 @@ type SafeSearchConfig struct {
|
|||
|
||||
Bing bool `yaml:"bing" json:"bing"`
|
||||
DuckDuckGo bool `yaml:"duckduckgo" json:"duckduckgo"`
|
||||
Ecosia bool `yaml:"duckduckgo" json:"ecosia"`
|
||||
Google bool `yaml:"google" json:"google"`
|
||||
Pixabay bool `yaml:"pixabay" json:"pixabay"`
|
||||
Yandex bool `yaml:"yandex" json:"yandex"`
|
||||
|
|
|
@ -14,6 +14,9 @@ var pixabay string
|
|||
//go:embed rules/duckduckgo.txt
|
||||
var duckduckgo string
|
||||
|
||||
//go:embed rules/ecosia.txt
|
||||
var ecosia string
|
||||
|
||||
//go:embed rules/yandex.txt
|
||||
var yandex string
|
||||
|
||||
|
@ -27,6 +30,7 @@ var youtube string
|
|||
var safeSearchRules = map[Service]string{
|
||||
Bing: bing,
|
||||
DuckDuckGo: duckduckgo,
|
||||
Ecosia: ecosia,
|
||||
Google: google,
|
||||
Pixabay: pixabay,
|
||||
Yandex: yandex,
|
||||
|
|
1
internal/filtering/safesearch/rules/ecosia.txt
Normal file
1
internal/filtering/safesearch/rules/ecosia.txt
Normal file
|
@ -0,0 +1 @@
|
|||
|www.ecosia.org^$dnsrewrite=NOERROR;CNAME;strict-safe-search.ecosia.org
|
|
@ -28,6 +28,7 @@ type Service string
|
|||
const (
|
||||
Bing Service = "bing"
|
||||
DuckDuckGo Service = "duckduckgo"
|
||||
Ecosia Service = "ecosia"
|
||||
Google Service = "google"
|
||||
Pixabay Service = "pixabay"
|
||||
Yandex Service = "yandex"
|
||||
|
@ -41,6 +42,8 @@ func isServiceProtected(s filtering.SafeSearchConfig, service Service) (ok bool)
|
|||
return s.Bing
|
||||
case DuckDuckGo:
|
||||
return s.DuckDuckGo
|
||||
case Ecosia:
|
||||
return s.Ecosia
|
||||
case Google:
|
||||
return s.Google
|
||||
case Pixabay:
|
||||
|
|
|
@ -25,6 +25,7 @@ var defaultSafeSearchConf = filtering.SafeSearchConfig{
|
|||
Enabled: true,
|
||||
Bing: true,
|
||||
DuckDuckGo: true,
|
||||
Ecosia: true,
|
||||
Google: true,
|
||||
Pixabay: true,
|
||||
Yandex: true,
|
||||
|
|
|
@ -34,6 +34,7 @@ var testConf = filtering.SafeSearchConfig{
|
|||
|
||||
Bing: true,
|
||||
DuckDuckGo: true,
|
||||
Ecosia: true,
|
||||
Google: true,
|
||||
Pixabay: true,
|
||||
Yandex: true,
|
||||
|
|
|
@ -248,6 +248,7 @@ func copySafeSearch(
|
|||
if conf.Enabled {
|
||||
conf.Bing = true
|
||||
conf.DuckDuckGo = true
|
||||
conf.Ecosia = true
|
||||
conf.Google = true
|
||||
conf.Pixabay = true
|
||||
conf.Yandex = true
|
||||
|
|
|
@ -423,6 +423,7 @@ var config = &configuration{
|
|||
Enabled: false,
|
||||
Bing: true,
|
||||
DuckDuckGo: true,
|
||||
Ecosia: true,
|
||||
Google: true,
|
||||
Pixabay: true,
|
||||
Yandex: true,
|
||||
|
|
Loading…
Reference in a new issue