Exploit databaseDownload repository ZIP
GH-096d7d27b0deb294a13e782188e102be
aaidilz/cve-search
Sources for CVE-2021-44228
465 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files7
aaidilz/cve-searchRevision 3c97db58bfcc
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
module/utils.py
Python · 3,210 bytes"""Utilities for CVE Search application."""
import re
import logging
from typing import Optional, Tuple
from .config import CVE_PATTERN
from .exceptions import InvalidCVEFormatError
def setup_logging(log_level: str = "INFO") -> logging.Logger:
"""Set up logging configuration.
Args:
log_level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Returns:
Configured logger instance
"""
logging.basicConfig(
level=getattr(logging, log_level.upper()),
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
)
return logging.getLogger(__name__)
def validate_cve_format(cve_id: str) -> bool:
"""Validate CVE ID format.
Args:
cve_id: CVE ID to validate
Returns:
True if valid, False otherwise
"""
if not cve_id:
return False
cve_id = cve_id.upper().strip()
return bool(re.match(CVE_PATTERN, cve_id))
def parse_cve_id(cve_id: str) -> Tuple[str, str]:
"""Parse CVE ID to extract year and full ID.
Args:
cve_id: CVE ID in format CVE-YYYY-NNNN
Returns:
Tuple of (year, normalized_cve_id)
Raises:
InvalidCVEFormatError: If CVE format is invalid
"""
cve_id = cve_id.upper().strip()
if not validate_cve_format(cve_id):
raise InvalidCVEFormatError(f"Invalid CVE format: {cve_id}")
parts = cve_id.split('-')
year = parts[1]
return year, cve_id
def get_user_confirmation(prompt: str, default: bool = False) -> bool:
"""Get user confirmation with y/n prompt.
Args:
prompt: Prompt message to display
default: Default value if user just presses enter
Returns:
True for yes, False for no
"""
default_text = " (Y/n)" if default else " (y/N)"
while True:
response = input(f"{prompt}{default_text}: ").strip().lower()
if not response:
return default
if response in ('y', 'yes'):
return True
elif response in ('n', 'no'):
return False
else:
print("Please enter 'y' for yes or 'n' for no.")
def truncate_content_for_display(content: str, max_lines: int = 100) -> Tuple[str, bool]:
"""Truncate content for display if it's too long.
Args:
content: Content to potentially truncate
max_lines: Maximum number of lines to display
Returns:
Tuple of (truncated_content, was_truncated)
"""
from .config import MAX_DISPLAY_LINES, TRUNCATION_MESSAGE
lines = content.split('\n')
if len(lines) <= max_lines:
return content, False
# Take first max_lines and add truncation message
truncated_lines = lines[:max_lines]
truncated_content = '\n'.join(truncated_lines) + TRUNCATION_MESSAGE
return truncated_content, True
def count_content_lines(content: str) -> int:
"""Count the number of lines in content.
Args:
content: Content to count lines for
Returns:
Number of lines
"""
return len(content.split('\n'))