-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
249 additions
and
78 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
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
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
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,107 @@ | ||
import datetime | ||
from typing import Optional | ||
|
||
from libmailgoose.language import Language | ||
from libmailgoose.scan import DomainValidationException, ScanningException | ||
from libmailgoose.translate import translate | ||
from redis import Redis | ||
|
||
from common.config import Config | ||
|
||
from .app_utils import get_from_and_dkim_domain, scan_and_log | ||
from .check_results import save_check_results | ||
from .db import ScanLogEntrySource | ||
from .logging import build_logger | ||
from .resolver import setup_resolver | ||
|
||
LOGGER = build_logger(__name__) | ||
REDIS = Redis.from_url(Config.Data.REDIS_URL) | ||
|
||
setup_resolver() | ||
|
||
|
||
def scan_domain_job( | ||
client_ip: Optional[str], | ||
client_user_agent: Optional[str], | ||
domain: str, | ||
token: str, | ||
) -> None: | ||
try: | ||
result = scan_and_log( | ||
source=ScanLogEntrySource.GUI, | ||
envelope_domain=domain, | ||
from_domain=domain, | ||
dkim_domain=None, | ||
message=None, | ||
message_timestamp=None, | ||
nameservers=Config.Network.NAMESERVERS, | ||
language=Language(Config.UI.LANGUAGE), | ||
client_ip=client_ip, | ||
client_user_agent=client_user_agent, | ||
) | ||
error = None | ||
except (DomainValidationException, ScanningException) as e: | ||
result = None | ||
error = translate(e.message, Language(Config.UI.LANGUAGE)) | ||
|
||
save_check_results( | ||
envelope_domain=domain, | ||
from_domain=domain, | ||
dkim_domain=None, | ||
result=result, | ||
error=error, | ||
rescan_url="/check-domain/", | ||
message_recipient_username=None, | ||
token=token, | ||
) | ||
|
||
|
||
def scan_message_and_domain_job( | ||
client_ip: Optional[str], | ||
client_user_agent: Optional[str], | ||
envelope_domain: str, | ||
token: str, | ||
message_key: bytes, | ||
recipient_username: str, | ||
) -> None: | ||
message_data = REDIS.get(message_key) | ||
message_timestamp_raw = REDIS.get(message_key + b"-timestamp") | ||
|
||
if not message_data or not message_timestamp_raw: | ||
raise RuntimeError("Worker coudn't access message data") | ||
|
||
message_timestamp = datetime.datetime.fromisoformat(message_timestamp_raw.decode("ascii")) | ||
|
||
from_domain, dkim_domain = get_from_and_dkim_domain(message_data) | ||
if not from_domain: | ||
result = None | ||
error = translate("Invalid or no e-mail domain in the message From header", Language(Config.UI.LANGUAGE)) | ||
else: | ||
try: | ||
result = scan_and_log( | ||
source=ScanLogEntrySource.GUI, | ||
envelope_domain=envelope_domain, | ||
from_domain=from_domain, | ||
dkim_domain=dkim_domain, | ||
message=message_data, | ||
message_timestamp=message_timestamp, | ||
nameservers=Config.Network.NAMESERVERS, | ||
language=Language(Config.UI.LANGUAGE), | ||
client_ip=client_ip, | ||
client_user_agent=client_user_agent, | ||
) | ||
error = None | ||
except (DomainValidationException, ScanningException) as e: | ||
result = None | ||
error = translate(e.message, Language(Config.UI.LANGUAGE)) | ||
|
||
save_check_results( | ||
envelope_domain=envelope_domain, | ||
from_domain=from_domain or envelope_domain, | ||
dkim_domain=dkim_domain, | ||
result=result, | ||
error=error, | ||
rescan_url="/check-email/", | ||
message_recipient_username=recipient_username, | ||
token=token, | ||
) |
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,20 @@ | ||
{% extends "custom_layout.html" %} | ||
|
||
{% block header_additional %} | ||
<meta http-equiv="refresh" content="5"> | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<div class="container"> | ||
<div class="p-4"> | ||
<h1>{% trans %}Domain analysis is running{% endtrans %}</h1> | ||
<div> | ||
<img class="float-start" src="/static/images/spinner.svg" /> | ||
<div class="py-5"> | ||
<h5 class="waiting">{% trans %}Waiting for the domain analysis to finish{% endtrans %}</h5> | ||
<div>{% trans %}This page will refresh automatically{% endtrans %}</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
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
Oops, something went wrong.