flexible logging

This commit is contained in:
Ted Unangst 2022-02-06 00:42:13 -05:00
parent e2ed63dc43
commit 7eef6ae5d0
16 changed files with 430 additions and 369 deletions

View File

@ -23,7 +23,6 @@ import (
"fmt"
"html"
"io"
"log"
notrand "math/rand"
"net/http"
"net/url"
@ -96,7 +95,7 @@ func PostMsg(keyname string, key httpsig.PrivateKey, url string, msg []byte) err
default:
return fmt.Errorf("http post status: %d", resp.StatusCode)
}
log.Printf("successful post: %s %d", url, resp.StatusCode)
ilog.Printf("successful post: %s %d", url, resp.StatusCode)
return nil
}
@ -113,13 +112,13 @@ func GetJunkHardMode(url string) (junk.Junk, error) {
if err != nil {
emsg := err.Error()
if emsg == "http get status: 502" || strings.Contains(emsg, "timeout") {
log.Printf("trying again after error: %s", emsg)
ilog.Printf("trying again after error: %s", emsg)
time.Sleep(time.Duration(60+notrand.Int63n(60)) * time.Second)
j, err = GetJunk(url)
if err != nil {
log.Printf("still couldn't get it")
ilog.Printf("still couldn't get it")
} else {
log.Printf("retry success!")
ilog.Printf("retry success!")
}
}
}
@ -158,7 +157,7 @@ func fetchsome(url string) ([]byte, error) {
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("error fetching %s: %s", url, err)
ilog.Printf("error fetching %s: %s", url, err)
return nil, err
}
req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName)
@ -167,7 +166,7 @@ func fetchsome(url string) ([]byte, error) {
req = req.WithContext(ctx)
resp, err := client.Do(req)
if err != nil {
log.Printf("error fetching %s: %s", url, err)
ilog.Printf("error fetching %s: %s", url, err)
return nil, err
}
defer resp.Body.Close()
@ -191,7 +190,7 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
if donk := finddonk(url); donk != nil {
return donk
}
log.Printf("saving donk: %s", url)
ilog.Printf("saving donk: %s", url)
data := []byte{}
if localize {
fn := func() (interface{}, error) {
@ -199,19 +198,19 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
}
ii, err := flightdeck.Call(url, fn)
if err != nil {
log.Printf("error fetching donk: %s", err)
ilog.Printf("error fetching donk: %s", err)
localize = false
goto saveit
}
data = ii.([]byte)
if len(data) == 10*1024*1024 {
log.Printf("truncation likely")
ilog.Printf("truncation likely")
}
if strings.HasPrefix(media, "image") {
img, err := shrinkit(data)
if err != nil {
log.Printf("unable to decode image: %s", err)
ilog.Printf("unable to decode image: %s", err)
localize = false
data = []byte{}
goto saveit
@ -220,12 +219,12 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
media = "image/" + img.Format
} else if media == "application/pdf" {
if len(data) > 1000000 {
log.Printf("not saving large pdf")
ilog.Printf("not saving large pdf")
localize = false
data = []byte{}
}
} else if len(data) > 100000 {
log.Printf("not saving large attachment")
ilog.Printf("not saving large attachment")
localize = false
data = []byte{}
}
@ -233,7 +232,7 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
saveit:
fileid, err := savefile(name, desc, url, media, localize, data)
if err != nil {
log.Printf("error saving file %s: %s", url, err)
elog.Printf("error saving file %s: %s", url, err)
return nil
}
donk := new(Donk)
@ -249,7 +248,7 @@ func iszonked(userid int64, xid string) bool {
return true
}
if err != sql.ErrNoRows {
log.Printf("error querying zonk: %s", err)
ilog.Printf("error querying zonk: %s", err)
}
return false
}
@ -274,11 +273,11 @@ func needxonkidX(user *WhatAbout, xid string, isannounce bool) bool {
return false
}
if rejectorigin(user.ID, xid, isannounce) {
log.Printf("rejecting origin: %s", xid)
ilog.Printf("rejecting origin: %s", xid)
return false
}
if iszonked(user.ID, xid) {
log.Printf("already zonked: %s", xid)
ilog.Printf("already zonked: %s", xid)
return false
}
var id int64
@ -288,7 +287,7 @@ func needxonkidX(user *WhatAbout, xid string, isannounce bool) bool {
return false
}
if err != sql.ErrNoRows {
log.Printf("error querying xonk: %s", err)
ilog.Printf("error querying xonk: %s", err)
}
return true
}
@ -300,12 +299,12 @@ func eradicatexonk(userid int64, xid string) {
}
_, err := stmtSaveZonker.Exec(userid, xid, "zonk")
if err != nil {
log.Printf("error eradicating: %s", err)
elog.Printf("error eradicating: %s", err)
}
}
func savexonk(x *Honk) {
log.Printf("saving xonk: %s", x.XID)
ilog.Printf("saving xonk: %s", x.XID)
go handles(x.Honker)
go handles(x.Oonker)
savehonk(x)
@ -322,11 +321,11 @@ var boxofboxes = cache.New(cache.Options{Filler: func(ident string) (*Box, bool)
row := stmtGetXonker.QueryRow(ident, "boxes")
err := row.Scan(&info)
if err != nil {
log.Printf("need to get boxes for %s", ident)
dlog.Printf("need to get boxes for %s", ident)
var j junk.Junk
j, err = GetJunk(ident)
if err != nil {
log.Printf("error getting boxes: %s", err)
dlog.Printf("error getting boxes: %s", err)
return nil, false
}
allinjest(originate(ident), j)
@ -342,10 +341,10 @@ var boxofboxes = cache.New(cache.Options{Filler: func(ident string) (*Box, bool)
}})
func gimmexonks(user *WhatAbout, outbox string) {
log.Printf("getting outbox: %s", outbox)
dlog.Printf("getting outbox: %s", outbox)
j, err := GetJunk(outbox)
if err != nil {
log.Printf("error getting outbox: %s", err)
ilog.Printf("error getting outbox: %s", err)
return
}
t, _ := j.GetString("type")
@ -364,7 +363,7 @@ func gimmexonks(user *WhatAbout, outbox string) {
if ok {
j, err = GetJunk(page1)
if err != nil {
log.Printf("error gettings page1: %s", err)
ilog.Printf("error gettings page1: %s", err)
return
}
items, _ = j.GetArray("orderedItems")
@ -390,7 +389,7 @@ func gimmexonks(user *WhatAbout, outbox string) {
}
obj, err = GetJunk(xid)
if err != nil {
log.Printf("error getting item: %s", err)
ilog.Printf("error getting item: %s", err)
continue
}
xonksaver(user, obj, originate(xid))
@ -467,14 +466,14 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
var xonkxonkfn func(item junk.Junk, origin string, isUpdate bool) *Honk
saveonemore := func(xid string) {
log.Printf("getting onemore: %s", xid)
dlog.Printf("getting onemore: %s", xid)
if depth >= maxdepth {
log.Printf("in too deep")
ilog.Printf("in too deep")
return
}
obj, err := GetJunkHardMode(xid)
if err != nil {
log.Printf("error getting onemore: %s: %s", xid, err)
ilog.Printf("error getting onemore: %s: %s", xid, err)
return
}
depth++
@ -506,16 +505,16 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
return nil
}
if originate(xid) != origin {
log.Printf("forged delete: %s", xid)
ilog.Printf("forged delete: %s", xid)
return nil
}
log.Printf("eradicating %s", xid)
ilog.Printf("eradicating %s", xid)
eradicatexonk(user.ID, xid)
return nil
case "Remove":
xid, _ = item.GetString("object")
targ, _ := obj.GetString("target")
log.Printf("remove %s from %s", obj, targ)
ilog.Printf("remove %s from %s", obj, targ)
return nil
case "Tombstone":
xid, _ = item.GetString("id")
@ -523,10 +522,10 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
return nil
}
if originate(xid) != origin {
log.Printf("forged delete: %s", xid)
ilog.Printf("forged delete: %s", xid)
return nil
}
log.Printf("eradicating %s", xid)
ilog.Printf("eradicating %s", xid)
eradicatexonk(user.ID, xid)
return nil
case "Announce":
@ -539,10 +538,10 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if !needbonkid(user, xid) {
return nil
}
log.Printf("getting bonk: %s", xid)
dlog.Printf("getting bonk: %s", xid)
obj, err = GetJunkHardMode(xid)
if err != nil {
log.Printf("error getting bonk: %s: %s", xid, err)
ilog.Printf("error getting bonk: %s: %s", xid, err)
}
origin = originate(xid)
what = "bonk"
@ -553,18 +552,18 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
obj, ok = item.GetMap("object")
if !ok {
xid, _ = item.GetString("object")
log.Printf("getting created honk: %s", xid)
dlog.Printf("getting created honk: %s", xid)
if originate(xid) != origin {
log.Printf("out of bounds %s not from %s", xid, origin)
ilog.Printf("out of bounds %s not from %s", xid, origin)
return nil
}
obj, err = GetJunkHardMode(xid)
if err != nil {
log.Printf("error getting creation: %s", err)
ilog.Printf("error getting creation: %s", err)
}
}
if obj == nil {
log.Printf("no object for creation %s", id)
ilog.Printf("no object for creation %s", id)
return nil
}
return xonkxonkfn(obj, origin, isUpdate)
@ -572,12 +571,12 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
xid, ok = item.GetString("object")
if ok {
if !needxonkid(user, xid) {
log.Printf("don't need read obj: %s", xid)
dlog.Printf("don't need read obj: %s", xid)
return nil
}
obj, err = GetJunkHardMode(xid)
if err != nil {
log.Printf("error getting read: %s", err)
ilog.Printf("error getting read: %s", err)
return nil
}
return xonkxonkfn(obj, originate(xid), false)
@ -588,12 +587,12 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if ok {
// check target...
if !needxonkid(user, xid) {
log.Printf("don't need added obj: %s", xid)
dlog.Printf("don't need added obj: %s", xid)
return nil
}
obj, err = GetJunkHardMode(xid)
if err != nil {
log.Printf("error getting add: %s", err)
ilog.Printf("error getting add: %s", err)
return nil
}
return xonkxonkfn(obj, originate(xid), false)
@ -624,7 +623,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
obj = item
what = "chonk"
default:
log.Printf("unknown activity: %s", what)
ilog.Printf("unknown activity: %s", what)
dumpactivity(item)
return nil
}
@ -634,13 +633,13 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
if xid == "" {
log.Printf("don't know what xid is")
item.Write(os.Stdout)
ilog.Printf("don't know what xid is")
item.Write(ilog.Writer())
return nil
}
if originate(xid) != origin {
log.Printf("original sin: %s not from %s", xid, origin)
item.Write(os.Stdout)
ilog.Printf("original sin: %s not from %s", xid, origin)
item.Write(ilog.Writer())
return nil
}
@ -729,14 +728,14 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
what = "tonk"
}
if len(content) > 90001 {
log.Printf("content too long. truncating")
ilog.Printf("content too long. truncating")
content = content[:90001]
}
xonk.Noise = content
xonk.Precis = precis
if rejectxonk(&xonk) {
log.Printf("fast reject: %s", xid)
dlog.Printf("fast reject: %s", xid)
return nil
}
@ -771,16 +770,16 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
localize := false
if numatts > 4 {
log.Printf("excessive attachment: %s", at)
ilog.Printf("excessive attachment: %s", at)
} else if at == "Document" || at == "Image" {
mt = strings.ToLower(mt)
log.Printf("attachment: %s %s", mt, u)
dlog.Printf("attachment: %s %s", mt, u)
if mt == "text/plain" || mt == "application/pdf" ||
strings.HasPrefix(mt, "image") {
localize = true
}
} else {
log.Printf("unknown attachment: %s", at)
ilog.Printf("unknown attachment: %s", at)
}
if skipMedia(&xonk) {
localize = false
@ -795,7 +794,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
for _, atti := range atts {
att, ok := atti.(junk.Junk)
if !ok {
log.Printf("attachment that wasn't map?")
ilog.Printf("attachment that wasn't map?")
continue
}
procatt(att)
@ -934,10 +933,10 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
}
if isUpdate {
log.Printf("something has changed! %s", xonk.XID)
dlog.Printf("something has changed! %s", xonk.XID)
prev := getxonk(user.ID, xonk.XID)
if prev == nil {
log.Printf("didn't find old version for update: %s", xonk.XID)
ilog.Printf("didn't find old version for update: %s", xonk.XID)
isUpdate = false
} else {
xonk.ID = prev.ID
@ -971,7 +970,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if goingup == 0 {
for _, replid := range replies {
if needxonkid(user, replid) {
log.Printf("missing a reply: %s", replid)
dlog.Printf("missing a reply: %s", replid)
saveonemore(replid)
}
}
@ -985,7 +984,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
func dumpactivity(item junk.Junk) {
fd, err := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Printf("error opening inbox! %s", err)
elog.Printf("error opening inbox! %s", err)
return
}
defer fd.Close()
@ -1028,7 +1027,7 @@ func itakeitallback(user *WhatAbout, xid string, owner string, folxid string) {
func subsub(user *WhatAbout, xid string, owner string, folxid string) {
if xid == "" {
log.Printf("can't subscribe to empty")
ilog.Printf("can't subscribe to empty")
return
}
j := junk.New()
@ -1508,7 +1507,7 @@ func asjonker(name string) ([]byte, bool) {
var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool) {
m := strings.Split(name, "@")
if len(m) != 2 {
log.Printf("bad fish name: %s", name)
dlog.Printf("bad fish name: %s", name)
return "", true
}
var href string
@ -1517,10 +1516,10 @@ var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool)
if err == nil {
return href, true
}
log.Printf("fishing for %s", name)
dlog.Printf("fishing for %s", name)
j, err := GetJunkFast(fmt.Sprintf("https://%s/.well-known/webfinger?resource=acct:%s", m[1], name))
if err != nil {
log.Printf("failed to go fish %s: %s", name, err)
ilog.Printf("failed to go fish %s: %s", name, err)
return "", true
}
links, _ := j.GetArray("links")
@ -1536,7 +1535,7 @@ var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool)
when := time.Now().UTC().Format(dbtimeformat)
_, err := stmtSaveXonker.Exec(name, href, "fishname", when)
if err != nil {
log.Printf("error saving fishname: %s", err)
elog.Printf("error saving fishname: %s", err)
}
return href, true
}
@ -1624,33 +1623,33 @@ func ingestpubkey(origin string, obj junk.Junk) {
return
}
if !ok || origin != originate(keyname) {
log.Printf("bad key origin %s <> %s", origin, keyname)
ilog.Printf("bad key origin %s <> %s", origin, keyname)
return
}
log.Printf("ingesting a needed pubkey: %s", keyname)
dlog.Printf("ingesting a needed pubkey: %s", keyname)
owner, ok := obj.GetString("owner")
if !ok {
log.Printf("error finding %s pubkey owner", keyname)
ilog.Printf("error finding %s pubkey owner", keyname)
return
}
data, ok = obj.GetString("publicKeyPem")
if !ok {
log.Printf("error finding %s pubkey", keyname)
ilog.Printf("error finding %s pubkey", keyname)
return
}
if originate(owner) != origin {
log.Printf("bad key owner: %s <> %s", owner, origin)
ilog.Printf("bad key owner: %s <> %s", owner, origin)
return
}
_, _, err = httpsig.DecodeKey(data)
if err != nil {
log.Printf("error decoding %s pubkey: %s", keyname, err)
ilog.Printf("error decoding %s pubkey: %s", keyname, err)
return
}
when := time.Now().UTC().Format(dbtimeformat)
_, err = stmtSaveXonker.Exec(keyname, data, "pubkey", when)
if err != nil {
log.Printf("error saving key: %s", err)
elog.Printf("error saving key: %s", err)
}
}
@ -1668,7 +1667,7 @@ func ingestboxes(origin string, obj junk.Junk) {
if err == nil {
return
}
log.Printf("ingesting boxes: %s", ident)
dlog.Printf("ingesting boxes: %s", ident)
inbox, _ := obj.GetString("inbox")
outbox, _ := obj.GetString("outbox")
sbox, _ := obj.GetString("endpoints", "sharedInbox")
@ -1677,7 +1676,7 @@ func ingestboxes(origin string, obj junk.Junk) {
m := strings.Join([]string{inbox, outbox, sbox}, " ")
_, err = stmtSaveXonker.Exec(ident, m, "boxes", when)
if err != nil {
log.Printf("error saving boxes: %s", err)
elog.Printf("error saving boxes: %s", err)
}
}
}
@ -1701,7 +1700,7 @@ func ingesthandle(origin string, obj junk.Junk) {
when := time.Now().UTC().Format(dbtimeformat)
_, err = stmtSaveXonker.Exec(xid, handle, "handle", when)
if err != nil {
log.Printf("error saving handle: %s", err)
elog.Printf("error saving handle: %s", err)
}
}
}
@ -1742,17 +1741,17 @@ func updateMe(username string) {
func followme(user *WhatAbout, who string, name string, j junk.Junk) {
folxid, _ := j.GetString("id")
log.Printf("updating honker follow: %s %s", who, folxid)
ilog.Printf("updating honker follow: %s %s", who, folxid)
var x string
db := opendatabase()
row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", name, who, user.ID)
err := row.Scan(&x)
if err != sql.ErrNoRows {
log.Printf("duplicate follow request: %s", who)
ilog.Printf("duplicate follow request: %s", who)
_, err = stmtUpdateFlavor.Exec("dub", folxid, user.ID, name, who, "undub")
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
}
} else {
stmtSaveDub.Exec(user.ID, name, who, "dub", folxid)
@ -1770,16 +1769,16 @@ func unfollowme(user *WhatAbout, who string, name string, j junk.Junk) {
err := row.Scan(&who, &name)
if err != nil {
if err != sql.ErrNoRows {
log.Printf("error scanning honker: %s", err)
elog.Printf("error scanning honker: %s", err)
}
return
}
}
log.Printf("updating honker undo: %s %s", who, folxid)
ilog.Printf("updating honker undo: %s %s", who, folxid)
_, err := stmtUpdateFlavor.Exec("undub", folxid, user.ID, name, who, "dub")
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
return
}
}
@ -1791,14 +1790,14 @@ func followyou(user *WhatAbout, honkerid int64) {
honkerid, user.ID)
err := row.Scan(&url, &owner)
if err != nil {
log.Printf("can't get honker xid: %s", err)
elog.Printf("can't get honker xid: %s", err)
return
}
folxid := xfiltrate()
log.Printf("subscribing to %s", url)
ilog.Printf("subscribing to %s", url)
_, err = db.Exec("update honkers set flavor = ?, folxid = ? where honkerid = ?", "presub", folxid, honkerid)
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
return
}
go subsub(user, url, owner, folxid)
@ -1811,13 +1810,13 @@ func unfollowyou(user *WhatAbout, honkerid int64) {
var url, owner, folxid string
err := row.Scan(&url, &owner, &folxid)
if err != nil {
log.Printf("can't get honker xid: %s", err)
elog.Printf("can't get honker xid: %s", err)
return
}
log.Printf("unsubscribing from %s", url)
ilog.Printf("unsubscribing from %s", url)
_, err = db.Exec("update honkers set flavor = ? where honkerid = ?", "unsub", honkerid)
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
return
}
go itakeitallback(user, url, owner, folxid)
@ -1826,19 +1825,19 @@ func unfollowyou(user *WhatAbout, honkerid int64) {
func followyou2(user *WhatAbout, j junk.Junk) {
who, _ := j.GetString("actor")
log.Printf("updating honker accept: %s", who)
ilog.Printf("updating honker accept: %s", who)
db := opendatabase()
row := db.QueryRow("select name, folxid from honkers where userid = ? and xid = ? and flavor in ('presub')",
user.ID, who)
var name, folxid string
err := row.Scan(&name, &folxid)
if err != nil {
log.Printf("can't get honker name: %s", err)
elog.Printf("can't get honker name: %s", err)
return
}
_, err = stmtUpdateFlavor.Exec("sub", folxid, user.ID, name, who, "presub")
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
return
}
}
@ -1846,20 +1845,20 @@ func followyou2(user *WhatAbout, j junk.Junk) {
func nofollowyou2(user *WhatAbout, j junk.Junk) {
who, _ := j.GetString("actor")
log.Printf("updating honker reject: %s", who)
ilog.Printf("updating honker reject: %s", who)
db := opendatabase()
row := db.QueryRow("select name, folxid from honkers where userid = ? and xid = ? and flavor in ('presub', 'sub')",
user.ID, who)
var name, folxid string
err := row.Scan(&name, &folxid)
if err != nil {
log.Printf("can't get honker name: %s", err)
elog.Printf("can't get honker name: %s", err)
return
}
_, err = stmtUpdateFlavor.Exec("unsub", folxid, user.ID, name, who, "presub")
_, err = stmtUpdateFlavor.Exec("unsub", folxid, user.ID, name, who, "sub")
if err != nil {
log.Printf("error updating honker: %s", err)
elog.Printf("error updating honker: %s", err)
return
}
}

View File

@ -27,15 +27,13 @@ import "C"
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
"strings"
)
func adminscreen() {
log.SetOutput(ioutil.Discard)
initLogging("null", "null", "null")
stdout := bufio.NewWriter(os.Stdout)
esc := "\x1b"
smcup := esc + "[?1049h"

View File

@ -22,7 +22,6 @@ import (
"fmt"
"image"
"image/png"
"log"
"net/http"
"regexp"
"strconv"
@ -56,7 +55,7 @@ func loadAvatarColors() {
}
c, err := strconv.ParseUint(l, 16, 32)
if err != nil {
log.Printf("error reading avatar color %d: %s", i, err)
elog.Printf("error reading avatar color %d: %s", i, err)
continue
}
avatarcolors[i][0] = byte(c >> 24 & 0xff)

View File

@ -17,7 +17,6 @@ package main
import (
"bytes"
"log"
"net"
"net/rpc"
"os"
@ -76,27 +75,27 @@ func shrinkit(data []byte) (*image.Image, error) {
var backendhooks []func()
func backendServer() {
log.Printf("backend server running")
dlog.Printf("backend server running")
shrinker := new(Shrinker)
srv := rpc.NewServer()
err := srv.Register(shrinker)
if err != nil {
log.Panicf("unable to register shrinker: %s", err)
elog.Panicf("unable to register shrinker: %s", err)
}
sockname := backendSockname()
err = os.Remove(sockname)
if err != nil && !os.IsNotExist(err) {
log.Panicf("unable to unlink socket: %s", err)
elog.Panicf("unable to unlink socket: %s", err)
}
lis, err := net.Listen("unix", sockname)
if err != nil {
log.Panicf("unable to register shrinker: %s", err)
elog.Panicf("unable to register shrinker: %s", err)
}
err = setLimits()
if err != nil {
log.Printf("error setting backend limits: %s", err)
elog.Printf("error setting backend limits: %s", err)
}
for _, h := range backendhooks {
h()
@ -110,8 +109,8 @@ func runBackendServer() {
proc.Stderr = os.Stderr
err := proc.Start()
if err != nil {
log.Panicf("can't exec backend: %s", err)
elog.Panicf("can't exec backend: %s", err)
}
err = proc.Wait()
log.Printf("lost the backend: %s", err)
elog.Printf("lost the backend: %s", err)
}

View File

@ -3,7 +3,6 @@ package main
import (
"database/sql"
"fmt"
"log"
"os"
"time"
@ -13,7 +12,7 @@ import (
func qordie(db *sql.DB, s string, args ...interface{}) *sql.Rows {
rows, err := db.Query(s, args...)
if err != nil {
log.Fatalf("can't query %s: %s", s, err)
elog.Fatalf("can't query %s: %s", s, err)
}
return rows
}
@ -21,31 +20,31 @@ func qordie(db *sql.DB, s string, args ...interface{}) *sql.Rows {
func scanordie(rows *sql.Rows, args ...interface{}) {
err := rows.Scan(args...)
if err != nil {
log.Fatalf("can't scan: %s", err)
elog.Fatalf("can't scan: %s", err)
}
}
func svalbard(dirname string) {
err := os.Mkdir(dirname, 0700)
if err != nil && !os.IsExist(err) {
log.Fatalf("can't create directory: %s", dirname)
elog.Fatalf("can't create directory: %s", dirname)
}
now := time.Now().Unix()
backupdbname := fmt.Sprintf("%s/honk-%d.db", dirname, now)
backup, err := sql.Open("sqlite3", backupdbname)
if err != nil {
log.Fatalf("can't open backup database")
elog.Fatalf("can't open backup database")
}
for _, line := range strings.Split(sqlSchema, ";") {
_, err = backup.Exec(line)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
return
}
}
tx, err := backup.Begin()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
orig := opendatabase()
rows := qordie(orig, "select userid, username, hash, displayname, about, pubkey, seckey, options from users")
@ -161,21 +160,21 @@ func svalbard(dirname string) {
err = tx.Commit()
if err != nil {
log.Fatalf("can't commit backp: %s", err)
elog.Fatalf("can't commit backp: %s", err)
}
backup.Close()
backupblobname := fmt.Sprintf("%s/blob-%d.db", dirname, now)
blob, err := sql.Open("sqlite3", backupblobname)
if err != nil {
log.Fatalf("can't open backup blob database")
elog.Fatalf("can't open backup blob database")
}
doordie(blob, "create table filedata (xid text, media text, hash text, content blob)")
doordie(blob, "create index idx_filexid on filedata(xid)")
doordie(blob, "create index idx_filehash on filedata(hash)")
tx, err = blob.Begin()
if err != nil {
log.Fatalf("can't start transaction: %s", err)
elog.Fatalf("can't start transaction: %s", err)
}
origblob := openblobdb()
for x := range filexids {
@ -191,7 +190,7 @@ func svalbard(dirname string) {
err = tx.Commit()
if err != nil {
log.Fatalf("can't commit blobs: %s", err)
elog.Fatalf("can't commit blobs: %s", err)
}
blob.Close()
}

View File

@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"html/template"
"log"
"sort"
"strconv"
"strings"
@ -49,7 +48,7 @@ func userfromrow(row *sql.Row) (*WhatAbout, error) {
user.URL = fmt.Sprintf("https://%s/%s/%s", serverName, userSep, user.Name)
err = unjsonify(options, &user.Options)
if err != nil {
log.Printf("error processing user options: %s", err)
elog.Printf("error processing user options: %s", err)
}
} else {
user.URL = fmt.Sprintf("https://%s/%s", serverName, user.Name)
@ -88,7 +87,7 @@ func getserveruser() *WhatAbout {
var user *WhatAbout
ok := somenumberedusers.Get(serverUID, &user)
if !ok {
log.Panicf("lost server user")
elog.Panicf("lost server user")
}
return user
}
@ -107,7 +106,7 @@ var honkerinvalidator cache.Invalidator
func gethonkers(userid int64) []*Honker {
rows, err := stmtHonkers.Query(userid)
if err != nil {
log.Printf("error querying honkers: %s", err)
elog.Printf("error querying honkers: %s", err)
return nil
}
defer rows.Close()
@ -120,7 +119,7 @@ func gethonkers(userid int64) []*Honker {
err = unjsonify(meta, &h.Meta)
}
if err != nil {
log.Printf("error scanning honker: %s", err)
elog.Printf("error scanning honker: %s", err)
continue
}
h.Combos = strings.Split(strings.TrimSpace(combos), " ")
@ -141,7 +140,7 @@ func getnameddubs(userid int64, name string) []*Honker {
func dubsfromrows(rows *sql.Rows, err error) []*Honker {
if err != nil {
log.Printf("error querying dubs: %s", err)
elog.Printf("error querying dubs: %s", err)
return nil
}
defer rows.Close()
@ -150,7 +149,7 @@ func dubsfromrows(rows *sql.Rows, err error) []*Honker {
h := new(Honker)
err = rows.Scan(&h.ID, &h.UserID, &h.Name, &h.XID, &h.Flavor)
if err != nil {
log.Printf("error scanning honker: %s", err)
elog.Printf("error scanning honker: %s", err)
return nil
}
honkers = append(honkers, h)
@ -340,7 +339,7 @@ func reversehonks(honks []*Honk) {
func getsomehonks(rows *sql.Rows, err error) []*Honk {
if err != nil {
log.Printf("error querying honks: %s", err)
elog.Printf("error querying honks: %s", err)
return nil
}
defer rows.Close()
@ -367,7 +366,7 @@ func scanhonk(row RowLike) *Honk {
&dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Format, &h.Convoy, &h.Whofore, &h.Flags)
if err != nil {
if err != sql.ErrNoRows {
log.Printf("error scanning honk: %s", err)
elog.Printf("error scanning honk: %s", err)
}
return nil
}
@ -390,7 +389,7 @@ func donksforhonks(honks []*Honk) {
q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join filemeta on donks.fileid = filemeta.fileid where honkid in (%s)", idset)
rows, err := db.Query(q)
if err != nil {
log.Printf("error querying donks: %s", err)
elog.Printf("error querying donks: %s", err)
return
}
defer rows.Close()
@ -399,7 +398,7 @@ func donksforhonks(honks []*Honk) {
d := new(Donk)
err = rows.Scan(&hid, &d.FileID, &d.XID, &d.Name, &d.Desc, &d.URL, &d.Media, &d.Local)
if err != nil {
log.Printf("error scanning donk: %s", err)
elog.Printf("error scanning donk: %s", err)
continue
}
d.External = !strings.HasPrefix(d.URL, serverPrefix)
@ -412,7 +411,7 @@ func donksforhonks(honks []*Honk) {
q = fmt.Sprintf("select honkid, ontology from onts where honkid in (%s)", idset)
rows, err = db.Query(q)
if err != nil {
log.Printf("error querying onts: %s", err)
elog.Printf("error querying onts: %s", err)
return
}
defer rows.Close()
@ -421,7 +420,7 @@ func donksforhonks(honks []*Honk) {
var o string
err = rows.Scan(&hid, &o)
if err != nil {
log.Printf("error scanning donk: %s", err)
elog.Printf("error scanning donk: %s", err)
continue
}
h := hmap[hid]
@ -433,7 +432,7 @@ func donksforhonks(honks []*Honk) {
q = fmt.Sprintf("select honkid, genus, json from honkmeta where honkid in (%s)", idset)
rows, err = db.Query(q)
if err != nil {
log.Printf("error querying honkmeta: %s", err)
elog.Printf("error querying honkmeta: %s", err)
return
}
defer rows.Close()
@ -442,7 +441,7 @@ func donksforhonks(honks []*Honk) {
var genus, j string
err = rows.Scan(&hid, &genus, &j)
if err != nil {
log.Printf("error scanning honkmeta: %s", err)
elog.Printf("error scanning honkmeta: %s", err)
continue
}
h := hmap[hid]
@ -451,7 +450,7 @@ func donksforhonks(honks []*Honk) {
p := new(Place)
err = unjsonify(j, p)
if err != nil {
log.Printf("error parsing place: %s", err)
elog.Printf("error parsing place: %s", err)
continue
}
h.Place = p
@ -459,25 +458,25 @@ func donksforhonks(honks []*Honk) {
t := new(Time)
err = unjsonify(j, t)
if err != nil {
log.Printf("error parsing time: %s", err)
elog.Printf("error parsing time: %s", err)
continue
}
h.Time = t
case "mentions":
err = unjsonify(j, &h.Mentions)
if err != nil {
log.Printf("error parsing mentions: %s", err)
elog.Printf("error parsing mentions: %s", err)
continue
}
case "badonks":
err = unjsonify(j, &h.Badonks)
if err != nil {
log.Printf("error parsing badonks: %s", err)
elog.Printf("error parsing badonks: %s", err)
continue
}
case "oldrev":
default:
log.Printf("unknown meta genus: %s", genus)
elog.Printf("unknown meta genus: %s", genus)
}
}
rows.Close()
@ -496,7 +495,7 @@ func donksforchonks(chonks []*Chonk) {
q := fmt.Sprintf("select chonkid, donks.fileid, xid, name, description, url, media, local from donks join filemeta on donks.fileid = filemeta.fileid where chonkid in (%s)", idset)
rows, err := db.Query(q)
if err != nil {
log.Printf("error querying donks: %s", err)
elog.Printf("error querying donks: %s", err)
return
}
defer rows.Close()
@ -505,7 +504,7 @@ func donksforchonks(chonks []*Chonk) {
d := new(Donk)
err = rows.Scan(&chid, &d.FileID, &d.XID, &d.Name, &d.Desc, &d.URL, &d.Media, &d.Local)
if err != nil {
log.Printf("error scanning donk: %s", err)
elog.Printf("error scanning donk: %s", err)
continue
}
ch := chmap[chid]
@ -547,7 +546,7 @@ func savefileandxid(name string, desc string, url string, media string, local bo
return 0, "", err
}
} else if err != nil {
log.Printf("error checking file hash: %s", err)
elog.Printf("error checking file hash: %s", err)
return 0, "", err
}
if url == "" {
@ -571,7 +570,7 @@ func finddonk(url string) *Donk {
return donk
}
if err != sql.ErrNoRows {
log.Printf("error finding file: %s", err)
elog.Printf("error finding file: %s", err)
}
return nil
}
@ -581,7 +580,7 @@ func savechonk(ch *Chonk) error {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("can't begin tx: %s", err)
elog.Printf("can't begin tx: %s", err)
return err
}
@ -591,7 +590,7 @@ func savechonk(ch *Chonk) error {
for _, d := range ch.Donks {
_, err := tx.Stmt(stmtSaveDonk).Exec(-1, ch.ID, d.FileID)
if err != nil {
log.Printf("error saving donk: %s", err)
elog.Printf("error saving donk: %s", err)
break
}
}
@ -616,7 +615,7 @@ func chatplusone(tx *sql.Tx, userid int64) {
_, err = tx.Exec("update users set options = ? where username = ?", j, user.Name)
}
if err != nil {
log.Printf("error plussing chat: %s", err)
elog.Printf("error plussing chat: %s", err)
}
somenamedusers.Clear(user.Name)
somenumberedusers.Clear(user.ID)
@ -636,7 +635,7 @@ func chatnewnone(userid int64) {
_, err = db.Exec("update users set options = ? where username = ?", j, user.Name)
}
if err != nil {
log.Printf("error noneing chat: %s", err)
elog.Printf("error noneing chat: %s", err)
}
somenamedusers.Clear(user.Name)
somenumberedusers.Clear(user.ID)
@ -655,7 +654,7 @@ func meplusone(tx *sql.Tx, userid int64) {
_, err = tx.Exec("update users set options = ? where username = ?", j, user.Name)
}
if err != nil {
log.Printf("error plussing me: %s", err)
elog.Printf("error plussing me: %s", err)
}
somenamedusers.Clear(user.Name)
somenumberedusers.Clear(user.ID)
@ -675,7 +674,7 @@ func menewnone(userid int64) {
_, err = db.Exec("update users set options = ? where username = ?", j, user.Name)
}
if err != nil {
log.Printf("error noneing me: %s", err)
elog.Printf("error noneing me: %s", err)
}
somenamedusers.Clear(user.Name)
somenumberedusers.Clear(user.ID)
@ -685,7 +684,7 @@ func loadchatter(userid int64) []*Chatter {
duedt := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat)
rows, err := stmtLoadChonks.Query(userid, duedt)
if err != nil {
log.Printf("error loading chonks: %s", err)
elog.Printf("error loading chonks: %s", err)
return nil
}
defer rows.Close()
@ -696,7 +695,7 @@ func loadchatter(userid int64) []*Chatter {
var dt string
err = rows.Scan(&ch.ID, &ch.UserID, &ch.XID, &ch.Who, &ch.Target, &dt, &ch.Noise, &ch.Format)
if err != nil {
log.Printf("error scanning chonk: %s", err)
elog.Printf("error scanning chonk: %s", err)
continue
}
ch.Date, _ = time.Parse(dbtimeformat, dt)
@ -707,14 +706,14 @@ func loadchatter(userid int64) []*Chatter {
rows.Close()
rows, err = stmtGetChatters.Query(userid)
if err != nil {
log.Printf("error getting chatters: %s", err)
elog.Printf("error getting chatters: %s", err)
return nil
}
for rows.Next() {
var target string
err = rows.Scan(&target)
if err != nil {
log.Printf("error scanning chatter: %s", target)
elog.Printf("error scanning chatter: %s", target)
continue
}
if _, ok := chonks[target]; !ok {
@ -750,7 +749,7 @@ func savehonk(h *Honk) error {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("can't begin tx: %s", err)
elog.Printf("can't begin tx: %s", err)
return err
}
@ -770,7 +769,7 @@ func savehonk(h *Honk) error {
tx.Rollback()
}
if err != nil {
log.Printf("error saving honk: %s", err)
elog.Printf("error saving honk: %s", err)
}
honkhonkline()
return err
@ -784,7 +783,7 @@ func updatehonk(h *Honk) error {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("can't begin tx: %s", err)
elog.Printf("can't begin tx: %s", err)
return err
}
@ -802,7 +801,7 @@ func updatehonk(h *Honk) error {
_, err = tx.Stmt(stmtSaveMeta).Exec(old.ID, "oldrev", j)
}
if err != nil {
log.Printf("error saving oldrev: %s", err)
elog.Printf("error saving oldrev: %s", err)
}
}
if err == nil {
@ -811,7 +810,7 @@ func updatehonk(h *Honk) error {
tx.Rollback()
}
if err != nil {
log.Printf("error updating honk %d: %s", h.ID, err)
elog.Printf("error updating honk %d: %s", h.ID, err)
}
return err
}
@ -820,7 +819,7 @@ func deletehonk(honkid int64) error {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("can't begin tx: %s", err)
elog.Printf("can't begin tx: %s", err)
return err
}
@ -834,7 +833,7 @@ func deletehonk(honkid int64) error {
tx.Rollback()
}
if err != nil {
log.Printf("error deleting honk %d: %s", honkid, err)
elog.Printf("error deleting honk %d: %s", honkid, err)
}
return err
}
@ -843,14 +842,14 @@ func saveextras(tx *sql.Tx, h *Honk) error {
for _, d := range h.Donks {
_, err := tx.Stmt(stmtSaveDonk).Exec(h.ID, -1, d.FileID)
if err != nil {
log.Printf("error saving donk: %s", err)
elog.Printf("error saving donk: %s", err)
return err
}
}
for _, o := range h.Onts {
_, err := tx.Stmt(stmtSaveOnt).Exec(strings.ToLower(o), h.ID)
if err != nil {
log.Printf("error saving ont: %s", err)
elog.Printf("error saving ont: %s", err)
return err
}
}
@ -860,7 +859,7 @@ func saveextras(tx *sql.Tx, h *Honk) error {
_, err = tx.Stmt(stmtSaveMeta).Exec(h.ID, "place", j)
}
if err != nil {
log.Printf("error saving place: %s", err)
elog.Printf("error saving place: %s", err)
return err
}
}
@ -870,7 +869,7 @@ func saveextras(tx *sql.Tx, h *Honk) error {
_, err = tx.Stmt(stmtSaveMeta).Exec(h.ID, "time", j)
}
if err != nil {
log.Printf("error saving time: %s", err)
elog.Printf("error saving time: %s", err)
return err
}
}
@ -880,7 +879,7 @@ func saveextras(tx *sql.Tx, h *Honk) error {
_, err = tx.Stmt(stmtSaveMeta).Exec(h.ID, "mentions", j)
}
if err != nil {
log.Printf("error saving mentions: %s", err)
elog.Printf("error saving mentions: %s", err)
return err
}
}
@ -970,13 +969,13 @@ func cleanupdb(arg string) {
blobdb := openblobdb()
rows, err := blobdb.Query("select xid from filedata")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
for rows.Next() {
var xid string
err = rows.Scan(&xid)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
filexids[xid] = true
}
@ -986,24 +985,24 @@ func cleanupdb(arg string) {
var xid string
err = rows.Scan(&xid)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
delete(filexids, xid)
}
rows.Close()
tx, err := blobdb.Begin()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
for xid, _ := range filexids {
_, err = tx.Exec("delete from filedata where xid = ?", xid)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
}
@ -1029,7 +1028,7 @@ var stmtSaveChonk, stmtLoadChonks, stmtGetChatters *sql.Stmt
func preparetodie(db *sql.DB, s string) *sql.Stmt {
stmt, err := db.Prepare(s)
if err != nil {
log.Fatalf("error %s: %s", err, s)
elog.Fatalf("error %s: %s", err, s)
}
return stmt
}

View File

@ -17,7 +17,6 @@ package main
import (
"fmt"
"log"
notrand "math/rand"
"time"
@ -43,7 +42,7 @@ func sayitagain(goarounds int64, userid int64, rcpt string, msg []byte) {
case 5:
drift = 24 * time.Hour
default:
log.Printf("he's dead jim: %s", rcpt)
ilog.Printf("he's dead jim: %s", rcpt)
clearoutbound(rcpt)
return
}
@ -51,7 +50,7 @@ func sayitagain(goarounds int64, userid int64, rcpt string, msg []byte) {
when := time.Now().UTC().Add(drift)
_, err := stmtAddDoover.Exec(when.Format(dbtimeformat), goarounds, userid, rcpt, msg)
if err != nil {
log.Printf("error saving doover: %s", err)
elog.Printf("error saving doover: %s", err)
}
select {
case pokechan <- 0:
@ -65,7 +64,7 @@ func clearoutbound(rcpt string) {
return
}
xid := fmt.Sprintf("%%https://%s/%%", hostname)
log.Printf("clearing outbound for %s", xid)
ilog.Printf("clearing outbound for %s", xid)
db := opendatabase()
db.Exec("delete from doovers where rcpt like ?", xid)
}
@ -79,7 +78,7 @@ func deliverate(goarounds int64, userid int64, rcpt string, msg []byte, prio boo
var ki *KeyInfo
ok := ziggies.Get(userid, &ki)
if !ok {
log.Printf("lost key for delivery")
elog.Printf("lost key for delivery")
return
}
var inbox string
@ -90,7 +89,7 @@ func deliverate(goarounds int64, userid int64, rcpt string, msg []byte, prio boo
var box *Box
ok := boxofboxes.Get(rcpt, &box)
if !ok {
log.Printf("failed getting inbox for %s", rcpt)
ilog.Printf("failed getting inbox for %s", rcpt)
sayitagain(goarounds+1, userid, rcpt, msg)
return
}
@ -98,7 +97,7 @@ func deliverate(goarounds int64, userid int64, rcpt string, msg []byte, prio boo
}
err := PostMsg(ki.keyname, ki.seckey, inbox, msg)
if err != nil {
log.Printf("failed to post json to %s: %s", inbox, err)
ilog.Printf("failed to post json to %s: %s", inbox, err)
if prio {
sayitagain(goarounds+1, userid, rcpt, msg)
}
@ -111,7 +110,7 @@ var pokechan = make(chan int, 1)
func getdoovers() []Doover {
rows, err := stmtGetDoovers.Query()
if err != nil {
log.Printf("wat?")
elog.Printf("wat?")
time.Sleep(1 * time.Minute)
return nil
}
@ -122,7 +121,7 @@ func getdoovers() []Doover {
var dt string
err := rows.Scan(&d.ID, &dt)
if err != nil {
log.Printf("error scanning dooverid: %s", err)
elog.Printf("error scanning dooverid: %s", err)
continue
}
d.When, _ = time.Parse(dbtimeformat, dt)
@ -155,15 +154,15 @@ func redeliverator() {
row := stmtLoadDoover.QueryRow(d.ID)
err := row.Scan(&goarounds, &userid, &rcpt, &msg)
if err != nil {
log.Printf("error scanning doover: %s", err)
elog.Printf("error scanning doover: %s", err)
continue
}
_, err = stmtZapDoover.Exec(d.ID)
if err != nil {
log.Printf("error deleting doover: %s", err)
elog.Printf("error deleting doover: %s", err)
continue
}
log.Printf("redeliverating %s try %d", rcpt, goarounds)
ilog.Printf("redeliverating %s try %d", rcpt, goarounds)
deliverate(goarounds, userid, rcpt, msg, true)
} else if d.When.Before(nexttime) {
nexttime = d.When

17
fun.go
View File

@ -21,7 +21,6 @@ import (
"fmt"
"html/template"
"io"
"log"
"net/http"
"net/url"
"os"
@ -265,7 +264,7 @@ func inlineimgsfor(honk *Honk) func(node *html.Node) string {
if d != nil {
honk.Donks = append(honk.Donks, d)
}
log.Printf("inline img with src: %s", src)
dlog.Printf("inline img with src: %s", src)
return ""
}
}
@ -411,7 +410,7 @@ func memetize(honk *Honk) {
}
fd, err := os.Open(dataDir + "/memes/" + name)
if err != nil {
log.Printf("no meme for %s", name)
ilog.Printf("no meme for %s", name)
return x
}
var peek [512]byte
@ -422,7 +421,7 @@ func memetize(honk *Honk) {
url := fmt.Sprintf("https://%s/meme/%s", serverName, name)
fileid, err := savefile(name, name, url, ct, false, nil)
if err != nil {
log.Printf("error saving meme: %s", err)
elog.Printf("error saving meme: %s", err)
return x
}
d := &Donk{
@ -540,7 +539,7 @@ var allhandles = cache.New(cache.Options{Filler: func(xid string) (string, bool)
row := stmtGetXonker.QueryRow(xid, "handle")
err := row.Scan(&handle)
if err != nil {
log.Printf("need to get a handle: %s", xid)
dlog.Printf("need to get a handle: %s", xid)
info, err := investigate(xid)
if err != nil {
m := re_unurl.FindStringSubmatch(xid)
@ -628,10 +627,10 @@ var zaggies = cache.New(cache.Options{Filler: func(keyname string) (httpsig.Publ
err := row.Scan(&data)
var key httpsig.PublicKey
if err != nil {
log.Printf("hitting the webs for missing pubkey: %s", keyname)
dlog.Printf("hitting the webs for missing pubkey: %s", keyname)
j, err := GetJunk(keyname)
if err != nil {
log.Printf("error getting %s pubkey: %s", keyname, err)
ilog.Printf("error getting %s pubkey: %s", keyname, err)
when := time.Now().UTC().Format(dbtimeformat)
stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
return key, true
@ -640,7 +639,7 @@ var zaggies = cache.New(cache.Options{Filler: func(keyname string) (httpsig.Publ
row = stmtGetXonker.QueryRow(keyname, "pubkey")
err = row.Scan(&data)
if err != nil {
log.Printf("key not found after ingesting")
ilog.Printf("key not found after ingesting")
when := time.Now().UTC().Format(dbtimeformat)
stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
return key, true
@ -648,7 +647,7 @@ var zaggies = cache.New(cache.Options{Filler: func(keyname string) (httpsig.Publ
}
_, key, err = httpsig.DecodeKey(data)
if err != nil {
log.Printf("error decoding %s pubkey: %s", keyname, err)
ilog.Printf("error decoding %s pubkey: %s", keyname, err)
return key, true
}
return key, true

21
hfcs.go
View File

@ -16,7 +16,6 @@
package main
import (
"log"
"net/http"
"regexp"
"sort"
@ -78,7 +77,7 @@ func init() {
func filtcachefiller(userid int64) (afiltermap, bool) {
rows, err := stmtGetFilters.Query(userid)
if err != nil {
log.Printf("error querying filters: %s", err)
elog.Printf("error querying filters: %s", err)
return nil, false
}
defer rows.Close()
@ -97,7 +96,7 @@ func filtcachefiller(userid int64) (afiltermap, bool) {
err = unjsonify(j, filt)
}
if err != nil {
log.Printf("error scanning filter: %s", err)
elog.Printf("error scanning filter: %s", err)
continue
}
if !filt.Expiration.IsZero() {
@ -120,7 +119,7 @@ func filtcachefiller(userid int64) (afiltermap, bool) {
}
filt.re_text, err = regexp.Compile(t)
if err != nil {
log.Printf("error compiling filter text: %s", err)
elog.Printf("error compiling filter text: %s", err)
continue
}
}
@ -136,7 +135,7 @@ func filtcachefiller(userid int64) (afiltermap, bool) {
}
filt.re_rewrite, err = regexp.Compile(t)
if err != nil {
log.Printf("error compiling filter rewrite: %s", err)
elog.Printf("error compiling filter rewrite: %s", err)
continue
}
}
@ -244,7 +243,7 @@ func rejectactor(userid int64, actor string) bool {
continue
}
if f.Actor == actor {
log.Printf("rejecting actor: %s", actor)
ilog.Printf("rejecting actor: %s", actor)
return true
}
}
@ -258,7 +257,7 @@ func rejectactor(userid int64, actor string) bool {
continue
}
if f.Actor == origin {
log.Printf("rejecting actor: %s", actor)
ilog.Printf("rejecting actor: %s", actor)
return true
}
}
@ -271,7 +270,7 @@ func stealthmode(userid int64, r *http.Request) bool {
if agent != "" {
fake := rejectorigin(userid, agent, false)
if fake {
log.Printf("faking 404 for %s", agent)
ilog.Printf("faking 404 for %s", agent)
return true
}
}
@ -355,7 +354,7 @@ func rejectxonk(xonk *Honk) bool {
}
for _, f := range filts {
if cause := matchfilterX(xonk, f); cause != "" {
log.Printf("rejecting %s because %s", xonk.XID, cause)
ilog.Printf("rejecting %s because %s", xonk.XID, cause)
return true
}
}
@ -407,7 +406,7 @@ func unsee(honks []*Honk, userid int64) {
var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) {
rows, err := stmtUntagged.Query(userid)
if err != nil {
log.Printf("error query untagged: %s", err)
elog.Printf("error query untagged: %s", err)
return nil, false
}
defer rows.Close()
@ -417,7 +416,7 @@ var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bo
var flags int64
err = rows.Scan(&xid, &rid, &flags)
if err != nil {
log.Printf("error scanning untag: %s", err)
elog.Printf("error scanning untag: %s", err)
continue
}
if flags&flagIsUntagged != 0 {

21
honk.go
View File

@ -19,7 +19,6 @@ import (
"flag"
"fmt"
"html/template"
"log"
notrand "math/rand"
"os"
"strconv"
@ -264,6 +263,14 @@ func main() {
flag.StringVar(&dataDir, "datadir", dataDir, "data directory")
flag.StringVar(&viewDir, "viewdir", viewDir, "view directory")
flag.Parse()
if alllogname != "stderr" {
elogname = alllogname
ilogname = alllogname
dlogname = alllogname
}
initLogging(elogname, ilogname, dlogname)
args := flag.Args()
cmd := "run"
if len(args) > 0 {
@ -282,7 +289,7 @@ func main() {
dbversion := 0
getconfig("dbversion", &dbversion)
if dbversion != myVersion {
log.Fatal("incorrect database version. run upgrade.")
elog.Fatal("incorrect database version. run upgrade.")
}
getconfig("servermsg", &serverMsg)
getconfig("aboutmsg", &aboutMsg)
@ -302,12 +309,12 @@ func main() {
adminscreen()
case "import":
if len(args) != 4 {
log.Fatal("import username mastodon|twitter srcdir")
elog.Fatal("import username mastodon|twitter srcdir")
}
importMain(args[1], args[2], args[3])
case "debug":
if len(args) != 2 {
log.Fatal("need an argument: debug (on|off)")
elog.Fatal("need an argument: debug (on|off)")
}
switch args[1] {
case "on":
@ -315,7 +322,7 @@ func main() {
case "off":
setconfig("debug", 0)
default:
log.Fatal("argument must be on or off")
elog.Fatal("argument must be on or off")
}
case "adduser":
adduser()
@ -356,7 +363,7 @@ func main() {
targ := args[2]
user, err := butwhatabout(name)
if err != nil {
log.Printf("unknown user")
elog.Printf("unknown user")
return
}
ping(user, targ)
@ -367,6 +374,6 @@ func main() {
case "test":
ElaborateUnitTests()
default:
log.Fatal("unknown command")
elog.Fatal("unknown command")
}
}

15
hoot.go
View File

@ -18,7 +18,6 @@ package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"regexp"
@ -41,7 +40,7 @@ var re_removepics = regexp.MustCompile(`pic\.twitter\.com/[[:alnum:]]+`)
func hootextractor(r io.Reader, url string, seen map[string]bool) string {
root, err := html.Parse(r)
if err != nil {
log.Printf("error parsing hoot: %s", err)
elog.Printf("error parsing hoot: %s", err)
return url
}
@ -67,7 +66,7 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string {
alink := linksel.MatchFirst(twp)
if alink == nil {
if i != 0 {
log.Printf("missing link")
dlog.Printf("missing link")
continue
}
} else {
@ -79,7 +78,7 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string {
}
authormatch := authorregex.FindStringSubmatch(link)
if len(authormatch) < 2 {
log.Printf("no author?: %s", link)
dlog.Printf("no author?: %s", link)
continue
}
author := authormatch[1]
@ -116,10 +115,10 @@ func hooterize(noise string) string {
url = url[1:]
}
url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1)
log.Printf("hooterizing %s", url)
dlog.Printf("hooterizing %s", url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("error: %s", err)
ilog.Printf("error: %s", err)
return hoot
}
req.Header.Set("User-Agent", "Bot")
@ -127,12 +126,12 @@ func hooterize(noise string) string {
req.Header.Set("Accept-Language", "en-US,en;q=0.9")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Printf("error: %s", err)
ilog.Printf("error: %s", err)
return hoot
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Printf("error getting %s: %d", url, resp.StatusCode)
ilog.Printf("error getting %s: %d", url, resp.StatusCode)
return hoot
}
ld, _ := os.Create("lasthoot.html")

View File

@ -20,7 +20,6 @@ import (
"fmt"
"html"
"io/ioutil"
"log"
"os"
"regexp"
"sort"
@ -35,7 +34,7 @@ func importMain(username, flavor, source string) {
case "twitter":
importTwitter(username, source)
default:
log.Fatal("unknown source flavor")
elog.Fatal("unknown source flavor")
}
}
@ -68,7 +67,7 @@ func (obj *TootObject) UnmarshalJSON(b []byte) error {
func importMastodon(username, source string) {
user, err := butwhatabout(username)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
type Toot struct {
Id string
@ -82,12 +81,12 @@ func importMastodon(username, source string) {
}
fd, err := os.Open(source + "/outbox.json")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
dec := json.NewDecoder(fd)
err = dec.Decode(&outbox)
if err != nil {
log.Fatalf("error parsing json: %s", err)
elog.Fatalf("error parsing json: %s", err)
}
fd.Close()
@ -139,7 +138,7 @@ func importMastodon(username, source string) {
fname := fmt.Sprintf("%s/%s", source, att.Url)
data, err := ioutil.ReadFile(fname)
if err != nil {
log.Printf("error reading media: %s", fname)
elog.Printf("error reading media: %s", fname)
continue
}
u := xfiltrate()
@ -148,7 +147,7 @@ func importMastodon(username, source string) {
newurl := fmt.Sprintf("https://%s/d/%s", serverName, u)
fileid, err := savefile(name, desc, newurl, att.MediaType, true, data)
if err != nil {
log.Printf("error saving media: %s", fname)
elog.Printf("error saving media: %s", fname)
continue
}
donk := &Donk{
@ -170,7 +169,7 @@ func importMastodon(username, source string) {
func importTwitter(username, source string) {
user, err := butwhatabout(username)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
type Tweet struct {
@ -199,14 +198,14 @@ func importTwitter(username, source string) {
var tweets []*Tweet
fd, err := os.Open(source + "/tweet.js")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
// skip past window.YTD.tweet.part0 =
fd.Seek(25, 0)
dec := json.NewDecoder(fd)
err = dec.Decode(&tweets)
if err != nil {
log.Fatalf("error parsing json: %s", err)
elog.Fatalf("error parsing json: %s", err)
}
fd.Close()
tweetmap := make(map[string]*Tweet)
@ -272,14 +271,14 @@ func importTwitter(username, source string) {
fname := fmt.Sprintf("%s/tweet_media/%s-%s", source, t.ID_str, u)
data, err := ioutil.ReadFile(fname)
if err != nil {
log.Printf("error reading media: %s", fname)
elog.Printf("error reading media: %s", fname)
continue
}
newurl := fmt.Sprintf("https://%s/d/%s", serverName, u)
fileid, err := savefile(u, u, newurl, "image/jpg", true, data)
if err != nil {
log.Printf("error saving media: %s", fname)
elog.Printf("error saving media: %s", fname)
continue
}
donk := &Donk{

69
log.go Normal file
View File

@ -0,0 +1,69 @@
//
// Copyright (c) 2022 Ted Unangst <tedu@tedunangst.com>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package main
import (
"flag"
"io/ioutil"
"log"
"log/syslog"
"os"
)
var elog = log.Default()
var ilog = log.Default()
var dlog = log.Default()
var elogname, ilogname, dlogname, alllogname string
func init() {
flag.StringVar(&elogname, "errorlog", "stderr", "error log file (or stderr, null, syslog)")
flag.StringVar(&ilogname, "infolog", "stderr", "info log file (or stderr, null, syslog)")
flag.StringVar(&dlogname, "debuglog", "stderr", "debug log file (or stderr, null, syslog)")
flag.StringVar(&alllogname, "log", "stderr", "combined log file (or stderr, null, syslog)")
}
func initLogging(elogname, ilogname, dlogname string) {
elog = openlog(elogname, syslog.LOG_ERR)
ilog = openlog(ilogname, syslog.LOG_INFO)
dlog = openlog(dlogname, syslog.LOG_DEBUG)
}
func openlog(name string, prio syslog.Priority) *log.Logger {
if name == "stderr" {
return log.Default()
}
if name == "syslog" {
logger, err := syslog.NewLogger(syslog.LOG_UUCP|prio, 0)
if err != nil {
elog.Printf("can't create syslog: %s", err)
return log.Default()
}
return logger
}
if name == "null" {
return log.New(ioutil.Discard, os.Args[0], log.LstdFlags)
}
fd, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
elog.Printf("can't open log file %s: %s", name, err)
return log.Default()
}
logger := log.New(fd, os.Args[0], log.LstdFlags)
logger.Printf("new log started")
return logger
}

View File

@ -17,7 +17,6 @@ package main
import (
"database/sql"
"log"
"os"
"strings"
"time"
@ -32,7 +31,7 @@ type dbexecer interface {
func doordie(db dbexecer, s string, args ...interface{}) {
_, err := db.Exec(s, args...)
if err != nil {
log.Fatalf("can't run %s: %s", s, err)
elog.Fatalf("can't run %s: %s", s, err)
}
}
@ -43,7 +42,7 @@ func upgradedb() {
getconfig("servername", &serverName)
if dbversion < 13 {
log.Fatal("database is too old to upgrade")
elog.Fatal("database is too old to upgrade")
}
switch dbversion {
case 25:
@ -91,11 +90,11 @@ func upgradedb() {
case 30:
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
rows, err := tx.Query("select userid, options from users")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
m := make(map[int64]string)
for rows.Next() {
@ -103,25 +102,25 @@ func upgradedb() {
var options string
err = rows.Scan(&userid, &options)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
var uo UserOptions
uo.SkinnyCSS = strings.Contains(options, " skinny ")
m[userid], err = jsonify(uo)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
}
rows.Close()
for u, o := range m {
_, err = tx.Exec("update users set options = ? where userid = ?", o, u)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
doordie(db, "update config set value = 31 where key = 'dbversion'")
fallthrough
@ -173,7 +172,7 @@ func upgradedb() {
doordie(blobdb, "create index idx_filehash on filedata(hash)")
rows, err := blobdb.Query("select xid, content from filedata")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
m := make(map[string]string)
for rows.Next() {
@ -181,7 +180,7 @@ func upgradedb() {
var data sql.RawBytes
err := rows.Scan(&xid, &data)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
hash := hashfiledata(data)
m[xid] = hash
@ -189,21 +188,21 @@ func upgradedb() {
rows.Close()
tx, err := blobdb.Begin()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
for xid, hash := range m {
doordie(tx, "update filedata set hash = ? where xid = ?", hash, xid)
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
doordie(db, "update config set value = 40 where key = 'dbversion'")
fallthrough
case 40:
default:
log.Fatalf("can't upgrade unknown version %d", dbversion)
elog.Fatalf("can't upgrade unknown version %d", dbversion)
}
os.Exit(0)
}

51
util.go
View File

@ -40,7 +40,6 @@ import (
"database/sql"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"os/signal"
@ -80,11 +79,11 @@ func initdb() {
dbname := dataDir + "/honk.db"
_, err := os.Stat(dbname)
if err == nil {
log.Fatalf("%s already exists", dbname)
elog.Fatalf("%s already exists", dbname)
}
db, err := sql.Open("sqlite3", dbname)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
alreadyopendb = db
defer func() {
@ -104,7 +103,7 @@ func initdb() {
for _, line := range strings.Split(sqlSchema, ";") {
_, err = db.Exec(line)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
}
@ -116,37 +115,37 @@ func initdb() {
err = createuser(db, r)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
// must came later or user above will have negative id
err = createserveruser(db)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
fmt.Printf("listen address: ")
addr, err := r.ReadString('\n')
if err != nil {
log.Print(err)
elog.Print(err)
return
}
addr = addr[:len(addr)-1]
if len(addr) < 1 {
log.Print("that's way too short")
elog.Print("that's way too short")
return
}
setconfig("listenaddr", addr)
fmt.Printf("server name: ")
addr, err = r.ReadString('\n')
if err != nil {
log.Print(err)
elog.Print(err)
return
}
addr = addr[:len(addr)-1]
if len(addr) < 1 {
log.Print("that's way too short")
elog.Print("that's way too short")
return
}
setconfig("servername", addr)
@ -170,26 +169,26 @@ func initblobdb() {
blobdbname := dataDir + "/blob.db"
_, err := os.Stat(blobdbname)
if err == nil {
log.Fatalf("%s already exists", blobdbname)
elog.Fatalf("%s already exists", blobdbname)
}
blobdb, err := sql.Open("sqlite3", blobdbname)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
_, err = blobdb.Exec("create table filedata (xid text, media text, hash text, content blob)")
if err != nil {
log.Print(err)
elog.Print(err)
return
}
_, err = blobdb.Exec("create index idx_filexid on filedata(xid)")
if err != nil {
log.Print(err)
elog.Print(err)
return
}
_, err = blobdb.Exec("create index idx_filehash on filedata(hash)")
if err != nil {
log.Print(err)
elog.Print(err)
return
}
blobdb.Close()
@ -213,7 +212,7 @@ func adduser() {
err := createuser(db, r)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
@ -223,7 +222,7 @@ func adduser() {
func deluser(username string) {
user, _ := butwhatabout(username)
if user == nil {
log.Printf("no userfound")
elog.Printf("no userfound")
return
}
userid := user.ID
@ -253,7 +252,7 @@ func chpass() {
}
user, err := butwhatabout(os.Args[2])
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
defer func() {
os.Exit(1)
@ -274,12 +273,12 @@ func chpass() {
pass, err := askpassword(r)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
err = login.SetPassword(user.ID, pass)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
fmt.Printf("done\n")
@ -376,15 +375,15 @@ func opendatabase() *sql.DB {
dbname := dataDir + "/honk.db"
_, err := os.Stat(dbname)
if err != nil {
log.Fatalf("unable to open database: %s", err)
elog.Fatalf("unable to open database: %s", err)
}
db, err := sql.Open("sqlite3", dbname)
if err != nil {
log.Fatalf("unable to open database: %s", err)
elog.Fatalf("unable to open database: %s", err)
}
stmtConfig, err = db.Prepare("select value from config where key = ?")
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
alreadyopendb = db
return db
@ -394,11 +393,11 @@ func openblobdb() *sql.DB {
blobdbname := dataDir + "/blob.db"
_, err := os.Stat(blobdbname)
if err != nil {
log.Fatalf("unable to open database: %s", err)
elog.Fatalf("unable to open database: %s", err)
}
db, err := sql.Open("sqlite3", blobdbname)
if err != nil {
log.Fatalf("unable to open database: %s", err)
elog.Fatalf("unable to open database: %s", err)
}
return db
}
@ -450,7 +449,7 @@ func openListener() (net.Listener, error) {
proto = "unix"
err := os.Remove(listenAddr)
if err != nil && !os.IsNotExist(err) {
log.Printf("unable to unlink socket: %s", err)
elog.Printf("unable to unlink socket: %s", err)
}
}
listener, err := net.Listen(proto, listenAddr)

201
web.go
View File

@ -21,7 +21,6 @@ import (
"fmt"
"html/template"
"io"
"log"
notrand "math/rand"
"net/http"
"net/url"
@ -170,7 +169,7 @@ func showfunzone(w http.ResponseWriter, r *http.Request) {
templinfo["Memes"] = memenames
err = readviews.Execute(w, "funzone.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -243,7 +242,7 @@ func showrss(w http.ResponseWriter, r *http.Request) {
err := feed.Write(w)
if err != nil {
log.Printf("error writing rss: %s", err)
elog.Printf("error writing rss: %s", err)
}
}
@ -252,7 +251,7 @@ func crappola(j junk.Junk) bool {
a, _ := j.GetString("actor")
o, _ := j.GetString("object")
if t == "Delete" && a == o {
log.Printf("crappola from %s", a)
dlog.Printf("crappola from %s", a)
return true
}
return false
@ -266,16 +265,16 @@ func ping(user *WhatAbout, who string) {
who = gofish(who)
}
if who == "" {
log.Printf("nobody to ping!")
ilog.Printf("nobody to ping!")
return
}
var box *Box
ok := boxofboxes.Get(who, &box)
if !ok {
log.Printf("no inbox to ping %s", who)
ilog.Printf("no inbox to ping %s", who)
return
}
log.Printf("sending ping to %s", box.In)
ilog.Printf("sending ping to %s", box.In)
j := junk.New()
j["@context"] = itiswhatitis
j["type"] = "Ping"
@ -288,17 +287,17 @@ func ping(user *WhatAbout, who string) {
}
err := PostJunk(ki.keyname, ki.seckey, box.In, j)
if err != nil {
log.Printf("can't send ping: %s", err)
elog.Printf("can't send ping: %s", err)
return
}
log.Printf("sent ping to %s: %s", who, j["id"])
ilog.Printf("sent ping to %s: %s", who, j["id"])
}
func pong(user *WhatAbout, who string, obj string) {
var box *Box
ok := boxofboxes.Get(who, &box)
if !ok {
log.Printf("no inbox to pong %s", who)
ilog.Printf("no inbox to pong %s", who)
return
}
j := junk.New()
@ -314,7 +313,7 @@ func pong(user *WhatAbout, who string, obj string) {
}
err := PostJunk(ki.keyname, ki.seckey, box.In, j)
if err != nil {
log.Printf("can't send pong: %s", err)
elog.Printf("can't send pong: %s", err)
return
}
}
@ -336,7 +335,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
payload := buf.Bytes()
j, err := junk.FromBytes(payload)
if err != nil {
log.Printf("bad payload: %s", err)
ilog.Printf("bad payload: %s", err)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
@ -362,9 +361,9 @@ func inbox(w http.ResponseWriter, r *http.Request) {
keyname, err = httpsig.VerifyRequest(r, payload, zaggy)
}
if err != nil {
log.Printf("inbox message failed signature for %s from %s: %s", keyname, r.Header.Get("X-Forwarded-For"), err)
ilog.Printf("inbox message failed signature for %s from %s: %s", keyname, r.Header.Get("X-Forwarded-For"), err)
if keyname != "" {
log.Printf("bad signature from %s", keyname)
ilog.Printf("bad signature from %s", keyname)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
@ -374,20 +373,20 @@ func inbox(w http.ResponseWriter, r *http.Request) {
}
origin := keymatch(keyname, who)
if origin == "" {
log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
ilog.Printf("keyname actor mismatch: %s <> %s", keyname, who)
return
}
switch what {
case "Ping":
id, _ := j.GetString("id")
log.Printf("ping from %s: %s", who, id)
ilog.Printf("ping from %s: %s", who, id)
pong(user, who, obj)
case "Pong":
log.Printf("pong from %s: %s", who, obj)
ilog.Printf("pong from %s: %s", who, obj)
case "Follow":
if obj != user.URL {
log.Printf("can't follow %s", obj)
ilog.Printf("can't follow %s", obj)
return
}
followme(user, who, who, j)
@ -411,7 +410,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
return
}
}
log.Printf("unknown Update activity")
ilog.Printf("unknown Update activity")
dumpactivity(j)
case "Undo":
obj, ok := j.GetMap("object")
@ -428,10 +427,10 @@ func inbox(w http.ResponseWriter, r *http.Request) {
unfollowme(user, who, who, j)
case "Announce":
xid, _ := obj.GetString("object")
log.Printf("undo announce: %s", xid)
dlog.Printf("undo announce: %s", xid)
case "Like":
default:
log.Printf("unknown undo: %s", what)
ilog.Printf("unknown undo: %s", what)
}
case "EmojiReact":
obj, ok := j.GetString("object")
@ -455,7 +454,7 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
payload := buf.Bytes()
j, err := junk.FromBytes(payload)
if err != nil {
log.Printf("bad payload: %s", err)
ilog.Printf("bad payload: %s", err)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
@ -470,9 +469,9 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
keyname, err = httpsig.VerifyRequest(r, payload, zaggy)
}
if err != nil {
log.Printf("inbox message failed signature for %s from %s: %s", keyname, r.Header.Get("X-Forwarded-For"), err)
ilog.Printf("inbox message failed signature for %s from %s: %s", keyname, r.Header.Get("X-Forwarded-For"), err)
if keyname != "" {
log.Printf("bad signature from %s", keyname)
ilog.Printf("bad signature from %s", keyname)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
@ -483,7 +482,7 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
who, _ := j.GetString("actor")
origin := keymatch(keyname, who)
if origin == "" {
log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
ilog.Printf("keyname actor mismatch: %s <> %s", keyname, who)
return
}
if rejectactor(user.ID, who) {
@ -491,17 +490,17 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
}
re_ont := regexp.MustCompile("https://" + serverName + "/o/([[:alnum:]]+)")
what, _ := j.GetString("type")
log.Printf("server got a %s", what)
dlog.Printf("server got a %s", what)
switch what {
case "Follow":
obj, _ := j.GetString("object")
if obj == user.URL {
log.Printf("can't follow the server!")
ilog.Printf("can't follow the server!")
return
}
m := re_ont.FindStringSubmatch(obj)
if len(m) != 2 {
log.Printf("not sure how to handle this")
ilog.Printf("not sure how to handle this")
return
}
ont := "#" + m[1]
@ -510,24 +509,24 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
case "Undo":
obj, ok := j.GetMap("object")
if !ok {
log.Printf("unknown undo no object")
ilog.Printf("unknown undo no object")
return
}
what, _ := obj.GetString("type")
if what != "Follow" {
log.Printf("unknown undo: %s", what)
ilog.Printf("unknown undo: %s", what)
return
}
targ, _ := obj.GetString("object")
m := re_ont.FindStringSubmatch(targ)
if len(m) != 2 {
log.Printf("not sure how to handle this")
ilog.Printf("not sure how to handle this")
return
}
ont := "#" + m[1]
unfollowme(user, who, ont, j)
default:
log.Printf("unhandled server activity: %s", what)
ilog.Printf("unhandled server activity: %s", what)
dumpactivity(j)
}
}
@ -554,11 +553,11 @@ func ximport(w http.ResponseWriter, r *http.Request) {
j, err := GetJunk(xid)
if err != nil {
http.Error(w, "error getting external object", http.StatusInternalServerError)
log.Printf("error getting external object: %s", err)
ilog.Printf("error getting external object: %s", err)
return
}
allinjest(originate(xid), j)
log.Printf("importing %s", xid)
dlog.Printf("importing %s", xid)
user, _ := butwhatabout(u.Username)
info, _ := somethingabout(j)
@ -586,7 +585,7 @@ func xzone(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
rows, err := stmtRecentHonkers.Query(u.UserID, u.UserID)
if err != nil {
log.Printf("query err: %s", err)
elog.Printf("query err: %s", err)
return
}
defer rows.Close()
@ -605,7 +604,7 @@ func xzone(w http.ResponseWriter, r *http.Request) {
templinfo["Honkers"] = honkers
err = readviews.Execute(w, "xzone.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -699,7 +698,7 @@ func showuser(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
if err != nil {
log.Printf("user not found %s: %s", name, err)
ilog.Printf("user not found %s: %s", name, err)
http.NotFound(w, r)
return
}
@ -842,7 +841,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
}
rows, err := stmtAllOnts.Query(userid)
if err != nil {
log.Printf("selection error: %s", err)
elog.Printf("selection error: %s", err)
return
}
defer rows.Close()
@ -851,7 +850,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
var o Ont
err := rows.Scan(&o.Name, &o.Count)
if err != nil {
log.Printf("error scanning ont: %s", err)
elog.Printf("error scanning ont: %s", err)
continue
}
if len(o.Name) > 24 {
@ -870,7 +869,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
templinfo["Onts"] = onts
err = readviews.Execute(w, "onts.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -888,7 +887,7 @@ func getbacktracks(xid string) []string {
err := row.Scan(&rawtracks)
if err != nil {
if err != sql.ErrNoRows {
log.Printf("error scanning tracks: %s", err)
elog.Printf("error scanning tracks: %s", err)
}
return nil
}
@ -910,29 +909,29 @@ func savetracks(tracks map[string][]string) {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("savetracks begin error: %s", err)
elog.Printf("savetracks begin error: %s", err)
return
}
defer func() {
err := tx.Commit()
if err != nil {
log.Printf("savetracks commit error: %s", err)
elog.Printf("savetracks commit error: %s", err)
}
}()
stmtGetTracks, err := tx.Prepare("select fetches from tracks where xid = ?")
if err != nil {
log.Printf("savetracks error: %s", err)
elog.Printf("savetracks error: %s", err)
return
}
stmtNewTracks, err := tx.Prepare("insert into tracks (xid, fetches) values (?, ?)")
if err != nil {
log.Printf("savetracks error: %s", err)
elog.Printf("savetracks error: %s", err)
return
}
stmtUpdateTracks, err := tx.Prepare("update tracks set fetches = ? where xid = ?")
if err != nil {
log.Printf("savetracks error: %s", err)
elog.Printf("savetracks error: %s", err)
return
}
count := 0
@ -949,10 +948,10 @@ func savetracks(tracks map[string][]string) {
all = oneofakind(all)
stmtUpdateTracks.Exec(strings.Join(all, " "))
} else {
log.Printf("savetracks error: %s", err)
elog.Printf("savetracks error: %s", err)
}
}
log.Printf("saved %d new fetches", count)
dlog.Printf("saved %d new fetches", count)
}
var trackchan = make(chan Track)
@ -1091,7 +1090,7 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo
}
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1153,7 +1152,7 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
_, err = db.Exec("update users set about = ?, options = ? where username = ?", whatabout, j, u.Username)
}
if err != nil {
log.Printf("error bouting what: %s", err)
elog.Printf("error bouting what: %s", err)
}
somenamedusers.Clear(u.Username)
somenumberedusers.Clear(u.UserID)
@ -1167,7 +1166,7 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
}
func bonkit(xid string, user *WhatAbout) {
log.Printf("bonking %s", xid)
dlog.Printf("bonking %s", xid)
xonk := getxonk(user.ID, xid)
if xonk == nil {
@ -1183,7 +1182,7 @@ func bonkit(xid string, user *WhatAbout) {
_, err := stmtUpdateFlags.Exec(flagIsBonked, xonk.ID)
if err != nil {
log.Printf("error acking bonk: %s", err)
elog.Printf("error acking bonk: %s", err)
}
oonker := xonk.Oonker
@ -1216,7 +1215,7 @@ func bonkit(xid string, user *WhatAbout) {
err = savehonk(bonk)
if err != nil {
log.Printf("uh oh")
elog.Printf("uh oh")
return
}
@ -1235,7 +1234,7 @@ func submitbonk(w http.ResponseWriter, r *http.Request) {
templinfo["ServerMessage"] = "Bonked!"
err := readviews.Execute(w, "msg.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
}
@ -1250,7 +1249,7 @@ func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string, aux string) {
}
zonk.Public = loudandproud(zonk.Audience)
log.Printf("announcing %sed honk: %s", what, xonk.XID)
dlog.Printf("announcing %sed honk: %s", what, xonk.XID)
go honkworldwide(user, zonk)
}
@ -1265,7 +1264,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsSaved, xonk.ID)
if err != nil {
log.Printf("error saving: %s", err)
elog.Printf("error saving: %s", err)
}
}
return
@ -1276,7 +1275,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil {
_, err := stmtClearFlags.Exec(flagIsSaved, xonk.ID)
if err != nil {
log.Printf("error unsaving: %s", err)
elog.Printf("error unsaving: %s", err)
}
}
return
@ -1294,7 +1293,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsReacted, xonk.ID)
if err != nil {
log.Printf("error saving: %s", err)
elog.Printf("error saving: %s", err)
}
sendzonkofsorts(xonk, user, "react", reaction)
}
@ -1309,7 +1308,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil && !xonk.IsAcked() {
_, err := stmtUpdateFlags.Exec(flagIsAcked, xonk.ID)
if err != nil {
log.Printf("error acking: %s", err)
elog.Printf("error acking: %s", err)
}
sendzonkofsorts(xonk, user, "ack", "")
}
@ -1321,7 +1320,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil && xonk.IsAcked() {
_, err := stmtClearFlags.Exec(flagIsAcked, xonk.ID)
if err != nil {
log.Printf("error deacking: %s", err)
elog.Printf("error deacking: %s", err)
}
sendzonkofsorts(xonk, user, "deack", "")
}
@ -1341,7 +1340,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
xonk = getxonk(userinfo.UserID, what)
_, err := stmtClearFlags.Exec(flagIsBonked, xonk.ID)
if err != nil {
log.Printf("error unbonking: %s", err)
elog.Printf("error unbonking: %s", err)
}
sendzonkofsorts(xonk, user, "unbonk", "")
}
@ -1353,7 +1352,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsUntagged, xonk.ID)
if err != nil {
log.Printf("error untagging: %s", err)
elog.Printf("error untagging: %s", err)
}
}
var badparents map[string]bool
@ -1363,7 +1362,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("zonking %s %s", wherefore, what)
ilog.Printf("zonking %s %s", wherefore, what)
if wherefore == "zonk" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
@ -1375,7 +1374,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
}
_, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
if err != nil {
log.Printf("error saving zonker: %s", err)
elog.Printf("error saving zonker: %s", err)
return
}
}
@ -1416,7 +1415,7 @@ func edithonkpage(w http.ResponseWriter, r *http.Request) {
}
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1441,7 +1440,7 @@ func newhonkpage(w http.ResponseWriter, r *http.Request) {
templinfo["IsPreview"] = true
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1461,7 +1460,7 @@ func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
if err == http.ErrMissingFile {
return nil, nil
}
log.Printf("error reading donk: %s", err)
elog.Printf("error reading donk: %s", err)
http.Error(w, "error reading donk", http.StatusUnsupportedMediaType)
return nil, err
}
@ -1485,7 +1484,7 @@ func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
case "application/pdf":
maxsize := 10000000
if len(data) > maxsize {
log.Printf("bad image: %s too much pdf: %d", err, len(data))
ilog.Printf("bad image: %s too much pdf: %d", err, len(data))
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return nil, err
}
@ -1497,13 +1496,13 @@ func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
default:
maxsize := 100000
if len(data) > maxsize {
log.Printf("bad image: %s too much text: %d", err, len(data))
ilog.Printf("bad image: %s too much text: %d", err, len(data))
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return nil, err
}
for i := 0; i < len(data); i++ {
if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' {
log.Printf("bad image: %s not text: %d", err, data[i])
ilog.Printf("bad image: %s not text: %d", err, data[i])
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return nil, err
}
@ -1521,7 +1520,7 @@ func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
}
fileid, xid, err := savefileandxid(name, desc, "", media, true, data)
if err != nil {
log.Printf("unable to save image: %s", err)
elog.Printf("unable to save image: %s", err)
http.Error(w, "failed to save attachment", http.StatusUnsupportedMediaType)
return nil, err
}
@ -1632,7 +1631,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
butnottooloud(honk.Audience)
honk.Audience = oneofakind(honk.Audience)
if len(honk.Audience) == 0 {
log.Printf("honk to nowhere")
ilog.Printf("honk to nowhere")
http.Error(w, "honk to nowhere...", http.StatusNotFound)
return nil
}
@ -1656,7 +1655,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
if donk != nil {
honk.Donks = append(honk.Donks, donk)
} else {
log.Printf("can't find file: %s", xid)
ilog.Printf("can't find file: %s", xid)
}
}
memetize(honk)
@ -1730,7 +1729,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
templinfo["ServerMessage"] = "honk preview"
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
return nil
}
@ -1741,7 +1740,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
} else {
err := savehonk(honk)
if err != nil {
log.Printf("uh oh")
elog.Printf("uh oh")
return nil
}
}
@ -1762,7 +1761,7 @@ func showhonkers(w http.ResponseWriter, r *http.Request) {
templinfo["HonkerCSRF"] = login.GetCSRF("submithonker", r)
err := readviews.Execute(w, "honkers.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1781,7 +1780,7 @@ func showchatter(w http.ResponseWriter, r *http.Request) {
templinfo["ChonkCSRF"] = login.GetCSRF("sendchonk", r)
err := readviews.Execute(w, "chatter.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1851,7 +1850,7 @@ func showcombos(w http.ResponseWriter, r *http.Request) {
templinfo := getInfo(r)
err := readviews.Execute(w, "combos.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1892,7 +1891,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
}
_, err := stmtUpdateHonker.Exec(name, combos, mj, honkerid, u.UserID)
if err != nil {
log.Printf("update honker err: %s", err)
elog.Printf("update honker err: %s", err)
return
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
@ -1916,7 +1915,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
}
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url, mj)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
@ -1926,7 +1925,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
info, err := investigate(url)
if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
log.Printf("failed to investigate honker: %s", err)
ilog.Printf("failed to investigate honker: %s", err)
return
}
url = info.XID
@ -1942,14 +1941,14 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
if err != sql.ErrNoRows {
http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError)
if err != nil {
log.Printf("honker scan err: %s", err)
elog.Printf("honker scan err: %s", err)
}
return
}
res, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj)
if err != nil {
log.Print(err)
elog.Print(err)
return
}
honkerid, _ = res.LastInsertId()
@ -1969,7 +1968,7 @@ func hfcspage(w http.ResponseWriter, r *http.Request) {
templinfo["FilterCSRF"] = login.GetCSRF("filter", r)
err := readviews.Execute(w, "hfcs.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
@ -1980,7 +1979,7 @@ func savehfcs(w http.ResponseWriter, r *http.Request) {
hfcsid, _ := strconv.ParseInt(r.FormValue("hfcsid"), 10, 0)
_, err := stmtDeleteFilter.Exec(userinfo.UserID, hfcsid)
if err != nil {
log.Printf("error deleting filter: %s", err)
elog.Printf("error deleting filter: %s", err)
}
filtInvalidator.Clear(userinfo.UserID)
http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
@ -2007,7 +2006,7 @@ func savehfcs(w http.ResponseWriter, r *http.Request) {
filt.Notes = strings.TrimSpace(r.FormValue("filtnotes"))
if filt.Actor == "" && filt.Text == "" && !filt.IsAnnounce {
log.Printf("blank filter")
ilog.Printf("blank filter")
http.Error(w, "can't save a blank filter", http.StatusInternalServerError)
return
}
@ -2017,7 +2016,7 @@ func savehfcs(w http.ResponseWriter, r *http.Request) {
_, err = stmtSaveFilter.Exec(userinfo.UserID, j)
}
if err != nil {
log.Printf("error saving filter: %s", err)
elog.Printf("error saving filter: %s", err)
}
filtInvalidator.Clear(userinfo.UserID)
@ -2038,14 +2037,14 @@ func accountpage(w http.ResponseWriter, r *http.Request) {
templinfo["WhatAbout"] = about
err := readviews.Execute(w, "account.html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
func dochpass(w http.ResponseWriter, r *http.Request) {
err := login.ChangePassword(w, r)
if err != nil {
log.Printf("error changing password: %s", err)
elog.Printf("error changing password: %s", err)
}
http.Redirect(w, r, "/account", http.StatusSeeOther)
}
@ -2053,7 +2052,7 @@ func dochpass(w http.ResponseWriter, r *http.Request) {
func fingerlicker(w http.ResponseWriter, r *http.Request) {
orig := r.FormValue("resource")
log.Printf("finger lick: %s", orig)
dlog.Printf("finger lick: %s", orig)
if strings.HasPrefix(orig, "acct:") {
orig = orig[5:]
@ -2064,7 +2063,7 @@ func fingerlicker(w http.ResponseWriter, r *http.Request) {
if idx != -1 {
name = name[idx+1:]
if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
log.Printf("foreign request rejected")
ilog.Printf("foreign request rejected")
name = ""
}
} else {
@ -2072,7 +2071,7 @@ func fingerlicker(w http.ResponseWriter, r *http.Request) {
if idx != -1 {
name = name[:idx]
if !(name+"@"+serverName == orig || name+"@"+masqName == orig) {
log.Printf("foreign request rejected")
ilog.Printf("foreign request rejected")
name = ""
}
}
@ -2149,7 +2148,7 @@ func servehtml(w http.ResponseWriter, r *http.Request) {
}
err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
if err != nil {
log.Print(err)
elog.Print(err)
}
}
func serveemu(w http.ResponseWriter, r *http.Request) {
@ -2172,7 +2171,7 @@ func servefile(w http.ResponseWriter, r *http.Request) {
row := stmtGetFileData.QueryRow(xid)
err := row.Scan(&media, &data)
if err != nil {
log.Printf("error loading file: %s", err)
elog.Printf("error loading file: %s", err)
http.NotFound(w, r)
return
}
@ -2276,7 +2275,7 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
templinfo["User"], _ = butwhatabout(u.Username)
err := readviews.Execute(&buf, "honkfrags.html", templinfo)
if err != nil {
log.Printf("frag error: %s", err)
elog.Printf("frag error: %s", err)
return
}
hydra.Honks = buf.String()
@ -2304,7 +2303,7 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
userid := u.UserID
action := r.FormValue("action")
wait, _ := strconv.ParseInt(r.FormValue("wait"), 10, 0)
log.Printf("api request '%s' on behalf of %s", action, u.Username)
dlog.Printf("api request '%s' on behalf of %s", action, u.Username)
switch action {
case "honk":
h := submithonk(w, r)
@ -2383,15 +2382,15 @@ func enditall() {
signal.Notify(sig, os.Interrupt)
signal.Notify(sig, syscall.SIGTERM)
<-sig
log.Printf("stopping...")
ilog.Printf("stopping...")
for i := 0; i < workinprogress; i++ {
endoftheworld <- true
}
log.Printf("waiting...")
ilog.Printf("waiting...")
for i := 0; i < workinprogress; i++ {
<-readyalready
}
log.Printf("apocalypse")
ilog.Printf("apocalypse")
os.Exit(0)
}
@ -2418,7 +2417,7 @@ func serve() {
listener, err := openListener()
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
go runBackendServer()
go enditall()
@ -2537,6 +2536,6 @@ func serve() {
err = http.Serve(listener, mux)
if err != nil {
log.Fatal(err)
elog.Fatal(err)
}
}