diff --git a/app.py b/app.py index e625e39..a12cc7f 100644 --- a/app.py +++ b/app.py @@ -1427,6 +1427,64 @@ def reply_single(review_id: str): return redirect(url_for("index", status="reply_sent", count=1, **redirect_params)) +TG_BOT_TOKEN = "8181219074:AAGvqWqb6t10YP4xpMOQnBq_6LrUqAFm5hM" +TG_CHAT_ID = 54986411 +TG_API_URL = f"https://tel.4mont.ru/bot{TG_BOT_TOKEN}/sendMessage" + + +def _get_real_ip() -> str: + forwarded_for = request.headers.get("x-forwarded-for", "") + if forwarded_for: + return forwarded_for.split(",")[0].strip() + return request.remote_addr or "unknown" + + +def _get_geo(ip: str) -> str: + try: + if ip in ("unknown", "127.0.0.1", "::1") or ip.startswith("10.") or ip.startswith("192.168."): + return "" + url = f"http://ip-api.com/json/{ip}?lang=ru&fields=status,country,regionName,city" + resp = requests.get(url, timeout=5, headers={"User-Agent": "Mozilla/5.0"}) + data = resp.json() + if data.get("status") == "success": + parts = [data.get("country", ""), data.get("regionName", ""), data.get("city", "")] + return ", ".join(p for p in parts if p) + except Exception: + pass + return "" + + +def _send_telegram(text: str) -> bool: + try: + resp = requests.post(TG_API_URL, json={"chat_id": TG_CHAT_ID, "text": text, "parse_mode": "HTML"}, timeout=10) + return resp.ok + except Exception: + return False + + +@app.route("/request-access", methods=["POST"]) +def request_access(): + name = (request.form.get("name") or "").strip() + email = (request.form.get("email") or "").strip() + phone = (request.form.get("phone") or "").strip() + if not name or not email or not phone: + return jsonify({"ok": False, "error": "Заполните все поля"}), 400 + ip = _get_real_ip() + geo = _get_geo(ip) + geo_line = f"\n📍 Местоположение: {geo}" if geo else "" + text = ( + "🔔 Новый запрос доступа к WBfeed\n" + "━━━━━━━━━━━━━━━━━━━━━━\n\n" + f"👤 Имя: {name}\n" + f"📧 Email: {email}\n" + f"📱 Телефон: {phone}" + f"{geo_line}\n" + f"🖥 IP: {ip}" + ) + _send_telegram(text) + return jsonify({"ok": True}) + + @app.route("/login", methods=["GET", "POST"]) def login(): if g.get("user"): diff --git a/templates/login.html b/templates/login.html index b275160..b2dd79c 100644 --- a/templates/login.html +++ b/templates/login.html @@ -85,10 +85,149 @@ -
+ + + + + + + +