Need to suspend inactive users.

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 14:08

I am loking for a script to suspend inactive users. Do you know a way?

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 15:03

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).
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 15:17

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.

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 15:24

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).
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 15:33

Actually I need to disable that account to disallow smtp auth.

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 16:15

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.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 16:25

How do I automa this with script?

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 16:29

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
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 16:56

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

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 17:09

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.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 17:45

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.

User avatar
jimimaseye
Moderator
Moderator
Posts: 10053
Joined: 2011-09-08 17:48

Re: Need to suspend inactive users.

Post by jimimaseye » 2016-06-22 19:17

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.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

ozgurerdogan
Senior user
Senior user
Posts: 268
Joined: 2010-11-19 18:50

Re: Need to suspend inactive users.

Post by ozgurerdogan » 2016-06-22 21:08

Yes you are right. I will keep that in mind. Thanks again.

Post Reply