mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
fix bug,fix spelling mistakes,del redundant code
This commit is contained in:
parent
8c9786a4d5
commit
0b7eb9972e
10
api/node.go
10
api/node.go
@ -196,11 +196,11 @@ func (c *Client) ParseSSNodeResponse() (*NodeInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
node := &NodeInfo{
|
||||
SpeedLimit: uint64(c.SpeedLimit * 1000000 / 8),
|
||||
DeviceLimit: c.DeviceLimit,
|
||||
EnableSS2022: c.EnableSS2022,
|
||||
NodeType: c.NodeType,
|
||||
NodeId: c.NodeID,
|
||||
SpeedLimit: uint64(c.SpeedLimit * 1000000 / 8),
|
||||
DeviceLimit: c.DeviceLimit,
|
||||
//EnableSS2022: c.EnableSS2022,
|
||||
NodeType: c.NodeType,
|
||||
NodeId: c.NodeID,
|
||||
SS: &SSConfig{
|
||||
Port: port,
|
||||
TransportProtocol: "tcp",
|
||||
|
@ -98,7 +98,7 @@ type DefaultDispatcher struct {
|
||||
dns dns.Client
|
||||
fdns dns.FakeDNSEngine
|
||||
Limiter *limiter.Limiter
|
||||
RuleManager *rule.RuleManager
|
||||
RuleManager *rule.Rule
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
"github.com/go-acme/lego/v4/registration"
|
@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/urfave/cli"
|
@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"crypto/x509"
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/go-acme/lego/v4/lego"
|
@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/certificate"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
"github.com/go-acme/lego/v4/registration"
|
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/certcrypto"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
"github.com/go-acme/lego/v4/registration"
|
@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/log"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/log"
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/challenge/http01"
|
@ -1,6 +1,6 @@
|
||||
// Let's Encrypt client to go!
|
||||
// Package legocmd Let's Encrypt client to go!
|
||||
// CLI application for generating Let's Encrypt certificates using the ACME package.
|
||||
package legocmd
|
||||
package legoCmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd/cmd"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd/cmd"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -34,18 +34,18 @@ func New() (*LegoCMD, error) {
|
||||
fmt.Printf("lego version %s %s/%s\n", c.App.Version, runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
|
||||
// Set default path to configPath/cert
|
||||
var path string = ""
|
||||
// Set default pathTemp to configPath/cert
|
||||
var pathTemp = ""
|
||||
configPath := os.Getenv("XRAY_LOCATION_CONFIG")
|
||||
if configPath != "" {
|
||||
path = configPath
|
||||
pathTemp = configPath
|
||||
} else if cwd, err := os.Getwd(); err == nil {
|
||||
path = cwd
|
||||
pathTemp = cwd
|
||||
} else {
|
||||
path = "."
|
||||
pathTemp = "."
|
||||
}
|
||||
|
||||
defaultPath = filepath.Join(path, "cert")
|
||||
defaultPath = filepath.Join(pathTemp, "cert")
|
||||
|
||||
app.Flags = cmd.CreateFlags(defaultPath)
|
||||
|
||||
@ -121,8 +121,8 @@ func (l *LegoCMD) HTTPCert(domain, email string) (CertPath string, KeyPath strin
|
||||
if err == nil {
|
||||
return CertPath, KeyPath, err
|
||||
}
|
||||
argstring := fmt.Sprintf("lego -a -d %s -m %s --http run", domain, email)
|
||||
err = l.cmdClient.Run(strings.Split(argstring, " "))
|
||||
argString := fmt.Sprintf("lego -a -d %s -m %s --http run", domain, email)
|
||||
err = l.cmdClient.Run(strings.Split(argString, " "))
|
||||
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
@ -146,7 +146,7 @@ func (l *LegoCMD) RenewCert(domain, email, certMode, provider string, DNSEnv map
|
||||
case error:
|
||||
err = x
|
||||
default:
|
||||
err = errors.New("unknow panic")
|
||||
err = errors.New("unknown panic")
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
@ -161,7 +161,7 @@ func (l *LegoCMD) RenewCert(domain, email, certMode, provider string, DNSEnv map
|
||||
}
|
||||
argstring = fmt.Sprintf("lego -a -d %s -m %s --dns %s renew --days 30", domain, email, provider)
|
||||
} else {
|
||||
return "", "", fmt.Errorf("Unsupport cert mode: %s", certMode)
|
||||
return "", "", fmt.Errorf("unsupport cert mode: %s", certMode)
|
||||
}
|
||||
err = l.cmdClient.Run(strings.Split(argstring, " "))
|
||||
|
||||
@ -178,10 +178,10 @@ func checkCertfile(domain string) (string, string, error) {
|
||||
keyPath := path.Join(defaultPath, "certificates", fmt.Sprintf("%s.key", domain))
|
||||
certPath := path.Join(defaultPath, "certificates", fmt.Sprintf("%s.crt", domain))
|
||||
if _, err := os.Stat(keyPath); os.IsNotExist(err) {
|
||||
return "", "", fmt.Errorf("Cert key failed: %s", domain)
|
||||
return "", "", fmt.Errorf("cert key failed: %s", domain)
|
||||
}
|
||||
if _, err := os.Stat(certPath); os.IsNotExist(err) {
|
||||
return "", "", fmt.Errorf("Cert cert failed: %s", domain)
|
||||
return "", "", fmt.Errorf("cert cert failed: %s", domain)
|
||||
}
|
||||
absKeyPath, _ := filepath.Abs(keyPath)
|
||||
absCertPath, _ := filepath.Abs(certPath)
|
@ -1,20 +1,20 @@
|
||||
package legocmd_test
|
||||
package legoCmd_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd"
|
||||
)
|
||||
|
||||
func TestLegoClient(t *testing.T) {
|
||||
_, err := legocmd.New()
|
||||
_, err := legoCmd.New()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegoDNSCert(t *testing.T) {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -36,7 +36,7 @@ func TestLegoDNSCert(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLegoHTTPCert(t *testing.T) {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -53,7 +53,7 @@ func TestLegoHTTPCert(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLegoRenewCert(t *testing.T) {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
@ -12,19 +12,19 @@ import (
|
||||
mapset "github.com/deckarep/golang-set"
|
||||
)
|
||||
|
||||
type RuleManager struct {
|
||||
type Rule struct {
|
||||
InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule
|
||||
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
|
||||
}
|
||||
|
||||
func New() *RuleManager {
|
||||
return &RuleManager{
|
||||
func New() *Rule {
|
||||
return &Rule{
|
||||
InboundRule: new(sync.Map),
|
||||
InboundDetectResult: new(sync.Map),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RuleManager) UpdateRule(tag string, newRuleList []api.DetectRule) error {
|
||||
func (r *Rule) UpdateRule(tag string, newRuleList []api.DetectRule) error {
|
||||
if value, ok := r.InboundRule.LoadOrStore(tag, newRuleList); ok {
|
||||
oldRuleList := value.([]api.DetectRule)
|
||||
if !reflect.DeepEqual(oldRuleList, newRuleList) {
|
||||
@ -34,7 +34,7 @@ func (r *RuleManager) UpdateRule(tag string, newRuleList []api.DetectRule) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RuleManager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
||||
func (r *Rule) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
||||
detectResult := make([]api.DetectResult, 0)
|
||||
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
|
||||
resultSet := value.(mapset.Set)
|
||||
@ -46,9 +46,9 @@ func (r *RuleManager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
||||
return &detectResult, nil
|
||||
}
|
||||
|
||||
func (r *RuleManager) Detect(tag string, destination string, email string) (reject bool) {
|
||||
func (r *Rule) Detect(tag string, destination string, email string) (reject bool) {
|
||||
reject = false
|
||||
var hitRuleID int = -1
|
||||
var hitRuleID = -1
|
||||
// If we have some rule for this inbound
|
||||
if value, ok := r.InboundRule.Load(tag); ok {
|
||||
ruleList := value.([]api.DetectRule)
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Package serverstatus generate the server system status
|
||||
package serverstatus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
// GetSystemInfo get the system info of a given periodic
|
||||
func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime int, err error) {
|
||||
|
||||
upTime := time.Now()
|
||||
cpuPercent, err := cpu.Percent(0, false)
|
||||
// Check if cpuPercent is empty
|
||||
if len(cpuPercent) > 0 {
|
||||
Cpu = cpuPercent[0]
|
||||
} else {
|
||||
Cpu = 0
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, fmt.Errorf("get cpu usage failed: %s", err)
|
||||
}
|
||||
|
||||
memUsage, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, fmt.Errorf("get mem usage failed: %s", err)
|
||||
}
|
||||
|
||||
diskUsage, err := disk.Usage("/")
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, fmt.Errorf("et disk usage failed: %s", err)
|
||||
}
|
||||
|
||||
Uptime = int(time.Since(upTime).Seconds())
|
||||
return Cpu, memUsage.UsedPercent, diskUsage.UsedPercent, Uptime, nil
|
||||
}
|
@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/Yuzuki616/V2bX/api"
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/task"
|
||||
"github.com/xtls/xray-core/core"
|
||||
@ -168,7 +168,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
||||
// Check Cert
|
||||
if c.nodeInfo.EnableTls && c.config.CertConfig.CertMode != "none" &&
|
||||
(c.config.CertConfig.CertMode == "dns" || c.config.CertConfig.CertMode == "http") {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
//Package generate the InbounderConfig used by add inbound
|
||||
// Package controller the InbounderConfig used by add inbound
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/api"
|
||||
"github.com/Yuzuki616/V2bX/common/legocmd"
|
||||
"github.com/Yuzuki616/V2bX/common/legoCmd"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
"github.com/xtls/xray-core/core"
|
||||
@ -178,7 +178,7 @@ func getCertFile(certConfig *CertConfig) (certFile string, keyFile string, err e
|
||||
}
|
||||
return certConfig.CertFile, certConfig.KeyFile, nil
|
||||
} else if certConfig.CertMode == "dns" {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@ -188,7 +188,7 @@ func getCertFile(certConfig *CertConfig) (certFile string, keyFile string, err e
|
||||
}
|
||||
return certPath, keyPath, err
|
||||
} else if certConfig.CertMode == "http" {
|
||||
lego, err := legocmd.New()
|
||||
lego, err := legoCmd.New()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
|
||||
// Build Send IP address
|
||||
if config.SendIP != "" {
|
||||
ipAddress := net.ParseAddress(config.SendIP)
|
||||
outboundDetourConfig.SendThrough = &conf.Address{ipAddress}
|
||||
outboundDetourConfig.SendThrough = &conf.Address{Address: ipAddress}
|
||||
}
|
||||
|
||||
// Freedom Protocol setting
|
||||
var domainStrategy string = "Asis"
|
||||
var domainStrategy = "Asis"
|
||||
if config.EnableDNS {
|
||||
if config.DNSType != "" {
|
||||
domainStrategy = config.DNSType
|
||||
@ -41,7 +41,7 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
|
||||
var setting json.RawMessage
|
||||
setting, err := json.Marshal(proxySetting)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||
}
|
||||
outboundDetourConfig.Settings = &setting
|
||||
return outboundDetourConfig.Build()
|
||||
|
Loading…
Reference in New Issue
Block a user