This commit is contained in:
cnlh 2020-01-16 15:17:21 +08:00
parent 0af9943540
commit 5bf52e9e24
2 changed files with 17 additions and 13 deletions

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"regexp"
"sort" "sort"
"strings" "strings"
"sync" "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 //Remove http(s) http(s)://a.proxy.com
//*.proxy.com *.a.proxy.com Do some pan-parsing //*.proxy.com *.a.proxy.com Do some pan-parsing
tmp := strings.Replace(v.Host, "*", `\w+?`, -1) if v.Scheme != "all" && v.Scheme != r.URL.Scheme {
var re *regexp.Regexp
if re, err = regexp.Compile(tmp); err != nil {
return true return true
} }
if len(re.FindAllString(host, -1)) > 0 && (v.Scheme == "all" || v.Scheme == r.URL.Scheme) { tmpHost := v.Host
//URL routing 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) hosts = append(hosts, v)
} }
return true return true

View File

@ -57,7 +57,7 @@ func NewHttp(bridge *bridge.Bridge, c *file.Tunnel, httpPort, httpsPort int, use
func (s *httpServer) Start() error { func (s *httpServer) Start() error {
var err error var err error
if s.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil { 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 { if s.httpPort > 0 {
s.httpServer = s.NewServer(s.httpPort, "http") s.httpServer = s.NewServer(s.httpPort, "http")
@ -118,7 +118,6 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) {
var ( var (
host *file.Host host *file.Host
target net.Conn target net.Conn
lastHost *file.Host
err error err error
connClient io.ReadWriteCloser connClient io.ReadWriteCloser
scheme = r.URL.Scheme scheme = r.URL.Scheme
@ -135,6 +134,10 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) {
} }
c.Close() c.Close()
}() }()
reset:
if isReset {
host.Client.AddConn()
}
if host, err = file.GetDb().GetInfoByHost(r.Host, r); err != nil { 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) logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
return 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()) logs.Warn("client id %d, host id %d, error %s, when https connection", host.Client.Id, host.Id, err.Error())
return 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 { if err = s.auth(r, c, host.Client.Cnf.U, host.Client.Cnf.P); err != nil {
logs.Warn("auth error", err, r.RemoteAddr) logs.Warn("auth error", err, r.RemoteAddr)
return return
} }
reset:
if targetAddr, err = host.Target.GetRandomTarget(); err != nil { if targetAddr, err = host.Target.GetRandomTarget(); err != nil {
logs.Warn(err.Error()) logs.Warn(err.Error())
return return
@ -159,7 +163,6 @@ reset:
return return
} }
connClient = conn.GetConn(target, lk.Crypt, lk.Compress, host.Client.Rate, true) connClient = conn.GetConn(target, lk.Crypt, lk.Compress, host.Client.Rate, true)
lastHost = host
//read from inc-client //read from inc-client
go func() { go func() {
@ -237,9 +240,8 @@ reset:
if hostTmp, err := file.GetDb().GetInfoByHost(r.Host, r); err != nil { 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) logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
break break
} else if host != lastHost { } else if host != hostTmp {
host = hostTmp host = hostTmp
lastHost = host
isReset = true isReset = true
connClient.Close() connClient.Close()
goto reset goto reset