#!/bin/bash echo "Content-type: text/html" echo "" # Log the raw POST data for debugging read POST_DATA echo "POST Data: $POST_DATA" >> /tmp/register_form.log # URL decoding function urldecode() { local url_encoded="${1//+/ }" printf '%b' "${url_encoded//%/\\x}" } # Parse the form data using IFS USERNAME="" EMAIL="" PASSWORD="" CONFIRM_PASSWORD="" 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" ;; password) PASSWORD="$value" ;; confirm_password) CONFIRM_PASSWORD="$value" ;; esac done # Check if passwords match if [ "$PASSWORD" != "$CONFIRM_PASSWORD" ]; then cat < Registration Failed

Passwords do not match!

Go back EOF exit 1 fi # Hash the password using SHA-256 PASSWORD_HASH=$(echo -n "$PASSWORD" | sha256sum | awk '{print $1}') # Insert the user into the SQLite database DB_PATH="/var/lib/monotreme/data/monotreme.db" sqlite3 $DB_PATH "INSERT INTO users (username, email, password_hash) VALUES ('$USERNAME', '$EMAIL', '$PASSWORD_HASH');" 2>> /tmp/register_form.log # Log the username and email for debugging echo "Username: $USERNAME, Email: $EMAIL" >> /tmp/register_form.log # Create the email with proper headers EMAIL_BODY=$(cat <> /tmp/register_form.log # Send the email using msmtp (or your protonmail-bridge setup) echo "$EMAIL_BODY" | msmtp --from=default "$EMAIL" # Response back to the browser cat < Registration Successful

Registration successful!

A confirmation email has been sent to $EMAIL.

Go to login page EOF