untitled1176 commited on
Commit
7ccc57f
·
verified ·
1 Parent(s): 581b0ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +149 -145
app.py CHANGED
@@ -1,159 +1,163 @@
1
- import socket
2
- from flask import Flask, render_template_string, request, session, redirect, url_for
3
- from wakeonlan import send_magic_packet
4
  from mcstatus import JavaServer
5
 
6
- app = Flask(__name__)
7
- app.secret_key = "une_cle_tres_secrete"
8
 
9
- app.config.update(
10
- SESSION_COOKIE_SAMESITE='None',
11
- SESSION_COOKIE_SECURE=True
12
- )
 
 
13
 
14
- # --- CONFIGURATION ---
15
- MAC_ADRESSE = "d4:3d:7e:31:e8:84"
16
- MON_HOST_NOIP = "cobblev2.redirectme.net"
17
- MOT_DE_PASSE = "pouletcrousty"
18
- MC_PORT = 25565
19
- IMAGE_FOND = "https://images.alphacoders.com/132/1327533.png"
20
-
21
- IMAGES_GALERIE = [
22
- "https://i.redd.it/ag4307hy62qe1.jpeg", "https://pbs.twimg.com/profile_images/1627794683362480129/3xUrVnUY_400x400.jpg",
23
- "https://sativa.fr/wp-content/uploads/SnoopDogg.jpg", "https://media.zenfs.com/fr_FR/News/Gameblog/kate-upton-gta-v.jpg",
24
- "https://i1.sndcdn.com/artworks-000148945005-hx6vn7-t1080x1080.jpg", "https://www.shutterstock.com/image-illustration/internet-meme-stupid-troll-face-260nw-201587906.jpg",
25
- "https://www.lycee3vallees.fr/wp-content/uploads/2024/08/Logo-Pole-emploi.png", "https://img.freepik.com/photos-gratuite/belle-photo-chaton-british-shorthair-blanc_181624-57681.jpg",
26
  "https://img.freepik.com/photos-premium/mignon-petit-chaton-britannique-bleu-gris-dormant-enveloppe-dans-couverture-carreaux-blanche-concept-adorables-animaux-compagnie_106368-4291.jpg",
27
- "https://images.eatself.com/811/38179_10273994.png", "https://miro.medium.com/0*Ug2qG0Ph4JkU5pEZ.png",
28
- "https://storage.googleapis.com/pod_public/1300/245798.jpg", "https://www.nextplz.fr/wp-content/uploads/nextplz/2018/05/18068280901060695.jpg",
29
- "https://passed.fr/wp-content/uploads/2019/12/Zidane-1.jpg", "https://i.kym-cdn.com/entries/icons/original/000/038/806/tco_-_2021-11-10T112501.292.jpg",
30
- "https://thumbs.dreamstime.com/z/homme-chinois-asiatique-d-affaires-7045702.jpg", "https://c8.alamy.com/compfr/b332ew/un-chinois-d-une-vingtaine-d-annees-avec-un-grand-sourire-b332ew.jpg",
31
- "https://www.toutpourvosfetes.fr/30551-large_default/moustache-et-barbe-chinois.jpg", "https://thumbs.dreamstime.com/b/nain-petit-homme-4339718.jpg",
32
- "https://pbs.twimg.com/media/GaecrTvaEAAreDl.jpg", "https://i.pinimg.com/736x/7f/a7/84/7fa78427092842091603dfcff6f849ca.jpg",
33
- "https://retrogems.fr/wp-content/uploads/2025/12/asterion-copine-virale.jpg", "https://tribunedelyon.fr/wp-content/uploads/sites/5/2025/10/khalamite-pierre-ferrandis-10.jpg",
34
- "https://media.tenor.com/JzOOJNV1gZUAAAAe/antoine-daniel-wtc.png", "https://www.pokepedia.fr/images/thumb/0/03/Lockpin-DP.png/800px-Lockpin-DP.png",
35
- "https://i.pinimg.com/736x/8a/42/d2/8a42d20954675f8f5bcb931f2560d380.jpg", "https://www.clipartmax.com/png/middle/166-1665846_pikachu-meets-minecraft-by-drpoochew-pikachu-face-meme-png.png",
36
- "https://www.picclickimg.com/ekoAAOSwrBBjrwRk/Flag-Palestine-Drapeau-Palestine-ecusson-brodu00e9-patche-thermocollant.webp",
37
  "https://www.radiofrance.fr/s3/cruiser-production/2019/10/2ccb44bb-6211-4340-b063-4d7a015575d4/1200x680_kaaris-or-noir.jpg_or_noir.jpg",
38
- "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",
39
- "https://upload.wikimedia.org/wikipedia/fr/b/b2/Minecraft%2C_le_film.png",
40
- ]
41
-
42
- def get_server_status():
43
- try:
44
- server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}")
45
- status = server.status()
46
- return f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})", "#00ff00"
47
- except:
48
- try:
49
- socket.create_connection((socket.gethostbyname(MON_HOST_NOIP), MC_PORT), timeout=1)
50
- return "DÉMARRAGE... 🟡", "#fbbf24"
51
- except:
52
- return "HORS LIGNE 🔴", "#ff4444"
53
-
54
- HTML_TEMPLATE = '''
55
- <!DOCTYPE html>
56
- <html>
57
- <head>
58
- <title>Cobblemon Dashboard</title>
59
- <style>
60
- body { background: url("{{ bg_image }}") no-repeat center center fixed; background-size: cover; font-family: 'Segoe UI', sans-serif; color: white; margin: 0; overflow: hidden; display: flex; justify-content: center; align-items: center; height: 100vh; }
61
- .galerie-background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
62
- .sticker { position: absolute; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); max-width: 200px; }
63
- .container { background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(15px); padding: 30px; border-radius: 30px; text-align: center; z-index: 10; border: 1px solid rgba(255,255,255,0.1); width: 90%; max-width: 400px; max-height: 90vh; overflow-y: auto; }
64
- .status-msg { margin: 15px 0; font-size: 1.1em; }
65
- .btn-wake { padding: 15px 30px; cursor: pointer; border-radius: 15px; border: none; background: #059669; color: white; font-weight: bold; transition: 0.2s; }
66
- .btn-wake:hover { transform: scale(1.05); }
67
- .confirmation { color: #fbbf24; background: rgba(251, 191, 36, 0.1); padding: 8px; border-radius: 10px; margin-bottom: 10px; border: 1px solid #fbbf24; font-size: 0.85em; }
68
- #snakeGame { border: 2px solid #2563eb; background: #000; margin-top: 15px; border-radius: 10px; width: 250px; height: 250px; }
69
- </style>
70
- </head>
71
- <body>
72
- <div class="galerie-background">
73
- {% for img_url in galerie %} <img src="{{ img_url }}" class="sticker"> {% endfor %}
74
- </div>
75
 
76
- <div class="container">
77
- <h2>Cobblemon V2</h2>
78
- {% if message %}<div class="confirmation">⚡ {{ message }}</div>{% endif %}
79
- <div class="status-msg">Statut : <strong style="color: {{ status_color }};">{{ status_text|safe }}</strong></div>
 
 
 
 
 
 
 
 
 
 
 
80
 
81
- {% if not logged_in %}
82
- <form method="post" action="/login">
83
- <input type="password" name="password" placeholder="Mot de passe" style="padding:10px; border-radius:8px; width: 70%;"><br><br>
84
- <button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION</button>
85
- </form>
86
- {% else %}
87
- {% if not show_snake %}
88
- <form action="/wake" method="post"><button type="submit" class="btn-wake">🚀 ALLUMER SERVEUR</button></form>
89
- {% else %}
90
- <canvas id="snakeGame" width="300" height="300"></canvas>
91
- <p style="font-size: 0.7em;">Touche un mur pour actualiser !</p>
92
- <script>
93
- const canvas = document.getElementById("snakeGame"); const ctx = canvas.getContext("2d");
94
- let snake = [{x:10, y:10}]; let food = {x:5, y:5}; let dx=0, dy=0;
95
- document.addEventListener("keydown", e => {
96
- if(e.key==="ArrowUp" && dy===0) {dx=0; dy=-1;} if(e.key==="ArrowDown" && dy===0) {dx=0; dy=1;}
97
- if(e.key==="ArrowLeft" && dx===0) {dx=-1; dy=0;} if(e.key==="ArrowRight" && dx===0) {dx=1; dy=0;}
98
- });
99
- function draw() {
100
- let head = {x: snake[0].x + dx, y: snake[0].y + dy};
101
- if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) { location.reload(); return; }
102
- for(let i=1; i<snake.length; i++) { if(head.x === snake[i].x && head.y === snake[i].y) { location.reload(); return; } }
103
- snake.unshift(head);
104
- if(head.x===food.x && head.y===food.y) { food = {x:Math.floor(Math.random()*15), y:Math.floor(Math.random()*15)}; } else { snake.pop(); }
105
- ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
106
- ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
107
- ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
108
- setTimeout(draw, 100);
109
- } draw();
110
- </script>
111
- {% endif %}
112
- <p><a href="/" style="color: #aaa; text-decoration: none; font-size: 0.8em; display: block; margin-top: 15px;">🔄 ACTUALISER</a></p>
113
- {% endif %}
114
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- <script>
117
- const stickers = document.querySelectorAll('.sticker');
118
- const cols = 6; const rows = 6; let cells = [];
119
- for(let i=0; i<cols; i++) { for(let j=0; j<rows; j++) { cells.push({x: i * (100/cols), y: j * (100/rows)}); } }
120
- cells.sort(() => Math.random() - 0.5);
121
- stickers.forEach((s, i) => { if(cells[i]) {
122
- s.style.left = (cells[i].x + (Math.random() * 5)) + "%";
123
- s.style.top = (cells[i].y + (Math.random() * 5)) + "%";
124
- s.style.transform = "rotate(" + (Math.floor(Math.random() * 30) - 15) + "deg)";
125
- }});
126
- </script>
127
- </body>
128
- </html>
129
- '''
130
 
