Skip to content

Commit

Permalink
chg: [api] rename domain lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Oct 4, 2024
1 parent 6f2a59c commit 5a052c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion bin/lib/crawlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
ITEMS_FOLDER = config_loader.get_config_str("Directories", "pastes")
HAR_DIR = config_loader.get_files_directory('har')
activate_crawler = config_loader.get_config_str("Crawler", "activate_crawler")
D_HAR = config_loader.get_config_boolean('Crawler', 'default_har')
D_SCREENSHOT = config_loader.get_config_boolean('Crawler', 'default_screenshot')
config_loader = None

faup = Faup()
Expand All @@ -65,9 +67,14 @@
# is safe ???
# TODO FILTER URL ???

def api_get_domain_lookup_meta(domain):
def api_get_onion_lookup(domain):
domain = domain.lower()
dom = Domain(domain)
if not is_valid_onion_v3_domain(domain):
return {'error': 'Invalid Domain', 'domain': domain}, 404
if not dom.exists():
if is_crawler_activated():
create_task(domain, parent='lookup', priority=0, har=D_HAR, screenshot=D_SCREENSHOT)
return {'error': 'domain not found', 'domain': domain}, 404
meta = dom.get_meta(options={'languages'})
meta['first_seen'] = meta['first_seen'].replace('/', '-')
Expand Down Expand Up @@ -109,6 +116,11 @@ def get_date_crawled_items_source(date):
def get_har_dir():
return HAR_DIR

def is_valid_onion_v3_domain(domain):
if len(domain) == 62: # v3 address
return domain[:56].isalnum()
return False

def is_valid_onion_domain(domain):
if not domain.endswith('.onion'):
return False
Expand Down
6 changes: 3 additions & 3 deletions var/www/blueprints/api_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ def objects_chat_thread_messages():
# # # # # # # # # # # # # # # DOMAINS # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

@api_rest.route("api/v1/domain/lookup/<domain>", methods=['GET'])
@api_rest.route("api/v1/lookup/onion/<domain>", methods=['GET'])
@token_required('user')
def api_domain_lookup(domain):
return create_json_response(crawlers.api_get_domain_lookup_meta(domain), 200)
def api_lookup_onion(domain):
return create_json_response(crawlers.api_get_onion_lookup(domain), 200)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # TITLES # # # # # # # # # # # # # # # # # # # TODO TO REVIEW
Expand Down

0 comments on commit 5a052c4

Please sign in to comment.