-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 1983: 5720-wildcard-ignored-domains
Updates #5720. Squashed commit of the following: commit e8093c9 Merge: df5413e 28fefaf Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 15:06:33 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit df5413e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 14:49:05 2023 +0300 confmigrate: imp docs commit 1644d99 Merge: 9542ee1 1e45178 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 14:23:42 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit 9542ee1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 12:48:48 2023 +0300 all: upd chlog commit 183f84a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Sep 1 17:11:31 2023 +0300 all: imp chlog commit a704325 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 31 18:59:52 2023 +0300 all: imp code commit fe99c3b Merge: 7f11e94 0182b9e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 31 18:43:09 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit 7f11e94 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 19:57:51 2023 +0300 aghnet: add tests commit f10f919 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 18:32:07 2023 +0300 all: add conf migration commit a53c14d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 13:37:30 2023 +0300 all: add ignore engine
- Loading branch information
Showing
22 changed files
with
577 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package aghnet | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/AdguardTeam/urlfilter" | ||
"github.com/AdguardTeam/urlfilter/filterlist" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// IgnoreEngine contains the list of rules for ignoring hostnames and matches | ||
// them. | ||
// | ||
// TODO(s.chzhen): Move all urlfilter stuff to aghfilter. | ||
type IgnoreEngine struct { | ||
// engine is the filtering engine that can match rules for ignoring | ||
// hostnames. | ||
engine *urlfilter.DNSEngine | ||
|
||
// ignored is the list of rules for ignoring hostnames. | ||
ignored []string | ||
} | ||
|
||
// NewIgnoreEngine creates a new instance of the IgnoreEngine and stores the | ||
// list of rules for ignoring hostnames. | ||
func NewIgnoreEngine(ignored []string) (e *IgnoreEngine, err error) { | ||
ruleList := &filterlist.StringRuleList{ | ||
RulesText: strings.ToLower(strings.Join(ignored, "\n")), | ||
IgnoreCosmetic: true, | ||
} | ||
ruleStorage, err := filterlist.NewRuleStorage([]filterlist.RuleList{ruleList}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &IgnoreEngine{ | ||
engine: urlfilter.NewDNSEngine(ruleStorage), | ||
ignored: ignored, | ||
}, nil | ||
} | ||
|
||
// Has returns true if IgnoreEngine matches the host. | ||
func (e *IgnoreEngine) Has(host string) (ignore bool) { | ||
if e == nil { | ||
return false | ||
} | ||
|
||
_, ignore = e.engine.Match(host) | ||
|
||
return ignore | ||
} | ||
|
||
// Values returns a copy of list of rules for ignoring hostnames. | ||
func (e *IgnoreEngine) Values() (ignored []string) { | ||
return slices.Clone(e.ignored) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package aghnet_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIgnoreEngine_Has(t *testing.T) { | ||
hostnames := []string{ | ||
"*.example.com", | ||
"example.com", | ||
"|.^", | ||
} | ||
|
||
engine, err := aghnet.NewIgnoreEngine(hostnames) | ||
require.NotNil(t, engine) | ||
require.NoError(t, err) | ||
|
||
testCases := []struct { | ||
name string | ||
host string | ||
ignore bool | ||
}{{ | ||
name: "basic", | ||
host: "example.com", | ||
ignore: true, | ||
}, { | ||
name: "root", | ||
host: ".", | ||
ignore: true, | ||
}, { | ||
name: "wildcard", | ||
host: "www.example.com", | ||
ignore: true, | ||
}, { | ||
name: "not_ignored", | ||
host: "something.com", | ||
ignore: false, | ||
}} | ||
|
||
for _, tc := range testCases { | ||
require.Equal(t, tc.ignore, engine.Has(tc.host)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
internal/confmigrate/testdata/TestMigrateConfig_Migrate/v27/input.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
http: | ||
address: 127.0.0.1:3000 | ||
session_ttl: 3h | ||
pprof: | ||
enabled: true | ||
port: 6060 | ||
users: | ||
- name: testuser | ||
password: testpassword | ||
dns: | ||
bind_hosts: | ||
- 127.0.0.1 | ||
port: 53 | ||
parental_sensitivity: 0 | ||
upstream_dns: | ||
- tls://1.1.1.1 | ||
- tls://1.0.0.1 | ||
- quic://8.8.8.8:784 | ||
bootstrap_dns: | ||
- 8.8.8.8:53 | ||
edns_client_subnet: | ||
enabled: true | ||
use_custom: false | ||
custom_ip: "" | ||
filtering: | ||
filtering_enabled: true | ||
parental_enabled: false | ||
safebrowsing_enabled: false | ||
safe_search: | ||
enabled: false | ||
bing: true | ||
duckduckgo: true | ||
google: true | ||
pixabay: true | ||
yandex: true | ||
youtube: true | ||
protection_enabled: true | ||
blocked_services: | ||
schedule: | ||
time_zone: Local | ||
ids: | ||
- 500px | ||
blocked_response_ttl: 10 | ||
filters: | ||
- url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt | ||
name: "" | ||
enabled: true | ||
- url: https://adaway.org/hosts.txt | ||
name: AdAway | ||
enabled: false | ||
- url: https://hosts-file.net/ad_servers.txt | ||
name: hpHosts - Ad and Tracking servers only | ||
enabled: false | ||
- url: http://www.malwaredomainlist.com/hostslist/hosts.txt | ||
name: MalwareDomainList.com Hosts List | ||
enabled: false | ||
clients: | ||
persistent: | ||
- name: localhost | ||
ids: | ||
- 127.0.0.1 | ||
- aa:aa:aa:aa:aa:aa | ||
use_global_settings: true | ||
use_global_blocked_services: true | ||
filtering_enabled: false | ||
parental_enabled: false | ||
safebrowsing_enabled: false | ||
safe_search: | ||
enabled: true | ||
bing: true | ||
duckduckgo: true | ||
google: true | ||
pixabay: true | ||
yandex: true | ||
youtube: true | ||
blocked_services: | ||
schedule: | ||
time_zone: Local | ||
ids: | ||
- 500px | ||
runtime_sources: | ||
whois: true | ||
arp: true | ||
rdns: true | ||
dhcp: true | ||
hosts: true | ||
dhcp: | ||
enabled: false | ||
interface_name: vboxnet0 | ||
local_domain_name: local | ||
dhcpv4: | ||
gateway_ip: 192.168.0.1 | ||
subnet_mask: 255.255.255.0 | ||
range_start: 192.168.0.10 | ||
range_end: 192.168.0.250 | ||
lease_duration: 1234 | ||
icmp_timeout_msec: 10 | ||
schema_version: 26 | ||
user_rules: [] | ||
querylog: | ||
enabled: true | ||
file_enabled: true | ||
interval: 720h | ||
size_memory: 1000 | ||
ignored: | ||
- '.' | ||
statistics: | ||
enabled: true | ||
interval: 240h | ||
ignored: | ||
- '.' | ||
os: | ||
group: '' | ||
rlimit_nofile: 123 | ||
user: '' | ||
log: | ||
file: "" | ||
max_backups: 0 | ||
max_size: 100 | ||
max_age: 3 | ||
compress: true | ||
local_time: false | ||
verbose: true |
Oops, something went wrong.