Files
Alcea 85d22f38f0 Add files via upload
Uptime monitor for m7350 tplink to run from it locally
2026-01-10 17:47:56 +01:00

95 lines
2.7 KiB
Bash

#!/bin/sh
# Configuration
DOMAIN1="alceawis.de:response_code"
DOMAIN2="alceawis.com:file_check"
DOMAIN3="alcea-wisteria.de:response_code"
# Function to check if URL is accessible
check_url_accessible() {
wget -q -O /dev/null -T 10 "$1" 2>/dev/null
[ $? -eq 0 ] && echo "200" || echo "404"
}
# Function to check file existence
check_file_existence() {
wget -q -O /dev/null -T 10 "$1" 2>/dev/null
return $?
}
# Process each domain
for domain_config in "$DOMAIN1" "$DOMAIN2" "$DOMAIN3"; do
domain=$(echo "$domain_config" | cut -d: -f1)
mode=$(echo "$domain_config" | cut -d: -f2)
DATE=$(date '+%Y-%m-%d %H:%M:%S')
RESPONSE_CODE="404"
echo "Testing: $domain ($mode)..."
# Check based on mode
if [ "$mode" = "file_check" ]; then
if check_file_existence "http://$domain/favicon.png" || \
check_file_existence "http://$domain/index.html"; then
RESPONSE_CODE="200"
echo " Found file via HTTP: 200 OK"
elif check_file_existence "https://$domain/favicon.png" || \
check_file_existence "https://$domain/index.html"; then
RESPONSE_CODE="200"
echo " Found file via HTTPS: 200 OK"
else
RESPONSE_CODE="404"
echo " No files found: 404"
fi
elif [ "$mode" = "response_code" ]; then
RESPONSE_CODE=$(check_url_accessible "http://$domain")
if [ "$RESPONSE_CODE" = "200" ]; then
echo " HTTP accessible: 200"
else
RESPONSE_CODE=$(check_url_accessible "https://$domain")
if [ "$RESPONSE_CODE" = "200" ]; then
echo " HTTPS accessible: 200"
else
echo " Not accessible: 404"
fi
fi
fi
FILENAME="${domain}.json"
TEMPFILE="${FILENAME}.tmp"
# Clean approach: rebuild JSON completely
if [ -f "$FILENAME" ] && [ -s "$FILENAME" ]; then
# File exists and has content
# Remove closing bracket if present
sed 's/\]//' "$FILENAME" > "$TEMPFILE"
# Remove trailing comma from last line if present
sed -i '$ s/,$//' "$TEMPFILE"
# Add comma to end of file for new entry
echo "," >> "$TEMPFILE"
else
# Start new JSON array
echo "[" > "$TEMPFILE"
fi
# Add new entry
cat >> "$TEMPFILE" << JSON_ENTRY
{
"date": "$DATE",
"mode": "$mode",
"domainname": "$domain",
"response_code": $RESPONSE_CODE
}
]
JSON_ENTRY
# Replace original with temp file
mv "$TEMPFILE" "$FILENAME"
echo "Test result for $domain saved/updated in $FILENAME"
echo ""
done