untitled1176 commited on
Commit
f75c51e
·
verified ·
1 Parent(s): 64a97a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -119
app.py CHANGED
@@ -1,158 +1,134 @@
 
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
- // COLLISION MUR OU CORPS -> ACTUALISATION PAGE
102
- if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) { location.reload(); return; }
103
- for(let i=1; i<snake.length; i++) { if(head.x === snake[i].x && head.y === snake[i].y) { location.reload(); return; } }
104
-
105
- snake.unshift(head);
106
- 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(); }
107
-
108
- ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
109
- ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
110
- ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
111
- setTimeout(draw, 100);
112
- } draw();
113
- </script>
114
  {% endif %}
115
- <p><a href="/" style="color: #aaa; text-decoration: none; font-size: 0.8em; display: block; margin-top: 15px;">🔄 ACTUALISER</a></p>
 
 
 
 
 
 
 
 
 
 
 
116
  {% endif %}
117
  </div>
118
 
119
  <script>
120
- const stickers = document.querySelectorAll('.sticker');
121
- const cols = 6; const rows = 6; let cells = [];
122
- for(let i=0; i<cols; i++) { for(let j=0; j<rows; j++) { cells.push({x: i * (100/cols), y: j * (100/rows)}); } }
123
- cells.sort(() => Math.random() - 0.5);
124
- stickers.forEach((s, i) => { if(cells[i]) {
125
- s.style.left = (cells[i].x + (Math.random() * 5)) + "%";
126
- s.style.top = (cells[i].y + (Math.random() * 5)) + "%";
127
- s.style.transform = "rotate(" + (Math.floor(Math.random() * 30) - 15) + "deg)";
128
- }});
 
 
 
 
 
 
 
 
 
 
129
  </script>
130
  </body>
131
  </html>
