Skip to content

Commit e311855

Browse files
committed
Merge pull request src-d#153 from camathieu/1.2-rc2
1.2-RC1 Fixes
2 parents ea9851a + a8528ad commit e311855

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

server/metadataBackend/bolt/bolt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func (bmb *MetadataBackend) GetUploadsToRemove(ctx *juliet.Context) (ids []strin
610610
}
611611

612612
// Extract upload id from key ( 16 last bytes )
613-
ids = append(ids, string(k[8:]))
613+
ids = append(ids, string(k[10:]))
614614
}
615615

616616
return nil

server/middleware/upload.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,29 @@ func Upload(ctx *juliet.Context, next http.Handler) http.Handler {
8181

8282
forbidden := func() {
8383
resp.Header().Set("WWW-Authenticate", "Basic realm=\"plik\"")
84+
85+
// Shouldn't redirect here to let the browser ask for credentials and retry
86+
ctx.Set("redirect", false)
87+
8488
common.Fail(ctx, req, resp, "Please provide valid credentials to access this upload", 401)
8589
}
8690

91+
// Check upload token
92+
uploadToken := req.Header.Get("X-UploadToken")
93+
if uploadToken != "" && uploadToken == upload.UploadToken {
94+
upload.IsAdmin = true
95+
} else {
96+
// Check if upload belongs to user
97+
if common.Config.Authentication && upload.User != "" {
98+
user := common.GetUser(ctx)
99+
if user != nil && user.ID == upload.User {
100+
upload.IsAdmin = true
101+
}
102+
}
103+
}
104+
87105
// Handle basic auth if upload is password protected
88-
if upload.ProtectedByPassword {
106+
if upload.ProtectedByPassword && !upload.IsAdmin {
89107
if req.Header.Get("Authorization") == "" {
90108
log.Warning("Missing Authorization header")
91109
forbidden()
@@ -120,20 +138,6 @@ func Upload(ctx *juliet.Context, next http.Handler) http.Handler {
120138
}
121139
}
122140

123-
// Check upload token
124-
uploadToken := req.Header.Get("X-UploadToken")
125-
if uploadToken != "" && uploadToken == upload.UploadToken {
126-
upload.IsAdmin = true
127-
} else {
128-
// Check if upload belongs to user
129-
if common.Config.Authentication && upload.User != "" {
130-
user := common.GetUser(ctx)
131-
if user != nil && user.ID == upload.User {
132-
upload.IsAdmin = true
133-
}
134-
}
135-
}
136-
137141
next.ServeHTTP(resp, req)
138142
})
139143
}

server/plikd.cfg

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Global params
88
#
99

10-
LogLevel = "DEBUG" # Other levels : DEBUG, INFO, WARNING, CRITICAL, FATAL
10+
LogLevel = "INFO" # Other levels : DEBUG, INFO, WARNING, CRITICAL, FATAL
1111
ListenPort = 8080
1212
ListenAddress = "0.0.0.0"
1313
MaxFileSize = 10737418240 # 10GB
@@ -49,6 +49,11 @@ StreamMode = true # Enable stream mode
4949
##
5050
# Data backend is for storing raw files
5151
#
52+
# Example using File :
53+
#
54+
# [DataBackendConfig]
55+
# Directory = "files"
56+
#
5257
# Example using OpenStack Swift :
5358
#
5459
# [DataBackendConfig]
@@ -58,6 +63,12 @@ StreamMode = true # Enable stream mode
5863
# Container = "plik"
5964
# Password = "#######"
6065
#
66+
# Example using SeaweedFS :
67+
#
68+
# [DataBackendConfig]
69+
# MasterURL = "http://127.0.0.1:9333"
70+
# ReplicationPattern = "000"
71+
#
6172

6273
[DataBackendConfig]
6374
Directory = "files"
@@ -67,6 +78,16 @@ Directory = "files"
6778
##
6879
# Metadata backend is for storing upload information (file names, size, md5, statuses,...)
6980
#
81+
# Example using BoltDB :
82+
#
83+
# [MetadataBackendConfig]
84+
# Path = "plik.db"
85+
#
86+
# Example using File (deprecated) :
87+
#
88+
# [MetadataBackendConfig]
89+
# Directory = "files"
90+
#
7091
# Example using MongoDB :
7192
#
7293
# [MetadataBackendConfig]
@@ -79,7 +100,7 @@ Directory = "files"
79100
#
80101

81102
[MetadataBackendConfig]
82-
Directory = "files"
103+
Path = "plik.db"
83104

84105

85106
####

0 commit comments

Comments
 (0)