Skip to content

Commit

Permalink
Merge branch 'AdguardTeam:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hoang-rio authored Jun 28, 2024
2 parents de29dd0 + 3993f4c commit 45c386e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/src/helpers/filters/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default {
"phishing_army": {
"name": "Phishing Army",
"categoryId": "security",
"homepage": "https://gitlab.com/malware-filter/phishing-filter",
"homepage": "https://phishing.army/",
"source": "https://adguardteam.github.io/HostlistsRegistry/assets/filter_18.txt"
},
"scam_blocklist_by_durablenapkin": {
Expand Down
45 changes: 29 additions & 16 deletions scripts/vetted-filters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ package main

import (
"bytes"
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"net/url"
"os"
"time"

"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/google/renameio/v2/maybe"
)

func main() {
ctx := context.Background()
l := slogutil.New(nil)

urlStr := "https://adguardteam.github.io/HostlistsRegistry/assets/filters.json"
if v, ok := os.LookupEnv("URL"); ok {
urlStr = v
Expand All @@ -31,7 +36,7 @@ func main() {

resp, err := c.Get(urlStr)
check(err)
defer log.OnCloserError(resp.Body, log.ERROR)
defer slogutil.CloseAndLog(ctx, l, resp.Body, slog.LevelError)

if resp.StatusCode != http.StatusOK {
panic(fmt.Errorf("expected code %d, got %d", http.StatusOK, resp.StatusCode))
Expand Down Expand Up @@ -64,13 +69,13 @@ func main() {
}

for i, f := range hlFlt.Filters {
id := f.FilterID
key := f.FilterKey
cat := f.category()
if cat == "" {
log.Info("warning: filter %s at index %d does not have a fitting category", id, i)
l.WarnContext(ctx, "no fitting category for filter", "key", key, "idx", i)
}

aghFlt.Filters[id] = &aghFiltersFilter{
aghFlt.Filters[key] = &aghFiltersFilter{
Name: f.Name,
CategoryID: cat,
Homepage: f.Homepage,
Expand Down Expand Up @@ -118,26 +123,34 @@ type hlFilters struct {

// hlFiltersFilter is the JSON structure for a filter in the Hostlists Registry.
type hlFiltersFilter struct {
DownloadURL string `json:"downloadUrl"`
FilterID string `json:"filterId"`
Homepage string `json:"homepage"`
Name string `json:"name"`
Tags []string `json:"tags"`
DownloadURL string `json:"downloadUrl"`
FilterKey string `json:"filterKey"`
Homepage string `json:"homepage"`
Name string `json:"name"`
Tags []int `json:"tags"`
}

// Known tag IDs. Keep in sync with tags/metadata.json in the source repo.
const (
tagIDGeneral = 1
tagIDSecurity = 2
tagIDRegional = 3
tagIDOther = 4
)

// category returns the AdGuard Home category for this filter. If there is no
// fitting category, cat is empty.
func (f *hlFiltersFilter) category() (cat string) {
for _, t := range f.Tags {
switch t {
case "purpose:general":
case tagIDGeneral:
return "general"
case "purpose:other":
return "other"
case "purpose:regional":
return "regional"
case "purpose:security":
case tagIDSecurity:
return "security"
case tagIDRegional:
return "regional"
case tagIDOther:
return "other"
}
}

Expand Down

0 comments on commit 45c386e

Please sign in to comment.