131
- @app.route('/')
132
- def index():
133
- status_text, status_color = get_server_status()
134
- msg = session.pop('msg', None)
135
- snake = session.pop('snake', False)
136
- return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'), status_text=status_text, status_color=status_color, bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, message=msg, show_snake=snake)
137
 
138
- @app.route('/login', methods=['POST'])
139
- def login():
140
- if request.form.get('password') == MOT_DE_PASSE: session['auth'] = True
141
- return redirect(url_for('index'))
142
-
143
- @app.route('/wake', methods=['POST'])
144
- def wake():
145
- if not session.get('auth'): return redirect(url_for('index'))
146
- try:
147
- target_ip = socket.gethostbyname(MON_HOST_NOIP)
148
- # Envoi en broadcast local ET vers l'IP publique
149
- send_magic_packet(MAC_ADRESSE, ip_address="255.255.255.255", port=9)
150
  send_magic_packet(MAC_ADRESSE, ip_address=target_ip, port=9)
151
-
152
- session['msg'] = "Paquet envoyé ! Joue pour actualiser."
153
- session['snake'] = True
154
- except Exception as e:
155
- session['msg'] = f"Erreur : {str(e)}"
156
- return redirect(url_for('index'))
 
 
 
 
157
 
158
- if __name__ == "__main__":
159
  app.run(host='0.0.0.0', port=7860)
 
