Skip to content

Commit e7a9fdd

Browse files
committed
feat(导出): 添加YAML格式导出支持
- 添加snakeyaml依赖以支持YAML格式导出 - 在用户交互中增加YAML格式选项 - 实现ExportToYAML方法用于将漏洞数据导出为YAML格式 - 更新相关提示信息包含YAML选项 参考: #1#2
1 parent 059b426 commit e7a9fdd

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
<version>3.45.2.0</version>
6262
</dependency>
6363

64+
<dependency>
65+
<groupId>org.yaml</groupId>
66+
<artifactId>snakeyaml</artifactId>
67+
<version>2.2</version>
68+
</dependency>
6469

6570
<!-- Jackson JSON 解析核心 -->
6671
<dependency>

src/main/java/xin/ctkqiang/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public static void main(String[] args) {
8686
Configuration.setDatabaseMode(Database.MYSQL);
8787

8888
int pages = userUtil.askForPositiveInt("📄 想爬多少页咧~?【建议填个50以上更爽!】");
89-
boolean isExport = userUtil.askForYesNo("💾 要不要顺便导出数据嘞?(支持 .csv/.json/.sql哦)✨:");
89+
boolean isExport = userUtil.askForYesNo("💾 要不要顺便导出数据嘞?(支持 .csv/.json/.sql/.yaml哦)✨:");
9090

9191
if (isExport) {
92-
String extension = userUtil.askForNonEmptyString("📦 你想导出成什么格式呢?(json / sql / csv默认:csv):");
92+
String extension = userUtil.askForNonEmptyString("📦 你想导出成什么格式呢?(json / sql / csv / yaml / 默认:csv):");
9393

9494
if (!(Main.allowed.contains(extension))) {
9595
System.out.println("❌ 不支持的格式,已默认使用 csv");

src/main/java/xin/ctkqiang/controller/DatabaseController.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import java.util.Arrays;
1616
import java.util.List;
1717

18+
import org.yaml.snakeyaml.DumperOptions;
19+
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
20+
import org.yaml.snakeyaml.Yaml;
21+
import org.yaml.snakeyaml.representer.Representer;
22+
1823
import com.fasterxml.jackson.databind.ObjectMapper;
1924

2025
import xin.ctkqiang.config.Configuration;
@@ -347,6 +352,34 @@ public int ExportToJSON(List<Exploit> exploits) {
347352
return 0;
348353
}
349354

355+
public int ExportToYAML(List<Exploit> exploits) {
356+
if (DatabaseController.EnsureFolderExists("output")) {
357+
try {
358+
DumperOptions options = new DumperOptions();
359+
options.setIndent(2);
360+
options.setPrettyFlow(true);
361+
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
362+
363+
Yaml yaml = new Yaml(options);
364+
365+
String filePath = FilePath(exploits.size(), ".yaml");
366+
367+
try (FileWriter writer = new FileWriter(filePath)) {
368+
yaml.dump(exploits, writer);
369+
}
370+
371+
System.out.println("✅ YAML 导出完成,文件位置: " + filePath);
372+
373+
return 1;
374+
} catch (IOException e) {
375+
e.printStackTrace();
376+
return -1;
377+
}
378+
}
379+
380+
return 0;
381+
}
382+
350383
/**
351384
* 将漏洞信息导出为SQL插入语句
352385
* 生成可直接执行的INSERT语句

src/main/java/xin/ctkqiang/controller/ExploitDbController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ public void Crawl(int pageSize, boolean isExport, String extension) {
199199
case "json":
200200
status = super.ExportToJSON(exploits);
201201
break;
202+
case "yaml":
203+
status = super.ExportToYAML(exploits);
204+
break;
202205
case "csv":
203206
default:
204207
status = super.ExportToCSV(exploits);
@@ -235,6 +238,11 @@ public int AddExploit(List<Exploit> exploit_list) {
235238
return super.AddExploit(exploit_list);
236239
}
237240

241+
@Override
242+
public int ExportToYAML(List<Exploit> exploits) {
243+
return super.ExportToYAML(exploits);
244+
}
245+
238246
/**
239247
* 将漏洞信息导出为JSON格式
240248
*

0 commit comments

Comments
 (0)