Skip to content

Commit

Permalink
#patch: use net package privateip function for privateip parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
circa10a committed Feb 26, 2022
1 parent 6e503a2 commit f16cd7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
17 changes: 17 additions & 0 deletions caddy_geofence.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/http"
"strings"
"time"

"github.com/caddyserver/caddy/v2"
Expand Down Expand Up @@ -154,6 +155,22 @@ func (cg CaddyGeofence) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
return next.ServeHTTP(w, r)
}

// isPrivateAddress checks if remote address is from known private ip space
func isPrivateAddress(addr string) bool {
ip := net.ParseIP(addr)
return ip.IsPrivate() || strings.HasPrefix(addr, "::1")
}

// strInSlice returns true if string is in slice
func strInSlice(str string, list []string) bool {
for _, item := range list {
if str == item {
return true
}
}
return false
}

// Interface guards
var (
_ caddy.Provisioner = (*CaddyGeofence)(nil)
Expand Down
21 changes: 0 additions & 21 deletions utils.go

This file was deleted.

0 comments on commit f16cd7d

Please sign in to comment.