Daily scheduler task for removing inactive users

You can share your Lua Scripts with everybody here.

Daily scheduler task for removing inactive users

Postby FTP » Mon Oct 19, 2009 1:11 pm

-- Description: daily scheduler task for removing inactive users that have not logged in within 15 days
-- Author: Luke
-- Date: 2009-10-12

Code: Select all
do
   --Get user list from domain "demo"
   local strUserlist = c_GetUserList("demo")
   local userlist = Split(strUserlist,"\n")

   for _,username in pairs(userlist) do
      local user = c_GetUser("demo",username)
      local logintime = user.last_logintime
      --get last login time, formatted as time_t
      local logintime_t = c_TranslateTime(logintime)
      if (os.time() - logintime_t) >= 3600*24*15 then
         c_DeleteUser("demo",username)
      end
   end
end



You may add a scheduler task with above lua scripts.
Image
FTP
Site Admin
 
posts 1423
 
joined Tue Sep 29, 2009 6:09 am

Re: Daily scheduler task for removing inactive users

Postby thomas.mccall » Tue Jul 12, 2016 9:22 am

Hello,

Could you explain how to modify this example so that inactive accounts are disabled not deleted?

Thanks!
thomas.mccall
 
posts 3
 
joined Tue Jul 12, 2016 9:19 am

Re: Daily scheduler task for removing inactive users

Postby FTP » Sat Jul 16, 2016 6:49 am

thomas.mccall wrote:Hello,

Could you explain how to modify this example so that inactive accounts are disabled not deleted?

Thanks!


You just need to replace the following line:

Code: Select all
c_DeleteUser("demo",username)


into:

Code: Select all
   for k,v in pairs(user) do
      if type(v) == "boolean" then
         if v == true then
            user[k] = 1
         else
            user[k] = 0
         end
      end
   end

   user.enable_account = 0
   user.oldpassword = user.password

   AddUser("demo", user)
FTP
Site Admin
 
posts 1423
 
joined Tue Sep 29, 2009 6:09 am

Re: Daily scheduler task for removing inactive users

Postby thomas.mccall » Wed Jul 20, 2016 11:09 am

Probably I done something wrong with the code but when I try to enter it into the task editor it rejects it saying:

attempt to call local 'type' (a string value)!

Code: Select all
do
--Get user list from domain "CBUK"
local strUserlist = c_GetUserList("CBUK")
local userlist = Split(strUserlist,"\n")

for _,username in pairs(userlist) do
  local user = c_GetUser("CBUK",username)
  local logintime = user.last_logintime
  --get last login time, formatted as time_t
  local logintime_t = c_TranslateTime(logintime)
   if (os.time() - logintime_t) >= 3600*24*15 then
    for k,v in pairs(user) do
    if type(v) == "boolean" then
     if v == true then
      user[k] = 1
     else
      user[k] = 0
     end
    end
    end

    user.enable_account = 0
    user.oldpassword = user.password
      
    AddUser("CBUK", user)

end


thomas.mccall
 
posts 3
 
joined Tue Jul 12, 2016 9:19 am

Re: Daily scheduler task for removing inactive users

Postby FTP » Wed Jul 20, 2016 3:26 pm

Already told you very clearly, just replace one line. OK, paste the full code here:

Code: Select all
do
   --Get user list from domain "demo"
   local strUserlist = c_GetUserList("demo")
   local userlist = Split(strUserlist,"\n")

   for _,username in pairs(userlist) do
      local user = c_GetUser("demo",username)
      local logintime = user.last_logintime
      --get last login time, formatted as time_t
      local logintime_t = c_TranslateTime(logintime)
      if (os.time() - logintime_t) >= 3600*24*15 then
      for k,v in pairs(user) do
         if type(v) == "boolean" then
       if v == true then
          user[k] = 1
       else
          user[k] = 0
       end
         end
      end

      user.enable_account = 0
      user.oldpassword = user.password

      AddUser("demo", user)
      end
   end
end
FTP
Site Admin
 
posts 1423
 
joined Tue Sep 29, 2009 6:09 am


Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 2 guests