clemency for the sinners. allow pardon of zonkers.
Ted Unangst tedu@tedunangst.com
Fri, 26 Apr 2019 15:11:24 -0400
4 files changed,
77 insertions(+),
19 deletions(-)
M
activity.go
→
activity.go
@@ -233,8 +233,8 @@ }
if x.What == "eradicate" { return true } - if thoudostbitethythumb(user.ID, x.Honker, x.XID) { - log.Printf("not saving thumb biter %s\n", x.Honker) + if thoudostbitethythumb(user.ID, x.Audience, x.XID) { + log.Printf("not saving thumb biter? %s", x.Honker) return false } return needxonkid(user, x.XID)
M
fun.go
→
fun.go
@@ -324,17 +324,51 @@ ziggylock.Unlock()
return zag(r, payload) } -func thoudostbitethythumb(userid int64, who string, objid string) bool { - where := "" - m := re_unurl.FindStringSubmatch(who) - if len(m) > 2 { - where = m[1] +var thumbbiters map[int64]map[string]bool +var thumblock sync.Mutex + +func bitethethumbs() { + rows, err := stmtThumbBiters.Query() + if err != nil { + log.Printf("error getting thumbbiters: %s", err) + return } - row := stmtThumbBiter.QueryRow(who, where, userid) - var id int64 - err := row.Scan(&id) - if err == nil { - return true + defer rows.Close() + thumblock.Lock() + defer thumblock.Unlock() + thumbbiters = make(map[int64]map[string]bool) + for rows.Next() { + var userid int64 + var name, wherefore string + err = rows.Scan(&userid, &name, &wherefore) + if err != nil { + log.Printf("error scanning zonker: %s", err) + continue + } + m := thumbbiters[userid] + if m == nil { + m = make(map[string]bool) + thumbbiters[userid] = m + } + m[name] = true + } +} + +func thoudostbitethythumb(userid int64, who []string, objid string) bool { + thumblock.Lock() + biters := thumbbiters[userid] + thumblock.Unlock() + for _, w := range who { + if biters[w] { + return true + } + m := re_unurl.FindStringSubmatch(w) + if len(m) > 2 { + where := m[1] + if biters[where] { + return true + } + } } return false }
M
honk.go
→
honk.go
@@ -321,7 +321,7 @@ log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
return } objid, _ := jsongetstring(j, "id") - if thoudostbitethythumb(user.ID, who, objid) { + if thoudostbitethythumb(user.ID, []string{who}, objid) { log.Printf("ignoring thumb sucker %s", who) return }@@ -1052,6 +1052,7 @@ http.Redirect(w, r, "/honkers", http.StatusSeeOther)
} type Zonker struct { + ID int64 Name string Wherefore string }@@ -1059,7 +1060,7 @@
func killzone(w http.ResponseWriter, r *http.Request) { db := opendatabase() userinfo := login.GetUserInfo(r) - rows, err := db.Query("select name, wherefore from zonkers where userid = ?", userinfo.UserID) + rows, err := db.Query("select zonkerid, name, wherefore from zonkers where userid = ?", userinfo.UserID) if err != nil { log.Printf("err: %s", err) return@@ -1067,7 +1068,7 @@ }
var zonkers []Zonker for rows.Next() { var z Zonker - rows.Scan(&z.Name, &z.Wherefore) + rows.Scan(&z.ID, &z.Name, &z.Wherefore) zonkers = append(zonkers, z) } templinfo := getInfo(r)@@ -1081,6 +1082,16 @@ }
func killitwithfire(w http.ResponseWriter, r *http.Request) { userinfo := login.GetUserInfo(r) + itsok := r.FormValue("itsok") + if itsok == "iforgiveyou" { + zonkerid, _ := strconv.ParseInt(r.FormValue("zonkerid"), 10, 0) + db := opendatabase() + db.Exec("delete from zonkers where userid = ? and zonkerid = ?", + userinfo.UserID, zonkerid) + bitethethumbs() + http.Redirect(w, r, "/killzone", http.StatusSeeOther) + return + } wherefore := r.FormValue("wherefore") name := r.FormValue("name") if name == "" {@@ -1095,7 +1106,10 @@ return
} db := opendatabase() db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", - userinfo.UserID, name, wherefore) + userinfo.UserID, name, wherefore) + if wherefore == "zonker" || wherefore == "zurl" { + bitethethumbs() + } http.Redirect(w, r, "/killzone", http.StatusSeeOther) }@@ -1174,6 +1188,8 @@ s = "views/local.css"
savedstyleparams[s] = getstyleparam(s) } + bitethethumbs() + mux := mux.NewRouter() mux.Use(login.Checker)@@ -1227,7 +1243,7 @@ var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt -var stmtHasHonker, stmtThumbBiter, stmtZonkIt *sql.Stmt +var stmtHasHonker, stmtThumbBiters, stmtZonkIt *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)@@ -1269,7 +1285,7 @@ stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers")
stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") stmtZonkIt = preparetodie(db, "update honks set what = 'zonk' where userid = ? and xid = ?") - stmtThumbBiter = preparetodie(db, "select zonkerid from zonkers where ((name = ? and wherefore = 'zonker') or (name = ? and wherefore = 'zurl')) and userid = ?") + stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl')") } func ElaborateUnitTests() {
M
views/zonkers.html
→
views/zonkers.html
@@ -19,10 +19,18 @@ <label for="iszonvoy">Zonvoy</label>
<p><input tabindex=1 type="submit" name="kill" value="kill"> </form> </div> +{{ $killcsrf := .KillCSRF }} {{ range .Zonkers }} -<div class="honk" id="honkerID"> +<div class="honk"> <p>What: {{ .Name }} <p>Where: {{ .Wherefore }} +<form action="/killitwithfire" method="POST"> +<input type="hidden" name="CSRF" value="{{ $killcsrf }}"> +<input type="hidden" name="zonkerid" value="{{ .ID }}"> +<input type="hidden" name="itsok" value="iforgiveyou"> +<input type="submit" name="pardon" value="pardon"> +</form> +<p> </div> {{ end }} </div>