#!/bin/bash

GUNAME=$USER

#this is used to determine if we should mark a session dirty or not.

#OLD: if someone has logged in with a username then the session needs to be declared dirty no matter what
#egrep "^${GUNAME}$" /etc/groovix//passwordlesslogins >/dev/null 2>&1
#if [ $? -ne 0 ] ; then
#	#session is automatically dirty since a user logged in
#	exit 2
#fi


SINCELOGIN=`groovix-seconds-since-login $GUNAME `
SINCEACTIVITY=`groovix-xserver-inactivity-time`

#2 second margin
#gives room for error, and someone should not be able to "poison" the session in under 2 seconds
#this is necessary because x activity is for whatever reason "detected" when xfce starts.  
#  should really remark session as starting at that point, but then time spent at acceptable use will
#  will be included in and cmon session time will not agree with pacrez

# leave some room for error
let SINCELOGIN-=2

#compare in milliseconds
let SINCELOGIN*=1000

echo SINCEACTIVITY IS $SINCEACTIVITY
echo SINCELOGIN IS $SINCELOGIN
echo MYUSERNAME is $GUNAME



if [ "$SINCEACTIVITY" -gt "$SINCELOGIN" ] ; then
	#no activity since login, return success
	exit 0	
else
	#detected activity since login, return failure
	exit 1
fi

