@@ -2,20 +2,21 @@ package pages
2
2
3
3
import (
4
4
"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"
10
5
"net"
11
6
"net/http"
12
7
"net/url"
13
8
"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"
14
15
)
15
16
16
17
type ProxyEngin struct {
17
- proxy * models.Proxy
18
- remote * models.Remote
18
+ proxy * models.Proxy
19
+ remote * models.Remote
19
20
access engin.Access
20
21
localForward engin.Forward
21
22
remoteForward engin.Forward
@@ -40,10 +41,10 @@ func parseAddress(protocal string, address string) (string, int, error) {
40
41
}
41
42
return "" , 0 , fmt .Errorf ("protocal not support" )
42
43
}
43
- return address [:idx ], util .Atoi (address [idx + 1 :]), nil
44
+ return address [:idx ], util .Atoi (address [idx + 1 :]), nil
44
45
}
45
46
46
- func (p * ProxyEngin )authHandler (info * engin.AuthInfo ) bool {
47
+ func (p * ProxyEngin ) authHandler (info * engin.AuthInfo ) bool {
47
48
if info == nil {
48
49
logger .Warnf ("not any auth info" )
49
50
return false
@@ -60,7 +61,7 @@ func (p *ProxyEngin)authHandler(info *engin.AuthInfo) bool {
60
61
return false
61
62
}
62
63
63
- func (p * ProxyEngin )AuthSwitch (auth int ) {
64
+ func (p * ProxyEngin ) AuthSwitch (auth int ) {
64
65
if auth > 0 {
65
66
p .access .AuthHandlerSet (p .authHandler )
66
67
} else {
@@ -69,15 +70,15 @@ func (p *ProxyEngin)AuthSwitch(auth int) {
69
70
p .proxy .Auth = auth
70
71
}
71
72
72
- func (p * ProxyEngin )Stop () {
73
+ func (p * ProxyEngin ) Stop () {
73
74
p .access .Shutdown ()
74
75
if p .remoteForward != nil {
75
76
p .remoteForward .Close ()
76
77
}
77
78
}
78
79
79
80
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 )
81
82
if err != nil {
82
83
return nil , err
83
84
}
@@ -108,7 +109,7 @@ func remoteForwardInit(remote *models.Remote) (engin.Forward, error) {
108
109
auth = & engin.AuthInfo {User : remote .User , Token : remote .Password }
109
110
}
110
111
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 )
112
113
if err != nil {
113
114
return nil , err
114
115
}
@@ -144,19 +145,19 @@ func remoteForwardTest(testurl string, forward engin.Forward) error {
144
145
return nil
145
146
}
146
147
147
- func (p * ProxyEngin )DomainForwardFunc (address string , r * http.Request ) engin.Forward {
148
+ func (p * ProxyEngin ) DomainForwardFunc (address string , r * http.Request ) engin.Forward {
148
149
if DomainCheck (address ) {
149
150
logs .Info ("%s auto forward to remote proxy" , address )
150
151
return p .remoteForward
151
152
}
152
153
return PublicLocalForward
153
154
}
154
155
155
- func (p * ProxyEngin )LocalForwardFunc (address string , r * http.Request ) engin.Forward {
156
+ func (p * ProxyEngin ) LocalForwardFunc (address string , r * http.Request ) engin.Forward {
156
157
return PublicLocalForward
157
158
}
158
159
159
- func (p * ProxyEngin )ProxyForwardFunc (address string , r * http.Request ) engin.Forward {
160
+ func (p * ProxyEngin ) ProxyForwardFunc (address string , r * http.Request ) engin.Forward {
160
161
return p .remoteForward
161
162
}
162
163
@@ -172,13 +173,6 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
172
173
if err != nil {
173
174
return nil , err
174
175
}
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
- }
182
176
models .RemoteUpdate (remote .Tag , func (u * models.Remote ) {
183
177
u .Status = "connected"
184
178
})
@@ -210,12 +204,12 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
210
204
proxyEngin .remoteForward = forword
211
205
212
206
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 )
219
213
default :
220
214
panic (fmt .Sprintf ("proxy mode(%s) not support" , proxy .Mode ))
221
215
}
@@ -225,7 +219,6 @@ func NewProxyEngin(proxy *models.Proxy, remote *models.Remote) (*ProxyEngin, err
225
219
226
220
var PublicLocalForward engin.Forward
227
221
228
- func init () {
229
- PublicLocalForward , _ = engin .NewDefault (30 )
222
+ func init () {
223
+ PublicLocalForward = engin .NewLocalForward (30 )
230
224
}
231
-
0 commit comments