Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import qrcode
|
|
| 6 |
from io import BytesIO
|
| 7 |
from flask import Flask
|
| 8 |
from pyrogram import Client, filters
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
# -----------------------------
|
|
@@ -19,7 +20,11 @@ def log(msg):
|
|
| 19 |
# QR GENERATOR
|
| 20 |
# -----------------------------
|
| 21 |
def make_qr(data: str):
|
| 22 |
-
qr = qrcode.QRCode(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
qr.add_data(data)
|
| 24 |
qr.make(fit=True)
|
| 25 |
|
|
@@ -34,41 +39,50 @@ def make_qr(data: str):
|
|
| 34 |
|
| 35 |
|
| 36 |
# -----------------------------
|
| 37 |
-
#
|
| 38 |
# -----------------------------
|
| 39 |
def fetch_bridges(transport: str):
|
| 40 |
|
|
|
|
| 41 |
if transport == "webtunnel":
|
| 42 |
url = "https://bridges.torproject.org/bridges/en?transport=webtunnel"
|
| 43 |
else:
|
| 44 |
url = f"https://bridges.torproject.org/bridges?transport={transport}"
|
| 45 |
|
| 46 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
try:
|
| 49 |
-
r = requests.get(url, headers=headers, timeout=
|
| 50 |
except Exception as e:
|
| 51 |
log(f"Request error: {e}")
|
| 52 |
return []
|
| 53 |
|
|
|
|
|
|
|
| 54 |
if r.status_code != 200:
|
| 55 |
return []
|
| 56 |
|
|
|
|
| 57 |
bridges = [
|
| 58 |
line.strip()
|
| 59 |
for line in r.text.splitlines()
|
| 60 |
if transport in line and ":" in line
|
| 61 |
]
|
| 62 |
|
| 63 |
-
# fallback
|
| 64 |
if transport == "webtunnel" and not bridges:
|
|
|
|
| 65 |
return fetch_bridges("obfs4")
|
| 66 |
|
| 67 |
return bridges
|
| 68 |
|
| 69 |
|
| 70 |
# -----------------------------
|
| 71 |
-
# FLASK
|
| 72 |
# -----------------------------
|
| 73 |
app = Flask(__name__)
|
| 74 |
|
|
@@ -105,47 +119,54 @@ bot = Client(
|
|
| 105 |
# -----------------------------
|
| 106 |
@bot.on_message(filters.command("start"))
|
| 107 |
def start(_, msg):
|
| 108 |
-
msg.reply_text(
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
@bot.on_message(filters.command("bridge"))
|
| 112 |
def bridge(_, msg):
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
|
| 116 |
# -----------------------------
|
| 117 |
-
#
|
| 118 |
# -----------------------------
|
| 119 |
-
@bot.
|
| 120 |
-
def
|
| 121 |
|
| 122 |
-
transport =
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
bridges = fetch_bridges(transport)
|
| 127 |
|
| 128 |
if not bridges:
|
| 129 |
-
|
| 130 |
return
|
| 131 |
|
| 132 |
-
#
|
| 133 |
-
|
| 134 |
-
# -------------------------
|
| 135 |
-
bridge_text = "\n".join(bridges)
|
| 136 |
-
|
| 137 |
-
msg.reply_text(bridge_text)
|
| 138 |
|
| 139 |
-
#
|
| 140 |
-
|
| 141 |
-
# -------------------------
|
| 142 |
-
qr_img = make_qr(bridge_text)
|
| 143 |
|
| 144 |
-
|
|
|
|
| 145 |
photo=qr_img,
|
| 146 |
-
caption=
|
| 147 |
)
|
| 148 |
|
|
|
|
|
|
|
| 149 |
|
| 150 |
# -----------------------------
|
| 151 |
# RUN SYSTEM
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
from flask import Flask
|
| 8 |
from pyrogram import Client, filters
|
| 9 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
| 10 |
|
| 11 |
|
| 12 |
# -----------------------------
|
|
|
|
| 20 |
# QR GENERATOR
|
| 21 |
# -----------------------------
|
| 22 |
def make_qr(data: str):
|
| 23 |
+
qr = qrcode.QRCode(
|
| 24 |
+
version=1,
|
| 25 |
+
box_size=8,
|
| 26 |
+
border=2
|
| 27 |
+
)
|
| 28 |
qr.add_data(data)
|
| 29 |
qr.make(fit=True)
|
| 30 |
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
# -----------------------------
|
| 42 |
+
# FETCH BRIDGES (FIXED WEBTUNNEL)
|
| 43 |
# -----------------------------
|
| 44 |
def fetch_bridges(transport: str):
|
| 45 |
|
| 46 |
+
# FIXED WEBTUNNEL ENDPOINT
|
| 47 |
if transport == "webtunnel":
|
| 48 |
url = "https://bridges.torproject.org/bridges/en?transport=webtunnel"
|
| 49 |
else:
|
| 50 |
url = f"https://bridges.torproject.org/bridges?transport={transport}"
|
| 51 |
|
| 52 |
+
headers = {
|
| 53 |
+
"User-Agent": "Mozilla/5.0"
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
log(f"Request → {url}")
|
| 57 |
|
| 58 |
try:
|
| 59 |
+
r = requests.get(url, headers=headers, timeout=20)
|
| 60 |
except Exception as e:
|
| 61 |
log(f"Request error: {e}")
|
| 62 |
return []
|
| 63 |
|
| 64 |
+
log(f"Status: {r.status_code}")
|
| 65 |
+
|
| 66 |
if r.status_code != 200:
|
| 67 |
return []
|
| 68 |
|
| 69 |
+
# SIMPLE PARSER
|
| 70 |
bridges = [
|
| 71 |
line.strip()
|
| 72 |
for line in r.text.splitlines()
|
| 73 |
if transport in line and ":" in line
|
| 74 |
]
|
| 75 |
|
| 76 |
+
# fallback if webtunnel empty
|
| 77 |
if transport == "webtunnel" and not bridges:
|
| 78 |
+
log("WebTunnel empty → fallback obfs4")
|
| 79 |
return fetch_bridges("obfs4")
|
| 80 |
|
| 81 |
return bridges
|
| 82 |
|
| 83 |
|
| 84 |
# -----------------------------
|
| 85 |
+
# FLASK KEEP ALIVE
|
| 86 |
# -----------------------------
|
| 87 |
app = Flask(__name__)
|
| 88 |
|
|
|
|
| 119 |
# -----------------------------
|
| 120 |
@bot.on_message(filters.command("start"))
|
| 121 |
def start(_, msg):
|
| 122 |
+
msg.reply_text(
|
| 123 |
+
"🌉 Tor Bridge Bot\n\n"
|
| 124 |
+
"Use /bridge and send:\nobfs4 or webtunnel"
|
| 125 |
+
)
|
| 126 |
|
| 127 |
|
| 128 |
@bot.on_message(filters.command("bridge"))
|
| 129 |
def bridge(_, msg):
|
| 130 |
+
keyboard = InlineKeyboardMarkup([
|
| 131 |
+
[
|
| 132 |
+
InlineKeyboardButton("🔵 obfs4", callback_data="obfs4"),
|
| 133 |
+
InlineKeyboardButton("🌐 webtunnel", callback_data="webtunnel")
|
| 134 |
+
]
|
| 135 |
+
])
|
| 136 |
+
|
| 137 |
+
msg.reply_text("Choose bridge type:", reply_markup=keyboard)
|
| 138 |
|
| 139 |
|
| 140 |
# -----------------------------
|
| 141 |
+
# CALLBACK HANDLER
|
| 142 |
# -----------------------------
|
| 143 |
+
@bot.on_callback_query()
|
| 144 |
+
def callback(_, query):
|
| 145 |
|
| 146 |
+
transport = query.data
|
| 147 |
|
| 148 |
+
query.message.edit_text("🔄 Fetching bridges...")
|
| 149 |
|
| 150 |
bridges = fetch_bridges(transport)
|
| 151 |
|
| 152 |
if not bridges:
|
| 153 |
+
query.message.edit_text("❌ No bridges found.")
|
| 154 |
return
|
| 155 |
|
| 156 |
+
# ONLY BRIDGES TEXT
|
| 157 |
+
text = "\n".join(bridges)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
+
# QR CODE FROM SAME DATA
|
| 160 |
+
qr_img = make_qr(text)
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
# SEND ONLY BRIDGES + QR
|
| 163 |
+
query.message.reply_photo(
|
| 164 |
photo=qr_img,
|
| 165 |
+
caption=text
|
| 166 |
)
|
| 167 |
|
| 168 |
+
query.message.delete()
|
| 169 |
+
|
| 170 |
|
| 171 |
# -----------------------------
|
| 172 |
# RUN SYSTEM
|