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