mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 07:42:38 +08:00 
			
		
		
		
	ssr: check obfs and protocol type
This commit is contained in:
		
							parent
							
								
									7abd39eecf
								
							
						
					
					
						commit
						6edf12f708
					
				@ -91,7 +91,7 @@ glider -config CONFIGPATH -listen :8080 -verbose
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Usage
 | 
					## Usage
 | 
				
			||||||
```bash
 | 
					```bash
 | 
				
			||||||
glider v0.5.3 usage:
 | 
					glider v0.5.2 usage:
 | 
				
			||||||
  -checkduration int
 | 
					  -checkduration int
 | 
				
			||||||
        proxy check duration(seconds) (default 30)
 | 
					        proxy check duration(seconds) (default 30)
 | 
				
			||||||
  -checkwebsite string
 | 
					  -checkwebsite string
 | 
				
			||||||
@ -175,7 +175,7 @@ Examples:
 | 
				
			|||||||
  glider -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443
 | 
					  glider -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443
 | 
				
			||||||
    -listen on :1081 as a transparent redirect server, forward all requests via remote ss server.
 | 
					    -listen on :1081 as a transparent redirect server, forward all requests via remote ss server.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  glider -listen redir://:1081 -forward ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d
 | 
					  glider -listen redir://:1081 -forward "ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d"
 | 
				
			||||||
    -listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.
 | 
					    -listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  glider -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443
 | 
					  glider -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								conf.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								conf.go
									
									
									
									
									
								
							@ -200,7 +200,7 @@ func usage() {
 | 
				
			|||||||
	fmt.Fprintf(os.Stderr, "  "+app+" -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443\n")
 | 
						fmt.Fprintf(os.Stderr, "  "+app+" -listen redir://:1081 -forward ss://method:pass@1.1.1.1:8443\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "    -listen on :1081 as a transparent redirect server, forward all requests via remote ss server.\n")
 | 
						fmt.Fprintf(os.Stderr, "    -listen on :1081 as a transparent redirect server, forward all requests via remote ss server.\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "\n")
 | 
						fmt.Fprintf(os.Stderr, "\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "  "+app+" -listen redir://:1081 -forward ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d\n")
 | 
						fmt.Fprintf(os.Stderr, "  "+app+" -listen redir://:1081 -forward \"ssr://method:pass@1.1.1.1:8444?protocol=a&protocol_param=b&obfs=c&obfs_param=d\"\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "    -listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.\n")
 | 
						fmt.Fprintf(os.Stderr, "    -listen on :1081 as a transparent redirect server, forward all requests via remote ssr server.\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "\n")
 | 
						fmt.Fprintf(os.Stderr, "\n")
 | 
				
			||||||
	fmt.Fprintf(os.Stderr, "  "+app+" -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443\n")
 | 
						fmt.Fprintf(os.Stderr, "  "+app+" -listen tcptun://:80=2.2.2.2:80 -forward ss://method:pass@1.1.1.1:8443\n")
 | 
				
			||||||
 | 
				
			|||||||
@ -39,7 +39,7 @@ checkduration=30
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Setup a dns forwarding server
 | 
					# Setup a dns forwarding server
 | 
				
			||||||
dns://53
 | 
					dns=:53
 | 
				
			||||||
# global remote dns server (you can specify different dns server in rule file)
 | 
					# global remote dns server (you can specify different dns server in rule file)
 | 
				
			||||||
dnsserver=8.8.8.8:53
 | 
					dnsserver=8.8.8.8:53
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								http.go
									
									
									
									
									
								
							@ -118,7 +118,7 @@ func (s *HTTP) Serve(c net.Conn) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	url, err := url.ParseRequestURI(requestURI)
 | 
						url, err := url.ParseRequestURI(requestURI)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logf("parse request url error: %s", err)
 | 
							logf("proxy-http parse request url error: %s", err)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -150,9 +150,11 @@ func (s *HTTP) Serve(c net.Conn) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// copy the left request bytes to remote server. eg. length specificed or chunked body.
 | 
						// copy the left request bytes to remote server. eg. length specificed or chunked body.
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		io.Copy(rc, reqR)
 | 
							if _, err := reqR.Peek(1); err == nil {
 | 
				
			||||||
		rc.SetDeadline(time.Now())
 | 
								io.Copy(rc, reqR)
 | 
				
			||||||
		c.SetDeadline(time.Now())
 | 
								rc.SetDeadline(time.Now())
 | 
				
			||||||
 | 
								c.SetDeadline(time.Now())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	respR := bufio.NewReader(rc)
 | 
						respR := bufio.NewReader(rc)
 | 
				
			||||||
@ -197,7 +199,7 @@ func (s *HTTP) servHTTPS(method, requestURI, proto string, c net.Conn) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	c.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
 | 
						c.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	logf("proxy-http %s <-> %s [connect]", c.RemoteAddr(), requestURI)
 | 
						logf("proxy-http %s <-> %s [c]", c.RemoteAddr(), requestURI)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, _, err = relay(c, rc)
 | 
						_, _, err = relay(c, rc)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@ -9,7 +9,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// VERSION .
 | 
					// VERSION .
 | 
				
			||||||
const VERSION = "0.5.3"
 | 
					const VERSION = "0.5.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func dialerFromConf() Dialer {
 | 
					func dialerFromConf() Dialer {
 | 
				
			||||||
	// global forwarders in xx.conf
 | 
						// global forwarders in xx.conf
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								ss.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								ss.go
									
									
									
									
									
								
							@ -25,7 +25,7 @@ type SS struct {
 | 
				
			|||||||
func NewSS(addr, method, pass string, dialer Dialer) (*SS, error) {
 | 
					func NewSS(addr, method, pass string, dialer Dialer) (*SS, error) {
 | 
				
			||||||
	ciph, err := core.PickCipher(method, nil, pass)
 | 
						ciph, err := core.PickCipher(method, nil, pass)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Fatalf("PickCipher for '%s', error: %s", method, err)
 | 
							log.Fatalf("proxy-ss PickCipher for '%s', error: %s", method, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s := &SS{
 | 
						s := &SS{
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								ssr.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								ssr.go
									
									
									
									
									
								
							@ -92,6 +92,10 @@ func (s *SSR) Dial(network, addr string) (net.Conn, error) {
 | 
				
			|||||||
	port, _ := strconv.Atoi(rs[1])
 | 
						port, _ := strconv.Atoi(rs[1])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ssrconn.IObfs = obfs.NewObfs(s.Obfs)
 | 
						ssrconn.IObfs = obfs.NewObfs(s.Obfs)
 | 
				
			||||||
 | 
						if ssrconn.IObfs == nil {
 | 
				
			||||||
 | 
							return nil, errors.New("proxy-ssr unsupported obfs type: " + s.Obfs)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	obfsServerInfo := &ssr.ServerInfoForObfs{
 | 
						obfsServerInfo := &ssr.ServerInfoForObfs{
 | 
				
			||||||
		Host:   rs[0],
 | 
							Host:   rs[0],
 | 
				
			||||||
		Port:   uint16(port),
 | 
							Port:   uint16(port),
 | 
				
			||||||
@ -99,7 +103,12 @@ func (s *SSR) Dial(network, addr string) (net.Conn, error) {
 | 
				
			|||||||
		Param:  s.ObfsParam,
 | 
							Param:  s.ObfsParam,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ssrconn.IObfs.SetServerInfo(obfsServerInfo)
 | 
						ssrconn.IObfs.SetServerInfo(obfsServerInfo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ssrconn.IProtocol = protocol.NewProtocol(s.Protocol)
 | 
						ssrconn.IProtocol = protocol.NewProtocol(s.Protocol)
 | 
				
			||||||
 | 
						if ssrconn.IProtocol == nil {
 | 
				
			||||||
 | 
							return nil, errors.New("proxy-ssr unsupported protocol type: " + s.Protocol)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protocolServerInfo := &ssr.ServerInfoForObfs{
 | 
						protocolServerInfo := &ssr.ServerInfoForObfs{
 | 
				
			||||||
		Host:   rs[0],
 | 
							Host:   rs[0],
 | 
				
			||||||
		Port:   uint16(port),
 | 
							Port:   uint16(port),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user