Commit 1ca13a41 authored by Rusty Myers's avatar Rusty Myers

Completed update to Idle Logout - Self contained app, no external scripts....

Completed update to Idle Logout - Self contained app, no external scripts. Forces logout, no rebooting. Added applescript to enable users to disable idle logout as needed. Updating version to 1.2
parent 01cdfb63
#tag BuildAutomation Begin BuildStepList Linux Begin BuildProjectStep Build End End Begin BuildStepList Mac OS X Begin IDEScriptBuildStep SaveProject , AppliesTo = 0 DoCommand "SaveFile" End Begin BuildProjectStep Build End Begin IDEScriptBuildStep UnDock , AppliesTo = 0 Dim AppLocation as String = CurrentBuildAppName + ".app" AppLocation = AppLocation.ReplaceAll( " ", "\ " ) AppLocation = CurrentBuildLocation + "/" + AppLocation //@ More cocoa info.plist keys here: // https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html Call DoShellCommand("/usr/bin/defaults write " + AppLocation + "/Contents/Info ""LSBackgroundOnly"" -bool ""true""") End Begin IDEScriptBuildStep tarProject , AppliesTo = 0 // Set Variables dim packageLoc, res, tarname as string tarname = "Idle-Logout.tar.bz2" packageLoc = "/Users/rzm102/Documents/_Programing/CLC\ Git/Software\ Packages/idle-logout/" if CurrentBuildLocation="/Users/rzm102/Documents/_Programing/Git/IdleLogout/Builds\ \-\ psuIdleLogout.rbvcp/Mac\ OS\ X\ \(Intel\)" then //print "Build Location: "+CurrentBuildLocation // Tar up folder res = DoShellCommand _ ("cd "+CurrentBuildLocation+"; /usr/bin/tar -c --exclude='.svn' -vjf "+tarname+" *") if res = "" then print "Results: "+res end // Delete old tar // print "rm "+packageLoc+tarname res = DoShellCommand _ ("rm "+packageLoc+tarname) // Move tar to luggage folder // print "mv "+CurrentBuildLocation+"/"+tarname+" "+packageLoc res = DoShellCommand _ ("mv "+CurrentBuildLocation+"/"+tarname+" "+packageLoc) // Make package res = DoShellCommand _ ("cd "+packageLoc+"; make pkg; open "+packageLoc) print res else print "Not on rusty's mac. Skipping pkg creation" //print CurrentBuildLocation//print "Build Location: "+CurrentBuildLocation end End End Begin BuildStepList Windows Begin BuildProjectStep Build End End #tag EndBuildAutomation
\ No newline at end of file
#tag BuildAutomation Begin BuildStepList Linux Begin BuildProjectStep Build End End Begin BuildStepList Mac OS X Begin IDEScriptBuildStep SaveProject , AppliesTo = 0 DoCommand "SaveFile" End Begin BuildProjectStep Build End Begin IDEScriptBuildStep UnDock , AppliesTo = 0 Dim AppLocation as String = CurrentBuildAppName + ".app" AppLocation = AppLocation.ReplaceAll( " ", "\ " ) AppLocation = CurrentBuildLocation + "/" + AppLocation //@ More cocoa info.plist keys here: // https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html Call DoShellCommand("/usr/bin/defaults write " + AppLocation + "/Contents/Info ""LSBackgroundOnly"" -bool ""true""") End Begin IDEScriptBuildStep tarProject , AppliesTo = 0 // Set Variables dim packageLoc, res, tarname as string tarname = "Idle-Logout.tar.bz2" packageLoc = "/Users/rzm102/Documents/_Programing/CLC\ Git/Software\ Packages/idle-logout/" if CurrentBuildLocation="/Users/rzm102/Documents/_Programing/Git/IdleLogout/Builds\ \-\ psuIdleLogout.rbvcp/Mac\ OS\ X\ \(Intel\)" OR CurrentBuildLocation="/Users/rzm102/Documents/_Programing/Git/IdleLogout/Builds\ \-\ psuIdleLogout.rbvcp/Mac\ OS\ X\ \(Cocoa\ Intel\)" then //print "Build Location: "+CurrentBuildLocation // Tar up folder res = DoShellCommand _ ("cd "+CurrentBuildLocation+"; /usr/bin/tar -c --exclude='.svn' -vjf "+tarname+" *") if res = "" then print "Results: "+res end // Delete old tar // print "rm "+packageLoc+tarname res = DoShellCommand _ ("rm "+packageLoc+tarname) // Move tar to luggage folder // print "mv "+CurrentBuildLocation+"/"+tarname+" "+packageLoc res = DoShellCommand _ ("mv "+CurrentBuildLocation+"/"+tarname+" "+packageLoc) // Make package res = DoShellCommand _ ("cd "+packageLoc+"; make pkg; open "+packageLoc) print res else print "Not on rusty's mac. Skipping pkg creation" //print CurrentBuildLocation//print "Build Location: "+CurrentBuildLocation end End End Begin BuildStepList Windows Begin BuildProjectStep Build End End #tag EndBuildAutomation
\ No newline at end of file
......
if getPID("idle") = 0 then
display dialog "Idle time is not currently being monitored." buttons {"OK"} default button "OK"
return
end if
set CR to return
set CRCR to return & return
set warnMsg to " •WARNING•"
set warnMsg to warnMsg & CRCR & "You are about to disable the automatic idle logout feature, which logs you out if you are idle too long. "
set warnMsg to warnMsg & CRCR & "Disabling this feature will expose you to the following problems "
set warnMsg to warnMsg & "should you leave the Mac unattended and remain logged in:"
set warnMsg to warnMsg & CRCR & "1) Others can use this Mac to access your files."
set warnMsg to warnMsg & CRCR & "2) Others can use this Mac to charge printing to your Penn State Access Account."
set warnMsg to warnMsg & CRCR & "3) Others can use this Mac to pose as you."
set warnMsg to warnMsg & CRCR & "Do you agree to stay in the vicinity of this computer to prevent such abuses?"
set userSelection to the button returned of (display dialog warnMsg with icon 2 buttons {"Cancel Request", "I Agree. Disable Auto Logout."} default button 1)
if userSelection contains "cancel" then
display dialog "Request cancelled by user" buttons {"OK"} default button 1
return
end if
killApp("idle")
if getPID("idle") = 0 then
display dialog "Automatic Idle Logout has been disabled." buttons {"OK"} default button "OK"
else
display dialog "There was a problem with disabling Automatic Idle Logout." buttons {"OK"} default button "OK"
end if
--••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
--• subroutines follow •
--••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
----------------------------------------------------------------------
-- getAppCount - return count of apps
----------------------------------------------------------------------
on getAppCount(appName)
set appCounter to (do shell script ("pid=`/bin/ps auxww | /usr/bin/grep -v grep | /usr/bin/grep -i -c " & quoted form of appName & "` ; [[ -n $pid ]] && echo $pid || echo 0 ")) as integer
return appCounter
end getAppCount
----------------------------------------------------------------------
-- getPID - return an app's processor id number
----------------------------------------------------------------------
on getPID(appName)
set appPID to (do shell script ("pid=`/bin/ps auxww | /usr/bin/grep -v grep | /usr/bin/grep -v psuGetPID | /usr/bin/grep -i " & quoted form of appName & " $appName | /usr/bin/awk '{print $2}'` ; [[ -n $pid ]] && echo $pid || echo 0 ")) as integer
return appPID
end getPID
----------------------------------------------------------------------
-- killApp - kill all running copies of an app
----------------------------------------------------------------------
on killApp(appName)
set appKilled to false
repeat while getAppCount(appName) > 0
set appPID to getPID(appName)
if appPID 0 then
try
do shell script ("/bin/kill -9 " & appPID)
end try
set appKilled to true
delay 1
end if
end repeat
end killApp
#!/bin/bash
# Written by Rusty Myers
# 2012-11-06
# postflight to tell etc/sudoers to add code
DEST_VOLUME="${3}"
TIME=`date "+%Y-%m-%d-%H-%M-%S"`
# Allow Runtime to run with root privileges without prompting for an admin password
# check sudoers for psuRebootNow.pl
RUN_AS_ROOT=`grep "psuRebootNow.pl" "${DEST_VOLUME}"/etc/sudoers`
if [ -n "${RUN_AS_ROOT}" ] # If it's there
then
# Remove it from /etc/sudoers if it exists
sed /psuRebootNow.pl/d "${DEST_VOLUME}"/etc/sudoers > "${DEST_VOLUME}"/tmp/sudoers
# Make a copy of the current version
mv "${DEST_VOLUME}"/etc/sudoers "${DEST_VOLUME}"/etc/sudoers."${TIME}"
# Replace old version with new version
mv "${DEST_VOLUME}"/tmp/sudoers "${DEST_VOLUME}"/etc/sudoers
else
# Make a copy of the current version
cp "${DEST_VOLUME}"/etc/sudoers "${DEST_VOLUME}"/etc/sudoers."${TIME}"
fi
# Add it back into /etc/sudoers
echo 'ALL ALL=NOPASSWD:/Library/CLMshared/psuRebootNow.pl' >> "${DEST_VOLUME}"/etc/sudoers
# Check permissions and reload sudoers file
chmod 440 "${DEST_VOLUME}"/etc/sudoers
chown root:wheel "${DEST_VOLUME}"/etc/sudoers
visudo -c
exit 0
#!/bin/bash
#--------------------------------------------------------------------------------------------------
#-- psuForceLogout
#--------------------------------------------------------------------------------------------------
# Program : psuForceLogout
# To Complie : n/a
#
# Purpose : Force user logout
#
# Called By : IdleLogout.app, TEM (As needed)
# Calls :
#
# Author : Rusty Myers <rzm102@psu.edu>
# Based Upon :
#
# Note :
#
# Revisions :
# 2014-03-18 <rzm102> Initial Version
#
# Version : 1.0
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
#-- Log - Echo messages with date and timestamp
#--------------------------------------------------------------------------------------------------
Log ()
{
logText=$1
# indent lines except for program entry and exit
if [[ "${logText}" == "-->"* ]];then
logText="${logText}`basename $0`: launched..."
else
if [[ "${logText}" == "<--"* ]];then
logText="${logText}`basename $0`: ...terminated"
else
logText=" ${logText}"
fi
fi
date=$(/bin/date)
echo "${date/E[DS]T /} ${logText}"
}
Log "-->"
Log "Found User $USER"
Log "Killing Apps"
kill -9 `ps axxx | grep "/Applications" | awk '{print $1}'`
Log "Log out user wihtout prompt"
osascript -e 'tell application "System Events"' -e 'keystroke "q" using {command down, shift down, option down}' -e 'end tell'
# Original https://jamfnation.jamfsoftware.com/discussion.html?id=9902
## Get the logged in user's name
# loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
## Get the PID of the logged in user
# loggedInPID=$( ps -axj | awk "/^$loggedInUser/ && /Dock.app/ {print \$2;exit}" )
## Use the above to run Applescript command to logout using keystroke commands
# /bin/launchctl bsexec "${loggedInPID}" sudo -iu "${loggedInUser}" "/usr/bin/osascript -e 'tell application \"System Events\" to keystroke \"q\" using {command down, option down, shift down}'"
Log "<--"
#!/usr/bin/perl -w
#
#--------------------------------------------------------------------------------------------------
#-- psuRebootRequested.pl
#--------------------------------------------------------------------------------------------------
# Program : psuRebootRequested.pl
#
# Purpose : Reboot computer
#
# Loaded By : launchd
# Called By : psuKioskIdleLogout.app touching file /tmp/psu_reboot_requested
#
# Author : <hkr@psu.edu> Ken Rosenberry
#
# Revisions : 2009/08/18 <hkr> Initial version
# : 2010/06/21 <hkr> no longer using /tmp/psu_reboot_now flag file
#--------------------------------------------------------------------------------------------------
# Get name of program for log records.
use File::Basename;
my ( $programName ) = basename($0);
LogData ("-->");
# psuCurrentUser.dat file contains the last logged in user.
# Remove this file, otherwise RunMaint tasks won't run because it looks like a user is logged in.
$current_user_dat_file = '/Library/PSUtemp/psuCurrentUser.dat';
if (-f $current_user_dat_file)
{
LogData("Remove current user file: $current_user_dat_file");
system "/bin/rm $current_user_dat_file";
}
LogData("Rebooting Now!");
LogData ("<--");
system '/sbin/reboot';
exit 0;
#--------------------------------------------------------------------------------------------------
#-- LogData - Print message to log file.
#--------------------------------------------------------------------------------------------------
sub LogData
{
my $text = $_[0] ;
if ( substr($text, -1, 1) ne "\n") { $text = $text . "\n"; } ### Log messages must end w/ newline.
if ( substr($text, 0, 3) eq "-->")
{
$text = substr($text, 0, 3) . $programName . ": launched..." . substr($text, 3);
}
elsif ( substr($text, 0, 3) eq "<--" )
{
$text = substr($text, 0, 3) . $programName . ": ...terminated." . substr($text, 3);
}
else
{
$text = " " . $programName . ": " . $text; ### All other log records indented.
}
$text = (scalar localtime) . " " . $text; ### Timestamp log records.
print $text;
}
This diff is collapsed.
......@@ -3,20 +3,24 @@ IdleLogout.app
Description
------------
Application to log out users after a specified period of time. The user will see a prompt with a countdown asking them if they wish to log out or continue working ("More Time").
Application to log out users after a specified period of time. The user will see a prompt with a countdown asking them if they wish to log out or continue working ("More Time"). Users can disable the Idle Logout process using the "Disable Idle Logout.applescript".
Download app: [Idle Logout.app](https://github.com/CLCMacTeam/IdleLogout/blob/LogoutNotRestart/IdleLogout%20app/Idle%20Logout.app1.1b2.zip)
Background
------------
Idle Logout.app was written in RealStudio 2014 R1. It uses the ioreg command to determine how long USB devices have been idle. Once the idle limit is meet, the computer is forcibly restarted to log out any users.
Idle Logout.app was written in RealStudio 2014 R2.1. It uses the ioreg command to determine how long USB devices have been idle. Once the idle limit is meet, the computer is forcibly restarted to log out any users.
The terminal command we use to check idle seconds on USB devices is:
> /bin/echo $((`/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))"
Important Notes
-------------
Idle Logout.app should be run at login with a LaunchAgent under the users context. **In order for the application to work, the /Library/CLMadmin/psuForceLogOut.sh needs to allow all users to execute the script (included in the repo under 'IdleLogout app' folder).** The Idle Logout.app will write log files into the /Users/Shared/IdleLogout folder.
Idle Logout.app should be run at login with a LaunchAgent under the users context. **UPDATE: The Idle Logout.app is self contained and will force a user logout without the need for external scripts!** The Idle Logout.app will write log files into the /Users/Shared/IdleLogout folder.
You can deploy the "Disable Idle Logout.applescript", as a compiled app, to give users an easy way to stop the Idle Logout process. This is helpful in locations where users need to allow processes to run for longer than you're normal logout time.
**The Idle Logout App will force close any applications the user has open. This will not save any data!**
Preferences
-------------
......@@ -40,10 +44,15 @@ Default Values if plist is not installed:
ToDo
-------------
* The path to the logout script should be set in the preference file OR the script should be part of the app.
** Make it part of the .app, create a new method to log out
* Add prefernece key for window wording.
* Use CFPrefernces for pref file
* Update code to Cocoa
** Only update UI from main thread
Completed
------------
* 01/2015 - The path to the logout script should be set in the preference file OR the script should be part of the app.
** 01/2015 - Make it part of the .app, create a new method to log out
* 01/2015 - Add preference key for window wording.
Attribution
------------
......
Type=Desktop RBProjectVersion=2014.021 MinIDEVersion=20070100 Class=IdleLogout;IdleLogout.rbbas;&h3007783E;&h0;false Window=LogoutWarning;LogoutWarning.rbfrm;&h3A6788BA;&h0;false MenuBar=MenuBar1;MenuBar1.rbmnu;&h6341CAF0;&h0;false BuildSteps=Build Automation;Build Automation.rbbas;&h2A7E2380;&h0;false Module=LogToFile;LogToFile.rbbas;&h236DD59E;&h0;false Module=Globals;Globals.rbbas;&h7FE3CBE3;&h0;false Module=MiscMethods;MiscMethods.rbbas;&h445F2753;&h0;false Module=myXMLTools;myXMLTools.rbbas;&h6DD0A4A2;&h0;false Module=PlistHelper;PlistHelper.rbbas;&h4AA6652A;&h0;false MajorVersion=1 MinorVersion=1 SubVersion=2 NonRelease=0 Release=2 InfoVersion= LongVersion=1.1, Penn State University/ITS/CLC ShortVersion=1.1 WinCompanyName= WinInternalName= WinProductName= WinFileDescription= AutoIncrementVersionInformation=False BuildFlags=&h1000 BuildLanguage=&h0 DebugLanguage=&h0 Region= WindowsName=My Application.exe MacCarbonMachName=Idle Logout LinuxX86Name=MyApplication MacCreator= MDI=0 MDICaption= DefaultEncoding=&h0 AppIcon=psuIdleLogout.rbres;&h0 OSXBundleID=edu.psu.idlelogout DebuggerCommandLine= UseGDIPlus=True UseBuildsFolder=True IsWebProject=False
\ No newline at end of file
Type=Desktop RBProjectVersion=2014.021 MinIDEVersion=20070100 Class=IdleLogout;IdleLogout.rbbas;&h3007783E;&h0;false Window=LogoutWarning;LogoutWarning.rbfrm;&h3A6788BA;&h0;false MenuBar=MenuBar1;MenuBar1.rbmnu;&h6341CAF0;&h0;false BuildSteps=Build Automation;Build Automation.rbbas;&h2A7E2380;&h0;false Module=LogToFile;LogToFile.rbbas;&h236DD59E;&h0;false Module=Globals;Globals.rbbas;&h7FE3CBE3;&h0;false Module=MiscMethods;MiscMethods.rbbas;&h445F2753;&h0;false Module=myXMLTools;myXMLTools.rbbas;&h6DD0A4A2;&h0;false Module=PlistHelper;PlistHelper.rbbas;&h4AA6652A;&h0;false MajorVersion=1 MinorVersion=2 SubVersion=0 NonRelease=0 Release=2 InfoVersion= LongVersion=1.2, Penn State University/ITS/CLC ShortVersion=1.2 WinCompanyName= WinInternalName= WinProductName= WinFileDescription= AutoIncrementVersionInformation=False BuildFlags=&h1000 BuildLanguage=&h0 DebugLanguage=&h0 Region= WindowsName=My Application.exe MacCarbonMachName=Idle Logout LinuxX86Name=MyApplication MacCreator= MDI=0 MDICaption= DefaultEncoding=&h0 AppIcon=psuIdleLogout.rbres;&h0 OSXBundleID=edu.psu.idlelogout DebuggerCommandLine= UseGDIPlus=True UseBuildsFolder=True IsWebProject=False
\ No newline at end of file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment