#!/bin/bash
if [ -z "$1" ]; then
    echo "Il faut ajouter le path du pass en paramètre!"
fi

ZM_ACC=$(pass $1 | awk '{print $1}')
ZM_KEY=$(pass $1 | awk '{print $2}')
TIMESTAMP=$(date +%s)000

CONCAT_SIMPL_DATA=$ZM_ACC"|name|0|"$TIMESTAMP
CONCAT_ADMIN_DATA=$ZM_ACC"|1|name|0|"$TIMESTAMP
HASH_SIMPL_PREAUTH=$(echo -n $CONCAT_SIMPL_DATA | openssl dgst -sha1 -hmac $ZM_KEY | awk '{print $2}')
HASH_ADMIN_PREAUTH=$(echo -n $CONCAT_ADMIN_DATA | openssl dgst -sha1 -hmac $ZM_KEY | awk '{print $2}')

echo "---mailbox access---"
echo "/service/preauth?account=$ZM_ACC&expires=0&timestamp=$TIMESTAMP&preauth=$HASH_SIMPL_PREAUTH"
echo "---admin acess---"
echo "/service/preauth?account=$ZM_ACC&admin=1&expires=0&timestamp=$TIMESTAMP&preauth=$HASH_ADMIN_PREAUTH"

