add diskFilesWorldReadable option to control 0644/0600 choice for new files
This commit is contained in:
parent
ee72f188a2
commit
cd60e4c855
10
Server.go
10
Server.go
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -23,12 +24,21 @@ type ServerPublicProperties struct {
|
||||
type ServerOptions struct {
|
||||
DataDirectory string
|
||||
DBPath string
|
||||
DiskFilesWorldReadable bool
|
||||
BandwidthLimit int64
|
||||
TrustXForwardedFor bool
|
||||
EnableHomepage bool
|
||||
ServerPublicProperties
|
||||
}
|
||||
|
||||
func (this *ServerOptions) FileMode() os.FileMode {
|
||||
if this.DiskFilesWorldReadable {
|
||||
return 0644
|
||||
} else {
|
||||
return 0600
|
||||
}
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
opts ServerOptions
|
||||
db *bolt.DB
|
||||
|
@ -20,6 +20,7 @@ func main() {
|
||||
maxUploadSpeed := flag.Int("speed", 0, "Maximum upload speed in bytes/sec (set zero for unlimited)")
|
||||
trustXForwardedFor := flag.Bool("trustXForwardedFor", false, "Trust X-Forwarded-For reverse proxy headers")
|
||||
enableHomepage := flag.Bool("enableHomepage", true, "Enable homepage (disable for embedded use only)")
|
||||
diskFilesWorldReadable := flag.Bool("diskFilesWorldReadable", false, "Save files as 0644 instead of 0600")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@ -29,6 +30,7 @@ func main() {
|
||||
BandwidthLimit: int64(*maxUploadSpeed),
|
||||
TrustXForwardedFor: *trustXForwardedFor,
|
||||
EnableHomepage: *enableHomepage,
|
||||
DiskFilesWorldReadable: *diskFilesWorldReadable,
|
||||
ServerPublicProperties: contented.ServerPublicProperties{
|
||||
AppTitle: *appTitle,
|
||||
MaxUploadBytes: int64(*maxUploadMb) * 1024 * 1024,
|
||||
|
@ -91,7 +91,7 @@ func (this *Server) handleUploadFile(src multipart.File, hdr *multipart.FileHead
|
||||
|
||||
// Save file to disk
|
||||
fileHash := hex.EncodeToString(hasher.Sum(nil))
|
||||
dest, err := os.OpenFile(filepath.Join(this.opts.DataDirectory, fileHash), os.O_CREATE|os.O_WRONLY, 0600)
|
||||
dest, err := os.OpenFile(filepath.Join(this.opts.DataDirectory, fileHash), os.O_CREATE|os.O_WRONLY, this.opts.FileMode())
|
||||
shouldSave := true
|
||||
if err != nil && os.IsExist(err) {
|
||||
// hash matches existing upload
|
||||
|
Loading…
Reference in New Issue
Block a user