Skip to content

Commit d1a25ea

Browse files
authored
Merge pull request #3 from ctkqiang/2-SQLite_and_release
支持SQLite数据库和发布Releases版本
2 parents 1f5aacd + 90f40b1 commit d1a25ea

File tree

9 files changed

+264
-24
lines changed

9 files changed

+264
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ out/
6868

6969
# 临时环境变量文件
7070
.env
71+
*.sqlite

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@
6464

6565
```bash
6666
mvn clean compile exec:java
67+
```
68+
69+
# Maven 来打包成 jar
6770

71+
```bash
72+
mvn clean package
6873
```
6974

7075
首次运行时会:

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
<scope>runtime</scope>
5656
</dependency>
5757

58+
<dependency>
59+
<groupId>org.xerial</groupId>
60+
<artifactId>sqlite-jdbc</artifactId>
61+
<version>3.45.2.0</version>
62+
</dependency>
63+
64+
5865
<!-- Jackson JSON 解析核心 -->
5966
<dependency>
6067
<groupId>com.fasterxml.jackson.core</groupId>

scripts/release.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
APP_NAME="ExploitDB"
4+
MAIN_CLASS="xin.ctkqiang.Main"
5+
VERSION="v1.0.0"
6+
RELEASE_DIR="releases/${VERSION}"
7+
OUT_DIR="out"
8+
9+
# 彩色 ASCII 标题(纯 echo)
10+
ascii_banner() {
11+
echo " _____ _ _ _ _ _ "
12+
echo " | ____|_ ___ __ | | ___ (_) |_(_)___| |_ ___ _ __ "
13+
echo " | _| \ \/ / '_ \| |/ _ \| | __| / __| __/ _ \| '__|"
14+
echo " | |___ > <| |_) | | (_) | | |_| \__ \ || (_) | | "
15+
echo " |_____/_/\_\ .__/|_|\___/|_|\__|_|___/\__\___/|_| "
16+
echo " |_| "
17+
}
18+
19+
# 动画函数
20+
wait_animation() {
21+
local MESSAGE=$1
22+
local DOTS=""
23+
24+
echo "$MESSAGE"
25+
for i in 1 2 3; do
26+
DOTS="$DOTS."
27+
echo "$DOTS"
28+
sleep 0.3
29+
done
30+
}
31+
32+
# 步骤开始
33+
ascii_banner
34+
wait_animation "🌸 灵儿正在为你编译 Java 11 项目"
35+
36+
# 清理旧文件
37+
rm -rf $OUT_DIR $RELEASE_DIR
38+
mkdir -p $OUT_DIR
39+
40+
# 编译
41+
find ./src -name "*.java" >sources.txt
42+
javac -source 11 -target 11 -d $OUT_DIR @sources.txt
43+
44+
if [ $? -ne 0 ]; then
45+
echo "❌ 编译失败了!检查一下语法哦~"
46+
exit 1
47+
fi
48+
49+
wait_animation "🎀 编译完成,开始打包成 JAR"
50+
51+
# 创建 JAR 包
52+
JAR_NAME="${APP_NAME}-${VERSION}.jar"
53+
jar cfe $JAR_NAME $MAIN_CLASS -C $OUT_DIR .
54+
55+
if [ $? -ne 0 ]; then
56+
echo "❌ 打包失败了!可能是入口类路径设置错了~"
57+
exit 1
58+
fi
59+
60+
# 准备 Release 目录
61+
mkdir -p $RELEASE_DIR
62+
mv $JAR_NAME $RELEASE_DIR/
63+
64+
wait_animation "📦 发布结构整理完成"
65+
66+
# Release Summary
67+
echo ""
68+
echo "🎉 Release 打包成功!少女完成度 100%~"
69+
echo "📁 输出目录: $RELEASE_DIR"
70+
echo "📦 文件名: $JAR_NAME"
71+
echo "🔮 Java 版本: $(java -version 2>&1 | head -n 1)"
72+
echo ""
73+
echo "下一步:上传 GitHub Release 页面吧 💖"

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

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
import java.util.List;
55
import java.util.Scanner;
66

7+
import xin.ctkqiang.config.Configuration;
78
import xin.ctkqiang.controller.ExploitDbController;
89
import xin.ctkqiang.controller.UserUtil;
10+
import xin.ctkqiang.dto.Database;
911

