]> Sergey Matveev's repositories - tofuproxy.git/blob - rounds/15spy.go
Refactoring
[tofuproxy.git] / rounds / 15spy.go
1 /*
2 tofuproxy -- HTTP proxy with TLS certificates management
3 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package rounds
19
20 import (
21         "fmt"
22         "net/http"
23         "strings"
24
25         "go.stargrave.org/tofuproxy/fifos"
26 )
27
28 var spyDomains = []string{
29         "google-analytics.com",
30         "goo.gl",
31         "ads.google.com",
32         "facebook.com",
33         "facebook.net",
34         "fbcdn.com",
35         "fbcdn.net",
36         "advertising.yandex.ru",
37         "an.yandex.ru",
38         "awaps.yandex.ru",
39         "bs.yandex.ru",
40         "informer.yandex.ru",
41         "mc.yandex.ru",
42         "metrika.yandex.ru",
43         "reklama-direct-yandex.ru",
44         "yandexadexchange.net",
45         "yandexreklama.com",
46         "doubleclick.net",
47         "tns-counter.ru",
48 }
49
50 func RoundDenySpy(
51         host string,
52         resp *http.Response,
53         w http.ResponseWriter,
54         req *http.Request,
55 ) (bool, error) {
56         for _, spy := range spyDomains {
57                 if strings.HasSuffix(host, spy) {
58                         http.NotFound(w, req)
59                         fifos.SinkOther <- fmt.Sprintf(
60                                 "%s %s\t%d\tdeny spy",
61                                 req.Method,
62                                 req.URL.String(),
63                                 http.StatusNotFound,
64                         )
65                         return false, nil
66                 }
67         }
68         return true, nil
69 }