-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (60 loc) · 1.4 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
// +build !lib
package main
import (
"flag"
log "github.com/sirupsen/logrus"
)
func main() {
rp := flag.String("rp", "", "Remote Port. eg: -rp 8080")
lp := flag.String("lp", "", "Local Port. eg: -lp 1080")
pk := flag.String("pk", "AwayPasskey", "Passkey to do crypto. eg: -pk \"Away Passkey\"")
ru := flag.String("ru", "", "Remote Url to connect. eg: -ru http://away.remote")
rf := flag.String("rf", "", "Rules File use to initilize rules. eg: /path/rules")
flag.Parse()
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, TimestampFormat: "2006/01/02 15:04:05.000"})
if *rp != "" && *lp != "" {
go startSocks(*lp, *pk, *rp, *ru, *rf)
startRemote(*rp, *pk)
} else if *rp != "" {
startRemote(*rp, *pk)
} else {
startSocks(*lp, *pk, *rp, *ru, *rf)
}
}
func defaultVal(origin, value string) string {
if origin != "" {
return origin
}
return value
}
func startRemote(rp, pk string) {
s := &Settings{
Passkey: pk,
Port: rp,
}
Remote(s)
}
func startSocks(lp, pk, rp, ru, rf string) {
s := &Settings{
Remote: defaultVal(ru, "http://localhost:"+rp),
Passkey: pk,
Port: lp,
}
away := NewAway(ModeAway, rf)
if rf != "" {
n, err := away.LoadRules()
if err != nil {
log.Error(err)
} else {
log.Infof("Initilize [%d] rules.", n)
}
if n > 0 {
away.ChangeMode(ModeRule)
}
}
srv, err := NewSocksSrv(s, away)
if err != nil {
log.Fatal(err)
}
srv.Start()
}