-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocks5.go
69 lines (56 loc) · 1.65 KB
/
socks5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"log"
"log/slog"
"os"
"strconv"
"github.com/alexng353/ihostproxy/context"
"github.com/alexng353/ihostproxy/credentials"
"github.com/alexng353/ihostproxy/helpers"
"github.com/things-go/go-socks5"
// "github.com/armon/go-socks5"
)
var c = credentials.Get()
func startProxy(ctx context.Env) {
if ctx.Creds != "" {
err := c.Load(ctx.Creds)
if err != nil {
slog.Error("Failed to load credentials", "error", err)
}
}
// if ctx.ProxyUser != "" && ctx.ProxyPassword != "" {
// err := c.AddEntry(ctx.ProxyUser, ctx.ProxyPassword)
// if err != nil {
// slog.Error("Failed to add entry", "error", err)
// }
// }
// socks5conf := &socks5.Config{
// Logger: log.New(os.Stdout, "socks5: ", log.LstdFlags),
// }
// cator := socks5.UserPassAuthenticator{Credentials: c}
// cator := socks5.UserPassAuthenticator{
// Credentials: socks5.StaticCredentials{
// ctx.ProxyUser: ctx.ProxyPassword,
// },
// }
// socks5conf.AuthMethods = []socks5.Authenticator{cator}
// server, err := socks5.New(socks5conf)
// if err != nil {
// log.Fatal(err)
// }
cator := socks5.UserPassAuthenticator{Credentials: c}
// cator := socks5.UserPassAuthenticator{
// Credentials: socks5.StaticCredentials{
// ctx.ProxyUser: ctx.ProxyPassword,
// },
// }
server := socks5.NewServer(
socks5.WithLogger(socks5.NewLogger(log.New(os.Stdout, "socks5: ", log.LstdFlags))),
socks5.WithAuthMethods([]socks5.Authenticator{cator}),
)
port := strconv.FormatInt(int64(helpers.ValidatePort(ctx.ProxyPort)), 10)
slog.Info("Starting Socks5 Proxy", "port", port)
if err := server.ListenAndServe("tcp", ":"+port); err != nil {
panic(err)
}
}