1012
public class Main {
1113
public static final String VERSION = "1.0";
1214
public static final String TITLE = "ExploitDB 搜索工具";
1315
public static final String AUTHOR = "钟智强";
16+
public static final String EMAIL = "[email protected]";
17+
public static final String GITHUB = "https://github.com/ctkqiang";
18+
public static final String GITCODE = "https://gitcode.com/ctkqiang_sr";
1419
public static final String DESCRIPTION = "ExploitDB 搜索工具";
15-
public static final String USAGE = "mvn clean compile exec:java";
20+
public static final String USAGE = "mvn clean compile exec:java 或 java -jar {FILENAME}.jar";
1621

1722
public static final Scanner scanner = new Scanner(System.in);
1823

@@ -24,18 +29,63 @@ public class Main {
2429
private static List<String> allowed = Arrays.asList("csv", "json", "sql");
2530

2631
private static void PrintBanner() {
27-
System.out.println("===================================");
28-
System.out.println(" " + TITLE + " v" + VERSION);
29-
System.out.println(" Author: " + AUTHOR);
30-
System.out.println(" " + DESCRIPTION);
31-
System.out.println("===================================\n");
32+
System.out.println();
33+
System.out.println("╭─────────────────────────────────────────────────────────────────────────╮");
34+
System.out.println("│ (๑˃̵ᴗ˂̵)و 欢迎来到灵儿的安全世界呀~♡ (づ。◕‿‿◕。)づ ");
35+
System.out.println("│ ");
36+
System.out.println("│ 工具名称:" + TITLE + " v" + VERSION);
37+
System.out.println("│ 作者昵称:" + AUTHOR + " (๑•̀ㅂ•́)و✧");
38+
System.out.println("│ 简介说明:" + DESCRIPTION);
39+
System.out.println("│ ");
40+
System.out.println("│ 📧 邮箱联系: " + EMAIL);
41+
System.out.println("│ 💻 GitHub : " + GITHUB);
42+
System.out.println("│ 📂 GitCode : " + GITCODE);
43+
System.out.println("│ ");
44+
System.out.println("│ 🛠️ 使用方法: " + USAGE);
45+
System.out.println("│ ");
46+
System.out.println("│ 💌 小声明哟~我是乖乖的好孩子,这工具是帮大家做好事的~ ");
47+
System.out.println("│ 不是让坏蛋乱用的哦 (ง •̀_•́)ง ");
48+
System.out.println("│ 如果有人坏坏地用了,后果自负哒~我不背锅哦~请保持正义感~♡ ");
49+
System.out.println("╰─────────────────────────────────────────────────────────────────────────╯");
50+
System.out.println();
3251
}
3352

3453
public static void main(String[] args) {
3554
try {
3655
Main.PrintBanner();
3756

38-
int pages = userUtil.askForPositiveInt("📄 想爬多少页咧~?(建议填个50以上更爽!):");
57+
/**
58+
* 嘻嘻~这里是数据库模式设置哦 ♡
59+
* 你可以从 {@link xin.ctkqiang.dto.Database Database} 枚举里选一个最爱滴数据库:
60+
* <ul>
61+
* <li>{@link xin.ctkqiang.dto.Database#MYSQL MYSQL} :咱们平时用的 MySQL
62+
* 数据库,默认就选它啦~</li>
63+
* <li>{@link xin.ctkqiang.dto.Database#SQLITE SQLITE} :轻巧灵活的 SQLite
64+
* 嵌入式数据库,萌萌哒!</li>
65+
* </ul>
66+
*
67+
* 小提示✨:默认模式是 MYSQL 哦,要用 SQLite 的话,记得把下面的代码改成
68+
* <code>Configuration.setDatabaseMode(Database.SQLITE);</code> 才能生效呢~
69+
*
70+
* 举个栗子给你看👇:
71+
*
72+
* 乖乖用【默认】 MySQL 嘛 ~
73+
*
74+
* <pre>
75+
* Configuration.setDatabaseMode(Database.MYSQL);
76+
* </pre>
77+
*
78+
* 想用 SQLite ~
79+
*
80+
* <pre>
81+
* Configuration.setDatabaseMode(Database.SQLITE);
82+
* </pre>
83+
*
84+
* 嘻嘻,这样就能轻轻松松切换数据库, 你棒棒啦!🎀🌸💖
85+
*/
86+
Configuration.setDatabaseMode(Database.MYSQL);
87+
88+
int pages = userUtil.askForPositiveInt("📄 想爬多少页咧~?【建议填个50以上更爽!】");
3989
boolean isExport = userUtil.askForYesNo("💾 要不要顺便导出数据嘞?(支持 .csv/.json/.sql哦)✨:");
4090

4191
if (isExport) {
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
package xin.ctkqiang.config;
22

3+
import xin.ctkqiang.dto.Database;
4+
35
public class Configuration {
6+
private static String DatabaseMode = Database.MYSQL.getValue();
7+
48
public static final String DB_NAME = "ExploitDB";
59
public static final String DB_URL = "jdbc:mysql://localhost:3306/" + DB_NAME
610
+ "?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false";
711

8-
public static final String DB_USER = "root"; // 改成你的数据库用户名
9-
public static final String DB_PASSWORD = ""; // 改成你的数据库密码
12+
public static final String DB_SQLITE_URL = "jdbc:sqlite:ling.sqlite";
13+
14+
public static final String DB_USER = "root";
15+
public static final String DB_PASSWORD = "";
1016
public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
1117

1218
public static final boolean DEBUG = false;
19+
20+
public static String getDatabaseMode() {
21+
return DatabaseMode;
22+
}
23+
24+
public static void setDatabaseMode(Database databaseMode) {
25+
DatabaseMode = databaseMode.getValue();
26+
System.out.println(String.format("🎀 你当前选择的数据库模式是:「%s」~酱酱 ♪(๑˃ᴗ˂)ﻭ \n", getDatabaseMode()));
27+
}
1328
}

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

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.fasterxml.jackson.databind.ObjectMapper;
1919

2020
import xin.ctkqiang.config.Configuration;
21+
import xin.ctkqiang.dto.Database;
2122
import xin.ctkqiang.dto.Exploit;
2223

2324
/**
@@ -32,7 +33,7 @@ public class DatabaseController {
3233
/** 数据库名称 */
3334
protected final static String DB_NAME = Configuration.DB_NAME;
3435

35-
/** 数据库连接URL */
36+
/** MYSQL 数据库连接URL */
3637
protected final static String DB_URL = Configuration.DB_URL;
3738

3839
/** 数据库用户名 */
@@ -44,6 +45,9 @@ public class DatabaseController {
4445
/** 数据库驱动类名 */
4546
protected final static String DB_DRIVER = Configuration.DB_DRIVER;
4647

48+
/** SQLITE 数据库连接URL */
49+
protected final static String DB_SQLITE_URL = Configuration.DB_SQLITE_URL;
50+
4751
/**
4852
* 静态初始化块
4953
* 在类加载时尝试加载数据库驱动
@@ -63,7 +67,35 @@ public class DatabaseController {
6367
* @throws SQLException 如果连接数据库时发生错误
6468
*/
6569
protected Connection getConnection() throws SQLException {
66-
return DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
70+
String mode = Configuration.getDatabaseMode();
71+
String upperMode = mode.toUpperCase();
72+
System.out.println("💡 切换数据库模式 -> " + upperMode);
73+
74+
switch (upperMode) {
75+
case "SQLITE":
76+
try {
77+
Class.forName("org.sqlite.JDBC");
78+
System.out.println("📦 嘻嘻~SQLite 驱动已加载好惹!我已经抱好数据库小可爱啦~ฅ(^・ω・^ฅ)");
79+
} catch (ClassNotFoundException e) {
80+
System.err.println("❌ 哎呀呀!SQLite JDBC 驱动不见惹~人家找不到驱动怎么贴贴数据库嘛喵呜呜。゚(゚´ω`゚)゚。");
81+
throw new SQLException("找不到 SQLite 驱动喵~要不要检查一下依赖有没有加对呀?");
82+
}
83+
return DriverManager.getConnection(DatabaseController.DB_SQLITE_URL);
84+
85+
case "MYSQL":
86+
default:
87+
try {
88+
Class.forName(DatabaseController.DB_DRIVER);
89+
System.out.println("📦 MySQL 驱动加载完成!我打扮好了,要去连接数据库小哥哥啦~(๑•̀ㅂ•́)و✧");
90+
} catch (ClassNotFoundException e) {
91+
System.err.println("❌ 呜呜呜 MySQL JDBC 驱动不见了~是不是打包的时候忘记带灵儿一起走啦 >///< ");
92+
throw new SQLException("MySQL 驱动加载失败了喵~快检查一下 `.jar` 有没有遗漏吧!");
93+
}
94+
return DriverManager.getConnection(
95+
DatabaseController.DB_URL,
96+
DatabaseController.DB_USER,
97+
DatabaseController.DB_PASSWORD);
98+
}
6799
}
68100

69101
/**
@@ -109,20 +141,52 @@ public void CreateTableIfNotExists() {
109141
+ ");";
110142

111143
try {
112-
// 确保数据库驱动已加载
113-
Class.forName(DatabaseController.DB_DRIVER);
114-
115-
// 创建数据库连接并执行建表语句
116-
try (Connection conn = DriverManager.getConnection(
117-
DatabaseController.DB_URL,
118-
DatabaseController.DB_USER,
119-
DatabaseController.DB_PASSWORD);
120-
Statement stmt = conn.createStatement()) {
121-
stmt.execute(query);
122-
System.out.println("💾 数据表【内容信息】初始化成功!");
144+
145+
String mode = Configuration.getDatabaseMode();
146+
Database dbMode;
147+
148+
try {
149+
dbMode = Database.fromValue(mode);
150+
} catch (IllegalArgumentException e) {
151+
dbMode = null;
152+
}
153+
154+
if (dbMode == null) {
155+
System.out.println("🥴 吃嗯的!这个数据库模式不认识喔:\"" + mode + "\" 妹妹我拒绝连接!");
156+
return;
157+
}
158+
159+
switch (dbMode) {
160+
case SQLITE:
161+
// 加载 SQLite JDBC 驱动
162+
Class.forName("org.sqlite.JDBC");
163+
164+
// 构建连接(数据库文件叫 ling.sqlite)
165+
try (Connection conn = DriverManager.getConnection(DatabaseController.DB_SQLITE_URL);
166+
Statement stmt = conn.createStatement()) {
167+
stmt.execute(query);
168+
System.out.println("🎀 SQLite 模式下,表结构初始化好啦!已经准备好可爱的记录了喵~");
169+
}
170+
171+
break;
172+
case MYSQL:
173+
default:
174+
// 确保数据库驱动已加载
175+
Class.forName(DatabaseController.DB_DRIVER);
176+
177+
// 创建数据库连接并执行建表语句
178+
try (Connection conn = DriverManager.getConnection(
179+
DatabaseController.DB_URL,
180+
DatabaseController.DB_USER,
181+
DatabaseController.DB_PASSWORD);
182+
Statement stmt = conn.createStatement()) {
183+
stmt.execute(query);
184+
System.out.println("💾 MySQL 模式下,数据表【内容信息】初始化成功~♡");
185+
}
123186
}
187+
124188
} catch (Exception e) {
125-
System.err.println("❌ 数据表创建失败:" + e.getMessage());
189+
System.err.println("❌ 表创建失败惹呜呜呜呜:妹抖崩坏 > <\n" + e.getMessage());
126190
e.printStackTrace();
127191
}
128192
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public int askForPositiveInt(String prompt) {
1515
int result = DEFAULT;
1616

1717
while (true) {
18-
System.out.print(prompt + " (默认 " + DEFAULT + "): ");
18+
System.out.print(prompt + " (默认 " + DEFAULT + "): 🌼 ");
1919
String input = scanner.nextLine().trim();
2020

2121
if (input.isEmpty()) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package xin.ctkqiang.dto;
2+
3+
public enum Database {
4+
MYSQL("MySQL"),
5+
SQLITE("SQLite");
6+
7+
private final String value;
8+
9+
Database(String value) {
10+
this.value = value;
11+
}
12+
13+
public String getValue() {
14+
return value;
15+
}
16+
17+
public static Database fromValue(String value) {
18+
for (Database db : values()) {
19+
if (db.value.equalsIgnoreCase(value)) {
20+
return db;
21+
}
22+
}
23+
throw new IllegalArgumentException("Unknown database type: " + value);
24+
}
25+
}

0 commit comments

Comments
 (0)