2020-07-29 21:11:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-10-22 16:50:40 +00:00
|
|
|
"strings"
|
2020-08-16 12:36:54 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2020-07-29 21:11:28 +00:00
|
|
|
)
|
|
|
|
|
2021-01-23 18:53:14 +00:00
|
|
|
var css = []string{"bundle.css", "remixicon.css"}
|
2021-01-15 18:57:12 +00:00
|
|
|
var cssHeader = func() string {
|
|
|
|
l := len(css)
|
|
|
|
h := ""
|
|
|
|
for i, f := range css {
|
|
|
|
h += "</css/" + f + ">; rel=preload; as=style"
|
|
|
|
if l > 1 && i != (l-1) {
|
|
|
|
h += ", "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return h
|
|
|
|
}()
|
|
|
|
|
2020-11-22 16:36:43 +00:00
|
|
|
func gcHTML(gc *gin.Context, code int, file string, templ gin.H) {
|
|
|
|
gc.Header("Cache-Control", "no-cache")
|
|
|
|
gc.HTML(code, file, templ)
|
|
|
|
}
|
|
|
|
|
2021-01-15 18:57:12 +00:00
|
|
|
func (app *appContext) pushResources(gc *gin.Context, admin bool) {
|
|
|
|
if pusher := gc.Writer.Pusher(); pusher != nil {
|
|
|
|
app.debug.Println("Using HTTP2 Server push")
|
|
|
|
if admin {
|
|
|
|
toPush := []string{"/js/admin.js", "/js/theme.js", "/js/lang.js", "/js/modal.js", "/js/tabs.js", "/js/invites.js", "/js/accounts.js", "/js/settings.js", "/js/profiles.js", "/js/common.js"}
|
|
|
|
for _, f := range toPush {
|
|
|
|
if err := pusher.Push(f, nil); err != nil {
|
|
|
|
app.debug.Printf("Failed HTTP2 ServerPush of \"%s\": %+v", f, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gc.Header("Link", cssHeader)
|
|
|
|
}
|
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) AdminPage(gc *gin.Context) {
|
2021-01-15 18:57:12 +00:00
|
|
|
app.pushResources(gc, true)
|
2021-01-12 00:11:40 +00:00
|
|
|
lang := gc.Query("lang")
|
|
|
|
if lang == "" {
|
2021-01-12 23:37:22 +00:00
|
|
|
lang = app.storage.lang.chosenAdminLang
|
2021-01-19 00:29:29 +00:00
|
|
|
} else if _, ok := app.storage.lang.Admin[lang]; !ok {
|
2021-01-12 23:37:22 +00:00
|
|
|
lang = app.storage.lang.chosenAdminLang
|
2021-01-12 00:11:40 +00:00
|
|
|
}
|
2020-08-16 12:36:54 +00:00
|
|
|
emailEnabled, _ := app.config.Section("invite_emails").Key("enabled").Bool()
|
|
|
|
notificationsEnabled, _ := app.config.Section("notifications").Key("enabled").Bool()
|
2020-09-05 16:32:49 +00:00
|
|
|
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "admin.html", gin.H{
|
2021-01-12 00:11:40 +00:00
|
|
|
"urlBase": app.URLBase,
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"contactMessage": "",
|
|
|
|
"email_enabled": emailEnabled,
|
|
|
|
"notifications": notificationsEnabled,
|
|
|
|
"version": VERSION,
|
|
|
|
"commit": COMMIT,
|
|
|
|
"ombiEnabled": ombiEnabled,
|
|
|
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
2021-01-19 00:29:29 +00:00
|
|
|
"strings": app.storage.lang.Admin[lang].Strings,
|
|
|
|
"quantityStrings": app.storage.lang.Admin[lang].QuantityStrings,
|
|
|
|
"language": app.storage.lang.Admin[lang].JSON,
|
2020-07-29 21:11:28 +00:00
|
|
|
})
|
|
|
|
}
|
2020-07-31 11:48:37 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) InviteProxy(gc *gin.Context) {
|
2021-01-15 18:57:12 +00:00
|
|
|
app.pushResources(gc, false)
|
2020-07-31 11:48:37 +00:00
|
|
|
code := gc.Param("invCode")
|
2021-01-11 19:17:43 +00:00
|
|
|
lang := gc.Query("lang")
|
|
|
|
if lang == "" {
|
|
|
|
lang = app.storage.lang.chosenFormLang
|
|
|
|
} else if _, ok := app.storage.lang.Form[lang]; !ok {
|
|
|
|
lang = app.storage.lang.chosenFormLang
|
|
|
|
}
|
2020-07-31 12:03:36 +00:00
|
|
|
/* Don't actually check if the invite is valid, just if it exists, just so the page loads quicker. Invite is actually checked on submit anyway. */
|
2020-08-16 12:36:54 +00:00
|
|
|
// if app.checkInvite(code, false, "") {
|
|
|
|
if _, ok := app.storage.invites[code]; ok {
|
|
|
|
email := app.storage.invites[code].Email
|
2020-10-22 16:50:40 +00:00
|
|
|
if strings.Contains(email, "Failed") {
|
|
|
|
email = ""
|
|
|
|
}
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, http.StatusOK, "form-loader.html", gin.H{
|
2021-01-18 22:06:50 +00:00
|
|
|
"urlBase": app.URLBase,
|
|
|
|
"cssClass": app.cssClass,
|
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
|
|
|
"helpMessage": app.config.Section("ui").Key("help_message").String(),
|
|
|
|
"successMessage": app.config.Section("ui").Key("success_message").String(),
|
|
|
|
"jfLink": app.config.Section("jellyfin").Key("public_server").String(),
|
|
|
|
"validate": app.config.Section("password_validation").Key("enabled").MustBool(false),
|
|
|
|
"requirements": app.validator.getCriteria(),
|
|
|
|
"email": email,
|
|
|
|
"username": !app.config.Section("email").Key("no_username").MustBool(false),
|
2021-01-19 00:29:29 +00:00
|
|
|
"strings": app.storage.lang.Form[lang].Strings,
|
|
|
|
"validationStrings": app.storage.lang.Form[lang].validationStringsJSON,
|
2021-01-25 18:01:18 +00:00
|
|
|
"notifications": app.storage.lang.Form[lang].notificationsJSON,
|
2021-01-18 22:06:50 +00:00
|
|
|
"code": code,
|
2020-07-31 11:48:37 +00:00
|
|
|
})
|
|
|
|
} else {
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, 404, "invalidCode.html", gin.H{
|
2021-01-05 18:16:23 +00:00
|
|
|
"cssClass": app.cssClass,
|
2020-09-23 19:14:16 +00:00
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
2020-07-31 12:03:36 +00:00
|
|
|
})
|
2020-07-31 11:48:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-31 12:03:36 +00:00
|
|
|
|
2020-08-16 12:36:54 +00:00
|
|
|
func (app *appContext) NoRouteHandler(gc *gin.Context) {
|
2021-01-15 18:57:12 +00:00
|
|
|
app.pushResources(gc, false)
|
2020-11-22 16:36:43 +00:00
|
|
|
gcHTML(gc, 404, "404.html", gin.H{
|
2021-01-05 18:16:23 +00:00
|
|
|
"cssClass": app.cssClass,
|
2020-08-16 12:36:54 +00:00
|
|
|
"contactMessage": app.config.Section("ui").Key("contact_message").String(),
|
2020-07-31 12:03:36 +00:00
|
|
|
})
|
|
|
|
}
|