added base path filter
This commit is contained in:
parent
98b53d3a33
commit
ec5a376733
15 changed files with 104 additions and 44 deletions
|
|
@ -15,8 +15,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
//TODO add missing CSRF checks
|
||||
|
||||
const noSuchFile = "no such file or directory"
|
||||
|
||||
type notFoundHandler struct {
|
||||
|
|
@ -95,7 +93,6 @@ func authHandler(h ctxHandler) ctxHandler {
|
|||
h(ctx)
|
||||
return
|
||||
}
|
||||
//ctx.Forbidden()
|
||||
ctx.Redirect(core.LoginURI, http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
|
@ -229,6 +226,9 @@ func uploadHandler(ctx *Context) {
|
|||
case "GET":
|
||||
ctx.Exec()
|
||||
case "POST":
|
||||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
f, orig, err := ctx.File("file")
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
|
@ -255,6 +255,9 @@ func newDirHandler(ctx *Context) {
|
|||
case "GET":
|
||||
ctx.Exec()
|
||||
case "POST":
|
||||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
err := ctx.Srv.FS.Mkdir(path, ctx.Form("name"))
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
|
@ -298,6 +301,9 @@ func moveHandler(ctx *Context) {
|
|||
case "GET":
|
||||
ctx.Exec()
|
||||
case "POST":
|
||||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
name := ctx.Form("name")
|
||||
dest := ctx.Form("destination")
|
||||
newfile, err := ctx.Srv.FS.Move(path, dest, name)
|
||||
|
|
@ -347,6 +353,9 @@ func deleteHandler(ctx *Context) {
|
|||
case "GET":
|
||||
ctx.Exec()
|
||||
case "POST":
|
||||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
files, err := ctx.Srv.FS.Delete(path)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
|
@ -405,6 +414,11 @@ func dirHandler(ctx *Context) {
|
|||
}
|
||||
ctx.Data.Paths = fs.Paths(path)
|
||||
ctx.Exec()
|
||||
default:
|
||||
ctx.Data = webData{
|
||||
Title: "Viewer",
|
||||
}
|
||||
ctx.Error(noSuchFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -638,5 +652,5 @@ func logoutHandler(ctx *Context) {
|
|||
log.Println("logout:", user)
|
||||
ctx.Srv.JWT.Invalidate(&ctx.Token)
|
||||
ctx.SetCookie(nil, 0)
|
||||
ctx.Redirect(core.IndexURI, http.StatusFound)
|
||||
ctx.Redirect(core.LoginURI, http.StatusFound)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue