Update cmd_wdir.py

This commit is contained in:
m5rcel { Marcel }
2025-09-09 17:27:12 +02:00
committed by GitHub
parent 7f14f18658
commit c69132b4a0

View File

@@ -34,29 +34,35 @@ class WdirCommand:
if not href: if not href:
continue continue
# Skip parent directory and in-page anchors # Ignore "parent directory" or anchors
if href.startswith("?") or href.startswith("#") or href == "../": if href.startswith("?") or href.startswith("#") or href.startswith("../"):
continue continue
filename = href.split("/")[-1] # Detect if it's a folder
full_url = urljoin(self.url, href) is_dir = href.endswith("/")
filename = href.rstrip("/").split("/")[-1]
# Skip HTML/PHP/ASP/etc. pages that arent real hosted files
if not is_dir and re.search(r"\.(php|html?|asp|aspx|jsp)$", filename, re.I):
continue
# Guess type # Guess type
if "." in filename: if is_dir:
ext = filename.split(".")[-1].lower()
ftype = f".{ext} file"
else:
ftype = "Directory" ftype = "Directory"
elif "." in filename:
ftype = f".{filename.split('.')[-1]} file"
else:
ftype = "File"
# Try to extract file size and modified date from raw HTML # Try to extract file size + modified date if available in listing row
row_text = link.parent.get_text(" ", strip=True) row_text = link.parent.get_text(" ", strip=True)
size_match = re.search(r"(\d+(?:\.\d+)?\s*(?:KB|MB|GB|B))", row_text, re.I) size_match = re.search(r"(\d+(?:\.\d+)?\s*(?:KB|MB|GB|B))", row_text, re.I)
date_match = re.search(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2})", row_text) date_match = re.search(r"(\d{4}-\d{2}-\d{2} \d{2}:\d{2})", row_text)
size = size_match.group(1) if size_match else "?" size = size_match.group(1) if size_match else "-"
modified = date_match.group(1) if date_match else "?" modified = date_match.group(1) if date_match else "-"
files.append((filename, ftype, size, modified, full_url)) files.append((filename, ftype, size, modified))
if not files: if not files:
print(Fore.YELLOW + "No files or directories found (maybe directory listing is disabled)." + Style.RESET_ALL) print(Fore.YELLOW + "No files or directories found (maybe directory listing is disabled)." + Style.RESET_ALL)
@@ -66,6 +72,13 @@ class WdirCommand:
print(Fore.MAGENTA + f"{'Name':<30}{'Type':<15}{'Size':<12}{'Modified':<20}" + Style.RESET_ALL) print(Fore.MAGENTA + f"{'Name':<30}{'Type':<15}{'Size':<12}{'Modified':<20}" + Style.RESET_ALL)
print(Fore.MAGENTA + "-" * 77 + Style.RESET_ALL) print(Fore.MAGENTA + "-" * 77 + Style.RESET_ALL)
for fname, ftype, size, modified, furl in files: for fname, ftype, size, modified in files:
print(f"{Fore.CYAN}{fname:<30}{Style.RESET_ALL} " if ftype == "Directory":
color = Fore.BLUE
elif ftype.endswith("file"):
color = Fore.CYAN
else:
color = Fore.WHITE
print(f"{color}{fname:<30}{Style.RESET_ALL} "
f"{Fore.WHITE}{ftype:<15}{size:<12}{modified:<20}{Style.RESET_ALL}") f"{Fore.WHITE}{ftype:<15}{size:<12}{modified:<20}{Style.RESET_ALL}")