untitled1176 commited on
Commit
9b8908e
·
verified ·
1 Parent(s): 7e58837

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +202 -0
app.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
5
+
6
+ app = Flask(__name__)
7
+ app.secret_key = "une_cle_tres_secrete"
8
+
9
+ # --- CONFIGURATION CHROME & HUGGING FACE ---
10
+ app.config.update(
11
+ SESSION_COOKIE_SAMESITE='None',
12
+ SESSION_COOKIE_SECURE=True
13
+ )
14
+
15
+ # --- CONFIGURATION ---
16
+ MAC_ADRESSE = "d4:3d:7e:31:e8:84"
17
+ MON_HOST_NOIP = "cobblev2.redirectme.net"
18
+ MOT_DE_PASSE = "pouletcrousty"
19
+ MC_PORT = 25565
20
+ IMAGE_FOND = "https://images.alphacoders.com/132/1327533.png"
21
+
22
+ IMAGES_GALERIE = [
23
+ "https://i.redd.it/ag4307hy62qe1.jpeg",
24
+ "https://pbs.twimg.com/profile_images/1627794683362480129/3xUrVnUY_400x400.jpg",
25
+ "https://sativa.fr/wp-content/uploads/SnoopDogg.jpg",
26
+ "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",
27
+ "https://i1.sndcdn.com/artworks-000148945005-hx6vn7-t1080x1080.jpg",
28
+ "https://www.shutterstock.com/image-illustration/internet-meme-stupid-troll-face-260nw-201587906.jpg",
29
+ "https://www.lycee3vallees.fr/wp-content/uploads/2024/08/Logo-Pole-emploi.png",
30
+ "https://img.freepik.com/photos-gratuite/belle-photo-chaton-british-shorthair-blanc_181624-57681.jpg",
31
+ "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",
32
+ "https://images.eatself.com/811/38179_10273994.png",
33
+ "https://miro.medium.com/0*Ug2qG0Ph4JkU5pEZ.png",
34
+ "https://www.radiofrance.fr/s3/cruiser-production/2019/10/2ccb44bb-6211-4340-b063-4d7a015575d4/1200x680_kaaris-or-noir.jpg_or_noir.jpg",
35
+ "https://i.ebayimg.com/images/g/jagAAOxyu1BTj-fx/s-l1200.jpg",
36
+ "https://www.radiofrance.fr/s3/cruiser-production-eu3/2019/06/d12bbc34-45f9-4b03-b762-25ae9988b888/640x340_gettyimages-624736982.jpg",
37
+ "https://upload.wikimedia.org/wikipedia/fr/b/b2/Minecraft%2C_le_film.png",
38
+ ]
39
+
40
+ def get_server_status():
41
+ try:
42
+ server = JavaServer.lookup(f"{MON_HOST_NOIP}:{MC_PORT}")
43
+ status = server.status()
44
+ ping = round(status.latency, 1)
45
+ info = f"EN LIGNE 🟢 ({status.players.online}/{status.players.max})"
46
+ sub_info = f"<br><small style='color:#aaa'>Ping: {ping}ms</small>"
47
+ return info + sub_info, "#00ff00"
48
+ except:
49
+ try:
50
+ ip = socket.gethostbyname(MON_HOST_NOIP)
51
+ with socket.create_connection((ip, MC_PORT), timeout=1):
52
+ return "DÉMARRAGE... 🟡", "#fbbf24"
53
+ except:
54
+ return "HORS LIGNE 🔴", "#ff4444"
55
+
56
+ HTML_TEMPLATE = '''
57
+ <!DOCTYPE html>
58
+ <html>
59
+ <head>
60
+ <title>Cobblemon Dashboard</title>
61
+ <style>
62
+ body {
63
+ background: url("{{ bg_image }}") no-repeat center center fixed;
64
+ background-size: cover;
65
+ font-family: 'Segoe UI', sans-serif;
66
+ color: white; margin: 0; overflow: hidden;
67
+ display: flex; justify-content: center; align-items: center; height: 100vh;
68
+ }
69
+ .galerie-background { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
70
+
71
+ /* MODIFICATION ICI : max-width passe de 150px à 225px (1.5x) */
72
+ .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: 225px; }
73
+
74
+ .container {
75
+ background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(15px);
76
+ padding: 40px; border-radius: 30px; text-align: center;
77
+ z-index: 10; border: 1px solid rgba(255,255,255,0.1); width: 90%; max-width: 400px;
78
+ }
79
+
80
+ .status-msg { margin: 20px 0; font-size: 1.2em; line-height: 1.4; }
81
+
82
+ .btn-wake {
83
+ padding: 18px 36px; cursor: pointer; border-radius: 15px; border: none;
84
+ background: #059669; color: white; font-weight: bold; font-size: 1.1em;
85
+ transition: transform 0.2s, background 0.2s;
86
+ }
87
+ .btn-wake:hover { transform: scale(1.05); background: #10b981; }
88
+
89
+ .confirmation {
90
+ color: #fbbf24; background: rgba(251, 191, 36, 0.1);
91
+ padding: 10px; border-radius: 10px; margin-bottom: 15px; border: 1px solid #fbbf24;
92
+ }
93
+
94
+ #snakeGame { border: 2px solid #2563eb; background: #000; margin-top: 20px; border-radius: 10px; }
95
+ .keys { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
96
+ .key { background: rgba(255,255,255,0.2); padding: 5px 12px; border-radius: 5px; border-bottom: 3px solid white; font-weight: bold; }
97
+ </style>
98
+ </head>
99
+ <body>
100
+
101
+ <div class="galerie-background">
102
+ {% for img_url in galerie %}
103
+ <img src="{{ img_url }}" class="sticker">
104
+ {% endfor %}
105
+ </div>
106
+
107
+ <div class="container">
108
+ <h1>Cobblemon V2</h1>
109
+
110
+ <div class="status-msg">
111
+ Statut : <strong style="color: {{ status_color }};">{{ status_text|safe }}</strong>
112
+ </div>
113
+
114
+ {% if not logged_in %}
115
+ <form method="post" action="/login">
116
+ <input type="password" name="password" placeholder="Mot de passe" style="padding:12px; border-radius:8px; width: 80%; border:none;"><br><br>
117
+ <button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION</button>
118
+ </form>
119
+ {% else %}
120
+ {% if message %}
121
+ <div class="confirmation">⚡ {{ message }}</div>
122
+ {% endif %}
123
+
124
+ {% if show_snake %}
125
+ <canvas id="snakeGame" width="300" height="300"></canvas>
126
+ <div class="keys">
127
+ <div class="key">↑</div><div class="key">↓</div><div class="key">←</div><div class="key">→</div>
128
+ </div>
129
+ <script>
130
+ const canvas = document.getElementById("snakeGame");
131
+ const ctx = canvas.getContext("2d");
132
+ let snake = [{x:10, y:10}]; let food = {x:5, y:5}; let dx=0, dy=0;
133
+ document.addEventListener("keydown", e => {
134
+ if(e.key==="ArrowUp" && dy===0) {dx=0; dy=-1;}
135
+ if(e.key==="ArrowDown" && dy===0) {dx=0; dy=1;}
136
+ if(e.key==="ArrowLeft" && dx===0) {dx=-1; dy=0;}
137
+ if(e.key==="ArrowRight" && dx===0) {dx=1; dy=0;}
138
+ });
139
+ function draw() {
140
+ let head = {x: snake[0].x + dx, y: snake[0].y + dy};
141
+ snake.unshift(head);
142
+ if(head.x===food.x && head.y===food.y) {
143
+ food = {x:Math.floor(Math.random()*15), y:Math.floor(Math.random()*15)};
144
+ } else { snake.pop(); }
145
+ if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) return location.reload();
146
+ ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
147
+ ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
148
+ ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
149
+ setTimeout(draw, 100);
150
+ } draw();
151
+ </script>
152
+ {% else %}
153
+ <form action="/wake" method="post">
154
+ <button type="submit" class="btn-wake">🚀 ALLUMER SERVEUR</button>
155
+ </form>
156
+ {% endif %}
157
+ <p><a href="/" style="color: #666; text-decoration: none; font-size: 0.8em; margin-top: 20px; display: block;">🔄 ACTUALISER</a></p>
158
+ {% endif %}
159
+ </div>
160
+
161
+ <script>
162
+ document.querySelectorAll('.sticker').forEach((s, i) => {
163
+ s.style.left = Math.floor(Math.random() * 80) + "%";
164
+ s.style.top = Math.floor(Math.random() * 80) + "%";
165
+ s.style.transform = "rotate(" + (Math.floor(Math.random() * 40) - 20) + "deg)";
166
+ });
167
+ </script>
168
+ </body>
169
+ </html>
170
+ '''
171
+
172
+ @app.route('/')
173
+ def index():
174
+ status_text, status_color = get_server_status()
175
+ return render_template_string(HTML_TEMPLATE, logged_in=session.get('auth'),
176
+ status_text=status_text, status_color=status_color,
177
+ bg_image=IMAGE_FOND, galerie=IMAGES_GALERIE, show_snake=False)
178
+
179
+ @app.route('/login', methods=['POST'])
180
+ def login():
181
+ if request.form.get('password') == MOT_DE_PASSE:
182
+ session['auth'] = True
183
+ return redirect('/')
184
+
185
+ @app.route('/wake', methods=['POST'])
186
+ def wake():
187
+ if not session.get('auth'): return redirect('/')
188
+ msg = "Échec de l'envoi"
189
+ try:
190
+ target_ip = socket.gethostbyname(MON_HOST_NOIP)
191
+ send_magic_packet(MAC_ADRESSE, ip_address=target_ip, port=9)
192
+ msg = f"Paquet envoyé !"
193
+ except Exception as e:
194
+ msg = f"Erreur : {str(e)}"
195
+
196
+ status_text, status_color = get_server_status()
197
+ return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
198
+ status_color=status_color, bg_image=IMAGE_FOND,
199
+ galerie=IMAGES_GALERIE, show_snake=True, message=msg)
200
+
201
+ if __name__ == "__main__":
202
+ app.run(host='0.0.0.0', port=7860)