bug修复

This commit is contained in:
刘河 2019-01-10 09:33:05 +08:00
parent 60b5ea2959
commit 12ec5d6b26
4 changed files with 13 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package server
import ( import (
"errors" "errors"
"github.com/astaxie/beego"
"github.com/cnlh/easyProxy/bridge" "github.com/cnlh/easyProxy/bridge"
"github.com/cnlh/easyProxy/utils" "github.com/cnlh/easyProxy/utils"
"log" "log"
@ -62,9 +63,9 @@ func NewMode(Bridge *bridge.Tunnel, config *ServerConfig) interface{} {
case "webServer": case "webServer":
InitCsvDb() InitCsvDb()
InitFromCsv() InitFromCsv()
//p, _ := beego.AppConfig.Int("hostPort") p, _ := beego.AppConfig.Int("hostPort")
t := &ServerConfig{ t := &ServerConfig{
TcpPort: 8088, TcpPort: p,
Mode: "httpHostServer", Mode: "httpHostServer",
Target: "", Target: "",
VerifyKey: "", VerifyKey: "",

View File

@ -12,7 +12,6 @@ import (
"strings" "strings"
) )
type process func(c *utils.Conn, s *TunnelModeServer) error type process func(c *utils.Conn, s *TunnelModeServer) error
type TunnelModeServer struct { type TunnelModeServer struct {
@ -87,7 +86,7 @@ func (s *TunnelModeServer) dealClient(c *utils.Conn, cnf *ServerConfig, addr str
if flag == utils.CONN_SUCCESS { if flag == utils.CONN_SUCCESS {
if method == "CONNECT" { if method == "CONNECT" {
fmt.Fprint(c, "HTTP/1.1 200 Connection established\r\n") fmt.Fprint(c, "HTTP/1.1 200 Connection established\r\n")
} else { } else if rb != nil {
link.WriteTo(rb, cnf.CompressEncode, cnf.Crypt) link.WriteTo(rb, cnf.CompressEncode, cnf.Crypt)
} }
go utils.Relay(link.Conn, c.Conn, cnf.CompressEncode, cnf.Crypt, cnf.Mux) go utils.Relay(link.Conn, c.Conn, cnf.CompressEncode, cnf.Crypt, cnf.Mux)
@ -104,13 +103,7 @@ func (s *TunnelModeServer) Close() error {
//tcp隧道模式 //tcp隧道模式
func ProcessTunnel(c *utils.Conn, s *TunnelModeServer) error { func ProcessTunnel(c *utils.Conn, s *TunnelModeServer) error {
method, _, rb, err, r := c.GetHost() return s.dealClient(c, s.config, s.config.Target, "", nil)
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, method, rb)
} }
//http代理模式 //http代理模式
@ -123,7 +116,7 @@ func ProcessHttp(c *utils.Conn, s *TunnelModeServer) error {
if err := s.auth(r, c, s.config.U, s.config.P); err != nil { if err := s.auth(r, c, s.config.U, s.config.P); err != nil {
return err return err
} }
//TODO效率问题 //TODO 效率问题
return s.dealClient(c, s.config, addr, method, rb) return s.dealClient(c, s.config, addr, method, rb)
} }
@ -158,7 +151,7 @@ func (s *WebServer) Start() {
beego.BConfig.WebConfig.Session.SessionOn = true beego.BConfig.WebConfig.Session.SessionOn = true
log.Println("web管理启动访问端口为", beego.AppConfig.String("httpport")) log.Println("web管理启动访问端口为", beego.AppConfig.String("httpport"))
beego.SetViewsPath(beego.AppPath + "/web/views") beego.SetViewsPath(beego.AppPath + "/web/views")
beego.SetStaticPath("/static/", "/web/static") beego.SetStaticPath("/static", beego.AppPath+"/web/static")
beego.Run() beego.Run()
} }

View File

@ -59,6 +59,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
if flag, err := conn.ReadFlag(); err == nil { if flag, err := conn.ReadFlag(); err == nil {
defer func() { defer func() {
if s.config.Mux { if s.config.Mux {
conn.WriteTo([]byte(utils.IO_EOF), s.config.CompressEncode, s.config.Crypt)
s.bridge.ReturnTunnel(conn, getverifyval(s.config.VerifyKey)) s.bridge.ReturnTunnel(conn, getverifyval(s.config.VerifyKey))
} else { } else {
conn.Close() conn.Close()
@ -74,7 +75,6 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
return return
} }
s.listener.WriteToUDP(buf[:n], addr) s.listener.WriteToUDP(buf[:n], addr)
conn.WriteTo([]byte(utils.IO_EOF), s.config.CompressEncode, s.config.Crypt)
} }
} }
} }

View File

@ -10,6 +10,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"net/http/httputil"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
@ -218,17 +219,14 @@ func (s *Conn) SetAlive() {
conn.SetKeepAlivePeriod(time.Duration(2 * time.Second)) conn.SetKeepAlivePeriod(time.Duration(2 * time.Second))
} }
//从tcp报文中解析出host连接类型等 //从tcp报文中解析出host连接类型等 TODO 多种情况
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) { func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
var b [32 * 1024]byte r, err = http.ReadRequest(bufio.NewReader(s))
var n int if err != nil {
if n, err = s.Read(b[:]); err != nil {
return return
} }
rb = b[:n] rb, err = httputil.DumpRequest(r, true)
r, err = http.ReadRequest(bufio.NewReader(bytes.NewReader(rb)))
if err != nil { if err != nil {
log.Println("解析host出错", err)
return return
} }
hostPortURL, err := url.Parse(r.Host) hostPortURL, err := url.Parse(r.Host)