mirror of
https://github.com/oneclickvirt/ecs.git
synced 2025-09-27 19:52:08 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9c9dbc6200 | ||
![]() |
20c8063e5e | ||
![]() |
fbe5eb8e58 | ||
![]() |
290f0d8d8c | ||
![]() |
140347c2a6 | ||
![]() |
aeda7a6e88 |
@@ -104,6 +104,7 @@ shell脚本的说明
|
||||
tar (几乎所有类 Unix 系统都有。)
|
||||
unzip (几乎所有类 Unix 系统都有。)
|
||||
dd (几乎所有类 Unix 系统都有。)
|
||||
iproute2 (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
|
||||
fio (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
|
||||
sysbench (几乎所有类 Unix 系统可以通过系统的包管理器安装。)
|
||||
geekbench (geekbench5) (仅支持 IPV4 环境,且内存大于 1GB 并需要持续联网,仅支持 amd64 和 arm64 架构。)
|
||||
|
@@ -93,6 +93,7 @@ Available commands:
|
||||
unzip (Almost all unix-like systems have it.)
|
||||
dd (Almost all unix-like systems have it.)
|
||||
fio (Almost all unix-like systems can be installed through the system's package manager.)
|
||||
iproute2 (Almost all unix-like systems can be installed through the system's package manager.)
|
||||
sysbench (Almost all unix-like systems can be installed through the system's package manager.)
|
||||
geekbench (geekbench5)(Only support IPV4 environment, and memory greater than 1GB network detection, only support amd64 and arm64 architecture.)
|
||||
speedtest (Use the officially provided binaries for more accurate test results.)
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 本包不在main中使用,仅做测试使用
|
||||
// 本包不在main中使用,仅做测试使用,真正调用的在 utils 中的 BasicsAndSecurityCheck
|
||||
func Basic(language string) {
|
||||
ipInfo, _, _ := network.NetworkCheck("both", false, language)
|
||||
systemInfo := system.CheckSystemInfo(language)
|
||||
|
4
go.mod
4
go.mod
@@ -5,9 +5,9 @@ go 1.22.4
|
||||
require (
|
||||
github.com/imroc/req/v3 v3.43.7
|
||||
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502
|
||||
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211
|
||||
github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546
|
||||
github.com/oneclickvirt/backtrace v0.0.4-20240702140722
|
||||
github.com/oneclickvirt/basics v0.0.7-20240821160408
|
||||
github.com/oneclickvirt/basics v0.0.8-20241108124433
|
||||
github.com/oneclickvirt/cputest v0.0.8-20240702070215
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
|
||||
github.com/oneclickvirt/disktest v0.0.4-20240809053456
|
||||
|
8
go.sum
8
go.sum
@@ -104,12 +104,12 @@ github.com/nxtrace/NTrace-core v1.3.2 h1:8aU/IQFmPnwbaWGVBIJHwwVIWk+roo+9+lG+U0O
|
||||
github.com/nxtrace/NTrace-core v1.3.2/go.mod h1:qCVsgSs982jw02BVjTtN8mjSg5OIXW9TaUdISQrMnTw=
|
||||
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502 h1:hRIYJ2uEp2N3AH5bP5X6bwfdwWfZQO/2WoqpUJ8+WsY=
|
||||
github.com/oneclickvirt/CommonMediaTests v0.0.4-20240704024502/go.mod h1:DAmFPRjFV5p9fEzUUSml5jJGn2f1NZJQCzTxITHDjc4=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211 h1:oDYlAXbUSt6JYTC+wcFDVWTacGuyBtWNfJhpKkrqNkU=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.16-20240823051211/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546 h1:KXRNdYPnZ10vi0+6WwrNK5E8GHvGRjaVAv5z7XEfb9Q=
|
||||
github.com/oneclickvirt/UnlockTests v0.0.17-20241020033546/go.mod h1:UELwZDDiddSxe38boYOPl1FlrL0ptEZYSQwdE3MYvUM=
|
||||
github.com/oneclickvirt/backtrace v0.0.4-20240702140722 h1:UJ/VWf+ZbhGarc9HcHMIyenpmX+b2LxkXu0hlLk3Gxs=
|
||||
github.com/oneclickvirt/backtrace v0.0.4-20240702140722/go.mod h1:zvsC7xY/WZqs5KL2JB967OVnuqjNbxu9bW6wXRLo5h8=
|
||||
github.com/oneclickvirt/basics v0.0.7-20240821160408 h1:IOqa7bBAkjhfru6arDsOTKB7qZ36ojfOP73kE+cDaqc=
|
||||
github.com/oneclickvirt/basics v0.0.7-20240821160408/go.mod h1:fUdVpU8gdjaZsTCyqnQBAbHc9BbbN8Fxr3sGPKooUpU=
|
||||
github.com/oneclickvirt/basics v0.0.8-20241108124433 h1:eKZcoNoa9uLWmfisk+qN/QOvSGT4ajCmZdZfIAcHG+o=
|
||||
github.com/oneclickvirt/basics v0.0.8-20241108124433/go.mod h1:fUdVpU8gdjaZsTCyqnQBAbHc9BbbN8Fxr3sGPKooUpU=
|
||||
github.com/oneclickvirt/cputest v0.0.8-20240702070215 h1:CcFpyVPlQkJ6vjFP17BRuJhh/afiJhOhZ0BW+TtfVDg=
|
||||
github.com/oneclickvirt/cputest v0.0.8-20240702070215/go.mod h1:MmaHN9+XMntI3rLycwj8Ne31fG18IfNoa8N2utDK1CY=
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
|
||||
|
6
goecs.go
6
goecs.go
@@ -39,7 +39,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ecsVersion = "v0.0.80"
|
||||
ecsVersion = "v0.0.84"
|
||||
menuMode bool
|
||||
onlyChinaTest bool
|
||||
input, choice string
|
||||
@@ -340,7 +340,7 @@ func main() {
|
||||
if basicStatus {
|
||||
utils.PrintCenteredTitle("系统基础信息", width)
|
||||
}
|
||||
basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
basicInfo, securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
if basicStatus {
|
||||
fmt.Printf(basicInfo)
|
||||
} else if (input == "6" || input == "9") && securityTestStatus {
|
||||
@@ -481,7 +481,7 @@ func main() {
|
||||
if basicStatus {
|
||||
utils.PrintCenteredTitle("System-Basic-Information", width)
|
||||
}
|
||||
basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
basicInfo, securityInfo, nt3CheckType = utils.BasicsAndSecurityCheck(language, nt3CheckType, securityTestStatus)
|
||||
if basicStatus {
|
||||
fmt.Printf(basicInfo)
|
||||
} else if (input == "6" || input == "9") && securityTestStatus {
|
||||
|
9
goecs.sh
9
goecs.sh
@@ -258,6 +258,9 @@ Check_Sysbench_InstantBuild() {
|
||||
if [ "$os_sysbench" = "astra" ]; then
|
||||
os_sysbench="debian"
|
||||
fi
|
||||
if [ "$os_sysbench" = "opencloudos" ]; then
|
||||
os_sysbench="centos"
|
||||
fi
|
||||
echo -e "${Msg_Info}Release Detected: ${os_sysbench}"
|
||||
echo -e "${Msg_Info}Preparing compile enviorment ..."
|
||||
prepare_compile_env "${os_sysbench}"
|
||||
@@ -347,7 +350,7 @@ env_check() {
|
||||
${PACKAGE_UPDATE[int]} 2>/dev/null
|
||||
|
||||
# 安装必要的命令
|
||||
for cmd in sudo wget tar unzip systemd-detect-virt dd fio; do
|
||||
for cmd in sudo wget tar unzip iproute2 systemd-detect-virt dd fio; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
_green "Installing $cmd"
|
||||
${PACKAGE_INSTALL[int]} "$cmd"
|
||||
@@ -401,8 +404,8 @@ env_check() {
|
||||
fi
|
||||
|
||||
if [ "$(uname -s)" = "Darwin" ]; then
|
||||
echo "Detected MacOS. Installing sysbench and fio..."
|
||||
brew install --force sysbench fio
|
||||
echo "Detected MacOS. Installing sysbench iproute2mac fio..."
|
||||
brew install --force sysbench iproute2mac fio
|
||||
else
|
||||
if ! grep -q "^net.ipv4.ping_group_range = 0 2147483647$" /etc/sysctl.conf; then
|
||||
echo "net.ipv4.ping_group_range = 0 2147483647" >> /etc/sysctl.conf
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/oneclickvirt/UnlockTests/uts"
|
||||
"github.com/oneclickvirt/basics/ipv6"
|
||||
"github.com/oneclickvirt/basics/system"
|
||||
. "github.com/oneclickvirt/defaultset"
|
||||
"github.com/oneclickvirt/security/network"
|
||||
@@ -128,12 +129,12 @@ func CheckChina(enableLogger bool) bool {
|
||||
return selectChina
|
||||
}
|
||||
|
||||
// SecurityCheck 执行安全检查
|
||||
func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) {
|
||||
// BasicsAndSecurityCheck 执行安全检查
|
||||
func BasicsAndSecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (string, string, string) {
|
||||
var wgt sync.WaitGroup
|
||||
var ipInfo, securityInfo, systemInfo string
|
||||
var err error
|
||||
wgt.Add(2)
|
||||
wgt.Add(1)
|
||||
go func() {
|
||||
defer wgt.Done()
|
||||
ipInfo, securityInfo, err = network.NetworkCheck("both", securtyCheckStatus, language)
|
||||
@@ -141,12 +142,17 @@ func SecurityCheck(language, nt3CheckType string, securtyCheckStatus bool) (stri
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}()
|
||||
wgt.Add(1)
|
||||
go func() {
|
||||
defer wgt.Done()
|
||||
systemInfo = system.CheckSystemInfo(language)
|
||||
}()
|
||||
wgt.Wait()
|
||||
ipv6Info, errv6 := ipv6.GetIPv6Mask(language)
|
||||
basicInfo := systemInfo + ipInfo
|
||||
if errv6 == nil && ipv6Info != "" {
|
||||
basicInfo += ipv6Info
|
||||
}
|
||||
if strings.Contains(ipInfo, "IPV4") && strings.Contains(ipInfo, "IPV6") {
|
||||
uts.IPV4 = true
|
||||
uts.IPV6 = true
|
||||
@@ -242,18 +248,29 @@ func UploadText(absPath string) (string, string, error) {
|
||||
primaryURL := "http://hpaste.spiritlhl.net/api/upload"
|
||||
backupURL := "https://paste.spiritlhl.net/api/upload"
|
||||
token := network.SecurityUploadToken
|
||||
client := req.DefaultClient()
|
||||
client.SetTimeout(6 * time.Second)
|
||||
client := req.C().SetTimeout(6 * time.Second)
|
||||
client.R().
|
||||
SetRetryCount(2).
|
||||
SetRetryBackoffInterval(1*time.Second, 5*time.Second).
|
||||
SetRetryFixedInterval(2 * time.Second)
|
||||
file, err := os.Open(absPath)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
upload := func(url string) (string, string, error) {
|
||||
// 重新打开文件,以确保我们总是从文件开头读取
|
||||
file, err := os.Open(absPath)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to re-open file for %s: %w", url, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// 读取文件内容
|
||||
content, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("failed to read file content for %s: %w", url, err)
|
||||
}
|
||||
resp, err := client.R().
|
||||
SetHeader("Authorization", token).
|
||||
SetHeader("Format", "RANDOM").
|
||||
@@ -261,16 +278,17 @@ func UploadText(absPath string) (string, string, error) {
|
||||
SetHeader("UploadText", "true").
|
||||
SetHeader("Content-Type", "multipart/form-data").
|
||||
SetHeader("No-JSON", "true").
|
||||
SetFileReader("file", "goecs.txt", file).
|
||||
SetFileBytes("file", "goecs.txt", content).
|
||||
Post(url)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf("failed to make request to %s: %w", url, err)
|
||||
}
|
||||
if resp.StatusCode >= 200 && resp.StatusCode <= 299 {
|
||||
return strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/"),
|
||||
strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/"), nil
|
||||
http_url := strings.ReplaceAll(resp.String(), "https://paste.spiritlhl.net/", "http://hpaste.spiritlhl.net/")
|
||||
https_url := strings.ReplaceAll(resp.String(), "http://hpaste.spiritlhl.net/", "https://paste.spiritlhl.net/")
|
||||
return http_url, https_url, nil
|
||||
} else {
|
||||
return "", "", fmt.Errorf("upload failed with status code: %d", resp.StatusCode)
|
||||
return "", "", fmt.Errorf("upload failed for %s with status code: %d", url, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
http_url, https_url, err := upload(primaryURL)
|
||||
@@ -279,7 +297,7 @@ func UploadText(absPath string) (string, string, error) {
|
||||
}
|
||||
http_url, https_url, err = upload(backupURL)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf("failed to upload to both primary and backup URLs: %w", err)
|
||||
}
|
||||
return http_url, https_url, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user