mirror of
http://bgp.hk.skcks.cn:10088/github.com/oneclickvirt/ecs
synced 2026-04-20 12:50:50 +08:00
fix: 修复中英文输出混乱的问题
This commit is contained in:
@@ -76,8 +76,8 @@ func NextTrace3Check(language, location, checkType string) {
|
||||
}
|
||||
|
||||
// UpstreamsCheck 上游及回程线路检测
|
||||
func UpstreamsCheck() {
|
||||
tests.UpstreamsCheck()
|
||||
func UpstreamsCheck(language string) {
|
||||
tests.UpstreamsCheck(language)
|
||||
}
|
||||
|
||||
// GetIPv4Address 获取当前IPv4地址
|
||||
|
||||
@@ -54,8 +54,8 @@ func PrintCenteredTitle(title string, width int) {
|
||||
// filePath: 文件路径
|
||||
// enableUpload: 是否启用上传
|
||||
// 返回: (HTTP URL, HTTPS URL)
|
||||
func ProcessAndUpload(output, filePath string, enableUpload bool) (string, string) {
|
||||
return utils.ProcessAndUpload(output, filePath, enableUpload)
|
||||
func ProcessAndUpload(output, filePath string, enableUpload bool, language string) (string, string) {
|
||||
return utils.ProcessAndUpload(output, filePath, enableUpload, language)
|
||||
}
|
||||
|
||||
// BasicsAndSecurityCheck 基础信息和安全检查
|
||||
|
||||
2
goecs.go
2
goecs.go
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ecsVersion = "v0.1.116" // 融合怪版本号
|
||||
ecsVersion = "v0.1.117" // 融合怪版本号
|
||||
configs = params.NewConfig(ecsVersion) // 全局配置实例
|
||||
userSetFlags = make(map[string]bool) // 用于跟踪哪些参数是用户显式设置的
|
||||
)
|
||||
|
||||
18
goecs.sh
18
goecs.sh
@@ -66,28 +66,28 @@ download_file() {
|
||||
}
|
||||
|
||||
check_china() {
|
||||
_yellow "正在检测IP所在区域......"
|
||||
_yellow "Detecting IP region......"
|
||||
if [ -z "${CN}" ]; then
|
||||
if curl -m 6 -s https://ipapi.co/json | grep -q 'China'; then
|
||||
_yellow "根据ipapi.co提供的信息,当前IP可能在中国"
|
||||
_yellow "According to ipapi.co, this IP may be located in China"
|
||||
if [ "$noninteractive" != "true" ]; then
|
||||
reading "是否使用中国镜像完成安装? ([y]/n) " input
|
||||
reading "Use China mirror for installation? ([y]/n) " input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY] | "")
|
||||
_green "已选择使用中国镜像"
|
||||
_green "China mirror selected"
|
||||
CN=true
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
_yellow "已选择不使用中国镜像"
|
||||
_yellow "China mirror not selected"
|
||||
CN=false
|
||||
;;
|
||||
*)
|
||||
_green "已选择使用中国镜像"
|
||||
_green "China mirror selected"
|
||||
CN=true
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# 在非交互模式下默认不使用中国镜像
|
||||
# In non-interactive mode, default to not using China mirror
|
||||
CN=false
|
||||
fi
|
||||
else
|
||||
@@ -270,9 +270,7 @@ goecs_check() {
|
||||
fi
|
||||
done
|
||||
if [ "$installed_to_system" = "false" ]; then
|
||||
_yellow "权限不足,无法安装到系统路径,goecs 已保留在当前目录下"
|
||||
_yellow "Insufficient permissions to install to system path, goecs is kept in the current directory"
|
||||
_yellow "请使用以下命令运行: ./goecs"
|
||||
_yellow "Please use the following command to run: ./goecs"
|
||||
fi
|
||||
if [ "$os" != "Darwin" ]; then
|
||||
@@ -290,7 +288,7 @@ goecs_check() {
|
||||
setcap cap_net_raw=+ep goecs 2>/dev/null || true
|
||||
setcap cap_net_raw=+ep /usr/bin/goecs 2>/dev/null || true
|
||||
setcap cap_net_raw=+ep /usr/local/bin/goecs 2>/dev/null || true
|
||||
_green "goecs 安装完成 / goecs installation complete, 当前版本 / current version:"
|
||||
_green "goecs installation complete, current version:"
|
||||
goecs -v 2>/dev/null || ./goecs -v
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,11 @@ func GetMenuChoice(language string) string {
|
||||
go func() {
|
||||
select {
|
||||
case <-sigChan:
|
||||
fmt.Println("\n程序在选择过程中被用户中断")
|
||||
if language == "zh" {
|
||||
fmt.Println("\n程序在选择过程中被用户中断")
|
||||
} else {
|
||||
fmt.Println("\nProgram interrupted by user during selection")
|
||||
}
|
||||
os.Exit(0)
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -34,7 +38,11 @@ func GetMenuChoice(language string) string {
|
||||
|
||||
for {
|
||||
var input string
|
||||
fmt.Print("请输入选项 / Please enter your choice: ")
|
||||
if language == "zh" {
|
||||
fmt.Print("请输入选项: ")
|
||||
} else {
|
||||
fmt.Print("Please enter your choice: ")
|
||||
}
|
||||
fmt.Scanln(&input)
|
||||
input = strings.TrimSpace(input)
|
||||
input = strings.TrimRight(input, "\n")
|
||||
@@ -175,7 +183,7 @@ Loop:
|
||||
os.Exit(0)
|
||||
case "1":
|
||||
SetFullTestStatus(preCheck, config)
|
||||
config.OnlyChinaTest = utils.CheckChina(config.EnableLogger)
|
||||
config.OnlyChinaTest = utils.CheckChina(config.EnableLogger, config.Language)
|
||||
break Loop
|
||||
case "2":
|
||||
SetMinimalTestStatus(preCheck, config)
|
||||
|
||||
@@ -296,7 +296,7 @@ func RunNetworkTests(config *params.Config, wg3 *sync.WaitGroup, ptInfo *string,
|
||||
return utils.PrintAndCapture(func() {
|
||||
if config.BacktraceStatus && !config.OnlyChinaTest {
|
||||
utils.PrintCenteredTitle("上游及回程线路检测", config.Width)
|
||||
tests.UpstreamsCheck()
|
||||
tests.UpstreamsCheck(config.Language)
|
||||
}
|
||||
if config.Nt3Status && !config.OnlyChinaTest {
|
||||
utils.PrintCenteredTitle("三网回程路由检测", config.Width)
|
||||
@@ -462,7 +462,7 @@ func HandleSignalInterrupt(sig chan os.Signal, config *params.Config, startTime
|
||||
defer uploadCancel()
|
||||
|
||||
go func() {
|
||||
httpURL, httpsURL := utils.ProcessAndUpload(finalOutput, config.FilePath, config.EnableUpload)
|
||||
httpURL, httpsURL := utils.ProcessAndUpload(finalOutput, config.FilePath, config.EnableUpload, config.Language)
|
||||
select {
|
||||
case resultChan <- struct {
|
||||
httpURL string
|
||||
@@ -516,7 +516,7 @@ func HandleSignalInterrupt(sig chan os.Signal, config *params.Config, startTime
|
||||
|
||||
// HandleUploadResults handles uploading results
|
||||
func HandleUploadResults(config *params.Config, output string) {
|
||||
httpURL, httpsURL := utils.ProcessAndUpload(output, config.FilePath, config.EnableUpload)
|
||||
httpURL, httpsURL := utils.ProcessAndUpload(output, config.FilePath, config.EnableUpload, config.Language)
|
||||
if httpURL != "" || httpsURL != "" {
|
||||
if config.Language == "en" {
|
||||
fmt.Printf("Upload successfully!\nHttp URL: %s\nHttps URL: %s\n", httpURL, httpsURL)
|
||||
|
||||
@@ -29,11 +29,15 @@ type ConcurrentResults struct {
|
||||
|
||||
var IPV4, IPV6 string
|
||||
|
||||
func UpstreamsCheck() {
|
||||
func UpstreamsCheck(language string) {
|
||||
// 添加panic恢复机制
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println("\n上游检测出现错误,已跳过")
|
||||
if language == "zh" {
|
||||
fmt.Println("\n上游检测出现错误,已跳过")
|
||||
} else {
|
||||
fmt.Println("\nUpstream check failed, skipped")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "[WARN] Upstream check panic: %v\n", r)
|
||||
}
|
||||
}()
|
||||
@@ -80,6 +84,11 @@ func UpstreamsCheck() {
|
||||
if results.backtraceResult != "" {
|
||||
fmt.Printf("%s\n", results.backtraceResult)
|
||||
}
|
||||
fmt.Println(Yellow("准确线路自行查看详细路由,本测试结果仅作参考"))
|
||||
fmt.Println(Yellow("同一目标地址多个线路时,检测可能已越过汇聚层,除第一个线路外,后续信息可能无效"))
|
||||
if language == "zh" {
|
||||
fmt.Println(Yellow("准确线路自行查看详细路由,本测试结果仅作参考"))
|
||||
fmt.Println(Yellow("同一目标地址多个线路时,检测可能已越过汇聚层,除第一个线路外,后续信息可能无效"))
|
||||
} else {
|
||||
fmt.Println(Yellow("For accurate routing, check the detailed routes yourself. This result is for reference only."))
|
||||
fmt.Println(Yellow("When multiple routes share the same destination, detection may have passed the aggregation layer; only the first route is reliable."))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func PrintHead(language string, width int, ecsVersion string) {
|
||||
}
|
||||
}
|
||||
|
||||
func CheckChina(enableLogger bool) bool {
|
||||
func CheckChina(enableLogger bool, language string) bool {
|
||||
if enableLogger {
|
||||
InitLogger()
|
||||
defer Logger.Sync()
|
||||
@@ -166,7 +166,7 @@ func CheckChina(enableLogger bool) bool {
|
||||
ipapiResp, err := client.R().Get(ipapiURL)
|
||||
if err != nil {
|
||||
if enableLogger {
|
||||
Logger.Info("无法获取IP信息:" + err.Error())
|
||||
Logger.Info("Failed to get IP info: " + err.Error())
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -174,24 +174,41 @@ func CheckChina(enableLogger bool) bool {
|
||||
ipapiBody, err := ipapiResp.ToString()
|
||||
if err != nil {
|
||||
if enableLogger {
|
||||
Logger.Info("无法读取IP信息响应:" + err.Error())
|
||||
Logger.Info("Failed to read IP info response: " + err.Error())
|
||||
}
|
||||
return false
|
||||
}
|
||||
isInChina := strings.Contains(ipapiBody, "China")
|
||||
if isInChina {
|
||||
fmt.Println("根据 ipapi.co 提供的信息,当前IP可能在中国")
|
||||
var input string
|
||||
fmt.Print("是否选用中国专项测试(无平台解锁测试,有三网Ping值测试)? ([y]/n) ")
|
||||
if language == "zh" {
|
||||
fmt.Println("根据 ipapi.co 提供的信息,当前IP可能在中国")
|
||||
fmt.Print("是否选用中国专项测试(无平台解锁测试,有三网Ping值测试)? ([y]/n) ")
|
||||
} else {
|
||||
fmt.Println("According to ipapi.co, this IP may be located in China")
|
||||
fmt.Print("Use China-specific test (no platform unlock test, includes 3-network ping test)? ([y]/n) ")
|
||||
}
|
||||
fmt.Scanln(&input)
|
||||
switch strings.ToLower(input) {
|
||||
case "yes", "y":
|
||||
fmt.Println("使用中国专项测试")
|
||||
if language == "zh" {
|
||||
fmt.Println("使用中国专项测试")
|
||||
} else {
|
||||
fmt.Println("Using China-specific test")
|
||||
}
|
||||
selectChina = true
|
||||
case "no", "n":
|
||||
fmt.Println("不使用中国专项测试")
|
||||
if language == "zh" {
|
||||
fmt.Println("不使用中国专项测试")
|
||||
} else {
|
||||
fmt.Println("Not using China-specific test")
|
||||
}
|
||||
default:
|
||||
fmt.Println("使用中国专项测试")
|
||||
if language == "zh" {
|
||||
fmt.Println("使用中国专项测试")
|
||||
} else {
|
||||
fmt.Println("Using China-specific test")
|
||||
}
|
||||
selectChina = true
|
||||
}
|
||||
}
|
||||
@@ -396,13 +413,11 @@ func UploadText(absPath string) (string, string, error) {
|
||||
}
|
||||
|
||||
// ProcessAndUpload 创建结果文件并上传文件
|
||||
func ProcessAndUpload(output string, filePath string, enableUplaod bool) (string, string) {
|
||||
func ProcessAndUpload(output string, filePath string, enableUplaod bool, language string) (string, string) {
|
||||
// 使用 defer 来处理 panic
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Fprintf(os.Stderr, "[ERROR] 处理上传时发生严重错误: %v\n", r)
|
||||
// 可以选择打印堆栈信息以便调试
|
||||
// debug.PrintStack()
|
||||
fmt.Fprintf(os.Stderr, "[ERROR] Fatal error during upload: %v\n", r)
|
||||
}
|
||||
}()
|
||||
// 检查文件是否存在
|
||||
@@ -410,14 +425,22 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) (string
|
||||
// 文件存在,删除文件
|
||||
err = os.Remove(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("无法删除文件:", err)
|
||||
if language == "zh" {
|
||||
fmt.Println("无法删除文件:", err)
|
||||
} else {
|
||||
fmt.Println("Failed to delete file:", err)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
}
|
||||
// 创建文件
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("无法创建文件:", err)
|
||||
if language == "zh" {
|
||||
fmt.Println("无法创建文件:", err)
|
||||
} else {
|
||||
fmt.Println("Failed to create file:", err)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
defer file.Close()
|
||||
@@ -429,27 +452,47 @@ func ProcessAndUpload(output string, filePath string, enableUplaod bool) (string
|
||||
writer := bufio.NewWriter(file)
|
||||
_, err = writer.WriteString(cleanedOutput)
|
||||
if err != nil {
|
||||
fmt.Println("无法写入文件:", err)
|
||||
if language == "zh" {
|
||||
fmt.Println("无法写入文件:", err)
|
||||
} else {
|
||||
fmt.Println("Failed to write file:", err)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
// 确保写入缓冲区的数据都刷新到文件中
|
||||
err = writer.Flush()
|
||||
if err != nil {
|
||||
fmt.Println("无法刷新文件缓冲:", err)
|
||||
if language == "zh" {
|
||||
fmt.Println("无法刷新文件缓冲:", err)
|
||||
} else {
|
||||
fmt.Println("Failed to flush file buffer:", err)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
fmt.Printf("测试结果已写入 %s\n", filePath)
|
||||
if language == "zh" {
|
||||
fmt.Printf("测试结果已写入 %s\n", filePath)
|
||||
} else {
|
||||
fmt.Printf("Test results written to %s\n", filePath)
|
||||
}
|
||||
if enableUplaod {
|
||||
// 获取文件的绝对路径
|
||||
absPath, err := filepath.Abs(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("无法获取文件绝对路径:", err)
|
||||
if language == "zh" {
|
||||
fmt.Println("无法获取文件绝对路径:", err)
|
||||
} else {
|
||||
fmt.Println("Failed to get absolute file path:", err)
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
// 上传文件并生成短链接
|
||||
http_url, https_url, err := UploadText(absPath)
|
||||
if err != nil {
|
||||
fmt.Println("上传失败,无法生成链接")
|
||||
if language == "zh" {
|
||||
fmt.Println("上传失败,无法生成链接")
|
||||
} else {
|
||||
fmt.Println("Upload failed, unable to generate link")
|
||||
}
|
||||
fmt.Println(err.Error())
|
||||
return "", ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user