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