From 6ea1f7bfa09ca8ed02e108280ab13d0a1429f97f Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 21 Sep 2019 18:20:50 -0400 Subject: [PATCH] rework stealth mode --- fun.go | 16 +++++++++++++++- honk.go | 1 - web.go | 19 ++++++------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/fun.go b/fun.go index 9c059a2..235a8c0 100644 --- a/fun.go +++ b/fun.go @@ -461,7 +461,7 @@ func ontologize(s string) string { } var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)") -var re_urlhost = regexp.MustCompile("https://([^/]+)") +var re_urlhost = regexp.MustCompile("https://([^/ ]+)") func originate(u string) string { m := re_urlhost.FindStringSubmatch(u) @@ -744,6 +744,20 @@ func thoudostbitethythumb(userid int64, who []string, objid string) bool { return false } +func stealthmode(userid int64, r *http.Request) bool { + agent := r.UserAgent() + agent = originate(agent) + addr := r.Header.Get("X-Forwarded-For") + thumblock.Lock() + biters := thumbbiters[userid] + thumblock.Unlock() + fake := (agent != "" && biters[agent]) || (addr != "" && biters[addr]) + if fake { + log.Printf("faking 404 for %s from %s", agent, addr) + } + return fake +} + func keymatch(keyname string, actor string) string { hash := strings.IndexByte(keyname, '#') if hash == -1 { diff --git a/honk.go b/honk.go index 9df04f2..7c3bb22 100644 --- a/honk.go +++ b/honk.go @@ -131,7 +131,6 @@ func main() { getconfig("servername", &serverName) getconfig("usersep", &userSep) getconfig("honksep", &honkSep) - getconfig("dnf", &donotfedafterdark) prepareStatements(db) switch cmd { case "adduser": diff --git a/web.go b/web.go index 58b2272..3e9d774 100644 --- a/web.go +++ b/web.go @@ -48,17 +48,6 @@ var readviews *templates.Template var userSep = "u" var honkSep = "h" -var donotfedafterdark = make(map[string]bool) - -func stealthed(r *http.Request) bool { - addr := r.Header.Get("X-Forwarded-For") - fake := donotfedafterdark[addr] - if fake { - log.Printf("faking 404 for %s", addr) - } - return fake -} - func getuserstyle(u *login.UserInfo) template.CSS { if u == nil { return "" @@ -438,7 +427,7 @@ func outbox(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - if stealthed(r) { + if stealthmode(user.ID, r) { http.NotFound(w, r) return } @@ -495,6 +484,10 @@ func showuser(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } + if stealthmode(user.ID, r) { + http.NotFound(w, r) + return + } if friendorfoe(r.Header.Get("Accept")) { j := asjonker(user) w.Header().Set("Content-Type", theonetruename) @@ -616,7 +609,7 @@ func showhonk(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } - if stealthed(r) { + if stealthmode(user.ID, r) { http.NotFound(w, r) return }