#!/bin/bash

# insert your token and key here
# if encryption is not needed then just leave the key blank
#
# ARRAY=( "token:key"
#         "token:" ) <- empty key, but there is a token. message will be sent without encryption
#         "token:key" ) <- do not forget the spaces to the parenthesis. this is bash =)
#
#

ARRAY=( ":"
        ":" )

if [ "$1" != "" ]; then
for i in "${ARRAY[@]}"
do
    #to make it clear that this
    token=${i%%:*}
    key=${i##*:}

    if [ "$token" == $1 ] ; then
        if [ "$key" != "" ] ; then
             # if FOUND encryption key. sent WITH encryption
            title=`echo -n $2 |openssl aes-256-cbc -K $key -iv 00000000000000000000000000000000 -base64 -A`
            desc=`echo -n $3 |openssl aes-256-cbc -K $key -iv 00000000000000000000000000000000 -base64 -A`
            curl -s -d '{"token":"'$1'", "encrypt":"true", "title":"'$title'", "desc":"'$desc'"}' -H "Content-Type: application/json" -X POST 'https://zbx.vovanys.com/push/sendPush_json.php'
        else
            # if NOT FOUND encryption key. sent without encryption
            curl -s -kG "https://zbx.vovanys.com/push/sendPush.php?token=$1&title=$2&desc=$3"
        fi
    fi
done
else
	echo 'FAIL: Params not defined.' && echo 'Usage: zbxviewer2.sh Token Subject Message'
fi

