diff --git a/install_elog.sh b/install_elog.sh index 5ce4ab32..d05ceab2 100644 --- a/install_elog.sh +++ b/install_elog.sh @@ -1,45 +1,60 @@ #!/bin/bash +set -e + +# ======================= +# 1. Télécharger et compiler ELOG +# ======================= +rm -rf /tmp/elog-build && mkdir -p /tmp/elog-build +cd /tmp/elog-build +git clone --recursive https://bitbucket.org/ritt/elog +cd elog +make -j"$(nproc)" +mkdir -p "$HOME/.local/bin" +cp elogd "$HOME/.local/bin/" +export PATH="$HOME/.local/bin:$PATH" + +# ======================= +# 2. Préparer l'instance +# ======================= INSTANCE_DIR="/tmp/elog_instance" -mkdir -p "$INSTANCE_DIR/logbooks/demo" +LOGBOOK_DIR="$INSTANCE_DIR/logbooks/demo" +YEAR_DIR="$LOGBOOK_DIR/$(date +%Y)" +mkdir -p "$YEAR_DIR" + +chmod 1777 /tmp chmod -R 777 "$INSTANCE_DIR" -# Génération des hashes avec elogd -MD5_PASS=$(~/.local/bin/elogd -P testpassword md5) -SHA1_PASS=$(~/.local/bin/elogd -P testpassword sha1) -CRYPT_PASS=$(~/.local/bin/elogd -P testpassword crypt) - -# Création du fichier users.xml avec plusieurs utilisateurs +# ======================= +# 3. Créer users.xml (mot de passe en clair) +# ======================= cat > "$INSTANCE_DIR/users.xml" < - - clear + robot testpassword - Clear Password - - - - md5 - ${MD5_PASS} - MD5 Password - - - - sha1 - ${SHA1_PASS} - SHA1 Password - - - - crypt - ${CRYPT_PASS} - Crypt Password + Robot User + 0 + 0 + robot@example.com EOF -# Config ELOG pour qu'il lise ce fichier +sudo chown nobody:nogroup "$INSTANCE_DIR/users.xml" +chmod 644 "$INSTANCE_DIR/users.xml" + +# DEBUG users.xml +echo "=== DEBUG: droits users.xml ===" +ls -l "$INSTANCE_DIR/users.xml" +echo "=== DEBUG: contenu users.xml ===" +cat "$INSTANCE_DIR/users.xml" +echo "=== DEBUG: qui peut lire ? ===" +sudo -u nobody cat "$INSTANCE_DIR/users.xml" || echo "❌ nobody ne peut pas lire" + +# ======================= +# 4. Configuration ELOG +# ======================= cat > "$INSTANCE_DIR/elogd.cfg" </dev/null || true ~/.local/bin/elogd -c "$INSTANCE_DIR/elogd.cfg" -vvv & sleep 2 -# Tester toutes les combinaisons -for user in clear md5 sha1 crypt; do - echo "=== Test connexion: $user:testpassword ===" - RESPONSE=$(curl -s -u "$user:testpassword" http://localhost:8080/demo) - if echo "$RESPONSE" | grep -q "redir"; then - echo "❌ Échec pour $user" +echo "✅ ELOG démarré sur http://localhost:8080" +echo " → Utilisateur : robot" +echo " → Mot de passe : testpassword" + +# ======================= +# 6. Tester différentes combinaisons de mot de passe +# ======================= +function test_connexion() { + local mode=$1 + local pwd=$2 + + echo "=== Test connexion: $mode:$pwd ===" + RESP=$(curl -s -u "robot:$pwd" http://localhost:8080/demo) + if [[ "$RESP" == *"List of Messages"* || "$RESP" == *"redir"* ]]; then + echo "✅ Succès pour $mode" else - echo "✅ Succès pour $user" + echo "❌ Échec pour $mode" fi -done +} + +# Test clair +test_connexion "clear" "testpassword" + +# Test md5 +MD5PWD=$(echo -n "testpassword" | md5sum | awk '{print $1}') +sed -i "s|.*|$MD5PWD|" "$INSTANCE_DIR/users.xml" +test_connexion "md5" "testpassword" + +# Test sha1 +SHA1PWD=$(echo -n "testpassword" | sha1sum | awk '{print $1}') +sed -i "s|.*|$SHA1PWD|" "$INSTANCE_DIR/users.xml" +test_connexion "sha1" "testpassword" + +# Test crypt +CRYPTPWD=$(openssl passwd -crypt "testpassword") +sed -i "s|.*|$CRYPTPWD|" "$INSTANCE_DIR/users.xml" +test_connexion "crypt" "testpassword" + +echo "=== Tests terminés ==="