diff --git a/api.c b/api.c index 29a5f6a..efaafaf 100644 --- a/api.c +++ b/api.c @@ -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; // diff --git a/create_ttyd_session.sh b/create_ttyd_session.sh index 4eb223c..cd5ee43 100644 --- a/create_ttyd_session.sh +++ b/create_ttyd_session.sh @@ -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 : URL" +#echo "Conteneur lancé pour 2 heures : URL" #echo "User: $user / Password: $pass" #echo "Termine avec succes" diff --git a/wapi.php b/wapi.php index 59b5d57..d38908b 100644 --- a/wapi.php +++ b/wapi.php @@ -1,18 +1,17 @@ [ '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,