diff --git a/caldav-test.sh b/caldav-test.sh new file mode 100755 index 0000000..ff17d61 --- /dev/null +++ b/caldav-test.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# Konfiguration +USERNAME="vollstock" +PASSWORD="bBm1AxSkE-tiw-_LXRicPQ" +TIMEOUT=10 + +# Farben für die Ausgabe +BLACK=$(tput setaf 0) +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +YELLOW=$(tput setaf 3) +LIME_YELLOW=$(tput setaf 190) +POWDER_BLUE=$(tput setaf 153) +BLUE=$(tput setaf 4) +MAGENTA=$(tput setaf 5) +CYAN=$(tput setaf 6) +WHITE=$(tput setaf 7) +GRAY=$(tput setaf 240) +BRIGHT=$(tput bold) +NORMAL=$(tput sgr0) +BLINK=$(tput blink) +REVERSE=$(tput smso) +UNDERLINE=$(tput smul) + + +# Funktion zum Formatieren der Ausgabe +format_output() { + local label=$1 + local result=$2 + local success=$3 + local output=$4 + local max_width=72 + + # Kürze das Label, falls es zu lang ist + if [ ${#label} -gt $((max_width - 20)) ]; then + label="${label:0:$((max_width - 20))}" + fi + + # Berechne die Anzahl der Punkte, die zwischen Label und Ergebnis eingefügt werden sollen + dots_count=$((max_width - ${#label} - ${#result} - 4)) # 4 für die Klammern und Leerzeichen + + # Erstelle die Punkte-Zeichenkette + dots=$(printf '%*s' "$dots_count" | tr ' ' '.') + + # Bestimme die Farbe für das Ergebnis + if [ "$success" = true ]; then + result_color=$GREEN + elif [ "$success" = false ]; then + result_color=$RED + else + result_color=$YELLOW + fi + + # Ausgabe formatieren + printf "%s%s%s %s%s%s [%s%s%s]\n\n" "$MAGENTA" "$label" "$NORMAL" "$GRAY" "$dots" "$NORMAL" "$result_color" "$result" "$NORMAL" + printf "%s\n\n" "$output" +} + +# Funktion zum Ausführen des Curl-Befehls und Formatieren der Ausgabe +run_test() { + label=$1 + url=$2 + method=$3 + depth=$4 + local curl_output + + curl_output=$(curl -s -w "\nHTTP Status: %{http_code}" \ + --max-time "$TIMEOUT" \ + -u "$USERNAME:$PASSWORD" \ + -H "Depth: $depth; Content-Type: application/xml" \ + -X $method \ + "$url") + + status_code=$(echo "$curl_output" | tail -n 1 | awk '{print $3}') + + if [ "$status_code" -gt 400 ]; then + success=false + else + success=true + fi + + # Ausgabe formatieren + format_output "$label" "$status_code" "$success" "$curl_output" + +} + +# Hauptfunktion +main() { + echo '' + # | label | url | method | depth + # |--------------|---------------------------------------------------------------------------------------------------|-------------| -------- + run_test "Base URL" "https://cloud.tooloop.de/remote.php/dav/" "GET" 0 + run_test "Principal" "https://cloud.tooloop.de/remote.php/dav/principals/users/vollstock" "PROPFIND" 1 + run_test "Calendars" "https://cloud.tooloop.de/remote.php/dav/calendars/vollstock" "PROPFIND" 1 + run_test "Calendar Info" "https://cloud.tooloop.de/remote.php/dav/calendars/vollstock/migrated-6E79619D-F037-413E-9FC2-46EA716E5CB3" "PROPFIND" 1 + echo '' +} + +# Skript ausführen +main \ No newline at end of file