#!/bin/bash

SECRET=$1
RTP_PATH="/etc/asterisk/rtp.d/01-xivo-edge-turn-cred.conf"

time=$(date +%s)
expiry=${2:-3153600000}
username=$(( "$time" + "$expiry" ))
password=$(echo -n $username | openssl dgst -binary -sha1 -hmac "$SECRET" | openssl base64)

echo Generating a username/password for $expiry secs
echo
echo username : $username
echo password : "$password"
echo

echo "turnusername=$username" > $RTP_PATH
echo "turnpassword=$password" >> $RTP_PATH
