#!/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 EOF exit 1 fi # Generate a unique token for resetting the password TOKEN=$(openssl rand -hex 16) # Set token expiration to 1 hour from now (Unix timestamp) EXPIRATION=$(($(date +%s) + 3600)) # Store the reset token and expiration in the database sqlite3 $DB_PATH "UPDATE users SET reset_token='$TOKEN', reset_expires=$EXPIRATION WHERE username='$USERNAME';" # Send reset link email RESET_LINK="https://monotreme.org/cgi-bin/reset_password.cgi?token=$TOKEN" EMAIL_BODY=$(cat <> /tmp/forgot_password.log # Send the email echo "$EMAIL_BODY" | msmtp --account=monotreme "$EMAIL" # Response back to the browser cat < Password Reset Sent

Reset link sent!

A reset link has been sent to $EMAIL. Please check your email.

Go to login page EOF