2021-05-21 13:15:47 +00:00
|
|
|
package filtering
|
2019-07-23 09:21:37 +00:00
|
|
|
|
|
|
|
import (
|
2019-07-23 09:16:36 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2021-12-16 17:54:59 +00:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
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
|
2022-03-23 11:19:45 +00:00
|
|
|
var serviceRulesArray = []svc{{
|
|
|
|
name: "whatsapp",
|
|
|
|
rules: []string{"||whatsapp.net^", "||whatsapp.com^"},
|
|
|
|
}, {
|
|
|
|
name: "facebook",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||facebook.com^",
|
|
|
|
"||facebook.net^",
|
|
|
|
"||fbcdn.net^",
|
|
|
|
"||accountkit.com^",
|
|
|
|
"||fb.me^",
|
|
|
|
"||fb.com^",
|
|
|
|
"||fbsbx.com^",
|
|
|
|
"||messenger.com^",
|
|
|
|
"||facebookcorewwwi.onion^",
|
|
|
|
"||fbcdn.com^",
|
2021-08-20 16:49:05 +00:00
|
|
|
"||fb.watch^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "twitter",
|
|
|
|
rules: []string{"||twitter.com^", "||twttr.com^", "||t.co^", "||twimg.com^"},
|
|
|
|
}, {
|
|
|
|
name: "youtube",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||youtube.com^",
|
2020-03-26 20:26:05 +00:00
|
|
|
"||ytimg.com^",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||youtu.be^",
|
|
|
|
"||googlevideo.com^",
|
|
|
|
"||youtubei.googleapis.com^",
|
|
|
|
"||youtube-nocookie.com^",
|
2020-05-30 15:51:44 +00:00
|
|
|
"||youtube",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "twitch",
|
|
|
|
rules: []string{"||twitch.tv^", "||ttvnw.net^", "||jtvnw.net^", "||twitchcdn.net^"},
|
|
|
|
}, {
|
|
|
|
name: "netflix",
|
|
|
|
rules: []string{
|
|
|
|
"||nflxext.com^",
|
|
|
|
"||netflix.com^",
|
|
|
|
"||nflximg.net^",
|
|
|
|
"||nflxvideo.net^",
|
|
|
|
"||nflxso.net^",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "instagram",
|
|
|
|
rules: []string{"||instagram.com^", "||cdninstagram.com^"},
|
|
|
|
}, {
|
|
|
|
name: "snapchat",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||snapchat.com^",
|
|
|
|
"||sc-cdn.net^",
|
|
|
|
"||snap-dev.net^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||snapkit.co",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||snapads.com^",
|
|
|
|
"||impala-media-production.s3.amazonaws.com^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "discord",
|
|
|
|
rules: []string{
|
|
|
|
"||discord.gg^",
|
|
|
|
"||discordapp.net^",
|
|
|
|
"||discordapp.com^",
|
|
|
|
"||discord.com^",
|
|
|
|
"||discord.media^",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "ok",
|
|
|
|
rules: []string{"||ok.ru^"},
|
|
|
|
}, {
|
|
|
|
name: "skype",
|
|
|
|
rules: []string{"||skype.com^", "||skypeassets.com^"},
|
|
|
|
}, {
|
|
|
|
name: "vk",
|
|
|
|
rules: []string{"||vk.com^", "||userapi.com^", "||vk-cdn.net^", "||vkuservideo.net^"},
|
|
|
|
}, {
|
|
|
|
name: "origin",
|
|
|
|
rules: []string{"||origin.com^", "||signin.ea.com^", "||accounts.ea.com^"},
|
|
|
|
}, {
|
|
|
|
name: "steam",
|
|
|
|
rules: []string{
|
2020-04-20 22:52:45 +00:00
|
|
|
"||steam.com^",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||steampowered.com^",
|
|
|
|
"||steamcommunity.com^",
|
|
|
|
"||steamstatic.com^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||steamstore-a.akamaihd.net^",
|
|
|
|
"||steamcdn-a.akamaihd.net^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "epic_games",
|
|
|
|
rules: []string{"||epicgames.com^", "||easyanticheat.net^", "||easy.ac^", "||eac-cdn.com^"},
|
|
|
|
}, {
|
|
|
|
name: "reddit",
|
|
|
|
rules: []string{"||reddit.com^", "||redditstatic.com^", "||redditmedia.com^", "||redd.it^"},
|
|
|
|
}, {
|
|
|
|
name: "mail_ru",
|
|
|
|
rules: []string{"||mail.ru^"},
|
|
|
|
}, {
|
|
|
|
name: "cloudflare",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||cloudflare.com^",
|
|
|
|
"||cloudflare-dns.com^",
|
|
|
|
"||cloudflare.net^",
|
|
|
|
"||cloudflareinsights.com^",
|
|
|
|
"||cloudflarestream.com^",
|
|
|
|
"||cloudflareresolve.com^",
|
|
|
|
"||cloudflareclient.com^",
|
|
|
|
"||cloudflarebolt.com^",
|
|
|
|
"||cloudflarestatus.com^",
|
|
|
|
"||cloudflare.cn^",
|
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-08-12 10:03:17 +00:00
|
|
|
"||dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "amazon",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||amazon.com^",
|
|
|
|
"||media-amazon.com^",
|
|
|
|
"||primevideo.com^",
|
|
|
|
"||amazontrust.com^",
|
|
|
|
"||images-amazon.com^",
|
|
|
|
"||ssl-images-amazon.com^",
|
|
|
|
"||amazonpay.com^",
|
|
|
|
"||amazonpay.in^",
|
|
|
|
"||amazon-adsystem.com^",
|
|
|
|
"||a2z.com^",
|
|
|
|
"||amazon.ae^",
|
|
|
|
"||amazon.ca^",
|
|
|
|
"||amazon.cn^",
|
|
|
|
"||amazon.de^",
|
|
|
|
"||amazon.es^",
|
|
|
|
"||amazon.fr^",
|
|
|
|
"||amazon.in^",
|
|
|
|
"||amazon.it^",
|
|
|
|
"||amazon.nl^",
|
|
|
|
"||amazon.com.au^",
|
|
|
|
"||amazon.com.br^",
|
|
|
|
"||amazon.co.jp^",
|
|
|
|
"||amazon.com.mx^",
|
|
|
|
"||amazon.co.uk^",
|
|
|
|
"||createspace.com^",
|
2020-05-30 15:51:44 +00:00
|
|
|
"||aws",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "ebay",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||ebay.com^",
|
|
|
|
"||ebayimg.com^",
|
|
|
|
"||ebaystatic.com^",
|
|
|
|
"||ebaycdn.net^",
|
|
|
|
"||ebayinc.com^",
|
|
|
|
"||ebay.at^",
|
|
|
|
"||ebay.be^",
|
|
|
|
"||ebay.ca^",
|
|
|
|
"||ebay.ch^",
|
|
|
|
"||ebay.cn^",
|
|
|
|
"||ebay.de^",
|
|
|
|
"||ebay.es^",
|
|
|
|
"||ebay.fr^",
|
|
|
|
"||ebay.ie^",
|
|
|
|
"||ebay.in^",
|
|
|
|
"||ebay.it^",
|
|
|
|
"||ebay.ph^",
|
|
|
|
"||ebay.pl^",
|
|
|
|
"||ebay.nl^",
|
|
|
|
"||ebay.com.au^",
|
|
|
|
"||ebay.com.cn^",
|
|
|
|
"||ebay.com.hk^",
|
|
|
|
"||ebay.com.my^",
|
|
|
|
"||ebay.com.sg^",
|
|
|
|
"||ebay.co.uk^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "tiktok",
|
|
|
|
rules: []string{
|
2020-08-12 10:03:17 +00:00
|
|
|
"||tiktok.com^",
|
|
|
|
"||tiktokcdn.com^",
|
2020-04-20 22:52:45 +00:00
|
|
|
"||musical.ly^",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||snssdk.com^",
|
|
|
|
"||amemv.com^",
|
2019-09-17 21:26:58 +00:00
|
|
|
"||toutiao.com^",
|
|
|
|
"||ixigua.com^",
|
|
|
|
"||pstatp.com^",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||ixiguavideo.com^",
|
|
|
|
"||toutiaocloud.com^",
|
|
|
|
"||toutiaocloud.net^",
|
|
|
|
"||bdurl.com^",
|
|
|
|
"||bytecdn.cn^",
|
|
|
|
"||byteimg.com^",
|
|
|
|
"||ixigua.com^",
|
|
|
|
"||muscdn.com^",
|
2019-11-21 21:51:52 +00:00
|
|
|
"||bytedance.map.fastly.net^",
|
2020-08-12 10:03:17 +00:00
|
|
|
"||douyin.com^",
|
|
|
|
"||tiktokv.com^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "vimeo",
|
|
|
|
rules: []string{"||vimeo.com^", "||vimeocdn.com^", "*vod-adaptive.akamaized.net^"},
|
|
|
|
}, {
|
|
|
|
name: "pinterest",
|
|
|
|
rules: []string{"||pinterest.*^", "||pinimg.com^"},
|
|
|
|
}, {
|
|
|
|
name: "imgur",
|
|
|
|
rules: []string{"||imgur.com^"},
|
|
|
|
}, {
|
|
|
|
name: "dailymotion",
|
|
|
|
rules: []string{"||dailymotion.com^", "||dm-event.net^", "||dmcdn.net^"},
|
|
|
|
}, {
|
|
|
|
name: "qq",
|
|
|
|
rules: []string{
|
|
|
|
// Block qq.com and subdomains excluding WeChat's domains.
|
|
|
|
"||qq.com^$denyallow=wx.qq.com|weixin.qq.com",
|
2021-02-04 15:16:01 +00:00
|
|
|
"||qqzaixian.com^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "wechat",
|
|
|
|
rules: []string{"||wechat.com^", "||weixin.qq.com^", "||wx.qq.com^"},
|
|
|
|
}, {
|
|
|
|
name: "viber",
|
|
|
|
rules: []string{"||viber.com^"},
|
|
|
|
}, {
|
|
|
|
name: "weibo",
|
|
|
|
rules: []string{"||weibo.com^"},
|
|
|
|
}, {
|
|
|
|
name: "9gag",
|
|
|
|
rules: []string{"||9cache.com^", "||9gag.com^"},
|
|
|
|
}, {
|
|
|
|
name: "telegram",
|
|
|
|
rules: []string{"||t.me^", "||telegram.me^", "||telegram.org^"},
|
|
|
|
}, {
|
|
|
|
name: "disneyplus",
|
|
|
|
rules: []string{
|
2021-02-04 15:16:01 +00:00
|
|
|
"||disney-plus.net^",
|
|
|
|
"||disneyplus.com^",
|
2021-08-20 16:49:05 +00:00
|
|
|
"||disney.playback.edge.bamgrid.com^",
|
|
|
|
"||media.dssott.com^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "hulu",
|
|
|
|
rules: []string{"||hulu.com^"},
|
|
|
|
}, {
|
|
|
|
name: "spotify",
|
|
|
|
rules: []string{
|
2021-02-04 15:16:01 +00:00
|
|
|
"/_spotify-connect._tcp.local/",
|
|
|
|
"||spotify.com^",
|
|
|
|
"||scdn.co^",
|
|
|
|
"||spotify.com.edgesuite.net^",
|
|
|
|
"||spotify.map.fastly.net^",
|
|
|
|
"||spotify.map.fastlylb.net^",
|
|
|
|
"||spotifycdn.net^",
|
|
|
|
"||audio-ak-spotify-com.akamaized.net^",
|
|
|
|
"||audio4-ak-spotify-com.akamaized.net^",
|
|
|
|
"||heads-ak-spotify-com.akamaized.net^",
|
|
|
|
"||heads4-ak-spotify-com.akamaized.net^",
|
2022-03-23 11:19:45 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "tinder",
|
|
|
|
rules: []string{
|
2021-02-04 15:16:01 +00:00
|
|
|
"||gotinder.com^",
|
|
|
|
"||tinder.com^",
|
|
|
|
"||tindersparks.com^",
|
2022-03-23 11:19:45 +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 {
|
2021-11-26 15:25:43 +00:00
|
|
|
rule, err := rules.NewNetworkRule(text, BlockedSvcsListID)
|
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
|
2021-05-21 13:15:47 +00:00
|
|
|
func (d *DNSFilter) ApplyBlockedServices(setts *Settings, list []string, global bool) {
|
2020-02-18 17:17:35 +00:00
|
|
|
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-12-17 10:32:46 +00:00
|
|
|
func (d *DNSFilter) handleBlockedServicesList(w http.ResponseWriter, r *http.Request) {
|
2020-02-18 17:17:35 +00:00
|
|
|
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 {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusInternalServerError, "json.Encode: %s", err)
|
|
|
|
|
2019-07-23 09:16:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 10:32:46 +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 {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(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
|
2020-12-17 10:32:46 +00:00
|
|
|
func (d *DNSFilter) registerBlockedServicesHandlers() {
|
2021-02-04 11:15:34 +00:00
|
|
|
d.Config.HTTPRegister(http.MethodGet, "/control/blocked_services/list", d.handleBlockedServicesList)
|
|
|
|
d.Config.HTTPRegister(http.MethodPost, "/control/blocked_services/set", d.handleBlockedServicesSet)
|
2019-07-23 09:16:36 +00:00
|
|
|
}
|