@@ -12,6 +12,7 @@ import (
12
12
"github.com/WangYihang/Platypus/lib/util/str"
13
13
"github.com/WangYihang/Platypus/lib/util/ui"
14
14
"github.com/WangYihang/readline"
15
+ "github.com/armon/go-socks5"
15
16
"github.com/fatih/color"
16
17
"github.com/gin-gonic/gin"
17
18
"gopkg.in/olahol/melody.v1"
@@ -50,6 +51,7 @@ type Context struct {
50
51
PullTunnelInstance map [string ]PullTunnelInstance
51
52
PushTunnelConfig map [string ]PushTunnelConfig
52
53
PushTunnelInstance map [string ]PushTunnelInstance
54
+ Socks5Servers map [string ](* socks5.Server )
53
55
// Set later in platypus.go
54
56
Distributor * Distributor
55
57
RESTful * gin.Engine
@@ -72,6 +74,7 @@ func CreateContext() {
72
74
PullTunnelInstance : make (map [string ]PullTunnelInstance ),
73
75
PushTunnelConfig : make (map [string ]PushTunnelConfig ),
74
76
PushTunnelInstance : make (map [string ]PushTunnelInstance ),
77
+ Socks5Servers : make (map [string ]* socks5.Server ),
75
78
}
76
79
}
77
80
// Signal Handler
@@ -197,6 +200,7 @@ func Shutdown() {
197
200
}
198
201
199
202
func AddPushTunnelConfig (termite * TermiteClient , local_address string , remote_address string ) {
203
+ log .Info ("Mapping local (%s) to remote (%s)" , local_address , remote_address )
200
204
termite .AtomLock .Lock ()
201
205
defer func () { termite .AtomLock .Unlock () }()
202
206
@@ -220,6 +224,7 @@ func AddPushTunnelConfig(termite *TermiteClient, local_address string, remote_ad
220
224
}
221
225
222
226
func AddPullTunnelConfig (termite * TermiteClient , local_address string , remote_address string ) {
227
+ log .Info ("Mapping remote (%s) to local (%s)" , remote_address , local_address )
223
228
tunnel , err := net .Listen ("tcp" , local_address )
224
229
if err != nil {
225
230
log .Error (err .Error ())
@@ -277,6 +282,24 @@ func WriteTunnel(termite *TermiteClient, token string, data []byte) {
277
282
}
278
283
}
279
284
285
+ func StartSocks5Server (local_address string ) error {
286
+ // Create tcp listener
287
+ socks5ServerListener , err := net .Listen ("tcp" , local_address )
288
+ if err != nil {
289
+ return err
290
+ }
291
+ // Create socks5 server
292
+ server , err := socks5 .New (& socks5.Config {})
293
+ if err != nil {
294
+ return err
295
+ }
296
+ Ctx .Socks5Servers [local_address ] = server
297
+ // Start socks5 server
298
+ go server .Serve (socks5ServerListener )
299
+ log .Success ("Socks server started at: %s" , local_address )
300
+ return nil
301
+ }
302
+
280
303
// func DeletePullTunnelConfig(local_host string, local_port uint16, remote_host string, remote_port uint16) {
281
304
// local_address := fmt.Sprintf("%s:%d", local_host, local_port)
282
305
// remote_address := fmt.Sprintf("%s:%d", remote_host, remote_port)
0 commit comments