Compare commits

...

11 Commits

Author SHA1 Message Date
Dirk Nederveen e1d2ebe219
Merge branch 'main' into docker 2023-07-16 07:08:24 +02:00
Ted Unangst 2dd6b27356 when looking at another user on the same server, don't display controls.
you can't interact with other users via their pages because technically
it's like they are on a different server.
2023-07-15 18:19:12 -04:00
Ted Unangst 97b9634a9e practically, sufficient for keys to be owned by same domain as actor.
the url scheme doesn't matter, and need not match.
problem identified by eta.
2023-07-15 18:07:07 -04:00
Ted Unangst 54fd484558 this query should not find bonks, which later causes crashes.
thanks benjojo
2023-07-15 18:03:47 -04:00
Ted Unangst 211ab9a97a cleanup some old mistakes and cruft from the database 2023-07-15 17:59:44 -04:00
Ted Unangst 14bc7f5cec CGO is required, and the compiler error without is confusing 2023-07-13 02:27:53 -04:00
Ted Unangst 51fe6d99b2 don't need fmt 2023-07-10 00:16:42 -04:00
Ted Unangst 43705654d1 fix 2023-07-10 00:16:17 -04:00
Ted Unangst dea831d23f error check unveil 2023-07-10 00:15:35 -04:00
Ted Unangst bf09636bc1 remove old imports 2023-07-10 00:15:02 -04:00
Ted Unangst cdc0ffaeb7 clean out some years old upgrade code 2023-07-08 12:32:48 -04:00
9 changed files with 28 additions and 195 deletions

View File

@ -2,7 +2,7 @@
all: honk
honk: .preflightcheck schema.sql *.go go.mod
go build -mod=`ls -d vendor 2> /dev/null` -o honk
env CGO_ENABLED=1 go build -mod=`ls -d vendor 2> /dev/null` -o honk
.preflightcheck: preflight.sh
@sh ./preflight.sh

View File

@ -850,9 +850,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
targ, _ := obj.GetString("target")
content += string(templates.Sprintf(`<p>Moved to <a href="%s">%s</a>`, targ, targ))
}
if what == "honk" && rid != "" {
what = "tonk"
}
if len(content) > 90001 {
ilog.Printf("content too long. truncating")
content = content[:90001]
@ -1239,8 +1236,6 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
switch h.What {
case "update":
fallthrough
case "tonk":
fallthrough
case "event":
fallthrough
case "honk":

View File

@ -504,8 +504,6 @@ func donksforhonks(honks []*Honk) {
elog.Printf("error parsing badonks: %s", err)
continue
}
case "wonkles":
case "guesses":
case "oldrev":
default:
elog.Printf("unknown meta genus: %s", genus)
@ -1151,14 +1149,14 @@ func prepareStatements(db *sql.DB) {
smalllimit := " order by honks.honkid desc limit ?"
butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)"
stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc")
stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? and what <> 'bonk' order by honks.honkid asc")
stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2")
stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+smalllimit)
stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+smalllimit)
stmtUserHonks = preparetodie(db, selecthonks+"where honks.honkid > ? and (whofore = 2 or whofore = ?) and username = ? and dt > ?"+smalllimit)
myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')"
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit)
stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit)
stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (rid = '' or what = 'bonk')"+myhonkers+butnotthose+limit)
stmtHonksForMe = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit)
stmtHonksFromLongAgo = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and dt < ? and whofore = 2"+butnotthose+limit)
stmtHonksISaved = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and flags & 4 order by honks.honkid desc")

12
fun.go
View File

