commit c517753e91d46629f7b78c574e8be4b35ab14c7f
parent d0bcbac439d17f9664e276f625913fe45fc1c6a8
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 26 Jan 2023 01:03:04 -0800
fancier filedrop page
Diffstat:
5 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/pkg/template/templates.go b/pkg/template/templates.go
@@ -76,7 +76,7 @@ func (t *Templates) Render(w io.Writer, name string, data any, c echo.Context) e
d.VersionHTML = template.HTML(fmt.Sprintf("<!-- VERSION: %s -->", config.Global.GetVersion().Original()))
d.ShaHTML = template.HTML(fmt.Sprintf("<!-- SHA: %s -->", config.Global.Sha()))
d.NullUsername = config.NullUsername
- d.CSRF = c.Get("csrf").(string)
+ d.CSRF, _ = c.Get("csrf").(string)
d.AcceptLanguage = c.Get("accept-language").(string)
d.Lang = c.Get("lang").(string)
d.BaseKeywords = strings.Join(getBaseKeywords(), ", ")
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -854,7 +854,8 @@ type publicProfileData struct {
}
type fileDropData struct {
- Error string
+ Error string
+ Success string
}
type stego1RoadChallengeData struct {
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4168,14 +4168,13 @@ func BHCHandler(c echo.Context) error {
}
func FileDropHandler(c echo.Context) error {
+ const filedropTmplName = "standalone.filedrop"
uuidParam := c.Param("uuid")
//if c.Request().ContentLength > config.MaxUserFileUploadSize {
// data.Error = fmt.Sprintf("The maximum file size is %s", humanize.Bytes(config.MaxUserFileUploadSize))
// return c.Render(http.StatusOK, "chat-top-bar", data)
//}
- formHTML := `<form method="post" enctype="multipart/form-data"><input name="file" type="file" /><input type="submit" value="submit" /></form>`
-
filedrop, err := database.GetFiledropByUUID(uuidParam)
if err != nil {
return c.Redirect(http.StatusFound, "/")
@@ -4187,13 +4186,13 @@ func FileDropHandler(c echo.Context) error {
var data fileDropData
if c.Request().Method == http.MethodGet {
- return c.HTML(http.StatusOK, formHTML)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
file, handler, uploadErr := c.Request().FormFile("file")
if uploadErr != nil {
data.Error = uploadErr.Error()
- return c.HTML(http.StatusOK, formHTML+data.Error)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
defer file.Close()
@@ -4203,25 +4202,25 @@ func FileDropHandler(c echo.Context) error {
//}
if !govalidator.StringLength(origFileName, "3", "50") {
data.Error = "invalid file name, 3-50 characters"
- return c.HTML(http.StatusOK, formHTML+data.Error)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
newFileName := utils.MD5([]byte(utils.GenerateToken32()))
outFile, err := os.OpenFile(filepath.Join(database.FiledropFolder, newFileName), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
data.Error = err.Error()
- return c.HTML(http.StatusOK, formHTML+data.Error)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
defer outFile.Close()
encrypter, err := utils.EncryptStream(file)
if err != nil {
data.Error = err.Error()
- return c.HTML(http.StatusOK, formHTML+data.Error)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
written, err := io.Copy(outFile, encrypter)
if err != nil {
data.Error = err.Error()
- return c.HTML(http.StatusOK, formHTML+data.Error)
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
filedrop.IV = encrypter.Meta().IV
@@ -4230,7 +4229,8 @@ func FileDropHandler(c echo.Context) error {
filedrop.FileSize = written
filedrop.DoSave()
- return c.String(http.StatusOK, "File uploaded successfully")
+ data.Success = "File uploaded successfully"
+ return c.Render(http.StatusOK, filedropTmplName, data)
}
func Stego1ChallengeHandler(c echo.Context) error {
diff --git a/pkg/web/public/views/pages/standalone/filedrop.gohtml b/pkg/web/public/views/pages/standalone/filedrop.gohtml
@@ -0,0 +1,25 @@
+{{ define "content" }}
+ <div id="parent">
+ <div class="container" id="form_login">
+ <div class="row">
+ <div class="col-8 offset-2 col-md-8 offset-md-2 col-sm-8 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4">
+ {{ if .Data.Success }}
+ <div class="alert alert-success">{{ .Data.Success }}</div>
+ {{ else }}
+ {{ if .Data.Error }}
+ <div class="alert alert-danger">{{ .Data.Error }}</div>
+ {{ end }}
+ <div class="card" style="background-color: rgba(0, 0, 0, 0.7);">
+ <div class="card-header" style="background-color: rgba(50, 50, 50, 0.7); color: #ccc;">
+ <strong>{{ t "File drop" . }}</strong>
+ </div>
+ <div class="card-body">
+ <form method="post" enctype="multipart/form-data"><input name="file" type="file" /><input type="submit" value="submit" /></form>
+ </div>
+ </div>
+ {{ end }}
+ </div>
+ </div>
+ </div>
+ </div>
+{{ end }}
+\ No newline at end of file
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -27,8 +27,7 @@ import (
yaml "gopkg.in/yaml.v1"
)
-func getMainServer() echo.HandlerFunc {
- i18nBundle := getI18nBundle()
+func getMainServer(i18nBundle *i18n.Bundle, renderer *tmp.Templates) echo.HandlerFunc {
e := echo.New()
e.HideBanner = true
e.HidePort = true
@@ -39,7 +38,7 @@ func getMainServer() echo.HandlerFunc {
e.Server.WriteTimeout = 10 * time.Second
e.Use(staticbin.Static(bindata.Asset, staticbin.Options{Dir: "/public", SkipLogging: true}))
- e.Renderer = tmp.GetRenderer(e)
+ e.Renderer = renderer
e.Use(middlewares.FirstUseMiddleware)
e.Use(middlewares.DdosMiddleware)
e.Use(middlewares.MaintenanceMiddleware)
@@ -283,12 +282,17 @@ func getMainServer() echo.HandlerFunc {
func getBaseServer() *echo.Echo {
e := echo.New()
+ renderer := tmp.GetRenderer(e)
+ i18nBundle := getI18nBundle()
e.HideBanner = true
e.HidePort = true
e.Debug = true
+ e.Renderer = renderer
+ e.Use(middlewares.SetUserMiddleware)
+ e.Use(middlewares.I18nMiddleware(i18nBundle, "en"))
e.GET("/file-drop/:uuid", handlers.FileDropHandler)
e.POST("/file-drop/:uuid", handlers.FileDropHandler)
- e.Any("*", getMainServer())
+ e.Any("*", getMainServer(i18nBundle, renderer))
return e
}