From b4baaa2743eafbcb0301a5b57014aeaf2599a4c8 Mon Sep 17 00:00:00 2001 From: Deville Date: Sun, 13 Sep 2026 11:54:00 +0200 Subject: [PATCH 1/2] feat: filename not hardcoded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lancement d'apid : ajout des paramètres : - nom fichier secret - nom du script shell qui lance ttyd --- api.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/api.c b/api.c index efaafaf..929dbf1 100644 --- a/api.c +++ b/api.c @@ -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, * 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; @@ -475,7 +481,7 @@ void trt_connexion() // *rep = 0; strcpy(rep, "X-data: 1234567890123456789012345678901234567890123456789012345678901234"); - if((fd = fopen("/root/data", "r"))) + if((fd = fopen(secretfile, "r"))) { fread(rep + 8, 64, 1, fd); fclose(fd); @@ -499,9 +505,9 @@ void trt_connexion() 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

Hello World !

"); - 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

Erreur, console de test non disponible, veuillez contacter l'administrateur

"); else { @@ -533,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 []\n", argv[0]); + trace("Usage : %s []\n", argv[0]); exit(1); } int demon = (argv[0][strlen(argv[0]) - 1] == 'd'); - if(argc == 5) + if(argc == 7) { flog = argv[4]; 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; @@ -586,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); @@ -643,7 +665,7 @@ int main(int argc, char *argv[]) break; } // - trt_connexion(); + trt_connexion(secretfile, scriptttyd); // break; } -- 2.56.0.windows.4 From 007aaf113a89a2bf5174702df963fd88cc408a30 Mon Sep 17 00:00:00 2001 From: Deville Date: Sun, 13 Sep 2026 11:55:58 +0200 Subject: [PATCH 2/2] fix: argv bug --- api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.c b/api.c index 929dbf1..24754f8 100644 --- a/api.c +++ b/api.c @@ -562,7 +562,7 @@ int main(int argc, char *argv[]) int demon = (argv[0][strlen(argv[0]) - 1] == 'd'); if(argc == 7) { - flog = argv[4]; + flog = argv[argc - 1]; if(*flog != '0') remove(flog); } -- 2.56.0.windows.4