statmo / app.py
Zhofang's picture
Update app.py
17d73d2 verified
import json
import random
import time
from datetime import datetime
from collections import deque
from flask import Flask, Response, render_template, stream_with_context, make_response
import requests
app = Flask(__name__)
random.seed()
# Rate limiting parameters
MAX_REQUESTS_PER_SECOND = 1500
REQUEST_TIME_WINDOW = 1
# Store timestamps of recent requests
recent_requests = deque()
# Telegram configuration
TELEGRAM_BOT_TOKEN = '7408530224:AAGLPps_bWOHQ7mQDBe-BsXTiaJA8JmYIeo'
TELEGRAM_CHAT_ID = '-1001825626706'
# Initialize a dictionary to store requests per second
requests_per_second = {}
def send_telegram_alert(message):
url = f"https://lol-v2.mxflower.eu.org/api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
data = {"chat_id": TELEGRAM_CHAT_ID, "text": message}
requests.post(url, json=data)
@app.route('/')
def index():
with open("index.html", "r") as f:
html = f.read()
return html
@app.route('/chart-data')
def chart_data():
def generate_random_data():
while True:
current_time = datetime.now().strftime('%M:%S')
if current_time not in requests_per_second:
requests_per_second[current_time] = 0
json_data = json.dumps(
{'time': current_time, 'value': requests_per_second[current_time]}
)
yield f"data:{json_data}\n\n"
time.sleep(1)
requests_per_second[current_time] = 0
response = Response(stream_with_context(generate_random_data()), mimetype="text/event-stream")
response.headers["Cache-Control"] = "no-cache"
response.headers["X-Accel-Buffering"] = "no"
return response
@app.route("/attack")
def attack():
global recent_requests
now = time.time()
current_time = datetime.now().strftime('%M:%S')
# Rate Limiting (Improved)
while recent_requests and now - recent_requests[0] > REQUEST_TIME_WINDOW:
recent_requests.popleft()
if len(recent_requests) >= MAX_REQUESTS_PER_SECOND:
return "Too many requests, please try again later.", 429
recent_requests.append(now)
if current_time in requests_per_second:
requests_per_second[current_time] += 1
else:
requests_per_second[current_time] = 1
if requests_per_second[current_time] == 700:
send_telegram_alert(f"High traffic detected! at https://skylinex.eu.org/ {current_time}")
# Create the response
response = make_response("Your Requests Get Approved and Cached Check https://skylinex.eu.org/")
# Set the desired Link header
response.headers["Link"] = "TELEGRAM VANO_GANZZZ"
return response
if __name__ == '__main__':
app.run(debug=True, threaded=True, host="0.0.0.0", port=7860)