progressioooooon

This commit is contained in:
Adrian Amaglio 2022-01-20 19:45:04 +01:00
parent a79f5cf687
commit d2acd917a8
8 changed files with 59 additions and 21 deletions

View File

@ -8,6 +8,7 @@ RUN apt-get update && apt-get install -y \
nano \ nano \
netcat \ netcat \
nginx \ nginx \
pandoc \
ssh \ ssh \
vim \ vim \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
@ -19,10 +20,13 @@ ENV TZ=Europe/Paris
# SSH server # SSH server
RUN mkdir /run/sshd RUN mkdir /run/sshd
CMD ["netcat", "-lp", "5000", "-e", "/root/http/http_bash.sh"] CMD ["sh", "-c", "while true ; do netcat -lp 5000 -e /root/http_bash.sh ; done"]
# Nginx conf # Nginx conf
COPY ./default /etc/nginx/sites-enabled/default COPY ./nginx-server.conf /etc/nginx/sites-enabled/default
# Bash HTTP website
COPY ./http_bash.sh ./http_bash.sh
# Entrypoint # Entrypoint
COPY ./entrypoint.sh ./entrypoint.sh COPY ./entrypoint.sh ./entrypoint.sh

View File

@ -6,6 +6,6 @@ services:
- ./config:/root/config - ./config:/root/config
- ./home_eleves:/home - ./home_eleves:/home
- ./exercices:/root/exercices - ./exercices:/root/exercices
- ./http:/root/http - ./exercices/html:/var/www/html
network_mode: "host" network_mode: "host"
restart: "unless-stopped" restart: "unless-stopped"

View File

@ -209,4 +209,4 @@ for i in {1..8} ; do
done done
pandoc --from=markdown --to=html --output=$html/$eleve.html --table-of-contents --columns=80 $enonces/ex*.txt pandoc --standalone --from=markdown --to=html --output=$html/$eleve.html --table-of-contents --columns=80 $enonces/ex*.txt

View File

@ -34,15 +34,25 @@ if echo $DIR | grep -v /$ > /dev/null ; then DIR=$DIR/ ; fi
mkdir -p $DIR$USER ; mkdir -p $DIR$USER ;
find $root -type d | shuf | head -n $folders > $DIR$USER/folders.seed if [[ ! -s $DIR$USER/folders.seed ]] ; then
find $root -type d | shuf | head -n $folders > $DIR$USER/folders.seed
echo folders
fi
find $root -type f | shuf | head -n $files > $DIR$USER/files.seed if [[ ! -s $DIR$USER/files.seed ]] ; then
find $root -type f | shuf | head -n $files > $DIR$USER/files.seed
echo files
fi
cat haddock.list | shuf | head -n $filenames > $DIR$USER/filenames.seed if [[ ! -s $DIR$USER/filenames.seed ]] ; then
cat haddock.list | shuf | head -n $filenames > $DIR$USER/filenames.seed
echo names
fi
if [[ -s $DIR$USER/ints.seed ]] ; then rm $DIR$USER/ints.seed ; fi if [[ ! -s $DIR$USER/ints.seed ]] ; then
for i in $(seq 1 $ints) ; do
for i in $(seq 1 $ints) ; do echo $((3 + $RANDOM % 13)) >> $DIR$USER/ints.seed
echo $((3 + $RANDOM % 13)) >> $DIR$USER/ints.seed done
done echo ints
fi

View File

