#!/usr/bin/perl
# Created by Pete Billson <pete@elbnet.com> 2001-12-15 to
# reset public Internet kiosks after xscreensaver kicks in.
# This should be run from /etc/crontab as often as desired,
# I run it once each minute.
#
# This script assumes that the worstations are named ws101,
# ws102, ws103, etc. and that they are set to autologin with
# a username that is the same as the workstation name. For
# example the user on workstaion ws101 is ws101.
#
#

# Check for lock file and exit if it exists
#
if (-f "/var/run/kiosk-reset.lock") {
   exit(0);
}

# Create Lock File So We Only Run Once
`/bin/touch /var/run/kiosk-reset.lock`;

#Define the first and last kiosk to check
$first_kiosk=101;
$last_kiosk=106;

# Now cycle through each kiosk
foreach $i ($first_kiosk .. $last_kiosk){
  $who = "ws";
  $who .= $i;

  # We grab the status of the screensaver
  $status =`/usr/bin/X11/xscreensaver-command -display $who:0 -time`;
  $status =~ m/XScreenSaver.*screen(.*)sin/m;

# Uncomment the next line if you want to run this manually and see some output
#print "$who - $1\n";

# Check if the screensaver is on or off
if ($1 eq " blanked "){
   # We check for a user lock file so that we are not resetting a reset kiosk
   if ( ! -f "/home/$who/.RESET" ){

# We reset the kiosk by killing off everything that should not be running
# You will want to modify these entries to fit your needs
 # First let us kill Mozilla and clean up
   `/bin/su --command='/usr/bin/killall -9 mozilla-bin' $who`;
   `/bin/su --command='/usr/bin/killall -9 java_vm' $who`;
      
 # Next, let us kill any AbiWords
   `/bin/su --command='/usr/bin/killall -9 AbiWord' $who`;
   `/bin/su --command='/usr/bin/killall -9 AbiWord_d' $who`;
      
 # Next, let us kill any OpenOffices
   `/bin/su --command='/usr/bin/killall -9 soffice.bin' $who`;

 # Next Let Us Kill Any AcroReaders that are hanging out
   `/bin/su --command='/usr/bin/killall -9 acroread' $who`;

 # You can add any other clean up tasks that you would like here


# Finally we create the user lock file
  `/bin/touch /home/$who/.RESET`;
}
  }else{

# If the screensaver was not active we remove the reset lock file, if it exists
  `/bin/rm -f /home/$who/.RESET`;
  }   
}

# We remove the run lock file so we are ready for the next run.

`rm -f '/var/run/kiosk-reset.lock'`;
exit(0);
