From 5a052c47d973a83d85b5151fe9d80edaf06e97e9 Mon Sep 17 00:00:00 2001 From: terrtia Date: Fri, 4 Oct 2024 11:53:55 +0200 Subject: [PATCH] chg: [api] rename domain lookup --- bin/lib/crawlers.py | 14 +++++++++++++- var/www/blueprints/api_rest.py | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/lib/crawlers.py b/bin/lib/crawlers.py index 1b852570..46c20d76 100755 --- a/bin/lib/crawlers.py +++ b/bin/lib/crawlers.py @@ -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() @@ -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('/', '-') @@ -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 diff --git a/var/www/blueprints/api_rest.py b/var/www/blueprints/api_rest.py index 84cb994c..ef11396c 100644 --- a/var/www/blueprints/api_rest.py +++ b/var/www/blueprints/api_rest.py @@ -218,10 +218,10 @@ def objects_chat_thread_messages(): # # # # # # # # # # # # # # # DOMAINS # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -@api_rest.route("api/v1/domain/lookup/", methods=['GET']) +@api_rest.route("api/v1/lookup/onion/", 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