mirror of
https://github.com/shadow1ng/fscan.git
synced 2026-09-25 12:41:53 +08:00
Expand i18n coverage
This commit is contained in:
+21
-21
@@ -38,28 +38,28 @@ func (p *LDPreloadPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
var output strings.Builder
|
||||
|
||||
if runtime.GOOS != "linux" {
|
||||
output.WriteString("LD_PRELOAD持久化只支持Linux平台\n")
|
||||
output.WriteString(i18n.GetText("ldpreload_linux_only") + "\n")
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Output: output.String(),
|
||||
Error: fmt.Errorf("不支持的平台: %s", runtime.GOOS),
|
||||
Error: fmt.Errorf("%s", i18n.Tr("unsupported_platform", runtime.GOOS)),
|
||||
}
|
||||
}
|
||||
|
||||
// 从config获取配置
|
||||
targetFile := config.PersistenceTargetFile
|
||||
if targetFile == "" {
|
||||
output.WriteString("必须通过 -persistence-file 参数指定目标文件路径\n")
|
||||
output.WriteString(i18n.GetText("persistence_file_required") + "\n")
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Output: output.String(),
|
||||
Error: fmt.Errorf("未指定目标文件"),
|
||||
Error: fmt.Errorf("%s", i18n.GetText("target_file_not_specified")),
|
||||
}
|
||||
}
|
||||
|
||||
// 检查目标文件是否存在
|
||||
if _, err := os.Stat(targetFile); os.IsNotExist(err) {
|
||||
output.WriteString(fmt.Sprintf("目标文件不存在: %s\n", targetFile))
|
||||
output.WriteString(i18n.Tr("target_file_not_exist", targetFile) + "\n")
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Output: output.String(),
|
||||
@@ -69,58 +69,58 @@ func (p *LDPreloadPlugin) Scan(ctx context.Context, info *common.HostInfo, sessi
|
||||
|
||||
// 检查文件类型
|
||||
if !p.isValidFile(targetFile) {
|
||||
output.WriteString(fmt.Sprintf("目标文件必须是 .so 动态库文件: %s\n", targetFile))
|
||||
output.WriteString(i18n.Tr("ldpreload_so_required", targetFile) + "\n")
|
||||
return &plugins.Result{
|
||||
Success: false,
|
||||
Output: output.String(),
|
||||
Error: fmt.Errorf("无效文件类型"),
|
||||
Error: fmt.Errorf("%s", i18n.GetText("invalid_file_type")),
|
||||
}
|
||||
}
|
||||
|
||||
output.WriteString("=== LD_PRELOAD持久化 ===\n")
|
||||
output.WriteString(fmt.Sprintf("目标文件: %s\n", targetFile))
|
||||
output.WriteString(fmt.Sprintf("平台: %s\n\n", runtime.GOOS))
|
||||
output.WriteString(i18n.GetText("ldpreload_header") + "\n")
|
||||
output.WriteString(i18n.Tr("local_target_file", targetFile) + "\n")
|
||||
output.WriteString(i18n.Tr("local_platform", runtime.GOOS) + "\n\n")
|
||||
|
||||
var successCount int
|
||||
|
||||
// 1. 复制文件到系统目录
|
||||
systemPath, err := p.copyToSystemPath(targetFile)
|
||||
if err != nil {
|
||||
output.WriteString(fmt.Sprintf("✗ 复制文件到系统目录失败: %v\n", err))
|
||||
output.WriteString(i18n.Tr("ldpreload_copy_system_failed", err) + "\n")
|
||||
} else {
|
||||
output.WriteString(fmt.Sprintf("✓ 文件已复制到: %s\n", systemPath))
|
||||
output.WriteString(i18n.Tr("file_copied_to", systemPath) + "\n")
|
||||
successCount++
|
||||
}
|
||||
|
||||
// 2. 添加到全局环境变量
|
||||
err = p.addToEnvironment(systemPath)
|
||||
if err != nil {
|
||||
output.WriteString(fmt.Sprintf("✗ 添加环境变量失败: %v\n", err))
|
||||
output.WriteString(i18n.Tr("ldpreload_env_add_failed", err) + "\n")
|
||||
} else {
|
||||
output.WriteString("✓ 已添加到全局环境变量\n")
|
||||
output.WriteString(i18n.GetText("ldpreload_env_added") + "\n")
|
||||
successCount++
|
||||
}
|
||||
|
||||
// 3. 添加到shell配置文件
|
||||
shellConfigs, err := p.addToShellConfigs(systemPath)
|
||||
if err != nil {
|
||||
output.WriteString(fmt.Sprintf("✗ 添加到shell配置失败: %v\n", err))
|
||||
output.WriteString(i18n.Tr("ldpreload_shell_add_failed", err) + "\n")
|
||||
} else {
|
||||
output.WriteString(fmt.Sprintf("✓ 已添加到shell配置: %s\n", strings.Join(shellConfigs, ", ")))
|
||||
output.WriteString(i18n.Tr("ldpreload_shell_added", strings.Join(shellConfigs, ", ")) + "\n")
|
||||
successCount++
|
||||
}
|
||||
|
||||
// 4. 创建库配置文件
|
||||
err = p.createLdConfig(systemPath)
|
||||
if err != nil {
|
||||
output.WriteString(fmt.Sprintf("✗ 创建ld配置失败: %v\n", err))
|
||||
output.WriteString(i18n.Tr("ldpreload_config_create_failed", err) + "\n")
|
||||
} else {
|
||||
output.WriteString("✓ 已创建ld预加载配置\n")
|
||||
output.WriteString(i18n.GetText("ldpreload_config_created") + "\n")
|
||||
successCount++
|
||||
}
|
||||
|
||||
// 输出统计
|
||||
output.WriteString(fmt.Sprintf("\nLD_PRELOAD持久化完成: 成功(%d) 总计(%d)\n", successCount, 4))
|
||||
output.WriteString("\n" + i18n.Tr("ldpreload_complete_summary", successCount, 4) + "\n")
|
||||
|
||||
if successCount > 0 {
|
||||
common.LogSuccess(i18n.Tr("ldpreload_success", successCount))
|
||||
@@ -154,7 +154,7 @@ func (p *LDPreloadPlugin) copyToSystemPath(targetFile string) (string, error) {
|
||||
}
|
||||
|
||||
if targetDir == "" {
|
||||
return "", fmt.Errorf("找不到合适的系统库目录")
|
||||
return "", fmt.Errorf("%s", i18n.GetText("ldpreload_system_lib_dir_not_found"))
|
||||
}
|
||||
|
||||
// 生成目标路径
|
||||
@@ -252,7 +252,7 @@ func (p *LDPreloadPlugin) addToShellConfigs(libPath string) ([]string, error) {
|
||||
}
|
||||
|
||||
if len(modified) == 0 {
|
||||
return nil, fmt.Errorf("无法修改任何shell配置文件")
|
||||
return nil, fmt.Errorf("%s", i18n.GetText("ldpreload_shell_config_modify_none"))
|
||||
}
|
||||
|
||||
return modified, nil
|
||||
|
||||
Reference in New Issue
Block a user