-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (74 loc) · 1.61 KB
/
main.go
File metadata and controls
79 lines (74 loc) · 1.61 KB
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
70
71
72
73
74
75
76
77
78
79
package main
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"time"
"github.com/elitah/fast-io"
"github.com/elitah/utils/autocert"
)
func main() {
acm := autocert.NewAutoCertManager()
go func() {
http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if hj, ok := w.(http.Hijacker); ok {
if conn, _, err := hj.Hijack(); nil == err {
defer conn.Close()
acm.ServeRequest(conn, r)
}
}
}))
}()
if ls, err := tls.Listen("tcp", ":443", &tls.Config{
GetCertificate: acm.GetCertificate,
}); nil == err {
for {
if conn, err := ls.Accept(); nil == err {
go func() {
//
defer conn.Close()
//
if src, ok := conn.(*tls.Conn); ok {
if err := src.Handshake(); nil == err {
//
var target string
//
state := src.ConnectionState()
//
fmt.Println(state.ServerName)
//
switch state.ServerName {
case "elitah.xyz", "elitah.tk", "elitah.ml":
target = "127.0.0.1:18880"
case "ssh.elitah.xyz", "ssh.elitah.tk", "ssh.elitah.ml":
target = "127.0.0.1:8788"
default:
target = "127.0.0.1:30080"
}
//
if "" != target {
if dst, err := net.DialTimeout("tcp", target, 5*time.Second); nil == err {
fast_io.FastCopy(dst, src)
} else {
fmt.Println(err)
}
} else {
fmt.Println("no target")
}
} else {
fmt.Println(err)
}
} else {
fmt.Println("no tls.Conn")
}
}()
} else {
fmt.Println(err)
break
}
}
} else {
fmt.Println(err)
}
}