EXPIRE UNUSED ACCOUNTS
From TDiWiki
This script is designed to find all accounts that have not had a login session in a specific number of days and to then set them as expired to prevent further logins.
[edit] Script Properties
Name: EXPIRE_UNUSED_ACCOUNTS
Description: This script will expire unused accounts when run from a scheduled event.
Profile: CONSOLE_MANAGER
Timeout: 30 (seconds)
[edit] Run Type
Run as Event Automatic Action
[edit] Script Text
// * Copyright 2011 TDi Technologies, Inc. All rights reserved. *
// * The information in this software is subject to change without *
// * notice and should not be construed as a commitment by TDi. *
// * Created: 5/27/2011 *
// * Set maxIdleDays to the number of days before disabling an idle account
var maxIdleDays = 30;
var maxIdleSeconds = maxIdleDays * 24 * 60 * 60;
// * Get today's date
var thisDateString = new Date();
var thisDate = thisDateString.getTime();
// * Make it into a ConsoleWorks database date
var UnixDate = Math.floor(thisDate / 1000);
// * Calculate the date of the max Idle date
var ExpireDate = UnixDate - maxIdleSeconds;
// * Get a list of all the Users
var user_names = User.getList();
// * Loop through all the users looking for anyone that is idle including anyone that has never logged in
for (var i=0;i<user_names.length;i++) {
thisUser = user_names[i].name;
thisLastLogin = user_names[i].lastlogin;
thisUserExpires = user_names[i].expire;
log("CONWRKS", thisUser + " expires " + thisUserExpires);
// change this to check for no expiration date if that is allowed to override the idle setting
// otherwise, anyone that has not logged in and has no expiration date will be expired
// Expire anyone that needs to be expired EXCEPT Console_Manager and put an entry in the CONWRKS log file
if (thisLastLogin <= ExpireDate && thisUser != "CONSOLE_MANAGER" && thisUserExpires >= UnixDate) {
user_names[i].expire = UnixDate;
user_names[i].save();
log("CONWRKS", "User: " + thisUser + " last login " + thisLastLogin + " has been expired for being idle");
}
}
