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(user, 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 savebonk(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 XID: xonk.XID,
738 Date: dt,
739 Donks: xonk.Donks,
740 Convoy: xonk.Convoy,
741 Audience: []string{thewholeworld, oonker},
742 Public: true,
743 }
744
745 aud := strings.Join(bonk.Audience, " ")
746 whofore := 2
747 onts := xonk.Onts
748 res, err := stmtSaveHonk.Exec(userinfo.UserID, "bonk", bonk.Honker, xid, "",
749 dt.Format(dbtimeformat), "", aud, xonk.Noise, xonk.Convoy, whofore, "html",
750 xonk.Precis, oonker, 0, strings.Join(onts, " "))
751 if err != nil {
752 log.Printf("error saving bonk: %s", err)
753 return
754 }
755 bonk.ID, _ = res.LastInsertId()
756 for _, d := range bonk.Donks {
757 _, err = stmtSaveDonk.Exec(bonk.ID, d.FileID)
758 if err != nil {
759 log.Printf("err saving donk: %s", err)
760 return
761 }
762 }
763 for _, o := range onts {
764 _, err = stmtSaveOnts.Exec(strings.ToLower(o), bonk.ID)
765 if err != nil {
766 log.Printf("error saving ont: %s", err)
767 }
768 }
769
770 go honkworldwide(user, &bonk)
771}
772
773func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string) {
774 zonk := Honk{
775 What: what,
776 XID: xonk.XID,
777 Date: time.Now().UTC(),
778 Audience: oneofakind(xonk.Audience),
779 }
780 zonk.Public = !keepitquiet(zonk.Audience)
781
782 log.Printf("announcing %sed honk: %s", what, xonk.XID)
783 go honkworldwide(user, &zonk)
784}
785
786func zonkit(w http.ResponseWriter, r *http.Request) {
787 wherefore := r.FormValue("wherefore")
788 what := r.FormValue("what")
789 userinfo := login.GetUserInfo(r)
790 user, _ := butwhatabout(userinfo.Username)
791
792 if wherefore == "ack" {
793 xonk := getxonk(userinfo.UserID, what)
794 if xonk != nil {
795 _, err := stmtUpdateFlags.Exec(flagIsAcked, xonk.ID)
796 if err != nil {
797 log.Printf("error acking: %s", err)
798 }
799 sendzonkofsorts(xonk, user, "ack")
800 }
801 return
802 }
803
804 if wherefore == "deack" {
805 xonk := getxonk(userinfo.UserID, what)
806 if xonk != nil {
807 _, err := stmtClearFlags.Exec(flagIsAcked, xonk.ID)
808 if err != nil {
809 log.Printf("error deacking: %s", err)
810 }
811 sendzonkofsorts(xonk, user, "deack")
812 }
813 return
814 }
815
816 if wherefore == "unbonk" {
817 xonk := getbonk(userinfo.UserID, what)
818 if xonk != nil {
819 _, err := stmtZonkDonks.Exec(xonk.ID)
820 if err != nil {
821 log.Printf("error zonking: %s", err)
822 }
823 _, err = stmtZonkIt.Exec(xonk.ID)
824 if err != nil {
825 log.Printf("error zonking: %s", err)
826 }
827 xonk = getxonk(userinfo.UserID, what)
828 _, err = stmtClearFlags.Exec(flagIsBonked, xonk.ID)
829 if err != nil {
830 log.Printf("error unbonking: %s", err)
831 }
832 sendzonkofsorts(xonk, user, "unbonk")
833 }
834 return
835 }
836
837 log.Printf("zonking %s %s", wherefore, what)
838 if wherefore == "zonk" {
839 xonk := getxonk(userinfo.UserID, what)
840 if xonk != nil {
841 _, err := stmtZonkDonks.Exec(xonk.ID)
842 if err != nil {
843 log.Printf("error zonking: %s", err)
844 }
845 _, err = stmtZonkIt.Exec(xonk.ID)
846 if err != nil {
847 log.Printf("error zonking: %s", err)
848 }
849 if xonk.Whofore == 2 || xonk.Whofore == 3 {
850 sendzonkofsorts(xonk, user, "zonk")
851 }
852 }
853 }
854 _, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
855 if err != nil {
856 log.Printf("error saving zonker: %s", err)
857 return
858 }
859}
860
861func savehonk(w http.ResponseWriter, r *http.Request) {
862 rid := r.FormValue("rid")
863 noise := r.FormValue("noise")
864
865 userinfo := login.GetUserInfo(r)
866 user, _ := butwhatabout(userinfo.Username)
867
868 dt := time.Now().UTC()
869 xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
870 what := "honk"
871 if rid != "" {
872 what = "tonk"
873 }
874 honk := Honk{
875 UserID: userinfo.UserID,
876 Username: userinfo.Username,
877 What: "honk",
878 Honker: user.URL,
879 XID: xid,
880 Date: dt,
881 }
882 if strings.HasPrefix(noise, "DZ:") {
883 idx := strings.Index(noise, "\n")
884 if idx == -1 {
885 honk.Precis = noise
886 noise = ""
887 } else {
888 honk.Precis = noise[:idx]
889 noise = noise[idx+1:]
890 }
891 }
892 noise = quickrename(noise, userinfo.UserID)
893 noise = hooterize(noise)
894 noise = strings.TrimSpace(noise)
895 honk.Precis = strings.TrimSpace(honk.Precis)
896
897 var convoy string
898 if rid != "" {
899 xonk := getxonk(userinfo.UserID, rid)
900 if xonk != nil {
901 if xonk.Public {
902 honk.Audience = append(honk.Audience, xonk.Audience...)
903 }
904 convoy = xonk.Convoy
905 } else {
906 xonkaud, c := whosthere(rid)
907 honk.Audience = append(honk.Audience, xonkaud...)
908 convoy = c
909 }
910 for i, a := range honk.Audience {
911 if a == thewholeworld {
912 honk.Audience[0], honk.Audience[i] = honk.Audience[i], honk.Audience[0]
913 break
914 }
915 }
916 honk.RID = rid
917 } else {
918 honk.Audience = []string{thewholeworld}
919 }
920 if noise != "" && noise[0] == '@' {
921 honk.Audience = append(grapevine(noise), honk.Audience...)
922 } else {
923 honk.Audience = append(honk.Audience, grapevine(noise)...)
924 }
925 if convoy == "" {
926 convoy = "data:,electrichonkytonk-" + xfiltrate()
927 }
928 butnottooloud(honk.Audience)
929 honk.Audience = oneofakind(honk.Audience)
930 if len(honk.Audience) == 0 {
931 log.Printf("honk to nowhere")
932 http.Error(w, "honk to nowhere...", http.StatusNotFound)
933 return
934 }
935 honk.Public = !keepitquiet(honk.Audience)
936 noise = obfusbreak(noise)
937 honk.Noise = noise
938 honk.Convoy = convoy
939
940 donkxid := r.FormValue("donkxid")
941 if donkxid == "" {
942 file, filehdr, err := r.FormFile("donk")
943 if err == nil {
944 var buf bytes.Buffer
945 io.Copy(&buf, file)
946 file.Close()
947 data := buf.Bytes()
948 xid := xfiltrate()
949 var media, name string
950 img, err := image.Vacuum(&buf, image.Params{MaxWidth: 2048, MaxHeight: 2048})
951 if err == nil {
952 data = img.Data
953 format := img.Format
954 media = "image/" + format
955 if format == "jpeg" {
956 format = "jpg"
957 }
958 name = xid + "." + format
959 xid = name
960 } else {
961 maxsize := 100000
962 if len(data) > maxsize {
963 log.Printf("bad image: %s too much text: %d", err, len(data))
964 http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
965 return
966 }
967 for i := 0; i < len(data); i++ {
968 if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' {
969 log.Printf("bad image: %s not text: %d", err, data[i])
970 http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
971 return
972 }
973 }
974 media = "text/plain"
975 name = filehdr.Filename
976 if name == "" {
977 name = xid + ".txt"
978 }
979 xid += ".txt"
980 }
981 desc := r.FormValue("donkdesc")
982 if desc == "" {
983 desc = name
984 }
985 url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
986 res, err := stmtSaveFile.Exec(xid, name, desc, url, media, 1, data)
987 if err != nil {
988 log.Printf("unable to save image: %s", err)
989 return
990 }
991 var d Donk
992 d.FileID, _ = res.LastInsertId()
993 honk.Donks = append(honk.Donks, &d)
994 donkxid = d.XID
995 }
996 } else {
997 xid := donkxid
998 url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
999 var donk Donk
1000 row := stmtFindFile.QueryRow(url)
1001 err := row.Scan(&donk.FileID)
1002 if err == nil {
1003 honk.Donks = append(honk.Donks, &donk)
1004 } else {
1005 log.Printf("can't find file: %s", xid)
1006 }
1007 }
1008 herd := herdofemus(honk.Noise)
1009 for _, e := range herd {
1010 donk := savedonk(e.ID, e.Name, e.Name, "image/png", true)
1011 if donk != nil {
1012 donk.Name = e.Name
1013 honk.Donks = append(honk.Donks, donk)
1014 }
1015 }
1016 memetize(&honk)
1017
1018 aud := strings.Join(honk.Audience, " ")
1019 whofore := 2
1020 if !honk.Public {
1021 whofore = 3
1022 }
1023 if r.FormValue("preview") == "preview" {
1024 honks := []*Honk{&honk}
1025 reverbolate(userinfo.UserID, honks)
1026 templinfo := getInfo(r)
1027 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1028 templinfo["Honks"] = honks
1029 templinfo["InReplyTo"] = r.FormValue("rid")
1030 templinfo["Noise"] = r.FormValue("noise")
1031 templinfo["SavedFile"] = donkxid
1032 templinfo["ServerMessage"] = "honk preview"
1033 err := readviews.Execute(w, "honkpage.html", templinfo)
1034 if err != nil {
1035 log.Print(err)
1036 }
1037 return
1038 }
1039 honk.Onts = oneofakind(ontologies(honk.Noise))
1040 res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid,
1041 dt.Format(dbtimeformat), "", aud, honk.Noise, convoy, whofore, "html",
1042 honk.Precis, honk.Oonker, 0, strings.Join(honk.Onts, " "))
1043 if err != nil {
1044 log.Printf("error saving honk: %s", err)
1045 http.Error(w, "something bad happened while saving", http.StatusInternalServerError)
1046 return
1047 }
1048 honk.ID, _ = res.LastInsertId()
1049 for _, d := range honk.Donks {
1050 _, err = stmtSaveDonk.Exec(honk.ID, d.FileID)
1051 if err != nil {
1052 log.Printf("err saving donk: %s", err)
1053 http.Error(w, "something bad happened while saving", http.StatusInternalServerError)
1054 return
1055 }
1056 }
1057 for _, o := range honk.Onts {
1058 _, err = stmtSaveOnts.Exec(strings.ToLower(o), honk.ID)
1059 if err != nil {
1060 log.Printf("error saving ont: %s", err)
1061 }
1062 }
1063 honk.Donks = nil
1064 donksforhonks([]*Honk{&honk})
1065
1066 go honkworldwide(user, &honk)
1067
1068 http.Redirect(w, r, xid, http.StatusSeeOther)
1069}
1070
1071func showhonkers(w http.ResponseWriter, r *http.Request) {
1072 userinfo := login.GetUserInfo(r)
1073 templinfo := getInfo(r)
1074 templinfo["Honkers"] = gethonkers(userinfo.UserID)
1075 templinfo["HonkerCSRF"] = login.GetCSRF("savehonker", r)
1076 err := readviews.Execute(w, "honkers.html", templinfo)
1077 if err != nil {
1078 log.Print(err)
1079 }
1080}
1081
1082func showcombos(w http.ResponseWriter, r *http.Request) {
1083 userinfo := login.GetUserInfo(r)
1084 templinfo := getInfo(r)
1085 honkers := gethonkers(userinfo.UserID)
1086 var combos []string
1087 for _, h := range honkers {
1088 combos = append(combos, h.Combos...)
1089 }
1090 for i, c := range combos {
1091 if c == "-" {
1092 combos[i] = ""
1093 }
1094 }
1095 combos = oneofakind(combos)
1096 sort.Strings(combos)
1097 templinfo["Combos"] = combos
1098 err := readviews.Execute(w, "combos.html", templinfo)
1099 if err != nil {
1100 log.Print(err)
1101 }
1102}
1103
1104func savehonker(w http.ResponseWriter, r *http.Request) {
1105 u := login.GetUserInfo(r)
1106 name := r.FormValue("name")
1107 url := r.FormValue("url")
1108 peep := r.FormValue("peep")
1109 combos := r.FormValue("combos")
1110 honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
1111
1112 if honkerid > 0 {
1113 goodbye := r.FormValue("goodbye")
1114 if goodbye == "F" {
1115 db := opendatabase()
1116 row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ?",
1117 honkerid, u.UserID)
1118 var xid string
1119 err := row.Scan(&xid)
1120 if err != nil {
1121 log.Printf("can't get honker xid: %s", err)
1122 return
1123 }
1124 log.Printf("unsubscribing from %s", xid)
1125 user, _ := butwhatabout(u.Username)
1126 go itakeitallback(user, xid)
1127 _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, xid, "sub")
1128 if err != nil {
1129 log.Printf("error updating honker: %s", err)
1130 return
1131 }
1132
1133 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1134 return
1135 }
1136 combos = " " + strings.TrimSpace(combos) + " "
1137 _, err := stmtUpdateCombos.Exec(combos, honkerid, u.UserID)
1138 if err != nil {
1139 log.Printf("update honker err: %s", err)
1140 return
1141 }
1142 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1143 }
1144
1145 flavor := "presub"
1146 if peep == "peep" {
1147 flavor = "peep"
1148 }
1149 p, err := investigate(url)
1150 if err != nil {
1151 http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
1152 log.Printf("failed to investigate honker")
1153 return
1154 }
1155 url = p.XID
1156 if name == "" {
1157 name = p.Handle
1158 }
1159 _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos)
1160 if err != nil {
1161 log.Print(err)
1162 return
1163 }
1164 if flavor == "presub" {
1165 user, _ := butwhatabout(u.Username)
1166 go subsub(user, url)
1167 }
1168 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1169}
1170
1171func zonkzone(w http.ResponseWriter, r *http.Request) {
1172 userinfo := login.GetUserInfo(r)
1173 rows, err := stmtGetZonkers.Query(userinfo.UserID)
1174 if err != nil {
1175 log.Printf("err: %s", err)
1176 return
1177 }
1178 defer rows.Close()
1179 var zonkers []Zonker
1180 for rows.Next() {
1181 var z Zonker
1182 rows.Scan(&z.ID, &z.Name, &z.Wherefore)
1183 zonkers = append(zonkers, z)
1184 }
1185 sort.Slice(zonkers, func(i, j int) bool {
1186 w1 := zonkers[i].Wherefore
1187 w2 := zonkers[j].Wherefore
1188 if w1 == w2 {
1189 return zonkers[i].Name < zonkers[j].Name
1190 }
1191 if w1 == "zonvoy" {
1192 w1 = "zzzzzzz"
1193 }
1194 if w2 == "zonvoy" {
1195 w2 = "zzzzzzz"
1196 }
1197 return w1 < w2
1198 })
1199
1200 templinfo := getInfo(r)
1201 templinfo["Zonkers"] = zonkers
1202 templinfo["ZonkCSRF"] = login.GetCSRF("zonkzonk", r)
1203 err = readviews.Execute(w, "zonkers.html", templinfo)
1204 if err != nil {
1205 log.Print(err)
1206 }
1207}
1208
1209func zonkzonk(w http.ResponseWriter, r *http.Request) {
1210 userinfo := login.GetUserInfo(r)
1211 itsok := r.FormValue("itsok")
1212 if itsok == "iforgiveyou" {
1213 zonkerid, _ := strconv.ParseInt(r.FormValue("zonkerid"), 10, 0)
1214 db := opendatabase()
1215 db.Exec("delete from zonkers where userid = ? and zonkerid = ?",
1216 userinfo.UserID, zonkerid)
1217 bitethethumbs()
1218 http.Redirect(w, r, "/zonkzone", http.StatusSeeOther)
1219 return
1220 }
1221 wherefore := r.FormValue("wherefore")
1222 name := r.FormValue("name")
1223 if name == "" {
1224 return
1225 }
1226 switch wherefore {
1227 case "zonker":
1228 case "zomain":
1229 case "zonvoy":
1230 case "zord":
1231 case "zilence":
1232 default:
1233 return
1234 }
1235 db := opendatabase()
1236 db.Exec("insert into zonkers (userid, name, wherefore) values (?, ?, ?)",
1237 userinfo.UserID, name, wherefore)
1238 if wherefore == "zonker" || wherefore == "zomain" || wherefore == "zord" || wherefore == "zilence" {
1239 bitethethumbs()
1240 }
1241
1242 http.Redirect(w, r, "/zonkzone", http.StatusSeeOther)
1243}
1244
1245func accountpage(w http.ResponseWriter, r *http.Request) {
1246 u := login.GetUserInfo(r)
1247 user, _ := butwhatabout(u.Username)
1248 templinfo := getInfo(r)
1249 templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
1250 templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
1251 templinfo["User"] = user
1252 err := readviews.Execute(w, "account.html", templinfo)
1253 if err != nil {
1254 log.Print(err)
1255 }
1256}
1257
1258func dochpass(w http.ResponseWriter, r *http.Request) {
1259 err := login.ChangePassword(w, r)
1260 if err != nil {
1261 log.Printf("error changing password: %s", err)
1262 }
1263 http.Redirect(w, r, "/account", http.StatusSeeOther)
1264}
1265
1266func fingerlicker(w http.ResponseWriter, r *http.Request) {
1267 orig := r.FormValue("resource")
1268
1269 log.Printf("finger lick: %s", orig)
1270
1271 if strings.HasPrefix(orig, "acct:") {
1272 orig = orig[5:]
1273 }
1274
1275 name := orig
1276 idx := strings.LastIndexByte(name, '/')
1277 if idx != -1 {
1278 name = name[idx+1:]
1279 if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
1280 log.Printf("foreign request rejected")
1281 name = ""
1282 }
1283 } else {
1284 idx = strings.IndexByte(name, '@')
1285 if idx != -1 {
1286 name = name[:idx]
1287 if name+"@"+serverName != orig {
1288 log.Printf("foreign request rejected")
1289 name = ""
1290 }
1291 }
1292 }
1293 user, err := butwhatabout(name)
1294 if err != nil {
1295 http.NotFound(w, r)
1296 return
1297 }
1298
1299 j := junk.New()
1300 j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName)
1301 j["aliases"] = []string{user.URL}
1302 var links []junk.Junk
1303 l := junk.New()
1304 l["rel"] = "self"
1305 l["type"] = `application/activity+json`
1306 l["href"] = user.URL
1307 links = append(links, l)
1308 j["links"] = links
1309
1310 w.Header().Set("Cache-Control", "max-age=3600")
1311 w.Header().Set("Content-Type", "application/jrd+json")
1312 j.Write(w)
1313}
1314
1315func somedays() string {
1316 secs := 432000 + notrand.Int63n(432000)
1317 return fmt.Sprintf("%d", secs)
1318}
1319
1320func avatate(w http.ResponseWriter, r *http.Request) {
1321 n := r.FormValue("a")
1322 a := avatar(n)
1323 w.Header().Set("Cache-Control", "max-age="+somedays())
1324 w.Write(a)
1325}
1326
1327func servecss(w http.ResponseWriter, r *http.Request) {
1328 data, _ := ioutil.ReadFile("views" + r.URL.Path)
1329 s := css.Process(string(data))
1330 w.Header().Set("Cache-Control", "max-age=7776000")
1331 w.Header().Set("Content-Type", "text/css; charset=utf-8")
1332 w.Write([]byte(s))
1333}
1334func servehtml(w http.ResponseWriter, r *http.Request) {
1335 templinfo := getInfo(r)
1336 err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
1337 if err != nil {
1338 log.Print(err)
1339 }
1340}
1341func serveemu(w http.ResponseWriter, r *http.Request) {
1342 xid := mux.Vars(r)["xid"]
1343 w.Header().Set("Cache-Control", "max-age="+somedays())
1344 http.ServeFile(w, r, "emus/"+xid)
1345}
1346func servememe(w http.ResponseWriter, r *http.Request) {
1347 xid := mux.Vars(r)["xid"]
1348 w.Header().Set("Cache-Control", "max-age="+somedays())
1349 http.ServeFile(w, r, "memes/"+xid)
1350}
1351
1352func servefile(w http.ResponseWriter, r *http.Request) {
1353 xid := mux.Vars(r)["xid"]
1354 row := stmtFileData.QueryRow(xid)
1355 var media string
1356 var data []byte
1357 err := row.Scan(&media, &data)
1358 if err != nil {
1359 log.Printf("error loading file: %s", err)
1360 http.NotFound(w, r)
1361 return
1362 }
1363 w.Header().Set("Content-Type", media)
1364 w.Header().Set("X-Content-Type-Options", "nosniff")
1365 w.Header().Set("Cache-Control", "max-age="+somedays())
1366 w.Write(data)
1367}
1368
1369func nomoroboto(w http.ResponseWriter, r *http.Request) {
1370 io.WriteString(w, "User-agent: *\n")
1371 io.WriteString(w, "Disallow: /a\n")
1372 io.WriteString(w, "Disallow: /d\n")
1373 io.WriteString(w, "Disallow: /meme\n")
1374 for _, u := range allusers() {
1375 fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
1376 }
1377}
1378
1379func serve() {
1380 db := opendatabase()
1381 login.Init(db)
1382
1383 listener, err := openListener()
1384 if err != nil {
1385 log.Fatal(err)
1386 }
1387 go redeliverator()
1388
1389 debug := false
1390 getconfig("debug", &debug)
1391 readviews = templates.Load(debug,
1392 "views/honkpage.html",
1393 "views/honkfrags.html",
1394 "views/honkers.html",
1395 "views/zonkers.html",
1396 "views/combos.html",
1397 "views/honkform.html",
1398 "views/honk.html",
1399 "views/account.html",
1400 "views/about.html",
1401 "views/funzone.html",
1402 "views/login.html",
1403 "views/xzone.html",
1404 "views/header.html",
1405 "views/onts.html",
1406 )
1407 if !debug {
1408 s := "views/style.css"
1409 savedstyleparams[s] = getstyleparam(s)
1410 s = "views/local.css"
1411 savedstyleparams[s] = getstyleparam(s)
1412 }
1413
1414 bitethethumbs()
1415
1416 mux := mux.NewRouter()
1417 mux.Use(login.Checker)
1418
1419 posters := mux.Methods("POST").Subrouter()
1420 getters := mux.Methods("GET").Subrouter()
1421
1422 getters.HandleFunc("/", homepage)
1423 getters.HandleFunc("/home", homepage)
1424 getters.HandleFunc("/front", homepage)
1425 getters.HandleFunc("/robots.txt", nomoroboto)
1426 getters.HandleFunc("/rss", showrss)
1427 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
1428 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showhonk)
1429 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
1430 posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
1431 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
1432 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
1433 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
1434 getters.HandleFunc("/a", avatate)
1435 getters.HandleFunc("/o", thelistingoftheontologies)
1436 getters.HandleFunc("/o/{name:[a-z0-9-]+}", showontology)
1437 getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
1438 getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
1439 getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe)
1440 getters.HandleFunc("/.well-known/webfinger", fingerlicker)
1441
1442 getters.HandleFunc("/style.css", servecss)
1443 getters.HandleFunc("/local.css", servecss)
1444 getters.HandleFunc("/about", servehtml)
1445 getters.HandleFunc("/login", servehtml)
1446 posters.HandleFunc("/dologin", login.LoginFunc)
1447 getters.HandleFunc("/logout", login.LogoutFunc)
1448
1449 loggedin := mux.NewRoute().Subrouter()
1450 loggedin.Use(login.Required)
1451 loggedin.HandleFunc("/account", accountpage)
1452 loggedin.HandleFunc("/funzone", showfunzone)
1453 loggedin.HandleFunc("/chpass", dochpass)
1454 loggedin.HandleFunc("/atme", homepage)
1455 loggedin.HandleFunc("/zonkzone", zonkzone)
1456 loggedin.HandleFunc("/xzone", xzone)
1457 loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(savehonk)))
1458 loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(savebonk)))
1459 loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
1460 loggedin.Handle("/zonkzonk", login.CSRFWrap("zonkzonk", http.HandlerFunc(zonkzonk)))
1461 loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
1462 loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
1463 loggedin.HandleFunc("/honkers", showhonkers)
1464 loggedin.HandleFunc("/h/{name:[[:alnum:]]+}", showhonker)
1465 loggedin.HandleFunc("/h", showhonker)
1466 loggedin.HandleFunc("/c/{name:[[:alnum:]]+}", showcombo)
1467 loggedin.HandleFunc("/c", showcombos)
1468 loggedin.HandleFunc("/t", showconvoy)
1469 loggedin.HandleFunc("/q", showsearch)
1470 loggedin.Handle("/savehonker", login.CSRFWrap("savehonker", http.HandlerFunc(savehonker)))
1471
1472 err = http.Serve(listener, mux)
1473 if err != nil {
1474 log.Fatal(err)
1475 }
1476}