-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: TheBoatyMcBoatFace <[email protected]>
- Loading branch information
1 parent
d575196
commit 27f8162
Showing
7 changed files
with
220 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
-- app/database/postgres/queries/clothe_domains.sql | ||
-- Creates url entry | ||
UPDATE targets.domains d | ||
SET home_url = :home_url | ||
WHERE id = :domain_id | ||
RETURNING id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
-- app/database/postgres/queries/get_naked_domains.sql | ||
SELECT | ||
id AS "domain_id", | ||
"domain" | ||
FROM targets.domains d | ||
WHERE home_url IS NULL | ||
WHERE (home_url IS NULL OR home_url = '') | ||
AND active = TRUE | ||
AND "valid" = TRUE | ||
LIMIT 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
# app/processes/__init__.py | ||
import time | ||
from multiprocessing import Process | ||
from app import logger | ||
|
||
# from .axe import get_axes, execute_axes | ||
# from .preprocess_tests import preprocess_data | ||
|
||
# Process Imports | ||
from .naked_urls import find_nakies | ||
from app import logger | ||
|
||
def process_loop(process_func, sleep_time): | ||
while True: | ||
if not process_func(): # If there is no data to process | ||
time.sleep(sleep_time) # Wait for the specified amount of time | ||
|
||
|
||
def start_processes(): | ||
logger.info('Starting processes...') | ||
find_nakies() | ||
|
||
# Functions with their sleep times | ||
processes = [ | ||
(find_nakies, 30) | ||
#(fix_axe, 60) | ||
] | ||
|
||
for process_func, sleep_time in processes: | ||
process = Process(target=process_loop, args=(process_func, sleep_time)) | ||
process.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from app import logger | ||
from app.database.postgres.run_query import run_query | ||
import requests | ||
|
||
def find_nakies(): | ||
logger.info('Starting to find naked domains...') | ||
query_name = "get_naked_domains" | ||
result = run_query(query_name) | ||
|
||
logger.debug('SQL result: %s', result) | ||
|
||
if result: | ||
try: | ||
domain_id, domain = result[0] | ||
except IndexError: | ||
logger.error('No rows were returned from the SQL query.') | ||
return False # No data to process | ||
|
||
home_url = get_home_url(domain) | ||
record_home_url(domain_id, home_url) | ||
|
||
if home_url == "BADDIE": | ||
logger.debug(f'We got a BADDIE for %s', domain) | ||
else: | ||
logger.debug(f'%s\'s home url is: %s', domain, home_url) | ||
|
||
return True # There is data to process | ||
|
||
else: | ||
logger.info('No naked domains found.') | ||
return False # No data to process | ||
|
||
|
||
def get_home_url(domain): | ||
logger.debug(f'Getting home url for %s', domain) | ||
|
||
try: | ||
response = requests.get(f'http://{domain}', timeout=5, allow_redirects=True) | ||
|
||
if response.status_code == 200: | ||
return response.url | ||
else: | ||
return "BADDIE" | ||
except requests.exceptions.RequestException as e: | ||
logger.error(f"Error while getting home URL for {domain}: {str(e)}") | ||
return "BADDIE" | ||
|
||
def record_home_url(domain_id, home_url): | ||
logger.debug('Fixing home_url for domain_id: %s', domain_id) | ||
query_name = "clothe_domains" | ||
variables = {"domain_id": domain_id, "home_url": home_url} | ||
result = run_query(query_name, variables) | ||
|
Oops, something went wrong.