diff --git a/src/load.go b/src/load.go index be25c39..53e592b 100644 --- a/src/load.go +++ b/src/load.go @@ -1,6 +1,8 @@ package main import ( + "encoding/json" + "fmt" log "github.com/sirupsen/logrus" "io" "io/ioutil" @@ -47,6 +49,38 @@ var outboundsConfig = `{ ] }` +type emptySettings struct{} + +type socksSettings struct { + UDP bool `json:"udp"` +} + +type tproxySettings struct { + Network string `json:"network"` + FollowRedirect bool `json:"followRedirect"` +} + +type tproxyStreamSettings struct { + Sockopt struct { + Tproxy string `json:"tproxy"` + } `json:"sockopt"` +} + +type sniffSettings struct { + Enabled bool `json:"enabled"` + RouteOnly bool `json:"routeOnly"` + DestOverride []string `json:"destOverride"` +} + +type inboundSettings struct { + Tag string `json:"tag"` + Port int `json:"port"` + Protocol string `json:"protocol"` + Settings interface{} `json:"settings"` + StreamSettings interface{} `json:"streamSettings"` + Sniffing sniffSettings `json:"sniffing"` +} + func isFileExist(filePath string) bool { s, err := os.Stat(filePath) if err != nil { // file or folder not exist @@ -126,6 +160,53 @@ func loadProxy(configDir string, exposeDir string) { // TODO: load inbounds config + sniffObject := sniffSettings{ + Enabled: enableSniff, + RouteOnly: !enableRedirect, + DestOverride: []string{"http", "tls"}, + } + + httpObject := inboundSettings{ + Tag: "123", + Port: 1234, + Protocol: "http", + Settings: emptySettings{}, + StreamSettings: emptySettings{}, + Sniffing: sniffObject, + } + + b, _ := json.Marshal(httpObject) + fmt.Println(string(b)) + + socksObject := inboundSettings{ + Tag: "123", + Port: 2345, + Protocol: "socks", + Settings: socksSettings{ + UDP: true, + }, + StreamSettings: emptySettings{}, + Sniffing: sniffObject, + } + + b, _ = json.Marshal(socksObject) + fmt.Println(string(b)) + + tproxyObject := inboundSettings{ + Tag: "123", + Port: 7288, + Protocol: "dokodemo-door", + Settings: tproxySettings{ + Network: "tcp,udp", + FollowRedirect: true, + }, + StreamSettings: emptySettings{}, + Sniffing: sniffObject, + } + + b, _ = json.Marshal(tproxyObject) + fmt.Println(string(b)) + for _, configFile := range listFolder(exposeDir+"/config", ".json") { if configFile == "log.json" || configFile == "inbounds.json" { log.Warningf("Config file `%s` will be overrided", configFile) diff --git a/src/main.go b/src/main.go index 16df17b..af96075 100644 --- a/src/main.go +++ b/src/main.go @@ -4,7 +4,12 @@ import ( log "github.com/sirupsen/logrus" ) -var logLevel = "debug" +var logLevel = "warning" +var v4TProxyPort = 7288 +var v6TProxyPort = 7289 + +var enableSniff = false +var enableRedirect = true func main() { log.SetLevel(log.DebugLevel) diff --git a/test.yml b/test.yml index 68127ee..3fccf2c 100644 --- a/test.yml +++ b/test.yml @@ -1,8 +1,18 @@ +proxy: + sniff: true + redirect: true + http: + - ipv4: 1084 + - ipv6: 1086 + socks: + - nodeA: 1681 + - nodeB: 1682 + - nodeC: 1683 + network: dns: - 223.5.5.5 - 119.29.29.29 -# - fesdc.fardf.afa ipv4: gateway: 192.168.2.1 address: 192.168.2.2/24