all repos — honk @ d7f4297dae03a4fa6097da17c7ea1d5b15eac4a7

my fork of honk

web.go (view raw)

   1//
   2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
   3//
   4// Permission to use, copy, modify, and distribute this software for any
   5// purpose with or without fee is hereby granted, provided that the above
   6// copyright notice and this permission notice appear in all copies.
   7//
   8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15
  16package main
  17
  18import (
  19	"bytes"
  20	"fmt"
  21	"html"
  22	"html/template"
  23	"io"
  24	"io/ioutil"
  25	"log"
  26	notrand "math/rand"
  27	"net/http"
  28	"net/url"
  29	"os"
  30	"sort"
  31	"strconv"
  32	"strings"
  33	"time"
  34
  35	"github.com/gorilla/mux"
  36	"humungus.tedunangst.com/r/webs/css"
  37	"humungus.tedunangst.com/r/webs/htfilter"
  38	"humungus.tedunangst.com/r/webs/httpsig"
  39	"humungus.tedunangst.com/r/webs/image"
  40	"humungus.tedunangst.com/r/webs/junk"
  41	"humungus.tedunangst.com/r/webs/login"
  42	"humungus.tedunangst.com/r/webs/rss"
  43	"humungus.tedunangst.com/r/webs/templates"
  44)
  45
  46var readviews *templates.Template
  47
  48var userSep = "u"
  49var honkSep = "h"
  50
  51var donotfedafterdark = make(map[string]bool)
  52
  53func stealthed(r *http.Request) bool {
  54	addr := r.Header.Get("X-Forwarded-For")
  55	fake := donotfedafterdark[addr]
  56	if fake {
  57		log.Printf("faking 404 for %s", addr)
  58	}
  59	return fake
  60}
  61
  62func getuserstyle(u *login.UserInfo) template.CSS {
  63	if u == nil {
  64		return ""
  65	}
  66	user, _ := butwhatabout(u.Username)
  67	if user.SkinnyCSS {
  68		return "main { max-width: 700px; }"
  69	}
  70	return ""
  71}
  72
  73func getInfo(r *http.Request) map[string]interface{} {
  74	u := login.GetUserInfo(r)
  75	templinfo := make(map[string]interface{})
  76	templinfo["StyleParam"] = getstyleparam("views/style.css")
  77	templinfo["LocalStyleParam"] = getstyleparam("views/local.css")
  78	templinfo["UserStyle"] = getuserstyle(u)
  79	templinfo["ServerName"] = serverName
  80	templinfo["IconName"] = iconName
  81	templinfo["UserInfo"] = u
  82	templinfo["UserSep"] = userSep
  83	return templinfo
  84}
  85
  86func homepage(w http.ResponseWriter, r *http.Request) {
  87	templinfo := getInfo(r)
  88	u := login.GetUserInfo(r)
  89	var honks []*Honk
  90	var userid int64 = -1
  91	if r.URL.Path == "/front" || u == nil {
  92		honks = getpublichonks()
  93	} else {
  94		userid = u.UserID
  95		if r.URL.Path == "/atme" {
  96			templinfo["PageName"] = "atme"
  97			honks = gethonksforme(userid)
  98		} else {
  99			templinfo["PageName"] = "home"
 100			honks = gethonksforuser(userid)
 101			honks = osmosis(honks, userid)
 102		}
 103		if len(honks) > 0 {
 104			templinfo["TopXID"] = honks[0].XID
 105		}
 106		templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
 107	}
 108
 109	tname := "honkpage.html"
 110	if topxid := r.FormValue("topxid"); topxid != "" {
 111		for i, h := range honks {
 112			if h.XID == topxid {
 113				honks = honks[0:i]
 114				break
 115			}
 116		}
 117		log.Printf("topxid %d frags", len(honks))
 118		tname = "honkfrags.html"
 119	}
 120
 121	reverbolate(userid, honks)
 122
 123	templinfo["Honks"] = honks
 124	templinfo["ShowRSS"] = true
 125	templinfo["ServerMessage"] = serverMsg
 126	if u == nil {
 127		w.Header().Set("Cache-Control", "max-age=60")
 128	} else {
 129		w.Header().Set("Cache-Control", "max-age=0")
 130	}
 131	w.Header().Set("Content-Type", "text/html; charset=utf-8")
 132
 133	err := readviews.Execute(w, tname, templinfo)
 134	if err != nil {
 135		log.Print(err)
 136	}
 137}
 138
 139func showfunzone(w http.ResponseWriter, r *http.Request) {
 140	var emunames, memenames []string
 141	dir, err := os.Open("emus")
 142	if err == nil {
 143		emunames, _ = dir.Readdirnames(0)
 144		dir.Close()
 145	}
 146	for i, e := range emunames {
 147		if len(e) > 4 {
 148			emunames[i] = e[:len(e)-4]
 149		}
 150	}
 151	dir, err = os.Open("memes")
 152	if err == nil {
 153		memenames, _ = dir.Readdirnames(0)
 154		dir.Close()
 155	}
 156	templinfo := getInfo(r)
 157	templinfo["Emus"] = emunames
 158	templinfo["Memes"] = memenames
 159	err = readviews.Execute(w, "funzone.html", templinfo)
 160	if err != nil {
 161		log.Print(err)
 162	}
 163
 164}
 165
 166func showrss(w http.ResponseWriter, r *http.Request) {
 167	name := mux.Vars(r)["name"]
 168
 169	var honks []*Honk
 170	if name != "" {
 171		honks = gethonksbyuser(name, false)
 172	} else {
 173		honks = getpublichonks()
 174	}
 175	if len(honks) > 20 {
 176		honks = honks[0:20]
 177	}
 178	reverbolate(-1, honks)
 179
 180	home := fmt.Sprintf("https://%s/", serverName)
 181	base := home
 182	if name != "" {
 183		home += "u/" + name
 184		name += " "
 185	}
 186	feed := rss.Feed{
 187		Title:       name + "honk",
 188		Link:        home,
 189		Description: name + "honk rss",
 190		Image: &rss.Image{
 191			URL:   base + "icon.png",
 192			Title: name + "honk rss",
 193			Link:  home,
 194		},
 195	}
 196	var modtime time.Time
 197	for _, honk := range honks {
 198		if !firstclass(honk) {
 199			continue
 200		}
 201		desc := string(honk.HTML)
 202		for _, d := range honk.Donks {
 203			desc += fmt.Sprintf(`<p><a href="%s">Attachment: %s</a>`,
 204				d.URL, html.EscapeString(d.Name))
 205		}
 206
 207		feed.Items = append(feed.Items, &rss.Item{
 208			Title:       fmt.Sprintf("%s %s %s", honk.Username, honk.What, honk.XID),
 209			Description: rss.CData{desc},
 210			Link:        honk.URL,
 211			PubDate:     honk.Date.Format(time.RFC1123),
 212			Guid:        &rss.Guid{IsPermaLink: true, Value: honk.URL},
 213		})
 214		if honk.Date.After(modtime) {
 215			modtime = honk.Date
 216		}
 217	}
 218	w.Header().Set("Cache-Control", "max-age=300")
 219	w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat))
 220
 221	err := feed.Write(w)
 222	if err != nil {
 223		log.Printf("error writing rss: %s", err)
 224	}
 225}
 226
 227func crappola(j junk.Junk) bool {
 228	t, _ := j.GetString("type")
 229	a, _ := j.GetString("actor")
 230	o, _ := j.GetString("object")
 231	if t == "Delete" && a == o {
 232		log.Printf("crappola from %s", a)
 233		return true
 234	}
 235	return false
 236}
 237
 238func ping(user *WhatAbout, who string) {
 239	box, err := getboxes(who)
 240	if err != nil {
 241		log.Printf("no inbox for ping: %s", err)
 242		return
 243	}
 244	j := junk.New()
 245	j["@context"] = itiswhatitis
 246	j["type"] = "Ping"
 247	j["id"] = user.URL + "/ping/" + xfiltrate()
 248	j["actor"] = user.URL
 249	j["to"] = who
 250	keyname, key := ziggy(user.Name)
 251	err = PostJunk(keyname, key, box.In, j)
 252	if err != nil {
 253		log.Printf("can't send ping: %s", err)
 254		return
 255	}
 256	log.Printf("sent ping to %s: %s", who, j["id"])
 257}
 258
 259func pong(user *WhatAbout, who string, obj string) {
 260	box, err := getboxes(who)
 261	if err != nil {
 262		log.Printf("no inbox for pong %s : %s", who, err)
 263		return
 264	}
 265	j := junk.New()
 266	j["@context"] = itiswhatitis
 267	j["type"] = "Pong"
 268	j["id"] = user.URL + "/pong/" + xfiltrate()
 269	j["actor"] = user.URL
 270	j["to"] = who
 271	j["object"] = obj
 272	keyname, key := ziggy(user.Name)
 273	err = PostJunk(keyname, key, box.In, j)
 274	if err != nil {
 275		log.Printf("can't send pong: %s", err)
 276		return
 277	}
 278}
 279
 280func inbox(w http.ResponseWriter, r *http.Request) {
 281	name := mux.Vars(r)["name"]
 282	user, err := butwhatabout(name)
 283	if err != nil {
 284		http.NotFound(w, r)
 285		return
 286	}
 287	var buf bytes.Buffer
 288	io.Copy(&buf, r.Body)
 289	payload := buf.Bytes()
 290	j, err := junk.Read(bytes.NewReader(payload))
 291	if err != nil {
 292		log.Printf("bad payload: %s", err)
 293		io.WriteString(os.Stdout, "bad payload\n")
 294		os.Stdout.Write(payload)
 295		io.WriteString(os.Stdout, "\n")
 296		return
 297	}
 298	if crappola(j) {
 299		return
 300	}
 301	keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
 302	if err != nil {
 303		log.Printf("inbox message failed signature: %s", err)
 304		if keyname != "" {
 305			keyname, err = makeitworksomehowwithoutregardforkeycontinuity(keyname, r, payload)
 306			if err != nil {
 307				log.Printf("still failed: %s", err)
 308			}
 309		}
 310		if err != nil {
 311			return
 312		}
 313	}
 314	what, _ := j.GetString("type")
 315	if what == "Like" {
 316		return
 317	}
 318	who, _ := j.GetString("actor")
 319	origin := keymatch(keyname, who)
 320	if origin == "" {
 321		log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
 322		return
 323	}
 324	objid, _ := j.GetString("id")
 325	if thoudostbitethythumb(user.ID, []string{who}, objid) {
 326		log.Printf("ignoring thumb sucker %s", who)
 327		return
 328	}
 329	switch what {
 330	case "Ping":
 331		obj, _ := j.GetString("id")
 332		log.Printf("ping from %s: %s", who, obj)
 333		pong(user, who, obj)
 334	case "Pong":
 335		obj, _ := j.GetString("object")
 336		log.Printf("pong from %s: %s", who, obj)
 337	case "Follow":
 338		obj, _ := j.GetString("object")
 339		if obj == user.URL {
 340			log.Printf("updating honker follow: %s", who)
 341			stmtSaveDub.Exec(user.ID, who, who, "dub")
 342			go rubadubdub(user, j)
 343		} else {
 344			log.Printf("can't follow %s", obj)
 345		}
 346	case "Accept":
 347		log.Printf("updating honker accept: %s", who)
 348		_, err = stmtUpdateFlavor.Exec("sub", user.ID, who, "presub")
 349		if err != nil {
 350			log.Printf("error updating honker: %s", err)
 351			return
 352		}
 353	case "Update":
 354		obj, ok := j.GetMap("object")
 355		if ok {
 356			what, _ := obj.GetString("type")
 357			switch what {
 358			case "Person":
 359				return
 360			case "Question":
 361				return
 362			}
 363		}
 364		log.Printf("unknown Update activity")
 365		fd, _ := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
 366		j.Write(fd)
 367		io.WriteString(fd, "\n")
 368		fd.Close()
 369
 370	case "Undo":
 371		obj, ok := j.GetMap("object")
 372		if !ok {
 373			log.Printf("unknown undo no object")
 374		} else {
 375			what, _ := obj.GetString("type")
 376			switch what {
 377			case "Follow":
 378				log.Printf("updating honker undo: %s", who)
 379				_, err = stmtUpdateFlavor.Exec("undub", user.ID, who, "dub")
 380				if err != nil {
 381					log.Printf("error updating honker: %s", err)
 382					return
 383				}
 384			case "Announce":
 385				xid, _ := obj.GetString("object")
 386				log.Printf("undo announce: %s", xid)
 387			case "Like":
 388			default:
 389				log.Printf("unknown undo: %s", what)
 390			}
 391		}
 392	default:
 393		go consumeactivity(user, j, origin)
 394	}
 395}
 396
 397func ximport(w http.ResponseWriter, r *http.Request) {
 398	xid := r.FormValue("xid")
 399	p, _ := investigate(xid)
 400	if p != nil {
 401		xid = p.XID
 402	}
 403	j, err := GetJunk(xid)
 404	if err != nil {
 405		http.Error(w, "error getting external object", http.StatusInternalServerError)
 406		log.Printf("error getting external object: %s", err)
 407		return
 408	}
 409	log.Printf("importing %s", xid)
 410	u := login.GetUserInfo(r)
 411	user, _ := butwhatabout(u.Username)
 412
 413	what, _ := j.GetString("type")
 414	if isactor(what) {
 415		outbox, _ := j.GetString("outbox")
 416		gimmexonks(user, outbox)
 417		http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther)
 418		return
 419	}
 420	xonk := xonkxonk(user, j, originate(xid))
 421	convoy := ""
 422	if xonk != nil {
 423		convoy = xonk.Convoy
 424		savexonk(xonk)
 425	}
 426	http.Redirect(w, r, "/t?c="+url.QueryEscape(convoy), http.StatusSeeOther)
 427}
 428
 429func xzone(w http.ResponseWriter, r *http.Request) {
 430	u := login.GetUserInfo(r)
 431	rows, err := stmtRecentHonkers.Query(u.UserID, u.UserID)
 432	if err != nil {
 433		log.Printf("query err: %s", err)
 434		return
 435	}
 436	defer rows.Close()
 437	var honkers []Honker
 438	for rows.Next() {
 439		var xid string
 440		rows.Scan(&xid)
 441		honkers = append(honkers, Honker{XID: xid})
 442	}
 443	rows.Close()
 444	for i, _ := range honkers {
 445		_, honkers[i].Handle = handles(honkers[i].XID)
 446	}
 447	templinfo := getInfo(r)
 448	templinfo["XCSRF"] = login.GetCSRF("ximport", r)
 449	templinfo["Honkers"] = honkers
 450	err = readviews.Execute(w, "xzone.html", templinfo)
 451	if err != nil {
 452		log.Print(err)
 453	}
 454}
 455
 456func outbox(w http.ResponseWriter, r *http.Request) {
 457	name := mux.Vars(r)["name"]
 458	user, err := butwhatabout(name)
 459	if err != nil {
 460		http.NotFound(w, r)
 461		return
 462	}
 463	if stealthed(r) {
 464		http.NotFound(w, r)
 465		return
 466	}
 467
 468	honks := gethonksbyuser(name, false)
 469	if len(honks) > 20 {
 470		honks = honks[0:20]
 471	}
 472
 473	var jonks []junk.Junk
 474	for _, h := range honks {
 475		j, _ := jonkjonk(user, h)
 476		jonks = append(jonks, j)
 477	}
 478
 479	j := junk.New()
 480	j["@context"] = itiswhatitis
 481	j["id"] = user.URL + "/outbox"
 482	j["type"] = "OrderedCollection"
 483	j["totalItems"] = len(jonks)
 484	j["orderedItems"] = jonks
 485
 486	w.Header().Set("Content-Type", theonetruename)
 487	j.Write(w)
 488}
 489
 490func emptiness(w http.ResponseWriter, r *http.Request) {
 491	name := mux.Vars(r)["name"]
 492	user, err := butwhatabout(name)
 493	if err != nil {
 494		http.NotFound(w, r)
 495		return
 496	}
 497	colname := "/followers"
 498	if strings.HasSuffix(r.URL.Path, "/following") {
 499		colname = "/following"
 500	}
 501	j := junk.New()
 502	j["@context"] = itiswhatitis
 503	j["id"] = user.URL + colname
 504	j["type"] = "OrderedCollection"
 505	j["totalItems"] = 0
 506	j["orderedItems"] = []junk.Junk{}
 507
 508	w.Header().Set("Content-Type", theonetruename)
 509	j.Write(w)
 510}
 511
 512func showuser(w http.ResponseWriter, r *http.Request) {
 513	name := mux.Vars(r)["name"]
 514	user, err := butwhatabout(name)
 515	if err != nil {
 516		log.Printf("user not found %s: %s", name, err)
 517		http.NotFound(w, r)
 518		return
 519	}
 520	if friendorfoe(r.Header.Get("Accept")) {
 521		j := asjonker(user)
 522		w.Header().Set("Content-Type", theonetruename)
 523		j.Write(w)
 524		return
 525	}
 526	u := login.GetUserInfo(r)
 527	honks := gethonksbyuser(name, u != nil && u.Username == name)
 528	honkpage(w, r, u, user, honks, "")
 529}
 530
 531func showhonker(w http.ResponseWriter, r *http.Request) {
 532	u := login.GetUserInfo(r)
 533	name := mux.Vars(r)["name"]
 534	var honks []*Honk
 535	if name == "" {
 536		name = r.FormValue("xid")
 537		honks = gethonksbyxonker(u.UserID, name)
 538	} else {
 539		honks = gethonksbyhonker(u.UserID, name)
 540	}
 541	name = html.EscapeString(name)
 542	msg := fmt.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, name, name)
 543	honkpage(w, r, u, nil, honks, template.HTML(msg))
 544}
 545
 546func showcombo(w http.ResponseWriter, r *http.Request) {
 547	name := mux.Vars(r)["name"]
 548	u := login.GetUserInfo(r)
 549	honks := gethonksbycombo(u.UserID, name)
 550	honks = osmosis(honks, u.UserID)
 551	honkpage(w, r, u, nil, honks, template.HTML(html.EscapeString("honks by combo: "+name)))
 552}
 553func showconvoy(w http.ResponseWriter, r *http.Request) {
 554	c := r.FormValue("c")
 555	u := login.GetUserInfo(r)
 556	honks := gethonksbyconvoy(u.UserID, c)
 557	honkpage(w, r, u, nil, honks, template.HTML(html.EscapeString("honks in convoy: "+c)))
 558}
 559func showsearch(w http.ResponseWriter, r *http.Request) {
 560	q := r.FormValue("q")
 561	u := login.GetUserInfo(r)
 562	honks := gethonksbysearch(u.UserID, q)
 563	honkpage(w, r, u, nil, honks, template.HTML(html.EscapeString("honks for search: "+q)))
 564}
 565func showontology(w http.ResponseWriter, r *http.Request) {
 566	name := mux.Vars(r)["name"]
 567	u := login.GetUserInfo(r)
 568	var userid int64 = -1
 569	if u != nil {
 570		userid = u.UserID
 571	}
 572	honks := gethonksbyontology(userid, "#"+name)
 573	honkpage(w, r, u, nil, honks, template.HTML(html.EscapeString("honks by ontology: "+name)))
 574}
 575
 576func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
 577	u := login.GetUserInfo(r)
 578	var userid int64 = -1
 579	if u != nil {
 580		userid = u.UserID
 581	}
 582	rows, err := stmtSelectOnts.Query(userid)
 583	if err != nil {
 584		log.Printf("selection error: %s", err)
 585		return
 586	}
 587	var onts [][]string
 588	for rows.Next() {
 589		var o string
 590		err := rows.Scan(&o)
 591		if err != nil {
 592			log.Printf("error scanning ont: %s", err)
 593			continue
 594		}
 595		onts = append(onts, []string{o, o[1:]})
 596	}
 597	if u == nil {
 598		w.Header().Set("Cache-Control", "max-age=300")
 599	}
 600	templinfo := getInfo(r)
 601	templinfo["Onts"] = onts
 602	err = readviews.Execute(w, "onts.html", templinfo)
 603	if err != nil {
 604		log.Print(err)
 605	}
 606}
 607
 608func showhonk(w http.ResponseWriter, r *http.Request) {
 609	name := mux.Vars(r)["name"]
 610	user, err := butwhatabout(name)
 611	if err != nil {
 612		http.NotFound(w, r)
 613		return
 614	}
 615	if stealthed(r) {
 616		http.NotFound(w, r)
 617		return
 618	}
 619
 620	xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path)
 621	honk := getxonk(user.ID, xid)
 622	if honk == nil {
 623		http.NotFound(w, r)
 624		return
 625	}
 626	u := login.GetUserInfo(r)
 627	if u != nil && u.UserID != user.ID {
 628		u = nil
 629	}
 630	if !honk.Public {
 631		if u == nil {
 632			http.NotFound(w, r)
 633			return
 634
 635		}
 636		honkpage(w, r, u, nil, []*Honk{honk}, "one honk maybe more")
 637		return
 638	}
 639	rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy)
 640	if friendorfoe(r.Header.Get("Accept")) {
 641		for _, h := range rawhonks {
 642			if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) {
 643				honk.Replies = append(honk.Replies, h)
 644			}
 645		}
 646		donksforhonks([]*Honk{honk})
 647		_, j := jonkjonk(user, honk)
 648		j["@context"] = itiswhatitis
 649		w.Header().Set("Content-Type", theonetruename)
 650		j.Write(w)
 651		return
 652	}
 653	var honks []*Honk
 654	for _, h := range rawhonks {
 655		if h.Public && (h.Whofore == 2 || h.IsAcked()) {
 656			honks = append(honks, h)
 657		}
 658	}
 659
 660	honkpage(w, r, u, nil, honks, "one honk maybe more")
 661}
 662
 663func honkpage(w http.ResponseWriter, r *http.Request, u *login.UserInfo, user *WhatAbout,
 664	honks []*Honk, infomsg template.HTML) {
 665	templinfo := getInfo(r)
 666	var userid int64 = -1
 667	if u != nil {
 668		templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
 669		userid = u.UserID
 670	}
 671	if u == nil {
 672		w.Header().Set("Cache-Control", "max-age=60")
 673	}
 674	reverbolate(userid, honks)
 675	if user != nil {
 676		filt := htfilter.New()
 677		templinfo["Name"] = user.Name
 678		whatabout := user.About
 679		whatabout = obfusbreak(user.About)
 680		templinfo["WhatAbout"], _ = filt.String(whatabout)
 681	}
 682	templinfo["Honks"] = honks
 683	templinfo["ServerMessage"] = infomsg
 684	err := readviews.Execute(w, "honkpage.html", templinfo)
 685	if err != nil {
 686		log.Print(err)
 687	}
 688}
 689
 690func saveuser(w http.ResponseWriter, r *http.Request) {
 691	whatabout := r.FormValue("whatabout")
 692	u := login.GetUserInfo(r)
 693	db := opendatabase()
 694	options := ""
 695	if r.FormValue("skinny") == "skinny" {
 696		options += " skinny "
 697	}
 698	_, err := db.Exec("update users set about = ?, options = ? where username = ?", whatabout, options, u.Username)
 699	if err != nil {
 700		log.Printf("error bouting what: %s", err)
 701	}
 702
 703	http.Redirect(w, r, "/account", http.StatusSeeOther)
 704}
 705
 706func submitbonk(w http.ResponseWriter, r *http.Request) {
 707	xid := r.FormValue("xid")
 708	userinfo := login.GetUserInfo(r)
 709	user, _ := butwhatabout(userinfo.Username)
 710
 711	log.Printf("bonking %s", xid)
 712
 713	xonk := getxonk(userinfo.UserID, xid)
 714	if xonk == nil {
 715		return
 716	}
 717	if !xonk.Public {
 718		return
 719	}
 720	donksforhonks([]*Honk{xonk})
 721
 722	_, err := stmtUpdateFlags.Exec(flagIsBonked, xonk.ID)
 723	if err != nil {
 724		log.Printf("error acking bonk: %s", err)
 725	}
 726
 727	oonker := xonk.Oonker
 728	if oonker == "" {
 729		oonker = xonk.Honker
 730	}
 731	dt := time.Now().UTC()
 732	bonk := Honk{
 733		UserID:   userinfo.UserID,
 734		Username: userinfo.Username,
 735		What:     "bonk",
 736		Honker:   user.URL,
 737		Oonker:   oonker,
 738		XID:      xonk.XID,
 739		RID:      xonk.RID,
 740		Noise:    xonk.Noise,
 741		Precis:   xonk.Precis,
 742		URL:      xonk.URL,
 743		Date:     dt,
 744		Donks:    xonk.Donks,
 745		Whofore:  2,
 746		Convoy:   xonk.Convoy,
 747		Audience: []string{thewholeworld, oonker},
 748		Public:   true,
 749	}
 750
 751	bonk.Format = "html"
 752
 753	err = savehonk(&bonk)
 754	if err != nil {
 755		log.Printf("uh oh")
 756		return
 757	}
 758
 759	go honkworldwide(user, &bonk)
 760}
 761
 762func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string) {
 763	zonk := Honk{
 764		What:     what,
 765		XID:      xonk.XID,
 766		Date:     time.Now().UTC(),
 767		Audience: oneofakind(xonk.Audience),
 768	}
 769	zonk.Public = !keepitquiet(zonk.Audience)
 770
 771	log.Printf("announcing %sed honk: %s", what, xonk.XID)
 772	go honkworldwide(user, &zonk)
 773}
 774
 775func zonkit(w http.ResponseWriter, r *http.Request) {
 776	wherefore := r.FormValue("wherefore")
 777	what := r.FormValue("what")
 778	userinfo := login.GetUserInfo(r)
 779	user, _ := butwhatabout(userinfo.Username)
 780
 781	if wherefore == "ack" {
 782		xonk := getxonk(userinfo.UserID, what)
 783		if xonk != nil {
 784			_, err := stmtUpdateFlags.Exec(flagIsAcked, xonk.ID)
 785			if err != nil {
 786				log.Printf("error acking: %s", err)
 787			}
 788			sendzonkofsorts(xonk, user, "ack")
 789		}
 790		return
 791	}
 792
 793	if wherefore == "deack" {
 794		xonk := getxonk(userinfo.UserID, what)
 795		if xonk != nil {
 796			_, err := stmtClearFlags.Exec(flagIsAcked, xonk.ID)
 797			if err != nil {
 798				log.Printf("error deacking: %s", err)
 799			}
 800			sendzonkofsorts(xonk, user, "deack")
 801		}
 802		return
 803	}
 804
 805	if wherefore == "unbonk" {
 806		xonk := getbonk(userinfo.UserID, what)
 807		if xonk != nil {
 808			_, err := stmtZonkDonks.Exec(xonk.ID)
 809			if err != nil {
 810				log.Printf("error zonking: %s", err)
 811			}
 812			_, err = stmtZonkIt.Exec(xonk.ID)
 813			if err != nil {
 814				log.Printf("error zonking: %s", err)
 815			}
 816			xonk = getxonk(userinfo.UserID, what)
 817			_, err = stmtClearFlags.Exec(flagIsBonked, xonk.ID)
 818			if err != nil {
 819				log.Printf("error unbonking: %s", err)
 820			}
 821			sendzonkofsorts(xonk, user, "unbonk")
 822		}
 823		return
 824	}
 825
 826	log.Printf("zonking %s %s", wherefore, what)
 827	if wherefore == "zonk" {
 828		xonk := getxonk(userinfo.UserID, what)
 829		if xonk != nil {
 830			_, err := stmtZonkDonks.Exec(xonk.ID)
 831			if err != nil {
 832				log.Printf("error zonking: %s", err)
 833			}
 834			_, err = stmtZonkIt.Exec(xonk.ID)
 835			if err != nil {
 836				log.Printf("error zonking: %s", err)
 837			}
 838			if xonk.Whofore == 2 || xonk.Whofore == 3 {
 839				sendzonkofsorts(xonk, user, "zonk")
 840			}
 841		}
 842	}
 843	_, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
 844	if err != nil {
 845		log.Printf("error saving zonker: %s", err)
 846		return
 847	}
 848}
 849
 850func submithonk(w http.ResponseWriter, r *http.Request) {
 851	rid := r.FormValue("rid")
 852	noise := r.FormValue("noise")
 853
 854	userinfo := login.GetUserInfo(r)
 855	user, _ := butwhatabout(userinfo.Username)
 856
 857	dt := time.Now().UTC()
 858	xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
 859	what := "honk"
 860	if rid != "" {
 861		what = "tonk"
 862	}
 863	honk := Honk{
 864		UserID:   userinfo.UserID,
 865		Username: userinfo.Username,
 866		What:     "honk",
 867		Honker:   user.URL,
 868		XID:      xid,
 869		Date:     dt,
 870	}
 871	if strings.HasPrefix(noise, "DZ:") {
 872		idx := strings.Index(noise, "\n")
 873		if idx == -1 {
 874			honk.Precis = noise
 875			noise = ""
 876		} else {
 877			honk.Precis = noise[:idx]
 878			noise = noise[idx+1:]
 879		}
 880	}
 881	noise = quickrename(noise, userinfo.UserID)
 882	noise = hooterize(noise)
 883	noise = strings.TrimSpace(noise)
 884	honk.Precis = strings.TrimSpace(honk.Precis)
 885
 886	var convoy string
 887	if rid != "" {
 888		xonk := getxonk(userinfo.UserID, rid)
 889		if xonk != nil {
 890			if xonk.Public {
 891				honk.Audience = append(honk.Audience, xonk.Audience...)
 892			}
 893			convoy = xonk.Convoy
 894		} else {
 895			xonkaud, c := whosthere(rid)
 896			honk.Audience = append(honk.Audience, xonkaud...)
 897			convoy = c
 898		}
 899		for i, a := range honk.Audience {
 900			if a == thewholeworld {
 901				honk.Audience[0], honk.Audience[i] = honk.Audience[i], honk.Audience[0]
 902				break
 903			}
 904		}
 905		honk.RID = rid
 906	} else {
 907		honk.Audience = []string{thewholeworld}
 908	}
 909	if noise != "" && noise[0] == '@' {
 910		honk.Audience = append(grapevine(noise), honk.Audience...)
 911	} else {
 912		honk.Audience = append(honk.Audience, grapevine(noise)...)
 913	}
 914	if convoy == "" {
 915		convoy = "data:,electrichonkytonk-" + xfiltrate()
 916	}
 917	butnottooloud(honk.Audience)
 918	honk.Audience = oneofakind(honk.Audience)
 919	if len(honk.Audience) == 0 {
 920		log.Printf("honk to nowhere")
 921		http.Error(w, "honk to nowhere...", http.StatusNotFound)
 922		return
 923	}
 924	honk.Public = !keepitquiet(honk.Audience)
 925	noise = obfusbreak(noise)
 926	honk.Noise = noise
 927	honk.Convoy = convoy
 928
 929	donkxid := r.FormValue("donkxid")
 930	if donkxid == "" {
 931		file, filehdr, err := r.FormFile("donk")
 932		if err == nil {
 933			var buf bytes.Buffer
 934			io.Copy(&buf, file)
 935			file.Close()
 936			data := buf.Bytes()
 937			xid := xfiltrate()
 938			var media, name string
 939			img, err := image.Vacuum(&buf, image.Params{MaxWidth: 2048, MaxHeight: 2048})
 940			if err == nil {
 941				data = img.Data
 942				format := img.Format
 943				media = "image/" + format
 944				if format == "jpeg" {
 945					format = "jpg"
 946				}
 947				name = xid + "." + format
 948				xid = name
 949			} else {
 950				maxsize := 100000
 951				if len(data) > maxsize {
 952					log.Printf("bad image: %s too much text: %d", err, len(data))
 953					http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
 954					return
 955				}
 956				for i := 0; i < len(data); i++ {
 957					if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' {
 958						log.Printf("bad image: %s not text: %d", err, data[i])
 959						http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
 960						return
 961					}
 962				}
 963				media = "text/plain"
 964				name = filehdr.Filename
 965				if name == "" {
 966					name = xid + ".txt"
 967				}
 968				xid += ".txt"
 969			}
 970			desc := r.FormValue("donkdesc")
 971			if desc == "" {
 972				desc = name
 973			}
 974			url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
 975			res, err := stmtSaveFile.Exec(xid, name, desc, url, media, 1, data)
 976			if err != nil {
 977				log.Printf("unable to save image: %s", err)
 978				return
 979			}
 980			var d Donk
 981			d.FileID, _ = res.LastInsertId()
 982			honk.Donks = append(honk.Donks, &d)
 983			donkxid = d.XID
 984		}
 985	} else {
 986		xid := donkxid
 987		url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
 988		var donk Donk
 989		row := stmtFindFile.QueryRow(url)
 990		err := row.Scan(&donk.FileID)
 991		if err == nil {
 992			honk.Donks = append(honk.Donks, &donk)
 993		} else {
 994			log.Printf("can't find file: %s", xid)
 995		}
 996	}
 997	herd := herdofemus(honk.Noise)
 998	for _, e := range herd {
 999		donk := savedonk(e.ID, e.Name, e.Name, "image/png", true)
1000		if donk != nil {
1001			donk.Name = e.Name
1002			honk.Donks = append(honk.Donks, donk)
1003		}
1004	}
1005	memetize(&honk)
1006
1007	if honk.Public {
1008		honk.Whofore = 2
1009	} else {
1010		honk.Whofore = 3
1011	}
1012	if r.FormValue("preview") == "preview" {
1013		honks := []*Honk{&honk}
1014		reverbolate(userinfo.UserID, honks)
1015		templinfo := getInfo(r)
1016		templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1017		templinfo["Honks"] = honks
1018		templinfo["InReplyTo"] = r.FormValue("rid")
1019		templinfo["Noise"] = r.FormValue("noise")
1020		templinfo["SavedFile"] = donkxid
1021		templinfo["ServerMessage"] = "honk preview"
1022		err := readviews.Execute(w, "honkpage.html", templinfo)
1023		if err != nil {
1024			log.Print(err)
1025		}
1026		return
1027	}
1028	honk.Onts = oneofakind(ontologies(honk.Noise))
1029	honk.UserID = userinfo.UserID
1030	honk.What = what
1031	honk.XID = xid
1032	honk.RID = rid
1033	honk.Date = dt
1034	honk.Convoy = convoy
1035	honk.Format = "html"
1036
1037	err := savehonk(&honk)
1038	if err != nil {
1039		log.Printf("uh oh")
1040		return
1041	}
1042
1043	// reload for consistency
1044	honk.Donks = nil
1045	donksforhonks([]*Honk{&honk})
1046
1047	go honkworldwide(user, &honk)
1048
1049	http.Redirect(w, r, xid, http.StatusSeeOther)
1050}
1051
1052func showhonkers(w http.ResponseWriter, r *http.Request) {
1053	userinfo := login.GetUserInfo(r)
1054	templinfo := getInfo(r)
1055	templinfo["Honkers"] = gethonkers(userinfo.UserID)
1056	templinfo["HonkerCSRF"] = login.GetCSRF("submithonker", r)
1057	err := readviews.Execute(w, "honkers.html", templinfo)
1058	if err != nil {
1059		log.Print(err)
1060	}
1061}
1062
1063func showcombos(w http.ResponseWriter, r *http.Request) {
1064	userinfo := login.GetUserInfo(r)
1065	templinfo := getInfo(r)
1066	honkers := gethonkers(userinfo.UserID)
1067	var combos []string
1068	for _, h := range honkers {
1069		combos = append(combos, h.Combos...)
1070	}
1071	for i, c := range combos {
1072		if c == "-" {
1073			combos[i] = ""
1074		}
1075	}
1076	combos = oneofakind(combos)
1077	sort.Strings(combos)
1078	templinfo["Combos"] = combos
1079	err := readviews.Execute(w, "combos.html", templinfo)
1080	if err != nil {
1081		log.Print(err)
1082	}
1083}
1084
1085func submithonker(w http.ResponseWriter, r *http.Request) {
1086	u := login.GetUserInfo(r)
1087	name := r.FormValue("name")
1088	url := r.FormValue("url")
1089	peep := r.FormValue("peep")
1090	combos := r.FormValue("combos")
1091	honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
1092
1093	if honkerid > 0 {
1094		goodbye := r.FormValue("goodbye")
1095		if goodbye == "F" {
1096			db := opendatabase()
1097			row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?",
1098				honkerid, u.UserID)
1099			var xid string
1100			err := row.Scan(&xid)
1101			if err != nil {
1102				log.Printf("can't get honker xid: %s", err)
1103				return
1104			}
1105			log.Printf("unsubscribing from %s", xid)
1106			user, _ := butwhatabout(u.Username)
1107			go itakeitallback(user, xid)
1108			_, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub")
1109			if err != nil {
1110				log.Printf("error updating honker: %s", err)
1111				return
1112			}
1113
1114			http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1115			return
1116		}
1117		combos = " " + strings.TrimSpace(combos) + " "
1118		_, err := stmtUpdateCombos.Exec(combos, honkerid, u.UserID)
1119		if err != nil {
1120			log.Printf("update honker err: %s", err)
1121			return
1122		}
1123		http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1124	}
1125
1126	flavor := "presub"
1127	if peep == "peep" {
1128		flavor = "peep"
1129	}
1130	p, err := investigate(url)
1131	if err != nil {
1132		http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
1133		log.Printf("failed to investigate honker")
1134		return
1135	}
1136	url = p.XID
1137	if name == "" {
1138		name = p.Handle
1139	}
1140	_, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
1141	if err != nil {
1142		log.Print(err)
1143		return
1144	}
1145	if flavor == "presub" {
1146		user, _ := butwhatabout(u.Username)
1147		go subsub(user, url)
1148	}
1149	http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1150}
1151
1152func zonkzone(w http.ResponseWriter, r *http.Request) {
1153	userinfo := login.GetUserInfo(r)
1154	rows, err := stmtGetZonkers.Query(userinfo.UserID)
1155	if err != nil {
1156		log.Printf("err: %s", err)
1157		return
1158	}
1159	defer rows.Close()
1160	var zonkers []Zonker
1161	for rows.Next() {
1162		var z Zonker
1163		rows.Scan(&z.ID, &z.Name, &z.Wherefore)
1164		zonkers = append(zonkers, z)
1165	}
1166	sort.Slice(zonkers, func(i, j int) bool {
1167		w1 := zonkers[i].Wherefore
1168		w2 := zonkers[j].Wherefore
1169		if w1 == w2 {
1170			return zonkers[i].Name < zonkers[j].Name
1171		}
1172		if w1 == "zonvoy" {
1173			w1 = "zzzzzzz"
1174		}
1175		if w2 == "zonvoy" {
1176			w2 = "zzzzzzz"
1177		}
1178		return w1 < w2
1179	})
1180
1181	templinfo := getInfo(r)
1182	templinfo["Zonkers"] = zonkers
1183	templinfo["ZonkCSRF"] = login.GetCSRF("zonkzonk", r)
1184	err = readviews.Execute(w, "zonkers.html", templinfo)
1185	if err != nil {
1186		log.Print(err)
1187	}
1188}
1189
1190func zonkzonk(w http.ResponseWriter, r *http.Request) {
1191	userinfo := login.GetUserInfo(r)
1192	itsok := r.FormValue("itsok")
1193	if itsok == "iforgiveyou" {
1194		zonkerid, _ := strconv.ParseInt(r.FormValue("zonkerid"), 10, 0)
1195		db := opendatabase()
1196		db.Exec("delete from zonkers where userid = ? and zonkerid = ?",
1197			userinfo.UserID, zonkerid)
1198		bitethethumbs()
1199		http.Redirect(w, r, "/zonkzone", http.StatusSeeOther)
1200		return
1201	}
1202	wherefore := r.FormValue("wherefore")
1203	name := r.FormValue("name")
1204	if name == "" {
1205		return
1206	}
1207	switch wherefore {
1208	case "zonker":
1209	case "zomain":
1210	case "zonvoy":
1211	case "zord":
1212	case "zilence":
1213	default:
1214		return
1215	}
1216	db := opendatabase()
1217	db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)",
1218		userinfo.UserID, name, wherefore)
1219	if wherefore == "zonker" || wherefore == "zomain" || wherefore == "zord" || wherefore == "zilence" {
1220		bitethethumbs()
1221	}
1222
1223	http.Redirect(w, r, "/zonkzone", http.StatusSeeOther)
1224}
1225
1226func accountpage(w http.ResponseWriter, r *http.Request) {
1227	u := login.GetUserInfo(r)
1228	user, _ := butwhatabout(u.Username)
1229	templinfo := getInfo(r)
1230	templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
1231	templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
1232	templinfo["User"] = user
1233	err := readviews.Execute(w, "account.html", templinfo)
1234	if err != nil {
1235		log.Print(err)
1236	}
1237}
1238
1239func dochpass(w http.ResponseWriter, r *http.Request) {
1240	err := login.ChangePassword(w, r)
1241	if err != nil {
1242		log.Printf("error changing password: %s", err)
1243	}
1244	http.Redirect(w, r, "/account", http.StatusSeeOther)
1245}
1246
1247func fingerlicker(w http.ResponseWriter, r *http.Request) {
1248	orig := r.FormValue("resource")
1249
1250	log.Printf("finger lick: %s", orig)
1251
1252	if strings.HasPrefix(orig, "acct:") {
1253		orig = orig[5:]
1254	}
1255
1256	name := orig
1257	idx := strings.LastIndexByte(name, '/')
1258	if idx != -1 {
1259		name = name[idx+1:]
1260		if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
1261			log.Printf("foreign request rejected")
1262			name = ""
1263		}
1264	} else {
1265		idx = strings.IndexByte(name, '@')
1266		if idx != -1 {
1267			name = name[:idx]
1268			if name+"@"+serverName != orig {
1269				log.Printf("foreign request rejected")
1270				name = ""
1271			}
1272		}
1273	}
1274	user, err := butwhatabout(name)
1275	if err != nil {
1276		http.NotFound(w, r)
1277		return
1278	}
1279
1280	j := junk.New()
1281	j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName)
1282	j["aliases"] = []string{user.URL}
1283	var links []junk.Junk
1284	l := junk.New()
1285	l["rel"] = "self"
1286	l["type"] = `application/activity+json`
1287	l["href"] = user.URL
1288	links = append(links, l)
1289	j["links"] = links
1290
1291	w.Header().Set("Cache-Control", "max-age=3600")
1292	w.Header().Set("Content-Type", "application/jrd+json")
1293	j.Write(w)
1294}
1295
1296func somedays() string {
1297	secs := 432000 + notrand.Int63n(432000)
1298	return fmt.Sprintf("%d", secs)
1299}
1300
1301func avatate(w http.ResponseWriter, r *http.Request) {
1302	n := r.FormValue("a")
1303	a := avatar(n)
1304	w.Header().Set("Cache-Control", "max-age="+somedays())
1305	w.Write(a)
1306}
1307
1308func servecss(w http.ResponseWriter, r *http.Request) {
1309	data, _ := ioutil.ReadFile("views" + r.URL.Path)
1310	s := css.Process(string(data))
1311	w.Header().Set("Cache-Control", "max-age=7776000")
1312	w.Header().Set("Content-Type", "text/css; charset=utf-8")
1313	w.Write([]byte(s))
1314}
1315func servehtml(w http.ResponseWriter, r *http.Request) {
1316	templinfo := getInfo(r)
1317	err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
1318	if err != nil {
1319		log.Print(err)
1320	}
1321}
1322func serveemu(w http.ResponseWriter, r *http.Request) {
1323	xid := mux.Vars(r)["xid"]
1324	w.Header().Set("Cache-Control", "max-age="+somedays())
1325	http.ServeFile(w, r, "emus/"+xid)
1326}
1327func servememe(w http.ResponseWriter, r *http.Request) {
1328	xid := mux.Vars(r)["xid"]
1329	w.Header().Set("Cache-Control", "max-age="+somedays())
1330	http.ServeFile(w, r, "memes/"+xid)
1331}
1332
1333func servefile(w http.ResponseWriter, r *http.Request) {
1334	xid := mux.Vars(r)["xid"]
1335	row := stmtFileData.QueryRow(xid)
1336	var media string
1337	var data []byte
1338	err := row.Scan(&media, &data)
1339	if err != nil {
1340		log.Printf("error loading file: %s", err)
1341		http.NotFound(w, r)
1342		return
1343	}
1344	w.Header().Set("Content-Type", media)
1345	w.Header().Set("X-Content-Type-Options", "nosniff")
1346	w.Header().Set("Cache-Control", "max-age="+somedays())
1347	w.Write(data)
1348}
1349
1350func nomoroboto(w http.ResponseWriter, r *http.Request) {
1351	io.WriteString(w, "User-agent: *\n")
1352	io.WriteString(w, "Disallow: /a\n")
1353	io.WriteString(w, "Disallow: /d\n")
1354	io.WriteString(w, "Disallow: /meme\n")
1355	for _, u := range allusers() {
1356		fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
1357	}
1358}
1359
1360func serve() {
1361	db := opendatabase()
1362	login.Init(db)
1363
1364	listener, err := openListener()
1365	if err != nil {
1366		log.Fatal(err)
1367	}
1368	go redeliverator()
1369
1370	debug := false
1371	getconfig("debug", &debug)
1372	readviews = templates.Load(debug,
1373		"views/honkpage.html",
1374		"views/honkfrags.html",
1375		"views/honkers.html",
1376		"views/zonkers.html",
1377		"views/combos.html",
1378		"views/honkform.html",
1379		"views/honk.html",
1380		"views/account.html",
1381		"views/about.html",
1382		"views/funzone.html",
1383		"views/login.html",
1384		"views/xzone.html",
1385		"views/header.html",
1386		"views/onts.html",
1387	)
1388	if !debug {
1389		s := "views/style.css"
1390		savedstyleparams[s] = getstyleparam(s)
1391		s = "views/local.css"
1392		savedstyleparams[s] = getstyleparam(s)
1393	}
1394
1395	bitethethumbs()
1396
1397	mux := mux.NewRouter()
1398	mux.Use(login.Checker)
1399
1400	posters := mux.Methods("POST").Subrouter()
1401	getters := mux.Methods("GET").Subrouter()
1402
1403	getters.HandleFunc("/", homepage)
1404	getters.HandleFunc("/home", homepage)
1405	getters.HandleFunc("/front", homepage)
1406	getters.HandleFunc("/robots.txt", nomoroboto)
1407	getters.HandleFunc("/rss", showrss)
1408	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
1409	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showhonk)
1410	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
1411	posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
1412	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
1413	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
1414	getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
1415	getters.HandleFunc("/a", avatate)
1416	getters.HandleFunc("/o", thelistingoftheontologies)
1417	getters.HandleFunc("/o/{name:[a-z0-9-]+}", showontology)
1418	getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
1419	getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
1420	getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe)
1421	getters.HandleFunc("/.well-known/webfinger", fingerlicker)
1422
1423	getters.HandleFunc("/style.css", servecss)
1424	getters.HandleFunc("/local.css", servecss)
1425	getters.HandleFunc("/about", servehtml)
1426	getters.HandleFunc("/login", servehtml)
1427	posters.HandleFunc("/dologin", login.LoginFunc)
1428	getters.HandleFunc("/logout", login.LogoutFunc)
1429
1430	loggedin := mux.NewRoute().Subrouter()
1431	loggedin.Use(login.Required)
1432	loggedin.HandleFunc("/account", accountpage)
1433	loggedin.HandleFunc("/funzone", showfunzone)
1434	loggedin.HandleFunc("/chpass", dochpass)
1435	loggedin.HandleFunc("/atme", homepage)
1436	loggedin.HandleFunc("/zonkzone", zonkzone)
1437	loggedin.HandleFunc("/xzone", xzone)
1438	loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk)))
1439	loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk)))
1440	loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
1441	loggedin.Handle("/zonkzonk", login.CSRFWrap("zonkzonk", http.HandlerFunc(zonkzonk)))
1442	loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
1443	loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
1444	loggedin.HandleFunc("/honkers", showhonkers)
1445	loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", showhonker)
1446	loggedin.HandleFunc("/h", showhonker)
1447	loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", showcombo)
1448	loggedin.HandleFunc("/c", showcombos)
1449	loggedin.HandleFunc("/t", showconvoy)
1450	loggedin.HandleFunc("/q", showsearch)
1451	loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
1452
1453	err = http.Serve(listener, mux)
1454	if err != nil {
1455		log.Fatal(err)
1456	}
1457}