Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
| 4 |
-
import re
|
| 5 |
-
import json
|
| 6 |
import random
|
| 7 |
from urllib.parse import urlparse, parse_qs
|
| 8 |
from threading import Event
|
|
@@ -14,17 +12,17 @@ class ReportSender:
|
|
| 14 |
self.is_running = False
|
| 15 |
|
| 16 |
def execute_reports_loop(self, master_url_batch, cookie_header, batch_count, current_status):
|
| 17 |
-
"""The main continuous execution loop
|
| 18 |
-
if self.is_running
|
| 19 |
-
yield
|
| 20 |
return
|
| 21 |
|
| 22 |
if not master_url_batch or not master_url_batch.strip():
|
| 23 |
-
yield "
|
| 24 |
return
|
| 25 |
|
| 26 |
if not cookie_header or not cookie_header.strip():
|
| 27 |
-
yield "
|
| 28 |
return
|
| 29 |
|
| 30 |
self.stop_event.clear()
|
|
@@ -35,7 +33,7 @@ class ReportSender:
|
|
| 35 |
|
| 36 |
if not master_urls:
|
| 37 |
self.is_running = False
|
| 38 |
-
yield "
|
| 39 |
return
|
| 40 |
|
| 41 |
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
@@ -63,9 +61,9 @@ class ReportSender:
|
|
| 63 |
|
| 64 |
log_history = f" Starting batch loop for {num_urls} report types...\n"
|
| 65 |
if csrf_token:
|
| 66 |
-
log_history += " ℹ️ CSRF Token detected and applied
|
| 67 |
else:
|
| 68 |
-
log_history += " ⚠️ WARNING: Could not find 'tt_csrf_token'
|
| 69 |
|
| 70 |
yield log_history, self.is_running, "Running"
|
| 71 |
total_requests_sent = 0
|
|
@@ -101,7 +99,6 @@ class ReportSender:
|
|
| 101 |
parsed = response.json()
|
| 102 |
status_code_val = parsed.get('status_code', -1)
|
| 103 |
status_code_msg = parsed.get('status_message', 'No Message')
|
| 104 |
-
|
| 105 |
if status_code_val == 0:
|
| 106 |
is_json_success = True
|
| 107 |
except:
|
|
@@ -126,16 +123,14 @@ class ReportSender:
|
|
| 126 |
)
|
| 127 |
|
| 128 |
log_history += log_entry
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
except requests.exceptions.Timeout:
|
| 133 |
-
log_history += f"[{time.strftime('%H:%M:%S')}] ERROR:
|
| 134 |
-
total_requests_sent += 1
|
| 135 |
yield log_history, self.is_running, "Running"
|
| 136 |
except Exception as e:
|
| 137 |
-
log_history += f"[{time.strftime('%H:%M:%S')}]
|
| 138 |
-
total_requests_sent += 1
|
| 139 |
yield log_history, self.is_running, "Running"
|
| 140 |
|
| 141 |
if batch_count != -1:
|
|
@@ -144,13 +139,14 @@ class ReportSender:
|
|
| 144 |
self.stop_event.set()
|
| 145 |
|
| 146 |
self.is_running = False
|
| 147 |
-
log_history += f"\n\n
|
| 148 |
yield log_history, self.is_running, "Stopped"
|
| 149 |
|
| 150 |
def stop_execution(self):
|
| 151 |
"""Sets the event flag to stop the continuous loop."""
|
| 152 |
self.stop_event.set()
|
| 153 |
-
|
|
|
|
| 154 |
|
| 155 |
sender = ReportSender()
|
| 156 |
|
|
@@ -164,26 +160,22 @@ with gr.Blocks() as app:
|
|
| 164 |
gr.Markdown("### 1. Request Context (CRITICAL)")
|
| 165 |
cookie_input = gr.Textbox(
|
| 166 |
label="Full Browser Cookie Header (REQUIRED)",
|
| 167 |
-
placeholder="Paste the ENTIRE 'Cookie: ...' string
|
| 168 |
-
lines=5,
|
| 169 |
-
max_lines=5
|
| 170 |
)
|
| 171 |
|
| 172 |
gr.Markdown("### 2. Report URLs Batch")
|
| 173 |
master_url_batch_input = gr.Textbox(
|
| 174 |
-
label="Master Signed Report URLs
|
| 175 |
-
placeholder="Paste ONE OR MORE FULLY SIGNED
|
| 176 |
-
lines=5,
|
| 177 |
-
max_lines=10
|
| 178 |
)
|
| 179 |
|
| 180 |
gr.Markdown("### 3. Loop Control")
|
| 181 |
with gr.Row(equal_height=False):
|
| 182 |
batch_count_input = gr.Number(
|
| 183 |
-
label="Batch Count (
|
| 184 |
-
|
| 185 |
-
value=-1,
|
| 186 |
-
scale=1
|
| 187 |
)
|
| 188 |
status_box = gr.Textbox(label="Status", value="Stopped", interactive=False, scale=1)
|
| 189 |
|
|
@@ -195,35 +187,35 @@ with gr.Blocks() as app:
|
|
| 195 |
gr.Markdown("### 4. Execution Logs")
|
| 196 |
logs_output = gr.Textbox(
|
| 197 |
show_label=False,
|
| 198 |
-
placeholder="
|
| 199 |
-
lines=20,
|
| 200 |
-
max_lines=20,
|
| 201 |
autoscroll=True,
|
| 202 |
elem_id="log-box"
|
| 203 |
)
|
| 204 |
|
| 205 |
-
send_btn.click(
|
| 206 |
fn=sender.execute_reports_loop,
|
| 207 |
inputs=[master_url_batch_input, cookie_input, batch_count_input, current_status],
|
| 208 |
outputs=[logs_output, is_running_state, status_box],
|
| 209 |
-
).then(
|
| 210 |
-
lambda is_running: [gr.Button(interactive=not is_running), gr.Button(interactive=is_running)],
|
| 211 |
-
inputs=[is_running_state],
|
| 212 |
-
outputs=[send_btn, stop_btn],
|
| 213 |
-
queue=False
|
| 214 |
)
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
stop_btn.click(
|
| 217 |
fn=sender.stop_execution,
|
| 218 |
inputs=[],
|
| 219 |
-
outputs=[
|
|
|
|
| 220 |
queue=False
|
| 221 |
).then(
|
| 222 |
-
lambda: [gr.Button(interactive=True), gr.Button(interactive=False),
|
| 223 |
-
outputs=[send_btn, stop_btn,
|
| 224 |
-
queue=False
|
| 225 |
)
|
| 226 |
-
|
| 227 |
status_box.change(lambda x: x, inputs=status_box, outputs=current_status)
|
| 228 |
|
| 229 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import time
|
|
|
|
|
|
|
| 4 |
import random
|
| 5 |
from urllib.parse import urlparse, parse_qs
|
| 6 |
from threading import Event
|
|
|
|
| 12 |
self.is_running = False
|
| 13 |
|
| 14 |
def execute_reports_loop(self, master_url_batch, cookie_header, batch_count, current_status):
|
| 15 |
+
"""The main continuous execution loop."""
|
| 16 |
+
if self.is_running:
|
| 17 |
+
yield gr.update(), True, "Running"
|
| 18 |
return
|
| 19 |
|
| 20 |
if not master_url_batch or not master_url_batch.strip():
|
| 21 |
+
yield "Error: Report URL Batch is empty.", False, "Stopped"
|
| 22 |
return
|
| 23 |
|
| 24 |
if not cookie_header or not cookie_header.strip():
|
| 25 |
+
yield "Error: Cookie Header is missing.", False, "Stopped"
|
| 26 |
return
|
| 27 |
|
| 28 |
self.stop_event.clear()
|
|
|
|
| 33 |
|
| 34 |
if not master_urls:
|
| 35 |
self.is_running = False
|
| 36 |
+
yield "Error: No valid URLs found.", False, "Stopped"
|
| 37 |
return
|
| 38 |
|
| 39 |
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
|
|
|
|
| 61 |
|
| 62 |
log_history = f" Starting batch loop for {num_urls} report types...\n"
|
| 63 |
if csrf_token:
|
| 64 |
+
log_history += " ℹ️ CSRF Token detected and applied.\n"
|
| 65 |
else:
|
| 66 |
+
log_history += " ⚠️ WARNING: Could not find 'tt_csrf_token'. Requests may fail.\n"
|
| 67 |
|
| 68 |
yield log_history, self.is_running, "Running"
|
| 69 |
total_requests_sent = 0
|
|
|
|
| 99 |
parsed = response.json()
|
| 100 |
status_code_val = parsed.get('status_code', -1)
|
| 101 |
status_code_msg = parsed.get('status_message', 'No Message')
|
|
|
|
| 102 |
if status_code_val == 0:
|
| 103 |
is_json_success = True
|
| 104 |
except:
|
|
|
|
| 123 |
)
|
| 124 |
|
| 125 |
log_history += log_entry
|
| 126 |
+
|
| 127 |
+
yield log_history, self.is_running, "Running"
|
| 128 |
|
| 129 |
except requests.exceptions.Timeout:
|
| 130 |
+
log_history += f"[{time.strftime('%H:%M:%S')}] ERROR: Timeout.\n"
|
|
|
|
| 131 |
yield log_history, self.is_running, "Running"
|
| 132 |
except Exception as e:
|
| 133 |
+
log_history += f"[{time.strftime('%H:%M:%S')}] ERROR: {str(e)}\n"
|
|
|
|
| 134 |
yield log_history, self.is_running, "Running"
|
| 135 |
|
| 136 |
if batch_count != -1:
|
|
|
|
| 139 |
self.stop_event.set()
|
| 140 |
|
| 141 |
self.is_running = False
|
| 142 |
+
log_history += f"\n\n🛑 STOPPED. Total Requests Sent: {total_requests_sent}."
|
| 143 |
yield log_history, self.is_running, "Stopped"
|
| 144 |
|
| 145 |
def stop_execution(self):
|
| 146 |
"""Sets the event flag to stop the continuous loop."""
|
| 147 |
self.stop_event.set()
|
| 148 |
+
self.is_running = False
|
| 149 |
+
return False, "Stopping..."
|
| 150 |
|
| 151 |
sender = ReportSender()
|
| 152 |
|
|
|
|
| 160 |
gr.Markdown("### 1. Request Context (CRITICAL)")
|
| 161 |
cookie_input = gr.Textbox(
|
| 162 |
label="Full Browser Cookie Header (REQUIRED)",
|
| 163 |
+
placeholder="Paste the ENTIRE 'Cookie: ...' string...",
|
| 164 |
+
lines=5, max_lines=5
|
|
|
|
| 165 |
)
|
| 166 |
|
| 167 |
gr.Markdown("### 2. Report URLs Batch")
|
| 168 |
master_url_batch_input = gr.Textbox(
|
| 169 |
+
label="Master Signed Report URLs",
|
| 170 |
+
placeholder="Paste ONE OR MORE FULLY SIGNED URLs...",
|
| 171 |
+
lines=5, max_lines=10
|
|
|
|
| 172 |
)
|
| 173 |
|
| 174 |
gr.Markdown("### 3. Loop Control")
|
| 175 |
with gr.Row(equal_height=False):
|
| 176 |
batch_count_input = gr.Number(
|
| 177 |
+
label="Batch Count (-1 for infinite)",
|
| 178 |
+
value=-1, scale=1
|
|
|
|
|
|
|
| 179 |
)
|
| 180 |
status_box = gr.Textbox(label="Status", value="Stopped", interactive=False, scale=1)
|
| 181 |
|
|
|
|
| 187 |
gr.Markdown("### 4. Execution Logs")
|
| 188 |
logs_output = gr.Textbox(
|
| 189 |
show_label=False,
|
| 190 |
+
placeholder="Logs will appear here...",
|
| 191 |
+
lines=20, max_lines=20,
|
|
|
|
| 192 |
autoscroll=True,
|
| 193 |
elem_id="log-box"
|
| 194 |
)
|
| 195 |
|
| 196 |
+
run_event = send_btn.click(
|
| 197 |
fn=sender.execute_reports_loop,
|
| 198 |
inputs=[master_url_batch_input, cookie_input, batch_count_input, current_status],
|
| 199 |
outputs=[logs_output, is_running_state, status_box],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
+
send_btn.click(
|
| 202 |
+
fn=lambda: [gr.Button(interactive=False), gr.Button(interactive=True)],
|
| 203 |
+
outputs=[send_btn, stop_btn]
|
| 204 |
+
)
|
| 205 |
+
run_event.then(
|
| 206 |
+
fn=lambda: [gr.Button(interactive=True), gr.Button(interactive=False)],
|
| 207 |
+
outputs=[send_btn, stop_btn]
|
| 208 |
+
)
|
| 209 |
stop_btn.click(
|
| 210 |
fn=sender.stop_execution,
|
| 211 |
inputs=[],
|
| 212 |
+
outputs=[is_running_state, status_box],
|
| 213 |
+
cancels=[run_event],
|
| 214 |
queue=False
|
| 215 |
).then(
|
| 216 |
+
fn=lambda: [gr.Button(interactive=True), gr.Button(interactive=False), "Stopped"],
|
| 217 |
+
outputs=[send_btn, stop_btn, status_box]
|
|
|
|
| 218 |
)
|
|
|
|
| 219 |
status_box.change(lambda x: x, inputs=status_box, outputs=current_status)
|
| 220 |
|
| 221 |
if __name__ == "__main__":
|