#!/bin/bash
. /etc/sambaedu/user.conf
if [ "$PAM_USER" == "root" ] || [ "$PAM_USER" == "Debian-gdm" ]; then
	exit 0
fi

# check if we're opening or closing the session
case $PAM_TYPE in
open_session)
	scripts=$(curl -F "action=logon-system" -F "user=$PAM_USER" -F "machine=$(hostname)" -F "os=linux" $URL/gpo/applications.php)
	eval "$scripts"
	;;
close_session)
	scripts=$(curl -F "action=logoff-system" -F "user=$PAM_USER" -F "machine=$(hostname)" -F "os=linux" $URL/gpo/applications.php)
	eval "$scripts"
	;;
*)
	# not in session stack, do nothing but don't fail
	;;
esac
exit 0
