Browse Source

feat: demo of inbound object

v1.x.x
dnomd343 2 years ago
parent
commit
f455cfd81e
  1. 81
      src/load.go
  2. 7
      src/main.go
  3. 12
      test.yml

81
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)

7
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)

12
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

Loading…
Cancel
Save