clemency for the sinners. allow pardon of zonkers.

This commit is contained in:
Ted Unangst 2019-04-26 15:11:24 -04:00
parent 2c0a66120a
commit 4da06786e9
4 changed files with 77 additions and 19 deletions

View File

@ -233,8 +233,8 @@ func needxonk(user *WhatAbout, x *Honk) bool {
if x.What == "eradicate" { if x.What == "eradicate" {
return true return true
} }
if thoudostbitethythumb(user.ID, x.Honker, x.XID) { if thoudostbitethythumb(user.ID, x.Audience, x.XID) {
log.Printf("not saving thumb biter %s\n", x.Honker) log.Printf("not saving thumb biter? %s", x.Honker)
return false return false
} }
return needxonkid(user, x.XID) return needxonkid(user, x.XID)

54
fun.go
View File

@ -324,17 +324,51 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ
return zag(r, payload) return zag(r, payload)
} }
func thoudostbitethythumb(userid int64, who string, objid string) bool { var thumbbiters map[int64]map[string]bool
where := "" var thumblock sync.Mutex
m := re_unurl.FindStringSubmatch(who)
if len(m) > 2 { func bitethethumbs() {
where = m[1] rows, err := stmtThumbBiters.Query()
if err != nil {
log.Printf("error getting thumbbiters: %s", err)
return
} }
row := stmtThumbBiter.QueryRow(who, where, userid) defer rows.Close()
var id int64 thumblock.Lock()
err := row.Scan(&id) defer thumblock.Unlock()
if err == nil { thumbbiters = make(map[int64]map[string]bool)
return true 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 return false
} }

28
honk.go
View File

@ -321,7 +321,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
return return
} }
objid, _ := jsongetstring(j, "id") objid, _ := jsongetstring(j, "id")
if thoudostbitethythumb(user.ID, who, objid) { if thoudostbitethythumb(user.ID, []string{who}, objid) {
log.Printf("ignoring thumb sucker %s", who) log.Printf("ignoring thumb sucker %s", who)
return return
} }
@ -1052,6 +1052,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
} }
type Zonker struct { type Zonker struct {
ID int64
Name string Name string
Wherefore string Wherefore string
} }
@ -1059,7 +1060,7 @@ type Zonker struct {
func killzone(w http.ResponseWriter, r *http.Request) { func killzone(w http.ResponseWriter, r *http.Request) {
db := opendatabase() db := opendatabase()
userinfo := login.GetUserInfo(r) 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 { if err != nil {
log.Printf("err: %s", err) log.Printf("err: %s", err)
return return
@ -1067,7 +1068,7 @@ func killzone(w http.ResponseWriter, r *http.Request) {
var zonkers []Zonker var zonkers []Zonker
for rows.Next() { for rows.Next() {
var z Zonker var z Zonker
rows.Scan(&z.Name, &z.Wherefore) rows.Scan(&z.ID, &z.Name, &z.Wherefore)
zonkers = append(zonkers, z) zonkers = append(zonkers, z)
} }
templinfo := getInfo(r) templinfo := getInfo(r)
@ -1081,6 +1082,16 @@ func killzone(w http.ResponseWriter, r *http.Request) {
func killitwithfire(w http.ResponseWriter, r *http.Request) { func killitwithfire(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r) 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") wherefore := r.FormValue("wherefore")
name := r.FormValue("name") name := r.FormValue("name")
if name == "" { if name == "" {
@ -1095,7 +1106,10 @@ func killitwithfire(w http.ResponseWriter, r *http.Request) {
} }
db := opendatabase() db := opendatabase()
db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)", 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) http.Redirect(w, r, "/killzone", http.StatusSeeOther)
} }
@ -1174,6 +1188,8 @@ func serve() {
savedstyleparams[s] = getstyleparam(s) savedstyleparams[s] = getstyleparam(s)
} }
bitethethumbs()
mux := mux.NewRouter() mux := mux.NewRouter()
mux.Use(login.Checker) mux.Use(login.Checker)
@ -1227,7 +1243,7 @@ var stmtHonksForUser, stmtHonksForMe, stmtDeleteHonk, stmtSaveDub *sql.Stmt
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *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 { func preparetodie(db *sql.DB, s string) *sql.Stmt {
stmt, err := db.Prepare(s) stmt, err := db.Prepare(s)
@ -1269,7 +1285,7 @@ func prepareStatements(db *sql.DB) {
stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?")
stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?")
stmtZonkIt = preparetodie(db, "update honks set what = 'zonk' where userid = ? and xid = ?") 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() { func ElaborateUnitTests() {

View File

@ -19,10 +19,18 @@
<p><input tabindex=1 type="submit" name="kill" value="kill"> <p><input tabindex=1 type="submit" name="kill" value="kill">
</form> </form>
</div> </div>
{{ $killcsrf := .KillCSRF }}
{{ range .Zonkers }} {{ range .Zonkers }}
<div class="honk" id="honkerID"> <div class="honk">
<p>What: {{ .Name }} <p>What: {{ .Name }}
<p>Where: {{ .Wherefore }} <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> </div>
{{ end }} {{ end }}
</div> </div>