rework stealth mode

This commit is contained in:
Ted Unangst 2019-09-21 18:20:50 -04:00
parent d97d815dae
commit 6ea1f7bfa0
3 changed files with 21 additions and 15 deletions

16
fun.go
View File

@ -461,7 +461,7 @@ func ontologize(s string) string {
} }
var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)") var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")
var re_urlhost = regexp.MustCompile("https://([^/]+)") var re_urlhost = regexp.MustCompile("https://([^/ ]+)")
func originate(u string) string { func originate(u string) string {
m := re_urlhost.FindStringSubmatch(u) m := re_urlhost.FindStringSubmatch(u)
@ -744,6 +744,20 @@ func thoudostbitethythumb(userid int64, who []string, objid string) bool {
return false 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 { func keymatch(keyname string, actor string) string {
hash := strings.IndexByte(keyname, '#') hash := strings.IndexByte(keyname, '#')
if hash == -1 { if hash == -1 {

View File

@ -131,7 +131,6 @@ func main() {
getconfig("servername", &serverName) getconfig("servername", &serverName)
getconfig("usersep", &userSep) getconfig("usersep", &userSep)
getconfig("honksep", &honkSep) getconfig("honksep", &honkSep)
getconfig("dnf", &donotfedafterdark)
prepareStatements(db) prepareStatements(db)
switch cmd { switch cmd {
case "adduser": case "adduser":

19
web.go
View File

@ -48,17 +48,6 @@ var readviews *templates.Template
var userSep = "u" var userSep = "u"
var honkSep = "h" 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 { func getuserstyle(u *login.UserInfo) template.CSS {
if u == nil { if u == nil {
return "" return ""
@ -438,7 +427,7 @@ func outbox(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
if stealthed(r) { if stealthmode(user.ID, r) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
@ -495,6 +484,10 @@ func showuser(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
if friendorfoe(r.Header.Get("Accept")) { if friendorfoe(r.Header.Get("Accept")) {
j := asjonker(user) j := asjonker(user)
w.Header().Set("Content-Type", theonetruename) w.Header().Set("Content-Type", theonetruename)
@ -616,7 +609,7 @@ func showhonk(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
if stealthed(r) { if stealthmode(user.ID, r) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }