#!/bin/bash
echo "Content-type: text/html"
echo ""
# Log the raw POST data for debugging
read POST_DATA
echo "POST Data: $POST_DATA" >> /tmp/forgot_password.log
# URL decoding function
urldecode() {
local url_encoded="${1//+/ }"
printf '%b' "${url_encoded//%/\\x}"
}
# Parse the form data using IFS
USERNAME=""
EMAIL=""
IFS='&' # Split fields by "&"
for param in $POST_DATA; do
IFS='=' read -r key value <<< "$param"
key=$(urldecode "$key")
value=$(urldecode "$value")
case $key in
username) USERNAME="$value" ;;
email) EMAIL="$value" ;;
esac
done
# Check if the user exists in the database
DB_PATH="/var/lib/monotreme/data/monotreme .db"
USER_EXISTS=$(sqlite3 $DB_PATH "SELECT COUNT(*) FROM users WHERE username='$USERNAME' AND email='$EMAIL';")
if [ "$USER_EXISTS" -eq 0 ]; then
cat <
Reset Failed
User not found!
Try again