honk/web.go

2243 lines
56 KiB
Go
Raw Normal View History

//
// Copyright (c) 2019 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 (
"bytes"
2019-10-07 03:43:35 +02:00
"database/sql"
"fmt"
"html/template"
"io"
"log"
notrand "math/rand"
"net/http"
"net/url"
"os"
"os/signal"
"regexp"
"sort"
"strconv"
"strings"
2019-11-11 06:00:05 +01:00
"syscall"
"time"
"github.com/gorilla/mux"
"humungus.tedunangst.com/r/webs/cache"
"humungus.tedunangst.com/r/webs/httpsig"
"humungus.tedunangst.com/r/webs/junk"
"humungus.tedunangst.com/r/webs/login"
"humungus.tedunangst.com/r/webs/rss"
"humungus.tedunangst.com/r/webs/templates"
)
var readviews *templates.Template
var userSep = "u"
var honkSep = "h"
func getuserstyle(u *login.UserInfo) template.CSS {
if u == nil {
return ""
}
user, _ := butwhatabout(u.Username)
if user.Options.SkinnyCSS {
return "main { max-width: 700px; }"
}
return ""
}
func getInfo(r *http.Request) map[string]interface{} {
u := login.GetUserInfo(r)
templinfo := make(map[string]interface{})
templinfo["StyleParam"] = getassetparam(viewDir + "/views/style.css")
templinfo["LocalStyleParam"] = getassetparam(viewDir + "/views/local.css")
templinfo["JSParam"] = getassetparam(viewDir + "/views/honkpage.js")
templinfo["UserStyle"] = getuserstyle(u)
templinfo["ServerName"] = serverName
templinfo["IconName"] = iconName
templinfo["UserInfo"] = u
templinfo["UserSep"] = userSep
2019-09-24 19:52:06 +02:00
if u != nil {
var combos []string
combocache.Get(u.UserID, &combos)
templinfo["Combos"] = combos
}
return templinfo
}
func homepage(w http.ResponseWriter, r *http.Request) {
templinfo := getInfo(r)
u := login.GetUserInfo(r)
var honks []*Honk
var userid int64 = -1
2019-10-11 02:37:03 +02:00
templinfo["ServerMessage"] = serverMsg
2019-10-20 22:30:28 +02:00
if u == nil || r.URL.Path == "/front" {
2019-10-11 02:37:03 +02:00
switch r.URL.Path {
case "/events":
honks = geteventhonks(userid)
templinfo["ServerMessage"] = "some recent and upcoming events"
default:
templinfo["ShowRSS"] = true
honks = getpublichonks()
}
} else {
userid = u.UserID
2019-10-11 02:37:03 +02:00
switch r.URL.Path {
case "/atme":
templinfo["ServerMessage"] = "at me!"
templinfo["PageName"] = "atme"
honks = gethonksforme(userid, 0)
honks = osmosis(honks, userid, false)
2019-10-11 02:37:03 +02:00
case "/events":
templinfo["ServerMessage"] = "some recent and upcoming events"
templinfo["PageName"] = "events"
honks = geteventhonks(userid)
honks = osmosis(honks, userid, true)
2019-10-11 02:37:03 +02:00
case "/first":
2019-09-26 17:28:05 +02:00
templinfo["PageName"] = "first"
2019-11-08 19:47:25 +01:00
honks = gethonksforuserfirstclass(userid, 0)
honks = osmosis(honks, userid, true)
2019-10-11 22:03:17 +02:00
case "/saved":
templinfo["ServerMessage"] = "saved honks"
templinfo["PageName"] = "saved"
honks = getsavedhonks(userid, 0)
2019-10-11 02:37:03 +02:00
default:
templinfo["PageName"] = "home"
honks = gethonksforuser(userid, 0)
honks = osmosis(honks, userid, true)
}
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
}
2019-09-17 03:52:48 +02:00
honkpage(w, u, honks, templinfo)
}
func showfunzone(w http.ResponseWriter, r *http.Request) {
var emunames, memenames []string
dir, err := os.Open(dataDir + "/emus")
if err == nil {
emunames, _ = dir.Readdirnames(0)
dir.Close()
}
for i, e := range emunames {
if len(e) > 4 {
emunames[i] = e[:len(e)-4]
}
}
dir, err = os.Open(dataDir + "/memes")
if err == nil {
memenames, _ = dir.Readdirnames(0)
dir.Close()
}
templinfo := getInfo(r)
templinfo["Emus"] = emunames
templinfo["Memes"] = memenames
err = readviews.Execute(w, "funzone.html", templinfo)
if err != nil {
log.Print(err)
}
}
func showrss(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
var honks []*Honk
if name != "" {
honks = gethonksbyuser(name, false, 0)
} else {
honks = getpublichonks()
}
reverbolate(-1, honks)
home := fmt.Sprintf("https://%s/", serverName)
base := home
if name != "" {
home += "u/" + name
name += " "
}
feed := rss.Feed{
Title: name + "honk",
Link: home,
Description: name + "honk rss",
Image: &rss.Image{
URL: base + "icon.png",
Title: name + "honk rss",
Link: home,
},
}
var modtime time.Time
for _, honk := range honks {
if !firstclass(honk) {
continue
}
desc := string(honk.HTML)
2019-10-03 21:49:36 +02:00
if t := honk.Time; t != nil {
desc += fmt.Sprintf(`<p>Time: %s`, t.StartTime.Local().Format("03:04PM EDT Mon Jan 02"))
if t.Duration != 0 {
desc += fmt.Sprintf(`<br>Duration: %s`, t.Duration)
}
}
if p := honk.Place; p != nil {
2019-10-17 00:45:19 +02:00
desc += string(templates.Sprintf(`<p>Location: <a href="%s">%s</a> %f %f`,
p.Url, p.Name, p.Latitude, p.Longitude))
2019-10-03 21:49:36 +02:00
}
2019-10-05 22:50:25 +02:00
for _, d := range honk.Donks {
2019-10-17 00:45:19 +02:00
desc += string(templates.Sprintf(`<p><a href="%s">Attachment: %s</a>`,
d.URL, d.Name))
2019-10-05 22:50:25 +02:00
}
feed.Items = append(feed.Items, &rss.Item{
Title: fmt.Sprintf("%s %s %s", honk.Username, honk.What, honk.XID),
2019-10-06 21:24:28 +02:00
Description: rss.CData{Data: desc},
Link: honk.URL,
PubDate: honk.Date.Format(time.RFC1123),
Guid: &rss.Guid{IsPermaLink: true, Value: honk.URL},
})
if honk.Date.After(modtime) {
modtime = honk.Date
}
}
w.Header().Set("Cache-Control", "max-age=300")
w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat))
err := feed.Write(w)
if err != nil {
log.Printf("error writing rss: %s", err)
}
}
func crappola(j junk.Junk) bool {
t, _ := j.GetString("type")
a, _ := j.GetString("actor")
o, _ := j.GetString("object")
if t == "Delete" && a == o {
log.Printf("crappola from %s", a)
return true
}
return false
}
func ping(user *WhatAbout, who string) {
var box *Box
ok := boxofboxes.Get(who, &box)
if !ok {
log.Printf("no inbox to ping %s", who)
return
}
j := junk.New()
j["@context"] = itiswhatitis
j["type"] = "Ping"
j["id"] = user.URL + "/ping/" + xfiltrate()
j["actor"] = user.URL
j["to"] = who
ki := ziggy(user.ID)
if ki == nil {
return
}
err := PostJunk(ki.keyname, ki.seckey, box.In, j)
if err != nil {
log.Printf("can't send ping: %s", err)
return
}
log.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)
return
}
j := junk.New()
j["@context"] = itiswhatitis
j["type"] = "Pong"
j["id"] = user.URL + "/pong/" + xfiltrate()
j["actor"] = user.URL
j["to"] = who
j["object"] = obj
ki := ziggy(user.ID)
if ki == nil {
return
}
err := PostJunk(ki.keyname, ki.seckey, box.In, j)
if err != nil {
log.Printf("can't send pong: %s", err)
return
}
}
func inbox(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
if err != nil {
http.NotFound(w, r)
return
}
2019-09-22 21:36:06 +02:00
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
var buf bytes.Buffer
2019-11-10 23:21:49 +01:00
limiter := io.LimitReader(r.Body, 1*1024*1024)
io.Copy(&buf, limiter)
payload := buf.Bytes()
2019-10-25 23:44:46 +02:00
j, err := junk.FromBytes(payload)
if err != nil {
log.Printf("bad payload: %s", err)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
return
}
if crappola(j) {
return
}
what, _ := j.GetString("type")
if what == "Like" {
return
}
who, _ := j.GetString("actor")
if rejectactor(user.ID, who) {
return
}
keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
if err != nil {
log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
if keyname != "" {
log.Printf("bad signature from %s", keyname)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
}
2019-10-08 08:35:51 +02:00
http.Error(w, "what did you call me?", http.StatusTeapot)
return
}
origin := keymatch(keyname, who)
if origin == "" {
log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
return
}
switch what {
case "Ping":
obj, _ := j.GetString("id")
log.Printf("ping from %s: %s", who, obj)
pong(user, who, obj)
case "Pong":
obj, _ := j.GetString("object")
log.Printf("pong from %s: %s", who, obj)
case "Follow":
obj, _ := j.GetString("object")
2019-10-27 01:17:46 +02:00
if obj != user.URL {
log.Printf("can't follow %s", obj)
return
}
log.Printf("updating honker follow: %s", who)
var x string
2019-10-27 01:17:46 +02:00
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('dub', 'undub')", who, user.ID)
err = row.Scan(&x)
if err != sql.ErrNoRows {
log.Printf("duplicate follow request: %s", who)
2019-10-28 19:58:18 +01:00
_, err = stmtUpdateFlavor.Exec("dub", user.ID, who, who, "undub")
2019-10-27 01:17:46 +02:00
if err != nil {
log.Printf("error updating honker: %s", err)
}
} else {
2019-10-27 01:17:46 +02:00
stmtSaveDub.Exec(user.ID, who, who, "dub")
}
2019-10-27 01:17:46 +02:00
go rubadubdub(user, j)
case "Accept":
log.Printf("updating honker accept: %s", who)
var name string
2019-10-29 19:18:01 +01:00
db := opendatabase()
row := db.QueryRow("select name from honkers where userid = ? and xid = ? and flavor in ('presub')",
user.ID, who)
err := row.Scan(&name)
if err != nil {
log.Printf("can't get honker name: %s", err)
return
}
_, err = stmtUpdateFlavor.Exec("sub", user.ID, who, name, "presub")
if err != nil {
log.Printf("error updating honker: %s", err)
return
}
case "Update":
obj, ok := j.GetMap("object")
if ok {
what, _ := obj.GetString("type")
switch what {
case "Person":
return
case "Question":
return
2019-09-17 00:00:13 +02:00
case "Note":
2019-10-01 05:32:10 +02:00
go xonksaver(user, j, origin)
2019-09-17 00:00:13 +02:00
return
}
}
log.Printf("unknown Update activity")
fd, _ := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
j.Write(fd)
io.WriteString(fd, "\n")
fd.Close()
case "Undo":
obj, ok := j.GetMap("object")
if !ok {
log.Printf("unknown undo no object")
2019-10-27 01:17:46 +02:00
return
}
what, _ := obj.GetString("type")
switch what {
case "Follow":
log.Printf("updating honker undo: %s", who)
2019-10-28 19:58:18 +01:00
_, err = stmtUpdateFlavor.Exec("undub", user.ID, who, who, "dub")
2019-10-27 01:17:46 +02:00
if err != nil {
log.Printf("error updating honker: %s", err)
return
}
2019-10-27 01:17:46 +02:00
case "Announce":
xid, _ := obj.GetString("object")
log.Printf("undo announce: %s", xid)
case "Like":
default:
log.Printf("unknown undo: %s", what)
}
default:
2019-10-01 05:32:10 +02:00
go xonksaver(user, j, origin)
}
}
2019-10-25 23:31:48 +02:00
func serverinbox(w http.ResponseWriter, r *http.Request) {
if stealthmode(serverUID, r) {
http.NotFound(w, r)
return
}
var buf bytes.Buffer
io.Copy(&buf, r.Body)
payload := buf.Bytes()
2019-10-25 23:44:46 +02:00
j, err := junk.FromBytes(payload)
2019-10-25 23:31:48 +02:00
if err != nil {
log.Printf("bad payload: %s", err)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
return
}
if crappola(j) {
return
}
keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
if err != nil {
log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
if keyname != "" {
log.Printf("bad signature from %s", keyname)
io.WriteString(os.Stdout, "bad payload\n")
os.Stdout.Write(payload)
io.WriteString(os.Stdout, "\n")
}
http.Error(w, "what did you call me?", http.StatusTeapot)
return
}
user := getserveruser()
who, _ := j.GetString("actor")
origin := keymatch(keyname, who)
if origin == "" {
log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
return
}
if rejectactor(user.ID, who) {
return
}
re_ont := regexp.MustCompile("https://" + serverName + "/o/([[:alnum:]]+)")
2019-10-25 23:31:48 +02:00
what, _ := j.GetString("type")
log.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!")
return
}
m := re_ont.FindStringSubmatch(obj)
2019-10-27 01:17:46 +02:00
if len(m) != 2 {
log.Printf("not sure how to handle this")
return
}
ont := "#" + m[1]
log.Printf("%s wants to follow %s", who, ont)
var x string
2019-10-27 01:17:46 +02:00
db := opendatabase()
row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", ont, who, user.ID)
err = row.Scan(&x)
if err != sql.ErrNoRows {
log.Printf("duplicate follow request: %s", who)
_, err = stmtUpdateFlavor.Exec("dub", user.ID, who, ont, "undub")
if err != nil {
log.Printf("error updating honker: %s", err)
}
} else {
2019-10-27 01:17:46 +02:00
stmtSaveDub.Exec(user.ID, ont, who, "dub")
}
2019-10-27 01:17:46 +02:00
go rubadubdub(user, j)
case "Undo":
obj, ok := j.GetMap("object")
if !ok {
log.Printf("unknown undo no object")
2019-10-27 01:17:46 +02:00
return
}
what, _ := obj.GetString("type")
if what != "Follow" {
log.Printf("unknown undo: %s", what)
}
targ, _ := obj.GetString("object")
m := re_ont.FindStringSubmatch(targ)
if len(m) != 2 {
log.Printf("not sure how to handle this")
return
}
ont := "#" + m[1]
2019-10-28 21:03:32 +01:00
log.Printf("updating honker undo: %s %s", who, ont)
2019-10-27 01:17:46 +02:00
_, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub")
if err != nil {
log.Printf("error updating honker: %s", err)
return
}
}
2019-10-25 23:31:48 +02:00
}
func serveractor(w http.ResponseWriter, r *http.Request) {
if stealthmode(serverUID, r) {
http.NotFound(w, r)
return
}
user := getserveruser()
j := junkuser(user)
w.Write(j)
}
func ximport(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
2019-10-11 00:13:38 +02:00
xid := strings.TrimSpace(r.FormValue("xid"))
2019-10-02 05:30:10 +02:00
xonk := getxonk(u.UserID, xid)
if xonk == nil {
p, _ := investigate(xid)
if p != nil {
xid = p.XID
}
j, err := GetJunk(xid)
if err != nil {
http.Error(w, "error getting external object", http.StatusInternalServerError)
log.Printf("error getting external object: %s", err)
return
}
allinjest(originate(xid), j)
2019-10-02 05:30:10 +02:00
log.Printf("importing %s", xid)
user, _ := butwhatabout(u.Username)
info, _ := somethingabout(j)
if info == nil {
xonk = xonksaver(user, j, originate(xid))
} else if info.What == SomeActor {
2019-10-02 05:30:10 +02:00
outbox, _ := j.GetString("outbox")
gimmexonks(user, outbox)
http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther)
return
} else if info.What == SomeCollection {
gimmexonks(user, xid)
http.Redirect(w, r, "/xzone", http.StatusSeeOther)
return
2019-10-02 05:30:10 +02:00
}
}
convoy := ""
if xonk != nil {
convoy = xonk.Convoy
}
http.Redirect(w, r, "/t?c="+url.QueryEscape(convoy), http.StatusSeeOther)
}
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)
return
}
defer rows.Close()
var honkers []Honker
for rows.Next() {
var xid string
rows.Scan(&xid)
honkers = append(honkers, Honker{XID: xid})
}
rows.Close()
for i, _ := range honkers {
_, honkers[i].Handle = handles(honkers[i].XID)
}
templinfo := getInfo(r)
templinfo["XCSRF"] = login.GetCSRF("ximport", r)
templinfo["Honkers"] = honkers
err = readviews.Execute(w, "xzone.html", templinfo)
if err != nil {
log.Print(err)
}
}
var oldoutbox = cache.New(cache.Options{Filler: func(name string) ([]byte, bool) {
user, err := butwhatabout(name)
if err != nil {
2019-10-08 00:11:35 +02:00
return nil, false
}
honks := gethonksbyuser(name, false, 0)
if len(honks) > 20 {
honks = honks[0:20]
}
var jonks []junk.Junk
for _, h := range honks {
j, _ := jonkjonk(user, h)
jonks = append(jonks, j)
}
j := junk.New()
j["@context"] = itiswhatitis
j["id"] = user.URL + "/outbox"
2019-10-25 23:59:30 +02:00
j["attributedTo"] = user.URL
j["type"] = "OrderedCollection"
j["totalItems"] = len(jonks)
j["orderedItems"] = jonks
2019-10-25 23:44:46 +02:00
return j.ToBytes(), true
}, Duration: 1 * time.Minute})
2019-10-08 00:11:35 +02:00
func outbox(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
if err != nil {
http.NotFound(w, r)
return
}
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
var j []byte
ok := oldoutbox.Get(name, &j)
if ok {
w.Header().Set("Content-Type", theonetruename)
w.Write(j)
} else {
http.NotFound(w, r)
}
}
var oldempties = cache.New(cache.Options{Filler: func(url string) ([]byte, bool) {
colname := "/followers"
if strings.HasSuffix(url, "/following") {
colname = "/following"
}
user := fmt.Sprintf("https://%s%s", serverName, url[:len(url)-10])
j := junk.New()
j["@context"] = itiswhatitis
j["id"] = user + colname
j["attributedTo"] = user
j["type"] = "OrderedCollection"
j["totalItems"] = 0
j["orderedItems"] = []junk.Junk{}
return j.ToBytes(), true
}})
func emptiness(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
if err != nil {
http.NotFound(w, r)
return
}
2019-09-24 23:03:20 +02:00
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
var j []byte
ok := oldempties.Get(r.URL.Path, &j)
if ok {
w.Header().Set("Content-Type", theonetruename)
w.Write(j)
} else {
http.NotFound(w, r)
}
}
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)
http.NotFound(w, r)
return
}
2019-09-22 00:20:50 +02:00
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
if friendorfoe(r.Header.Get("Accept")) {
2019-10-07 21:47:37 +02:00
j, ok := asjonker(name)
if ok {
w.Header().Set("Content-Type", theonetruename)
w.Write(j)
} else {
http.NotFound(w, r)
}
return
}
u := login.GetUserInfo(r)
honks := gethonksbyuser(name, u != nil && u.Username == name, 0)
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
templinfo["Name"] = user.Name
whatabout := user.About
whatabout = markitzero(user.About)
2019-10-22 08:02:36 +02:00
templinfo["WhatAbout"] = template.HTML(whatabout)
2019-09-17 03:52:48 +02:00
templinfo["ServerMessage"] = ""
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
func showhonker(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
name := mux.Vars(r)["name"]
var honks []*Honk
if name == "" {
name = r.FormValue("xid")
honks = gethonksbyxonker(u.UserID, name, 0)
} else {
honks = gethonksbyhonker(u.UserID, name, 0)
}
2019-10-17 00:45:19 +02:00
msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, name, name)
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
2019-09-17 04:02:42 +02:00
templinfo["PageName"] = "honker"
templinfo["PageArg"] = name
2019-10-17 00:45:19 +02:00
templinfo["ServerMessage"] = msg
2019-09-17 03:52:48 +02:00
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
func showcombo(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
u := login.GetUserInfo(r)
honks := gethonksbycombo(u.UserID, name, 0)
honks = osmosis(honks, u.UserID, true)
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
2019-09-17 03:55:51 +02:00
templinfo["PageName"] = "combo"
templinfo["PageArg"] = name
2019-09-17 03:52:48 +02:00
templinfo["ServerMessage"] = "honks by combo: " + name
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
func showconvoy(w http.ResponseWriter, r *http.Request) {
c := r.FormValue("c")
u := login.GetUserInfo(r)
honks := gethonksbyconvoy(u.UserID, c, 0)
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
if len(honks) > 0 {
templinfo["TopHID"] = honks[0].ID
}
honks = osmosis(honks, u.UserID, false)
reversehonks(honks)
templinfo["PageName"] = "convoy"
templinfo["PageArg"] = c
2019-09-17 03:52:48 +02:00
templinfo["ServerMessage"] = "honks in convoy: " + c
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
func showsearch(w http.ResponseWriter, r *http.Request) {
q := r.FormValue("q")
u := login.GetUserInfo(r)
honks := gethonksbysearch(u.UserID, q, 0)
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
templinfo["PageName"] = "search"
templinfo["PageArg"] = q
2019-09-17 03:52:48 +02:00
templinfo["ServerMessage"] = "honks for search: " + q
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
func showontology(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
u := login.GetUserInfo(r)
var userid int64 = -1
if u != nil {
userid = u.UserID
}
honks := gethonksbyontology(userid, "#"+name, 0)
2019-10-25 23:59:30 +02:00
if friendorfoe(r.Header.Get("Accept")) {
2019-11-07 03:51:38 +01:00
if len(honks) > 40 {
honks = honks[0:40]
2019-10-25 23:59:30 +02:00
}
var xids []string
for _, h := range honks {
xids = append(xids, h.XID)
}
user := getserveruser()
j := junk.New()
j["@context"] = itiswhatitis
j["id"] = fmt.Sprintf("https://%s/o/%s", serverName, name)
j["name"] = "#" + name
2019-10-25 23:59:30 +02:00
j["attributedTo"] = user.URL
j["type"] = "OrderedCollection"
j["totalItems"] = len(xids)
j["orderedItems"] = xids
j.Write(w)
return
}
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
templinfo["ServerMessage"] = "honks by ontology: " + name
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
2019-10-13 07:58:01 +02:00
type Ont struct {
Name string
2019-10-13 07:58:01 +02:00
Count int64
}
func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
var userid int64 = -1
if u != nil {
userid = u.UserID
}
2019-10-13 07:58:01 +02:00
rows, err := stmtAllOnts.Query(userid)
if err != nil {
log.Printf("selection error: %s", err)
return
}
2019-09-17 15:45:02 +02:00
defer rows.Close()
2019-10-13 07:58:01 +02:00
var onts []Ont
for rows.Next() {
2019-10-13 07:58:01 +02:00
var o Ont
err := rows.Scan(&o.Name, &o.Count)
if err != nil {
log.Printf("error scanning ont: %s", err)
continue
}
2019-10-13 08:04:36 +02:00
if len(o.Name) > 24 {
continue
}
2019-10-13 07:58:01 +02:00
o.Name = o.Name[1:]
onts = append(onts, o)
}
2019-10-13 07:58:01 +02:00
sort.Slice(onts, func(i, j int) bool {
return onts[i].Name < onts[j].Name
})
if u == nil {
w.Header().Set("Cache-Control", "max-age=300")
}
templinfo := getInfo(r)
templinfo["Onts"] = onts
err = readviews.Execute(w, "onts.html", templinfo)
if err != nil {
log.Print(err)
}
}
2019-11-08 21:14:11 +01:00
type Track struct {
xid string
who string
}
2019-11-08 22:22:05 +01:00
func savetracks(tracks map[string][]string) {
db := opendatabase()
tx, err := db.Begin()
if err != nil {
log.Printf("savetracks begin error: %s", err)
return
}
defer func() {
err := tx.Commit()
if err != nil {
log.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)
return
}
stmtNewTracks, err := tx.Prepare("insert into tracks (xid, fetches) values (?, ?)")
if err != nil {
log.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)
return
}
count := 0
for xid, f := range tracks {
count += len(f)
var prev string
row := stmtGetTracks.QueryRow(xid)
err := row.Scan(&prev)
if err == sql.ErrNoRows {
f = oneofakind(f)
stmtNewTracks.Exec(xid, strings.Join(f, " "))
} else if err == nil {
all := append(strings.Split(prev, " "), f...)
all = oneofakind(all)
stmtUpdateTracks.Exec(strings.Join(all, " "))
} else {
log.Printf("savetracks error: %s", err)
}
}
log.Printf("saved %d new fetches", count)
}
2019-11-08 21:14:11 +01:00
var trackchan = make(chan Track)
func tracker() {
2019-11-08 22:22:05 +01:00
timeout := 4 * time.Minute
sleeper := time.NewTimer(timeout)
tracks := make(map[string][]string)
2019-11-08 21:14:11 +01:00
for {
select {
2019-11-08 22:22:05 +01:00
case track := <-trackchan:
tracks[track.xid] = append(tracks[track.xid], track.who)
case <-sleeper.C:
if len(tracks) > 0 {
go savetracks(tracks)
tracks = make(map[string][]string)
}
sleeper.Reset(timeout)
case <-endoftheworld:
if len(tracks) > 0 {
savetracks(tracks)
}
readyalready <- true
2019-11-08 21:14:11 +01:00
}
}
}
var re_keyholder = regexp.MustCompile(`keyId="([^"]+)"`)
2019-11-08 20:50:57 +01:00
func trackback(xid string, r *http.Request) {
agent := r.UserAgent()
who := originate(agent)
sig := r.Header.Get("Signature")
2019-11-08 21:14:11 +01:00
if sig != "" {
m := re_keyholder.FindStringSubmatch(sig)
2019-11-08 21:26:41 +01:00
if len(m) == 2 {
2019-11-08 21:14:11 +01:00
who = m[1]
}
}
2019-11-08 22:22:05 +01:00
if who != "" {
trackchan <- Track{xid: xid, who: who}
}
2019-11-08 20:50:57 +01:00
}
2019-10-29 21:00:41 +01:00
func showonehonk(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
if err != nil {
http.NotFound(w, r)
return
}
2019-09-22 00:20:50 +02:00
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path)
2019-10-07 21:22:10 +02:00
if friendorfoe(r.Header.Get("Accept")) {
j, ok := gimmejonk(xid)
if ok {
2019-11-08 20:50:57 +01:00
trackback(xid, r)
2019-10-07 21:22:10 +02:00
w.Header().Set("Content-Type", theonetruename)
w.Write(j)
} else {
http.NotFound(w, r)
}
return
}
honk := getxonk(user.ID, xid)
if honk == nil {
http.NotFound(w, r)
return
}
u := login.GetUserInfo(r)
if u != nil && u.UserID != user.ID {
u = nil
}
if !honk.Public {
if u == nil {
http.NotFound(w, r)
return
}
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
templinfo["ServerMessage"] = "one honk maybe more"
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, []*Honk{honk}, templinfo)
return
}
rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0)
reversehonks(rawhonks)
var honks []*Honk
for _, h := range rawhonks {
if h.XID == xid && len(honks) != 0 {
2019-10-29 21:00:41 +01:00
h.Style += " glow"
}
if h.Public && (h.Whofore == 2 || h.IsAcked()) {
honks = append(honks, h)
}
}
2019-09-17 03:52:48 +02:00
templinfo := getInfo(r)
templinfo["ServerMessage"] = "one honk maybe more"
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
honkpage(w, u, honks, templinfo)
}
2019-09-17 03:52:48 +02:00
func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo map[string]interface{}) {
var userid int64 = -1
if u != nil {
userid = u.UserID
}
reverbolate(userid, honks)
templinfo["Honks"] = honks
2019-10-20 20:49:49 +02:00
if templinfo["TopHID"] == nil {
if len(honks) > 0 {
templinfo["TopHID"] = honks[0].ID
} else {
templinfo["TopHID"] = 0
}
2019-10-07 22:33:31 +02:00
}
if u == nil {
w.Header().Set("Cache-Control", "max-age=60")
}
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
}
}
func saveuser(w http.ResponseWriter, r *http.Request) {
whatabout := r.FormValue("whatabout")
u := login.GetUserInfo(r)
db := opendatabase()
var options UserOptions
if r.FormValue("skinny") == "skinny" {
options.SkinnyCSS = true
}
j, err := jsonify(options)
if err == nil {
_, err = db.Exec("update users set about = ?, options = ? where username = ?", whatabout, j, u.Username)
}
if err != nil {
log.Printf("error bouting what: %s", err)
}
somenamedusers.Clear(u.Username)
somenumberedusers.Clear(u.UserID)
http.Redirect(w, r, "/account", http.StatusSeeOther)
}
2019-09-11 22:20:22 +02:00
func submitbonk(w http.ResponseWriter, r *http.Request) {
xid := r.FormValue("xid")
userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username)
log.Printf("bonking %s", xid)
xonk := getxonk(userinfo.UserID, xid)
if xonk == nil {
return
}
if !xonk.Public {
return
}
2019-10-30 22:31:48 +01:00
if xonk.IsBonked() {
return
}
donksforhonks([]*Honk{xonk})
_, err := stmtUpdateFlags.Exec(flagIsBonked, xonk.ID)
if err != nil {
log.Printf("error acking bonk: %s", err)
}
oonker := xonk.Oonker
if oonker == "" {
oonker = xonk.Honker
}
dt := time.Now().UTC()
2019-10-16 08:06:53 +02:00
bonk := &Honk{
UserID: userinfo.UserID,
Username: userinfo.Username,
What: "bonk",
Honker: user.URL,
2019-09-11 22:20:22 +02:00
Oonker: oonker,
XID: xonk.XID,
2019-09-10 22:06:06 +02:00
RID: xonk.RID,
2019-09-11 22:20:22 +02:00
Noise: xonk.Noise,
Precis: xonk.Precis,
URL: xonk.URL,
Date: dt,
Donks: xonk.Donks,
2019-09-11 22:20:22 +02:00
Whofore: 2,
Convoy: xonk.Convoy,
Audience: []string{thewholeworld, oonker},
Public: true,
2019-10-16 08:06:53 +02:00
Format: "html",
Place: xonk.Place,
Onts: xonk.Onts,
Time: xonk.Time,
}
2019-10-16 08:06:53 +02:00
err = savehonk(bonk)
if err != nil {
2019-09-11 22:20:22 +02:00
log.Printf("uh oh")
return
}
2019-10-16 08:06:53 +02:00
go honkworldwide(user, bonk)
if r.FormValue("js") != "1" {
templinfo := getInfo(r)
templinfo["ServerMessage"] = "Bonked!"
err = readviews.Execute(w, "msg.html", templinfo)
if err != nil {
log.Print(err)
}
}
}
func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string) {
2019-10-16 08:06:53 +02:00
zonk := &Honk{
What: what,
XID: xonk.XID,
Date: time.Now().UTC(),
Audience: oneofakind(xonk.Audience),
}
zonk.Public = loudandproud(zonk.Audience)
log.Printf("announcing %sed honk: %s", what, xonk.XID)
2019-10-16 08:06:53 +02:00
go honkworldwide(user, zonk)
}
func zonkit(w http.ResponseWriter, r *http.Request) {
wherefore := r.FormValue("wherefore")
what := r.FormValue("what")
userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username)
2019-10-11 22:03:17 +02:00
if wherefore == "save" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsSaved, xonk.ID)
if err != nil {
log.Printf("error saving: %s", err)
}
}
return
}
if wherefore == "unsave" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
_, err := stmtClearFlags.Exec(flagIsSaved, xonk.ID)
if err != nil {
log.Printf("error unsaving: %s", err)
}
}
return
}
2019-10-07 21:22:10 +02:00
// my hammer is too big, oh well
defer oldjonks.Flush()
if wherefore == "ack" {
xonk := getxonk(userinfo.UserID, what)
2019-10-30 22:23:02 +01:00
if xonk != nil && !xonk.IsAcked() {
_, err := stmtUpdateFlags.Exec(flagIsAcked, xonk.ID)
if err != nil {
log.Printf("error acking: %s", err)
}
sendzonkofsorts(xonk, user, "ack")
}
return
}
if wherefore == "deack" {
xonk := getxonk(userinfo.UserID, what)
2019-10-30 22:23:02 +01:00
if xonk != nil && xonk.IsAcked() {
_, err := stmtClearFlags.Exec(flagIsAcked, xonk.ID)
if err != nil {
log.Printf("error deacking: %s", err)
}
sendzonkofsorts(xonk, user, "deack")
}
return
}
if wherefore == "unbonk" {
xonk := getbonk(userinfo.UserID, what)
if xonk != nil {
2019-09-16 23:00:50 +02:00
deletehonk(xonk.ID)
xonk = getxonk(userinfo.UserID, what)
2019-09-16 23:00:50 +02:00
_, err := stmtClearFlags.Exec(flagIsBonked, xonk.ID)
if err != nil {
log.Printf("error unbonking: %s", err)
}
sendzonkofsorts(xonk, user, "unbonk")
}
return
}
2019-10-30 00:14:41 +01:00
if wherefore == "untag" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsUntagged, xonk.ID)
if err != nil {
log.Printf("error untagging: %s", err)
}
}
var badparents map[string]bool
untagged.GetAndLock(userinfo.UserID, &badparents)
badparents[what] = true
untagged.Unlock()
2019-10-30 00:14:41 +01:00
return
}
log.Printf("zonking %s %s", wherefore, what)
if wherefore == "zonk" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
2019-09-16 23:00:50 +02:00
deletehonk(xonk.ID)
if xonk.Whofore == 2 || xonk.Whofore == 3 {
sendzonkofsorts(xonk, user, "zonk")
}
}
}
_, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
if err != nil {
log.Printf("error saving zonker: %s", err)
return
}
}
2019-09-17 00:00:13 +02:00
func edithonkpage(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
user, _ := butwhatabout(u.Username)
xid := r.FormValue("xid")
honk := getxonk(u.UserID, xid)
2019-10-09 22:16:38 +02:00
if !canedithonk(user, honk) {
http.Error(w, "no editing that please", http.StatusInternalServerError)
2019-09-17 00:00:13 +02:00
return
}
noise := honk.Noise
2019-09-17 00:00:13 +02:00
honks := []*Honk{honk}
donksforhonks(honks)
2019-09-17 00:00:13 +02:00
reverbolate(u.UserID, honks)
templinfo := getInfo(r)
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
templinfo["Honks"] = honks
templinfo["Noise"] = noise
templinfo["SavedPlace"] = honk.Place
2019-09-17 00:00:13 +02:00
templinfo["ServerMessage"] = "honk edit"
templinfo["IsPreview"] = true
2019-09-17 00:00:13 +02:00
templinfo["UpdateXID"] = honk.XID
if len(honk.Donks) > 0 {
templinfo["SavedFile"] = honk.Donks[0].XID
}
2019-09-17 00:00:13 +02:00
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
}
}
func newhonkpage(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
rid := r.FormValue("rid")
noise := ""
xonk := getxonk(u.UserID, rid)
if xonk != nil {
_, replto := handles(xonk.Honker)
if replto != "" {
noise = "@" + replto + " "
}
}
templinfo := getInfo(r)
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
templinfo["InReplyTo"] = rid
templinfo["Noise"] = noise
templinfo["ServerMessage"] = "compose honk"
templinfo["IsPreview"] = true
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
}
}
2019-10-09 22:16:38 +02:00
func canedithonk(user *WhatAbout, honk *Honk) bool {
if honk == nil || honk.Honker != user.URL || honk.What == "bonk" {
return false
}
return true
}
2019-11-11 01:33:40 +01:00
func submitwebhonk(w http.ResponseWriter, r *http.Request) {
submithonk(w, r, false)
}
// what a hot mess this function is
2019-11-11 01:33:40 +01:00
func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) {
rid := r.FormValue("rid")
noise := r.FormValue("noise")
userinfo := login.GetUserInfo(r)
user, _ := butwhatabout(userinfo.Username)
dt := time.Now().UTC()
2019-09-17 00:00:13 +02:00
updatexid := r.FormValue("updatexid")
var honk *Honk
if updatexid != "" {
honk = getxonk(userinfo.UserID, updatexid)
2019-10-09 22:16:38 +02:00
if !canedithonk(user, honk) {
http.Error(w, "no editing that please", http.StatusInternalServerError)
2019-09-17 00:00:13 +02:00
return
}
honk.Date = dt
honk.What = "update"
honk.Format = "markdown"
2019-09-17 00:00:13 +02:00
} 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,
What: what,
Honker: user.URL,
XID: xid,
Date: dt,
Format: "markdown",
2019-09-17 00:00:13 +02:00
}
}
noise = strings.Replace(noise, "\r", "", -1)
noise = quickrename(noise, userinfo.UserID)
noise = hooterize(noise)
honk.Noise = noise
2019-10-22 06:19:31 +02:00
translate(honk, false)
var convoy string
if rid != "" {
xonk := getxonk(userinfo.UserID, rid)
if xonk != nil {
if xonk.Public {
honk.Audience = append(honk.Audience, xonk.Audience...)
}
convoy = xonk.Convoy
} else {
xonkaud, c := whosthere(rid)
honk.Audience = append(honk.Audience, xonkaud...)
convoy = c
}
for i, a := range honk.Audience {
if a == thewholeworld {
honk.Audience[0], honk.Audience[i] = honk.Audience[i], honk.Audience[0]
break
}
}
honk.RID = rid
} else {
honk.Audience = []string{thewholeworld}
}
if honk.Noise != "" && honk.Noise[0] == '@' {
honk.Audience = append(grapevine(honk.Noise), honk.Audience...)
} else {
honk.Audience = append(honk.Audience, grapevine(honk.Noise)...)
}
if convoy == "" {
convoy = "data:,electrichonkytonk-" + xfiltrate()
}
butnottooloud(honk.Audience)
honk.Audience = oneofakind(honk.Audience)
if len(honk.Audience) == 0 {
log.Printf("honk to nowhere")
http.Error(w, "honk to nowhere...", http.StatusNotFound)
return
}
honk.Public = loudandproud(honk.Audience)
honk.Convoy = convoy
donkxid := r.FormValue("donkxid")
if donkxid == "" {
file, filehdr, err := r.FormFile("donk")
if err == nil {
var buf bytes.Buffer
io.Copy(&buf, file)
file.Close()
data := buf.Bytes()
xid := xfiltrate()
var media, name string
img, err := shrinkit(data)
if err == nil {
data = img.Data
format := img.Format
media = "image/" + format
if format == "jpeg" {
format = "jpg"
}
name = xid + "." + format
xid = name
} else {
ct := http.DetectContentType(data)
switch ct {
case "application/pdf":
maxsize := 1000000
if len(data) > maxsize {
log.Printf("bad image: %s too much pdf: %d", err, len(data))
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return
}
media = ct
xid += ".pdf"
name = filehdr.Filename
if name == "" {
name = xid
}
default:
maxsize := 100000
if len(data) > maxsize {
log.Printf("bad image: %s too much text: %d", err, len(data))
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return
}
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])
http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
return
}
}
media = "text/plain"
xid += ".txt"
name = filehdr.Filename
if name == "" {
name = xid
}
}
}
2019-10-11 00:13:38 +02:00
desc := strings.TrimSpace(r.FormValue("donkdesc"))
if desc == "" {
desc = name
}
url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
fileid, err := savefile(xid, name, desc, url, media, true, data)
if err != nil {
log.Printf("unable to save image: %s", err)
return
}
2019-10-21 07:29:39 +02:00
d := &Donk{
FileID: fileid,
XID: xid,
Desc: desc,
URL: url,
Local: true,
}
honk.Donks = append(honk.Donks, d)
2019-10-11 16:30:23 +02:00
donkxid = xid
}
} else {
xid := donkxid
url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
donk := finddonk(url)
if donk != nil {
honk.Donks = append(honk.Donks, donk)
} else {
log.Printf("can't find file: %s", xid)
}
}
herd := herdofemus(noise)
for _, e := range herd {
donk := savedonk(e.ID, e.Name, e.Name, "image/png", true)
if donk != nil {
donk.Name = e.Name
honk.Donks = append(honk.Donks, donk)
}
}
2019-09-17 00:00:13 +02:00
memetize(honk)
2019-10-22 06:19:31 +02:00
imaginate(honk)
2019-10-11 00:13:38 +02:00
placename := strings.TrimSpace(r.FormValue("placename"))
placelat := strings.TrimSpace(r.FormValue("placelat"))
placelong := strings.TrimSpace(r.FormValue("placelong"))
placeurl := strings.TrimSpace(r.FormValue("placeurl"))
if placename != "" || placelat != "" || placelong != "" || placeurl != "" {
2019-09-28 06:12:50 +02:00
p := new(Place)
p.Name = placename
p.Latitude, _ = strconv.ParseFloat(placelat, 64)
p.Longitude, _ = strconv.ParseFloat(placelong, 64)
2019-10-11 00:13:38 +02:00
p.Url = placeurl
2019-09-28 06:12:50 +02:00
honk.Place = p
}
2019-10-11 00:13:38 +02:00
timestart := strings.TrimSpace(r.FormValue("timestart"))
if timestart != "" {
t := new(Time)
now := time.Now().Local()
2019-10-03 06:11:02 +02:00
for _, layout := range []string{"2006-01-02 3:04pm", "2006-01-02 15:04", "3:04pm", "15:04"} {
start, err := time.ParseInLocation(layout, timestart, now.Location())
if err == nil {
if start.Year() == 0 {
start = time.Date(now.Year(), now.Month(), now.Day(), start.Hour(), start.Minute(), 0, 0, now.Location())
}
t.StartTime = start
break
}
}
2019-10-03 06:11:02 +02:00
timeend := r.FormValue("timeend")
2019-10-21 08:28:35 +02:00
dur := parseDuration(timeend)
if dur != 0 {
2019-10-03 06:11:02 +02:00
t.Duration = Duration(dur)
}
if !t.StartTime.IsZero() {
honk.What = "event"
honk.Time = t
}
}
2019-09-28 06:12:50 +02:00
2019-09-11 22:20:22 +02:00
if honk.Public {
honk.Whofore = 2
} else {
honk.Whofore = 3
}
2019-09-18 21:30:39 +02:00
// back to markdown
honk.Noise = noise
if r.FormValue("preview") == "preview" {
2019-09-17 00:00:13 +02:00
honks := []*Honk{honk}
reverbolate(userinfo.UserID, honks)
templinfo := getInfo(r)
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
templinfo["Honks"] = honks
templinfo["InReplyTo"] = r.FormValue("rid")
templinfo["Noise"] = r.FormValue("noise")
templinfo["SavedFile"] = donkxid
templinfo["IsPreview"] = true
2019-11-10 00:44:02 +01:00
templinfo["UpdateXID"] = updatexid
templinfo["ServerMessage"] = "honk preview"
err := readviews.Execute(w, "honkpage.html", templinfo)
if err != nil {
log.Print(err)
}
return
}
2019-09-11 22:20:22 +02:00
2019-09-17 00:00:13 +02:00
if updatexid != "" {
updatehonk(honk)
2019-10-07 21:22:10 +02:00
oldjonks.Clear(honk.XID)
2019-09-17 00:00:13 +02:00
} else {
err := savehonk(honk)
if err != nil {
log.Printf("uh oh")
return
}
}
2019-09-11 22:20:22 +02:00
// reload for consistency
honk.Donks = nil
2019-09-17 00:00:13 +02:00
donksforhonks([]*Honk{honk})
2019-09-17 00:00:13 +02:00
go honkworldwide(user, honk)
2019-11-11 01:33:40 +01:00
if isAPI {
w.Write([]byte(honk.XID))
} else {
http.Redirect(w, r, honk.XID[len(serverName)+8:], http.StatusSeeOther)
}
}
func showhonkers(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r)
templinfo := getInfo(r)
templinfo["Honkers"] = gethonkers(userinfo.UserID)
2019-09-11 22:20:22 +02:00
templinfo["HonkerCSRF"] = login.GetCSRF("submithonker", r)
err := readviews.Execute(w, "honkers.html", templinfo)
if err != nil {
log.Print(err)
}
}
var combocache = cache.New(cache.Options{Filler: func(userid int64) ([]string, bool) {
2019-09-24 19:40:20 +02:00
honkers := gethonkers(userid)
var combos []string
for _, h := range honkers {
combos = append(combos, h.Combos...)
}
for i, c := range combos {
if c == "-" {
combos[i] = ""
}
}
combos = oneofakind(combos)
sort.Strings(combos)
2019-09-24 19:40:20 +02:00
return combos, true
}, Invalidator: &honkerinvalidator})
2019-09-24 19:40:20 +02:00
func showcombos(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r)
var combos []string
combocache.Get(userinfo.UserID, &combos)
templinfo := getInfo(r)
err := readviews.Execute(w, "combos.html", templinfo)
if err != nil {
log.Print(err)
}
}
2019-09-11 22:20:22 +02:00
func submithonker(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
2019-10-11 00:13:38 +02:00
name := strings.TrimSpace(r.FormValue("name"))
url := strings.TrimSpace(r.FormValue("url"))
peep := r.FormValue("peep")
2019-10-11 00:13:38 +02:00
combos := strings.TrimSpace(r.FormValue("combos"))
combos = " " + combos + " "
honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
defer honkerinvalidator.Clear(u.UserID)
2019-09-24 19:40:20 +02:00
if honkerid > 0 {
goodbye := r.FormValue("goodbye")
if goodbye == "F" {
db := opendatabase()
2019-10-07 03:50:56 +02:00
row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('sub')",
honkerid, u.UserID)
2019-10-07 03:33:10 +02:00
err := row.Scan(&url)
if err != nil {
log.Printf("can't get honker xid: %s", err)
return
}
2019-10-07 03:33:10 +02:00
log.Printf("unsubscribing from %s", url)
user, _ := butwhatabout(u.Username)
2019-10-28 19:58:18 +01:00
_, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, name, "sub")
if err != nil {
log.Printf("error updating honker: %s", err)
return
}
2019-10-07 03:33:10 +02:00
go itakeitallback(user, url)
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return
}
if goodbye == "X" {
var owner string
2019-10-07 03:33:10 +02:00
db := opendatabase()
row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')",
2019-10-07 03:33:10 +02:00
honkerid, u.UserID)
err := row.Scan(&url, &owner)
2019-10-07 03:33:10 +02:00
if err != nil {
log.Printf("can't get honker xid: %s", err)
return
}
log.Printf("resubscribing to %s", url)
user, _ := butwhatabout(u.Username)
_, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "unsub")
2019-10-07 03:33:10 +02:00
if err == nil {
_, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "peep")
2019-10-07 03:33:10 +02:00
}
if err != nil {
log.Printf("error updating honker: %s", err)
return
}
go subsub(user, url, owner)
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
return
}
2019-10-07 03:45:58 +02:00
_, err := stmtUpdateHonker.Exec(name, combos, honkerid, u.UserID)
if err != nil {
log.Printf("update honker err: %s", err)
return
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
2019-09-19 00:30:43 +02:00
return
}
2019-10-28 19:50:50 +01:00
if url == "" {
http.Error(w, "subscribing to nothing?", http.StatusInternalServerError)
return
}
flavor := "presub"
if peep == "peep" {
flavor = "peep"
}
2019-10-27 00:55:39 +02:00
if url[0] == '#' {
flavor = "peep"
if name == "" {
name = url
}
_, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url)
2019-10-27 00:55:39 +02:00
if err != nil {
log.Print(err)
return
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
2019-10-27 06:02:50 +01:00
return
2019-10-27 00:55:39 +02:00
}
info, err := investigate(url)
if err != nil {
http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
2019-10-07 03:43:35 +02:00
log.Printf("failed to investigate honker: %s", err)
return
}
url = info.XID
2019-10-07 03:43:35 +02:00
var x string
2019-10-07 03:43:35 +02:00
db := opendatabase()
row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)
err = row.Scan(&x)
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)
}
return
}
if name == "" {
name = info.Name
}
_, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner)
if err != nil {
log.Print(err)
return
}
if flavor == "presub" {
user, _ := butwhatabout(u.Username)
go subsub(user, url, info.Owner)
}
http.Redirect(w, r, "/honkers", http.StatusSeeOther)
}
2019-10-07 02:26:21 +02:00
func hfcspage(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r)
2019-10-07 02:26:21 +02:00
filters := getfilters(userinfo.UserID, filtAny)
templinfo := getInfo(r)
templinfo["Filters"] = filters
2019-10-07 02:26:21 +02:00
templinfo["FilterCSRF"] = login.GetCSRF("filter", r)
err := readviews.Execute(w, "hfcs.html", templinfo)
if err != nil {
log.Print(err)
}
}
2019-10-07 02:26:21 +02:00
func savehfcs(w http.ResponseWriter, r *http.Request) {
userinfo := login.GetUserInfo(r)
itsok := r.FormValue("itsok")
if itsok == "iforgiveyou" {
2019-10-07 02:26:21 +02:00
hfcsid, _ := strconv.ParseInt(r.FormValue("hfcsid"), 10, 0)
_, err := stmtDeleteFilter.Exec(userinfo.UserID, hfcsid)
if err != nil {
log.Printf("error deleting filter: %s", err)
}
filtcache.Clear(userinfo.UserID)
2019-10-07 02:26:21 +02:00
http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
return
}
filt := new(Filter)
2019-10-11 00:13:38 +02:00
filt.Name = strings.TrimSpace(r.FormValue("name"))
2019-10-07 02:26:21 +02:00
filt.Date = time.Now().UTC()
2019-10-11 00:13:38 +02:00
filt.Actor = strings.TrimSpace(r.FormValue("actor"))
2019-10-07 02:26:21 +02:00
filt.IncludeAudience = r.FormValue("incaud") == "yes"
2019-10-11 00:13:38 +02:00
filt.Text = strings.TrimSpace(r.FormValue("filttext"))
2019-10-07 02:26:21 +02:00
filt.IsAnnounce = r.FormValue("isannounce") == "yes"
2019-10-11 00:13:38 +02:00
filt.AnnounceOf = strings.TrimSpace(r.FormValue("announceof"))
2019-10-07 02:26:21 +02:00
filt.Reject = r.FormValue("doreject") == "yes"
filt.SkipMedia = r.FormValue("doskipmedia") == "yes"
filt.Hide = r.FormValue("dohide") == "yes"
filt.Collapse = r.FormValue("docollapse") == "yes"
2019-10-11 00:13:38 +02:00
filt.Rewrite = strings.TrimSpace(r.FormValue("filtrewrite"))
filt.Replace = strings.TrimSpace(r.FormValue("filtreplace"))
2019-10-21 08:28:35 +02:00
if dur := parseDuration(r.FormValue("filtduration")); dur > 0 {
filt.Expiration = time.Now().UTC().Add(dur)
}
2019-10-07 02:26:21 +02:00
if filt.Actor == "" && filt.Text == "" {
log.Printf("blank filter")
return
}
2019-10-07 02:26:21 +02:00
j, err := jsonify(filt)
if err == nil {
_, err = stmtSaveFilter.Exec(userinfo.UserID, j)
}
if err != nil {
log.Printf("error saving filter: %s", err)
}
filtcache.Clear(userinfo.UserID)
http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
}
func accountpage(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
user, _ := butwhatabout(u.Username)
templinfo := getInfo(r)
templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
templinfo["User"] = user
err := readviews.Execute(w, "account.html", templinfo)
if err != nil {
log.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)
}
http.Redirect(w, r, "/account", http.StatusSeeOther)
}
func fingerlicker(w http.ResponseWriter, r *http.Request) {
orig := r.FormValue("resource")
log.Printf("finger lick: %s", orig)
if strings.HasPrefix(orig, "acct:") {
orig = orig[5:]
}
name := orig
idx := strings.LastIndexByte(name, '/')
if idx != -1 {
name = name[idx+1:]
if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
log.Printf("foreign request rejected")
name = ""
}
} else {
idx = strings.IndexByte(name, '@')
if idx != -1 {
name = name[:idx]
if name+"@"+serverName != orig {
log.Printf("foreign request rejected")
name = ""
}
}
}
user, err := butwhatabout(name)
if err != nil {
http.NotFound(w, r)
return
}
2019-09-24 23:03:20 +02:00
if stealthmode(user.ID, r) {
http.NotFound(w, r)
return
}
j := junk.New()
j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName)
j["aliases"] = []string{user.URL}
l := junk.New()
l["rel"] = "self"
l["type"] = `application/activity+json`
l["href"] = user.URL
2019-10-19 21:20:47 +02:00
j["links"] = []junk.Junk{l}
w.Header().Set("Content-Type", "application/jrd+json")
j.Write(w)
}
func somedays() string {
secs := 432000 + notrand.Int63n(432000)
return fmt.Sprintf("%d", secs)
}
func avatate(w http.ResponseWriter, r *http.Request) {
n := r.FormValue("a")
a := avatar(n)
w.Header().Set("Cache-Control", "max-age="+somedays())
w.Write(a)
}
2019-09-19 04:17:50 +02:00
func serveasset(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=7776000")
dir := viewDir
if r.URL.Path == "/local.css" {
dir = dataDir
}
http.ServeFile(w, r, dir+"/views"+r.URL.Path)
2019-09-19 04:17:50 +02:00
}
2019-10-07 07:25:41 +02:00
func servehelp(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
w.Header().Set("Cache-Control", "max-age=3600")
http.ServeFile(w, r, viewDir+"/docs/"+name)
2019-10-07 07:25:41 +02:00
}
func servehtml(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
templinfo := getInfo(r)
templinfo["AboutMsg"] = aboutMsg
templinfo["LoginMsg"] = loginMsg
2019-11-09 03:15:40 +01:00
templinfo["HonkVersion"] = softwareVersion
2019-11-09 01:11:37 +01:00
if r.URL.Path == "/about" {
templinfo["Sensors"] = getSensors()
}
if u == nil {
w.Header().Set("Cache-Control", "max-age=60")
}
err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
if err != nil {
log.Print(err)
}
}
func serveemu(w http.ResponseWriter, r *http.Request) {
xid := mux.Vars(r)["xid"]
w.Header().Set("Cache-Control", "max-age="+somedays())
http.ServeFile(w, r, dataDir+"/emus/"+xid)
}
func servememe(w http.ResponseWriter, r *http.Request) {
xid := mux.Vars(r)["xid"]
w.Header().Set("Cache-Control", "max-age="+somedays())
http.ServeFile(w, r, dataDir+"/memes/"+xid)
}
func servefile(w http.ResponseWriter, r *http.Request) {
xid := mux.Vars(r)["xid"]
var media string
var data []byte
row := stmtGetFileData.QueryRow(xid)
err := row.Scan(&media, &data)
if err != nil {
log.Printf("error loading file: %s", err)
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", media)
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Cache-Control", "max-age="+somedays())
w.Write(data)
}
func nomoroboto(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "User-agent: *\n")
io.WriteString(w, "Disallow: /a\n")
io.WriteString(w, "Disallow: /d\n")
io.WriteString(w, "Disallow: /meme\n")
2019-10-14 00:15:30 +02:00
io.WriteString(w, "Disallow: /o\n")
for _, u := range allusers() {
fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
}
}
2019-09-16 21:15:32 +02:00
func webhydra(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
userid := u.UserID
templinfo := getInfo(r)
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
page := r.FormValue("page")
wanted, _ := strconv.ParseInt(r.FormValue("tophid"), 10, 0)
2019-09-16 21:15:32 +02:00
var honks []*Honk
switch page {
case "atme":
honks = gethonksforme(userid, wanted)
honks = osmosis(honks, userid, false)
2019-10-07 18:34:36 +02:00
templinfo["ServerMessage"] = "at me!"
2019-09-16 21:15:32 +02:00
case "home":
honks = gethonksforuser(userid, wanted)
honks = osmosis(honks, userid, true)
2019-10-07 18:34:36 +02:00
templinfo["ServerMessage"] = serverMsg
2019-09-26 17:28:05 +02:00
case "first":
honks = gethonksforuserfirstclass(userid, wanted)
honks = osmosis(honks, userid, true)
2019-10-07 18:34:36 +02:00
templinfo["ServerMessage"] = "first class only"
2019-10-11 22:03:17 +02:00
case "saved":
honks = getsavedhonks(userid, wanted)
2019-10-11 22:03:17 +02:00
templinfo["PageName"] = "saved"
templinfo["ServerMessage"] = "saved honks"
case "combo":
c := r.FormValue("c")
honks = gethonksbycombo(userid, c, wanted)
honks = osmosis(honks, userid, false)
2019-10-07 18:34:36 +02:00
templinfo["ServerMessage"] = "honks by combo: " + c
2019-09-16 21:15:32 +02:00
case "convoy":
c := r.FormValue("c")
honks = gethonksbyconvoy(userid, c, wanted)
honks = osmosis(honks, userid, false)
2019-10-07 18:34:36 +02:00
templinfo["ServerMessage"] = "honks in convoy: " + c
2019-10-02 01:45:17 +02:00
case "honker":
xid := r.FormValue("xid")
if strings.IndexByte(xid, '@') != -1 {
xid = gofish(xid)
}
honks = gethonksbyxonker(userid, xid, wanted)
2019-10-17 00:45:19 +02:00
msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, xid, xid)
templinfo["ServerMessage"] = msg
2019-09-16 21:15:32 +02:00
default:
http.NotFound(w, r)
}
if len(honks) > 0 {
templinfo["TopHID"] = honks[0].ID
2019-10-20 20:49:49 +02:00
} else {
templinfo["TopHID"] = wanted
2019-09-16 21:15:32 +02:00
}
reverbolate(userid, honks)
templinfo["Honks"] = honks
w.Header().Set("Content-Type", "text/html; charset=utf-8")
err := readviews.Execute(w, "honkfrags.html", templinfo)
if err != nil {
log.Printf("frag error: %s", err)
}
}
2019-11-12 07:09:08 +01:00
var honkline = make(chan bool)
func honkhonkline() {
for {
select {
case honkline <- true:
default:
return
}
}
}
2019-11-07 22:50:37 +01:00
func apihandler(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
2019-11-12 07:09:08 +01:00
userid := u.UserID
2019-11-07 22:50:37 +01:00
action := r.FormValue("action")
2019-11-12 07:09:08 +01:00
wait, _ := strconv.ParseInt(r.FormValue("wait"), 10, 0)
2019-11-07 22:50:37 +01:00
log.Printf("api request '%s' on behalf of %s", action, u.Username)
switch action {
case "honk":
2019-11-11 01:33:40 +01:00
submithonk(w, r, true)
2019-11-12 07:09:08 +01:00
case "gethonks":
var honks []*Honk
wanted, _ := strconv.ParseInt(r.FormValue("after"), 10, 0)
page := r.FormValue("page")
var waitchan <-chan time.Time
requery:
switch page {
case "atme":
honks = gethonksforme(userid, wanted)
honks = osmosis(honks, userid, false)
case "home":
honks = gethonksforuser(userid, wanted)
honks = osmosis(honks, userid, true)
default:
http.Error(w, "unknown page", http.StatusNotFound)
return
}
if len(honks) == 0 && wait > 0 {
if waitchan == nil {
waitchan = time.After(time.Duration(wait) * time.Second)
}
select {
case <-honkline:
goto requery
case <-waitchan:
}
}
reverbolate(userid, honks)
j := junk.New()
j["honks"] = honks
j.Write(w)
2019-11-07 22:50:37 +01:00
default:
http.Error(w, "unknown action", http.StatusNotFound)
2019-11-12 07:09:08 +01:00
return
2019-11-07 22:50:37 +01:00
}
}
var endoftheworld = make(chan bool)
var readyalready = make(chan bool)
func enditall() {
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
2019-11-11 06:00:05 +01:00
signal.Notify(sig, syscall.SIGTERM)
<-sig
count := 0
log.Printf("stopping...")
sendloop:
for {
select {
case endoftheworld <- true:
count++
default:
break sendloop
}
}
log.Printf("waiting...")
for i := 0; i < count; i++ {
<-readyalready
}
log.Printf("apocalypse")
os.Exit(0)
}
2019-11-12 22:27:12 +01:00
var preservehooks []func()
func serve() {
db := opendatabase()
login.Init(db)
listener, err := openListener()
if err != nil {
log.Fatal(err)
}
startBackendServer()
go enditall()
go redeliverator()
2019-11-08 21:14:11 +01:00
go tracker()
debug := false
getconfig("debug", &debug)
readviews = templates.Load(debug,
viewDir+"/views/honkpage.html",
viewDir+"/views/honkfrags.html",
viewDir+"/views/honkers.html",
viewDir+"/views/hfcs.html",
viewDir+"/views/combos.html",
viewDir+"/views/honkform.html",
viewDir+"/views/honk.html",
viewDir+"/views/account.html",
viewDir+"/views/about.html",
viewDir+"/views/funzone.html",
viewDir+"/views/login.html",
viewDir+"/views/xzone.html",
viewDir+"/views/msg.html",
viewDir+"/views/header.html",
viewDir+"/views/onts.html",
viewDir+"/views/honkpage.js",
)
if !debug {
assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"}
2019-09-19 04:17:50 +02:00
for _, s := range assets {
savedassetparams[s] = getassetparam(s)
}
}
2019-11-12 22:27:12 +01:00
for _, h := range preservehooks {
h()
}
mux := mux.NewRouter()
mux.Use(login.Checker)
2019-11-07 22:50:37 +01:00
mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler)))
posters := mux.Methods("POST").Subrouter()
getters := mux.Methods("GET").Subrouter()
getters.HandleFunc("/", homepage)
getters.HandleFunc("/home", homepage)
getters.HandleFunc("/front", homepage)
2019-10-11 02:37:03 +02:00
getters.HandleFunc("/events", homepage)
getters.HandleFunc("/robots.txt", nomoroboto)
getters.HandleFunc("/rss", showrss)
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
2019-10-29 21:00:41 +01:00
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showonehonk)
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
getters.HandleFunc("/a", avatate)
getters.HandleFunc("/o", thelistingoftheontologies)
getters.HandleFunc("/o/{name:.+}", showontology)
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe)
getters.HandleFunc("/.well-known/webfinger", fingerlicker)
2019-10-25 23:31:48 +02:00
getters.HandleFunc("/server", serveractor)
posters.HandleFunc("/server/inbox", serverinbox)
getters.HandleFunc("/style.css", serveasset)
getters.HandleFunc("/local.css", serveasset)
2019-09-19 04:17:50 +02:00
getters.HandleFunc("/honkpage.js", serveasset)
getters.HandleFunc("/about", servehtml)
getters.HandleFunc("/login", servehtml)
posters.HandleFunc("/dologin", login.LoginFunc)
getters.HandleFunc("/logout", login.LogoutFunc)
2019-10-07 07:25:41 +02:00
getters.HandleFunc("/help/{name:[[:alnum:]_.-]+}", servehelp)
loggedin := mux.NewRoute().Subrouter()
loggedin.Use(login.Required)
2019-10-11 16:35:54 +02:00
loggedin.HandleFunc("/first", homepage)
2019-10-11 22:03:17 +02:00
loggedin.HandleFunc("/saved", homepage)
loggedin.HandleFunc("/account", accountpage)
loggedin.HandleFunc("/funzone", showfunzone)
loggedin.HandleFunc("/chpass", dochpass)
loggedin.HandleFunc("/atme", homepage)
2019-10-07 02:26:21 +02:00
loggedin.HandleFunc("/hfcs", hfcspage)
loggedin.HandleFunc("/xzone", xzone)
loggedin.HandleFunc("/newhonk", newhonkpage)
2019-09-17 00:00:13 +02:00
loggedin.HandleFunc("/edit", edithonkpage)
2019-11-11 01:33:40 +01:00
loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitwebhonk)))
2019-09-11 22:20:22 +02:00
loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk)))
loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
2019-10-07 02:26:21 +02:00
loggedin.Handle("/savehfcs", login.CSRFWrap("filter", http.HandlerFunc(savehfcs)))
loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
loggedin.HandleFunc("/honkers", showhonkers)
2019-09-19 00:30:04 +02:00
loggedin.HandleFunc("/h/{name:[[:alnum:]_.-]+}", showhonker)
loggedin.HandleFunc("/h", showhonker)
2019-09-19 00:30:04 +02:00
loggedin.HandleFunc("/c/{name:[[:alnum:]_.-]+}", showcombo)
loggedin.HandleFunc("/c", showcombos)
loggedin.HandleFunc("/t", showconvoy)
loggedin.HandleFunc("/q", showsearch)
2019-09-16 21:15:32 +02:00
loggedin.HandleFunc("/hydra", webhydra)
2019-09-11 22:20:22 +02:00
loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
err = http.Serve(listener, mux)
if err != nil {
log.Fatal(err)
}
}