mirror of https://github.com/dnomd343/XProxy.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.1 KiB
112 lines
3.1 KiB
package proxy
|
|
|
|
import (
|
|
"XProxy/cmd/common"
|
|
log "github.com/sirupsen/logrus"
|
|
"path"
|
|
)
|
|
|
|
var outboundsConfig = `{
|
|
"outbounds": [
|
|
{
|
|
"protocol": "freedom",
|
|
"settings": {}
|
|
}
|
|
]
|
|
}`
|
|
|
|
type logObject struct {
|
|
Log struct {
|
|
Loglevel string `json:"loglevel"`
|
|
Access string `json:"access"`
|
|
Error string `json:"error"`
|
|
} `json:"log"`
|
|
}
|
|
|
|
type inboundsObject struct {
|
|
Inbounds []interface{} `json:"inbounds"`
|
|
}
|
|
|
|
type sniffObject struct {
|
|
Enabled bool `json:"enabled"`
|
|
RouteOnly bool `json:"routeOnly"`
|
|
DestOverride []string `json:"destOverride"`
|
|
DomainsExcluded []string `json:"domainsExcluded"`
|
|
}
|
|
|
|
type inboundObject struct {
|
|
Tag string `json:"tag"`
|
|
Port int `json:"port"`
|
|
Protocol string `json:"protocol"`
|
|
Settings interface{} `json:"settings"`
|
|
StreamSettings interface{} `json:"streamSettings"`
|
|
Sniffing sniffObject `json:"sniffing"`
|
|
}
|
|
|
|
func loadLogConfig(logLevel string, logDir string) string {
|
|
if logLevel == "" {
|
|
logLevel = "warning" // using warning level without log output
|
|
}
|
|
if logLevel != "debug" && logLevel != "info" &&
|
|
logLevel != "warning" && logLevel != "error" && logLevel != "none" {
|
|
log.Warningf("Unknown log level -> %s", logLevel)
|
|
logLevel = "warning" // using `warning` as default
|
|
}
|
|
logConfig := logObject{}
|
|
logConfig.Log.Loglevel = logLevel
|
|
logConfig.Log.Access = path.Join(logDir, "access.log")
|
|
logConfig.Log.Error = path.Join(logDir, "error.log")
|
|
return common.JsonEncode(logConfig)
|
|
}
|
|
|
|
func loadHttpConfig(tag string, port int, sniff sniffObject) interface{} {
|
|
type empty struct{}
|
|
return inboundObject{
|
|
Tag: tag,
|
|
Port: port,
|
|
Protocol: "http",
|
|
Settings: empty{},
|
|
StreamSettings: empty{},
|
|
Sniffing: sniff,
|
|
}
|
|
}
|
|
|
|
func loadSocksConfig(tag string, port int, sniff sniffObject) interface{} {
|
|
type empty struct{}
|
|
type socksObject struct {
|
|
UDP bool `json:"udp"`
|
|
}
|
|
return inboundObject{
|
|
Tag: tag,
|
|
Port: port,
|
|
Protocol: "socks",
|
|
Settings: socksObject{UDP: true},
|
|
StreamSettings: empty{},
|
|
Sniffing: sniff,
|
|
}
|
|
}
|
|
|
|
func loadTProxyConfig(tag string, port int, sniff sniffObject) interface{} {
|
|
type tproxyObject struct {
|
|
Network string `json:"network"`
|
|
FollowRedirect bool `json:"followRedirect"`
|
|
}
|
|
type tproxyStreamObject struct {
|
|
Sockopt struct {
|
|
Tproxy string `json:"tproxy"`
|
|
} `json:"sockopt"`
|
|
}
|
|
tproxyStream := tproxyStreamObject{}
|
|
tproxyStream.Sockopt.Tproxy = "tproxy"
|
|
return inboundObject{
|
|
Tag: tag,
|
|
Port: port,
|
|
Protocol: "dokodemo-door",
|
|
Settings: tproxyObject{
|
|
Network: "tcp,udp",
|
|
FollowRedirect: true,
|
|
},
|
|
StreamSettings: tproxyStream,
|
|
Sniffing: sniff,
|
|
}
|
|
}
|
|
|