diff --git a/lib/file/db.go b/lib/file/db.go index 50be394..8552d5e 100644 --- a/lib/file/db.go +++ b/lib/file/db.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "net/http" - "regexp" "sort" "strings" "sync" @@ -328,13 +327,16 @@ func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err erro } //Remove http(s) http(s)://a.proxy.com //*.proxy.com *.a.proxy.com Do some pan-parsing - tmp := strings.Replace(v.Host, "*", `\w+?`, -1) - var re *regexp.Regexp - if re, err = regexp.Compile(tmp); err != nil { + if v.Scheme != "all" && v.Scheme != r.URL.Scheme { return true } - if len(re.FindAllString(host, -1)) > 0 && (v.Scheme == "all" || v.Scheme == r.URL.Scheme) { - //URL routing + tmpHost := v.Host + if strings.Contains(tmpHost, "*") { + tmpHost = strings.Replace(tmpHost, "*", "", -1) + if strings.Contains(host, tmpHost) { + hosts = append(hosts, v) + } + } else if v.Host == host { hosts = append(hosts, v) } return true diff --git a/server/proxy/http.go b/server/proxy/http.go index 9cf0ce7..73507ee 100644 --- a/server/proxy/http.go +++ b/server/proxy/http.go @@ -57,7 +57,7 @@ func NewHttp(bridge *bridge.Bridge, c *file.Tunnel, httpPort, httpsPort int, use func (s *httpServer) Start() error { var err error if s.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil { - s.errorContent = []byte("easyProxy 404") + s.errorContent = []byte("nps 404") } if s.httpPort > 0 { s.httpServer = s.NewServer(s.httpPort, "http") @@ -118,7 +118,6 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) { var ( host *file.Host target net.Conn - lastHost *file.Host err error connClient io.ReadWriteCloser scheme = r.URL.Scheme @@ -135,6 +134,10 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) { } c.Close() }() +reset: + if isReset { + host.Client.AddConn() + } if host, err = file.GetDb().GetInfoByHost(r.Host, r); err != nil { logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI) return @@ -143,12 +146,13 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) { logs.Warn("client id %d, host id %d, error %s, when https connection", host.Client.Id, host.Id, err.Error()) return } - defer host.Client.AddConn() + if !isReset { + defer host.Client.AddConn() + } if err = s.auth(r, c, host.Client.Cnf.U, host.Client.Cnf.P); err != nil { logs.Warn("auth error", err, r.RemoteAddr) return } -reset: if targetAddr, err = host.Target.GetRandomTarget(); err != nil { logs.Warn(err.Error()) return @@ -159,7 +163,6 @@ reset: return } connClient = conn.GetConn(target, lk.Crypt, lk.Compress, host.Client.Rate, true) - lastHost = host //read from inc-client go func() { @@ -237,9 +240,8 @@ reset: if hostTmp, err := file.GetDb().GetInfoByHost(r.Host, r); err != nil { logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI) break - } else if host != lastHost { + } else if host != hostTmp { host = hostTmp - lastHost = host isReset = true connClient.Close() goto reset