diff --git a/api.c b/api.c
index efaafaf..24754f8 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\nErreur, 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];
+ 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;
@@ -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;
}