|
|
@ -159,32 +159,30 @@ func AddCorsWildcardHeaders(serve http.HandlerFunc) http.HandlerFunc { |
|
|
|
func AddAccessKey(serve http.HandlerFunc, accessKey string) http.HandlerFunc { |
|
|
|
func AddAccessKey(serve http.HandlerFunc, accessKey string) http.HandlerFunc { |
|
|
|
return func(w http.ResponseWriter, r *http.Request) { |
|
|
|
return func(w http.ResponseWriter, r *http.Request) { |
|
|
|
// Get key or md5sum from this access.
|
|
|
|
// Get key or md5sum from this access.
|
|
|
|
keys, key_ok := r.URL.Query()["key"] |
|
|
|
keys, keyOk := r.URL.Query()["key"] |
|
|
|
var code string |
|
|
|
var code string |
|
|
|
if !key_ok || len(keys[0]) < 1 { |
|
|
|
if !keyOk || len(keys[0]) < 1 { |
|
|
|
// In case a code is provided
|
|
|
|
// In case a code is provided
|
|
|
|
codes, code_ok := r.URL.Query()["code"] |
|
|
|
codes, codeOk := r.URL.Query()["code"] |
|
|
|
if !code_ok || len(codes[0]) < 1 { |
|
|
|
if !codeOk || len(codes[0]) < 1 { |
|
|
|
http.NotFound(w, r) |
|
|
|
http.NotFound(w, r) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
code = codes[0] |
|
|
|
code = strings.ToUpper(codes[0]) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// In case a key is provided, convert to code.
|
|
|
|
// In case a key is provided, convert to code.
|
|
|
|
data := []byte(r.URL.Path + keys[0]) |
|
|
|
data := []byte(r.URL.Path + keys[0]) |
|
|
|
hash := md5.Sum(data) |
|
|
|
hash := md5.Sum(data) |
|
|
|
code = fmt.Sprintf("%x", hash) |
|
|
|
code = fmt.Sprintf("%X", hash) |
|
|
|
} |
|
|
|
} |
|
|
|
code = strings.ToUpper(code) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compute the correct md5sum of this access.
|
|
|
|
// Compute the correct md5sum of this access.
|
|
|
|
local_data := []byte(r.URL.Path + accessKey) |
|
|
|
localData := []byte(r.URL.Path + accessKey) |
|
|
|
hash := md5.Sum(local_data) |
|
|
|
hash := md5.Sum(localData) |
|
|
|
local_code := fmt.Sprintf("%x", hash) |
|
|
|
localCode := fmt.Sprintf("%X", hash) |
|
|
|
local_code = strings.ToUpper(local_code) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compare the two.
|
|
|
|
// Compare the two.
|
|
|
|
if code != local_code { |
|
|
|
if code != localCode { |
|
|
|
http.NotFound(w, r) |
|
|
|
http.NotFound(w, r) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|