Change blacklist to comprise domains.
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
gemini://gemi.dev/cgi-bin/waffle.cgi
|
|
||||||
gemini://alexey.shpakovsky.ru/maze
|
|
||||||
gemini://kennedy.gemi.dev
|
|
||||||
gemini://musicbrainz.uploadedlobster.com
|
|
||||||
gemini://gemini.bunburya.eu/remini
|
|
||||||
5
blacklists/domains.txt
Normal file
5
blacklists/domains.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
gemi.dev
|
||||||
|
kennedy.gemi.dev
|
||||||
|
alexey.shpakovsky.ru
|
||||||
|
musicbrainz.uploadedlobster.com
|
||||||
|
gemini.bunburya.eu
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
package gemini
|
package gemini
|
||||||
|
|
||||||
import "strings"
|
import "gemini-grc/logging"
|
||||||
|
|
||||||
var Blacklist *[]string
|
var Blacklist *[]string
|
||||||
|
|
||||||
func InBlacklist(s *Snapshot) bool {
|
func InBlacklist(s *Snapshot) bool {
|
||||||
if Blacklist == nil {
|
if Blacklist == nil {
|
||||||
data := ReadLines("blacklist.txt")
|
data := ReadLines("blacklists/domains.txt")
|
||||||
Blacklist = &data
|
Blacklist = &data
|
||||||
|
logging.LogInfo("Loaded %d blacklisted domains", len(*Blacklist))
|
||||||
}
|
}
|
||||||
for _, l := range *Blacklist {
|
for _, l := range *Blacklist {
|
||||||
if strings.HasPrefix(s.URL.String(), l) {
|
if s.Host == l {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// if strings.HasPrefix(s.URL.String(), l) {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func SaveToFile(rootPath string, s *Snapshot, done chan struct{}) {
|
|||||||
func ReadLines(path string) []string {
|
func ReadLines(path string) []string {
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("Failed to read blacklist file: %s", err))
|
panic(fmt.Sprintf("Failed to read file: %s", err))
|
||||||
}
|
}
|
||||||
lines := strings.Split(string(data), "\n")
|
lines := strings.Split(string(data), "\n")
|
||||||
// Remove last line if empty
|
// Remove last line if empty
|
||||||
@@ -108,6 +108,5 @@ func ReadLines(path string) []string {
|
|||||||
if lines[len(lines)-1] == "" {
|
if lines[len(lines)-1] == "" {
|
||||||
lines = lines[:len(lines)-1]
|
lines = lines[:len(lines)-1]
|
||||||
}
|
}
|
||||||
logging.LogInfo("Loaded %d blacklist URLs", len(lines))
|
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user