mirror of
https://github.com/j93es/oauth-backend.git
synced 2026-10-12 07:21:20 +09:00
[Refactor] 리팩터링
This commit is contained in:
parent
afcfd7de87
commit
062552d3d8
2 changed files with 24 additions and 22 deletions
32
lib/cur_target_url.py
Normal file
32
lib/cur_target_url.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# save ./data/target.temp file as domain string
|
||||
import os
|
||||
|
||||
def save(target: str, file_path: str = "./data/target.dump") -> None:
|
||||
"""
|
||||
Save the target domain to a temporary file.
|
||||
|
||||
:param target: Target domain to be saved.
|
||||
"""
|
||||
# Create directory if it doesn't exist
|
||||
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
||||
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(target)
|
||||
|
||||
print(f"Target saved to {file_path}") # Debug message
|
||||
|
||||
def load(file_path: str = "./data/target.dump") -> str:
|
||||
"""
|
||||
Load the target domain from a temporary file.
|
||||
|
||||
:return: Target domain string.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
print(f"[ERROR] Target file {file_path} does not exist.")
|
||||
return ""
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
target = f.read().strip()
|
||||
|
||||
print(f"Loaded target from {file_path}: {target}") # Debug message
|
||||
return target
|
||||
32
lib/report_vuln.py
Normal file
32
lib/report_vuln.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# save as data/report.csv
|
||||
import os
|
||||
import csv
|
||||
from typing import List, Dict, Any
|
||||
|
||||
# target, status, title, description, uri
|
||||
|
||||
# file path는 'data/report.csv'로 고정
|
||||
def save_report(report_data: List[Dict[str, Any]], file_path: str = 'data/report.csv') -> None:
|
||||
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
||||
|
||||
|
||||
"""
|
||||
report_data 안의 각 레포트를 한 줄씩 CSV에 추가로 저장합니다.
|
||||
파일이 없으면 헤더를 먼저 쓰고, 있으면 레코드만 이어서 씁니다.
|
||||
"""
|
||||
fieldnames = ['target', 'status', 'title', 'description', 'uri']
|
||||
file_exists = os.path.exists(file_path)
|
||||
|
||||
with open(file_path, mode='a', newline='', encoding='utf-8') as csvfile:
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
# 파일이 없던 새로 만들 때만 헤더 작성
|
||||
if not file_exists:
|
||||
writer.writeheader()
|
||||
|
||||
for row in report_data:
|
||||
# None 방지 & 줄바꿈 이스케이프
|
||||
escaped = {
|
||||
k: str(v).replace('\n', '\\n') if v is not None else ''
|
||||
for k, v in row.items()
|
||||
}
|
||||
writer.writerow(escaped)
|
||||
Loading…
Reference in a new issue