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 "database/sql"
21 "fmt"
22 "html/template"
23 "io"
24 "log"
25 notrand "math/rand"
26 "net/http"
27 "net/url"
28 "os"
29 "os/signal"
30 "regexp"
31 "sort"
32 "strconv"
33 "strings"
34 "time"
35
36 "github.com/gorilla/mux"
37 "humungus.tedunangst.com/r/webs/cache"
38 "humungus.tedunangst.com/r/webs/httpsig"
39 "humungus.tedunangst.com/r/webs/junk"
40 "humungus.tedunangst.com/r/webs/login"
41 "humungus.tedunangst.com/r/webs/rss"
42 "humungus.tedunangst.com/r/webs/templates"
43)
44
45var readviews *templates.Template
46
47var userSep = "u"
48var honkSep = "h"
49
50func getuserstyle(u *login.UserInfo) template.CSS {
51 if u == nil {
52 return ""
53 }
54 user, _ := butwhatabout(u.Username)
55 if user.Options.SkinnyCSS {
56 return "main { max-width: 700px; }"
57 }
58 return ""
59}
60
61func getInfo(r *http.Request) map[string]interface{} {
62 u := login.GetUserInfo(r)
63 templinfo := make(map[string]interface{})
64 templinfo["StyleParam"] = getassetparam(viewDir + "/views/style.css")
65 templinfo["LocalStyleParam"] = getassetparam(viewDir + "/views/local.css")
66 templinfo["JSParam"] = getassetparam(viewDir + "/views/honkpage.js")
67 templinfo["UserStyle"] = getuserstyle(u)
68 templinfo["ServerName"] = serverName
69 templinfo["IconName"] = iconName
70 templinfo["UserInfo"] = u
71 templinfo["UserSep"] = userSep
72 if u != nil {
73 var combos []string
74 combocache.Get(u.UserID, &combos)
75 templinfo["Combos"] = combos
76 }
77 return templinfo
78}
79
80func homepage(w http.ResponseWriter, r *http.Request) {
81 templinfo := getInfo(r)
82 u := login.GetUserInfo(r)
83 var honks []*Honk
84 var userid int64 = -1
85
86 templinfo["ServerMessage"] = serverMsg
87 if u == nil || r.URL.Path == "/front" {
88 switch r.URL.Path {
89 case "/events":
90 honks = geteventhonks(userid)
91 templinfo["ServerMessage"] = "some recent and upcoming events"
92 default:
93 templinfo["ShowRSS"] = true
94 honks = getpublichonks()
95 }
96 } else {
97 userid = u.UserID
98 switch r.URL.Path {
99 case "/atme":
100 templinfo["ServerMessage"] = "at me!"
101 templinfo["PageName"] = "atme"
102 honks = gethonksforme(userid, 0)
103 honks = osmosis(honks, userid, false)
104 case "/events":
105 templinfo["ServerMessage"] = "some recent and upcoming events"
106 templinfo["PageName"] = "events"
107 honks = geteventhonks(userid)
108 honks = osmosis(honks, userid, true)
109 case "/first":
110 templinfo["PageName"] = "first"
111 honks = gethonksforuserfirstclass(userid, 0)
112 honks = osmosis(honks, userid, true)
113 case "/saved":
114 templinfo["ServerMessage"] = "saved honks"
115 templinfo["PageName"] = "saved"
116 honks = getsavedhonks(userid, 0)
117 default:
118 templinfo["PageName"] = "home"
119 honks = gethonksforuser(userid, 0)
120 honks = osmosis(honks, userid, true)
121 }
122 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
123 }
124
125 honkpage(w, u, honks, templinfo)
126}
127
128func showfunzone(w http.ResponseWriter, r *http.Request) {
129 var emunames, memenames []string
130 dir, err := os.Open(dataDir + "/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(dataDir + "/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
154func showrss(w http.ResponseWriter, r *http.Request) {
155 name := mux.Vars(r)["name"]
156
157 var honks []*Honk
158 if name != "" {
159 honks = gethonksbyuser(name, false, 0)
160 } else {
161 honks = getpublichonks()
162 }
163 if len(honks) > 20 {
164 honks = honks[0:20]
165 }
166 reverbolate(-1, honks)
167
168 home := fmt.Sprintf("https://%s/", serverName)
169 base := home
170 if name != "" {
171 home += "u/" + name
172 name += " "
173 }
174 feed := rss.Feed{
175 Title: name + "honk",
176 Link: home,
177 Description: name + "honk rss",
178 Image: &rss.Image{
179 URL: base + "icon.png",
180 Title: name + "honk rss",
181 Link: home,
182 },
183 }
184 var modtime time.Time
185 for _, honk := range honks {
186 if !firstclass(honk) {
187 continue
188 }
189 desc := string(honk.HTML)
190 if t := honk.Time; t != nil {
191 desc += fmt.Sprintf(`<p>Time: %s`, t.StartTime.Local().Format("03:04PM EDT Mon Jan 02"))
192 if t.Duration != 0 {
193 desc += fmt.Sprintf(`<br>Duration: %s`, t.Duration)
194 }
195 }
196 if p := honk.Place; p != nil {
197 desc += string(templates.Sprintf(`<p>Location: <a href="%s">%s</a> %f %f`,
198 p.Url, p.Name, p.Latitude, p.Longitude))
199 }
200 for _, d := range honk.Donks {
201 desc += string(templates.Sprintf(`<p><a href="%s">Attachment: %s</a>`,
202 d.URL, d.Name))
203 }
204
205 feed.Items = append(feed.Items, &rss.Item{
206 Title: fmt.Sprintf("%s %s %s", honk.Username, honk.What, honk.XID),
207 Description: rss.CData{Data: desc},
208 Link: honk.URL,
209 PubDate: honk.Date.Format(time.RFC1123),
210 Guid: &rss.Guid{IsPermaLink: true, Value: honk.URL},
211 })
212 if honk.Date.After(modtime) {
213 modtime = honk.Date
214 }
215 }
216 w.Header().Set("Cache-Control", "max-age=300")
217 w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat))
218
219 err := feed.Write(w)
220 if err != nil {
221 log.Printf("error writing rss: %s", err)
222 }
223}
224
225func crappola(j junk.Junk) bool {
226 t, _ := j.GetString("type")
227 a, _ := j.GetString("actor")
228 o, _ := j.GetString("object")
229 if t == "Delete" && a == o {
230 log.Printf("crappola from %s", a)
231 return true
232 }
233 return false
234}
235
236func ping(user *WhatAbout, who string) {
237 var box *Box
238 ok := boxofboxes.Get(who, &box)
239 if !ok {
240 log.Printf("no inbox to ping %s", who)
241 return
242 }
243 j := junk.New()
244 j["@context"] = itiswhatitis
245 j["type"] = "Ping"
246 j["id"] = user.URL + "/ping/" + xfiltrate()
247 j["actor"] = user.URL
248 j["to"] = who
249 ki := ziggy(user.ID)
250 if ki == nil {
251 return
252 }
253 err := PostJunk(ki.keyname, ki.seckey, box.In, j)
254 if err != nil {
255 log.Printf("can't send ping: %s", err)
256 return
257 }
258 log.Printf("sent ping to %s: %s", who, j["id"])
259}
260
261func pong(user *WhatAbout, who string, obj string) {
262 var box *Box
263 ok := boxofboxes.Get(who, &box)
264 if !ok {
265 log.Printf("no inbox to pong %s", who)
266 return
267 }
268 j := junk.New()
269 j["@context"] = itiswhatitis
270 j["type"] = "Pong"
271 j["id"] = user.URL + "/pong/" + xfiltrate()
272 j["actor"] = user.URL
273 j["to"] = who
274 j["object"] = obj
275 ki := ziggy(user.ID)
276 if ki == nil {
277 return
278 }
279 err := PostJunk(ki.keyname, ki.seckey, box.In, j)
280 if err != nil {
281 log.Printf("can't send pong: %s", err)
282 return
283 }
284}
285
286func inbox(w http.ResponseWriter, r *http.Request) {
287 name := mux.Vars(r)["name"]
288 user, err := butwhatabout(name)
289 if err != nil {
290 http.NotFound(w, r)
291 return
292 }
293 if stealthmode(user.ID, r) {
294 http.NotFound(w, r)
295 return
296 }
297 var buf bytes.Buffer
298 io.Copy(&buf, r.Body)
299 payload := buf.Bytes()
300 j, err := junk.FromBytes(payload)
301 if err != nil {
302 log.Printf("bad payload: %s", err)
303 io.WriteString(os.Stdout, "bad payload\n")
304 os.Stdout.Write(payload)
305 io.WriteString(os.Stdout, "\n")
306 return
307 }
308
309 if crappola(j) {
310 return
311 }
312 what, _ := j.GetString("type")
313 if what == "Like" {
314 return
315 }
316 who, _ := j.GetString("actor")
317 if rejectactor(user.ID, who) {
318 return
319 }
320
321 keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
322 if err != nil {
323 log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
324 if keyname != "" {
325 log.Printf("bad signature from %s", keyname)
326 io.WriteString(os.Stdout, "bad payload\n")
327 os.Stdout.Write(payload)
328 io.WriteString(os.Stdout, "\n")
329 }
330 http.Error(w, "what did you call me?", http.StatusTeapot)
331 return
332 }
333 origin := keymatch(keyname, who)
334 if origin == "" {
335 log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
336 return
337 }
338
339 switch what {
340 case "Ping":
341 obj, _ := j.GetString("id")
342 log.Printf("ping from %s: %s", who, obj)
343 pong(user, who, obj)
344 case "Pong":
345 obj, _ := j.GetString("object")
346 log.Printf("pong from %s: %s", who, obj)
347 case "Follow":
348 obj, _ := j.GetString("object")
349 if obj != user.URL {
350 log.Printf("can't follow %s", obj)
351 return
352 }
353 log.Printf("updating honker follow: %s", who)
354
355 db := opendatabase()
356 row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('dub', 'undub')", who, user.ID)
357 var x string
358 err = row.Scan(&x)
359 if err != sql.ErrNoRows {
360 log.Printf("duplicate follow request: %s", who)
361 _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, who, "undub")
362 if err != nil {
363 log.Printf("error updating honker: %s", err)
364 }
365 } else {
366 stmtSaveDub.Exec(user.ID, who, who, "dub")
367 }
368 go rubadubdub(user, j)
369 case "Accept":
370 log.Printf("updating honker accept: %s", who)
371 db := opendatabase()
372 row := db.QueryRow("select name from honkers where userid = ? and xid = ? and flavor in ('presub')",
373 user.ID, who)
374 var name string
375 err := row.Scan(&name)
376 if err != nil {
377 log.Printf("can't get honker name: %s", err)
378 return
379 }
380 _, err = stmtUpdateFlavor.Exec("sub", user.ID, who, name, "presub")
381 if err != nil {
382 log.Printf("error updating honker: %s", err)
383 return
384 }
385 case "Update":
386 obj, ok := j.GetMap("object")
387 if ok {
388 what, _ := obj.GetString("type")
389 switch what {
390 case "Person":
391 return
392 case "Question":
393 return
394 case "Note":
395 go xonksaver(user, j, origin)
396 return
397 }
398 }
399 log.Printf("unknown Update activity")
400 fd, _ := os.OpenFile("savedinbox.json", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
401 j.Write(fd)
402 io.WriteString(fd, "\n")
403 fd.Close()
404
405 case "Undo":
406 obj, ok := j.GetMap("object")
407 if !ok {
408 log.Printf("unknown undo no object")
409 return
410 }
411 what, _ := obj.GetString("type")
412 switch what {
413 case "Follow":
414 log.Printf("updating honker undo: %s", who)
415 _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, who, "dub")
416 if err != nil {
417 log.Printf("error updating honker: %s", err)
418 return
419 }
420 case "Announce":
421 xid, _ := obj.GetString("object")
422 log.Printf("undo announce: %s", xid)
423 case "Like":
424 default:
425 log.Printf("unknown undo: %s", what)
426 }
427 default:
428 go xonksaver(user, j, origin)
429 }
430}
431
432func serverinbox(w http.ResponseWriter, r *http.Request) {
433 if stealthmode(serverUID, r) {
434 http.NotFound(w, r)
435 return
436 }
437 var buf bytes.Buffer
438 io.Copy(&buf, r.Body)
439 payload := buf.Bytes()
440 j, err := junk.FromBytes(payload)
441 if err != nil {
442 log.Printf("bad payload: %s", err)
443 io.WriteString(os.Stdout, "bad payload\n")
444 os.Stdout.Write(payload)
445 io.WriteString(os.Stdout, "\n")
446 return
447 }
448 if crappola(j) {
449 return
450 }
451 keyname, err := httpsig.VerifyRequest(r, payload, zaggy)
452 if err != nil {
453 log.Printf("inbox message failed signature for %s from %s", keyname, r.Header.Get("X-Forwarded-For"))
454 if keyname != "" {
455 log.Printf("bad signature from %s", keyname)
456 io.WriteString(os.Stdout, "bad payload\n")
457 os.Stdout.Write(payload)
458 io.WriteString(os.Stdout, "\n")
459 }
460 http.Error(w, "what did you call me?", http.StatusTeapot)
461 return
462 }
463 user := getserveruser()
464 who, _ := j.GetString("actor")
465 origin := keymatch(keyname, who)
466 if origin == "" {
467 log.Printf("keyname actor mismatch: %s <> %s", keyname, who)
468 return
469 }
470 if rejectactor(user.ID, who) {
471 return
472 }
473 re_ont := regexp.MustCompile("https://" + serverName + "/o/([[:alnum:]]+)")
474 what, _ := j.GetString("type")
475 log.Printf("server got a %s", what)
476 switch what {
477 case "Follow":
478 obj, _ := j.GetString("object")
479 if obj == user.URL {
480 log.Printf("can't follow the server!")
481 return
482 }
483 m := re_ont.FindStringSubmatch(obj)
484 if len(m) != 2 {
485 log.Printf("not sure how to handle this")
486 return
487 }
488 ont := "#" + m[1]
489 log.Printf("%s wants to follow %s", who, ont)
490 db := opendatabase()
491 row := db.QueryRow("select xid from honkers where name = ? and xid = ? and userid = ? and flavor in ('dub', 'undub')", ont, who, user.ID)
492 var x string
493 err = row.Scan(&x)
494 if err != sql.ErrNoRows {
495 log.Printf("duplicate follow request: %s", who)
496 _, err = stmtUpdateFlavor.Exec("dub", user.ID, who, ont, "undub")
497 if err != nil {
498 log.Printf("error updating honker: %s", err)
499 }
500 } else {
501 stmtSaveDub.Exec(user.ID, ont, who, "dub")
502 }
503 go rubadubdub(user, j)
504 case "Undo":
505 obj, ok := j.GetMap("object")
506 if !ok {
507 log.Printf("unknown undo no object")
508 return
509 }
510 what, _ := obj.GetString("type")
511 if what != "Follow" {
512 log.Printf("unknown undo: %s", what)
513 }
514 targ, _ := obj.GetString("object")
515 m := re_ont.FindStringSubmatch(targ)
516 if len(m) != 2 {
517 log.Printf("not sure how to handle this")
518 return
519 }
520 ont := "#" + m[1]
521 log.Printf("updating honker undo: %s %s", who, ont)
522 _, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub")
523 if err != nil {
524 log.Printf("error updating honker: %s", err)
525 return
526 }
527 }
528}
529
530func serveractor(w http.ResponseWriter, r *http.Request) {
531 if stealthmode(serverUID, r) {
532 http.NotFound(w, r)
533 return
534 }
535 user := getserveruser()
536 j := junkuser(user)
537 w.Write(j)
538}
539
540func ximport(w http.ResponseWriter, r *http.Request) {
541 u := login.GetUserInfo(r)
542 xid := strings.TrimSpace(r.FormValue("xid"))
543 xonk := getxonk(u.UserID, xid)
544 if xonk == nil {
545 p, _ := investigate(xid)
546 if p != nil {
547 xid = p.XID
548 }
549 j, err := GetJunk(xid)
550 if err != nil {
551 http.Error(w, "error getting external object", http.StatusInternalServerError)
552 log.Printf("error getting external object: %s", err)
553 return
554 }
555 log.Printf("importing %s", xid)
556 user, _ := butwhatabout(u.Username)
557
558 info, _ := somethingabout(j)
559 if info == nil {
560 xonk = xonksaver(user, j, originate(xid))
561 } else if info.What == SomeActor {
562 outbox, _ := j.GetString("outbox")
563 gimmexonks(user, outbox)
564 http.Redirect(w, r, "/h?xid="+url.QueryEscape(xid), http.StatusSeeOther)
565 return
566 } else if info.What == SomeCollection {
567 gimmexonks(user, xid)
568 http.Redirect(w, r, "/xzone", http.StatusSeeOther)
569 return
570 }
571 }
572 convoy := ""
573 if xonk != nil {
574 convoy = xonk.Convoy
575 }
576 http.Redirect(w, r, "/t?c="+url.QueryEscape(convoy), http.StatusSeeOther)
577}
578
579func xzone(w http.ResponseWriter, r *http.Request) {
580 u := login.GetUserInfo(r)
581 rows, err := stmtRecentHonkers.Query(u.UserID, u.UserID)
582 if err != nil {
583 log.Printf("query err: %s", err)
584 return
585 }
586 defer rows.Close()
587 var honkers []Honker
588 for rows.Next() {
589 var xid string
590 rows.Scan(&xid)
591 honkers = append(honkers, Honker{XID: xid})
592 }
593 rows.Close()
594 for i, _ := range honkers {
595 _, honkers[i].Handle = handles(honkers[i].XID)
596 }
597 templinfo := getInfo(r)
598 templinfo["XCSRF"] = login.GetCSRF("ximport", r)
599 templinfo["Honkers"] = honkers
600 err = readviews.Execute(w, "xzone.html", templinfo)
601 if err != nil {
602 log.Print(err)
603 }
604}
605
606var oldoutbox = cache.New(cache.Options{Filler: func(name string) ([]byte, bool) {
607 user, err := butwhatabout(name)
608 if err != nil {
609 return nil, false
610 }
611 honks := gethonksbyuser(name, false, 0)
612 if len(honks) > 20 {
613 honks = honks[0:20]
614 }
615
616 var jonks []junk.Junk
617 for _, h := range honks {
618 j, _ := jonkjonk(user, h)
619 jonks = append(jonks, j)
620 }
621
622 j := junk.New()
623 j["@context"] = itiswhatitis
624 j["id"] = user.URL + "/outbox"
625 j["attributedTo"] = user.URL
626 j["type"] = "OrderedCollection"
627 j["totalItems"] = len(jonks)
628 j["orderedItems"] = jonks
629
630 return j.ToBytes(), true
631}, Duration: 1 * time.Minute})
632
633func outbox(w http.ResponseWriter, r *http.Request) {
634 name := mux.Vars(r)["name"]
635 user, err := butwhatabout(name)
636 if err != nil {
637 http.NotFound(w, r)
638 return
639 }
640 if stealthmode(user.ID, r) {
641 http.NotFound(w, r)
642 return
643 }
644 var j []byte
645 ok := oldoutbox.Get(name, &j)
646 if ok {
647 w.Header().Set("Content-Type", theonetruename)
648 w.Write(j)
649 } else {
650 http.NotFound(w, r)
651 }
652}
653
654func emptiness(w http.ResponseWriter, r *http.Request) {
655 name := mux.Vars(r)["name"]
656 user, err := butwhatabout(name)
657 if err != nil {
658 http.NotFound(w, r)
659 return
660 }
661 if stealthmode(user.ID, r) {
662 http.NotFound(w, r)
663 return
664 }
665 colname := "/followers"
666 if strings.HasSuffix(r.URL.Path, "/following") {
667 colname = "/following"
668 }
669 j := junk.New()
670 j["@context"] = itiswhatitis
671 j["id"] = user.URL + colname
672 j["attributedTo"] = user.URL
673 j["type"] = "OrderedCollection"
674 j["totalItems"] = 0
675 j["orderedItems"] = []junk.Junk{}
676
677 w.Header().Set("Content-Type", theonetruename)
678 j.Write(w)
679}
680
681func showuser(w http.ResponseWriter, r *http.Request) {
682 name := mux.Vars(r)["name"]
683 user, err := butwhatabout(name)
684 if err != nil {
685 log.Printf("user not found %s: %s", name, err)
686 http.NotFound(w, r)
687 return
688 }
689 if stealthmode(user.ID, r) {
690 http.NotFound(w, r)
691 return
692 }
693 if friendorfoe(r.Header.Get("Accept")) {
694 j, ok := asjonker(name)
695 if ok {
696 w.Header().Set("Content-Type", theonetruename)
697 w.Write(j)
698 } else {
699 http.NotFound(w, r)
700 }
701 return
702 }
703 u := login.GetUserInfo(r)
704 honks := gethonksbyuser(name, u != nil && u.Username == name, 0)
705 templinfo := getInfo(r)
706 templinfo["Name"] = user.Name
707 whatabout := user.About
708 whatabout = markitzero(user.About)
709 templinfo["WhatAbout"] = template.HTML(whatabout)
710 templinfo["ServerMessage"] = ""
711 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
712 honkpage(w, u, honks, templinfo)
713}
714
715func showhonker(w http.ResponseWriter, r *http.Request) {
716 u := login.GetUserInfo(r)
717 name := mux.Vars(r)["name"]
718 var honks []*Honk
719 if name == "" {
720 name = r.FormValue("xid")
721 honks = gethonksbyxonker(u.UserID, name, 0)
722 } else {
723 honks = gethonksbyhonker(u.UserID, name, 0)
724 }
725 msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, name, name)
726 templinfo := getInfo(r)
727 templinfo["PageName"] = "honker"
728 templinfo["PageArg"] = name
729 templinfo["ServerMessage"] = msg
730 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
731 honkpage(w, u, honks, templinfo)
732}
733
734func showcombo(w http.ResponseWriter, r *http.Request) {
735 name := mux.Vars(r)["name"]
736 u := login.GetUserInfo(r)
737 honks := gethonksbycombo(u.UserID, name, 0)
738 honks = osmosis(honks, u.UserID, true)
739 templinfo := getInfo(r)
740 templinfo["PageName"] = "combo"
741 templinfo["PageArg"] = name
742 templinfo["ServerMessage"] = "honks by combo: " + name
743 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
744 honkpage(w, u, honks, templinfo)
745}
746func showconvoy(w http.ResponseWriter, r *http.Request) {
747 c := r.FormValue("c")
748 u := login.GetUserInfo(r)
749 honks := gethonksbyconvoy(u.UserID, c, 0)
750 templinfo := getInfo(r)
751 if len(honks) > 0 {
752 templinfo["TopHID"] = honks[0].ID
753 }
754 honks = osmosis(honks, u.UserID, false)
755 reversehonks(honks)
756 templinfo["PageName"] = "convoy"
757 templinfo["PageArg"] = c
758 templinfo["ServerMessage"] = "honks in convoy: " + c
759 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
760 honkpage(w, u, honks, templinfo)
761}
762func showsearch(w http.ResponseWriter, r *http.Request) {
763 q := r.FormValue("q")
764 u := login.GetUserInfo(r)
765 honks := gethonksbysearch(u.UserID, q, 0)
766 templinfo := getInfo(r)
767 templinfo["PageName"] = "search"
768 templinfo["PageArg"] = q
769 templinfo["ServerMessage"] = "honks for search: " + q
770 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
771 honkpage(w, u, honks, templinfo)
772}
773func showontology(w http.ResponseWriter, r *http.Request) {
774 name := mux.Vars(r)["name"]
775 u := login.GetUserInfo(r)
776 var userid int64 = -1
777 if u != nil {
778 userid = u.UserID
779 }
780 honks := gethonksbyontology(userid, "#"+name, 0)
781 if friendorfoe(r.Header.Get("Accept")) {
782 if len(honks) > 40 {
783 honks = honks[0:40]
784 }
785
786 var xids []string
787 for _, h := range honks {
788 xids = append(xids, h.XID)
789 }
790
791 user := getserveruser()
792
793 j := junk.New()
794 j["@context"] = itiswhatitis
795 j["id"] = fmt.Sprintf("https://%s/o/%s", serverName, name)
796 j["name"] = "#" + name
797 j["attributedTo"] = user.URL
798 j["type"] = "OrderedCollection"
799 j["totalItems"] = len(xids)
800 j["orderedItems"] = xids
801
802 j.Write(w)
803 return
804 }
805
806 templinfo := getInfo(r)
807 templinfo["ServerMessage"] = "honks by ontology: " + name
808 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
809 honkpage(w, u, honks, templinfo)
810}
811
812type Ont struct {
813 Name string
814 Count int64
815}
816
817func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) {
818 u := login.GetUserInfo(r)
819 var userid int64 = -1
820 if u != nil {
821 userid = u.UserID
822 }
823 rows, err := stmtAllOnts.Query(userid)
824 if err != nil {
825 log.Printf("selection error: %s", err)
826 return
827 }
828 defer rows.Close()
829 var onts []Ont
830 for rows.Next() {
831 var o Ont
832 err := rows.Scan(&o.Name, &o.Count)
833 if err != nil {
834 log.Printf("error scanning ont: %s", err)
835 continue
836 }
837 if len(o.Name) > 24 {
838 continue
839 }
840 o.Name = o.Name[1:]
841 onts = append(onts, o)
842 }
843 sort.Slice(onts, func(i, j int) bool {
844 return onts[i].Name < onts[j].Name
845 })
846 if u == nil {
847 w.Header().Set("Cache-Control", "max-age=300")
848 }
849 templinfo := getInfo(r)
850 templinfo["Onts"] = onts
851 err = readviews.Execute(w, "onts.html", templinfo)
852 if err != nil {
853 log.Print(err)
854 }
855}
856
857type Track struct {
858 xid string
859 who string
860}
861
862func savetracks(tracks map[string][]string) {
863 db := opendatabase()
864 tx, err := db.Begin()
865 if err != nil {
866 log.Printf("savetracks begin error: %s", err)
867 return
868 }
869 defer func() {
870 err := tx.Commit()
871 if err != nil {
872 log.Printf("savetracks commit error: %s", err)
873 }
874
875 }()
876 stmtGetTracks, err := tx.Prepare("select fetches from tracks where xid = ?")
877 if err != nil {
878 log.Printf("savetracks error: %s", err)
879 return
880 }
881 stmtNewTracks, err := tx.Prepare("insert into tracks (xid, fetches) values (?, ?)")
882 if err != nil {
883 log.Printf("savetracks error: %s", err)
884 return
885 }
886 stmtUpdateTracks, err := tx.Prepare("update tracks set fetches = ? where xid = ?")
887 if err != nil {
888 log.Printf("savetracks error: %s", err)
889 return
890 }
891 count := 0
892 for xid, f := range tracks {
893 count += len(f)
894 var prev string
895 row := stmtGetTracks.QueryRow(xid)
896 err := row.Scan(&prev)
897 if err == sql.ErrNoRows {
898 f = oneofakind(f)
899 stmtNewTracks.Exec(xid, strings.Join(f, " "))
900 } else if err == nil {
901 all := append(strings.Split(prev, " "), f...)
902 all = oneofakind(all)
903 stmtUpdateTracks.Exec(strings.Join(all, " "))
904 } else {
905 log.Printf("savetracks error: %s", err)
906 }
907 }
908 log.Printf("saved %d new fetches", count)
909}
910
911var trackchan = make(chan Track)
912
913func tracker() {
914 timeout := 4 * time.Minute
915 sleeper := time.NewTimer(timeout)
916 tracks := make(map[string][]string)
917 for {
918 select {
919 case track := <-trackchan:
920 tracks[track.xid] = append(tracks[track.xid], track.who)
921 case <-sleeper.C:
922 if len(tracks) > 0 {
923 go savetracks(tracks)
924 tracks = make(map[string][]string)
925 }
926 sleeper.Reset(timeout)
927 case <-endoftheworld:
928 if len(tracks) > 0 {
929 savetracks(tracks)
930 }
931 readyalready <- true
932 }
933 }
934}
935
936var re_keyholder = regexp.MustCompile(`keyId="([^"]+)"`)
937
938func trackback(xid string, r *http.Request) {
939 agent := r.UserAgent()
940 who := originate(agent)
941 sig := r.Header.Get("Signature")
942 if sig != "" {
943 m := re_keyholder.FindStringSubmatch(sig)
944 if len(m) == 2 {
945 who = m[1]
946 }
947 }
948 if who != "" {
949 trackchan <- Track{xid: xid, who: who}
950 }
951}
952
953func showonehonk(w http.ResponseWriter, r *http.Request) {
954 name := mux.Vars(r)["name"]
955 user, err := butwhatabout(name)
956 if err != nil {
957 http.NotFound(w, r)
958 return
959 }
960 if stealthmode(user.ID, r) {
961 http.NotFound(w, r)
962 return
963 }
964 xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path)
965
966 if friendorfoe(r.Header.Get("Accept")) {
967 j, ok := gimmejonk(xid)
968 if ok {
969 trackback(xid, r)
970 w.Header().Set("Content-Type", theonetruename)
971 w.Write(j)
972 } else {
973 http.NotFound(w, r)
974 }
975 return
976 }
977 honk := getxonk(user.ID, xid)
978 if honk == nil {
979 http.NotFound(w, r)
980 return
981 }
982 u := login.GetUserInfo(r)
983 if u != nil && u.UserID != user.ID {
984 u = nil
985 }
986 if !honk.Public {
987 if u == nil {
988 http.NotFound(w, r)
989 return
990
991 }
992 templinfo := getInfo(r)
993 templinfo["ServerMessage"] = "one honk maybe more"
994 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
995 honkpage(w, u, []*Honk{honk}, templinfo)
996 return
997 }
998 rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0)
999 reversehonks(rawhonks)
1000 var honks []*Honk
1001 for _, h := range rawhonks {
1002 if h.XID == xid && len(honks) != 0 {
1003 h.Style += " glow"
1004 }
1005 if h.Public && (h.Whofore == 2 || h.IsAcked()) {
1006 honks = append(honks, h)
1007 }
1008 }
1009
1010 templinfo := getInfo(r)
1011 templinfo["ServerMessage"] = "one honk maybe more"
1012 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1013 honkpage(w, u, honks, templinfo)
1014}
1015
1016func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo map[string]interface{}) {
1017 var userid int64 = -1
1018 if u != nil {
1019 userid = u.UserID
1020 }
1021 reverbolate(userid, honks)
1022 templinfo["Honks"] = honks
1023 if templinfo["TopHID"] == nil {
1024 if len(honks) > 0 {
1025 templinfo["TopHID"] = honks[0].ID
1026 } else {
1027 templinfo["TopHID"] = 0
1028 }
1029 }
1030 if u == nil {
1031 w.Header().Set("Cache-Control", "max-age=60")
1032 }
1033 err := readviews.Execute(w, "honkpage.html", templinfo)
1034 if err != nil {
1035 log.Print(err)
1036 }
1037}
1038
1039func saveuser(w http.ResponseWriter, r *http.Request) {
1040 whatabout := r.FormValue("whatabout")
1041 u := login.GetUserInfo(r)
1042 db := opendatabase()
1043 var options UserOptions
1044 if r.FormValue("skinny") == "skinny" {
1045 options.SkinnyCSS = true
1046 }
1047 j, err := jsonify(options)
1048 if err == nil {
1049 _, err = db.Exec("update users set about = ?, options = ? where username = ?", whatabout, j, u.Username)
1050 }
1051 if err != nil {
1052 log.Printf("error bouting what: %s", err)
1053 }
1054 somenamedusers.Clear(u.Username)
1055 somenumberedusers.Clear(u.UserID)
1056
1057 http.Redirect(w, r, "/account", http.StatusSeeOther)
1058}
1059
1060func submitbonk(w http.ResponseWriter, r *http.Request) {
1061 xid := r.FormValue("xid")
1062 userinfo := login.GetUserInfo(r)
1063 user, _ := butwhatabout(userinfo.Username)
1064
1065 log.Printf("bonking %s", xid)
1066
1067 xonk := getxonk(userinfo.UserID, xid)
1068 if xonk == nil {
1069 return
1070 }
1071 if !xonk.Public {
1072 return
1073 }
1074 if xonk.IsBonked() {
1075 return
1076 }
1077 donksforhonks([]*Honk{xonk})
1078
1079 _, err := stmtUpdateFlags.Exec(flagIsBonked, xonk.ID)
1080 if err != nil {
1081 log.Printf("error acking bonk: %s", err)
1082 }
1083
1084 oonker := xonk.Oonker
1085 if oonker == "" {
1086 oonker = xonk.Honker
1087 }
1088 dt := time.Now().UTC()
1089 bonk := &Honk{
1090 UserID: userinfo.UserID,
1091 Username: userinfo.Username,
1092 What: "bonk",
1093 Honker: user.URL,
1094 Oonker: oonker,
1095 XID: xonk.XID,
1096 RID: xonk.RID,
1097 Noise: xonk.Noise,
1098 Precis: xonk.Precis,
1099 URL: xonk.URL,
1100 Date: dt,
1101 Donks: xonk.Donks,
1102 Whofore: 2,
1103 Convoy: xonk.Convoy,
1104 Audience: []string{thewholeworld, oonker},
1105 Public: true,
1106 Format: "html",
1107 Place: xonk.Place,
1108 Onts: xonk.Onts,
1109 Time: xonk.Time,
1110 }
1111
1112 err = savehonk(bonk)
1113 if err != nil {
1114 log.Printf("uh oh")
1115 return
1116 }
1117
1118 go honkworldwide(user, bonk)
1119
1120 if r.FormValue("js") != "1" {
1121 templinfo := getInfo(r)
1122 templinfo["ServerMessage"] = "Bonked!"
1123 err = readviews.Execute(w, "msg.html", templinfo)
1124 if err != nil {
1125 log.Print(err)
1126 }
1127 }
1128}
1129
1130func sendzonkofsorts(xonk *Honk, user *WhatAbout, what string) {
1131 zonk := &Honk{
1132 What: what,
1133 XID: xonk.XID,
1134 Date: time.Now().UTC(),
1135 Audience: oneofakind(xonk.Audience),
1136 }
1137 zonk.Public = loudandproud(zonk.Audience)
1138
1139 log.Printf("announcing %sed honk: %s", what, xonk.XID)
1140 go honkworldwide(user, zonk)
1141}
1142
1143func zonkit(w http.ResponseWriter, r *http.Request) {
1144 wherefore := r.FormValue("wherefore")
1145 what := r.FormValue("what")
1146 userinfo := login.GetUserInfo(r)
1147 user, _ := butwhatabout(userinfo.Username)
1148
1149 if wherefore == "save" {
1150 xonk := getxonk(userinfo.UserID, what)
1151 if xonk != nil {
1152 _, err := stmtUpdateFlags.Exec(flagIsSaved, xonk.ID)
1153 if err != nil {
1154 log.Printf("error saving: %s", err)
1155 }
1156 }
1157 return
1158 }
1159
1160 if wherefore == "unsave" {
1161 xonk := getxonk(userinfo.UserID, what)
1162 if xonk != nil {
1163 _, err := stmtClearFlags.Exec(flagIsSaved, xonk.ID)
1164 if err != nil {
1165 log.Printf("error unsaving: %s", err)
1166 }
1167 }
1168 return
1169 }
1170
1171 // my hammer is too big, oh well
1172 defer oldjonks.Flush()
1173
1174 if wherefore == "ack" {
1175 xonk := getxonk(userinfo.UserID, what)
1176 if xonk != nil && !xonk.IsAcked() {
1177 _, err := stmtUpdateFlags.Exec(flagIsAcked, xonk.ID)
1178 if err != nil {
1179 log.Printf("error acking: %s", err)
1180 }
1181 sendzonkofsorts(xonk, user, "ack")
1182 }
1183 return
1184 }
1185
1186 if wherefore == "deack" {
1187 xonk := getxonk(userinfo.UserID, what)
1188 if xonk != nil && xonk.IsAcked() {
1189 _, err := stmtClearFlags.Exec(flagIsAcked, xonk.ID)
1190 if err != nil {
1191 log.Printf("error deacking: %s", err)
1192 }
1193 sendzonkofsorts(xonk, user, "deack")
1194 }
1195 return
1196 }
1197
1198 if wherefore == "unbonk" {
1199 xonk := getbonk(userinfo.UserID, what)
1200 if xonk != nil {
1201 deletehonk(xonk.ID)
1202 xonk = getxonk(userinfo.UserID, what)
1203 _, err := stmtClearFlags.Exec(flagIsBonked, xonk.ID)
1204 if err != nil {
1205 log.Printf("error unbonking: %s", err)
1206 }
1207 sendzonkofsorts(xonk, user, "unbonk")
1208 }
1209 return
1210 }
1211
1212 if wherefore == "untag" {
1213 xonk := getxonk(userinfo.UserID, what)
1214 if xonk != nil {
1215 _, err := stmtUpdateFlags.Exec(flagIsUntagged, xonk.ID)
1216 if err != nil {
1217 log.Printf("error untagging: %s", err)
1218 }
1219 }
1220 var badparents map[string]bool
1221 untagged.GetAndLock(userinfo.UserID, &badparents)
1222 badparents[what] = true
1223 untagged.Unlock()
1224 return
1225 }
1226
1227 log.Printf("zonking %s %s", wherefore, what)
1228 if wherefore == "zonk" {
1229 xonk := getxonk(userinfo.UserID, what)
1230 if xonk != nil {
1231 deletehonk(xonk.ID)
1232 if xonk.Whofore == 2 || xonk.Whofore == 3 {
1233 sendzonkofsorts(xonk, user, "zonk")
1234 }
1235 }
1236 }
1237 _, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
1238 if err != nil {
1239 log.Printf("error saving zonker: %s", err)
1240 return
1241 }
1242}
1243
1244func edithonkpage(w http.ResponseWriter, r *http.Request) {
1245 u := login.GetUserInfo(r)
1246 user, _ := butwhatabout(u.Username)
1247 xid := r.FormValue("xid")
1248 honk := getxonk(u.UserID, xid)
1249 if !canedithonk(user, honk) {
1250 http.Error(w, "no editing that please", http.StatusInternalServerError)
1251 return
1252 }
1253
1254 noise := honk.Noise
1255
1256 honks := []*Honk{honk}
1257 donksforhonks(honks)
1258 reverbolate(u.UserID, honks)
1259 templinfo := getInfo(r)
1260 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1261 templinfo["Honks"] = honks
1262 templinfo["Noise"] = noise
1263 templinfo["SavedPlace"] = honk.Place
1264 templinfo["ServerMessage"] = "honk edit"
1265 templinfo["IsPreview"] = true
1266 templinfo["UpdateXID"] = honk.XID
1267 if len(honk.Donks) > 0 {
1268 templinfo["SavedFile"] = honk.Donks[0].XID
1269 }
1270 err := readviews.Execute(w, "honkpage.html", templinfo)
1271 if err != nil {
1272 log.Print(err)
1273 }
1274}
1275
1276func newhonkpage(w http.ResponseWriter, r *http.Request) {
1277 u := login.GetUserInfo(r)
1278 rid := r.FormValue("rid")
1279 noise := ""
1280
1281 xonk := getxonk(u.UserID, rid)
1282 if xonk != nil {
1283 _, replto := handles(xonk.Honker)
1284 if replto != "" {
1285 noise = "@" + replto + " "
1286 }
1287 }
1288
1289 templinfo := getInfo(r)
1290 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1291 templinfo["InReplyTo"] = rid
1292 templinfo["Noise"] = noise
1293 templinfo["ServerMessage"] = "compose honk"
1294 templinfo["IsPreview"] = true
1295 err := readviews.Execute(w, "honkpage.html", templinfo)
1296 if err != nil {
1297 log.Print(err)
1298 }
1299}
1300
1301func canedithonk(user *WhatAbout, honk *Honk) bool {
1302 if honk == nil || honk.Honker != user.URL || honk.What == "bonk" {
1303 return false
1304 }
1305 return true
1306}
1307
1308// what a hot mess this function is
1309func submithonk(w http.ResponseWriter, r *http.Request) {
1310 rid := r.FormValue("rid")
1311 noise := r.FormValue("noise")
1312
1313 userinfo := login.GetUserInfo(r)
1314 user, _ := butwhatabout(userinfo.Username)
1315
1316 dt := time.Now().UTC()
1317 updatexid := r.FormValue("updatexid")
1318 var honk *Honk
1319 if updatexid != "" {
1320 honk = getxonk(userinfo.UserID, updatexid)
1321 if !canedithonk(user, honk) {
1322 http.Error(w, "no editing that please", http.StatusInternalServerError)
1323 return
1324 }
1325 honk.Date = dt
1326 honk.What = "update"
1327 honk.Format = "markdown"
1328 } else {
1329 xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, xfiltrate())
1330 what := "honk"
1331 if rid != "" {
1332 what = "tonk"
1333 }
1334 honk = &Honk{
1335 UserID: userinfo.UserID,
1336 Username: userinfo.Username,
1337 What: what,
1338 Honker: user.URL,
1339 XID: xid,
1340 Date: dt,
1341 Format: "markdown",
1342 }
1343 }
1344
1345 noise = strings.Replace(noise, "\r", "", -1)
1346 noise = quickrename(noise, userinfo.UserID)
1347 noise = hooterize(noise)
1348 honk.Noise = noise
1349 translate(honk, false)
1350
1351 var convoy string
1352 if rid != "" {
1353 xonk := getxonk(userinfo.UserID, rid)
1354 if xonk != nil {
1355 if xonk.Public {
1356 honk.Audience = append(honk.Audience, xonk.Audience...)
1357 }
1358 convoy = xonk.Convoy
1359 } else {
1360 xonkaud, c := whosthere(rid)
1361 honk.Audience = append(honk.Audience, xonkaud...)
1362 convoy = c
1363 }
1364 for i, a := range honk.Audience {
1365 if a == thewholeworld {
1366 honk.Audience[0], honk.Audience[i] = honk.Audience[i], honk.Audience[0]
1367 break
1368 }
1369 }
1370 honk.RID = rid
1371 } else {
1372 honk.Audience = []string{thewholeworld}
1373 }
1374 if honk.Noise != "" && honk.Noise[0] == '@' {
1375 honk.Audience = append(grapevine(honk.Noise), honk.Audience...)
1376 } else {
1377 honk.Audience = append(honk.Audience, grapevine(honk.Noise)...)
1378 }
1379
1380 if convoy == "" {
1381 convoy = "data:,electrichonkytonk-" + xfiltrate()
1382 }
1383 butnottooloud(honk.Audience)
1384 honk.Audience = oneofakind(honk.Audience)
1385 if len(honk.Audience) == 0 {
1386 log.Printf("honk to nowhere")
1387 http.Error(w, "honk to nowhere...", http.StatusNotFound)
1388 return
1389 }
1390 honk.Public = loudandproud(honk.Audience)
1391 honk.Convoy = convoy
1392
1393 donkxid := r.FormValue("donkxid")
1394 if donkxid == "" {
1395 file, filehdr, err := r.FormFile("donk")
1396 if err == nil {
1397 var buf bytes.Buffer
1398 io.Copy(&buf, file)
1399 file.Close()
1400 data := buf.Bytes()
1401 xid := xfiltrate()
1402 var media, name string
1403 img, err := shrinkit(data)
1404 if err == nil {
1405 data = img.Data
1406 format := img.Format
1407 media = "image/" + format
1408 if format == "jpeg" {
1409 format = "jpg"
1410 }
1411 name = xid + "." + format
1412 xid = name
1413 } else {
1414 ct := http.DetectContentType(data)
1415 switch ct {
1416 case "application/pdf":
1417 maxsize := 1000000
1418 if len(data) > maxsize {
1419 log.Printf("bad image: %s too much pdf: %d", err, len(data))
1420 http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
1421 return
1422 }
1423 media = ct
1424 xid += ".pdf"
1425 name = filehdr.Filename
1426 if name == "" {
1427 name = xid
1428 }
1429 default:
1430 maxsize := 100000
1431 if len(data) > maxsize {
1432 log.Printf("bad image: %s too much text: %d", err, len(data))
1433 http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
1434 return
1435 }
1436 for i := 0; i < len(data); i++ {
1437 if data[i] < 32 && data[i] != '\t' && data[i] != '\r' && data[i] != '\n' {
1438 log.Printf("bad image: %s not text: %d", err, data[i])
1439 http.Error(w, "didn't like your attachment", http.StatusUnsupportedMediaType)
1440 return
1441 }
1442 }
1443 media = "text/plain"
1444 xid += ".txt"
1445 name = filehdr.Filename
1446 if name == "" {
1447 name = xid
1448 }
1449 }
1450 }
1451 desc := strings.TrimSpace(r.FormValue("donkdesc"))
1452 if desc == "" {
1453 desc = name
1454 }
1455 url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
1456 fileid, err := savefile(xid, name, desc, url, media, true, data)
1457 if err != nil {
1458 log.Printf("unable to save image: %s", err)
1459 return
1460 }
1461 d := &Donk{
1462 FileID: fileid,
1463 XID: xid,
1464 Desc: desc,
1465 URL: url,
1466 Local: true,
1467 }
1468 honk.Donks = append(honk.Donks, d)
1469 donkxid = xid
1470 }
1471 } else {
1472 xid := donkxid
1473 url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
1474 donk := finddonk(url)
1475 if donk != nil {
1476 honk.Donks = append(honk.Donks, donk)
1477 } else {
1478 log.Printf("can't find file: %s", xid)
1479 }
1480 }
1481 herd := herdofemus(noise)
1482 for _, e := range herd {
1483 donk := savedonk(e.ID, e.Name, e.Name, "image/png", true)
1484 if donk != nil {
1485 donk.Name = e.Name
1486 honk.Donks = append(honk.Donks, donk)
1487 }
1488 }
1489 memetize(honk)
1490 imaginate(honk)
1491
1492 placename := strings.TrimSpace(r.FormValue("placename"))
1493 placelat := strings.TrimSpace(r.FormValue("placelat"))
1494 placelong := strings.TrimSpace(r.FormValue("placelong"))
1495 placeurl := strings.TrimSpace(r.FormValue("placeurl"))
1496 if placename != "" || placelat != "" || placelong != "" || placeurl != "" {
1497 p := new(Place)
1498 p.Name = placename
1499 p.Latitude, _ = strconv.ParseFloat(placelat, 64)
1500 p.Longitude, _ = strconv.ParseFloat(placelong, 64)
1501 p.Url = placeurl
1502 honk.Place = p
1503 }
1504 timestart := strings.TrimSpace(r.FormValue("timestart"))
1505 if timestart != "" {
1506 t := new(Time)
1507 now := time.Now().Local()
1508 for _, layout := range []string{"2006-01-02 3:04pm", "2006-01-02 15:04", "3:04pm", "15:04"} {
1509 start, err := time.ParseInLocation(layout, timestart, now.Location())
1510 if err == nil {
1511 if start.Year() == 0 {
1512 start = time.Date(now.Year(), now.Month(), now.Day(), start.Hour(), start.Minute(), 0, 0, now.Location())
1513 }
1514 t.StartTime = start
1515 break
1516 }
1517 }
1518 timeend := r.FormValue("timeend")
1519 dur := parseDuration(timeend)
1520 if dur != 0 {
1521 t.Duration = Duration(dur)
1522 }
1523 if !t.StartTime.IsZero() {
1524 honk.What = "event"
1525 honk.Time = t
1526 }
1527 }
1528
1529 if honk.Public {
1530 honk.Whofore = 2
1531 } else {
1532 honk.Whofore = 3
1533 }
1534
1535 // back to markdown
1536 honk.Noise = noise
1537
1538 if r.FormValue("preview") == "preview" {
1539 honks := []*Honk{honk}
1540 reverbolate(userinfo.UserID, honks)
1541 templinfo := getInfo(r)
1542 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1543 templinfo["Honks"] = honks
1544 templinfo["InReplyTo"] = r.FormValue("rid")
1545 templinfo["Noise"] = r.FormValue("noise")
1546 templinfo["SavedFile"] = donkxid
1547 templinfo["IsPreview"] = true
1548 templinfo["ServerMessage"] = "honk preview"
1549 err := readviews.Execute(w, "honkpage.html", templinfo)
1550 if err != nil {
1551 log.Print(err)
1552 }
1553 return
1554 }
1555
1556 if updatexid != "" {
1557 updatehonk(honk)
1558 oldjonks.Clear(honk.XID)
1559 } else {
1560 err := savehonk(honk)
1561 if err != nil {
1562 log.Printf("uh oh")
1563 return
1564 }
1565 }
1566
1567 // reload for consistency
1568 honk.Donks = nil
1569 donksforhonks([]*Honk{honk})
1570
1571 go honkworldwide(user, honk)
1572
1573 http.Redirect(w, r, honk.XID[len(serverName)+8:], http.StatusSeeOther)
1574}
1575
1576func showhonkers(w http.ResponseWriter, r *http.Request) {
1577 userinfo := login.GetUserInfo(r)
1578 templinfo := getInfo(r)
1579 templinfo["Honkers"] = gethonkers(userinfo.UserID)
1580 templinfo["HonkerCSRF"] = login.GetCSRF("submithonker", r)
1581 err := readviews.Execute(w, "honkers.html", templinfo)
1582 if err != nil {
1583 log.Print(err)
1584 }
1585}
1586
1587var combocache = cache.New(cache.Options{Filler: func(userid int64) ([]string, bool) {
1588 honkers := gethonkers(userid)
1589 var combos []string
1590 for _, h := range honkers {
1591 combos = append(combos, h.Combos...)
1592 }
1593 for i, c := range combos {
1594 if c == "-" {
1595 combos[i] = ""
1596 }
1597 }
1598 combos = oneofakind(combos)
1599 sort.Strings(combos)
1600 return combos, true
1601}, Invalidator: &honkerinvalidator})
1602
1603func showcombos(w http.ResponseWriter, r *http.Request) {
1604 userinfo := login.GetUserInfo(r)
1605 var combos []string
1606 combocache.Get(userinfo.UserID, &combos)
1607 templinfo := getInfo(r)
1608 err := readviews.Execute(w, "combos.html", templinfo)
1609 if err != nil {
1610 log.Print(err)
1611 }
1612}
1613
1614func submithonker(w http.ResponseWriter, r *http.Request) {
1615 u := login.GetUserInfo(r)
1616 name := strings.TrimSpace(r.FormValue("name"))
1617 url := strings.TrimSpace(r.FormValue("url"))
1618 peep := r.FormValue("peep")
1619 combos := strings.TrimSpace(r.FormValue("combos"))
1620 combos = " " + combos + " "
1621 honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
1622
1623 defer honkerinvalidator.Clear(u.UserID)
1624
1625 if honkerid > 0 {
1626 goodbye := r.FormValue("goodbye")
1627 if goodbye == "F" {
1628 db := opendatabase()
1629 row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('sub')",
1630 honkerid, u.UserID)
1631 err := row.Scan(&url)
1632 if err != nil {
1633 log.Printf("can't get honker xid: %s", err)
1634 return
1635 }
1636 log.Printf("unsubscribing from %s", url)
1637 user, _ := butwhatabout(u.Username)
1638 _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, name, "sub")
1639 if err != nil {
1640 log.Printf("error updating honker: %s", err)
1641 return
1642 }
1643 go itakeitallback(user, url)
1644
1645 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1646 return
1647 }
1648 if goodbye == "X" {
1649 var owner string
1650 db := opendatabase()
1651 row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')",
1652 honkerid, u.UserID)
1653 err := row.Scan(&url, &owner)
1654 if err != nil {
1655 log.Printf("can't get honker xid: %s", err)
1656 return
1657 }
1658 log.Printf("resubscribing to %s", url)
1659 user, _ := butwhatabout(u.Username)
1660 _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "unsub")
1661 if err == nil {
1662 _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "peep")
1663 }
1664 if err != nil {
1665 log.Printf("error updating honker: %s", err)
1666 return
1667 }
1668 go subsub(user, url, owner)
1669
1670 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1671 return
1672 }
1673 _, err := stmtUpdateHonker.Exec(name, combos, honkerid, u.UserID)
1674 if err != nil {
1675 log.Printf("update honker err: %s", err)
1676 return
1677 }
1678 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1679 return
1680 }
1681
1682 if url == "" {
1683 http.Error(w, "subscribing to nothing?", http.StatusInternalServerError)
1684 return
1685 }
1686
1687 flavor := "presub"
1688 if peep == "peep" {
1689 flavor = "peep"
1690 }
1691
1692 if url[0] == '#' {
1693 flavor = "peep"
1694 if name == "" {
1695 name = url
1696 }
1697 _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url)
1698 if err != nil {
1699 log.Print(err)
1700 return
1701 }
1702 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1703 return
1704 }
1705
1706 info, err := investigate(url)
1707 if err != nil {
1708 http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
1709 log.Printf("failed to investigate honker: %s", err)
1710 return
1711 }
1712 url = info.XID
1713
1714 db := opendatabase()
1715 row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)
1716 var x string
1717 err = row.Scan(&x)
1718 if err != sql.ErrNoRows {
1719 http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError)
1720 if err != nil {
1721 log.Printf("honker scan err: %s", err)
1722 }
1723 return
1724 }
1725
1726 if name == "" {
1727 name = info.Name
1728 }
1729 _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner)
1730 if err != nil {
1731 log.Print(err)
1732 return
1733 }
1734 if flavor == "presub" {
1735 user, _ := butwhatabout(u.Username)
1736 go subsub(user, url, info.Owner)
1737 }
1738 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1739}
1740
1741func hfcspage(w http.ResponseWriter, r *http.Request) {
1742 userinfo := login.GetUserInfo(r)
1743
1744 filters := getfilters(userinfo.UserID, filtAny)
1745
1746 templinfo := getInfo(r)
1747 templinfo["Filters"] = filters
1748 templinfo["FilterCSRF"] = login.GetCSRF("filter", r)
1749 err := readviews.Execute(w, "hfcs.html", templinfo)
1750 if err != nil {
1751 log.Print(err)
1752 }
1753}
1754
1755func savehfcs(w http.ResponseWriter, r *http.Request) {
1756 userinfo := login.GetUserInfo(r)
1757 itsok := r.FormValue("itsok")
1758 if itsok == "iforgiveyou" {
1759 hfcsid, _ := strconv.ParseInt(r.FormValue("hfcsid"), 10, 0)
1760 _, err := stmtDeleteFilter.Exec(userinfo.UserID, hfcsid)
1761 if err != nil {
1762 log.Printf("error deleting filter: %s", err)
1763 }
1764 filtcache.Clear(userinfo.UserID)
1765 http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
1766 return
1767 }
1768
1769 filt := new(Filter)
1770 filt.Name = strings.TrimSpace(r.FormValue("name"))
1771 filt.Date = time.Now().UTC()
1772 filt.Actor = strings.TrimSpace(r.FormValue("actor"))
1773 filt.IncludeAudience = r.FormValue("incaud") == "yes"
1774 filt.Text = strings.TrimSpace(r.FormValue("filttext"))
1775 filt.IsAnnounce = r.FormValue("isannounce") == "yes"
1776 filt.AnnounceOf = strings.TrimSpace(r.FormValue("announceof"))
1777 filt.Reject = r.FormValue("doreject") == "yes"
1778 filt.SkipMedia = r.FormValue("doskipmedia") == "yes"
1779 filt.Hide = r.FormValue("dohide") == "yes"
1780 filt.Collapse = r.FormValue("docollapse") == "yes"
1781 filt.Rewrite = strings.TrimSpace(r.FormValue("filtrewrite"))
1782 filt.Replace = strings.TrimSpace(r.FormValue("filtreplace"))
1783 if dur := parseDuration(r.FormValue("filtduration")); dur > 0 {
1784 filt.Expiration = time.Now().UTC().Add(dur)
1785 }
1786
1787 if filt.Actor == "" && filt.Text == "" {
1788 log.Printf("blank filter")
1789 return
1790 }
1791
1792 j, err := jsonify(filt)
1793 if err == nil {
1794 _, err = stmtSaveFilter.Exec(userinfo.UserID, j)
1795 }
1796 if err != nil {
1797 log.Printf("error saving filter: %s", err)
1798 }
1799
1800 filtcache.Clear(userinfo.UserID)
1801 http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
1802}
1803
1804func accountpage(w http.ResponseWriter, r *http.Request) {
1805 u := login.GetUserInfo(r)
1806 user, _ := butwhatabout(u.Username)
1807 templinfo := getInfo(r)
1808 templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
1809 templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
1810 templinfo["User"] = user
1811 err := readviews.Execute(w, "account.html", templinfo)
1812 if err != nil {
1813 log.Print(err)
1814 }
1815}
1816
1817func dochpass(w http.ResponseWriter, r *http.Request) {
1818 err := login.ChangePassword(w, r)
1819 if err != nil {
1820 log.Printf("error changing password: %s", err)
1821 }
1822 http.Redirect(w, r, "/account", http.StatusSeeOther)
1823}
1824
1825func fingerlicker(w http.ResponseWriter, r *http.Request) {
1826 orig := r.FormValue("resource")
1827
1828 log.Printf("finger lick: %s", orig)
1829
1830 if strings.HasPrefix(orig, "acct:") {
1831 orig = orig[5:]
1832 }
1833
1834 name := orig
1835 idx := strings.LastIndexByte(name, '/')
1836 if idx != -1 {
1837 name = name[idx+1:]
1838 if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
1839 log.Printf("foreign request rejected")
1840 name = ""
1841 }
1842 } else {
1843 idx = strings.IndexByte(name, '@')
1844 if idx != -1 {
1845 name = name[:idx]
1846 if name+"@"+serverName != orig {
1847 log.Printf("foreign request rejected")
1848 name = ""
1849 }
1850 }
1851 }
1852 user, err := butwhatabout(name)
1853 if err != nil {
1854 http.NotFound(w, r)
1855 return
1856 }
1857 if stealthmode(user.ID, r) {
1858 http.NotFound(w, r)
1859 return
1860 }
1861
1862 j := junk.New()
1863 j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName)
1864 j["aliases"] = []string{user.URL}
1865 l := junk.New()
1866 l["rel"] = "self"
1867 l["type"] = `application/activity+json`
1868 l["href"] = user.URL
1869 j["links"] = []junk.Junk{l}
1870
1871 w.Header().Set("Content-Type", "application/jrd+json")
1872 j.Write(w)
1873}
1874
1875func somedays() string {
1876 secs := 432000 + notrand.Int63n(432000)
1877 return fmt.Sprintf("%d", secs)
1878}
1879
1880func avatate(w http.ResponseWriter, r *http.Request) {
1881 n := r.FormValue("a")
1882 a := avatar(n)
1883 w.Header().Set("Cache-Control", "max-age="+somedays())
1884 w.Write(a)
1885}
1886
1887func serveasset(w http.ResponseWriter, r *http.Request) {
1888 w.Header().Set("Cache-Control", "max-age=7776000")
1889 dir := viewDir
1890 if r.URL.Path == "/local.css" {
1891 dir = dataDir
1892 }
1893 http.ServeFile(w, r, dir+"/views"+r.URL.Path)
1894}
1895func servehelp(w http.ResponseWriter, r *http.Request) {
1896 name := mux.Vars(r)["name"]
1897 w.Header().Set("Cache-Control", "max-age=3600")
1898 http.ServeFile(w, r, viewDir+"/docs/"+name)
1899}
1900func servehtml(w http.ResponseWriter, r *http.Request) {
1901 u := login.GetUserInfo(r)
1902 templinfo := getInfo(r)
1903 templinfo["AboutMsg"] = aboutMsg
1904 templinfo["LoginMsg"] = loginMsg
1905 templinfo["HonkVersion"] = softwareVersion
1906 if r.URL.Path == "/about" {
1907 templinfo["Sensors"] = getSensors()
1908 }
1909 if u == nil {
1910 w.Header().Set("Cache-Control", "max-age=60")
1911 }
1912 err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
1913 if err != nil {
1914 log.Print(err)
1915 }
1916}
1917func serveemu(w http.ResponseWriter, r *http.Request) {
1918 xid := mux.Vars(r)["xid"]
1919 w.Header().Set("Cache-Control", "max-age="+somedays())
1920 http.ServeFile(w, r, dataDir+"/emus/"+xid)
1921}
1922func servememe(w http.ResponseWriter, r *http.Request) {
1923 xid := mux.Vars(r)["xid"]
1924 w.Header().Set("Cache-Control", "max-age="+somedays())
1925 http.ServeFile(w, r, dataDir+"/memes/"+xid)
1926}
1927
1928func servefile(w http.ResponseWriter, r *http.Request) {
1929 xid := mux.Vars(r)["xid"]
1930 row := stmtGetFileData.QueryRow(xid)
1931 var media string
1932 var data []byte
1933 err := row.Scan(&media, &data)
1934 if err != nil {
1935 log.Printf("error loading file: %s", err)
1936 http.NotFound(w, r)
1937 return
1938 }
1939 w.Header().Set("Content-Type", media)
1940 w.Header().Set("X-Content-Type-Options", "nosniff")
1941 w.Header().Set("Cache-Control", "max-age="+somedays())
1942 w.Write(data)
1943}
1944
1945func nomoroboto(w http.ResponseWriter, r *http.Request) {
1946 io.WriteString(w, "User-agent: *\n")
1947 io.WriteString(w, "Disallow: /a\n")
1948 io.WriteString(w, "Disallow: /d\n")
1949 io.WriteString(w, "Disallow: /meme\n")
1950 io.WriteString(w, "Disallow: /o\n")
1951 for _, u := range allusers() {
1952 fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
1953 }
1954}
1955
1956func webhydra(w http.ResponseWriter, r *http.Request) {
1957 u := login.GetUserInfo(r)
1958 userid := u.UserID
1959 templinfo := getInfo(r)
1960 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1961 page := r.FormValue("page")
1962
1963 wanted, _ := strconv.ParseInt(r.FormValue("tophid"), 10, 0)
1964
1965 var honks []*Honk
1966 switch page {
1967 case "atme":
1968 honks = gethonksforme(userid, wanted)
1969 honks = osmosis(honks, userid, false)
1970 templinfo["ServerMessage"] = "at me!"
1971 case "home":
1972 honks = gethonksforuser(userid, wanted)
1973 honks = osmosis(honks, userid, true)
1974 templinfo["ServerMessage"] = serverMsg
1975 case "first":
1976 honks = gethonksforuserfirstclass(userid, wanted)
1977 honks = osmosis(honks, userid, true)
1978 templinfo["ServerMessage"] = "first class only"
1979 case "saved":
1980 honks = getsavedhonks(userid, wanted)
1981 templinfo["PageName"] = "saved"
1982 templinfo["ServerMessage"] = "saved honks"
1983 case "combo":
1984 c := r.FormValue("c")
1985 honks = gethonksbycombo(userid, c, wanted)
1986 honks = osmosis(honks, userid, false)
1987 templinfo["ServerMessage"] = "honks by combo: " + c
1988 case "convoy":
1989 c := r.FormValue("c")
1990 honks = gethonksbyconvoy(userid, c, wanted)
1991 honks = osmosis(honks, userid, false)
1992 templinfo["ServerMessage"] = "honks in convoy: " + c
1993 case "honker":
1994 xid := r.FormValue("xid")
1995 if strings.IndexByte(xid, '@') != -1 {
1996 xid = gofish(xid)
1997 }
1998 honks = gethonksbyxonker(userid, xid, wanted)
1999 msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, xid, xid)
2000 templinfo["ServerMessage"] = msg
2001 default:
2002 http.NotFound(w, r)
2003 }
2004 if len(honks) > 0 {
2005 templinfo["TopHID"] = honks[0].ID
2006 } else {
2007 templinfo["TopHID"] = wanted
2008 }
2009 reverbolate(userid, honks)
2010 templinfo["Honks"] = honks
2011 w.Header().Set("Content-Type", "text/html; charset=utf-8")
2012 err := readviews.Execute(w, "honkfrags.html", templinfo)
2013 if err != nil {
2014 log.Printf("frag error: %s", err)
2015 }
2016}
2017
2018func apihandler(w http.ResponseWriter, r *http.Request) {
2019 u := login.GetUserInfo(r)
2020 action := r.FormValue("action")
2021 log.Printf("api request '%s' on behalf of %s", action, u.Username)
2022 switch action {
2023 case "honk":
2024 submithonk(w, r)
2025 default:
2026 http.Error(w, "unknown action", http.StatusNotFound)
2027 }
2028}
2029
2030var endoftheworld = make(chan bool)
2031var readyalready = make(chan bool)
2032
2033func enditall() {
2034 sig := make(chan os.Signal)
2035 signal.Notify(sig, os.Interrupt)
2036 <-sig
2037 count := 0
2038 log.Printf("stopping...")
2039sendloop:
2040 for {
2041 select {
2042 case endoftheworld <- true:
2043 count++
2044 default:
2045 break sendloop
2046 }
2047 }
2048 log.Printf("waiting...")
2049 for i := 0; i < count; i++ {
2050 <-readyalready
2051 }
2052 log.Printf("apocalypse")
2053 os.Exit(0)
2054}
2055
2056func serve() {
2057 db := opendatabase()
2058 login.Init(db)
2059
2060 listener, err := openListener()
2061 if err != nil {
2062 log.Fatal(err)
2063 }
2064 startBackendServer()
2065 go enditall()
2066 go redeliverator()
2067 go tracker()
2068
2069 debug := false
2070 getconfig("debug", &debug)
2071 readviews = templates.Load(debug,
2072 viewDir+"/views/honkpage.html",
2073 viewDir+"/views/honkfrags.html",
2074 viewDir+"/views/honkers.html",
2075 viewDir+"/views/hfcs.html",
2076 viewDir+"/views/combos.html",
2077 viewDir+"/views/honkform.html",
2078 viewDir+"/views/honk.html",
2079 viewDir+"/views/account.html",
2080 viewDir+"/views/about.html",
2081 viewDir+"/views/funzone.html",
2082 viewDir+"/views/login.html",
2083 viewDir+"/views/xzone.html",
2084 viewDir+"/views/msg.html",
2085 viewDir+"/views/header.html",
2086 viewDir+"/views/onts.html",
2087 viewDir+"/views/honkpage.js",
2088 )
2089 if !debug {
2090 assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"}
2091 for _, s := range assets {
2092 savedassetparams[s] = getassetparam(s)
2093 }
2094 }
2095
2096 mux := mux.NewRouter()
2097 mux.Use(login.Checker)
2098
2099 mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler)))
2100
2101 posters := mux.Methods("POST").Subrouter()
2102 getters := mux.Methods("GET").Subrouter()
2103
2104 getters.HandleFunc("/", homepage)
2105 getters.HandleFunc("/home", homepage)
2106 getters.HandleFunc("/front", homepage)
2107 getters.HandleFunc("/events", homepage)
2108 getters.HandleFunc("/robots.txt", nomoroboto)
2109 getters.HandleFunc("/rss", showrss)
2110 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
2111 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showonehonk)
2112 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
2113 posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
2114 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
2115 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
2116 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
2117 getters.HandleFunc("/a", avatate)
2118 getters.HandleFunc("/o", thelistingoftheontologies)
2119 getters.HandleFunc("/o/{name:.+}", showontology)
2120 getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
2121 getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
2122 getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe)
2123 getters.HandleFunc("/.well-known/webfinger", fingerlicker)
2124
2125 getters.HandleFunc("/server", serveractor)
2126 posters.HandleFunc("/server/inbox", serverinbox)
2127
2128 getters.HandleFunc("/style.css", serveasset)
2129 getters.HandleFunc("/local.css", serveasset)
2130 getters.HandleFunc("/honkpage.js", serveasset)
2131 getters.HandleFunc("/about", servehtml)
2132 getters.HandleFunc("/login", servehtml)
2133 posters.HandleFunc("/dologin", login.LoginFunc)
2134 getters.HandleFunc("/logout", login.LogoutFunc)
2135 getters.HandleFunc("/help/{name:[[:alnum:]_.-]+}", servehelp)
2136
2137 loggedin := mux.NewRoute().Subrouter()
2138 loggedin.Use(login.Required)
2139 loggedin.HandleFunc("/first", homepage)
2140 loggedin.HandleFunc("/saved", homepage)
2141 loggedin.HandleFunc("/account", accountpage)
2142 loggedin.HandleFunc("/funzone", showfunzone)
2143 loggedin.HandleFunc("/chpass", dochpass)
2144 loggedin.HandleFunc("/atme", homepage)
2145 loggedin.HandleFunc("/hfcs", hfcspage)
2146 loggedin.HandleFunc("/xzone", xzone)
2147 loggedin.HandleFunc("/newhonk", newhonkpage)
2148 loggedin.HandleFunc("/edit", edithonkpage)
2149 loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk)))
2150 loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk)))
2151 loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
2152 loggedin.Handle("/savehfcs", login.CSRFWrap("filter", http.HandlerFunc(savehfcs)))
2153 loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
2154 loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
2155 loggedin.HandleFunc("/honkers", showhonkers)
2156 loggedin.HandleFunc("/h/{name:[[:alnum:]_.-]+}", showhonker)
2157 loggedin.HandleFunc("/h", showhonker)
2158 loggedin.HandleFunc("/c/{name:[[:alnum:]_.-]+}", showcombo)
2159 loggedin.HandleFunc("/c", showcombos)
2160 loggedin.HandleFunc("/t", showconvoy)
2161 loggedin.HandleFunc("/q", showsearch)
2162 loggedin.HandleFunc("/hydra", webhydra)
2163 loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
2164
2165 err = http.Serve(listener, mux)
2166 if err != nil {
2167 log.Fatal(err)
2168 }
2169}