rework stealth mode
Ted Unangst tedu@tedunangst.com
Sat, 21 Sep 2019 18:20:50 -0400
M
fun.go
→
fun.go
@@ -461,7 +461,7 @@ return s
} 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)@@ -742,6 +742,20 @@ }
} } 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 {
M
web.go
→
web.go
@@ -48,17 +48,6 @@
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 @@ if err != nil {
http.NotFound(w, r) return } - if stealthed(r) { + if stealthmode(user.ID, r) { http.NotFound(w, r) return }@@ -492,6 +481,10 @@ name := mux.Vars(r)["name"]
user, err := butwhatabout(name) if err != nil { log.Printf("user not found %s: %s", name, err) + http.NotFound(w, r) + return + } + if stealthmode(user.ID, r) { http.NotFound(w, r) return }@@ -616,7 +609,7 @@ if err != nil {
http.NotFound(w, r) return } - if stealthed(r) { + if stealthmode(user.ID, r) { http.NotFound(w, r) return }