1
+ import socket
2
+ from flask import Flask, render_template_string, request, session, redirect, url_for
3
+ from wakeonlan import send_magic_packet
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",
18
+ "https://pbs.twimg.com/profile_images/1627794683362480129/3xUrVnUY_400x400.jpg",
19
+ "https://sativa.fr/wp-content/uploads/SnoopDogg.jpg",
20
+ "https://s.yimg.com/ny/api/res/1.2/7OIT.QOoe256UkTdaHDxIw--/YXBwaWQ9aGlnaGxhbmRlcjt3PTk2MDtoPTQwMDtjZj13ZWJw/https://media.zenfs.com/fr_FR/News/Gameblog/kate-upton-gta-v.jpg",
21
+ "https://i1.sndcdn.com/artworks-000148945005-hx6vn7-t1080x1080.jpg",
22
+ "https://www.shutterstock.com/image-illustration/internet-meme-stupid-troll-face-260nw-201587906.jpg",
23
+ "https://www.lycee3vallees.fr/wp-content/uploads/2024/08/Logo-Pole-emploi.png",
24
+ "https://img.freepik.com/photos-gratuite/belle-photo-chaton-british-shorthair-blanc_181624-57681.jpg",
 
 
 
25
  "https://img.freepik.com/photos-premium/mignon-petit-chaton-britannique-bleu-gris-dormant-enveloppe-dans-couverture-carreaux-blanche-concept-adorables-animaux-compagnie_106368-4291.jpg",
