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" {
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)

52
fun.go
View File

@ -324,18 +324,52 @@ func makeitworksomehowwithoutregardforkeycontinuity(keyname string, r *http.Requ
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 {
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
}

26
honk.go
View File

@ -321,7 +321,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
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 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
}
type Zonker struct {
ID int64
Name string
Wherefore string
}
@ -1059,7 +1060,7 @@ type Zonker struct {
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 @@ func killzone(w http.ResponseWriter, r *http.Request) {
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 killzone(w http.ResponseWriter, r *http.Request) {
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 == "" {
@ -1096,6 +1107,9 @@ func killitwithfire(w http.ResponseWriter, r *http.Request) {
db := opendatabase()
db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)",
userinfo.UserID, name, wherefore)
if wherefore == "zonker" || wherefore == "zurl" {
bitethethumbs()
}
http.Redirect(w, r, "/killzone", http.StatusSeeOther)
}
@ -1174,6 +1188,8 @@ func serve() {
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 @@ func prepareStatements(db *sql.DB) {
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() {

View File

@ -19,10 +19,18 @@
<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>