Skip to content

Commit 0914eb7

Browse files
committed
refactor(storage): 统一数据库文件存储到sqlite_dbs目录
- 创建sqlite_dbs目录以统一存放所有数据库文件 - 修改IPC数据库初始化路径,固定存储到sqlite_dbs目录下ipc.db - 修改Header数据库初始化,默认路径指向sqlite_dbs目录的headers.db - 修改Scan Preset数据库初始化,默认路径使用sqlite_dbs目录的scan_presets.db - 调整get_scan_preset_db函数以支持传入数据库路径参数 - 修改.idea项目配置文件,修正Python SDK路径和测试源目录设置 - 在任务监控中添加调试日志,完善任务信息输出 - Task类增加__str__方法,便于任务信息打印调试
1 parent 96c35fb commit 0914eb7

8 files changed

Lines changed: 54 additions & 48 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sqlmapWebUI.iml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 22 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backEnd/main.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,29 @@ def main(username, password):
132132
global_username = username
133133
global_password = password
134134

135-
_, Database.filepath = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.IPC, text=False)
136-
os.close(_)
135+
# 创建 sqlite_dbs 目录(所有数据库文件统一存放)
136+
sqlite_dbs_dir = os.path.join(current_dir, "sqlite_dbs")
137+
os.makedirs(sqlite_dbs_dir, exist_ok=True)
138+
logger.info(f"[*] SQLite database directory: {sqlite_dbs_dir}")
137139

138-
# Initialize IPC database
139-
# pdb.set_trace()
140+
# Initialize IPC database (固定存储到 sqlite_dbs 目录)
141+
Database.filepath = os.path.join(sqlite_dbs_dir, f"{MKSTEMP_PREFIX.IPC}ipc.db")
140142
DataStore.current_db = Database()
141143
logger.info(f"id(DataStore.current_db): {id(DataStore.current_db)}")
142144
DataStore.current_db.connect()
143145
DataStore.current_db.init()
144146
logger.info("[*] IPC database initialized")
145147

146-
# Initialize Header database
147-
DataStore.header_db = HeaderDatabase()
148+
# Initialize Header database (存储到 sqlite_dbs 目录)
149+
header_db_path = os.path.join(sqlite_dbs_dir, "headers.db")
150+
DataStore.header_db = HeaderDatabase(database_path=header_db_path)
148151
DataStore.header_db.connect()
149152
DataStore.header_db.init()
150153
logger.info("[*] Header database initialized")
151154

152-
# Initialize Scan Preset database
153-
DataStore.scan_preset_db = get_scan_preset_db()
155+
# Initialize Scan Preset database (存储到 sqlite_dbs 目录)
156+
scan_preset_db_path = os.path.join(sqlite_dbs_dir, "scan_presets.db")
157+
DataStore.scan_preset_db = get_scan_preset_db(database_path=scan_preset_db_path)
154158
logger.info("[*] Scan preset database initialized")
155159

156160
scheduler = BackgroundScheduler()

src/backEnd/model/HeaderDatabase.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class HeaderDatabase(Database):
1212
"""独立的请求头管理数据库"""
1313

1414
def __init__(self, database_path=None):
15-
# 如果没有指定数据库路径,则使用程序所在目录下的headers.db文件
15+
# 如果没有指定数据库路径,则使用 sqlite_dbs 目录下的 headers.db 文件
1616
if database_path is None:
17-
# 获取当前脚本所在目录
1817
current_dir = os.path.dirname(os.path.abspath(__file__))
19-
# 确保是src目录的上一级目录
2018
project_dir = os.path.dirname(current_dir)
21-
database_path = os.path.join(project_dir, "headers.db")
19+
sqlite_dbs_dir = os.path.join(project_dir, "sqlite_dbs")
20+
os.makedirs(sqlite_dbs_dir, exist_ok=True)
21+
database_path = os.path.join(sqlite_dbs_dir, "headers.db")
2222

2323
super().__init__(database_path)
2424
self.database_path = database_path

