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_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 {

View File

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

19
web.go
View File

@ -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
}