Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,4 +81,92 @@ HTML_TEMPLATE = '''
|
|
| 81 |
{% if not logged_in %}
|
| 82 |
<form method="post" action="/login">
|
| 83 |
<input type="password" name="password" placeholder="Mot de passe" style="padding:12px; border-radius:8px; width: 80%; border:none;"><br><br>
|
| 84 |
-
<button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
{% if not logged_in %}
|
| 82 |
<form method="post" action="/login">
|
| 83 |
<input type="password" name="password" placeholder="Mot de passe" style="padding:12px; border-radius:8px; width: 80%; border:none;"><br><br>
|
| 84 |
+
<button type="submit" class="btn-wake" style="background: #2563eb;">CONNEXION</button>
|
| 85 |
+
</form>
|
| 86 |
+
{% else %}
|
| 87 |
+
{% if message %} <div class="confirmation">โก {{ message }}</div> {% endif %}
|
| 88 |
+
{% if show_snake %}
|
| 89 |
+
<canvas id="snakeGame" width="300" height="300"></canvas>
|
| 90 |
+
<div class="keys">
|
| 91 |
+
<div class="key">โ</div><div class="key">โ</div><div class="key">โ</div><div class="key">โ</div>
|
| 92 |
+
</div>
|
| 93 |
+
<script>
|
| 94 |
+
const canvas = document.getElementById("snakeGame"); const ctx = canvas.getContext("2d");
|
| 95 |
+
let snake = [{x:10, y:10}]; let food = {x:5, y:5}; let dx=0, dy=0;
|
| 96 |
+
document.addEventListener("keydown", e => {
|
| 97 |
+
if(e.key==="ArrowUp" && dy===0) {dx=0; dy=-1;}
|
| 98 |
+
if(e.key==="ArrowDown" && dy===0) {dx=0; dy=1;}
|
| 99 |
+
if(e.key==="ArrowLeft" && dx===0) {dx=-1; dy=0;}
|
| 100 |
+
if(e.key==="ArrowRight" && dx===0) {dx=1; dy=0;}
|
| 101 |
+
});
|
| 102 |
+
function draw() {
|
| 103 |
+
let head = {x: snake[0].x + dx, y: snake[0].y + dy};
|
| 104 |
+
snake.unshift(head);
|
| 105 |
+
if(head.x===food.x && head.y===food.y) {
|
| 106 |
+
food = {x:Math.floor(Math.random()*15), y:Math.floor(Math.random()*15)};
|
| 107 |
+
} else { snake.pop(); }
|
| 108 |
+
if(head.x<0 || head.x>=15 || head.y<0 || head.y>=15) return location.reload();
|
| 109 |
+
ctx.fillStyle = "black"; ctx.fillRect(0,0,300,300);
|
| 110 |
+
ctx.fillStyle = "red"; ctx.fillRect(food.x*20, food.y*20, 18, 18);
|
| 111 |
+
ctx.fillStyle = "#2563eb"; snake.forEach(p => ctx.fillRect(p.x*20, p.y*20, 18, 18));
|
| 112 |
+
setTimeout(draw, 100);
|
| 113 |
+
} draw();
|
| 114 |
+
</script>
|
| 115 |
+
{% else %}
|
| 116 |
+
<form action="/wake" method="post">
|
| 117 |
+
<button type="submit" class="btn-wake">๐ ALLUMER SERVEUR</button>
|
| 118 |
+
</form>
|
| 119 |
+
{% endif %}
|
| 120 |
+
<p><a href="/" style="color: #666; text-decoration: none; font-size: 0.8em; margin-top: 20px; display: block;">๐ ACTUALISER</a></p>
|
| 121 |
+
{% endif %}
|
| 122 |
+
</div>
|
| 123 |
+
<script>
|
| 124 |
+
document.querySelectorAll('.sticker').forEach((s, i) => {
|
| 125 |
+
s.style.left = Math.floor(Math.random() * 80) + "%";
|
| 126 |
+
s.style.top = Math.floor(Math.random() * 80) + "%";
|
| 127 |
+
s.style.transform = "rotate(" + (Math.floor(Math.random() * 40) - 20) + "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 |
+
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 |
+
mac_clean = MAC_ADRESSE.replace(':', '').upper()
|
| 151 |
+
try:
|
| 152 |
+
target_ip = socket.gethostbyname(MON_HOST_NOIP)
|
| 153 |
+
depicus_url = f"https://www.depicus.com/wake-on-lan/woli?m={mac_clean}&i={target_ip}&s=255.255.255.255&p=9"
|
| 154 |
+
|
| 155 |
+
headers = {
|
| 156 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
| 157 |
+
'Referer': 'https://www.depicus.com/'
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
requests.get(depicus_url, headers=headers, timeout=10)
|
| 161 |
+
msg = "๐ Signal envoyรฉ au Proxy Bbox !"
|
| 162 |
+
|
| 163 |
+
except Exception as e:
|
| 164 |
+
msg = f"Erreur de relais : {str(e)}"
|
| 165 |
+
|
| 166 |
+
status_text, status_color = get_server_status()
|
| 167 |
+
return render_template_string(HTML_TEMPLATE, logged_in=True, status_text=status_text,
|
| 168 |
+
status_color=status_color, bg_image=IMAGE_FOND,
|
| 169 |
+
galerie=IMAGES_GALERIE, show_snake=True, message=msg)
|
| 170 |
+
|
| 171 |
+
if __name__ == "__main__":
|
| 172 |
+
app.run(host='0.0.0.0', port=7860)
|