35 lines
786 B
Go
35 lines
786 B
Go
package httpapi
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
)
|
|
|
|
func (s *Server) internalStatusByPhone(w http.ResponseWriter, r *http.Request) {
|
|
s.statusByPhone(w, r, false)
|
|
}
|
|
|
|
func (s *Server) requireInternalNetwork(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
address := remoteIP(r)
|
|
if address == nil {
|
|
writeInternalNetworkRequired(w)
|
|
return
|
|
}
|
|
ip := net.ParseIP(*address)
|
|
if ip == nil || (!ip.IsPrivate() && !ip.IsLoopback()) {
|
|
writeInternalNetworkRequired(w)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
func writeInternalNetworkRequired(w http.ResponseWriter) {
|
|
writeError(w, &apiError{
|
|
Status: http.StatusForbidden,
|
|
Code: "INTERNAL_NETWORK_REQUIRED",
|
|
Message: "该接口仅允许内部网络访问",
|
|
})
|
|
}
|