Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
| 1 |
-
import socket
|
| 2 |
-
import requests
|
| 3 |
-
from flask import Flask, render_template_string, request, session, redirect, url_for
|
| 4 |
-
from mcstatus import JavaServer
|
| 5 |
|
| 6 |
-
app = Flask(__name__)
|
| 7 |
-
app.secret_key = "une_cle_tres_secrete"
|
| 8 |
|
| 9 |
-
# --- CONFIGURATION ---
|
| 10 |
-
MAC_ADRESSE = "d4:3d:7e:31:e8:84"
|
| 11 |
-
MON_HOST_NOIP = "cobblev2.redirectme.net"
|
| 12 |
-
MOT_DE_PASSE = "pouletcrousty"
|
| 13 |
-
MC_PORT = 25565
|
| 14 |
-
IMAGE_FOND = "https://images.alphacoders.com/132/1327533.png"
|
| 15 |
|
| 16 |
-
IMAGES_GALERIE
|
|
|
|
| 17 |
"https://i.redd.it/ag4307hy62qe1.jpeg", "https://pbs.twimg.com/profile_images/1627794683362480129/3xUrVnUY_400x400.jpg",
|
| 18 |
"https://sativa.fr/wp-content/uploads/SnoopDogg.jpg", "https://media.zenfs.com/fr_FR/News/Gameblog/kate-upton-gta-v.jpg",
|
| 19 |
"https://i1.sndcdn.com/artworks-000148945005-hx6vn7-t1080x1080.jpg", "https://www.shutterstock.com/image-illustration/internet-meme-stupid-troll-face-260nw-201587906.jpg",
|
|
@@ -32,24 +33,25 @@ IMAGES_GALERIE = [
|
|
| 32 |
"https://www.radiofrance.fr/s3/cruiser-production/2019/10/2ccb44bb-6211-4340-b063-4d7a015575d4/1200x680_kaaris-or-noir.jpg_or_noir.jpg",
|
| 33 |
"https://i.ebayimg.com/images/g/jagAAOxyu1BTj-fx/s-l1200.jpg", "https://www.radiofrance.fr/s3/cruiser-production-eu3/2019/06/d12bbc34-45f9-4b03-b762-25ae9988b888/640x340_gettyimages-624736982.jpg",
|
| 34 |
"https://upload.wikimedia.org/wikipedia/fr/b/b2/Minecraft%2C_le_film.png",
|
| 35 |
-
]
|
| 36 |
|
| 37 |
-
def get_server_status():
|
| 38 |
-
try:
|
| 39 |
-
server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}")
|
| 40 |
-
status = server.status()
|
| 41 |
-
ping = round(status.latency, 1)
|
| 42 |
-
info = f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})"
|
| 43 |
-
sub_info = f"<br><small style='color:#aaa'>Ping: {ping}ms</small>"
|
| 44 |
-
return info + sub_info, "#00ff00"
|
| 45 |
-
except:
|
| 46 |
-
try:
|
| 47 |
-
ip = socket.gethostbyname(MON_HOST_NOIP)
|
| 48 |
-
with socket.create_connection((ip, MC_PORT), timeout=1):
|
| 49 |
-
return "DÉMARRAGE... 🟡", "#fbbf24"
|
| 50 |
-
except:
|
| 51 |
-
return "HORS LIGNE 🔴", "#ff4444"
|
| 52 |
|
|
|
|
| 53 |
HTML_TEMPLATE = '''
|
| 54 |
<!DOCTYPE html>
|
| 55 |
<html>
|
|
@@ -131,36 +133,36 @@ HTML_TEMPLATE = '''
|
|
| 131 |
</html>
|
| 132 |
'''
|
| 133 |
|
| 134 |
-
@app.route('/')
|
| 135 |
-
def index():
|
| 136 |
-
status_text, status_color = get_server_status()
|
| 137 |
-
return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'),
|
| 138 |
-
status_text=status_text, status_color=status_color,
|
| 139 |
-
bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, show_snake=False)
|
| 140 |
|
| 141 |
-
@app.route('/login', methods=['POST'])
|
| 142 |
-
def login():
|
| 143 |
-
if request.form.get('password') == MOT_DE_PASSE: session['auth'] = True
|
| 144 |
-
return redirect('/')
|
| 145 |
|
| 146 |
-
@app.route('/wake', methods=['POST'])
|
| 147 |
-
def wake():
|
| 148 |
-
if not session.get('auth'): return redirect('/')
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
except Exception as e:
|
| 158 |
-
msg = "Le relais n'a pas répondu, mais le PC se réveille peut-être."
|
| 159 |
-
|
| 160 |
-
status_text, status_color = get_server_status()
|
| 161 |
-
return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
|
| 162 |
-
status_color=status_color, bg_image=IMAGE_FOND,
|
| 163 |
-
galerie=IMAGES_GALERIE, show_snake=True, message=msg)
|
| 164 |
|
| 165 |
-
if __name__ == "__main__":
|
| 166 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
+
import socket
|
| 2 |
+
import requests
|
| 3 |
+
from flask import Flask, render_template_string, request, session, redirect, url_for
|
| 4 |
+
from mcstatus import JavaServer
|
| 5 |
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
app.secret_key = "une_cle_tres_secrete"
|
| 8 |
|
| 9 |
+
# --- CONFIGURATION ---
|
| 10 |
+
MAC_ADRESSE = "d4:3d:7e:31:e8:84"
|
| 11 |
+
MON_HOST_NOIP = "cobblev2.redirectme.net"
|
| 12 |
+
MOT_DE_PASSE = "pouletcrousty"
|
| 13 |
+
MC_PORT = 25565
|
| 14 |
+
IMAGE_FOND = "https://images.alphacoders.com/132/1327533.png"
|
| 15 |
|
| 16 |
+
# ... (IMAGES_GALERIE et get_server_status restent identiques)
|
| 17 |
+
IMAGES_GALERIE = [
|
| 18 |
"https://i.redd.it/ag4307hy62qe1.jpeg", "https://pbs.twimg.com/profile_images/1627794683362480129/3xUrVnUY_400x400.jpg",
|
| 19 |
"https://sativa.fr/wp-content/uploads/SnoopDogg.jpg", "https://media.zenfs.com/fr_FR/News/Gameblog/kate-upton-gta-v.jpg",
|
| 20 |
"https://i1.sndcdn.com/artworks-000148945005-hx6vn7-t1080x1080.jpg", "https://www.shutterstock.com/image-illustration/internet-meme-stupid-troll-face-260nw-201587906.jpg",
|
|
|
|
| 33 |
"https://www.radiofrance.fr/s3/cruiser-production/2019/10/2ccb44bb-6211-4340-b063-4d7a015575d4/1200x680_kaaris-or-noir.jpg_or_noir.jpg",
|
| 34 |
"https://i.ebayimg.com/images/g/jagAAOxyu1BTj-fx/s-l1200.jpg", "https://www.radiofrance.fr/s3/cruiser-production-eu3/2019/06/d12bbc34-45f9-4b03-b762-25ae9988b888/640x340_gettyimages-624736982.jpg",
|
| 35 |
"https://upload.wikimedia.org/wikipedia/fr/b/b2/Minecraft%2C_le_film.png",
|
| 36 |
+
]
|
| 37 |
|
| 38 |
+
def get_server_status():
|
| 39 |
+
try:
|
| 40 |
+
server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}")
|
| 41 |
+
status = server.status()
|
| 42 |
+
ping = round(status.latency, 1)
|
| 43 |
+
info = f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})"
|
| 44 |
+
sub_info = f"<br><small style='color:#aaa'>Ping: {ping}ms</small>"
|
| 45 |
+
return info + sub_info, "#00ff00"
|
| 46 |
+
except:
|
| 47 |
+
try:
|
| 48 |
+
ip = socket.gethostbyname(MON_HOST_NOIP)
|
| 49 |
+
with socket.create_connection((ip, MC_PORT), timeout=1):
|
| 50 |
+
return "DÉMARRAGE... 🟡", "#fbbf24"
|
| 51 |
+
except:
|
| 52 |
+
return "HORS LIGNE 🔴", "#ff4444"
|
| 53 |
|
| 54 |
+
# ... (HTML_TEMPLATE reste identique)
|
| 55 |
HTML_TEMPLATE = '''
|
| 56 |
<!DOCTYPE html>
|
| 57 |
<html>
|
|
|
|
| 133 |
</html>
|
| 134 |
'''
|
| 135 |
|
| 136 |
+
@app.route('/')
|
| 137 |
+
def index():
|
| 138 |
+
status_text, status_color = get_server_status()
|
| 139 |
+
return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'),
|
| 140 |
+
status_text=status_text, status_color=status_color,
|
| 141 |
+
bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, show_snake=False)
|
| 142 |
|
| 143 |
+
@app.route('/login', methods=['POST'])
|
| 144 |
+
def login():
|
| 145 |
+
if request.form.get('password') == MOT_DE_PASSE: session['auth'] = True
|
| 146 |
+
return redirect('/')
|
| 147 |
|
| 148 |
+
@app.route('/wake', methods=['POST'])
|
| 149 |
+
def wake():
|
| 150 |
+
if not session.get('auth'): return redirect('/')
|
| 151 |
|
| 152 |
+
mac = MAC_ADRESSE.replace(':', '')
|
| 153 |
+
try:
|
| 154 |
+
target_ip = socket.gethostbyname(MON_HOST_NOIP)
|
| 155 |
+
# Utilisation de Depicus, service de WOL très robuste
|
| 156 |
+
depicus_url = f"https://www.depicus.com/wake-on-lan/woli?m={mac}&i={target_ip}&s=255.255.255.255&p=9"
|
| 157 |
+
requests.get(depicus_url, headers={'User-Agent': 'Mozilla/5.0'}, timeout=10)
|
| 158 |
+
msg = "🚀 Signal envoyé ! Le PC devrait s'allumer."
|
| 159 |
+
except Exception as e:
|
| 160 |
+
msg = f"Erreur : {str(e)}"
|
| 161 |
|
| 162 |
+
status_text, status_color = get_server_status()
|
| 163 |
+
return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
|
| 164 |
+
status_color=status_color, bg_image=IMAGE_FOND,
|
| 165 |
+
galerie=IMAGES_GALERIE, show_snake=True, message=msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
+
if __name__ == "__main__":
|
| 168 |
app.run(host='0.0.0.0', port=7860)
|