26
+ "https://images.eatself.com/811/38179_10273994.png",
27
+ "https://miro.medium.com/0*Ug2qG0Ph4JkU5pEZ.png",
 
 
 
 
 
 
 
 
28
  "https://www.radiofrance.fr/s3/cruiser-production/2019/10/2ccb44bb-6211-4340-b063-4d7a015575d4/1200x680_kaaris-or-noir.jpg_or_noir.jpg",
29
+ "https://i.ebayimg.com/images/g/jagAAOxyu1BTj-fx/s-l1200.jpg",
30
+ "https://www.radiofrance.fr/s3/cruiser-production-eu3/2019/06/d12bbc34-45f9-4b03-b762-25ae9988b888/640x340_gettyimages-624736982.jpg",
31
+ "https://upload.wikimedia.org/wikipedia/fr/b/b2/Minecraft%2C_le_film.png",
32
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ def get_server_status():
35
+ try:
36
+ server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}")
37
+ status = server.status()
38
+ ping = round(status.latency, 1)
39
+ info = f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})"
40
+ sub_info = f"<br><small style='color:#aaa'>Ping: {ping}ms</small>"
41
+ return info + sub_info, "#00ff00"
42
+ except:
43
+ try:
44
+ ip = socket.gethostbyname(MON_HOST_NOIP)
45
+ with socket.create_connection((ip, MC_PORT), timeout=1):
46
+ return "DÉMARRAGE... 🟡", "#fbbf24"
47
+ except:
48
+ return "HORS LIGNE 🔴", "#ff4444"
49
 
