Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6301b83d57 | ||
|
|
5bee6269d4 | ||
|
|
14e4b63f9b | ||
|
|
afba9c2200 | ||
|
|
bbe362c65d | ||
|
|
b702f8a548 | ||
|
|
e3a6596e46 | ||
|
|
f557d1db92 | ||
|
|
02e166e1e5 | ||
|
|
1410df4f00 | ||
|
|
d577060e87 |
No files matched your search
@@ -15,6 +15,8 @@
|
||||
|
||||
/* compilation : gcc -o api api.c -Wall -lssl -lcrypto */
|
||||
|
||||
/* ./apid 50000 cert.pem server.key 0 */
|
||||
|
||||
char * flog = NULL;
|
||||
|
||||
#define TRUE 1
|
||||
@@ -51,6 +53,8 @@ void trace(const char * fmt, ...)
|
||||
va_start(args, fmt);
|
||||
if(flog)
|
||||
{
|
||||
if(*flog == '0') return; // si fichier log = "0" : ne rien afficher ni logguer
|
||||
//
|
||||
FILE * f = fopen(flog, "a+");
|
||||
if(f)
|
||||
{
|
||||
@@ -450,9 +454,10 @@ void trt_sig(int sig)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
char data[64000]; // buffer de lecture/ecriture sur la socket securisee
|
||||
char data[64000], rep[64000]; // buffer de lecture/ecriture sur la socket securisee
|
||||
void trt_connexion()
|
||||
{
|
||||
FILE * fp;
|
||||
//Dynamic req, methode, uri, rep, tmp, fld;
|
||||
//long meth, cr, nb;
|
||||
int keepAlive;
|
||||
@@ -470,7 +475,27 @@ void trt_connexion()
|
||||
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>");
|
||||
//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)
|
||||
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
|
||||
{
|
||||
*data = 0;
|
||||
*rep = 0;
|
||||
fseek(fp, 0, SEEK_END);
|
||||
long lg = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
fread(rep, lg, 1, fp);
|
||||
rep[lg] = 0;
|
||||
fclose(fp);
|
||||
//
|
||||
sprintf(data, "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Type:text/html\r\nContent-Length:%ld", lg);
|
||||
strcat(data, "\r\n\r\n");
|
||||
strncat(data, rep, lg);
|
||||
}
|
||||
//
|
||||
trace("Reponse:\n%s\n", data);
|
||||
ecrireConnexion(data);
|
||||
*data = 0;
|
||||
@@ -497,7 +522,8 @@ int main(int argc, char *argv[])
|
||||
if(argc == 5)
|
||||
{
|
||||
flog = argv[4];
|
||||
remove(flog);
|
||||
if(*flog != '0')
|
||||
remove(flog);
|
||||
}
|
||||
/* */
|
||||
int port = atoi(argv[1]);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# dans /root du serveur docker (avec apid et certificat/cle privee)
|
||||
|
||||
cat /docker/registry/auth/password | docker login 192.168.10.10:5000/v2 -u nicolas --password-stdin
|
||||
|
||||
# Configuration
|
||||
IMAGE_NAME="192.168.10.10:5000/ttyd_docker:latest"
|
||||
BASE_PORT=9101
|
||||
MAX_PORT=9105
|
||||
|
||||
# Générer un nom unique (apt install uuid-runtime)
|
||||
USER_ID=$(uuidgen | cut -d'-' -f1)
|
||||
CONTAINER_NAME="ttyd_docker_$USER_ID"
|
||||
|
||||
# Trouver un port disponible
|
||||
find_free_port() {
|
||||
for ((port=$BASE_PORT; port<=$MAX_PORT; port++)); do
|
||||
if ! lsof -i :$port > /dev/null; then
|
||||
echo $port
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
PORT=$(find_free_port)
|
||||
|
||||
if [ -z "$PORT" ]; then
|
||||
echo "Aucun port disponible entre $BASE_PORT et $MAX_PORT."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
user=$(uuidgen | cut -d'-' -f1)
|
||||
pass=$(uuidgen | cut -d'-' -f1)
|
||||
|
||||
# Lancer le conteneur ttyd
|
||||
docker run -d \
|
||||
--name "$CONTAINER_NAME" \
|
||||
-p "$PORT":7681 \
|
||||
-e TTYD_USER=$user \
|
||||
-e TTYD_PASS=$pass \
|
||||
--rm \
|
||||
--stop-timeout=30 \
|
||||
--memory="2g" \
|
||||
--cpus="0.75" \
|
||||
"$IMAGE_NAME"
|
||||
|
||||
( sleep 7200 && docker stop "$CONTAINER_NAME" ) &
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Erreur lors du démarrage du conteneur."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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 "User: $user / Password: $pass"
|
||||
#echo "Termine avec succes"
|
||||
|
||||
echo "https://$user:$pass@w-$PORT_URL.lanisys.fr/"
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// dans /var/www/w.lanisys.fr sur le serveur ionos
|
||||
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'timeout' => 4,
|
||||
],
|
||||
]);
|
||||
|
||||
echo file_get_contents(
|
||||
"https://api.lanisys.fr:50000/",
|
||||
false,
|
||||
$ctx
|
||||
);
|
||||
|
||||
$rep = file_get_contents(
|
||||
"https://api.lanisys.fr:50000/",
|
||||
false,
|
||||
$ctx
|
||||
);
|
||||
|
||||
$pos = strpos($rep, "https://");
|
||||
if ($pos !== false)
|
||||
{
|
||||
header("Location: ".substr($rep, $pos));
|
||||
exit;
|
||||
}
|
||||
else
|
||||
echo $rep;
|
||||
Reference in new issue
Block a user