@ -1,14 +1,23 @@
#!/bin/bash #!/bin/bash
if [ "$#" -ne 1 ] ; then if [ "$#" -ne 1 && "$#" -ne 2 ] ; then
echo -e "usage : $0 <FILE>\n\tGenerate the exercice for a class.\nFILE must be a list containing identifiers (names) and passwords for each student, separated by a '='.\n\tEx:\n\t\tJean-claude-dus=mot_de_passe\n\t\tJean-dus-claude=passe_de_mot\n\t\tClaude-jean-dus=azerty\n\nThis file must be executed from the same folder as the files gen_arbo.sh, gen_seed.sh and gen_enonces.sh.\nFolders will be created in this directory, containing the exercices, their correction and the grades of the students." echo -e "usage : $0 <FILE> [USER]\n Generate the exercice for a class.\nFILE must be a list containing identifiers (names) and passwords for each student, separated by a '='.\n Ex:\n Jean-claude-dus=mot_de_passe\n Jean-dus-claude=passe_de_mot\n Claude-jean-dus=azerty\nIf a USER is provided, init will only be run for that user (useful to add a student mid-class, reset a session when something went horribly wrong, or if a student finished early and wants to start over.\n\nThis file must be executed from the same folder as the files gen_arbo.sh, gen_seed.sh and gen_enonces.sh.\nFolders will be created in this directory, containing the exercices, their correction and the grades of the students."
exit 1; exit 1;
fi fi
cat $1
home=/home home=/home
#Little debug option for one of the devs. If we forgot to remove it before deployment, feel free to erase this line.
if [ $USER = karsaell ] ; then home=root ; fi
names=$(cut -d '=' -f 1 $1) names=$(cut -d '=' -f 1 $1)
if [ "$#" -eq 2 ] ; then
names=$(grep $2 $1 | cut -d '=' -f 1)
if [ -z $names ] ; then
echo "Error : no user named $2 found in $1"
exit 1
fi
fi
for name in $names ; do for name in $names ; do
./gen_arbo.sh $home/$name $name ./gen_arbo.sh $home/$name $name

View File

@ -58,9 +58,23 @@ serve_static_string() {
send_response_ok_exit <<< "$1" send_response_ok_exit <<< "$1"
} }
where () {
h="$(dirname "$0")"
# If $h isnt absolute, prepend working dir
if [[ ! "${h:0:1}" = "/" ]] ; then
h="$(pwd)/$(dirname "$0")"
fi
h="$(realpath "$h")"
echo "$h"
}
main () { main () {
# Request uri must be a relative path from the exercices/corriges directory
[ -x "$REQUEST_URI" ] || [ ! -d "$REQUEST_URI" ] || fail_with 404 [ -x "$REQUEST_URI" ] || [ ! -d "$REQUEST_URI" ] || fail_with 404
serve_static_string "$(basename "$REQUEST_URI" | cut -d '.' -f 1) : $(sh "$REQUEST_URI" 2>&1 && echo Ok || echo 'Non validé')" here="$(where)"
path="$(realpath "$here/exercices/corriges/$REQUEST_URI")"
[[ "$path" = "$here"* ]] || fail_with 404
serve_static_string "$(basename "$path" | cut -d '.' -f 1) : $(bash "$path" 2>&1 && echo Ok || echo 'Non validé')"
} }
# Request-Line HTTP RFC 2616 $5.1 # Request-Line HTTP RFC 2616 $5.1

View File

@ -2,7 +2,7 @@ server {
listen 80 default_server; listen 80 default_server;
listen [::]:80 default_server; listen [::]:80 default_server;
root /root/exercices/html; root /var/www/html;
index index.html; index index.html;
@ -12,10 +12,11 @@ server {
# First attempt to serve request as file, then # First attempt to serve request as file, then
# as directory, then fall back to displaying a 404. # as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
add_header Content-Type 'text/html;';
autoindex on; autoindex on;
} }
location ~ /.sh$ { location ~ \.sh$ {
proxy_pass http://127.0.0.1:5000; proxy_pass http://127.0.0.1:5000;
} }

View File

@ -18,7 +18,7 @@ Chaque élève a un dossier perso dans `/home` dans lequel il peut se connecter
## Génération de lactivité ## Génération de lactivité
``` ```
cd exercices cd exercices
./init.sh ./init.sh ../config/passwords.txt
``` ```
## Énoncés des exercices ## Énoncés des exercices
@ -29,7 +29,7 @@ Si un·e élève a saccagé ses fichiers, il est possible de les réparer en lan
$username est son nom dutilisateurice. $username est son nom dutilisateurice.
``` ```
cd exercices cd exercices
./init.sh $username ./init.sh ../config/passwords.txt $username
``` ```
## Ajouter des élèves en cours de route ## Ajouter des élèves en cours de route