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