132
- '''
133
 
134
  @app.route('/')
135
  def index():
136
- status_text, status_color = get_server_status()
137
- msg = session.pop('msg', None)
138
- snake = session.pop('snake', False)
139
- 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)
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(url_for('index'))
 
145
 
146
  @app.route('/wake', methods=['POST'])
147
  def wake():
148
- if not session.get('auth'): return redirect(url_for('index'))
149
  try:
150
- send_magic_packet(MAC_ADRESSE, ip_address=socket.gethostbyname(MON_HOST_NOIP), port=9)
151
- session['msg'] = "Paquet envoyé ! Joue pour actualiser."
152
- session['snake'] = True
153
  except Exception as e:
154
- session['msg'] = f"Erreur : {str(e)}"
155
- return redirect(url_for('index'))
156
 
157
  if __name__ == "__main__":
158
- app.run(host='0.0.0.0', port=7860)
 
1
+ import os
2
  import socket
3
+ from flask import Flask, render_template_string, request, session, redirect
 
 
4
 
5
  app = Flask(__name__)
6
+ app.secret_key = "ton_secret_ultra_safe"
7
 
8
+ # --- CONFIGURATION (À REMPLIR) ---
9
+ PASSWORD = "ton_mot_de_passe"
10
+ MAC_ADRESSE = "XX:XX:XX:XX:XX:XX"
11
+ MON_HOST_NOIP = "ton_host.ddns.net"
12
 
13
+ # --- FONCTION WOL ROBUSTE ---
14
+ def send_wol(mac_addr, ip_addr):
15
+ mac_clean = mac_addr.replace(":", "").replace("-", "").replace(".", "")
16
+ packet = bytes.fromhex('F' * 12 + mac_clean * 16)
17
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
18
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
19
+ s.sendto(packet, (ip_addr, 9))
20
 
21
+ # --- TEMPLATE AVEC IMAGES ET JEU ---
22
+ HTML_TEMPLATE = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  <!DOCTYPE html>
24
+ <html lang="fr">
25
  <head>
26
+ <meta charset="UTF-8">
27
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
28
  <title>Cobblemon Dashboard</title>
29
  <style>
30
+ body {
31
+ margin: 0; padding: 0;
32
+ background: url('https://images.alphacoders.com/132/1324508.png') no-repeat center center fixed;
33
+ background-size: cover;
34
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
35
+ display: flex; align-items: center; justify-content: center; height: 100vh;
36
+ }
37
+ .container {
38
+ background: rgba(0, 0, 0, 0.85);
39
+ padding: 30px; border-radius: 20px;
40
+ box-shadow: 0 15px 35px rgba(0,0,0,0.7);
41
+ text-align: center; width: 350px; color: white;
42
+ border: 1px solid rgba(255,255,255,0.1);
43
+ }
44
+ h1 { color: #ffcb05; text-shadow: 2px 2px #3b4cca; margin-bottom: 25px; }
45
+ input[type="password"] {
46
+ width: 80%; padding: 12px; border-radius: 8px; border: none; margin-bottom: 15px;
47
+ }
48
+ .btn-wake {
49
+ background: linear-gradient(135deg, #ff4757, #ff6b81);
50
+ color: white; border: none; padding: 15px 30px;
51
+ border-radius: 10px; font-weight: bold; cursor: pointer;
52
+ width: 100%; font-size: 1.1em; transition: 0.3s;
53
+ }
54
+ .btn-wake:hover { transform: scale(1.05); filter: brightness(1.2); }
55
+ canvas { border: 2px solid #555; background: #000; margin-top: 15px; border-radius: 5px; }
56
+ .footer { margin-top: 20px; font-size: 0.85em; color: #bbb; }
57
+ .confirmation { color: #2ed573; margin-bottom: 15px; font-weight: bold; }
58
  </style>
59
  </head>
60
  <body>
 
 
 
 
61
  <div class="container">
62
+ <h1>Cobblemon V2</h1>
 
 
63
 
64
+ {% if not session.get('auth') %}
65
  <form method="post" action="/login">
66
+ <input type="password" name="password" placeholder="Mot de passe">
67
+ <button type="submit" class="btn-wake">CONNEXION</button>
68
  </form>
69
  {% else %}
70
+ {% if message %}
71
+ <div class="confirmation">⚡ {{ message }}</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  {% endif %}
73
+
74
+ <form action="/wake" method="post">
75
+ <button type="submit" class="btn-wake">🚀 ALLUMER LE PC</button>
76
+ </form>
77
+
78
+ <canvas id="snakeGame" width="300" height="300"></canvas>
79
+
80
+ <div class="footer">
81
+ <hr style="border: 0; border-top: 1px solid #444; margin: 20px 0;">
82
+ <p>🛠️ <strong>Support :</strong> @TonPseudoDiscord</p>
83
+ <p style="color: #ffb7b7;">⚠️ <code>/stop</code> avant d'éteindre !</p>
84
+ </div>
85
  {% endif %}
86
  </div>
87
 
88
  <script>
89
+ const canvas = document.getElementById('snakeGame');
90
+ if (canvas) {
91
+ const ctx = canvas.getContext('2d');
92
+ let box = 15; let snake = [{x: 10 * box, y: 10 * box}];
93
+ let food = {x: Math.floor(Math.random()*20)*box, y: Math.floor(Math.random()*20)*box};
94
+ let d;
95
+ document.addEventListener("keydown", e => { if(e.keyCode==37 && d!="RIGHT") d="LEFT"; else if(e.keyCode==38 && d!="DOWN") d="UP"; else if(e.keyCode==39 && d!="LEFT") d="RIGHT"; else if(e.keyCode==40 && d!="UP") d="DOWN"; });
96
+ function draw() {
97
+ ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
98
+ for(let i=0; i<snake.length; i++){ ctx.fillStyle = (i==0)?"#ffcb05":"#3b4cca"; ctx.fillRect(snake[i].x, snake[i].y, box, box); }
99
+ ctx.fillStyle = "red"; ctx.fillRect(food.x, food.y, box, box);
100
+ let head = {x: snake[0].x, y: snake[0].y};
101
+ if(d=="LEFT") head.x -= box; if(d=="UP") head.y -= box; if(d=="RIGHT") head.x += box; if(d=="DOWN") head.y += box;
102
+ if(head.x == food.x && head.y == food.y) food = {x: Math.floor(Math.random()*20)*box, y: Math.floor(Math.random()*20)*box}; else snake.pop();
103
+ if(head.x<0 || head.y<0 || head.x>=300 || head.y>=300) { snake=[{x:10*box,y:10*box}]; d=null; }
104
+ snake.unshift(head);
105
+ }
106
+ setInterval(draw, 100);
107
+ }
108
  </script>
109
  </body>
110
  </html>
111
+ """
112
 
113
  @app.route('/')
114
  def index():
115
+ return render_template_string(HTML_TEMPLATE, message=request.args.get('msg'))
 
 
 
116
 
117
  @app.route('/login', methods=['POST'])
118
  def login():
119
+ if request.form.get('password') == PASSWORD:
120
+ session['auth'] = True
121
+ return redirect('/')
122
 
123
  @app.route('/wake', methods=['POST'])
124
  def wake():
125
+ if not session.get('auth'): return redirect('/')
126
  try:
127
+ target_ip = socket.gethostbyname(MON_HOST_NOIP)
128
+ send_wol(MAC_ADRESSE, target_ip)
129
+ return redirect('/?msg=Paquet envoyé !')
130
  except Exception as e:
131
+ return redirect('/?msg=Erreur : ' + str(e))
 
132
 
133
  if __name__ == "__main__":
134
+ app.run(host="0.0.0.0", port=7860)