that_one_nigga_you_k

backend que tem foto e controle (sem ID)

May 15th, 2025
69
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.07 KB | None | 0 0
  1. from http.server import BaseHTTPRequestHandler, HTTPServer
  2. import urllib
  3.  
  4. # Estado dos LEDs por ID
  5. esp_led_states = {}
  6.  
  7. class SimpleHandler(BaseHTTPRequestHandler):
  8.  
  9.     # Armazena a última imagem recebida
  10.     last_image = None
  11.  
  12.     def do_GET(self):
  13.         parsed_path = urllib.parse.urlparse(self.path)
  14.         path = parsed_path.path
  15.         query_components = urllib.parse.parse_qs(parsed_path.query)
  16.         esp_id = query_components.get("id", [None])[0]
  17.        
  18.         #global esp_led_states
  19.         # agora você pode acessar/modificar esp_led_states
  20.  
  21.         if path == "/led_status":
  22.             if not esp_id:
  23.                 self.send_error(400, "ID do ESP ausente na query string (?id=ESP_ID)")
  24.                 return
  25.  
  26.             # Verificando se a requisição é para alternar o LED
  27.             toggle = query_components.get("toggle", [None])[0]  # 'toggle' vai alternar o estado
  28.             if toggle == "true":
  29.                 current_state = esp_led_states.get(esp_id, False)  # Padrão para False se ID não conhecido
  30.                 new_state = not current_state  # Alterna o estado
  31.                 esp_led_states[esp_id] = new_state  # Atualiza o estado do LED
  32.                 print(f"[GET /led_status] ID: {esp_id}, Novo estado do LED: {new_state}")
  33.                 response_message = "LED acionado" if new_state else "LED desligado"
  34.             else:
  35.                 current_state = esp_led_states.get(esp_id, False)  # Padrão para False se ID não conhecido
  36.                 response_message = "True" if current_state else "False"
  37.            
  38.             self.send_response(200)
  39.             self.send_header("Content-Type", "text/plain")
  40.             self.end_headers()
  41.             self.wfile.write(response_message.encode())  # Converte para bytes
  42.             print(f"[GET /led_status] ID: {esp_id}, Estado enviado: {response_message}")
  43.  
  44.         elif path == "/photos/latest":
  45.             if SimpleHandler.last_image:
  46.                 self.send_response(200)
  47.                 self.send_header("Content-Type", "image/jpeg")
  48.                 self.end_headers()
  49.                 self.wfile.write(SimpleHandler.last_image)
  50.             else:
  51.                 self.send_error(404, "Imagem não encontrada")
  52.  
  53.         elif path == "/":
  54.             self.send_response(200)
  55.             self.send_header("Content-type", "text/html")
  56.             self.end_headers()
  57.             html_content = """
  58.                <html>
  59.                <head>
  60.                    <title>Servidor ESP32-CAM</title>
  61.                    <script>
  62.                        function toggleLed(espId) {
  63.                            fetch(`/toggle_led?id=${espId}`, { method: "POST" })
  64.                                .then(() => {
  65.                                    fetch(`/led_status?id=${espId}`)
  66.                                        .then(response => response.text())
  67.                                        .then(state => {
  68.                                            const newState = (state === "True") ? "ON" : "OFF";
  69.                                            document.getElementById("led-state").innerText = newState;
  70.                                        });
  71.                                })
  72.                                .catch(error => alert("Erro ao alternar o LED"));
  73.                        }
  74.  
  75.                        function fetchLatestPhoto(espId) {
  76.                            const timestamp = Date.now();  // Para evitar cache
  77.                            const imageUrl = `/photos/latest?id=${espId}&nocache=${timestamp}`;
  78.                            document.getElementById("latest-photo").src = imageUrl;
  79.                        }
  80.  
  81.                        setInterval(function () {
  82.                            fetchLatestPhoto("esp01");
  83.                        }, 5000);
  84.                    </script>
  85.                </head>
  86.                <body>
  87.                    <h1>Servidor Python para ESP32-CAM Ativo</h1>
  88.                    <p>Estado do LED (ID: ESP1): <span id="led-state">OFF</span></p>
  89.                    <button onclick="toggleLed('esp01')">Alternar LED</button>
  90.                    <h2>Última Foto</h2>
  91.                    <img id="latest-photo" src="" alt="Última foto do ESP" width="300"/>
  92.                </body>
  93.                </html>
  94.            """
  95.             self.wfile.write(html_content.encode())
  96.        
  97.         else:
  98.             self.send_error(404, f"Endpoint GET não encontrado: {path}")
  99.  
  100.     def do_POST(self):
  101.         parsed_path = urllib.parse.urlparse(self.path)
  102.         path = parsed_path.path
  103.         query_components = urllib.parse.parse_qs(parsed_path.query)
  104.         esp_id = query_components.get("id", [None])[0]
  105.  
  106.         if path == "/upload_image":
  107.             content_length = int(self.headers['Content-Length'])
  108.             post_data = self.rfile.read(content_length)
  109.  
  110.             SimpleHandler.last_image = post_data
  111.             self.send_response(200)
  112.             self.send_header("Content-Type", "text/plain")
  113.             self.end_headers()
  114.             self.wfile.write(b"Imagem recebida com sucesso")
  115.             print(f"[POST /upload_image] Imagem recebida, tamanho: {len(post_data)} bytes")
  116.  
  117.         elif path == "/toggle_led":
  118.             if not esp_id:
  119.                 self.send_error(400, "ID do ESP ausente")
  120.                 return
  121.  
  122.             current = esp_led_states.get(esp_id, False)
  123.             esp_led_states[esp_id] = not current
  124.             print(f"[POST /toggle_led] ID: {esp_id}, Novo estado: {esp_led_states[esp_id]}")
  125.  
  126.             self.send_response(200)
  127.             self.send_header("Content-Type", "text/plain")
  128.             self.end_headers()
  129.             self.wfile.write(b"OK")
  130.        
  131.         else:
  132.             self.send_error(404, f"Endpoint POST não encontrado: {path}")
  133.  
  134. # Configuração do servidor
  135. def run(server_class=HTTPServer, handler_class=SimpleHandler, port=8000):
  136.     server_address = ('', port)
  137.     httpd = server_class(server_address, handler_class)
  138.     print(f"Servidor rodando na porta {port}")
  139.     httpd.serve_forever()
  140.  
  141. if __name__ == "__main__":
  142.     run()
  143.  
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Halkexig
    38 days
    # CSS 0.44 KB | 0 0
    1. Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1Cz5fHkwyaApTWwqfgBBtpvConU8Lo_qJ9xtn7RazWpk/edit?usp=sharing
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • Nokgalgu
    13 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=kwxmrabvet
    4.  
    5. This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment