Karl 4352004ed3 feat(app): restructure as a modern Flask API
This commit refactors the entire backend application into a more structured and maintainable Flask project. It introduces an application factory pattern, consolidates routes into a blueprint, and implements a robust authentication and database layer.

- Introduces a Flask application factory (`create_app` in `main.py`) for better organization and testability.
- Consolidates all API routes into a single blueprint (`routes/api.py`) for modularity.
- Implements a new basic authentication system using a decorator (`@requires_basic_auth`) to secure all endpoints.
- Refactors the database access layer with standardized query execution and connection handling.
- Adds new modules for core logic, including an account checker (`checker.py`) and user retrieval (`get_users.py`).
- Updates the VSCode launch configuration to support the new Flask application structure.

BREAKING CHANGE: The application has been completely restructured. The old `server.py` entry point is removed. The application should now be run via the app factory in `main.py`. All API endpoints now require basic authentication.
2025-07-13 19:40:04 +01:00

41 lines
1.6 KiB
Python

import requests
import concurrent.futures
import time
from requests_tor import RequestsTor
import os
from dotenv import load_dotenv
from get_urls import generate_urls_for_user
import json
load_dotenv()
rt = RequestsTor(tor_host=os.getenv('TORSSRV'), tor_ports=(9001, 9002, 9003, 9004, 9005), tor_cport=9051, password=os.getenv('TORSPWD'), autochange_id=3)
def get_status(url):
try:
resp = rt.get(url=url, timeout=2)
if resp.status_code == 200:
if "<html><head>" not in resp.text:
response_data = json.loads(resp.text)
if response_data['user_info']['auth'] == 1:
return response_data
except:
pass
def find_url_for_user_details(username, password):
urls = generate_urls_for_user(username, password)
tm1 = time.perf_counter()
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for url in urls:
futures.append(executor.submit(get_status, url=url))
for future in concurrent.futures.as_completed(futures):
if future._result != None:
executor.shutdown(wait=False)
print(f"{future._result['user_info']['username']} - {future._result['server_info']['url']}:{future._result['server_info']['port']}")
tm2 = time.perf_counter()
print(f'Total time elapsed: {tm2-tm1:0.2f} seconds')
# find_url_for_user_details('Karl061122', 'gkuEDWzxHD')
# find_url_for_user_details('Karl130623', 'emYZWPs')
# find_url_for_user_details('Karlos2306', 'Gg58Wg8MB9')
# find_url_for_user_details('Maxine2306', 'EszFDNNcb2')