Improved Security Logging
This commit is contained in:
parent
b8fdab8822
commit
de6b3bc23f
|
@ -25,6 +25,7 @@ type MetadataJSON struct {
|
|||
Mimetype string `json:"mimetype"`
|
||||
Size int64 `json:"size"`
|
||||
Expiry int64 `json:"expiry"`
|
||||
SrcIp string `json:"srcip,omitempty"`
|
||||
ArchiveFiles []string `json:"archive_files,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -106,6 +107,8 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
|
|||
Sha256sum: metadata.Sha256sum,
|
||||
Expiry: metadata.Expiry.Unix(),
|
||||
Size: metadata.Size,
|
||||
SrcIp: metadata.SrcIp,
|
||||
|
||||
}
|
||||
|
||||
dst, err := os.Create(metaPath)
|
||||
|
@ -124,7 +127,7 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) {
|
||||
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
|
||||
filePath := path.Join(b.filesPath, key)
|
||||
|
||||
dst, err := os.Create(filePath)
|
||||
|
@ -153,6 +156,7 @@ func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey
|
|||
m.Expiry = expiry
|
||||
m.DeleteKey = deleteKey
|
||||
m.AccessKey = accessKey
|
||||
m.SrcIp = srcIp
|
||||
m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, dst)
|
||||
|
||||
err = b.writeMetadata(key, m)
|
||||
|
|
|
@ -12,6 +12,7 @@ type Metadata struct {
|
|||
Mimetype string
|
||||
Size int64
|
||||
Expiry time.Time
|
||||
SrcIp string
|
||||
ArchiveFiles []string
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ type StorageBackend interface {
|
|||
Exists(key string) (bool, error)
|
||||
Head(key string) (Metadata, error)
|
||||
Get(key string) (Metadata, io.ReadCloser, error)
|
||||
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (Metadata, error)
|
||||
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (Metadata, error)
|
||||
PutMetadata(key string, m Metadata) error
|
||||
ServeFile(key string, w http.ResponseWriter, r *http.Request) error
|
||||
Size(key string) (int64, error)
|
||||
|
|
|
@ -42,6 +42,7 @@ type UploadRequest struct {
|
|||
deleteKey string // Empty string if not defined
|
||||
randomBarename bool
|
||||
accessKey string // Empty string if not defined
|
||||
srcIp string // Empty string if not defined
|
||||
}
|
||||
|
||||
// Metadata associated with a file as it would actually be stored
|
||||
|
@ -333,8 +334,8 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
|
|||
if upReq.deleteKey == "" {
|
||||
upReq.deleteKey = uniuri.NewLen(30)
|
||||
}
|
||||
|
||||
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey)
|
||||
var srcIp = r.Header.get("X-Forwarded-For")
|
||||
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey, srcIp)
|
||||
if err != nil {
|
||||
return upload, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue