2020-02-18 17:17:35 +00:00
|
|
|
package dnsfilter
|
2019-07-23 09:21:37 +00:00
|
|
|
|
|
|
|
import (
|
2019-07-23 09:16:36 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2019-07-23 09:21:37 +00:00
|
|
|
"github.com/AdguardTeam/golibs/log"
|
2019-11-27 12:11:46 +00:00
|
|
|
"github.com/AdguardTeam/urlfilter/rules"
|
2019-07-23 09:21:37 +00:00
|
|
|
)
|
|
|
|
|
2019-11-27 12:11:46 +00:00
|
|
|
var serviceRules map[string][]*rules.NetworkRule // service name -> filtering rules
|
2019-07-23 09:21:37 +00:00
|
|
|
|
|
|
|
type svc struct {
|
|
|
|
name string
|
|
|
|
rules []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep in sync with:
|
|
|
|
// client/src/helpers/constants.js
|
|
|
|
// client/src/components/ui/Icons.js
|
2020-07-06 00:01:15 +00:00
|
|
|
// Do not use ||example.TLD^ rule unless particular name is unique or many extensions belong to it
|
2019-07-23 09:21:37 +00:00
|
|
|
var serviceRulesArray = []svc{
|
2020-07-06 00:01:15 +00:00
|
|
|
{"whatsapp", []string{"||whatsapp.TLD^"}},
|
2020-03-26 20:26:05 +00:00
|
|
|
{"facebook", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||facebook.TLD^",
|
|
|
|
"||fbcdn.TLD^",
|
|
|
|
"||accountkit.TLD^",
|
|
|
|
"||fb.TLD^",
|
|
|
|
"||fbsbx.TLD^",
|
|
|
|
"||discoverapp.TLD^",
|
|
|
|
"||freebasics.TLD^",
|
|
|
|
"||freebasic.TLD^",
|
|
|
|
"||internet.org^",
|
|
|
|
"||messenger.TLD^",
|
|
|
|
"||m.me^",
|
|
|
|
"||i.org^",
|
|
|
|
"||f8.TLD^",
|
|
|
|
"||tfbnw.TLD^",
|
|
|
|
"||fburl.TLD^",
|
|
|
|
"||hob.bi^",
|
|
|
|
"||workplace.TLD^",
|
|
|
|
"||novi.TLD^",
|
|
|
|
"||libra.org^",
|
|
|
|
"||f8.TLD^",
|
|
|
|
"||oculus.TLD^",
|
|
|
|
"||acebook.TLD^",
|
|
|
|
"||forecastapp.net^",
|
|
|
|
"||adversarialnli.TLD^",
|
|
|
|
"||facebookblueprint.TLD^",
|
|
|
|
"||facebookrecruiting.TLD^",
|
|
|
|
"||boostwithfacebook.TLD^",
|
|
|
|
"||facebooksuppliers.TLD^",
|
|
|
|
"||facebookbrand.TLD^",
|
|
|
|
"||accessfacebookfromschool.TLD^",
|
|
|
|
"||facebookcorewwwi.TLD^",
|
2020-03-26 20:26:05 +00:00
|
|
|
}},
|
2020-07-06 00:01:15 +00:00
|
|
|
{"twitter", []string{"||twitter.TLD^", "||twttr.TLD^", "||t.co^", "||twimg.TLD^", "||ads-twitter.TLD^"}},
|
2020-03-26 20:26:05 +00:00
|
|
|
{"youtube", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||youtube.TLD^",
|
2020-03-26 20:26:05 +00:00
|
|
|
"||ytimg.com^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||youtu.TLD^",
|
|
|
|
"||googlevideo.TLD^",
|
|
|
|
"||youtubei.googleapis.TLD^",
|
|
|
|
"||youtube-nocookie.TLD^",
|
2020-05-30 15:51:44 +00:00
|
|
|
"||youtube",
|
2020-03-26 20:26:05 +00:00
|
|
|
}},
|
2020-07-06 00:01:15 +00:00
|
|
|
{"twitch", []string{"||twitch.tv^", "||ttvnw.TLD^", "||jtvnw.TLD^", "||twitchcdn.TLD^"}},
|
|
|
|
{"netflix", []string{"||nflxext.TLD^", "||netflix.TLD^", "||nflximg.TLD^", "||nflxvideo.TLD^"}},
|
|
|
|
{"instagram", []string{"||instagram.TLD^", "||cdninstagram.TLD^", "||instagram-brand.TLD^"}},
|
2020-04-20 22:52:45 +00:00
|
|
|
{"snapchat", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||snapchat.TLD^",
|
|
|
|
"||sc-cdn.TLD^",
|
|
|
|
"||snap-dev.TLD^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||snapkit.co",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||snapads.TLD^",
|
|
|
|
"||impala-media-production.s3.amazonaws.TLD^",
|
2020-04-20 22:52:45 +00:00
|
|
|
}},
|
2020-07-06 00:01:15 +00:00
|
|
|
{"discord", []string{"||discordapp.TLD^", "||discord.TLD^"}},
|
2019-07-23 09:21:37 +00:00
|
|
|
{"ok", []string{"||ok.ru^"}},
|
2020-07-06 00:01:15 +00:00
|
|
|
{"skype", []string{"||skype.TLD^", "||skypeassets.TLD^"}},
|
|
|
|
{"vk", []string{"||vk.TLD^", "||userapi.TLD^", "||vk-cdn.TLD^", "||vkuservideo.TLD^"}},
|
2019-11-05 13:00:15 +00:00
|
|
|
{"origin", []string{"||origin.com^", "||signin.ea.com^", "||accounts.ea.com^"}},
|
2020-04-20 22:52:45 +00:00
|
|
|
{"steam", []string{
|
|
|
|
"||steam.com^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||steampowered.TLD^",
|
|
|
|
"||steamcommunity.TLD^",
|
|
|
|
"||steamstatic.TLD^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||steamstore-a.akamaihd.net^",
|
|
|
|
"||steamcdn-a.akamaihd.net^",
|
|
|
|
}},
|
2020-07-06 00:01:15 +00:00
|
|
|
{"epic_games", []string{"||epicgames.TLD^", "||easyanticheat.TLD^", "||easy.ac^", "||eac-cdn.TLD^"}},
|
|
|
|
{"reddit", []string{"||reddit.TLD^", "||redditstatic.TLD^", "||redditmedia.TLD^", "||redd.it^"}},
|
2019-07-23 09:21:37 +00:00
|
|
|
{"mail_ru", []string{"||mail.ru^"}},
|
2019-11-07 02:39:30 +00:00
|
|
|
{"cloudflare", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||cloudflare.TLD^",
|
|
|
|
"||cloudflare-dns.TLD^",
|
|
|
|
"||cloudflareinsights.TLD^",
|
|
|
|
"||cloudflarestream.TLD^",
|
|
|
|
"||cloudflareresolve.TLD^",
|
|
|
|
"||cloudflareclient.TLD^",
|
|
|
|
"||cloudflare-quic.TLD^",
|
|
|
|
"||cloudflareapi.TLD^",
|
|
|
|
"||cloudflareapps.TLD^",
|
|
|
|
"||cloudflarechallenge.TLD^",
|
|
|
|
"||cloudflarepreview.TLD^",
|
|
|
|
"||cloudflarepreviews.TLD^",
|
|
|
|
"||cloudflarebolt.TLD^",
|
|
|
|
"||cloudflare-free.TLD^",
|
|
|
|
"||cloudflare-ipfs.TLD",
|
|
|
|
"||cloudflareworkers.TLD^",
|
|
|
|
"||cloudflarestatus.TLD^",
|
|
|
|
"||cloudflareaccess.TLD^",
|
|
|
|
"||cloudflareenterprise.TLD^",
|
|
|
|
"||cloudflarespeedtest.TLD^",
|
|
|
|
"||cloudflaressl.TLD^",
|
|
|
|
"||encryptedsni.TLD^",
|
|
|
|
"||mycloudflare.TLD^",
|
|
|
|
"||workers.dev^",
|
2019-11-07 02:39:30 +00:00
|
|
|
"||one.one^",
|
|
|
|
"||warp.plus^",
|
2020-03-26 20:26:05 +00:00
|
|
|
"||1.1.1.1^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.TLD^",
|
2019-11-07 02:39:30 +00:00
|
|
|
}},
|
2019-11-05 09:36:06 +00:00
|
|
|
{"amazon", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||amazon.TLD^",
|
|
|
|
"||media-amazon.TLD^",
|
|
|
|
"||primevideo.TLD^",
|
|
|
|
"||amazontrust.TLD^",
|
|
|
|
"||images-amazon.TLD^",
|
|
|
|
"||amazonvideo.TLD^",
|
|
|
|
"||assoc-amazon.TLD^",
|
|
|
|
"||ssl-images-amazon.TLD^",
|
|
|
|
"||amazonpay.TLD^",
|
|
|
|
"||amazon-adsystem.TLD^",
|
|
|
|
"||amazonaws.TLD^",
|
|
|
|
"||aboutamazon.TLD^",
|
|
|
|
"||awsdns-cn-00.TLD^",
|
|
|
|
"||awsdns-00.TLD^",
|
|
|
|
"||awsstatic.TLD^",
|
|
|
|
"||comixology.TLD^",
|
|
|
|
"||boxofficemojo.TLD^",
|
|
|
|
"||aiv-delivery.TLD^",
|
|
|
|
"||jtvnw.TLD^",
|
|
|
|
"||awscloud.TLD^",
|
|
|
|
"||goodreads.TLD^",
|
|
|
|
"||shopbop.TLD^",
|
|
|
|
"||fabric.TLD^",
|
|
|
|
"||zappos.TLD^",
|
|
|
|
"||6pm.TLD^",
|
|
|
|
"||psdops.TLD^",
|
|
|
|
"||woot.TLD^",
|
|
|
|
"||mturk.TLD^",
|
|
|
|
"||aiv-cdn.TLD^",
|
|
|
|
"||a2z.TLD^",
|
|
|
|
"||createspace.TLD^",
|
2020-05-30 15:51:44 +00:00
|
|
|
"||aws",
|
2019-11-05 09:36:06 +00:00
|
|
|
}},
|
2019-11-06 09:00:05 +00:00
|
|
|
{"ebay", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||ebay.TLD^",
|
|
|
|
"||ebayimg.TLD^",
|
|
|
|
"||ebaystatic.TLD^",
|
|
|
|
"||ebaycdn.TLD^",
|
|
|
|
"||appforebay.TLD^",
|
|
|
|
"||ebayinc.TLD^",
|
|
|
|
"||terapeak.TLD^",
|
|
|
|
"||e-bay.TLD^",
|
|
|
|
"||ebaydts.TLD^",
|
|
|
|
"||shopping.TLD^",
|
|
|
|
"||ebaystores.TLD^",
|
|
|
|
"||ebayglobalshipping.TLD^",
|
2019-11-06 09:00:05 +00:00
|
|
|
}},
|
2019-09-17 21:26:58 +00:00
|
|
|
{"tiktok", []string{
|
2020-07-06 00:01:15 +00:00
|
|
|
"||tiktok.TLD^",
|
|
|
|
"||tiktokcdn.TLD^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||musical.ly^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||snssdk.TLD^",
|
|
|
|
"||amemv.TLD^",
|
2019-09-17 21:26:58 +00:00
|
|
|
"||toutiao.com^",
|
|
|
|
"||ixigua.com^",
|
|
|
|
"||pstatp.com^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||ixiguavideo.TLD^",
|
|
|
|
"||toutiaocloud.TLD^",
|
|
|
|
"||bdurl.TLD^",
|
|
|
|
"||byteimg.TLD^",
|
|
|
|
"||muscdn.TLD^",
|
2019-11-21 21:51:52 +00:00
|
|
|
"||bytedance.map.fastly.net^",
|
2020-07-06 00:01:15 +00:00
|
|
|
"||douyin.TLD^",
|
|
|
|
"||iesdouyin.TLD^",
|
|
|
|
"||tiktokv.TLD^",
|
2019-09-17 21:26:58 +00:00
|
|
|
}},
|
2019-07-23 09:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert array to map
|
2020-02-18 17:17:35 +00:00
|
|
|
func initBlockedServices() {
|
2019-11-27 12:11:46 +00:00
|
|
|
serviceRules = make(map[string][]*rules.NetworkRule)
|
2019-07-23 09:21:37 +00:00
|
|
|
for _, s := range serviceRulesArray {
|
2019-11-27 12:11:46 +00:00
|
|
|
netRules := []*rules.NetworkRule{}
|
2019-07-23 09:21:37 +00:00
|
|
|
for _, text := range s.rules {
|
2019-11-27 12:11:46 +00:00
|
|
|
rule, err := rules.NewNetworkRule(text, 0)
|
2019-07-23 09:21:37 +00:00
|
|
|
if err != nil {
|
2019-11-27 12:11:46 +00:00
|
|
|
log.Error("rules.NewNetworkRule: %s rule: %s", err, text)
|
2019-07-23 09:21:37 +00:00
|
|
|
continue
|
|
|
|
}
|
2019-11-27 12:11:46 +00:00
|
|
|
netRules = append(netRules, rule)
|
2019-07-23 09:21:37 +00:00
|
|
|
}
|
2019-11-27 12:11:46 +00:00
|
|
|
serviceRules[s.name] = netRules
|
2019-07-23 09:21:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
// BlockedSvcKnown - return TRUE if a blocked service name is known
|
|
|
|
func BlockedSvcKnown(s string) bool {
|
2020-03-02 15:51:48 +00:00
|
|
|
_, ok := serviceRules[s]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2019-07-23 09:21:37 +00:00
|
|
|
// ApplyBlockedServices - set blocked services settings for this DNS request
|
2020-02-18 17:17:35 +00:00
|
|
|
func (d *Dnsfilter) ApplyBlockedServices(setts *RequestFilteringSettings, list []string, global bool) {
|
|
|
|
setts.ServicesRules = []ServiceEntry{}
|
|
|
|
if global {
|
|
|
|
d.confLock.RLock()
|
|
|
|
defer d.confLock.RUnlock()
|
|
|
|
list = d.Config.BlockedServices
|
|
|
|
}
|
2019-07-23 09:21:37 +00:00
|
|
|
for _, name := range list {
|
|
|
|
rules, ok := serviceRules[name]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
log.Error("unknown service name: %s", name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
s := ServiceEntry{}
|
2019-07-23 09:21:37 +00:00
|
|
|
s.Name = name
|
|
|
|
s.Rules = rules
|
|
|
|
setts.ServicesRules = append(setts.ServicesRules, s)
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 09:16:36 +00:00
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
func (d *Dnsfilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
d.confLock.RLock()
|
|
|
|
list := d.Config.BlockedServices
|
|
|
|
d.confLock.RUnlock()
|
2019-07-23 09:16:36 +00:00
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
err := json.NewEncoder(w).Encode(list)
|
|
|
|
if err != nil {
|
2020-02-18 17:17:35 +00:00
|
|
|
httpError(r, w, http.StatusInternalServerError, "json.Encode: %s", err)
|
2019-07-23 09:16:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
func (d *Dnsfilter) handleBlockedServicesSet(w http.ResponseWriter, r *http.Request) {
|
2019-07-23 09:16:36 +00:00
|
|
|
list := []string{}
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&list)
|
|
|
|
if err != nil {
|
2020-02-18 17:17:35 +00:00
|
|
|
httpError(r, w, http.StatusBadRequest, "json.Decode: %s", err)
|
2019-07-23 09:16:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
d.confLock.Lock()
|
|
|
|
d.Config.BlockedServices = list
|
|
|
|
d.confLock.Unlock()
|
2019-07-23 09:16:36 +00:00
|
|
|
|
|
|
|
log.Debug("Updated blocked services list: %d", len(list))
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
d.ConfigModified()
|
2019-07-23 09:16:36 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 17:17:35 +00:00
|
|
|
// registerBlockedServicesHandlers - register HTTP handlers
|
|
|
|
func (d *Dnsfilter) registerBlockedServicesHandlers() {
|
|
|
|
d.Config.HTTPRegister("GET", "/control/blocked_services/list", d.handleBlockedServicesList)
|
|
|
|
d.Config.HTTPRegister("POST", "/control/blocked_services/set", d.handleBlockedServicesSet)
|
2019-07-23 09:16:36 +00:00
|
|
|
}
|