all repos — honk @ f0517822b4985b269f9a8e108cfbda6dfc620831

my fork of honk

first part of a do not federate firewall
Ted Unangst tedu@tedunangst.com
Mon, 24 Jun 2019 21:14:47 -0400
commit

f0517822b4985b269f9a8e108cfbda6dfc620831

parent

46df8b5ced26c13c8e746f3812d05b7b516126a7

2 files changed, 39 insertions(+), 0 deletions(-)

jump to
M honk.gohonk.go

@@ -107,6 +107,17 @@ templinfo["UserInfo"] = login.GetUserInfo(r)

return templinfo } +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 homepage(w http.ResponseWriter, r *http.Request) { templinfo := getInfo(r) u := login.GetUserInfo(r)

@@ -449,6 +460,11 @@ if err != nil {

http.NotFound(w, r) return } + if stealthed(r) { + http.NotFound(w, r) + return + } + honks := gethonksbyuser(name, false) var jonks []map[string]interface{}

@@ -546,6 +562,11 @@ if err != nil {

http.NotFound(w, r) return } + if stealthed(r) { + http.NotFound(w, r) + return + } + xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path) h := getxonk(user.ID, xid) if h == nil || !h.Public {

@@ -1539,6 +1560,7 @@ log.Fatal("incorrect database version. run upgrade.")

} getconfig("servermsg", &serverMsg) getconfig("servername", &serverName) + getconfig("dnf", &donotfedafterdark) prepareStatements(db) switch cmd { case "adduser":
M util.goutil.go

@@ -260,6 +260,23 @@ return db

} func getconfig(key string, value interface{}) error { + m, ok := value.(*map[string]bool) + if ok { + rows, err := stmtConfig.Query(key) + if err != nil { + return err + } + defer rows.Close() + for rows.Next() { + var s string + err = rows.Scan(&s) + if err != nil { + return err + } + (*m)[s] = true + } + return nil + } row := stmtConfig.QueryRow(key) err := row.Scan(value) if err == sql.ErrNoRows {