Skip to content

Commit

Permalink
add getrealip
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed Jun 15, 2023
1 parent 2509745 commit 12685b9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,13 @@ func (c *Server) SaveFileInfoToLevelDB(key string, fileInfo *FileInfo, db *level
return fileInfo, nil
}

func (c *Server) GetRealIp(r *http.Request) string {
client_ip := ""
clients := strings.Split(r.RemoteAddr, ":")
client_ip = clients[0]
return client_ip
}

func (c *Server) IsPeer(r *http.Request) bool {
var (
ip string
Expand All @@ -639,6 +646,7 @@ func (c *Server) IsPeer(r *http.Request) bool {
cidr *net.IPNet
err error
)

IsPublicIP := func(IP net.IP) bool {
if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
return false
Expand All @@ -658,7 +666,7 @@ func (c *Server) IsPeer(r *http.Request) bool {
return false
}
//return true
ip = c.util.GetClientIp(r)
ip = c.GetRealIp(r)
if c.util.Contains("0.0.0.0", Config().AdminIps) {
if IsPublicIP(net.ParseIP(ip)) {
return false
Expand Down

0 comments on commit 12685b9

Please sign in to comment.