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["UpdateXID"] = updatexid
1549 templinfo["ServerMessage"] = "honk preview"
1550 err := readviews.Execute(w, "honkpage.html", templinfo)
1551 if err != nil {
1552 log.Print(err)
1553 }
1554 return
1555 }
1556
1557 if updatexid != "" {
1558 updatehonk(honk)
1559 oldjonks.Clear(honk.XID)
1560 } else {
1561 err := savehonk(honk)
1562 if err != nil {
1563 log.Printf("uh oh")
1564 return
1565 }
1566 }
1567
1568 // reload for consistency
1569 honk.Donks = nil
1570 donksforhonks([]*Honk{honk})
1571
1572 go honkworldwide(user, honk)
1573
1574 http.Redirect(w, r, honk.XID[len(serverName)+8:], http.StatusSeeOther)
1575}
1576
1577func showhonkers(w http.ResponseWriter, r *http.Request) {
1578 userinfo := login.GetUserInfo(r)
1579 templinfo := getInfo(r)
1580 templinfo["Honkers"] = gethonkers(userinfo.UserID)
1581 templinfo["HonkerCSRF"] = login.GetCSRF("submithonker", r)
1582 err := readviews.Execute(w, "honkers.html", templinfo)
1583 if err != nil {
1584 log.Print(err)
1585 }
1586}
1587
1588var combocache = cache.New(cache.Options{Filler: func(userid int64) ([]string, bool) {
1589 honkers := gethonkers(userid)
1590 var combos []string
1591 for _, h := range honkers {
1592 combos = append(combos, h.Combos...)
1593 }
1594 for i, c := range combos {
1595 if c == "-" {
1596 combos[i] = ""
1597 }
1598 }
1599 combos = oneofakind(combos)
1600 sort.Strings(combos)
1601 return combos, true
1602}, Invalidator: &honkerinvalidator})
1603
1604func showcombos(w http.ResponseWriter, r *http.Request) {
1605 userinfo := login.GetUserInfo(r)
1606 var combos []string
1607 combocache.Get(userinfo.UserID, &combos)
1608 templinfo := getInfo(r)
1609 err := readviews.Execute(w, "combos.html", templinfo)
1610 if err != nil {
1611 log.Print(err)
1612 }
1613}
1614
1615func submithonker(w http.ResponseWriter, r *http.Request) {
1616 u := login.GetUserInfo(r)
1617 name := strings.TrimSpace(r.FormValue("name"))
1618 url := strings.TrimSpace(r.FormValue("url"))
1619 peep := r.FormValue("peep")
1620 combos := strings.TrimSpace(r.FormValue("combos"))
1621 combos = " " + combos + " "
1622 honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
1623
1624 defer honkerinvalidator.Clear(u.UserID)
1625
1626 if honkerid > 0 {
1627 goodbye := r.FormValue("goodbye")
1628 if goodbye == "F" {
1629 db := opendatabase()
1630 row := db.QueryRow("select xid from honkers where honkerid = ? and userid = ? and flavor in ('sub')",
1631 honkerid, u.UserID)
1632 err := row.Scan(&url)
1633 if err != nil {
1634 log.Printf("can't get honker xid: %s", err)
1635 return
1636 }
1637 log.Printf("unsubscribing from %s", url)
1638 user, _ := butwhatabout(u.Username)
1639 _, err = stmtUpdateFlavor.Exec("unsub", u.UserID, url, name, "sub")
1640 if err != nil {
1641 log.Printf("error updating honker: %s", err)
1642 return
1643 }
1644 go itakeitallback(user, url)
1645
1646 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1647 return
1648 }
1649 if goodbye == "X" {
1650 var owner string
1651 db := opendatabase()
1652 row := db.QueryRow("select xid, owner from honkers where honkerid = ? and userid = ? and flavor in ('unsub', 'peep')",
1653 honkerid, u.UserID)
1654 err := row.Scan(&url, &owner)
1655 if err != nil {
1656 log.Printf("can't get honker xid: %s", err)
1657 return
1658 }
1659 log.Printf("resubscribing to %s", url)
1660 user, _ := butwhatabout(u.Username)
1661 _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "unsub")
1662 if err == nil {
1663 _, err = stmtUpdateFlavor.Exec("presub", u.UserID, url, name, "peep")
1664 }
1665 if err != nil {
1666 log.Printf("error updating honker: %s", err)
1667 return
1668 }
1669 go subsub(user, url, owner)
1670
1671 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1672 return
1673 }
1674 _, err := stmtUpdateHonker.Exec(name, combos, honkerid, u.UserID)
1675 if err != nil {
1676 log.Printf("update honker err: %s", err)
1677 return
1678 }
1679 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1680 return
1681 }
1682
1683 if url == "" {
1684 http.Error(w, "subscribing to nothing?", http.StatusInternalServerError)
1685 return
1686 }
1687
1688 flavor := "presub"
1689 if peep == "peep" {
1690 flavor = "peep"
1691 }
1692
1693 if url[0] == '#' {
1694 flavor = "peep"
1695 if name == "" {
1696 name = url
1697 }
1698 _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url)
1699 if err != nil {
1700 log.Print(err)
1701 return
1702 }
1703 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1704 return
1705 }
1706
1707 info, err := investigate(url)
1708 if err != nil {
1709 http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError)
1710 log.Printf("failed to investigate honker: %s", err)
1711 return
1712 }
1713 url = info.XID
1714
1715 db := opendatabase()
1716 row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID)
1717 var x string
1718 err = row.Scan(&x)
1719 if err != sql.ErrNoRows {
1720 http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError)
1721 if err != nil {
1722 log.Printf("honker scan err: %s", err)
1723 }
1724 return
1725 }
1726
1727 if name == "" {
1728 name = info.Name
1729 }
1730 _, err = stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner)
1731 if err != nil {
1732 log.Print(err)
1733 return
1734 }
1735 if flavor == "presub" {
1736 user, _ := butwhatabout(u.Username)
1737 go subsub(user, url, info.Owner)
1738 }
1739 http.Redirect(w, r, "/honkers", http.StatusSeeOther)
1740}
1741
1742func hfcspage(w http.ResponseWriter, r *http.Request) {
1743 userinfo := login.GetUserInfo(r)
1744
1745 filters := getfilters(userinfo.UserID, filtAny)
1746
1747 templinfo := getInfo(r)
1748 templinfo["Filters"] = filters
1749 templinfo["FilterCSRF"] = login.GetCSRF("filter", r)
1750 err := readviews.Execute(w, "hfcs.html", templinfo)
1751 if err != nil {
1752 log.Print(err)
1753 }
1754}
1755
1756func savehfcs(w http.ResponseWriter, r *http.Request) {
1757 userinfo := login.GetUserInfo(r)
1758 itsok := r.FormValue("itsok")
1759 if itsok == "iforgiveyou" {
1760 hfcsid, _ := strconv.ParseInt(r.FormValue("hfcsid"), 10, 0)
1761 _, err := stmtDeleteFilter.Exec(userinfo.UserID, hfcsid)
1762 if err != nil {
1763 log.Printf("error deleting filter: %s", err)
1764 }
1765 filtcache.Clear(userinfo.UserID)
1766 http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
1767 return
1768 }
1769
1770 filt := new(Filter)
1771 filt.Name = strings.TrimSpace(r.FormValue("name"))
1772 filt.Date = time.Now().UTC()
1773 filt.Actor = strings.TrimSpace(r.FormValue("actor"))
1774 filt.IncludeAudience = r.FormValue("incaud") == "yes"
1775 filt.Text = strings.TrimSpace(r.FormValue("filttext"))
1776 filt.IsAnnounce = r.FormValue("isannounce") == "yes"
1777 filt.AnnounceOf = strings.TrimSpace(r.FormValue("announceof"))
1778 filt.Reject = r.FormValue("doreject") == "yes"
1779 filt.SkipMedia = r.FormValue("doskipmedia") == "yes"
1780 filt.Hide = r.FormValue("dohide") == "yes"
1781 filt.Collapse = r.FormValue("docollapse") == "yes"
1782 filt.Rewrite = strings.TrimSpace(r.FormValue("filtrewrite"))
1783 filt.Replace = strings.TrimSpace(r.FormValue("filtreplace"))
1784 if dur := parseDuration(r.FormValue("filtduration")); dur > 0 {
1785 filt.Expiration = time.Now().UTC().Add(dur)
1786 }
1787
1788 if filt.Actor == "" && filt.Text == "" {
1789 log.Printf("blank filter")
1790 return
1791 }
1792
1793 j, err := jsonify(filt)
1794 if err == nil {
1795 _, err = stmtSaveFilter.Exec(userinfo.UserID, j)
1796 }
1797 if err != nil {
1798 log.Printf("error saving filter: %s", err)
1799 }
1800
1801 filtcache.Clear(userinfo.UserID)
1802 http.Redirect(w, r, "/hfcs", http.StatusSeeOther)
1803}
1804
1805func accountpage(w http.ResponseWriter, r *http.Request) {
1806 u := login.GetUserInfo(r)
1807 user, _ := butwhatabout(u.Username)
1808 templinfo := getInfo(r)
1809 templinfo["UserCSRF"] = login.GetCSRF("saveuser", r)
1810 templinfo["LogoutCSRF"] = login.GetCSRF("logout", r)
1811 templinfo["User"] = user
1812 err := readviews.Execute(w, "account.html", templinfo)
1813 if err != nil {
1814 log.Print(err)
1815 }
1816}
1817
1818func dochpass(w http.ResponseWriter, r *http.Request) {
1819 err := login.ChangePassword(w, r)
1820 if err != nil {
1821 log.Printf("error changing password: %s", err)
1822 }
1823 http.Redirect(w, r, "/account", http.StatusSeeOther)
1824}
1825
1826func fingerlicker(w http.ResponseWriter, r *http.Request) {
1827 orig := r.FormValue("resource")
1828
1829 log.Printf("finger lick: %s", orig)
1830
1831 if strings.HasPrefix(orig, "acct:") {
1832 orig = orig[5:]
1833 }
1834
1835 name := orig
1836 idx := strings.LastIndexByte(name, '/')
1837 if idx != -1 {
1838 name = name[idx+1:]
1839 if fmt.Sprintf("https://%s/%s/%s", serverName, userSep, name) != orig {
1840 log.Printf("foreign request rejected")
1841 name = ""
1842 }
1843 } else {
1844 idx = strings.IndexByte(name, '@')
1845 if idx != -1 {
1846 name = name[:idx]
1847 if name+"@"+serverName != orig {
1848 log.Printf("foreign request rejected")
1849 name = ""
1850 }
1851 }
1852 }
1853 user, err := butwhatabout(name)
1854 if err != nil {
1855 http.NotFound(w, r)
1856 return
1857 }
1858 if stealthmode(user.ID, r) {
1859 http.NotFound(w, r)
1860 return
1861 }
1862
1863 j := junk.New()
1864 j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName)
1865 j["aliases"] = []string{user.URL}
1866 l := junk.New()
1867 l["rel"] = "self"
1868 l["type"] = `application/activity+json`
1869 l["href"] = user.URL
1870 j["links"] = []junk.Junk{l}
1871
1872 w.Header().Set("Content-Type", "application/jrd+json")
1873 j.Write(w)
1874}
1875
1876func somedays() string {
1877 secs := 432000 + notrand.Int63n(432000)
1878 return fmt.Sprintf("%d", secs)
1879}
1880
1881func avatate(w http.ResponseWriter, r *http.Request) {
1882 n := r.FormValue("a")
1883 a := avatar(n)
1884 w.Header().Set("Cache-Control", "max-age="+somedays())
1885 w.Write(a)
1886}
1887
1888func serveasset(w http.ResponseWriter, r *http.Request) {
1889 w.Header().Set("Cache-Control", "max-age=7776000")
1890 dir := viewDir
1891 if r.URL.Path == "/local.css" {
1892 dir = dataDir
1893 }
1894 http.ServeFile(w, r, dir+"/views"+r.URL.Path)
1895}
1896func servehelp(w http.ResponseWriter, r *http.Request) {
1897 name := mux.Vars(r)["name"]
1898 w.Header().Set("Cache-Control", "max-age=3600")
1899 http.ServeFile(w, r, viewDir+"/docs/"+name)
1900}
1901func servehtml(w http.ResponseWriter, r *http.Request) {
1902 u := login.GetUserInfo(r)
1903 templinfo := getInfo(r)
1904 templinfo["AboutMsg"] = aboutMsg
1905 templinfo["LoginMsg"] = loginMsg
1906 templinfo["HonkVersion"] = softwareVersion
1907 if r.URL.Path == "/about" {
1908 templinfo["Sensors"] = getSensors()
1909 }
1910 if u == nil {
1911 w.Header().Set("Cache-Control", "max-age=60")
1912 }
1913 err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo)
1914 if err != nil {
1915 log.Print(err)
1916 }
1917}
1918func serveemu(w http.ResponseWriter, r *http.Request) {
1919 xid := mux.Vars(r)["xid"]
1920 w.Header().Set("Cache-Control", "max-age="+somedays())
1921 http.ServeFile(w, r, dataDir+"/emus/"+xid)
1922}
1923func servememe(w http.ResponseWriter, r *http.Request) {
1924 xid := mux.Vars(r)["xid"]
1925 w.Header().Set("Cache-Control", "max-age="+somedays())
1926 http.ServeFile(w, r, dataDir+"/memes/"+xid)
1927}
1928
1929func servefile(w http.ResponseWriter, r *http.Request) {
1930 xid := mux.Vars(r)["xid"]
1931 row := stmtGetFileData.QueryRow(xid)
1932 var media string
1933 var data []byte
1934 err := row.Scan(&media, &data)
1935 if err != nil {
1936 log.Printf("error loading file: %s", err)
1937 http.NotFound(w, r)
1938 return
1939 }
1940 w.Header().Set("Content-Type", media)
1941 w.Header().Set("X-Content-Type-Options", "nosniff")
1942 w.Header().Set("Cache-Control", "max-age="+somedays())
1943 w.Write(data)
1944}
1945
1946func nomoroboto(w http.ResponseWriter, r *http.Request) {
1947 io.WriteString(w, "User-agent: *\n")
1948 io.WriteString(w, "Disallow: /a\n")
1949 io.WriteString(w, "Disallow: /d\n")
1950 io.WriteString(w, "Disallow: /meme\n")
1951 io.WriteString(w, "Disallow: /o\n")
1952 for _, u := range allusers() {
1953 fmt.Fprintf(w, "Disallow: /%s/%s/%s/\n", userSep, u.Username, honkSep)
1954 }
1955}
1956
1957func webhydra(w http.ResponseWriter, r *http.Request) {
1958 u := login.GetUserInfo(r)
1959 userid := u.UserID
1960 templinfo := getInfo(r)
1961 templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
1962 page := r.FormValue("page")
1963
1964 wanted, _ := strconv.ParseInt(r.FormValue("tophid"), 10, 0)
1965
1966 var honks []*Honk
1967 switch page {
1968 case "atme":
1969 honks = gethonksforme(userid, wanted)
1970 honks = osmosis(honks, userid, false)
1971 templinfo["ServerMessage"] = "at me!"
1972 case "home":
1973 honks = gethonksforuser(userid, wanted)
1974 honks = osmosis(honks, userid, true)
1975 templinfo["ServerMessage"] = serverMsg
1976 case "first":
1977 honks = gethonksforuserfirstclass(userid, wanted)
1978 honks = osmosis(honks, userid, true)
1979 templinfo["ServerMessage"] = "first class only"
1980 case "saved":
1981 honks = getsavedhonks(userid, wanted)
1982 templinfo["PageName"] = "saved"
1983 templinfo["ServerMessage"] = "saved honks"
1984 case "combo":
1985 c := r.FormValue("c")
1986 honks = gethonksbycombo(userid, c, wanted)
1987 honks = osmosis(honks, userid, false)
1988 templinfo["ServerMessage"] = "honks by combo: " + c
1989 case "convoy":
1990 c := r.FormValue("c")
1991 honks = gethonksbyconvoy(userid, c, wanted)
1992 honks = osmosis(honks, userid, false)
1993 templinfo["ServerMessage"] = "honks in convoy: " + c
1994 case "honker":
1995 xid := r.FormValue("xid")
1996 if strings.IndexByte(xid, '@') != -1 {
1997 xid = gofish(xid)
1998 }
1999 honks = gethonksbyxonker(userid, xid, wanted)
2000 msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, xid, xid)
2001 templinfo["ServerMessage"] = msg
2002 default:
2003 http.NotFound(w, r)
2004 }
2005 if len(honks) > 0 {
2006 templinfo["TopHID"] = honks[0].ID
2007 } else {
2008 templinfo["TopHID"] = wanted
2009 }
2010 reverbolate(userid, honks)
2011 templinfo["Honks"] = honks
2012 w.Header().Set("Content-Type", "text/html; charset=utf-8")
2013 err := readviews.Execute(w, "honkfrags.html", templinfo)
2014 if err != nil {
2015 log.Printf("frag error: %s", err)
2016 }
2017}
2018
2019func apihandler(w http.ResponseWriter, r *http.Request) {
2020 u := login.GetUserInfo(r)
2021 action := r.FormValue("action")
2022 log.Printf("api request '%s' on behalf of %s", action, u.Username)
2023 switch action {
2024 case "honk":
2025 submithonk(w, r)
2026 default:
2027 http.Error(w, "unknown action", http.StatusNotFound)
2028 }
2029}
2030
2031var endoftheworld = make(chan bool)
2032var readyalready = make(chan bool)
2033
2034func enditall() {
2035 sig := make(chan os.Signal)
2036 signal.Notify(sig, os.Interrupt)
2037 <-sig
2038 count := 0
2039 log.Printf("stopping...")
2040sendloop:
2041 for {
2042 select {
2043 case endoftheworld <- true:
2044 count++
2045 default:
2046 break sendloop
2047 }
2048 }
2049 log.Printf("waiting...")
2050 for i := 0; i < count; i++ {
2051 <-readyalready
2052 }
2053 log.Printf("apocalypse")
2054 os.Exit(0)
2055}
2056
2057func serve() {
2058 db := opendatabase()
2059 login.Init(db)
2060
2061 listener, err := openListener()
2062 if err != nil {
2063 log.Fatal(err)
2064 }
2065 startBackendServer()
2066 go enditall()
2067 go redeliverator()
2068 go tracker()
2069
2070 debug := false
2071 getconfig("debug", &debug)
2072 readviews = templates.Load(debug,
2073 viewDir+"/views/honkpage.html",
2074 viewDir+"/views/honkfrags.html",
2075 viewDir+"/views/honkers.html",
2076 viewDir+"/views/hfcs.html",
2077 viewDir+"/views/combos.html",
2078 viewDir+"/views/honkform.html",
2079 viewDir+"/views/honk.html",
2080 viewDir+"/views/account.html",
2081 viewDir+"/views/about.html",
2082 viewDir+"/views/funzone.html",
2083 viewDir+"/views/login.html",
2084 viewDir+"/views/xzone.html",
2085 viewDir+"/views/msg.html",
2086 viewDir+"/views/header.html",
2087 viewDir+"/views/onts.html",
2088 viewDir+"/views/honkpage.js",
2089 )
2090 if !debug {
2091 assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"}
2092 for _, s := range assets {
2093 savedassetparams[s] = getassetparam(s)
2094 }
2095 }
2096
2097 mux := mux.NewRouter()
2098 mux.Use(login.Checker)
2099
2100 mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler)))
2101
2102 posters := mux.Methods("POST").Subrouter()
2103 getters := mux.Methods("GET").Subrouter()
2104
2105 getters.HandleFunc("/", homepage)
2106 getters.HandleFunc("/home", homepage)
2107 getters.HandleFunc("/front", homepage)
2108 getters.HandleFunc("/events", homepage)
2109 getters.HandleFunc("/robots.txt", nomoroboto)
2110 getters.HandleFunc("/rss", showrss)
2111 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}", showuser)
2112 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/"+honkSep+"/{xid:[[:alnum:]]+}", showonehonk)
2113 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/rss", showrss)
2114 posters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/inbox", inbox)
2115 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/outbox", outbox)
2116 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/followers", emptiness)
2117 getters.HandleFunc("/"+userSep+"/{name:[[:alnum:]]+}/following", emptiness)
2118 getters.HandleFunc("/a", avatate)
2119 getters.HandleFunc("/o", thelistingoftheontologies)
2120 getters.HandleFunc("/o/{name:.+}", showontology)
2121 getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
2122 getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu)
2123 getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe)
2124 getters.HandleFunc("/.well-known/webfinger", fingerlicker)
2125
2126 getters.HandleFunc("/server", serveractor)
2127 posters.HandleFunc("/server/inbox", serverinbox)
2128
2129 getters.HandleFunc("/style.css", serveasset)
2130 getters.HandleFunc("/local.css", serveasset)
2131 getters.HandleFunc("/honkpage.js", serveasset)
2132 getters.HandleFunc("/about", servehtml)
2133 getters.HandleFunc("/login", servehtml)
2134 posters.HandleFunc("/dologin", login.LoginFunc)
2135 getters.HandleFunc("/logout", login.LogoutFunc)
2136 getters.HandleFunc("/help/{name:[[:alnum:]_.-]+}", servehelp)
2137
2138 loggedin := mux.NewRoute().Subrouter()
2139 loggedin.Use(login.Required)
2140 loggedin.HandleFunc("/first", homepage)
2141 loggedin.HandleFunc("/saved", homepage)
2142 loggedin.HandleFunc("/account", accountpage)
2143 loggedin.HandleFunc("/funzone", showfunzone)
2144 loggedin.HandleFunc("/chpass", dochpass)
2145 loggedin.HandleFunc("/atme", homepage)
2146 loggedin.HandleFunc("/hfcs", hfcspage)
2147 loggedin.HandleFunc("/xzone", xzone)
2148 loggedin.HandleFunc("/newhonk", newhonkpage)
2149 loggedin.HandleFunc("/edit", edithonkpage)
2150 loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk)))
2151 loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk)))
2152 loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit)))
2153 loggedin.Handle("/savehfcs", login.CSRFWrap("filter", http.HandlerFunc(savehfcs)))
2154 loggedin.Handle("/saveuser", login.CSRFWrap("saveuser", http.HandlerFunc(saveuser)))
2155 loggedin.Handle("/ximport", login.CSRFWrap("ximport", http.HandlerFunc(ximport)))
2156 loggedin.HandleFunc("/honkers", showhonkers)
2157 loggedin.HandleFunc("/h/{name:[[:alnum:]_.-]+}", showhonker)
2158 loggedin.HandleFunc("/h", showhonker)
2159 loggedin.HandleFunc("/c/{name:[[:alnum:]_.-]+}", showcombo)
2160 loggedin.HandleFunc("/c", showcombos)
2161 loggedin.HandleFunc("/t", showconvoy)
2162 loggedin.HandleFunc("/q", showsearch)
2163 loggedin.HandleFunc("/hydra", webhydra)
2164 loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
2165
2166 err = http.Serve(listener, mux)
2167 if err != nil {
2168 log.Fatal(err)
2169 }
2170}