mirror of https://github.com/dnomd343/XProxy.git
dnomd343
2 years ago
8 changed files with 246 additions and 224 deletions
@ -0,0 +1,43 @@ |
|||||
|
package common |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
log "github.com/sirupsen/logrus" |
||||
|
"net" |
||||
|
"os/exec" |
||||
|
"strings" |
||||
|
"syscall" |
||||
|
) |
||||
|
|
||||
|
func isIP(ipAddr string, isCidr bool) bool { |
||||
|
if !isCidr { |
||||
|
return net.ParseIP(ipAddr) != nil |
||||
|
} |
||||
|
_, _, err := net.ParseCIDR(ipAddr) |
||||
|
return err == nil |
||||
|
} |
||||
|
|
||||
|
func IsIPv4(ipAddr string, isCidr bool) bool { |
||||
|
return isIP(ipAddr, isCidr) && strings.Contains(ipAddr, ".") |
||||
|
} |
||||
|
|
||||
|
func IsIPv6(ipAddr string, isCidr bool) bool { |
||||
|
return isIP(ipAddr, isCidr) && strings.Contains(ipAddr, ":") |
||||
|
} |
||||
|
|
||||
|
func JsonEncode(raw interface{}) string { |
||||
|
jsonOutput, _ := json.MarshalIndent(raw, "", " ") // json encode
|
||||
|
return string(jsonOutput) |
||||
|
} |
||||
|
|
||||
|
func RunCommand(command ...string) (int, string) { |
||||
|
log.Debugf("Running system command -> %v", command) |
||||
|
process := exec.Command(command[0], command[1:]...) |
||||
|
output, _ := process.CombinedOutput() |
||||
|
log.Debugf("Command %v -> \n%s", command, string(output)) |
||||
|
code := process.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() |
||||
|
if code != 0 { |
||||
|
log.Warningf("Command %v return code %d", command, code) |
||||
|
} |
||||
|
return code, string(output) |
||||
|
} |
@ -1,22 +0,0 @@ |
|||||
package common |
|
||||
|
|
||||
import ( |
|
||||
"net" |
|
||||
"strings" |
|
||||
) |
|
||||
|
|
||||
func isIP(ipAddr string, isCidr bool) bool { |
|
||||
if !isCidr { |
|
||||
return net.ParseIP(ipAddr) != nil |
|
||||
} |
|
||||
_, _, err := net.ParseCIDR(ipAddr) |
|
||||
return err == nil |
|
||||
} |
|
||||
|
|
||||
func IsIPv4(ipAddr string, isCidr bool) bool { |
|
||||
return isIP(ipAddr, isCidr) && strings.Contains(ipAddr, ".") |
|
||||
} |
|
||||
|
|
||||
func IsIPv6(ipAddr string, isCidr bool) bool { |
|
||||
return isIP(ipAddr, isCidr) && strings.Contains(ipAddr, ":") |
|
||||
} |
|
@ -1,19 +0,0 @@ |
|||||
package common |
|
||||
|
|
||||
import ( |
|
||||
log "github.com/sirupsen/logrus" |
|
||||
"os/exec" |
|
||||
"syscall" |
|
||||
) |
|
||||
|
|
||||
func RunCommand(command ...string) (int, string) { |
|
||||
log.Debugf("Running system command -> %v", command) |
|
||||
process := exec.Command(command[0], command[1:]...) |
|
||||
output, _ := process.CombinedOutput() |
|
||||
log.Debugf("Command %v -> \n%s", command, string(output)) |
|
||||
code := process.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() |
|
||||
if code != 0 { |
|
||||
log.Warningf("Command %v return code %d", command, code) |
|
||||
} |
|
||||
return code, string(output) |
|
||||
} |
|
@ -1,37 +0,0 @@ |
|||||
package proxy |
|
||||
|
|
||||
type Config struct { |
|
||||
Sniff bool |
|
||||
Redirect bool |
|
||||
V4TProxyPort int |
|
||||
V6TProxyPort int |
|
||||
LogLevel string |
|
||||
HttpInbounds map[string]int |
|
||||
SocksInbounds map[string]int |
|
||||
AddOnInbounds []interface{} |
|
||||
} |
|
||||
|
|
||||
type logObject struct { |
|
||||
Loglevel string `json:"loglevel"` |
|
||||
Access string `json:"access"` |
|
||||
Error string `json:"error"` |
|
||||
} |
|
||||
|
|
||||
type inboundsObject struct { |
|
||||
Inbounds []interface{} `json:"inbounds"` |
|
||||
} |
|
||||
|
|
||||
type sniffObject struct { |
|
||||
Enabled bool `json:"enabled"` |
|
||||
RouteOnly bool `json:"routeOnly"` |
|
||||
DestOverride []string `json:"destOverride"` |
|
||||
} |
|
||||
|
|
||||
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"` |
|
||||
} |
|
Loading…
Reference in new issue