1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-02 15:06:23 -07:00

Enable processing of files with extensions explicitly allowed by the admin

This commit is contained in:
Eggbertx 2023-04-26 13:23:12 -07:00
parent ef5a9f49c3
commit 530011be61
4 changed files with 21 additions and 9 deletions

BIN
html/static/otherthumb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

View file

@ -393,7 +393,16 @@ type UploadConfig struct {
ExiftoolPath string ExiftoolPath string
} }
func (uc *UploadConfig) AcceptexExtension(filename string) bool { func (uc *UploadConfig) AcceptedOtherExtension(ext string) bool {
for _, allowedExt := range uc.AllowOtherExtensions {
if ext == allowedExt {
return true
}
}
return false
}
func (uc *UploadConfig) AcceptedExtension(filename string) bool {
ext := strings.ToLower(path.Ext(filename)) ext := strings.ToLower(path.Ext(filename))
switch ext { switch ext {
// images // images
@ -420,12 +429,7 @@ func (uc *UploadConfig) AcceptexExtension(filename string) bool {
case ".zip": case ".zip":
return uc.AllowUploadingZipFiles return uc.AllowUploadingZipFiles
} }
for _, allowedExt := range uc.AllowOtherExtensions { return uc.AcceptedOtherExtension(ext)
if ext == allowedExt {
return true
}
}
return false
} }
type PostConfig struct { type PostConfig struct {

View file

@ -60,7 +60,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
gcutil.LogStr("originalFilename", upload.OriginalFilename, errEv, infoEv) gcutil.LogStr("originalFilename", upload.OriginalFilename, errEv, infoEv)
boardConfig := config.GetBoardConfig(postBoard.Dir) boardConfig := config.GetBoardConfig(postBoard.Dir)
if !boardConfig.AcceptexExtension(upload.OriginalFilename) { if !boardConfig.AcceptedExtension(upload.OriginalFilename) {
errEv.Caller().Msg("Upload filetype not supported") errEv.Caller().Msg("Upload filetype not supported")
server.ServeError(writer, "Upload filetype not supported", wantsJSON, map[string]interface{}{ server.ServeError(writer, "Upload filetype not supported", wantsJSON, map[string]interface{}{
"filename": upload.OriginalFilename, "filename": upload.OriginalFilename,
@ -190,7 +190,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
upload.ThumbnailWidth, upload.ThumbnailHeight = getThumbnailSize( upload.ThumbnailWidth, upload.ThumbnailHeight = getThumbnailSize(
upload.Width, upload.Height, postBoard.Dir, thumbType) upload.Width, upload.Height, postBoard.Dir, thumbType)
} }
} else if ext == ".pdf" || ext == ".zip" { } else if ext == ".pdf" || ext == ".zip" || boardConfig.AcceptedOtherExtension(ext) {
stat, err := os.Stat(filePath) stat, err := os.Stat(filePath)
if err != nil { if err != nil {
errEv.Err(err).Caller(). errEv.Err(err).Caller().
@ -212,8 +212,16 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
switch ext { switch ext {
case ".pdf": case ".pdf":
staticThumbPath = "static/pdfthumb.png" staticThumbPath = "static/pdfthumb.png"
case ".txt":
staticThumbPath = "static/txtthumb.png"
case ".gz":
fallthrough
case ".xz":
fallthrough
case ".zip": case ".zip":
staticThumbPath = "static/archivethumb.png" staticThumbPath = "static/archivethumb.png"
default:
staticThumbPath = "static/otherthumb.png"
} }
originalThumbPath := path.Join(documentRoot, staticThumbPath) originalThumbPath := path.Join(documentRoot, staticThumbPath)
if _, err = os.Stat(originalThumbPath); err != nil { if _, err = os.Stat(originalThumbPath); err != nil {