Skip to content

Commit

Permalink
feat(logging): log a few more things
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxencs committed Jan 18, 2024
1 parent 4dd7839 commit 7599cdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ func (s Server) isAuthenticated(next http.Handler) http.Handler {
if token := r.Header.Get("X-API-Token"); token != "" {
// check header
if token != s.cfg.Config.APIToken {
s.log.Error().Msgf("unauthorized access attempt with incorrect API token in header from IP: %s", r.RemoteAddr)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
} else if key := r.URL.Query().Get("apikey"); key != "" {
// check query param ?apikey=TOKEN
if key != s.cfg.Config.APIToken {
s.log.Error().Msgf("unauthorized access attempt with incorrect API token in query parameters from IP: %s", r.RemoteAddr)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
} else {
// neither header nor query parameter provided a token
s.log.Error().Msgf("unauthorized access attempt without API token from IP: %s", r.RemoteAddr)
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
return
}
Expand Down
3 changes: 3 additions & 0 deletions internal/http/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (p processor) ProcessSeasonPack(w netHTTP.ResponseWriter, r *netHTTP.Reques
}

packDirName := utils.FormatSeasonPackTitle(p.req.Name)
p.log.Debug().Msgf("formatted season pack name: %q", packDirName)

for _, child := range v {
if checkCandidates(&requestrls, &child) == 210 {
Expand Down Expand Up @@ -252,6 +253,7 @@ func (p processor) ProcessSeasonPack(w netHTTP.ResponseWriter, r *netHTTP.Reques

newMatches := append(oldMatches.([]matchPaths), currentMatch...)
matchesMap.Store(p.req.Name, newMatches)
p.log.Debug().Msgf("matched torrent from client %q: %q %q", clientName, child.t.Name, child.t.Hash)
continue
}
}
Expand Down Expand Up @@ -335,6 +337,7 @@ func (p processor) ParseTorrent(w netHTTP.ResponseWriter, r *netHTTP.Request) {
netHTTP.Error(w, fmt.Sprintf("error parsing folder name: %q", err), 466)
return
}
p.log.Debug().Msgf("parsed season pack name: %q", folderName)

matchesSlice, ok := matchesMap.Load(p.req.Name)
if !ok {
Expand Down

0 comments on commit 7599cdd

Please sign in to comment.