#!/bin/bash set -o pipefail set -o errexit echo -en "Status: 200 OK\r\n" echo -en "Content-type: text/plain;charset=UTF-8\r\n\r\n" trap ' echo -- echo User Agent: $HTTP_USER_AGENT echo IP Address: $REMOTE_ADDR echo echo mehdix.ir ' EXIT # Read $CONTENT_LENGTH bytes into POST_STRING variable. # This applies only to POST requests. # or VAR=$(cat) for multiline input #read POST_STRING POST_STRING=$(cat) # https://stackoverflow.com/a/37840948/ function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } saveIFS=$IFS IFS='=&' parm=($POST_STRING) IFS=$saveIFS # https://stackoverflow.com/a/3919908/ for ((i=0; i<${#parm[@]}; i+=2)) do # Convert dashes to underscores and define a variable varname=var_$( echo ${parm[i]} | sed s/-/_/ ) declare $varname="$(urldecode ${parm[i+1]})" #echo "${varname}=${!varname}" done # Make sure mandatory fields are present ([ -z "$var_message" ] || [ -z "$var_name" ] || [ -z "$var_email" ]) && { echo "لطفا برای ثبت دیدگاه متن و نام و ایمیل را وارد کنید." echo "mehdix.ir: missing mandatory form fields." >&2 exit 1 } # Make sure anti spam field is present and correct ([ -z "$var_puzzle" ] || [ "$var_puzzle" != "$ALEF_PUZZLE" ]) && { echo "معما رو درست حل نکردی رفیق. نمی‌شه، شرمنده." echo "mehdix.ir: wrong puzzle." >&2 exit 1 } true && [ -n "$var_reply_to" ] && { #echo is a reply: $var_reply_to #echo getting the email of the OP op_email_query=$(cat <<-EOF SELECT DISTINCT email FROM comments WHERE id = "$var_reply_to" or legacy_id = "$var_reply_to"; EOF ) op_email=$(sqlite3 "$ALEF_DB" "$op_email_query") #echo "$op_email" } false && [ -n "$var_website" ] && { echo has a websitie: $var_website } false && [ -n "$var_page_id" ] && { echo has a page id: $var_page_id } # Initialize DB if not exists [ ! -f "$ALEF_DB" ] && { cat <