Geogate kill switch

This commit is contained in:
Noah Petherbridge 2023-07-01 16:35:35 -07:00
parent 77bbea38cc
commit 2682512dd3
2 changed files with 5 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package config package config
// GeoIP gating rules. TODO: make dynamically configurable. // GeoIP gating rules. TODO: make dynamically configurable.
var GeoGateEnabled bool
// GeoIP database path (standard location on Fedora/Debian) // GeoIP database path (standard location on Fedora/Debian)
const GeoIPPath = "/usr/share/GeoIP/GeoLite2-City.mmdb" const GeoIPPath = "/usr/share/GeoIP/GeoLite2-City.mmdb"

View File

@ -14,6 +14,10 @@ import (
// GeoGate: block access to the site based on the user's location (due to local laws or regulations). // GeoGate: block access to the site based on the user's location (due to local laws or regulations).
func GeoGate(handler http.Handler) http.Handler { func GeoGate(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !config.GeoGateEnabled {
handler.ServeHTTP(w, r)
return
}
// Flash errors to admins. // Flash errors to admins.
onError := func(err error) { onError := func(err error) {