Add support for IP-based bans (#1703)

* Add support for IP-based bans. Closes #1534

* Linter cleanup
This commit is contained in:
Gabe Kangas
2022-03-06 20:34:49 -08:00
committed by GitHub
parent 78c27ddbdd
commit 19b9a8bdf6
21 changed files with 488 additions and 98 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/core/user"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
)
@@ -101,6 +102,16 @@ func RequireUserAccessToken(handler http.HandlerFunc) http.HandlerFunc {
return
}
ipAddress := utils.GetIPAddressFromRequest(r)
// Check if this client's IP address is banned.
if blocked, err := data.IsIPAddressBanned(ipAddress); blocked {
log.Debugln("Client ip address has been blocked. Rejecting.")
accessDenied(w)
return
} else if err != nil {
log.Errorln("error determining if IP address is blocked: ", err)
}
// A user is required to use the websocket
user := user.GetUserByToken(accessToken)
if user == nil || !user.IsEnabled() {