22import subprocess
33
44from celery import shared_task
5- from django .db import transaction
65from django .utils import timezone
76
8- from common .models import BaseScanJob
97from .models import PathScanJob , PathScanResult # 确保导入模型
10-
8+ from common . utils import get_scan_job_by_task_id
119
1210@shared_task (bind = True )
13- def scan_paths (self , wordlist , url , delay , from_job = None ):
11+ def scan_paths (self , wordlist , url , delay , from_job_id = None ):
1412 # 确保URL格式正确,移除FUZZ前的斜杠(如果存在)
1513 url = url .replace ('/FUZZ' , 'FUZZ' ) # 直接替换'/FUZZ'为'FUZZ'
1614
15+ from_job_instance = None
16+ if from_job_id :
17+ try :
18+ from_job_instance = get_scan_job_by_task_id (from_job_id )
19+ except Exception :
20+ from_job_instance = None
21+
1722 # 创建PathScanJob实例
1823 scan_job = PathScanJob .objects .create (
1924 target = url ,
2025 status = 'R' ,
2126 task_id = self .request .id ,
22- from_job = from_job ,
27+ from_job = from_job_instance ,
2328 )
2429
2530 # 构建输出文件名
@@ -29,13 +34,6 @@ def scan_paths(self, wordlist, url, delay, from_job=None):
2934 cmd = f"ffuf -w { wordlist } -u { url } -r -p { delay } -mc all -o { output_file_path } -of json"
3035
3136 try :
32- # 如果提供了from_job_id,则设置对应from_job的to_job为当前任务
33- if from_job_id :
34- with transaction .atomic (): # 确保以下操作在一个事务中
35- from_job = BaseScanJob .objects .get (task_id = from_job_id )
36- from_job .to_job = scan_job .task_id
37- from_job .save ()
38-
3937 # 执行ffuf命令
4038 process = subprocess .run (cmd , shell = True , check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
4139
0 commit comments