Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logging): log a few more things #64

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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