@ -66,7 +66,7 @@ func reverbolate(userid int64, honks []*Honk) {
somenumberedusers.Get(userid, &user)
for _, h := range honks {
h.What += "ed"
if h.What == "tonked" {
if h.What == "honked" && h.RID != "" {
h.What = "honked back"
h.Style += " subtle"
}
@ -694,13 +694,9 @@ func savingthrow(keyname string) {
}
func keymatch(keyname string, actor string) string {
hash := strings.IndexByte(keyname, '#')
if hash == -1 {
hash = len(keyname)
}
owner := keyname[0:hash]
if owner == actor {
return originate(actor)
origin := originate(actor)
if origin == originate(keyname) {
return origin
}
return ""
}

View File

@ -155,7 +155,6 @@ const (
flagIsSaved = 4
flagIsUntagged = 8
flagIsReacted = 16
flagIsWonked = 32
)
func (honk *Honk) IsAcked() bool {

View File

@ -148,9 +148,6 @@ func importMastotoots(user *WhatAbout, source string) {
Format: "html",
Precis: toot.Object.Summary,
}
if honk.RID != "" {
honk.What = "tonk"
}
if !loudandproud(honk.Audience) {
honk.Whofore = 3
}
@ -387,13 +384,11 @@ func importTwitter(username, source string) {
noise := ""
if parent := tweetmap[t.Tweet.InReplyToStatusID]; parent != nil {
t.convoy = parent.convoy
what = "tonk"
} else {
t.convoy = "data:,acoustichonkytonk-" + t.Tweet.IdStr
if t.Tweet.InReplyToScreenName != "" {
noise = fmt.Sprintf("re: https://twitter.com/%s/status/%s\n\n",
t.Tweet.InReplyToScreenName, t.Tweet.InReplyToStatusID)
what = "tonk"
}
}
audience := []string{thewholeworld}

View File

@ -25,11 +25,10 @@ package main
import "C"
import (
"fmt"
"unsafe"
)
func Unveil(path string, perms string) error {
func Unveil(path string, perms string) {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
cperms := C.CString(perms)
@ -37,20 +36,18 @@ func Unveil(path string, perms string) error {
rv, err := C.unveil(cpath, cperms)
if rv != 0 {
return fmt.Errorf("unveil(%s, %s) failure (%d)", path, perms, err)
elog.Fatalf("unveil(%s, %s) failure (%d)", path, perms, err)
}
return nil
}
func Pledge(promises string) error {
func Pledge(promises string) {
cpromises := C.CString(promises)
defer C.free(unsafe.Pointer(cpromises))
rv, err := C.pledge(cpromises, nil)
if rv != 0 {
return fmt.Errorf("pledge(%s) failure (%d)", promises, err)
elog.Fatalf("pledge(%s) failure (%d)", promises, err)
}
return nil
}
func init() {

View File

@ -18,11 +18,9 @@ package main
import (
"database/sql"
"os"
"strings"
"time"
)
var myVersion = 42
var myVersion = 43
type dbexecer interface {
Exec(query string, args ...interface{}) (sql.Result, error)
@ -41,164 +39,10 @@ func upgradedb() {
getconfig("dbversion", &dbversion)
getconfig("servername", &serverName)
if dbversion < 13 {
if dbversion < 40 {
elog.Fatal("database is too old to upgrade")
}
switch dbversion {
case 25:
doordie(db, "delete from auth")
doordie(db, "alter table auth add column expiry text")
doordie(db, "update config set value = 26 where key = 'dbversion'")
fallthrough
case 26:
s := ""
getconfig("servermsg", &s)
if s == "" {
setconfig("servermsg", "<h2>Things happen.</h2>")
}
s = ""
getconfig("aboutmsg", &s)
if s == "" {
setconfig("aboutmsg", "<h3>What is honk?</h3><p>Honk is amazing!")
}
s = ""
getconfig("loginmsg", &s)
if s == "" {
setconfig("loginmsg", "<h2>login</h2>")
}
d := -1
getconfig("devel", &d)
if d == -1 {
setconfig("devel", 0)
}
doordie(db, "update config set value = 27 where key = 'dbversion'")
fallthrough
case 27:
createserveruser(db)
doordie(db, "update config set value = 28 where key = 'dbversion'")
fallthrough
case 28:
doordie(db, "drop table doovers")
doordie(db, "create table doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob)")
doordie(db, "update config set value = 29 where key = 'dbversion'")
fallthrough
case 29:
doordie(db, "alter table honkers add column owner text")
doordie(db, "update honkers set owner = xid")
doordie(db, "update config set value = 30 where key = 'dbversion'")
fallthrough
case 30:
tx, err := db.Begin()
if err != nil {
elog.Fatal(err)
}
rows, err := tx.Query("select userid, options from users")
if err != nil {
elog.Fatal(err)
}
m := make(map[int64]string)
for rows.Next() {
var userid int64
var options string
err = rows.Scan(&userid, &options)
if err != nil {
elog.Fatal(err)
}
var uo UserOptions
uo.SkinnyCSS = strings.Contains(options, " skinny ")
m[userid], err = jsonify(uo)
if err != nil {
elog.Fatal(err)
}
}
rows.Close()
for u, o := range m {
_, err = tx.Exec("update users set options = ? where userid = ?", o, u)
if err != nil {
elog.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
elog.Fatal(err)
}
doordie(db, "update config set value = 31 where key = 'dbversion'")
fallthrough
case 31:
doordie(db, "create table tracks (xid text, fetches text)")
doordie(db, "create index idx_trackhonkid on tracks(xid)")
doordie(db, "update config set value = 32 where key = 'dbversion'")
fallthrough
case 32:
doordie(db, "alter table xonkers add column dt text")
doordie(db, "update xonkers set dt = ?", time.Now().UTC().Format(dbtimeformat))
doordie(db, "update config set value = 33 where key = 'dbversion'")
fallthrough
case 33:
doordie(db, "alter table honkers add column meta text")
doordie(db, "update honkers set meta = '{}'")
doordie(db, "update config set value = 34 where key = 'dbversion'")
fallthrough
case 34:
doordie(db, "create table chonks (chonkid integer primary key, userid integer, xid text, who txt, target text, dt text, noise text, format text)")
doordie(db, "update config set value = 35 where key = 'dbversion'")
fallthrough
case 35:
doordie(db, "alter table donks add column chonkid integer")
doordie(db, "update donks set chonkid = -1")
doordie(db, "create index idx_donkshonk on donks(honkid)")
doordie(db, "create index idx_donkschonk on donks(chonkid)")
doordie(db, "update config set value = 36 where key = 'dbversion'")
fallthrough
case 36:
doordie(db, "alter table honkers add column folxid text")
doordie(db, "update honkers set folxid = 'lostdata'")
doordie(db, "update config set value = 37 where key = 'dbversion'")
fallthrough
case 37:
doordie(db, "update honkers set combos = '' where combos is null")
doordie(db, "update honkers set owner = '' where owner is null")
doordie(db, "update honkers set meta = '' where meta is null")
doordie(db, "update honkers set folxid = '' where folxid is null")
doordie(db, "update config set value = 38 where key = 'dbversion'")
fallthrough
case 38:
doordie(db, "update honkers set folxid = abs(random())")
doordie(db, "update config set value = 39 where key = 'dbversion'")
fallthrough
case 39:
blobdb := openblobdb()
doordie(blobdb, "alter table filedata add column hash text")
doordie(blobdb, "create index idx_filehash on filedata(hash)")
rows, err := blobdb.Query("select xid, content from filedata")
if err != nil {
elog.Fatal(err)
}
m := make(map[string]string)
for rows.Next() {
var xid string
var data sql.RawBytes
err := rows.Scan(&xid, &data)
if err != nil {
elog.Fatal(err)
}
hash := hashfiledata(data)
m[xid] = hash
}
rows.Close()
tx, err := blobdb.Begin()
if err != nil {
elog.Fatal(err)
}
for xid, hash := range m {
doordie(tx, "update filedata set hash = ? where xid = ?", hash, xid)
}
err = tx.Commit()
if err != nil {
elog.Fatal(err)
}
doordie(db, "update config set value = 40 where key = 'dbversion'")
fallthrough
case 40:
doordie(db, "PRAGMA journal_mode=WAL")
blobdb := openblobdb()
@ -238,6 +82,11 @@ func upgradedb() {
doordie(db, "update config set value = 42 where key = 'dbversion'")
fallthrough
case 42:
doordie(db, "update honks set what = 'honk', flags = flags & ~ 32 where what = 'tonk' or what = 'wonk'")
doordie(db, "delete from honkmeta where genus = 'wonkles' or genus = 'guesses'")
doordie(db, "update config set value = 43 where key = 'dbversion'")
fallthrough
case 43:
default:
elog.Fatalf("can't upgrade unknown version %d", dbversion)

12
web.go
View File

@ -723,14 +723,19 @@ func showuser(w http.ResponseWriter, r *http.Request) {
return
}
u := login.GetUserInfo(r)
honks := gethonksbyuser(name, u != nil && u.Username == name, 0)
if u != nil && u.Username != name {
u = nil
}
honks := gethonksbyuser(name, u != nil, 0)
templinfo := getInfo(r)
templinfo["PageName"] = "user"
templinfo["PageArg"] = name
templinfo["Name"] = user.Name
templinfo["WhatAbout"] = user.HTAbout
templinfo["ServerMessage"] = ""
if u != nil {
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
}
honkpage(w, u, honks, templinfo)
}
@ -1184,7 +1189,9 @@ func showonehonk(w http.ResponseWriter, r *http.Request) {
}
templinfo["ServerMessage"] = "one honk maybe more"
if u != nil {
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
}
templinfo["APAltLink"] = templates.Sprintf("<link href='%s' rel='alternate' type='application/activity+json'>", xid)
honkpage(w, u, honks, templinfo)
}
@ -1708,9 +1715,6 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
} else {
xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
what := "honk"
if rid != "" {
what = "tonk"
}
honk = &Honk{
UserID: userinfo.UserID,
Username: userinfo.Username,