-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
84 lines (70 loc) · 1.52 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
"syscall"
"github.com/aiocloud/stream/api"
"github.com/aiocloud/stream/dns"
"github.com/aiocloud/stream/mitm"
)
var (
flags struct {
Path string
VerCode bool
}
version = "1.1.3"
Data struct {
API struct {
Addr string `json:"addr"`
Secret string `json:"secret"`
} `json:"api"`
DNS struct {
Upstream string `json:"upstream"`
} `json:"dns"`
MiTM struct {
HTTP []string `json:"http"`
TLS []string `json:"tls"`
} `json:"mitm"`
Allowed []string `json:"allowed"`
}
)
func main() {
flag.StringVar(&flags.Path, "c", "/etc/stream.json", "Path")
flag.BoolVar(&flags.VerCode, "v", false, "VerCode")
flag.Parse()
if flags.VerCode {
fmt.Println(version)
return
}
{
data, err := ioutil.ReadFile(flags.Path)
if err != nil {
log.Fatalf("[APP] %v", err)
}
if err = json.Unmarshal(data, &Data); err != nil {
log.Fatalf("[APP] %v", err)
}
}
api.Secret = Data.API.Secret
dns.Upstream = Data.DNS.Upstream
for i := 0; i < len(Data.Allowed); i++ {
api.Create(Data.Allowed[i])
}
for i := 0; i < len(Data.MiTM.HTTP); i++ {
mitm.ListenHTTP(Data.MiTM.HTTP[i])
}
for i := 0; i < len(Data.MiTM.TLS); i++ {
mitm.ListenTLS(Data.MiTM.TLS[i])
}
if Data.API.Addr != "" {
api.Listen(Data.API.Addr)
}
channel := make(chan os.Signal, 1)
signal.Notify(channel, syscall.SIGINT, syscall.SIGTERM)
<-channel
}