|
|
|
@ -50,16 +50,18 @@ var honkSep = "h"
|
|
|
|
|
|
|
|
|
|
var develMode = false
|
|
|
|
|
|
|
|
|
|
func getuserstyle(u *login.UserInfo) template.CSS {
|
|
|
|
|
var allemus []Emu
|
|
|
|
|
|
|
|
|
|
func getuserstyle(u *login.UserInfo) template.HTMLAttr {
|
|
|
|
|
if u == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
user, _ := butwhatabout(u.Username)
|
|
|
|
|
css := template.CSS("")
|
|
|
|
|
class := template.HTMLAttr("")
|
|
|
|
|
if user.Options.SkinnyCSS {
|
|
|
|
|
css += "main { max-width: 700px; }\n"
|
|
|
|
|
class += `class="skinny"`
|
|
|
|
|
}
|
|
|
|
|
return css
|
|
|
|
|
return class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getmaplink(u *login.UserInfo) string {
|
|
|
|
@ -80,6 +82,7 @@ func getInfo(r *http.Request) map[string]interface{} {
|
|
|
|
|
templinfo["LocalStyleParam"] = getassetparam(dataDir + "/views/local.css")
|
|
|
|
|
templinfo["JSParam"] = getassetparam(viewDir + "/views/honkpage.js")
|
|
|
|
|
templinfo["LocalJSParam"] = getassetparam(dataDir + "/views/local.js")
|
|
|
|
|
templinfo["MiscJSParam"] = getassetparam(dataDir + "/views/misc.js")
|
|
|
|
|
templinfo["ServerName"] = serverName
|
|
|
|
|
templinfo["IconName"] = iconName
|
|
|
|
|
templinfo["UserSep"] = userSep
|
|
|
|
@ -118,6 +121,7 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
honks = gethonksforme(userid, 0)
|
|
|
|
|
honks = osmosis(honks, userid, false)
|
|
|
|
|
menewnone(userid)
|
|
|
|
|
templinfo["UserInfo"], _ = butwhatabout(u.Username)
|
|
|
|
|
case "/longago":
|
|
|
|
|
templinfo["ServerMessage"] = "long ago and far away!"
|
|
|
|
|
templinfo["PageName"] = "longago"
|
|
|
|
@ -147,6 +151,15 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
honkpage(w, u, honks, templinfo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func showemus(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
templinfo := getInfo(r)
|
|
|
|
|
templinfo["Emus"] = allemus
|
|
|
|
|
err := readviews.Execute(w, "emus.html", templinfo)
|
|
|
|
|
if err != nil {
|
|
|
|
|
elog.Print(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func showfunzone(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
var emunames, memenames []string
|
|
|
|
|
emuext := make(map[string]string)
|
|
|
|
@ -1111,11 +1124,6 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
} else {
|
|
|
|
|
options.SkinnyCSS = false
|
|
|
|
|
}
|
|
|
|
|
if r.FormValue("avahex") == "avahex" {
|
|
|
|
|
options.Avahex = true
|
|
|
|
|
} else {
|
|
|
|
|
options.Avahex = false
|
|
|
|
|
}
|
|
|
|
|
if r.FormValue("omitimages") == "omitimages" {
|
|
|
|
|
options.OmitImages = true
|
|
|
|
|
} else {
|
|
|
|
@ -1126,6 +1134,11 @@ func saveuser(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
} else {
|
|
|
|
|
options.MentionAll = false
|
|
|
|
|
}
|
|
|
|
|
if r.FormValue("inlineqts") == "inlineqts" {
|
|
|
|
|
options.InlineQuotes = true
|
|
|
|
|
} else {
|
|
|
|
|
options.InlineQuotes = false
|
|
|
|
|
}
|
|
|
|
|
if r.FormValue("maps") == "apple" {
|
|
|
|
|
options.MapLink = "apple"
|
|
|
|
|
} else {
|
|
|
|
@ -1317,21 +1330,6 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if wherefore == "wonk" {
|
|
|
|
|
xonk := getxonk(userinfo.UserID, what)
|
|
|
|
|
if xonk != nil {
|
|
|
|
|
_, err := stmtUpdateFlags.Exec(flagIsWonked, xonk.ID)
|
|
|
|
|
if err == nil {
|
|
|
|
|
guesses := r.FormValue("guesses")
|
|
|
|
|
_, err = stmtSaveMeta.Exec(xonk.ID, "guesses", guesses)
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
elog.Printf("error saving: %s", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// my hammer is too big, oh well
|
|
|
|
|
defer oldjonks.Flush()
|
|
|
|
|
|
|
|
|
@ -1433,7 +1431,7 @@ func edithonkpage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
templinfo["Noise"] = noise
|
|
|
|
|
templinfo["SavedPlace"] = honk.Place
|
|
|
|
|
if tm := honk.Time; tm != nil {
|
|
|
|
|
templinfo["ShowTime"] = ";"
|
|
|
|
|
templinfo["ShowTime"] = " "
|
|
|
|
|
templinfo["StartTime"] = tm.StartTime.Format("2006-01-02 15:04")
|
|
|
|
|
if tm.Duration != 0 {
|
|
|
|
|
templinfo["Duration"] = tm.Duration
|
|
|
|
@ -1607,10 +1605,6 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
|
|
|
|
|
if rid != "" {
|
|
|
|
|
what = "tonk"
|
|
|
|
|
}
|
|
|
|
|
wonkles := r.FormValue("wonkles")
|
|
|
|
|
if wonkles != "" {
|
|
|
|
|
what = "wonk"
|
|
|
|
|
}
|
|
|
|
|
honk = &Honk{
|
|
|
|
|
UserID: userinfo.UserID,
|
|
|
|
|
Username: userinfo.Username,
|
|
|
|
@ -1619,7 +1613,6 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
|
|
|
|
|
XID: xid,
|
|
|
|
|
Date: dt,
|
|
|
|
|
Format: format,
|
|
|
|
|
Wonkles: wonkles,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1649,7 +1642,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
|
|
|
|
|
honk.RID = rid
|
|
|
|
|
if xonk.Precis != "" && honk.Precis == "" {
|
|
|
|
|
honk.Precis = xonk.Precis
|
|
|
|
|
if !(strings.HasPrefix(honk.Precis, "DZ:") || strings.HasPrefix(honk.Precis, "re: re: re: ")) {
|
|
|
|
|
if !re_dangerous.MatchString(honk.Precis) {
|
|
|
|
|
honk.Precis = "re: " + honk.Precis
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1755,7 +1748,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
|
|
|
|
|
templinfo["Noise"] = r.FormValue("noise")
|
|
|
|
|
templinfo["SavedFile"] = donkxid
|
|
|
|
|
if tm := honk.Time; tm != nil {
|
|
|
|
|
templinfo["ShowTime"] = ";"
|
|
|
|
|
templinfo["ShowTime"] = " "
|
|
|
|
|
templinfo["StartTime"] = tm.StartTime.Format("2006-01-02 15:04")
|
|
|
|
|
if tm.Duration != 0 {
|
|
|
|
|
templinfo["Duration"] = tm.Duration
|
|
|
|
@ -2151,8 +2144,7 @@ func avatate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
loadAvatarColors()
|
|
|
|
|
}
|
|
|
|
|
n := r.FormValue("a")
|
|
|
|
|
hex := r.FormValue("hex") == "1"
|
|
|
|
|
a := genAvatar(n, hex)
|
|
|
|
|
a := genAvatar(n)
|
|
|
|
|
if !develMode {
|
|
|
|
|
w.Header().Set("Cache-Control", "max-age="+somedays())
|
|
|
|
|
}
|
|
|
|
@ -2462,6 +2454,37 @@ func bgmonitor() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addcspheaders(next http.Handler) http.Handler {
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.Header().Set("Content-Security-Policy", "default-src 'none'; script-src 'self'; connect-src 'self'; style-src 'self'; img-src 'self'; report-uri /csp-violation")
|
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func emuinit() {
|
|
|
|
|
var emunames []string
|
|
|
|
|
dir, err := os.Open(dataDir + "/emus")
|
|
|
|
|
if err == nil {
|
|
|
|
|
emunames, _ = dir.Readdirnames(0)
|
|
|
|
|
dir.Close()
|
|
|
|
|
}
|
|
|
|
|
for _, e := range emunames {
|
|
|
|
|
if len(e) <= 4 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
ext := e[len(e)-4:]
|
|
|
|
|
emu := Emu{
|
|
|
|
|
ID: fmt.Sprintf("/emu/%s", e),
|
|
|
|
|
Name: e[:len(e)-4],
|
|
|
|
|
Type: "image/" + ext[1:],
|
|
|
|
|
}
|
|
|
|
|
allemus = append(allemus, emu)
|
|
|
|
|
}
|
|
|
|
|
sort.Slice(allemus, func(i, j int) bool {
|
|
|
|
|
return allemus[i].Name < allemus[j].Name
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func serve() {
|
|
|
|
|
db := opendatabase()
|
|
|
|
|
login.Init(login.InitArgs{Db: db, Logger: ilog, Insecure: develMode, SameSiteStrict: !develMode})
|
|
|
|
@ -2476,6 +2499,7 @@ func serve() {
|
|
|
|
|
go tracker()
|
|
|
|
|
go bgmonitor()
|
|
|
|
|
loadLingo()
|
|
|
|
|
emuinit()
|
|
|
|
|
|
|
|
|
|
readviews = templates.Load(develMode,
|
|
|
|
|
viewDir+"/views/honkpage.html",
|
|
|
|
@ -2494,6 +2518,7 @@ func serve() {
|
|
|
|
|
viewDir+"/views/msg.html",
|
|
|
|
|
viewDir+"/views/header.html",
|
|
|
|
|
viewDir+"/views/onts.html",
|
|
|
|
|
viewDir+"/views/emus.html",
|
|
|
|
|
viewDir+"/views/honkpage.js",
|
|
|
|
|
)
|
|
|
|
|
if !develMode {
|
|
|
|
@ -2514,6 +2539,7 @@ func serve() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mux := mux.NewRouter()
|
|
|
|
|
mux.Use(addcspheaders)
|
|
|
|
|
mux.Use(login.Checker)
|
|
|
|
|
|
|
|
|
|
mux.Handle("/api", login.TokenRequired(http.HandlerFunc(apihandler)))
|
|
|
|
@ -2552,7 +2578,7 @@ func serve() {
|
|
|
|
|
|
|
|
|
|
getters.HandleFunc("/style.css", serveviewasset)
|
|
|
|
|
getters.HandleFunc("/honkpage.js", serveviewasset)
|
|
|
|
|
getters.HandleFunc("/wonk.js", serveviewasset)
|
|
|
|
|
getters.HandleFunc("/misc.js", serveviewasset)
|
|
|
|
|
getters.HandleFunc("/local.css", servedataasset)
|
|
|
|
|
getters.HandleFunc("/local.js", servedataasset)
|
|
|
|
|
getters.HandleFunc("/icon.png", servedataasset)
|
|
|
|
@ -2564,8 +2590,6 @@ func serve() {
|
|
|
|
|
getters.HandleFunc("/logout", login.LogoutFunc)
|
|
|
|
|
getters.HandleFunc("/help/{name:[\\pL[:digit:]_.-]+}", servehelp)
|
|
|
|
|
|
|
|
|
|
getters.HandleFunc("/bloat/wonkles", servewonkles)
|
|
|
|
|
|
|
|
|
|
loggedin := mux.NewRoute().Subrouter()
|
|
|
|
|
loggedin.Use(login.Required)
|
|
|
|
|
loggedin.HandleFunc("/first", homepage)
|
|
|
|
@ -2595,6 +2619,7 @@ func serve() {
|
|
|
|
|
loggedin.HandleFunc("/t", showconvoy)
|
|
|
|
|
loggedin.HandleFunc("/q", showsearch)
|
|
|
|
|
loggedin.HandleFunc("/hydra", webhydra)
|
|
|
|
|
loggedin.HandleFunc("/emus", showemus)
|
|
|
|
|
loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker)))
|
|
|
|
|
|
|
|
|
|
err = http.Serve(listener, mux)
|
|
|
|
|