untitled1176 commited on
Commit
72a135b
·
verified ·
1 Parent(s): 84ba8e8

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +196 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import socket
2
+ from flask import Flask, render_template_string, request, session, redirect
3
+ from wakeonlan import send_magic_packet
4
+ from mcstatus import JavaServer # <--- CORRIGÉ (Ligne 4)
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
+ # On interroge le serveur Minecraft
37
+ server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}") # <--- CORRIGÉ (Ligne 30)
38
+ status = server.status()
39
+ ping = round(status.latency, 1)
40
+
41
+ info = f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})"
42
+ sub_info = f"<br><small style='color:#aaa'>Ping: {ping}ms</small>"
43
+ return info + sub_info, "#00ff00"
44
+ except:
45
+ try:
46
+ ip = socket.gethostbyname(MON_HOST_NOIP)
47
+ with socket.create_connection((ip, MC_PORT), timeout=1):
48
+ return "DÉMARRAGE... 🟡", "#fbbf24"
49
+ except:
50
+ return "HORS LIGNE 🔴", "#ff4444"
51
+
52
+ # ... (Tout le reste du code HTML est identique et correct !)
53
+ HTML_TEMPLATE = '''
54
+ <!DOCTYPE html>
55
+ <html>
56
+ <head>
57
+ <title>Cobblemon Dashboard</title>
58
+ <style>
59
+ body {
60
+ background: url("{{ bg_image }}") no-repeat center center fixed;
61
+ background-size: cover;
62
+ font-family: 'Segoe UI', sans-serif;
63
+ color: white; margin: 0; overflow: hidden;
64
+ display: flex; justify-content: center; align-items: center; height: 100vh;
65
+ }
66
+ .galerie-background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
67
+ .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; }
68
+
69
+ .container {
70
+ background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(15px);
71
+ padding: 40px; border-radius: 30px; text-align: center;
72
+ z-index: 10; border: 1px solid rgba(255,255,255,0.1); width: 90%; max-width: 400px;
73
+ }
74
+
75
+ .status-msg { margin: 20px 0; font-size: 1.2em; line-height: 1.4; }
76
+
77
+ .btn-wake {
78
+ padding: 18px 36px; cursor: pointer; border-radius: 15px; border: none;
79
+ background: #059669; color: white; font-weight: bold; font-size: 1.1em;
80
+ transition: transform 0.2s, background 0.2s;
81
+ }
82
+ .btn-wake:hover { transform: scale(1.05); background: #10b981; }
83
+
84
+ .confirmation {
85
+ color: #fbbf24; background: rgba(251, 191, 36, 0.1);
86
+ padding: 10px; border-radius: 10px; margin-bottom: 15px; border: 1px solid #fbbf24;
87
+ }
88
+
89
+ #snakeGame { border: 2px solid #2563eb; background: #000; margin-top: 20px; border-radius: 10px; }
90
+ .keys { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
91
+ .key { background: rgba(255,255,255,0.2); padding: 5px 12px; border-radius: 5px; border-bottom: 3px solid white; font-weight: bold; }
92
+ </style>
93
+ </head>
94
+ <body>
95
+
96
+ <div class="galerie-background">
97
+ {% for img_url in galerie %}
98
+ <img src="{{ img_url }}" class="sticker">
99
+ {% endfor %}
100
+ </div>
101
+
102
+ <div class="container">
103
+ <h1>Cobblemon V2</h1>
104
+
105
+ <div class="status-msg">
106
+ Statut : <strong style="color: {{ status_color }};">{{ status_text|safe }}</strong>
107
+ </div>
108
+
109
+ {% if not logged_in %}
110
+ <form method="post" action="/login">
111
+ <input type="password" name="password" placeholder="Mot de passe" style="padding:12px; border-radius:8px; width: 80%; border:none;"><br><br>
112
+ <button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION</button>
113
+ </form>
114
+ {% else %}
115
+ {% if message %}
116
+ <div class="confirmation">⚡ {{ message }}</div>
117
+ {% endif %}
118
+
119
+ {% if show_snake %}
120
+ <canvas id="snakeGame" width="300" height="300"></canvas>
121
+ <div class="keys">
122
+ <div class="key">↑</div><div class="key">↓</div><div class="key">←</div><div class="key">→</div>
123
+ </div>
124
+ <script>
125
+ const canvas = document.getElementById("snakeGame");
126
+ const ctx = canvas.getContext("2d");
127
+ let snake = [{x:10, y:10}]; let food = {x:5, y:5}; let dx=0, dy=0;
128
+ document.addEventListener("keydown", e => {
129
+ if(e.key==="ArrowUp" && dy===0) {dx=0; dy=-1;}
130
+ if(e.key==="ArrowDown" && dy===0) {dx=0; dy=1;}
131
+ if(e.key==="ArrowLeft" && dx===0) {dx=-1; dy=0;}
132
+ if(e.key==="ArrowRight" && dx===0) {dx=1; dy=0;}
133
+ });
134
+ function draw() {
135
+ let head = {x: snake[0].x + dx, y: snake[0].y + dy};
136
+ snake.unshift(head);
137
+ if(head.x===food.x && head.y===food.y) {
138
+ food = {x:Math.floor(Math.random()*15), y:Math.floor(Math.random()*15)};
139
+ } else { snake.pop(); }
140
+ if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) return location.reload();
141
+ ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
142
+ ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
143
+ ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
144
+ setTimeout(draw, 100);
145
+ } draw();
146
+ </script>
147
+ {% else %}
148
+ <form action="/wake" method="post">
149
+ <button type="submit" class="btn-wake">🚀 ALLUMER SERVEUR</button>
150
+ </form>
151
+ {% endif %}
152
+ <p><a href="/" style="color: #666; text-decoration: none; font-size: 0.8em; margin-top: 20px; display: block;">🔄 ACTUALISER</a></p>
153
+ {% endif %}
154
+ </div>
155
+
156
+ <script>
157
+ document.querySelectorAll('.sticker').forEach((s, i) => {
158
+ s.style.left = Math.floor(Math.random() * 80) + "%";
159
+ s.style.top = Math.floor(Math.random() * 80) + "%";
160
+ s.style.transform = "rotate(" + (Math.floor(Math.random() * 40) - 20) + "deg)";
161
+ });
162
+ </script>
163
+ </body>
164
+ </html>
165
+ '''
166
+
167
+ @app.route('/')
168
+ def index():
169
+ status_text, status_color = get_server_status()
170
+ return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'),
171
+ status_text=status_text, status_color=status_color,
172
+ bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, show_snake=False)
173
+
174
+ @app.route('/login', methods=['POST'])
175
+ def login():
176
+ if request.form.get('password') == MOT_DE_PASSE: session['auth'] = True
177
+ return redirect('/')
178
+
179
+ @app.route('/wake', methods=['POST'])
180
+ def wake():
181
+ if not session.get('auth'): return redirect('/')
182
+ msg = "Échec de l'envoi"
183
+ try:
184
+ target_ip = socket.gethostbyname(MON_HOST_NOIP)
185
+ send_magic_packet(MAC_ADRESSE, ip_address=target_ip, port=9)
186
+ msg = f"Paquet envoyé !"
187
+ except Exception as e:
188
+ msg = f"Erreur : {str(e)}"
189
+
190
+ status_text, status_color = get_server_status()
191
+ return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
192
+ status_color=status_color, bg_image=IMAGE_FOND,
193
+ galerie=IMAGES_GALERIE, show_snake=True, message=msg)
194
+
195
+ if __name__ == "__main__":
196
+ app.run(host='0.0.0.0', port=8000)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Flask
2
+ wakeonlan
3
+ gunicorn
4
+ requests
5
+ mcstatus
6
+ asyncio-dgram
7
+ dnspython