Page 1 of 1

Need to suspend inactive users.

Posted: 2016-06-22 14:08
by ozgurerdogan
I am loking for a script to suspend inactive users. Do you know a way?

Re: Need to suspend inactive users.

Posted: 2016-06-22 15:03
by jimimaseye
Define "suspend".

Define "inactive".

Alsoif they are 'inactive', what is the point in suspending them?!

(Guidance can then be given when the above is clarified).

Re: Need to suspend inactive users.

Posted: 2016-06-22 15:17
by ozgurerdogan
Sometimes, some company employees leave their work and company does not inform us so their mailbox keeps open. And It eats disk space by spam mails. Also could be used by viruses to send bulk mails which ends up in RBL.

I want to automacitly suspend not active users lets say those havent logged in for 90 days.

Re: Need to suspend inactive users.

Posted: 2016-06-22 15:24
by jimimaseye
See this script: viewtopic.php?p=186628#p186628 and use it as a starter. This simply rejects incoming emails to that account.

IF you REALLY want to 'remove' the account without actually removing it, you could simply rename the account instead (append "OLD" to the end of it or something similar). Remember, though, that this isnt the best idea as I believe HMS then effectively has to go through and copy all existing emails to a new 'accountOLD' folder (its not clever enough to simply do a rename of the account folder itself). And depending on how many or how big those emials are it could take considerable time and resources (including temporarily doubling its disk requirements during the process).

Re: Need to suspend inactive users.

Posted: 2016-06-22 15:33
by ozgurerdogan
Actually I need to disable that account to disallow smtp auth.

Re: Need to suspend inactive users.

Posted: 2016-06-22 16:15
by jimimaseye
So you can simply just 'disable' it then. That will result in connections attempts to deliver in of 'account not active' and "SENT: 535 Authentication failed" for attempts to send with authentication.

Re: Need to suspend inactive users.

Posted: 2016-06-22 16:25
by ozgurerdogan
How do I automa this with script?

Re: Need to suspend inactive users.

Posted: 2016-06-22 16:29
by jimimaseye
You need a standalone script that authenticates to the HMS object and is run, I would say, once a day by Task Scheduler.

Script help: https://www.hmailserver.com/documentati ... ce_scripts

Re: Need to suspend inactive users.

Posted: 2016-06-22 16:56
by ozgurerdogan
I have no idea about these sciprting. I was looking for a ready go script. I found one but that does not seems to work. viewtopic.php?t=24235

Re: Need to suspend inactive users.

Posted: 2016-06-22 17:09
by jimimaseye
Put this in a notepad file. Save as "Disactivate.vbs" (or whatever you want to call it). Change the password (HMPassword). Call it by Task Scheduler.

Code: Select all

option explicit
Dim HMPassword, x, y, diffDays, oApp, oDomain, oAccount

HMPassword = "secretpassword"

Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", HMPassword )
 
For x = 0 To oApp.Domains.Count - 1
   Set oDomain = oApp.Domains.Item(x)
   If oDomain.Active Then
      For y = 0 To oDomain.Accounts.Count - 1
         Set oAccount = oDomain.Accounts.Item(y)
         If oAccount.Active Then
            diffDays = DateDiff("d", oAccount.LastLogonTime, Now)  ' get the difference in DAYS
'            wscript.echo "Account=" & oAccount.address & ", oAccount.LastLogonTime=" & oAccount.LastLogonTime & ", diffdays=" & diffDays
            If diffDays > 90 Then  ' 90 days since last logon 
               oAccount.Active = False
               oAccount.save
            End if
         End If
      Next
   End If
Next

You can modify the line 'wscript' to include whatever information you want (and remove the leading apostrophe) and it will then output to whatever output destination (log file or screen) you have at time of running. (You can run this script interactively if you want).

Warning: it goes through ALL accounts on ALL domains.

Re: Need to suspend inactive users.

Posted: 2016-06-22 17:45
by ozgurerdogan
You know what! Thanks a lot. This will really help me lot. I tested it and it works as expected. Lately I am fighting lots of spam issue because of client based viruses those steals users password.

I really thank you. I hope last login time is trustable value.

Re: Need to suspend inactive users.

Posted: 2016-06-22 19:17
by jimimaseye
Of course, the problem is that if there is a spambot using a stolen password to send out spam emails, then that 'last login' will always be renewed. So there's a chance that you are only disabling TRULY inactive accounts that are not sending spam or being a problem, and not disabling the ones that are. You would be better tackling the problem by looking at what accounts are causing the problem (been compromised) and getting their passwords changed or made inactive.

Re: Need to suspend inactive users.

Posted: 2016-06-22 21:08
by ozgurerdogan
Yes you are right. I will keep that in mind. Thanks again.