Skip to content

Commit

Permalink
Merge pull request #23 from rly0nheart/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rly0nheart authored Sep 29, 2023
2 parents f818def + c4cf2c9 commit 1a410f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages = ["tor2tor"]

[project]
name = "tor2tor"
version = "0.8.1"
version = "0.9.0"
description = "Capture screenshots of onion services on an onion service."
readme = "README.md"
requires-python = ">=3.9"
Expand Down
2 changes: 1 addition & 1 deletion tor2tor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = "Richard Mwewa"
__about__ = "https://about.me/rly0nheart"
__version__ = "0.8.1"
__version__ = "0.9.0"
8 changes: 5 additions & 3 deletions tor2tor/coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ def is_valid_onion(url: str) -> bool:
-----------------
- ^ - Asserts the start of a string.
- (http://|https://)? - Matches HTTP or HTTPS protocol in the string (optional).
- [a-z2-7]{56,} - Matches 56 or more characters, where each can be a lowercase letter or a digit from 2 to 7.
- d\\.onion - Matches the letter "d" followed by .onion.
- (www\\.)? - Optionally matches the www. subdomain.
- ([a-z2-7]{54,}d) - Matches 55 or more characters, where each can be a lowercase letter or a digit from 2 to 7,
and ends with 'd'.
- \\.onion - Matches .onion.
- (/|$) - Matches either a forward slash or the end of the string.
"""
if re.search(r"^(http://|https://)?[a-z2-7]{56,}d\.onion(/|$)", url):
if re.search(r"^(http://|https://)?(www\.)?([a-z2-7]{54,}d)\.onion(/|$)", url):
return True
else:
return False
Expand Down
67 changes: 46 additions & 21 deletions tor2tor/tor2tor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ def open_firefox_pool(pool_size: int) -> Queue:
log.info(f"Opening WebDriver pool with {args.pool} instances...")

# Populate the pool with Firefox instances.
for webdriver_instance in range(pool_size): # Create 3 (default) instances
for instance_index, webdriver_instance in enumerate(
range(pool_size), start=1
): # Create 3 (default) instances
driver = webdriver.Firefox(
options=firefox_options(instance_index=webdriver_instance)
options=firefox_options(instance_index=instance_index)
)
pool.put(driver)

Expand Down Expand Up @@ -124,24 +126,42 @@ def worker(queue: Queue, screenshots_table: Table, pool: Queue):
# Get a new task from the queue
onion_index, onion = queue.get()

# Borrow a Firefox instance from the pool
driver = pool.get()

# Capture the screenshot
capture_onion(
onion_url=onion,
onion_index=onion_index,
driver=driver,
table=screenshots_table,
)
captured_onions_queue.put(
(onion_index, onion, convert_timestamp_to_utc(timestamp=time.time()))
)

# On successful capture, return the Firefox instance back to the pool and mark the task as done
# Do the same on exception.
pool.put(driver)
queue.task_done()
if is_valid_onion(url=onion):
# Borrow a Firefox instance from the pool
driver = pool.get()

# Capture the screenshot
capture_onion(
onion_url=onion,
onion_index=onion_index,
driver=driver,
table=screenshots_table,
)
captured_onions_queue.put(
(
onion_index,
onion,
convert_timestamp_to_utc(timestamp=time.time()),
)
)

# On successful capture, return the Firefox instance back to the pool and mark the task as done
# Do the same on exception.
pool.put(driver)
queue.task_done()
else:
log.warning(
f"{onion_index} {onion} does not seem to be a valid onion. Skipping..."
)
# Add the invalid onion to the skipped_onions queue
skipped_onions_queue.put(
(
onion_index,
onion,
"[yellow]Invalid onion[/]",
convert_timestamp_to_utc(timestamp=time.time()),
)
)

except KeyboardInterrupt:
log.warning(f"User interruption detected ([yellow]Ctrl+C[/])")
Expand All @@ -152,7 +172,12 @@ def worker(queue: Queue, screenshots_table: Table, pool: Queue):

# Add the skipped onion index, the onion itself, the time it was skipped, and the reason it was skipped
skipped_onions_queue.put(
(onion_index, onion, e, convert_timestamp_to_utc(timestamp=time.time()))
(
onion_index,
onion,
f"[red]{e}[/]",
convert_timestamp_to_utc(timestamp=time.time()),
)
)

pool.put(driver)
Expand Down

0 comments on commit 1a410f9

Please sign in to comment.