diff --git a/Scripts/Billing/dkim-verify.sh b/Scripts/Billing/dkim-verify.sh index 321d4d6..f14f639 100755 --- a/Scripts/Billing/dkim-verify.sh +++ b/Scripts/Billing/dkim-verify.sh @@ -4,7 +4,7 @@ # Written by John Ryland # Copyright 2015 # -# Usage: dkim-verify.sh raw-email.txt +# Usage: dkim-verify.sh tmp-path raw-email.txt # # Returns: # 0 if success and verifies OK @@ -13,9 +13,10 @@ # PROGRAM_NAME=`basename $0` -INPUT=$1 +TEMPDIR=$1 +INPUT=$2 -if [ "$#" != "1" ] +if [ "$#" != "2" ] then echo "$PROGRAM_NAME: Invalid number of parameters" exit -1 @@ -27,17 +28,12 @@ exit -1 fi -mkdir -p $HOME/tmp -TEMPDIR=`mktemp -d -p $HOME/tmp` - if [ ! -d "$TEMPDIR" ] then - echo "$PROGRAM_NAME: Error creating temp directory" + echo "$PROGRAM_NAME: Error, tempdir is not a directory" exit -1 fi -echo "TEMPDIR=$TEMPDIR" - cat << EOF > $TEMPDIR/parameters.sh DKIM_VERSION=0 DKIM_ALGORITHM=rsa-sha256 diff --git a/Scripts/Billing/dkim-verify.sh b/Scripts/Billing/dkim-verify.sh index 321d4d6..f14f639 100755 --- a/Scripts/Billing/dkim-verify.sh +++ b/Scripts/Billing/dkim-verify.sh @@ -4,7 +4,7 @@ # Written by John Ryland # Copyright 2015 # -# Usage: dkim-verify.sh raw-email.txt +# Usage: dkim-verify.sh tmp-path raw-email.txt # # Returns: # 0 if success and verifies OK @@ -13,9 +13,10 @@ # PROGRAM_NAME=`basename $0` -INPUT=$1 +TEMPDIR=$1 +INPUT=$2 -if [ "$#" != "1" ] +if [ "$#" != "2" ] then echo "$PROGRAM_NAME: Invalid number of parameters" exit -1 @@ -27,17 +28,12 @@ exit -1 fi -mkdir -p $HOME/tmp -TEMPDIR=`mktemp -d -p $HOME/tmp` - if [ ! -d "$TEMPDIR" ] then - echo "$PROGRAM_NAME: Error creating temp directory" + echo "$PROGRAM_NAME: Error, tempdir is not a directory" exit -1 fi -echo "TEMPDIR=$TEMPDIR" - cat << EOF > $TEMPDIR/parameters.sh DKIM_VERSION=0 DKIM_ALGORITHM=rsa-sha256 diff --git a/Scripts/Billing/email-template.sh b/Scripts/Billing/email-template.sh index fca45e4..8e63a5a 100755 --- a/Scripts/Billing/email-template.sh +++ b/Scripts/Billing/email-template.sh @@ -1,14 +1,15 @@ #!/bin/bash -CUSTOMER_NAME='John Ryland' -CUSTOMER_EMAIL='John Ryland ' -PRODUCT_NAME='WickedDocs v1.0' -PAYMENT='$0.99' -CONTACT='support@subflexion.com' +CUSTOMER_NAME="$1" +CUSTOMER_EMAIL="$2" +PRODUCT_NAME="$3" +DETAILS="Quantity: $4" +PAYMENT="$5" +BILLING_EMAIL="Subflexion Billing " +CONTACT="support@subflexion.com" DATE=`date -R` -DETAILS='order details ...' -cat << EOF | mailx -a "From: Subflexion Billing " -s "Order Processed" "$CUSTOMER_EMAIL" +cat - "$6" << EOF | mailx -a "From: $BILLING_EMAIL" -s "Order Processed" "$CUSTOMER_NAME <$CUSTOMER_EMAIL>" Dear $CUSTOMER_NAME, @@ -38,7 +39,8 @@ If any of the details are not correct, please contact us at $CONTACT. -We will send you an invoice and your license key soon. If you do not recieve these in the next 12 hours, please contact us as $CONTACT. +We will send you an invoice soon. If you do not recieve this in the next 24 hours, please contact us as $CONTACT. +Please find attached your license key. Kind regards, diff --git a/Scripts/Billing/dkim-verify.sh b/Scripts/Billing/dkim-verify.sh index 321d4d6..f14f639 100755 --- a/Scripts/Billing/dkim-verify.sh +++ b/Scripts/Billing/dkim-verify.sh @@ -4,7 +4,7 @@ # Written by John Ryland # Copyright 2015 # -# Usage: dkim-verify.sh raw-email.txt +# Usage: dkim-verify.sh tmp-path raw-email.txt # # Returns: # 0 if success and verifies OK @@ -13,9 +13,10 @@ # PROGRAM_NAME=`basename $0` -INPUT=$1 +TEMPDIR=$1 +INPUT=$2 -if [ "$#" != "1" ] +if [ "$#" != "2" ] then echo "$PROGRAM_NAME: Invalid number of parameters" exit -1 @@ -27,17 +28,12 @@ exit -1 fi -mkdir -p $HOME/tmp -TEMPDIR=`mktemp -d -p $HOME/tmp` - if [ ! -d "$TEMPDIR" ] then - echo "$PROGRAM_NAME: Error creating temp directory" + echo "$PROGRAM_NAME: Error, tempdir is not a directory" exit -1 fi -echo "TEMPDIR=$TEMPDIR" - cat << EOF > $TEMPDIR/parameters.sh DKIM_VERSION=0 DKIM_ALGORITHM=rsa-sha256 diff --git a/Scripts/Billing/email-template.sh b/Scripts/Billing/email-template.sh index fca45e4..8e63a5a 100755 --- a/Scripts/Billing/email-template.sh +++ b/Scripts/Billing/email-template.sh @@ -1,14 +1,15 @@ #!/bin/bash -CUSTOMER_NAME='John Ryland' -CUSTOMER_EMAIL='John Ryland ' -PRODUCT_NAME='WickedDocs v1.0' -PAYMENT='$0.99' -CONTACT='support@subflexion.com' +CUSTOMER_NAME="$1" +CUSTOMER_EMAIL="$2" +PRODUCT_NAME="$3" +DETAILS="Quantity: $4" +PAYMENT="$5" +BILLING_EMAIL="Subflexion Billing " +CONTACT="support@subflexion.com" DATE=`date -R` -DETAILS='order details ...' -cat << EOF | mailx -a "From: Subflexion Billing " -s "Order Processed" "$CUSTOMER_EMAIL" +cat - "$6" << EOF | mailx -a "From: $BILLING_EMAIL" -s "Order Processed" "$CUSTOMER_NAME <$CUSTOMER_EMAIL>" Dear $CUSTOMER_NAME, @@ -38,7 +39,8 @@ If any of the details are not correct, please contact us at $CONTACT. -We will send you an invoice and your license key soon. If you do not recieve these in the next 12 hours, please contact us as $CONTACT. +We will send you an invoice soon. If you do not recieve this in the next 24 hours, please contact us as $CONTACT. +Please find attached your license key. Kind regards, diff --git a/Scripts/Billing/postfix-filter b/Scripts/Billing/postfix-filter index 372068b..8ca9e37 100644 --- a/Scripts/Billing/postfix-filter +++ b/Scripts/Billing/postfix-filter @@ -1 +1 @@ -"| /home/subflexion_billing/process-mail.sh" +"| /home/subflexion_billing/Scripts/Billing/process-mail.sh" diff --git a/Scripts/Billing/dkim-verify.sh b/Scripts/Billing/dkim-verify.sh index 321d4d6..f14f639 100755 --- a/Scripts/Billing/dkim-verify.sh +++ b/Scripts/Billing/dkim-verify.sh @@ -4,7 +4,7 @@ # Written by John Ryland # Copyright 2015 # -# Usage: dkim-verify.sh raw-email.txt +# Usage: dkim-verify.sh tmp-path raw-email.txt # # Returns: # 0 if success and verifies OK @@ -13,9 +13,10 @@ # PROGRAM_NAME=`basename $0` -INPUT=$1 +TEMPDIR=$1 +INPUT=$2 -if [ "$#" != "1" ] +if [ "$#" != "2" ] then echo "$PROGRAM_NAME: Invalid number of parameters" exit -1 @@ -27,17 +28,12 @@ exit -1 fi -mkdir -p $HOME/tmp -TEMPDIR=`mktemp -d -p $HOME/tmp` - if [ ! -d "$TEMPDIR" ] then - echo "$PROGRAM_NAME: Error creating temp directory" + echo "$PROGRAM_NAME: Error, tempdir is not a directory" exit -1 fi -echo "TEMPDIR=$TEMPDIR" - cat << EOF > $TEMPDIR/parameters.sh DKIM_VERSION=0 DKIM_ALGORITHM=rsa-sha256 diff --git a/Scripts/Billing/email-template.sh b/Scripts/Billing/email-template.sh index fca45e4..8e63a5a 100755 --- a/Scripts/Billing/email-template.sh +++ b/Scripts/Billing/email-template.sh @@ -1,14 +1,15 @@ #!/bin/bash -CUSTOMER_NAME='John Ryland' -CUSTOMER_EMAIL='John Ryland ' -PRODUCT_NAME='WickedDocs v1.0' -PAYMENT='$0.99' -CONTACT='support@subflexion.com' +CUSTOMER_NAME="$1" +CUSTOMER_EMAIL="$2" +PRODUCT_NAME="$3" +DETAILS="Quantity: $4" +PAYMENT="$5" +BILLING_EMAIL="Subflexion Billing " +CONTACT="support@subflexion.com" DATE=`date -R` -DETAILS='order details ...' -cat << EOF | mailx -a "From: Subflexion Billing " -s "Order Processed" "$CUSTOMER_EMAIL" +cat - "$6" << EOF | mailx -a "From: $BILLING_EMAIL" -s "Order Processed" "$CUSTOMER_NAME <$CUSTOMER_EMAIL>" Dear $CUSTOMER_NAME, @@ -38,7 +39,8 @@ If any of the details are not correct, please contact us at $CONTACT. -We will send you an invoice and your license key soon. If you do not recieve these in the next 12 hours, please contact us as $CONTACT. +We will send you an invoice soon. If you do not recieve this in the next 24 hours, please contact us as $CONTACT. +Please find attached your license key. Kind regards, diff --git a/Scripts/Billing/postfix-filter b/Scripts/Billing/postfix-filter index 372068b..8ca9e37 100644 --- a/Scripts/Billing/postfix-filter +++ b/Scripts/Billing/postfix-filter @@ -1 +1 @@ -"| /home/subflexion_billing/process-mail.sh" +"| /home/subflexion_billing/Scripts/Billing/process-mail.sh" diff --git a/Scripts/Billing/process-mail.sh b/Scripts/Billing/process-mail.sh index 4c11c38..7206738 100755 --- a/Scripts/Billing/process-mail.sh +++ b/Scripts/Billing/process-mail.sh @@ -1,21 +1,39 @@ #!/bin/bash +BILLING_PATH="$HOME/Scripts/Billing" -mailfile=`mktemp` -cat - > $mailfile +echo "-----------------------------------------------" >> $HOME/process.log +echo "Got Mail!" >> $HOME/process.log +mkdir -p $HOME/tmp +TEMPDIR=`mktemp -d -p $HOME/tmp` +if [ ! -d "$TEMPDIR" ] +then + echo " $PROGRAM_NAME: Error creating temp directory" >> $HOME/process.log + exit -1 +fi -echo "Environment:" >> ~/emails.txt -set >> ~/emails.txt -echo "Sender:" >> ~/emails.txt -echo $SENDER >> ~/emails.txt -echo "Got the following email: " >> ~/emails.txt -cat $mailfile >> ~/emails.txt +echo "TEMPDIR=$TEMPDIR" >> $HOME/process.log +echo "Environment:" > $TEMPDIR/env.txt +set >> $TEMPDIR/env.txt -# Now you have your email on the temporary file -# pointed by $mailfile and can do whatever you want. -# Just don't forget to end the program with: +MAILFILE=$TEMPDIR/email.txt +cat - > $MAILFILE -rm $mailfile +$BILLING_PATH/process-order.sh $TEMPDIR $MAILFILE >> $HOME/process.log + +# Cleanup temporary files +if [ -d "$TEMPDIR" ] +then + if [ `dirname $TEMPDIR` == "$HOME/tmp" ] + then + # If debugged and don't want to store the intermediate files + # then remove the temp files. + # For now it is probably better not to delete these though + #rm -rf $TEMPDIR + echo "Done!" >> $HOME/process.log + echo "===============================================" >> $HOME/process.log + fi +fi diff --git a/Scripts/Billing/dkim-verify.sh b/Scripts/Billing/dkim-verify.sh index 321d4d6..f14f639 100755 --- a/Scripts/Billing/dkim-verify.sh +++ b/Scripts/Billing/dkim-verify.sh @@ -4,7 +4,7 @@ # Written by John Ryland # Copyright 2015 # -# Usage: dkim-verify.sh raw-email.txt +# Usage: dkim-verify.sh tmp-path raw-email.txt # # Returns: # 0 if success and verifies OK @@ -13,9 +13,10 @@ # PROGRAM_NAME=`basename $0` -INPUT=$1 +TEMPDIR=$1 +INPUT=$2 -if [ "$#" != "1" ] +if [ "$#" != "2" ] then echo "$PROGRAM_NAME: Invalid number of parameters" exit -1 @@ -27,17 +28,12 @@ exit -1 fi -mkdir -p $HOME/tmp -TEMPDIR=`mktemp -d -p $HOME/tmp` - if [ ! -d "$TEMPDIR" ] then - echo "$PROGRAM_NAME: Error creating temp directory" + echo "$PROGRAM_NAME: Error, tempdir is not a directory" exit -1 fi -echo "TEMPDIR=$TEMPDIR" - cat << EOF > $TEMPDIR/parameters.sh DKIM_VERSION=0 DKIM_ALGORITHM=rsa-sha256 diff --git a/Scripts/Billing/email-template.sh b/Scripts/Billing/email-template.sh index fca45e4..8e63a5a 100755 --- a/Scripts/Billing/email-template.sh +++ b/Scripts/Billing/email-template.sh @@ -1,14 +1,15 @@ #!/bin/bash -CUSTOMER_NAME='John Ryland' -CUSTOMER_EMAIL='John Ryland ' -PRODUCT_NAME='WickedDocs v1.0' -PAYMENT='$0.99' -CONTACT='support@subflexion.com' +CUSTOMER_NAME="$1" +CUSTOMER_EMAIL="$2" +PRODUCT_NAME="$3" +DETAILS="Quantity: $4" +PAYMENT="$5" +BILLING_EMAIL="Subflexion Billing " +CONTACT="support@subflexion.com" DATE=`date -R` -DETAILS='order details ...' -cat << EOF | mailx -a "From: Subflexion Billing " -s "Order Processed" "$CUSTOMER_EMAIL" +cat - "$6" << EOF | mailx -a "From: $BILLING_EMAIL" -s "Order Processed" "$CUSTOMER_NAME <$CUSTOMER_EMAIL>" Dear $CUSTOMER_NAME, @@ -38,7 +39,8 @@ If any of the details are not correct, please contact us at $CONTACT. -We will send you an invoice and your license key soon. If you do not recieve these in the next 12 hours, please contact us as $CONTACT. +We will send you an invoice soon. If you do not recieve this in the next 24 hours, please contact us as $CONTACT. +Please find attached your license key. Kind regards, diff --git a/Scripts/Billing/postfix-filter b/Scripts/Billing/postfix-filter index 372068b..8ca9e37 100644 --- a/Scripts/Billing/postfix-filter +++ b/Scripts/Billing/postfix-filter @@ -1 +1 @@ -"| /home/subflexion_billing/process-mail.sh" +"| /home/subflexion_billing/Scripts/Billing/process-mail.sh" diff --git a/Scripts/Billing/process-mail.sh b/Scripts/Billing/process-mail.sh index 4c11c38..7206738 100755 --- a/Scripts/Billing/process-mail.sh +++ b/Scripts/Billing/process-mail.sh @@ -1,21 +1,39 @@ #!/bin/bash +BILLING_PATH="$HOME/Scripts/Billing" -mailfile=`mktemp` -cat - > $mailfile +echo "-----------------------------------------------" >> $HOME/process.log +echo "Got Mail!" >> $HOME/process.log +mkdir -p $HOME/tmp +TEMPDIR=`mktemp -d -p $HOME/tmp` +if [ ! -d "$TEMPDIR" ] +then + echo " $PROGRAM_NAME: Error creating temp directory" >> $HOME/process.log + exit -1 +fi -echo "Environment:" >> ~/emails.txt -set >> ~/emails.txt -echo "Sender:" >> ~/emails.txt -echo $SENDER >> ~/emails.txt -echo "Got the following email: " >> ~/emails.txt -cat $mailfile >> ~/emails.txt +echo "TEMPDIR=$TEMPDIR" >> $HOME/process.log +echo "Environment:" > $TEMPDIR/env.txt +set >> $TEMPDIR/env.txt -# Now you have your email on the temporary file -# pointed by $mailfile and can do whatever you want. -# Just don't forget to end the program with: +MAILFILE=$TEMPDIR/email.txt +cat - > $MAILFILE -rm $mailfile +$BILLING_PATH/process-order.sh $TEMPDIR $MAILFILE >> $HOME/process.log + +# Cleanup temporary files +if [ -d "$TEMPDIR" ] +then + if [ `dirname $TEMPDIR` == "$HOME/tmp" ] + then + # If debugged and don't want to store the intermediate files + # then remove the temp files. + # For now it is probably better not to delete these though + #rm -rf $TEMPDIR + echo "Done!" >> $HOME/process.log + echo "===============================================" >> $HOME/process.log + fi +fi diff --git a/Scripts/Billing/process-order.sh b/Scripts/Billing/process-order.sh index 59a92c0..cce7a33 100755 --- a/Scripts/Billing/process-order.sh +++ b/Scripts/Billing/process-order.sh @@ -1,7 +1,9 @@ #!/bin/bash BILLING_PATH="$HOME/Scripts/Billing" -OUTPUT=`$BILLING_PATH/dkim-verify.sh $1` +TEMPDIR=$1 +INPUT=$2 +OUTPUT=`$BILLING_PATH/dkim-verify.sh $TEMPDIR $INPUT` RESULT=$? if [ "$RESULT" != "0" ] then @@ -9,15 +11,6 @@ exit $RESULT fi -KEY=`echo $OUTPUT | cut -d '=' -f 1` -VAL=`echo $OUTPUT | cut -d '=' -f 2- | cut -d ' ' -f 1` -if [ "$KEY" == "TEMPDIR" ] -then - TEMPDIR=$VAL -fi - -# echo "tempdir = -$TEMPDIR-" - echo > $TEMPDIR/check-params.sh cat $TEMPDIR/cheaders.txt | while read LINE do @@ -40,6 +33,9 @@ done echo >> $TEMPDIR/check-params.sh +# TODO: Need to really check the domain is from paypal, the only way to properly check is +# checking the DKIM signature domain and that it is one controlled by PayPal + . $TEMPDIR/check-params.sh echo > $TEMPDIR/plain-body.txt @@ -118,19 +114,25 @@ exit -1 fi -if [ "$ITEM" == "Item no.v1.0" ] +# if [ "$ITEM" == "Item no.v1.0" ] +if [ "$ITEM" == "Item no.Site License" ] then echo "Found requested stock item" - if [ "$UNIT_PRICE" != "\$0.99 USD" ] + # if [ "$UNIT_PRICE" != "\$0.05 USD" ] + if [ "$UNIT_PRICE" != "\$0.05 AUD" ] then echo "Price mismatch:" - echo " -$UNIT_PRICE- != \$0.99 USD" + # echo " -$UNIT_PRICE- != \$0.05 USD" + echo " -$UNIT_PRICE- != \$0.05 AUD" echo " Prices changed, but this script not updated?" echo " Or potentially someone is trying to make a paypal payment with the correct details except for the price" exit -1 fi # TODO: calculate that the total price is the correctly calculated product of the unit price by the quantitya else + echo "Stock item not found!" + echo " Item: -$ITEM-" + echo " Items changed, but this script not updated?" exit -1 fi @@ -167,13 +169,7 @@ cat $TEMPDIR/license.txt -# Cleanup temporary files -if [ -d "$TEMPDIR" ] -then - if [ `dirname $TEMPDIR` == "$HOME/tmp" ] - then - rm -rf $TEMPDIR - fi -fi + +$BILLING_PATH/email-template.sh "$BUYER_NAME" "$BUYER_EMAIL" "$DESC" "$QTY" "$UNIT_PRICE" "$TEMPDIR/license.txt"