This commit is contained in:
chrislusf
2015-10-19 22:03:18 -07:00
parent faaf44f171
commit 805740069a
2 changed files with 19 additions and 20 deletions

View File

@@ -4,8 +4,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"regexp"
"net/http" "net/http"
"regexp"
"github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/glog"
) )
@@ -90,25 +90,24 @@ func (g *Guard) checkWhiteList(w http.ResponseWriter, r *http.Request) error {
if err == nil { if err == nil {
for _, ip := range g.whiteList { for _, ip := range g.whiteList {
// If the whitelist entry contains a "/" it // If the whitelist entry contains a "/" it
// is a CIDR range, and we should check the // is a CIDR range, and we should check the
// remote host is within it // remote host is within it
match, _ := regexp.MatchString("/", ip) match, _ := regexp.MatchString("/", ip)
if ( match ) { if match {
_, cidrnet, err := net.ParseCIDR(ip) _, cidrnet, err := net.ParseCIDR(ip)
if err != nil { if err != nil {
panic(err) panic(err)
} }
remote := net.ParseIP(host) remote := net.ParseIP(host)
if cidrnet.Contains(remote) { if cidrnet.Contains(remote) {
return nil return nil
} }
} }
//
// // Otherwise we're looking for a literal match.
// Otherwise we're looking for a literal match. //
//
if ip == host { if ip == host {
return nil return nil
} }

View File

@@ -11,7 +11,7 @@ import (
func OnInterrupt(fn func()) { func OnInterrupt(fn func()) {
// deal with control+c,etc // deal with control+c,etc
signalChan := make(chan os.Signal, 1) signalChan := make(chan os.Signal, 1)
// controlling terminal close, daemon not exit // controlling terminal close, daemon not exit
signal.Ignore(syscall.SIGHUP) signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan, signal.Notify(signalChan,
os.Interrupt, os.Interrupt,