Skip to content

Commit 86bebe2

Browse files
committed
Fix issue
1 parent ccc3db7 commit 86bebe2

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*.exe~
66
*.zip
77
console/proxyweb
8+
proxyweb

pages/engin.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ package pages
22

33
import (
44
"fmt"
5-
"github.com/astaxie/beego/logs"
6-
"github.com/easymesh/autoproxy-web/models"
7-
util "github.com/easymesh/autoproxy-web/uitl"
8-
"github.com/easymesh/autoproxy-web/engin"
9-
"github.com/GoAdminGroup/go-admin/modules/logger"
105
"net"
116
"net/http"
127
"net/url"
138
"strings"
9+
10+
"github.com/GoAdminGroup/go-admin/modules/logger"
11+
"github.com/astaxie/beego/logs"
12+
"github.com/easymesh/autoproxy-web/engin"
13+
"github.com/easymesh/autoproxy-web/models"
14+
util "github.com/easymesh/autoproxy-web/uitl"
1415
)
1516

1617
type ProxyEngin struct {
17-
proxy *models.Proxy
18-
remote *models.Remote
18+
proxy *models.Proxy
19+
remote *models.Remote
1920
access engin.Access
2021
localForward engin.Forward
2122
remoteForward engin.Forward
@@ -40,10 +41,10 @@ func parseAddress(protocal string, address string) (string, int, error) {
4041
}
4142
return "", 0, fmt.Errorf("protocal not support")
4243
}
43-
return address[:idx], util.Atoi(address[idx + 1:]), nil
44+
return address[:idx], util.Atoi(address[idx+1:]), nil
4445
}
4546

46-
func (p *ProxyEngin)authHandler(info *engin.AuthInfo) bool {
47+
func (p *ProxyEngin) authHandler(info *engin.AuthInfo) bool {
4748
if info == nil {
4849
logger.Warnf("not any auth info")
4950
return false
@@ -60,7 +61,7 @@ func (p *ProxyEngin)authHandler(info *engin.AuthInfo) bool {
6061
return false
6162
}
6263

63-
func (p *ProxyEngin)AuthSwitch(auth int) {
64+
func (p *ProxyEngin) AuthSwitch(auth int) {
6465
if auth > 0 {
6566
p.access.AuthHandlerSet(p.authHandler)
6667
} else {
@@ -69,15 +70,15 @@ func (p *ProxyEngin)AuthSwitch(auth int) {
6970
p.proxy.Auth = auth
7071
}
7172

72-
func (p *ProxyEngin)Stop() {
73+
func (p *ProxyEngin) Stop() {
7374
p.access.Shutdown()
7475
if p.remoteForward != nil {
7576
p.remoteForward.Close()
7677
}
7778
}
7879

7980
func remoteForwardInit(remote *models.Remote) (engin.Forward, error) {
80-
address, port , err := parseAddress(remote.Protocal, remote.Address)
81+
address, port, err := parseAddress(remote.Protocal, remote.Address)
8182
if err != nil {
8283
return nil, err
8384
}
@@ -108,7 +109,7 @@ func remoteForwardInit(remote *models.Remote) (engin.Forward, error) {
108109
auth = &engin.AuthInfo{User: remote.User, Token: remote.Password}
109110
}
110111

111-
forward, err := engin.NewHttpsProtcal(address, 30, auth, tlsEnable, TLS_CERT_FILE, TLS_KEY_FILE )
112+
forward, err := engin.NewHttpProxyForward(address, 30, auth, tlsEnable, TLS_CERT_FILE, TLS_KEY_FILE)
112113
if err != nil {
113114
return nil, err
114115
}
@@ -144,19 +145,19 @@ func remoteForwardTest(testurl string, forward engin.Forward) error {
144145
return nil
145146
}
146147

147-
func (p *ProxyEngin)DomainForwardFunc(address string, r *http.Request) engin.Forward {
148+
func (p *ProxyEngin) DomainForwardFunc(address string, r *http.Request) engin.Forward {
148149
if DomainCheck(address) {
149150
logs.Info("%s auto forward to remote proxy", address)
150151
return p.remoteForward
151152
}
152153
return PublicLocalForward
153154
}
154155

155-
func (p *ProxyEngin)LocalForwardFunc(address string, r *http.Request) engin.Forward {
156+
func (p *ProxyEngin) LocalForwardFunc(address string, r *http.Request) engin.Forward {
156157
return PublicLocalForward
157158
}
158159

159-
func (p *ProxyEngin)ProxyForwardFunc(address string, r *http.Request) engin.Forward {
160+
func (p *ProxyEngin) ProxyForwardFunc(address string, r *http.Request) engin.Forward {
160161
return p.remoteForward
161162
}
162163

@@ -172,13 +173,6 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
172173
if err != nil {
173174
return nil, err
174175
}
175-
err = remoteForwardTest("https://www.google.com/", forword)
176-
if err != nil {
177-
models.RemoteUpdate(remote.Tag, func(u *models.Remote) {
178-
u.Status = err.Error()
179-
})
180-
return nil, err
181-
}
182176
models.RemoteUpdate(remote.Tag, func(u *models.Remote) {
183177
u.Status = "connected"
184178
})
@@ -210,12 +204,12 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
210204
proxyEngin.remoteForward = forword
211205

212206
switch strings.ToLower(proxy.Mode) {
213-
case models.MODE_DOMAIN:
214-
access.ForwardHandlerSet(proxyEngin.DomainForwardFunc)
215-
case models.MODE_REMOTE:
216-
access.ForwardHandlerSet(proxyEngin.ProxyForwardFunc)
217-
case models.MODE_LOCAL:
218-
access.ForwardHandlerSet(proxyEngin.LocalForwardFunc)
207+
case models.MODE_DOMAIN:
208+
access.ForwardHandlerSet(proxyEngin.DomainForwardFunc)
209+
case models.MODE_REMOTE:
210+
access.ForwardHandlerSet(proxyEngin.ProxyForwardFunc)
211+
case models.MODE_LOCAL:
212+
access.ForwardHandlerSet(proxyEngin.LocalForwardFunc)
219213
default:
220214
panic(fmt.Sprintf("proxy mode(%s) not support", proxy.Mode))
221215
}
@@ -225,7 +219,6 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
225219

226220
var PublicLocalForward engin.Forward
227221

228-
func init() {
229-
PublicLocalForward, _ = engin.NewDefault(30)
222+
func init() {
223+
PublicLocalForward = engin.NewLocalForward(30)
230224
}
231-

0 commit comments

Comments
 (0)