mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-10-01 05:32:18 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5b686abdc8 | ||
![]() |
f99a37edbe | ||
![]() |
4ff49c8b90 | ||
![]() |
1d9257beb3 | ||
![]() |
fc6ccb9f92 | ||
![]() |
88a2a7fdc9 |
140
goecs.go
140
goecs.go
@@ -39,7 +39,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ecsVersion = "v0.1.74"
|
||||
ecsVersion = "v0.1.75"
|
||||
menuMode bool
|
||||
onlyChinaTest bool
|
||||
input, choice string
|
||||
@@ -59,10 +59,9 @@ var (
|
||||
autoChangeDiskTestMethod = true
|
||||
filePath = "goecs.txt"
|
||||
enabelUpload = true
|
||||
help bool
|
||||
onlyIpInfoCheckStatus, help bool
|
||||
goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError)
|
||||
finish bool
|
||||
IPV4, IPV6 string
|
||||
)
|
||||
|
||||
func getMenuChoice(language string) string {
|
||||
@@ -186,7 +185,7 @@ func handleMenuMode(preCheck utils.NetCheckResult) {
|
||||
commTestStatus, utTestStatus, securityTestStatus, emailTestStatus = false, false, false, false
|
||||
backtraceStatus, nt3Status, speedTestStatus = false, false, false
|
||||
autoChangeDiskTestMethod = true
|
||||
printMenuOptions()
|
||||
printMenuOptions(preCheck)
|
||||
Loop:
|
||||
for {
|
||||
choice = getMenuChoice(language)
|
||||
@@ -245,44 +244,62 @@ Loop:
|
||||
}
|
||||
}
|
||||
|
||||
func printMenuOptions() {
|
||||
func printMenuOptions(preCheck utils.NetCheckResult) {
|
||||
var stats *utils.StatsResponse
|
||||
var statsErr error
|
||||
var githubInfo *utils.GitHubRelease
|
||||
var githubErr error
|
||||
var pwg sync.WaitGroup
|
||||
pwg.Add(2)
|
||||
go func() {
|
||||
defer pwg.Done()
|
||||
stats, statsErr = utils.GetGoescStats()
|
||||
}()
|
||||
go func() {
|
||||
defer pwg.Done()
|
||||
githubInfo, githubErr = utils.GetLatestEcsRelease()
|
||||
}()
|
||||
pwg.Wait()
|
||||
var statsInfo string
|
||||
if statsErr != nil {
|
||||
statsInfo = "NULL"
|
||||
// 只有在网络连接正常时才获取统计信息和版本信息
|
||||
if preCheck.Connected {
|
||||
var pwg sync.WaitGroup
|
||||
pwg.Add(2)
|
||||
go func() {
|
||||
defer pwg.Done()
|
||||
stats, statsErr = utils.GetGoescStats()
|
||||
}()
|
||||
go func() {
|
||||
defer pwg.Done()
|
||||
githubInfo, githubErr = utils.GetLatestEcsRelease()
|
||||
}()
|
||||
pwg.Wait()
|
||||
} else {
|
||||
statsInfo = fmt.Sprintf("总使用量: %s | 今日使用: %s",
|
||||
utils.FormatGoecsNumber(stats.Total),
|
||||
utils.FormatGoecsNumber(stats.Daily))
|
||||
statsErr = fmt.Errorf("network not connected")
|
||||
githubErr = fmt.Errorf("network not connected")
|
||||
}
|
||||
var statsInfo string
|
||||
var cmp int
|
||||
if githubErr == nil {
|
||||
cmp = utils.CompareVersions(ecsVersion, githubInfo.TagName)
|
||||
} else {
|
||||
cmp = 0
|
||||
if preCheck.Connected {
|
||||
// 网络连接正常时处理统计信息和版本比较
|
||||
if statsErr != nil {
|
||||
statsInfo = "NULL"
|
||||
} else {
|
||||
switch language {
|
||||
case "zh":
|
||||
statsInfo = fmt.Sprintf("总使用量: %s | 今日使用: %s",
|
||||
utils.FormatGoecsNumber(stats.Total),
|
||||
utils.FormatGoecsNumber(stats.Daily))
|
||||
case "en":
|
||||
statsInfo = fmt.Sprintf("Total Usage: %s | Daily Usage: %s",
|
||||
utils.FormatGoecsNumber(stats.Total),
|
||||
utils.FormatGoecsNumber(stats.Daily))
|
||||
}
|
||||
}
|
||||
if githubErr == nil {
|
||||
cmp = utils.CompareVersions(ecsVersion, githubInfo.TagName)
|
||||
} else {
|
||||
cmp = 0
|
||||
}
|
||||
}
|
||||
switch language {
|
||||
case "zh":
|
||||
fmt.Printf("VPS融合怪版本: %s\n", ecsVersion)
|
||||
switch cmp {
|
||||
case -1:
|
||||
fmt.Printf("检测到新版本 %s 如有必要请更新!\n", githubInfo.TagName)
|
||||
if preCheck.Connected {
|
||||
switch cmp {
|
||||
case -1:
|
||||
fmt.Printf("检测到新版本 %s 如有必要请更新!\n", githubInfo.TagName)
|
||||
}
|
||||
fmt.Printf("使用统计: %s\n", statsInfo)
|
||||
}
|
||||
fmt.Printf("使用统计: %s\n", statsInfo)
|
||||
fmt.Println("1. 融合怪完全体(能测全测)")
|
||||
fmt.Println("2. 极简版(系统信息+CPU+内存+磁盘+测速节点5个)")
|
||||
fmt.Println("3. 精简版(系统信息+CPU+内存+磁盘+常用流媒体+路由+测速节点5个)")
|
||||
@@ -295,13 +312,13 @@ func printMenuOptions() {
|
||||
fmt.Println("10. 三网回程线路检测+三网回程详细路由(北京上海广州成都)+三网延迟测试(全国)")
|
||||
case "en":
|
||||
fmt.Printf("VPS Fusion Monster Test Version: %s\n", ecsVersion)
|
||||
switch cmp {
|
||||
case -1:
|
||||
fmt.Printf("New version detected %s update if necessary!\n", githubInfo.TagName)
|
||||
if preCheck.Connected {
|
||||
switch cmp {
|
||||
case -1:
|
||||
fmt.Printf("New version detected %s update if necessary!\n", githubInfo.TagName)
|
||||
}
|
||||
fmt.Printf("%s\n", statsInfo)
|
||||
}
|
||||
fmt.Printf("Total Usage: %s | Daily Usage: %s\n",
|
||||
utils.FormatGoecsNumber(stats.Total),
|
||||
utils.FormatGoecsNumber(stats.Daily))
|
||||
fmt.Println("1. VPS Fusion Monster Test Comprehensive Test Suite")
|
||||
fmt.Println("2. Minimal Test Suite (System Info + CPU + Memory + Disk + 5 Speed Test Nodes)")
|
||||
fmt.Println("3. Standard Test Suite (System Info + CPU + Memory + Disk + Basic Unlock Tests + 5 Speed Test Nodes)")
|
||||
@@ -377,6 +394,7 @@ func setUnlockFocusedTestStatus(preCheck utils.NetCheckResult) {
|
||||
}
|
||||
|
||||
func setNetworkOnlyTestStatus() {
|
||||
onlyIpInfoCheckStatus = true
|
||||
securityTestStatus = true
|
||||
speedTestStatus = true
|
||||
backtraceStatus = true
|
||||
@@ -385,9 +403,9 @@ func setNetworkOnlyTestStatus() {
|
||||
}
|
||||
|
||||
func setUnlockOnlyTestStatus() {
|
||||
onlyIpInfoCheckStatus = true
|
||||
commTestStatus = true
|
||||
utTestStatus = true
|
||||
enabelUpload = false
|
||||
}
|
||||
|
||||
func setHardwareOnlyTestStatus(preCheck utils.NetCheckResult) {
|
||||
@@ -401,15 +419,16 @@ func setHardwareOnlyTestStatus(preCheck utils.NetCheckResult) {
|
||||
}
|
||||
|
||||
func setIPQualityTestStatus() {
|
||||
onlyIpInfoCheckStatus = true
|
||||
securityTestStatus = true
|
||||
emailTestStatus = true
|
||||
}
|
||||
|
||||
func setRouteTestStatus() {
|
||||
onlyIpInfoCheckStatus = true
|
||||
backtraceStatus = true
|
||||
nt3Status = true
|
||||
pingTestStatus = true
|
||||
enabelUpload = false
|
||||
}
|
||||
|
||||
func printInvalidChoice() {
|
||||
@@ -430,7 +449,7 @@ func handleLanguageSpecificSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *string, tempOutput string, uploadDone chan bool, outputMutex *sync.Mutex) {
|
||||
func handleSignalInterrupt(sig chan os.Signal, startTime *time.Time, output *string, _ string, uploadDone chan bool, outputMutex *sync.Mutex) {
|
||||
select {
|
||||
case <-sig:
|
||||
if !finish {
|
||||
@@ -511,6 +530,9 @@ func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGrou
|
||||
*output = runCPUTest(*output, tempOutput, outputMutex)
|
||||
*output = runMemoryTest(*output, tempOutput, outputMutex)
|
||||
*output = runDiskTest(*output, tempOutput, outputMutex)
|
||||
if onlyIpInfoCheckStatus && !basicStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
|
||||
*output = runIpInfoCheck(*output, tempOutput, outputMutex)
|
||||
}
|
||||
if (onlyChinaTest || pingTestStatus) && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
|
||||
wg3.Add(1)
|
||||
go func() {
|
||||
@@ -551,6 +573,9 @@ func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, ba
|
||||
*output = runCPUTest(*output, tempOutput, outputMutex)
|
||||
*output = runMemoryTest(*output, tempOutput, outputMutex)
|
||||
*output = runDiskTest(*output, tempOutput, outputMutex)
|
||||
if onlyIpInfoCheckStatus && !basicStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
|
||||
*output = runIpInfoCheck(*output, tempOutput, outputMutex)
|
||||
}
|
||||
if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" {
|
||||
if utTestStatus {
|
||||
wg1.Add(1)
|
||||
@@ -574,6 +599,23 @@ func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, ba
|
||||
*output = appendTimeInfo(*output, tempOutput, startTime, outputMutex)
|
||||
}
|
||||
|
||||
func runIpInfoCheck(output, tempOutput string, outputMutex *sync.Mutex) string {
|
||||
outputMutex.Lock()
|
||||
defer outputMutex.Unlock()
|
||||
return utils.PrintAndCapture(func() {
|
||||
var ipinfo string
|
||||
upstreams.IPV4, upstreams.IPV6, ipinfo = utils.OnlyBasicsIpInfo(language)
|
||||
if ipinfo != "" {
|
||||
if language == "zh" {
|
||||
utils.PrintCenteredTitle("IP信息", width)
|
||||
} else {
|
||||
utils.PrintCenteredTitle("IP-Information", width)
|
||||
}
|
||||
fmt.Printf("%s", ipinfo)
|
||||
}
|
||||
}, tempOutput, output)
|
||||
}
|
||||
|
||||
func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string {
|
||||
outputMutex.Lock()
|
||||
defer outputMutex.Unlock()
|
||||
@@ -588,13 +630,13 @@ func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *strin
|
||||
}
|
||||
}
|
||||
if preCheck.Connected && preCheck.StackType == "DualStack" {
|
||||
IPV4, IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
upstreams.IPV4, upstreams.IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
} else if preCheck.Connected && preCheck.StackType == "IPv4" {
|
||||
IPV4, IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "ipv4", securityTestStatus)
|
||||
upstreams.IPV4, upstreams.IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "ipv4", securityTestStatus)
|
||||
} else if preCheck.Connected && preCheck.StackType == "IPv6" {
|
||||
IPV4, IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "ipv6", securityTestStatus)
|
||||
upstreams.IPV4, upstreams.IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "ipv6", securityTestStatus)
|
||||
} else {
|
||||
IPV4, IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "", false)
|
||||
upstreams.IPV4, upstreams.IPV6, *basicInfo, *securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, "", false)
|
||||
securityTestStatus = false
|
||||
}
|
||||
if basicStatus {
|
||||
@@ -735,7 +777,7 @@ func runNetworkTests(wg3 *sync.WaitGroup, ptInfo *string, output, tempOutput str
|
||||
output = utils.PrintAndCapture(func() {
|
||||
if backtraceStatus && !onlyChinaTest {
|
||||
utils.PrintCenteredTitle("上游及回程线路检测", width)
|
||||
upstreams.UpstreamsCheck(IPV4)
|
||||
upstreams.UpstreamsCheck()
|
||||
}
|
||||
}, tempOutput, output)
|
||||
output = utils.PrintAndCapture(func() {
|
||||
@@ -826,12 +868,16 @@ func main() {
|
||||
return
|
||||
}
|
||||
initLogger()
|
||||
go func() {
|
||||
http.Get("https://hits.spiritlhl.net/goecs.svg?action=hit&title=Hits&title_bg=%23555555&count_bg=%230eecf8&edge_flat=false")
|
||||
}()
|
||||
preCheck := utils.CheckPublicAccess(3 * time.Second)
|
||||
go func() {
|
||||
if preCheck.Connected {
|
||||
http.Get("https://hits.spiritlhl.net/goecs.svg?action=hit&title=Hits&title_bg=%23555555&count_bg=%230eecf8&edge_flat=false")
|
||||
}
|
||||
}()
|
||||
if menuMode {
|
||||
handleMenuMode(preCheck)
|
||||
} else {
|
||||
onlyIpInfoCheckStatus = true
|
||||
}
|
||||
handleLanguageSpecificSettings()
|
||||
if !preCheck.Connected {
|
||||
|
6
goecs.sh
6
goecs.sh
@@ -143,7 +143,7 @@ goecs_check() {
|
||||
os=$(uname -s 2>/dev/null || echo "Unknown")
|
||||
arch=$(uname -m 2>/dev/null || echo "Unknown")
|
||||
check_china
|
||||
ECS_VERSION="0.1.73"
|
||||
ECS_VERSION="0.1.74"
|
||||
for api in \
|
||||
"https://api.github.com/repos/oneclickvirt/ecs/releases/latest" \
|
||||
"https://githubapi.spiritlhl.workers.dev/repos/oneclickvirt/ecs/releases/latest" \
|
||||
@@ -155,8 +155,8 @@ goecs_check() {
|
||||
sleep 1
|
||||
done
|
||||
if [ -z "$ECS_VERSION" ]; then
|
||||
_yellow "Unable to get version info, using default version 0.1.73"
|
||||
ECS_VERSION="0.1.73"
|
||||
_yellow "Unable to get version info, using default version 0.1.74"
|
||||
ECS_VERSION="0.1.74"
|
||||
fi
|
||||
version_output=""
|
||||
for cmd_path in "goecs" "./goecs" "/usr/bin/goecs" "/usr/local/bin/goecs"; do
|
||||
|
@@ -6,5 +6,5 @@ import (
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
fmt.Print("%s", MediaTest("zh"))
|
||||
fmt.Printf("%s", MediaTest("zh"))
|
||||
}
|
||||
|
@@ -8,11 +8,13 @@ import (
|
||||
backtrace "github.com/oneclickvirt/backtrace/bk"
|
||||
)
|
||||
|
||||
func UpstreamsCheck(ip string) {
|
||||
if ip != "" {
|
||||
if result, err := bgptools.GetPoPInfo(ip); err == nil {
|
||||
var IPV4, IPV6 string
|
||||
|
||||
func UpstreamsCheck() {
|
||||
if IPV4 != "" {
|
||||
if result, err := bgptools.GetPoPInfo(IPV4); err == nil {
|
||||
fmt.Print(result.Result)
|
||||
}
|
||||
}
|
||||
backtrace.BackTrace(uts.IPV6)
|
||||
}
|
||||
}
|
@@ -3,5 +3,6 @@ package upstreams
|
||||
import "testing"
|
||||
|
||||
func TestUpstreamsCheck(t *testing.T) {
|
||||
UpstreamsCheck("148.100.85.25")
|
||||
IPV4 = "148.100.85.25"
|
||||
UpstreamsCheck()
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/oneclickvirt/UnlockTests/uts"
|
||||
bnetwork "github.com/oneclickvirt/basics/network"
|
||||
"github.com/oneclickvirt/basics/system"
|
||||
butils "github.com/oneclickvirt/basics/utils"
|
||||
. "github.com/oneclickvirt/defaultset"
|
||||
@@ -115,18 +116,38 @@ func CheckChina(enableLogger bool) bool {
|
||||
return selectChina
|
||||
}
|
||||
|
||||
// OnlyBasicsIpInfo 仅检查和输出IP信息
|
||||
func OnlyBasicsIpInfo(language string) (string, string, string) {
|
||||
ipv4, ipv6, ipInfo, _, err := bnetwork.NetworkCheck("both", false, language)
|
||||
if err != nil {
|
||||
return "", "", ""
|
||||
}
|
||||
basicInfo := ipInfo
|
||||
if strings.Contains(ipInfo, "IPV4") && strings.Contains(ipInfo, "IPV6") && ipv4 != "" && ipv6 != "" {
|
||||
uts.IPV4 = true
|
||||
uts.IPV6 = true
|
||||
} else if strings.Contains(ipInfo, "IPV4") && ipv4 != "" {
|
||||
uts.IPV4 = true
|
||||
uts.IPV6 = false
|
||||
} else if strings.Contains(ipInfo, "IPV6") && ipv6 != "" {
|
||||
uts.IPV6 = true
|
||||
uts.IPV4 = false
|
||||
}
|
||||
basicInfo = strings.ReplaceAll(basicInfo, "\n\n", "\n")
|
||||
return ipv4, ipv6, basicInfo
|
||||
}
|
||||
|
||||
// BasicsAndSecurityCheck 执行安全检查
|
||||
func BasicsAndSecurityCheck(language, nt3CheckType string, securityCheckStatus bool) (string, string, string, string, string) {
|
||||
var wgt sync.WaitGroup
|
||||
var ipv4, ipv6, ipInfo, securityInfo, systemInfo string
|
||||
var err error
|
||||
wgt.Add(1)
|
||||
go func() {
|
||||
defer wgt.Done()
|
||||
ipv4, ipv6, ipInfo, securityInfo, err = network.NetworkCheck("both", securityCheckStatus, language)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
ipv4, ipv6, ipInfo, securityInfo, _ = network.NetworkCheck("both", securityCheckStatus, language)
|
||||
// if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
// }
|
||||
}()
|
||||
wgt.Add(1)
|
||||
go func() {
|
||||
|
@@ -20,7 +20,7 @@ func TestBasicsAndSecurityCheck(t *testing.T) {
|
||||
timeout := 3 * time.Second
|
||||
result := CheckPublicAccess(timeout)
|
||||
if result.Connected {
|
||||
fmt.Print("✅ 本机有公网连接,类型: %s\n", result.StackType)
|
||||
fmt.Printf("✅ 本机有公网连接,类型: %s\n", result.StackType)
|
||||
} else {
|
||||
fmt.Println("❌ 本机未检测到公网连接")
|
||||
}
|
||||
|
Reference in New Issue
Block a user