diff --git a/config.json b/config.json deleted file mode 100755 index c405931..0000000 --- a/config.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "Server": { - "ip": "123.206.77.88", - "tcp": 8224, - "vkey": "DKibZF5TXvic1g3kY", - "num": 10 - }, - "SiteList": [ - { - "host": "a.server.ourcauc.com", - "url": "10.1.50.203", - "port": 80 - }, - { - "host": "b.server.ourcauc.com", - "url": "10.1.50.196", - "port": 4000 - } - ] -} diff --git a/server/server.go b/server/server.go index 4329c44..80928d0 100644 --- a/server/server.go +++ b/server/server.go @@ -141,6 +141,11 @@ func DelTask(vKey string) error { if err := StopServer(vKey); err != nil { return err } + for _, v := range CsvDb.Hosts { + if v.Vkey == vKey { + CsvDb.DelHost(v.Host) + } + } return CsvDb.DelTask(vKey) } diff --git a/server/tcp.go b/server/tcp.go index def5521..84bd894 100755 --- a/server/tcp.go +++ b/server/tcp.go @@ -104,13 +104,20 @@ func (s *TunnelModeServer) Close() error { //tcp隧道模式 func ProcessTunnel(c *utils.Conn, s *TunnelModeServer) error { - return s.dealClient(c, s.config, s.config.Target, "", nil) + _, _, rb, err, r := c.GetHost() + if err == nil { + if err := s.auth(r, c, s.config.U, s.config.P); err != nil { + return err + } + } + return s.dealClient(c, s.config, s.config.Target, "", rb) } //http代理模式 func ProcessHttp(c *utils.Conn, s *TunnelModeServer) error { method, addr, rb, err, r := c.GetHost() if err != nil { + log.Println(err) c.Close() return err } diff --git a/utils/conn.go b/utils/conn.go index e1c77c2..616380b 100755 --- a/utils/conn.go +++ b/utils/conn.go @@ -10,7 +10,6 @@ import ( "log" "net" "net/http" - "net/http/httputil" "net/url" "strconv" "strings" @@ -245,16 +244,20 @@ func (s *Conn) SetAlive() { //从tcp报文中解析出host,连接类型等 TODO 多种情况 func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) { - r, err = http.ReadRequest(bufio.NewReader(s)) - if err != nil { + var b [32 * 1024]byte + var n int + if n, err = s.Read(b[:]); err != nil { return } - rb, err = httputil.DumpRequest(r, true) + rb = b[:n] + r, err = http.ReadRequest(bufio.NewReader(bytes.NewReader(rb))) if err != nil { return } hostPortURL, err := url.Parse(r.Host) if err != nil { + address = r.Host + err = nil return } if hostPortURL.Opaque == "443" { //https访问