src/backEnd/model/ScanPresetDatabase.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ def __init__(self, database_path=None):
3737
if self._initialized:
3838
return
3939

40-
# 如果没有指定数据库路径,使用默认路径
40+
# 如果没有指定数据库路径,使用 sqlite_dbs 目录下的默认路径
4141
if database_path is None:
4242
current_dir = os.path.dirname(os.path.abspath(__file__))
4343
project_dir = os.path.dirname(current_dir)
44-
database_path = os.path.join(project_dir, "scan_presets.db")
44+
sqlite_dbs_dir = os.path.join(project_dir, "sqlite_dbs")
45+
os.makedirs(sqlite_dbs_dir, exist_ok=True)
46+
database_path = os.path.join(sqlite_dbs_dir, "scan_presets.db")
4547

4648
super().__init__(database_path)
4749
self.database_path = database_path
@@ -605,10 +607,10 @@ def _row_to_preset(self, row) -> Optional[ScanPreset]:
605607
_scan_preset_db: Optional[ScanPresetDatabase] = None
606608

607609

608-
def get_scan_preset_db() -> ScanPresetDatabase:
610+
def get_scan_preset_db(database_path=None) -> ScanPresetDatabase:
609611
"""获取扫描配置预设数据库实例"""
610612
global _scan_preset_db
611613
if _scan_preset_db is None:
612-
_scan_preset_db = ScanPresetDatabase()
614+
_scan_preset_db = ScanPresetDatabase(database_path=database_path)
613615
_scan_preset_db.init()
614616
return _scan_preset_db

src/backEnd/model/Task.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def __init__(self, taskid, remote_addr, scanUrl, host, method, headers, body):
7676

7777
logger.debug(f"[{self.taskid}] Task initialization completed")
7878

79+
80+
def __str__(self):
81+
return f"Task(taskid={self.taskid}, status={self.status}, create_datetime={self.create_datetime}, start_datetime={self.start_datetime}, scanUrl={self.scanUrl}, host={self.host}, method={self.method}, headers={self.headers}, body={self.body}, remote_addr={self.remote_addr}, process={self.process}, output_directory={self.output_directory}, options={self.options}, _original_options={self._original_options}, _user_set_options={self._user_set_options}, _header_rules_applied={self._header_rules_applied}, _body_field_rules_applied={self._body_field_rules_applied}, _request_file_path={self._request_file_path})"
82+
7983
def initialize_options(self, taskid):
8084
datatype = {"boolean": False, "string": None, "integer": None, "float": None}
8185
self.options = AttribDict()

src/backEnd/utils/task_monitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_max_tasks_count():
3434

3535

3636
def monitor(max_tasks_count=None):
37-
# logger.info("monitor...")
37+
logger.debug("monitor triggered...")
3838
# logger.debug(f"monitor -> id(DataStore.tasks): {id(DataStore.tasks)}")
3939
# logger.debug(f"monitor -> id(DataStore.current_db): {id(DataStore.current_db)}")
4040
local_max_tasks_count = 0
@@ -56,7 +56,6 @@ def monitor(max_tasks_count=None):
5656
with DataStore.tasks_lock:
5757
runnable_list = []
5858
running_task_cnt = 0
59-
6059
for taskid in DataStore.tasks:
6160
task = DataStore.tasks[taskid]
6261
task_orin_status = task.status
@@ -87,7 +86,8 @@ def monitor(max_tasks_count=None):
8786
continue
8887
else:
8988
running_task_cnt += 1
90-
# logger.debug(f"monitor -> task_id: {task.options.taskid} task.start_datetime: {task.start_datetime}")
89+
logger.debug(f"monitor -> task_id: {task.options.taskid} task.start_datetime: {task.start_datetime}")
90+
logger.debug(f"monitor -> task_info: {task}")
9191
task.start_datetime = datetime.now()
9292
task.engine_start()
9393
task.status = TaskStatus.Running

0 commit comments

Comments
 (0)