Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import http.server
- import socketserver
- import os
- import threading
- import time
- # Ezen a porton fog futni a szerver.
- PORT = 8888
- class SleepHandler(http.server.BaseHTTPRequestHandler):
- def log_message(self, format, *args):
- pass
- def do_GET(self):
- if self.path == '/':
- self.send_response(200)
- self.send_header("Content-type", "text/html; charset=utf-8")
- self.end_headers()
- # Módosított HTML: nincs confirm(), nincs alert()
- html = """
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>PC Alvás</title>
- <style>
- body {
- font-family: sans-serif;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- margin: 0;
- background-color: #121212;
- color: white;
- }
- .sleep-btn {
- width: 80%;
- height: 200px;
- font-size: 30px;
- font-weight: bold;
- background-color: #d32f2f;
- color: white;
- border: none;
- border-radius: 30px;
- box-shadow: 0 10px 20px rgba(0,0,0,0.5);
- cursor: pointer;
- -webkit-tap-highlight-color: transparent;
- }
- .sleep-btn:active {
- background-color: #b71c1c;
- transform: scale(0.98);
- }
- </style>
- </head>
- <body>
- <button class="sleep-btn" onclick="sleepPC()">ALVÁS</button>
- <script>
- function sleepPC() {
- // Azonnali küldés visszajelzés nélkül
- fetch('/sleep');
- // Opcionális: Vizuális visszajelzés a gombon, hogy tudd, megnyomtad
- document.querySelector('.sleep-btn').innerText = 'KIKAPCSOLÁS...';
- document.querySelector('.sleep-btn').style.backgroundColor = '#444';
- }
- </script>
- </body>
- </html>
- """
- self.wfile.write(html.encode("utf-8"))
- elif self.path == '/sleep':
- self.send_response(200)
- self.send_header("Content-type", "text/plain")
- self.end_headers()
- self.wfile.write(b"OK")
- def suspend_system():
- time.sleep(0.5) # Rövid várakozás, hogy a hálózati kérés lefusson
- os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
- threading.Thread(target=suspend_system).start()
- # A print() sorokat eltávolítottuk, mert a pythonw összeomlik tőlük!
- with socketserver.TCPServer(("0.0.0.0", PORT), SleepHandler) as httpd:
- httpd.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment