bug修复

pull/1219/head
刘河 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 (
"errors"
"github.com/astaxie/beego"
"github.com/cnlh/easyProxy/bridge"
"github.com/cnlh/easyProxy/utils"
"log"
@ -62,9 +63,9 @@ func NewMode(Bridge *bridge.Tunnel, config *ServerConfig) interface{} {
case "webServer":
InitCsvDb()
InitFromCsv()
//p, _ := beego.AppConfig.Int("hostPort")
p, _ := beego.AppConfig.Int("hostPort")
t := &ServerConfig{
TcpPort: 8088,
TcpPort: p,
Mode: "httpHostServer",
Target: "",
VerifyKey: "",

View File

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

View File

@ -59,6 +59,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
if flag, err := conn.ReadFlag(); err == nil {
defer func() {
if s.config.Mux {
conn.WriteTo([]byte(utils.IO_EOF), s.config.CompressEncode, s.config.Crypt)
s.bridge.ReturnTunnel(conn, getverifyval(s.config.VerifyKey))
} else {
conn.Close()
@ -74,7 +75,6 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
return
}
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"
"net"
"net/http"
"net/http/httputil"
"net/url"
"strconv"
"strings"
@ -218,17 +219,14 @@ func (s *Conn) SetAlive() {
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) {
var b [32 * 1024]byte
var n int
if n, err = s.Read(b[:]); err != nil {
r, err = http.ReadRequest(bufio.NewReader(s))
if err != nil {
return
}
rb = b[:n]
r, err = http.ReadRequest(bufio.NewReader(bytes.NewReader(rb)))
rb, err = httputil.DumpRequest(r, true)
if err != nil {
log.Println("解析host出错", err)
return
}
hostPortURL, err := url.Parse(r.Host)