Skip to content

Commit a4dfe35

Browse files
update
1 parent 7f9d5c4 commit a4dfe35

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

containers/llm-orchestrator/api.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,42 @@
33

44
from flask import Flask, request, jsonify
55
import requests
6+
from email_utils import get_latest_token_from_email
67

78
app = Flask(__name__)
89

10+
@app.route('/get-email-token', methods=['POST'])
11+
def get_email_token():
12+
"""
13+
Pobiera najnowszy token (np. kod 2FA) ze skrzynki email.
14+
Wymaga JSON z polami: imap_server, email_user, email_pass, optional: mailbox, search_subject, token_regex
15+
"""
16+
data = request.json
17+
imap_server = data.get('imap_server')
18+
email_user = data.get('email_user')
19+
email_pass = data.get('email_pass')
20+
mailbox = data.get('mailbox', 'INBOX')
21+
search_subject = data.get('search_subject')
22+
token_regex = data.get('token_regex', r'\\b\d{6}\\b')
23+
if not (imap_server and email_user and email_pass):
24+
return jsonify({"error": "Brak wymaganych pól: imap_server, email_user, email_pass"}), 400
25+
try:
26+
token = get_latest_token_from_email(
27+
imap_server=imap_server,
28+
email_user=email_user,
29+
email_pass=email_pass,
30+
mailbox=mailbox,
31+
search_subject=search_subject,
32+
token_regex=token_regex
33+
)
34+
if token:
35+
return jsonify({"token": token})
36+
else:
37+
return jsonify({"error": "Nie znaleziono tokenu."}), 404
38+
except Exception as e:
39+
return jsonify({"error": str(e)}), 500
40+
41+
942
# --- Lazy loading przykładowego modelu transformers ---
1043
from transformers import AutoModelForCausalLM, AutoTokenizer
1144

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import imaplib
2+
import email
3+
from email.header import decode_header
4+
import re
5+
from typing import Optional
6+
import os
7+
8+
def get_latest_token_from_email(
9+
imap_server: str,
10+
email_user: str,
11+
email_pass: str,
12+
mailbox: str = "INBOX",
13+
search_subject: Optional[str] = None,
14+
token_regex: str = r"\\b\d{6}\\b"
15+
) -> Optional[str]:
16+
"""
17+
Pobiera najnowszy token (np. kod 2FA) ze skrzynki email.
18+
:param imap_server: adres serwera IMAP
19+
:param email_user: login do skrzynki
20+
:param email_pass: hasło do skrzynki
21+
:param mailbox: skrzynka (domyślnie INBOX)
22+
:param search_subject: opcjonalny filtr po temacie
23+
:param token_regex: regex do wyłuskania tokenu (domyślnie 6-cyfrowy kod)
24+
:return: token lub None
25+
"""
26+
mail = imaplib.IMAP4_SSL(imap_server)
27+
mail.login(email_user, email_pass)
28+
mail.select(mailbox)
29+
search_criteria = '(UNSEEN)'
30+
if search_subject:
31+
search_criteria = f'(UNSEEN SUBJECT "{search_subject}")'
32+
status, messages = mail.search(None, search_criteria)
33+
if status != 'OK':
34+
return None
35+
for num in reversed(messages[0].split()):
36+
status, data = mail.fetch(num, '(RFC822)')
37+
if status != 'OK':
38+
continue
39+
msg = email.message_from_bytes(data[0][1])
40+
if msg.is_multipart():
41+
for part in msg.walk():
42+
if part.get_content_type() == "text/plain":
43+
body = part.get_payload(decode=True).decode(errors='ignore')
44+
break
45+
else:
46+
continue
47+
else:
48+
body = msg.get_payload(decode=True).decode(errors='ignore')
49+
match = re.search(token_regex, body)
50+
if match:
51+
return match.group(0)
52+
return None

docker-compose.min.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ services:
55
build:
66
context: ./containers/llm-orchestrator-min
77
args:
8-
- BUILDKIT_INLINE_CACHE=1
98
container_name: llm-orchestrator-min
109
volumes:
1110
- ./volumes/models:/app/models
@@ -31,7 +30,6 @@ services:
3130
build:
3231
context: ./containers/browser-service
3332
args:
34-
- BUILDKIT_INLINE_CACHE=1
3533
container_name: browser-service
3634
volumes:
3735
- ./volumes/recordings:/app/recordings
@@ -53,7 +51,6 @@ services:
5351
build:
5452
context: ./containers/novnc
5553
args:
56-
- BUILDKIT_INLINE_CACHE=1
5754
container_name: novnc
5855
deploy:
5956
resources:

0 commit comments

Comments
 (0)