feat: secret key to authorize ttyd only from w's wiki #4

Merged
nicolas merged 1 commits from feat/add-key into main 2026-09-12 21:14:53 +02:00
3 changed files with 38 additions and 9 deletions

No files matched your search

+24 -1
View File
@@ -457,7 +457,7 @@ void trt_sig(int sig)
char data[64000], rep[64000]; // buffer de lecture/ecriture sur la socket securisee
void trt_connexion()
{
FILE * fp;
FILE * fp, * fd;
//Dynamic req, methode, uri, rep, tmp, fld;
//long meth, cr, nb;
int keepAlive;
@@ -472,6 +472,29 @@ void trt_connexion()
if ( ! lireConnexion(data))
break; // fin du client
trace("lu:\n%s\n", data);
//
*rep = 0;
strcpy(rep, "X-data: 1234567890123456789012345678901234567890123456789012345678901234");
if((fd = fopen("/root/data", "r")))
{
fread(rep + 8, 64, 1, fd);
fclose(fd);
}
else
{
// erreur sur le serveur : tout refuser
strcpy(data, "HTTP/1.1 401 Unauthorized\r\n\r\n");
ecrireConnexion(data);
break;
}
if(strstr(data, rep) == NULL)
{
// le client ne vient pas de wapi.php : refuser
strcpy(data, "HTTP/1.1 401 Unauthorized\r\n\r\n");
ecrireConnexion(data);
break;
}
//
if(strstr(data,"keep-alive") == NULL)
keepAlive = FALSE;
//
+9 -2
View File
@@ -1,6 +1,13 @@
#!/bin/bash
# dans /root du serveur docker (avec apid et certificat/cle privee)
# duree est le nb de minute pour la session, par defaut 7200 mn
duree="${1:-7200}"
if (( duree < 15 || duree > 14400 )); then
echo "Duree de la session incorrecte."
exit 2
fi
cat /docker/registry/auth/password | docker login 192.168.10.10:5000/v2 -u nicolas --password-stdin
# Configuration
@@ -45,7 +52,7 @@ docker run -d \
--cpus="0.75" \
"$IMAGE_NAME"
( sleep 7200 && docker stop "$CONTAINER_NAME" ) &
( sleep $duree && docker stop "$CONTAINER_NAME" ) &
if [ $? -ne 0 ]; then
echo "Erreur lors du démarrage du conteneur."
@@ -56,7 +63,7 @@ PORT_URL=$(($PORT - $BASE_PORT + 1))
# Afficher l'URL d'accès
#echo "Session ttyd créée avec succès !"
#echo "Nom du conteneur : $CONTAINER_NAME"
#echo "Conteneur lancé pour 2 heures : <a href=\"https://w-$PORT_URL.lanisys.fr\">URL</a>"
#echo "Conteneur lancé pour 2 heures : <a href=\"https://user:pass@w-$PORT_URL.lanisys.fr\">URL</a>"
#echo "User: $user / Password: $pass"
#echo "Termine avec succes"
+5 -6
View File
@@ -1,18 +1,17 @@
<?php
// dans /var/www/w.lanisys.fr sur le serveur ionos
$data = file_get_contents('/etc/wapi/data');
$ctx = stream_context_create([
'http' => [
'timeout' => 4,
'header' => [
'X-data: '.$data
]
],
]);
echo file_get_contents(
"https://api.lanisys.fr:50000/",
false,
$ctx
);
$rep = file_get_contents(
"https://api.lanisys.fr:50000/",
false,