Skip to content

Commit

Permalink
Merge pull request #56 from KanoComputing/logon-session-tracker
Browse files Browse the repository at this point in the history
Adding lightdm hook scripts to track user login sessions
  • Loading branch information
pazdera committed Jan 13, 2015
2 parents 3f11003 + 1fd576b commit 44e75dd
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions debian/install
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ gtk-themes/Kano usr/share/themes
bin/kano-screenshot-hotkey usr/bin
bin/kano-uixinit usr/bin
bin/open-me.sh etc/skel/.Rabbithole

scripts/* usr/share/kano-desktop/scripts
8 changes: 8 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ SQUEAKDIR=/usr/share/squeak

TMP_SUDOERS_FILE=/tmp/kano-desktop_conf

ldm_conf=/etc/lightdm/lightdm.conf
ldm_login=/usr/share/kano-desktop/scripts/ldm-session-setup-script
ldm_logout=/usr/share/kano-desktop/scripts/ldm-session-cleanup-script

case "$1" in
configure)

Expand Down Expand Up @@ -92,6 +96,10 @@ case "$1" in
# Move the file to the sudoers directory
mv $TMP_SUDOERS_FILE /etc/sudoers.d/

# Add login and logoff hooks to track usage of the kit
sed -i "s|#\?\(session-setup-script\=\).*|\1$ldm_login|" $ldm_conf
sed -i "s|#\?\(session-cleanup-script\=\).*|\1$ldm_logout|" $ldm_conf

;;
esac

Expand Down
8 changes: 8 additions & 0 deletions debian/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ lxde_autostart=/etc/xdg/lxsession/LXDE/autostart

SUDOERS_FILE=/etc/sudoers.d/kano-desktop_conf

ldm_conf=/etc/lightdm/lightdm.conf
ldm_login=/usr/share/kano-desktop/scripts/ldm-session-setup-script
ldm_logout=/usr/share/kano-desktop/scripts/ldm-session-cleanup-script

case "$1" in
remove|upgrade)

Expand Down Expand Up @@ -55,6 +59,10 @@ case "$1" in
# remove sudoers file to switch VTs
rm -f $SUDOERS_FILE

# Remove login and logoff hooks
sed -i "s|#\?\(session-setup-script\=\).*|#\1|" $ldm_conf
sed -i "s|#\?\(session-cleanup-script\=\).*|#\1|" $ldm_conf

;;
esac

Expand Down
20 changes: 20 additions & 0 deletions scripts/ldm-session-cleanup-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# ldm-session-cleanup-script
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#
# https://wiki.ubuntu.com/LightDM
#
# This script is called by lightm when the user logs off
# We collect the time the users spent on this session and save it on the tracker
#

started=`cat /home/$USER/.session-started`
finish=$(date +"%s")
session_time=$(($finish-$started))

su - $USER -c "kano-profile-cli increment_app_runtime logon-session $session_time"

return 0
17 changes: 17 additions & 0 deletions scripts/ldm-session-setup-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# ldm-session-setup-script
#
# Copyright (C) 2014 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#
# https://wiki.ubuntu.com/LightDM
#
# This script is called by lightm during user logon session
# We save the current time here so we can estimate usage timings
#

su - $USER -c "date +'%s' > ~/.session-started"

# zero means proceed with login, anything else will cancel the session
exit 0

0 comments on commit 44e75dd

Please sign in to comment.