5 Commits
Author SHA1 Message Date
nicolas 03f9197854 Merge pull request 'Feat/add parameters' (#5) from feat/add-parameters into main
Reviewed-on: #5
Reviewed-by: Nicolas Deville <nicolas@lanisys.fr>
2026-09-13 16:10:50 +02:00
fred 007aaf113a fix: argv bug 2026-09-13 11:55:58 +02:00
fred b4baaa2743 feat: filename not hardcoded
lancement d'apid : ajout des paramètres :
- nom fichier secret
- nom du script shell qui lance ttyd
2026-09-13 11:54:00 +02:00
nicolas 972e51dd39 Merge pull request 'feat: secret key to authorize ttyd only from w's wiki' (#4) from feat/add-key into main
Reviewed-on: #4
Reviewed-by: Nicolas Deville <nicolas@lanisys.fr>
2026-09-12 21:14:50 +02:00
fred f18dbe01f7 feat: secret key to authorize ttyd only from w's wiki 2026-09-12 21:09:05 +02:00
3 changed files with 69 additions and 18 deletions

No files matched your search

+55 -10
View File
@@ -455,9 +455,15 @@ void trt_sig(int sig)
// -----------------------------------------------------------
char data[64000], rep[64000]; // buffer de lecture/ecriture sur la socket securisee
void trt_connexion()
void trt_connexion(char * secretfile, char * scriptttyd)
{
FILE * fp;
FILE * fp, * fd;
// script => /root/create_ttyd_session.sh
char redirectfile[] = "/tmp/ttyd.txt";
char redirection[] = " > /tmp/ttyd.txt";
char script[strlen(scriptttyd) + strlen(redirection) + 1];
strcpy(script, scriptttyd);
strcat(script, redirection);
//Dynamic req, methode, uri, rep, tmp, fld;
//long meth, cr, nb;
int keepAlive;
@@ -472,13 +478,36 @@ 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(secretfile, "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;
//
//strcpy(data, "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Type:text/html\r\nContent-Length:35\r\n\r\n<html><h2>Hello World !</h2></html>");
remove("/tmp/ttyd.txt");
system("/root/create_ttyd_session.sh > /tmp/ttyd.txt");
if((fp = fopen("/tmp/ttyd.txt", "r")) == NULL)
remove(redirectfile);
system(script);
if((fp = fopen(redirectfile, "r")) == NULL)
strcpy(data, "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Type:text/html\r\nContent-Length:97\r\n\r\n<html><h2>Erreur, console de test non disponible, veuillez contacter l'administrateur</h2></html>");
else
{
@@ -510,25 +539,40 @@ void trt_connexion()
trace("fin cnx client\n");
}
void writePid(long pid)
{
char pidfile[] = "/run/apid.pid";
remove(pidfile);
FILE * f = fopen(pidfile, "a+");
if(f)
{
fprintf(f, "%ld\n", pid);
fclose(f);
}
}
// ----------------------------------------------------------
int main(int argc, char *argv[])
{
if(argc != 4 && argc != 5)
if(argc != 6 && argc != 7)
{
trace("Usage : %s <port> <certificat> <cleprivee> [<fichierlog>]\n", argv[0]);
trace("Usage : %s <port> <fichiercertificat> <fichiercleprivee> <fichiersecret> <fichierscriptttyd> [<fichierlog>]\n", argv[0]);
exit(1);
}
int demon = (argv[0][strlen(argv[0]) - 1] == 'd');
if(argc == 5)
if(argc == 7)
{
flog = argv[4];
flog = argv[argc - 1];
if(*flog != '0')
remove(flog);
}
/* */
int port = atoi(argv[1]);
certificat = argv[2];
cleprivee = argv[3];
char * secretfile = argv[4];
char * scriptttyd = argv[5];
/* */
mServeur = TRUE;
mFin = FALSE;
@@ -563,6 +607,7 @@ int main(int argc, char *argv[])
setsid();
//for(int i=0;i < FOPEN_MAX; i++) /* OPEN_MAX sous AIX */
// close(i);
writePid(mPid);
}
//
trace("Demarrage serveur, port %d pid %d mode %d bits\n", port, getpid(), sizeof(long)==4?32:64);
@@ -620,7 +665,7 @@ int main(int argc, char *argv[])
break;
}
//
trt_connexion();
trt_connexion(secretfile, scriptttyd);
//
break;
}
+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,