tonyrulez

Gemini - Sleep PC server pyw

Apr 21st, 2026
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. import http.server
  2. import socketserver
  3. import os
  4. import threading
  5. import time
  6.  
  7. # Ezen a porton fog futni a szerver.
  8. PORT = 8888
  9.  
  10. class SleepHandler(http.server.BaseHTTPRequestHandler):
  11.     def log_message(self, format, *args):
  12.         pass
  13.     def do_GET(self):
  14.         if self.path == '/':
  15.             self.send_response(200)
  16.             self.send_header("Content-type", "text/html; charset=utf-8")
  17.             self.end_headers()
  18.            
  19.             # Módosított HTML: nincs confirm(), nincs alert()
  20.             html = """
  21.            <!DOCTYPE html>
  22.            <html>
  23.            <head>
  24.                <meta name="viewport" content="width=device-width, initial-scale=1.0">
  25.                <title>PC Alvás</title>
  26.                <style>
  27.                    body {
  28.                        font-family: sans-serif;
  29.                        display: flex;
  30.                        justify-content: center;
  31.                        align-items: center;
  32.                        height: 100vh;
  33.                        margin: 0;
  34.                        background-color: #121212;
  35.                        color: white;
  36.                    }
  37.                    .sleep-btn {
  38.                        width: 80%;
  39.                        height: 200px;
  40.                        font-size: 30px;
  41.                        font-weight: bold;
  42.                        background-color: #d32f2f;
  43.                        color: white;
  44.                        border: none;
  45.                        border-radius: 30px;
  46.                        box-shadow: 0 10px 20px rgba(0,0,0,0.5);
  47.                        cursor: pointer;
  48.                        -webkit-tap-highlight-color: transparent;
  49.                    }
  50.                    .sleep-btn:active {
  51.                        background-color: #b71c1c;
  52.                        transform: scale(0.98);
  53.                    }
  54.                </style>
  55.            </head>
  56.            <body>
  57.                <button class="sleep-btn" onclick="sleepPC()">ALVÁS</button>
  58.  
  59.                <script>
  60.                    function sleepPC() {
  61.                        // Azonnali küldés visszajelzés nélkül
  62.                        fetch('/sleep');
  63.                        
  64.                        // Opcionális: Vizuális visszajelzés a gombon, hogy tudd, megnyomtad
  65.                        document.querySelector('.sleep-btn').innerText = 'KIKAPCSOLÁS...';
  66.                        document.querySelector('.sleep-btn').style.backgroundColor = '#444';
  67.                    }
  68.                </script>
  69.            </body>
  70.            </html>
  71.            """
  72.             self.wfile.write(html.encode("utf-8"))
  73.            
  74.         elif self.path == '/sleep':
  75.             self.send_response(200)
  76.             self.send_header("Content-type", "text/plain")
  77.             self.end_headers()
  78.             self.wfile.write(b"OK")
  79.            
  80.             def suspend_system():
  81.                 time.sleep(0.5) # Rövid várakozás, hogy a hálózati kérés lefusson
  82.                 os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
  83.                
  84.             threading.Thread(target=suspend_system).start()
  85.  
  86. # A print() sorokat eltávolítottuk, mert a pythonw összeomlik tőlük!
  87. with socketserver.TCPServer(("0.0.0.0", PORT), SleepHandler) as httpd:
  88.     httpd.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment