#!/bin/bash


KEY_SESSION=${SSH_AUTH_INFO_0//$'\n'/}

KEY_SESSION=`echo "${KEY_SESSION}" | cut -d ' ' -f 3`
REMOTE_PORT=`echo "${SSH_CONNECTION}" | cut -d ' ' -f 2`
REMOTE_IP=`echo "${SSH_CONNECTION}" | cut -d ' ' -f 1`

echo "\n" >> /tmp/curlout.log 
echo `date +"%Y%m%d_%H%M%S"` >> /tmp/curlout.log 

curl --connect-timeout 5 --max-time 10 -k -X 'POST' \
  'https://dev.cloudlocalnet.com/back/proxy-session' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Host: dev.cloudlocalnet.com" \
  -d '{
  "host": "'"$HOSTNAME"'",
  "host_key": "'"$KEY_SESSION"'",
  "status": "'"$PAM_TYPE"'",
  "host_remote": "'"$PAM_RHOST"'",
  "port_remote": "'"$REMOTE_PORT"'",
  "ip_remote": "'"$REMOTE_IP"'",
  "user": "'"$PAM_USER"'"
}' >> /tmp/curlout.log 


exit 0

