fix bug,fix spelling mistakes,del redundant code

This commit is contained in:
yuzuki999 2022-06-04 17:12:28 +08:00
parent 8c9786a4d5
commit 0b7eb9972e
25 changed files with 51 additions and 92 deletions

View File

@ -196,11 +196,11 @@ func (c *Client) ParseSSNodeResponse() (*NodeInfo, error) {
return nil, err return nil, err
} }
node := &NodeInfo{ node := &NodeInfo{
SpeedLimit: uint64(c.SpeedLimit * 1000000 / 8), SpeedLimit: uint64(c.SpeedLimit * 1000000 / 8),
DeviceLimit: c.DeviceLimit, DeviceLimit: c.DeviceLimit,
EnableSS2022: c.EnableSS2022, //EnableSS2022: c.EnableSS2022,
NodeType: c.NodeType, NodeType: c.NodeType,
NodeId: c.NodeID, NodeId: c.NodeID,
SS: &SSConfig{ SS: &SSConfig{
Port: port, Port: port,
TransportProtocol: "tcp", TransportProtocol: "tcp",

View File

@ -98,7 +98,7 @@ type DefaultDispatcher struct {
dns dns.Client dns dns.Client
fdns dns.FakeDNSEngine fdns dns.FakeDNSEngine
Limiter *limiter.Limiter Limiter *limiter.Limiter
RuleManager *rule.RuleManager RuleManager *rule.Rule
} }
func init() { func init() {

View File

@ -13,7 +13,7 @@ import (
"path/filepath" "path/filepath"
"strings" "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/certcrypto"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "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/certcrypto"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
"github.com/urfave/cli" "github.com/urfave/cli"

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/Yuzuki616/V2bX/common/legocmd/log" "github.com/Yuzuki616/V2bX/common/legoCmd/log"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View File

@ -5,7 +5,7 @@ import (
"crypto/x509" "crypto/x509"
"time" "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/certcrypto"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/Yuzuki616/V2bX/common/legocmd/log" "github.com/Yuzuki616/V2bX/common/legoCmd/log"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"strings" "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/certificate"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "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/certcrypto"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "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"
"github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/challenge/http01" "github.com/go-acme/lego/v4/challenge/http01"

View File

@ -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. // CLI application for generating Let's Encrypt certificates using the ACME package.
package legocmd package legoCmd
import ( import (
"errors" "errors"
@ -11,7 +11,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/Yuzuki616/V2bX/common/legocmd/cmd" "github.com/Yuzuki616/V2bX/common/legoCmd/cmd"
"github.com/urfave/cli" "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) fmt.Printf("lego version %s %s/%s\n", c.App.Version, runtime.GOOS, runtime.GOARCH)
} }
// Set default path to configPath/cert // Set default pathTemp to configPath/cert
var path string = "" var pathTemp = ""
configPath := os.Getenv("XRAY_LOCATION_CONFIG") configPath := os.Getenv("XRAY_LOCATION_CONFIG")
if configPath != "" { if configPath != "" {
path = configPath pathTemp = configPath
} else if cwd, err := os.Getwd(); err == nil { } else if cwd, err := os.Getwd(); err == nil {
path = cwd pathTemp = cwd
} else { } else {
path = "." pathTemp = "."
} }
defaultPath = filepath.Join(path, "cert") defaultPath = filepath.Join(pathTemp, "cert")
app.Flags = cmd.CreateFlags(defaultPath) app.Flags = cmd.CreateFlags(defaultPath)
@ -121,8 +121,8 @@ func (l *LegoCMD) HTTPCert(domain, email string) (CertPath string, KeyPath strin
if err == nil { if err == nil {
return CertPath, KeyPath, err return CertPath, KeyPath, err
} }
argstring := fmt.Sprintf("lego -a -d %s -m %s --http run", domain, email) argString := fmt.Sprintf("lego -a -d %s -m %s --http run", domain, email)
err = l.cmdClient.Run(strings.Split(argstring, " ")) err = l.cmdClient.Run(strings.Split(argString, " "))
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -146,7 +146,7 @@ func (l *LegoCMD) RenewCert(domain, email, certMode, provider string, DNSEnv map
case error: case error:
err = x err = x
default: default:
err = errors.New("unknow panic") err = errors.New("unknown panic")
} }
return "", "", err 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) argstring = fmt.Sprintf("lego -a -d %s -m %s --dns %s renew --days 30", domain, email, provider)
} else { } else {
return "", "", fmt.Errorf("Unsupport cert mode: %s", certMode) return "", "", fmt.Errorf("unsupport cert mode: %s", certMode)
} }
err = l.cmdClient.Run(strings.Split(argstring, " ")) 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)) keyPath := path.Join(defaultPath, "certificates", fmt.Sprintf("%s.key", domain))
certPath := path.Join(defaultPath, "certificates", fmt.Sprintf("%s.crt", domain)) certPath := path.Join(defaultPath, "certificates", fmt.Sprintf("%s.crt", domain))
if _, err := os.Stat(keyPath); os.IsNotExist(err) { 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) { 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) absKeyPath, _ := filepath.Abs(keyPath)
absCertPath, _ := filepath.Abs(certPath) absCertPath, _ := filepath.Abs(certPath)

View File

@ -1,20 +1,20 @@
package legocmd_test package legoCmd_test
import ( import (
"testing" "testing"
"github.com/Yuzuki616/V2bX/common/legocmd" "github.com/Yuzuki616/V2bX/common/legoCmd"
) )
func TestLegoClient(t *testing.T) { func TestLegoClient(t *testing.T) {
_, err := legocmd.New() _, err := legoCmd.New()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
} }
func TestLegoDNSCert(t *testing.T) { func TestLegoDNSCert(t *testing.T) {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -36,7 +36,7 @@ func TestLegoDNSCert(t *testing.T) {
} }
func TestLegoHTTPCert(t *testing.T) { func TestLegoHTTPCert(t *testing.T) {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -53,7 +53,7 @@ func TestLegoHTTPCert(t *testing.T) {
} }
func TestLegoRenewCert(t *testing.T) { func TestLegoRenewCert(t *testing.T) {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -12,19 +12,19 @@ import (
mapset "github.com/deckarep/golang-set" mapset "github.com/deckarep/golang-set"
) )
type RuleManager struct { type Rule struct {
InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
} }
func New() *RuleManager { func New() *Rule {
return &RuleManager{ return &Rule{
InboundRule: new(sync.Map), InboundRule: new(sync.Map),
InboundDetectResult: 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 { if value, ok := r.InboundRule.LoadOrStore(tag, newRuleList); ok {
oldRuleList := value.([]api.DetectRule) oldRuleList := value.([]api.DetectRule)
if !reflect.DeepEqual(oldRuleList, newRuleList) { if !reflect.DeepEqual(oldRuleList, newRuleList) {
@ -34,7 +34,7 @@ func (r *RuleManager) UpdateRule(tag string, newRuleList []api.DetectRule) error
return nil 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) detectResult := make([]api.DetectResult, 0)
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok { if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
resultSet := value.(mapset.Set) resultSet := value.(mapset.Set)
@ -46,9 +46,9 @@ func (r *RuleManager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
return &detectResult, nil 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 reject = false
var hitRuleID int = -1 var hitRuleID = -1
// If we have some rule for this inbound // If we have some rule for this inbound
if value, ok := r.InboundRule.Load(tag); ok { if value, ok := r.InboundRule.Load(tag); ok {
ruleList := value.([]api.DetectRule) ruleList := value.([]api.DetectRule)

View File

@ -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
}

View File

@ -8,7 +8,7 @@ import (
"time" "time"
"github.com/Yuzuki616/V2bX/api" "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/protocol"
"github.com/xtls/xray-core/common/task" "github.com/xtls/xray-core/common/task"
"github.com/xtls/xray-core/core" "github.com/xtls/xray-core/core"
@ -168,7 +168,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
// Check Cert // Check Cert
if c.nodeInfo.EnableTls && c.config.CertConfig.CertMode != "none" && if c.nodeInfo.EnableTls && c.config.CertConfig.CertMode != "none" &&
(c.config.CertConfig.CertMode == "dns" || c.config.CertConfig.CertMode == "http") { (c.config.CertConfig.CertMode == "dns" || c.config.CertConfig.CertMode == "http") {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }

View File

@ -1,11 +1,11 @@
//Package generate the InbounderConfig used by add inbound // Package controller the InbounderConfig used by add inbound
package controller package controller
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api" "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/net"
"github.com/xtls/xray-core/common/uuid" "github.com/xtls/xray-core/common/uuid"
"github.com/xtls/xray-core/core" "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 return certConfig.CertFile, certConfig.KeyFile, nil
} else if certConfig.CertMode == "dns" { } else if certConfig.CertMode == "dns" {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
@ -188,7 +188,7 @@ func getCertFile(certConfig *CertConfig) (certFile string, keyFile string, err e
} }
return certPath, keyPath, err return certPath, keyPath, err
} else if certConfig.CertMode == "http" { } else if certConfig.CertMode == "http" {
lego, err := legocmd.New() lego, err := legoCmd.New()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }

View File

@ -19,11 +19,11 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
// Build Send IP address // Build Send IP address
if config.SendIP != "" { if config.SendIP != "" {
ipAddress := net.ParseAddress(config.SendIP) ipAddress := net.ParseAddress(config.SendIP)
outboundDetourConfig.SendThrough = &conf.Address{ipAddress} outboundDetourConfig.SendThrough = &conf.Address{Address: ipAddress}
} }
// Freedom Protocol setting // Freedom Protocol setting
var domainStrategy string = "Asis" var domainStrategy = "Asis"
if config.EnableDNS { if config.EnableDNS {
if config.DNSType != "" { if config.DNSType != "" {
domainStrategy = config.DNSType domainStrategy = config.DNSType
@ -41,7 +41,7 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
var setting json.RawMessage var setting json.RawMessage
setting, err := json.Marshal(proxySetting) setting, err := json.Marshal(proxySetting)
if err != nil { 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 outboundDetourConfig.Settings = &setting
return outboundDetourConfig.Build() return outboundDetourConfig.Build()