-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle-clients.go
41 lines (34 loc) · 1.06 KB
/
handle-clients.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"net/http"
"github.com/Pilladian/logger"
)
func handleRequests(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if ok {
logger.Info(fmt.Sprintf("user \"%s\" - method %s - %s ", username, r.Method, r.RequestURI))
authorized, authentication_err := authenticate(username, password)
if authentication_err != nil {
logger.Error(authentication_err.Error())
}
if authorized {
if username != "" {
sendLogsToElastic(ELASTIC_SEARCH_PID, true, username, r.Method, r.URL.String())
}
w.Header().Set("Timeout", "99999999")
WEBDAV_SERVER.ServeHTTP(w, r)
return
}
}
if username != "" {
sendLogsToElastic(ELASTIC_SEARCH_PID, false, username, r.Method, r.URL.String())
}
logger.Error(fmt.Sprintf("user \"%s\" tried accessing %s", username, r.URL.String()))
w.Header().Set("WWW-Authenticate", `Basic realm="BASIC WebDAV REALM"`)
w.WriteHeader(401)
w.Write([]byte("401 Unauthorized\n"))
}
func healthyRequestHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "running")
}