50
+ HTML_TEMPLATE = '''
51
+ <!DOCTYPE html>
52
+ <html>
53
+ <head>
54
+ <title>Cobblemon Dashboard</title>
55
+ <style>
56
+ body { background: url("{{ bg_image }}") no-repeat center center fixed; background-size: cover; font-family: 'Segoe UI', sans-serif; color: white; margin: 0; overflow: hidden; display: flex; justify-content: center; align-items: center; height: 100vh; }
57
+ .galerie-background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
58
+ .sticker { position: absolute; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); pointer-events: auto; transition: transform 0.3s ease; max-width: 150px; }
59
+ .container { background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(15px); padding: 40px; border-radius: 30px; text-align: center; z-index: 10; border: 1px solid rgba(255,255,255,0.1); width: 90%; max-width: 400px; }
60
+ .status-msg { margin: 20px 0; font-size: 1.2em; line-height: 1.4; }
61
+ .btn-wake { padding: 18px 36px; cursor: pointer; border-radius: 15px; border: none; background: #059669; color: white; font-weight: bold; font-size: 1.1em; transition: transform 0.2s, background 0.2s; }
62
+ .btn-wake:hover { transform: scale(1.05); background: #10b981; }
63
+ .confirmation { color: #fbbf24; background: rgba(251, 191, 36, 0.1); padding: 10px; border-radius: 10px; margin-bottom: 15px; border: 1px solid #fbbf24; }
64
+ #snakeGame { border: 2px solid #2563eb; background: #000; margin-top: 20px; border-radius: 10px; }
65
+ .keys { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
66
+ .key { background: rgba(255,255,255,0.2); padding: 5px 12px; border-radius: 5px; border-bottom: 3px solid white; font-weight: bold; }
67
+ </style>
68
+ </head>
69
+ <body>
70
+ <div class="galerie-background">
71
+ {% for img_url in galerie %} <img src="{{ img_url }}" class="sticker"> {% endfor %}
72
+ </div>
73
+ <div class="container">
74
+ <h1>Cobblemon V2</h1>
75
+ <div class="status-msg">
76
+ Statut : <strong style="color: {{ status_color }};">{{ status_text|safe }}</strong>
77
+ </div>
78
+ {% if not logged_in %}
79
+ <form method="post" action="/login">
80
+ <input type="password" name="password" placeholder="Mot de passe" style="padding:12px; border-radius:8px; width: 80%; border:none;"><br><br>
81
+ <button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION</button>
82
+ </form>
83
+ {% else %}
84
+ {% if message %} <div class="confirmation">⚡ {{ message }}</div> {% endif %}
85
+ {% if show_snake %}
86
+ <canvas id="snakeGame" width="300" height="300"></canvas>
87
+ <div class="keys">
88
+ <div class="key">↑</div><div class="key">↓</div><div class="key">←</div><div class="key">→</div>
89
+ </div>
90
+ <script>
91
+ const canvas = document.getElementById("snakeGame"); const ctx = canvas.getContext("2d");
92
+ let snake = [{x:10, y:10}]; let food = {x:5, y:5}; let dx=0, dy=0;
93
+ document.addEventListener("keydown", e => {
94
+ if(e.key==="ArrowUp" && dy===0) {dx=0; dy=-1;}
95
+ if(e.key==="ArrowDown" && dy===0) {dx=0; dy=1;}
96
+ if(e.key==="ArrowLeft" && dx===0) {dx=-1; dy=0;}
97
+ if(e.key==="ArrowRight" && dx===0) {dx=1; dy=0;}
98
+ });
99
+ function draw() {
100
+ let head = {x: snake[0].x + dx, y: snake[0].y + dy};
101
+ snake.unshift(head);
102
+ if(head.x===food.x && head.y===food.y) {
103
+ food = {x:Math.floor(Math.random()*15), y:Math.floor(Math.random()*15)};
104
+ } else { snake.pop(); }
105
+ if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) return location.reload();
106
+ ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
107
+ ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
108
+ ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
109
+ setTimeout(draw, 100);
110
+ } draw();
111
+ </script>
112
+ {% else %}
113
+ <form action="/wake" method="post">
114
+ <button type="submit" class="btn-wake">🚀 ALLUMER SERVEUR</button>
115
+ </form>
116
+ {% endif %}
117
+ <p><a href="/" style="color: #666; text-decoration: none; font-size: 0.8em; margin-top: 20px; display: block;">🔄 ACTUALISER</a></p>
118
+ {% endif %}
119
+ </div>
120
+ <script>
121
+ document.querySelectorAll('.sticker').forEach((s, i) => {
122
+ s.style.left = Math.floor(Math.random() * 80) + "%";
123
+ s.style.top = Math.floor(Math.random() * 80) + "%";
124
+ s.style.transform = "rotate(" + (Math.floor(Math.random() * 40) - 20) + "deg)";
125
+ });
126
+ </script>
127
+ </body>
128
+ </html>
129
+ '''
130
 
131
+ @app.route('/')
132
+ def index():
133
+ status_text, status_color = get_server_status()
134
+ return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'),
135
+ status_text=status_text, status_color=status_color,
136
+ bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, show_snake=False)
 
 
 
 
 
 
 
 
137
 
138
+ @app.route('/login', methods=['POST'])
139
+ def login():
140
+ if request.form.get('password') == MOT_DE_PASSE: session['auth'] = True
141
+ return redirect('/')
 
 
142
 
143
+ @app.route('/wake', methods=['POST'])
144
+ def wake():
145
+ if not session.get('auth'): return redirect('/')
146
+ msg = "Échec de l'envoi"
147
+ try:
148
+ target_ip = socket.gethostbyname(MON_HOST_NOIP)
149
+ # On tente l'envoi via l'IP résolue
 
 
 
 
 
150
  send_magic_packet(MAC_ADRESSE, ip_address=target_ip, port=9)
151
+ # On tente AUSSI le broadcast par sécurité
152
+ send_magic_packet(MAC_ADRESSE, ip_address="255.255.255.255", port=9)
153
+ msg = "Paquet envoyé !"
154
+ except Exception as e:
155
+ msg = f"Erreur : {str(e)}"
156
+
157
+ status_text, status_color = get_server_status()
158
+ return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
159
+ status_color=status_color, bg_image=IMAGE_FOND,
160
+ galerie=IMAGES_GALERIE, show_snake=True, message=msg)
161
 
162
+ if __name__ == "__main__":
163
  app.run(host='0.0.0.0', port=7860)