Head scratcher: help please

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
User avatar
jimimaseye
Moderator
Moderator
Posts: 8306
Joined: 2011-09-08 17:48

Head scratcher: help please

Post by jimimaseye » 2017-08-17 08:57

Hi Friends,

I am referring to the SETTINGS DIAGNOSTIC REPORT script viewtopic.php?f=20&t=30914

Under the PROTOCOLS - SMTP section, line 2 should be showing the 'Host', 'Empty Sender' and 'Batch Recipients' fields.

eg
[code]SMTP
GENERAL DELIVERY RFC COMPLIANCE ADVANCED
No. Connections: 0 No Retries: 4 Mins: 5 Plain Text: False Bind:
Host: EXTERNAL.TLD Empty sender: True Batch recipients: 100 <<-------------- LINE 2
Max Msg Size: 20480 Relay:- Incorrect endings: True Use STARTTLS: False
[/code]


Every system I test it on works ok.

However, there have been a couple of posters that have given their results back to the forum where line 2 is missing completely.

eg
[code]PROTOCOLS

SMTP
GENERAL DELIVERY RFC COMPLIANCE ADVANCED
No. Connections: 0 No Retries: 4 Mins: 60 Plain Text: False Bind: 192.168.0.6 <<----- LINE 1
Max Msg Size: 20480 Relay:- Incorrect endings: True Use STARTTLS: True <<----- LINE 3[/code]
(This was taken from viewtopic.php?p=198135#p198135)


Both posters so far have been using the same version of HMS (current production).

I have looked in the code and simply cannot figure out or replicate why this is happening.

Current (from line 303) reads:

Code: Select all

   'Line 2
      Txt = txt & space(21) & "Host: " & LJust(DomainReveal(oTarget.HostName,1),18) & "  Empty sender:      " & _
       RJust(BooTrans(not(oTarget.DenyMailFromNull)),5) & "  Batch recipients: " & RJust(oTarget.MaxSMTPRecipientsInBatch,5) & vbcrlf
The usual cause for such a line missing is when one of the fields doesnt exist. However, when this happens, there is a line at the bottom of the report reading "Error 438. Out-dated version. Some fields or objects missing." (This caters for older versions that dont have all the fields that were introduced in later releases.) But in no case does this line ever show on these reports with the missing line 2 and, anyway, none of those 3 fields are incorrect and should always exist. If one is suspect then I would think it is the "[settings].DenyMailFromNull" as the documentation says it should be called "AllowMailFromNull" - but this doesnt exist on my system and I found the other instead.

Anyone got any ideas?
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 09:20

On mine 5.6.7 Build 2415(.10) it reads different again,

Windows Server 2016

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries:  4 Mins: 60   Plain Text:        False  Bind: 
Max Msg Size:     0  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:   True  Delivered-To hdr:  True
                     Req Auth: False           Max number commands: 100  Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: None
Windows Server 2012

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries:  4 Mins: 60   Plain Text:        False  Bind: 
                     Host: EXTERNAL.TLD        Empty sender:       True  Batch recipients:   100
Max Msg Size: 40960  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:   True  Delivered-To hdr:  True
                     Req Auth: False           Max number commands: 100  Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: None
FYI: Connection: None, Should read Connection Security: none or just Security: None if previous is to long
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 10:09

Hmmm.... so you also have the missing line 2 on one box but not the other. So it seems its OS dependant?

Would you mind doing a quick test please? Line 303, change:

Code: Select all

  'Line 2
      Txt = txt & space(21) & "Host: " & LJust(DomainReveal(oTarget.HostName,1),18) & "  Empty sender:      " & _
       RJust(BooTrans(not(oTarget.DenyMailFromNull)),5) & "  Batch recipients: " & RJust(oTarget.MaxSMTPRecipientsInBatch,5) & vbcrlf
TO

Code: Select all

  'Line 2
      Txt = txt & space(21) & "Host: " & LJust(DomainReveal(oTarget.HostName,1),18) & "  Empty sender:      " & _
       RJust(BooTrans(oTarget.DenyMailFromNull),5) & "  Batch recipients: " & RJust(oTarget.MaxSMTPRecipientsInBatch,5) & vbcrlf
and see if it runs correctly/displays line 2 on your Server2016 box. (The 'Empty Sender' value, if now displayed, will be the reverse of how it appears in Admin but it will prove if its the cause. I will at least be able to work with it).

FYI: Connection: None, Should read Connection Security: none or just Security: None if previous is to long
Noted. Ta.
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

tunis
Normal user
Normal user
Posts: 237
Joined: 2015-01-05 20:22
Location: Sweden

Re: Head scratcher: help please

Post by tunis » 2017-08-17 10:13

I think the error is in "DomainReveal" function.

If I just enter oTarget.HostName in steed of DomainReveal(oTarget.HostName,1) it worked, else it fail and the line is missing.

On 2012 server!
HMS 5.6.8 B2494.24 on Windows Server 2019 Core VM.
HMS 5.6.8 B2494.24 on Windows Server 2016 Core VM.
HMS 5.6.7 B2425.16 on Windows Server 2012 R2 Core VM.

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 10:20

If I just enter oTarget.HostName in steed of DomainReveal(oTarget.HostName,1) it worked, else it fail and the line is missing.

On 2012 server!
On your previous post you Server2012 showed the line displaying correctly. (It showed it as 'EXTERNAL.TLD' which would be right). The DomainReveal function is used throughout so if it is failing it would be because of the parameter being passed to it (in this case "oTarget.HostName"). Is there anything strange with those values?



Actually, to help determine, would you mind changing that line to this instead:

Code: Select all

  'Line 2
      Txt = Txt & space(21) & "Host: " & LJust(DomainReveal(oTarget.HostName,1),18) 
      Txt = Txt & "  Empty sender:      " &  RJust(BooTrans(oTarget.DenyMailFromNull),5)
      Txt = Txt & "  Batch recipients: " & RJust(oTarget.MaxSMTPRecipientsInBatch,5)
      Txt = Txt & vbcrlf
This will show for sure which field has the problem (it will be the one that doesnt appear). And then we can work on that specifically.
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

tunis
Normal user
Normal user
Posts: 237
Joined: 2015-01-05 20:22
Location: Sweden

Re: Head scratcher: help please

Post by tunis » 2017-08-17 10:34

It was RvdH:s widows server 2012 that worked.

My 2012 do not as the new code show.

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries: 10 Mins:  6   Plain Text:        False  Bind: 
  Empty sender:      False  Batch recipients:   125
Max Msg Size: 20480  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:  False  Delivered-To hdr:  True
                     Req Auth: False                                     Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: StartTLS Optional
My hostname is mail.xxxxx.xxxxxxxxx.se
HMS 5.6.8 B2494.24 on Windows Server 2019 Core VM.
HMS 5.6.8 B2494.24 on Windows Server 2016 Core VM.
HMS 5.6.7 B2425.16 on Windows Server 2012 R2 Core VM.

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 10:37

tunis wrote:It was RvdH:s widows server 2012 that worked.

My 2012 do not as the new code show.

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries: 10 Mins:  6   Plain Text:        False  Bind: 
  Empty sender:      False  Batch recipients:   125
Max Msg Size: 20480  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:  False  Delivered-To hdr:  True
                     Req Auth: False                                     Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: StartTLS Optional
My hostname is mail.xxxxx.xxxxxxxxx.se
cheers.

Presumably that "mail.xxxxx.xxxxxxxxx.se" is not any of your listed domains or aliases and therefore should be returning EXTERNAL.TLD ? (I simply cannot get it to fail like this. If I put any none-listed domain or string in this field it always gives EXTERNAL.TLD).
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

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 12:33

So, anyone got any ideas? :-(
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 12:36

The actual hostname does not have to be one of the domains listed, the PTR my ISP gave me is nowhere near the domains i host on my own box
But I entered the hostname my ISP has given me in the 'Local host name' input, just to avoid Spamcheck PTR failures

Leaving out DomainReveal works like tunis mentioned

Code: Select all

	   Txt = txt & space(21) & "Host: " & LJust(oTarget.HostName,18) & "  Empty sender:      " & _
       RJust(BooTrans(oTarget.DenyMailFromNull),5) & "  Batch recipients: " & RJust(oTarget.MaxSMTPRecipientsInBatch,5) & vbcrlf

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries:  4 Mins: 60   Plain Text:        False  Bind: 
                     Host: ip3e832edd.speed.planet.nl  Empty sender:      False  Batch recipients:   100
Max Msg Size:     0  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:   True  Delivered-To hdr:  True
                     Req Auth: False           Max number commands: 100  Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: None
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 12:47

RvdH wrote:The actual hostname does not have to be one of the domains listed,
Indeed.

The DomainReveal function takes that value and looks through the existing array of domains and aliases (set up at the top of the script in the "Set up masked Domains array - ' End of array setup" section) to see if there is a match and if so reveals the pseudonuym (ie, "Domain1.com", "Alias2.com" etc). If there isnt a match (which will be the case for your value) then it should then simply return "EXTERNAL.TLD" (hardcoded - meaning that the value entered is not a local domain to this system).

This is the function:

Code: Select all

Function DomainReveal(inDomain,cType) ' (type 0 (default) = convert if possible. type 1 = always mask)
   For d = 0 to ubound(RecordedDomains)
      if RecordedDomains(d) = lcase(inDomain) then
         DomainReveal = "Domain" & d & ".com"
         Exit Function
      End if
   Next
   For d = 0 to ubound(RecordedAliases)
      if RecordedAliases(d) = lcase(inDomain) then
         DomainReveal = "Alias" & d & ".com"
         Exit Function
      End if
   Next
   DomainReveal = inDomain ' set as type 0 - do not mask external/non-local domains
   if cType = 1 then DomainReveal = "EXTERNAL.TLD"  'type 1 - mask all domains including external/non-local domains 
End Function
So you can see it takes the input value ("indomain") and compares it to the array of domains and aliases. If found, it takes the pseudonym and exits the function. If not found it returns "EXTERNAL.TLD" (because the mask ('ctype') = 1).

This is used throughout the script. do a search in the script for DomainReveal and you can see where. Maybe you can check those ocrrunces to see if the function is correctly returning the pseudonyms in those cases too. (As I said, I cant get this to fail and logically looks fine - this is why it has stumped me).
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 12:51

CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 13:03

RvdH wrote:CType is a reserved word?

https://docs.microsoft.com/en-us/dotnet ... e-function
Ooh! Ok.

I am without access to my system at the moment and cannot test a change. Also, I cant really retest as I cant reproduce the error in the first place. Would you be willing to do a test if I post a changed version?

(Or would you mind simply renaming the occurrences of the word "CType" to "ConverstionType" and retest please. There is only 2):?

Code: Select all

Function DomainReveal(inDomain,converstionType) ' (type 0 (default) = convert if possible. type 1 = always mask)
   For d = 0 to ubound(RecordedDomains)
      if RecordedDomains(d) = lcase(inDomain) then
         DomainReveal = "Domain" & d & ".com"
         Exit Function
      End if
   Next
   For d = 0 to ubound(RecordedAliases)
      if RecordedAliases(d) = lcase(inDomain) then
         DomainReveal = "Alias" & d & ".com"
         Exit Function
      End if
   Next
   DomainReveal = inDomain ' set as type 0 - do not mask external/non-local domains
   if converstionType = 1 then DomainReveal = "EXTERNAL.TLD"  'type 1 - mask all domains including external/non-local domains 
End Function

Perhaps I also need to have "indomain" and (now) "Conversiontype" dimmed at the top? (They aren't at present).
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 13:08

Nope, that doesn't fix anything.... something in that function is wrong...but i can't see it
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 13:10

RvdH wrote:Something in that function is wrong...but i can't see it
A bloomin' mystery.

Perhaps its the lack of DIM for 'inDomain' and 'Conversiontype' ? Could you add those to the top?
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 13:33

If i put a 'Error Resume Next' around it, it seems to work....sort of...the domain is now called Alias3.com ?

FYI: None of the domains have aliases...so Alias3.com ???

Code: Select all

SMTP
GENERAL             DELIVERY                  RFC COMPLIANCE            ADVANCED
No. Connections:  0  No Retries:  4 Mins: 60   Plain Text:        False  Bind: 
                     Host: Alias3.com          Empty sender:       True  Batch recipients:   100
Max Msg Size:     0  Relay:-                   Incorrect endings:  True  Use STARTTLS:      True
                     (none entered)            Disc. on invalid:   True  Delivered-To hdr:  True
                     Req Auth: False           Max number commands: 100  Loop limit:           5
                                                                         Recipient hosts:     15
                     Connection: None
So the error has to be within

Code: Select all

   x = 0
   For iDomainIdx = 0 To obApp.Domains.Count -1
      set oDomain = obApp.Domains.Item(iDomainIdx)
      ReDim preserve RecordedDomains(iDomainIdx + 1)
      RecordedDomains(iDomainIdx + 1) = lcase(oDomain.name)
      For A = 0 To obApp.Domains.item(iDomainIdx).DomainAliases.Count-1
         ReDim preserve RecordedAliases(x + 1)
         RecordedAliases(x+1) = lcase(oDomain.DomainAliases.Item(A).Aliasname)
         x=x+1
      Next
   Next 
   set oDomain = Nothing
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

User avatar
mattg
Moderator
Moderator
Posts: 20548
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Head scratcher: help please

Post by mattg » 2017-08-17 14:13

I've think I've found it

Line 42-46
If you don't have any domain aliases then line 43 is not triggered
Then there is no RecordedAliases, causing an error, IFF the host name is not one of the domain names.

To test.
#1 Have no domain names (aliases)
#2 have a local host name of random stuff

Script fails
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 14:17

Brill.

Thanks guys.

I will use that info to

a, set up a test environment to reproduce the problem and
b, change the script

when I get home tonight.

Cheers again.
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 14:27

Nice find matt :!:

Just add

Code: Select all

dim RecordedAliases(0)

Code: Select all

  ' Set up masked Domains array
   dim RecordedAliases(0)
   x = 0
   For iDomainIdx = 0 To obApp.Domains.Count -1
      set oDomain = obApp.Domains.Item(iDomainIdx)
      ReDim preserve RecordedDomains(iDomainIdx + 1)
      RecordedDomains(iDomainIdx + 1) = lcase(oDomain.name)
      For A = 0 To obApp.Domains.item(iDomainIdx).DomainAliases.Count -1
         ReDim preserve RecordedAliases(x + 1)
         RecordedAliases(x+1) = lcase(oDomain.DomainAliases.Item(A).Aliasname)
         x=x+1
      Next
   Next 
   set oDomain = Nothing
' End of array setup.  Call by "DomainReveal("fqdn.com",type)" where type "1" = always mask (including non-local/external domains)
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 14:38

RvdH wrote:Nice find matt :!:

Just add

Code: Select all

dim RecordedAliases(0)
Yep, will do. Im guessing its a similar situation for domains too (not everyone has domains set up - they are using for relaying only).
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 14:50

dim RecordedDomains(0) gives you:

Code: Select all

---------------------------
Windows Script Host
---------------------------
Script:	C:\Users\Administrator\Desktop\HMSSettingsDiagnostics.vbs
Line:	42
Char:	7
Error:	This array is fixed or temporarily locked
Code:	800A000A
Source: 	Microsoft VBScript runtime error

---------------------------
OK   
---------------------------
So my guess is if an alias exits it also will do for: dim RecordedAliases(0)

EDIT: Check....mmm, have to look further

Code: Select all

dim RecordedDomains()
dim RecordedAliases()
Will produce same output as before, eg missing line
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-17 15:05

Code: Select all

   dim RecordedDomains()
   dim RecordedAliases()
   x = 0
   For iDomainIdx = 0 To obApp.Domains.Count -1
      set oDomain = obApp.Domains.Item(iDomainIdx)
      ReDim preserve RecordedDomains(iDomainIdx + 1)
      RecordedDomains(iDomainIdx + 1) = lcase(oDomain.name)
      For A = 0 To obApp.Domains.item(iDomainIdx).DomainAliases.Count -1
         ReDim preserve RecordedAliases(x + 1)
         RecordedAliases(x+1) = lcase(oDomain.DomainAliases.Item(A).Aliasname)
         x=x+1
      Next
   Next 
   set oDomain = Nothing

Code: Select all

Function DomainReveal(inDomain,cType) ' (type 0 (default) = convert if possible. type 1 = always mask)
	If Not IsNothing(RecordedDomains) Then
	   For d = 0 to ubound(RecordedDomains)
		  if RecordedDomains(d) = lcase(inDomain) then
			 DomainReveal = "Domain" & d & ".com"
			 Exit Function
		  End if
	   Next
	End If
	If Not IsNothing(RecordedAliases) Then
	   For d = 0 to ubound(RecordedAliases)
		  if RecordedAliases(d) = lcase(inDomain) then
			 DomainReveal = "Alias" & d & ".com"
			 Exit Function
		  End if
	   Next
	End If
   DomainReveal = inDomain ' set as type 0 - do not mask external/non-local domains
   if cType = 1 then DomainReveal = "EXTERNAL.TLD"  'type 1 - mask all domains including external/non-local domains 
End Function

Code: Select all

Wscript.Echo("IsNull:" & Cstr(IsNull(RecordedAliases)) & vbCRLF & "IsArray:" & Cstr(IsArray(RecordedAliases)) & vbCRLF & "IsEmpty:" & Cstr(IsEmpty(RecordedAliases)) & vbCRLF & "IsNothing:" & Cstr(IsNothing(RecordedAliases)))
---------------------------
Windows Script Host
---------------------------
IsNull:False

IsArray:True

IsEmpty:False

IsNothing:True
---------------------------
OK
---------------------------

Code: Select all

Function IsNothing(Value)

	Dim vTest
	Dim iArrayStart
	Dim iCtr, nDim, nRows, nCols, x, y
	Dim objLog, strErrMsg
	Dim bFlag : bFlag = false

	If IsEmpty(Value) Then
		IsNothing = True
		Exit Function
	End If

	If IsNull(Value) Then
	IsNothing = True
		Exit Function
	End If

	If VarType(Value) = vbString Then
		If Value = "" Then
			IsNothing = True
			Exit Function
		End If
	End If

	If IsNumeric(Value) Then
		If Value = 0 Then
			IsNothing = True
			Exit Function
		End If
	End If

	If IsObject(Value) Then
		If Value Is Nothing Then
			IsNothing = True
			Exit Function
		End If
	End If

	'Check for arrays
	If IsArray(Value) Then
	nDim = NoDim(Value)
	'Handle mutli dim arrays
	If nDim = 0 then
		IsNothing = true
		Exit Function
	Elseif nDim = 1 then 'check single dim array
		On Error Resume Next
		'Handle Single dim arrays
		vTest = Value(0)
		iArrayStart = IIf(Err.Number = 0, 0, 1)
		Err.Clear
		On Error GoTo 0
		For iCtr = iArrayStart To UBound(Value)
			If Not IsNothing(Value(iCtr)) Then
				'Has something in it
				bFlag = True
				Exit For
			End If
		Next

		IsNothing = Not bFlag
		Exit Function
		Elseif nDim = 2 then
			nRows = Ubound(Value, 2)+1
			nCols = Ubound(Value, 1)+1

			for x = 0 to nRows - 1
				for y = 0 to nCols - 1
				If not IsNothing(Value(y,x)) then
					bFlag = True
					Exit For
				End if
				next
				if (bFlag) then
					Exit For
				end if
			next
			IsNothing = Not bFlag
			Exit Function
		End if
	End If
	IsNothing = False
End Function

'* These functions are used by the IsNothing routine
Function IIf(condition,value1,value2)
	If condition Then IIf = value1 Else IIf = value2
End Function

'** will return the number of dimensions of an array
Function NoDim(arr)

dim n, mynextArray

On Error Resume Next
For n = 1 to 60
	mynextArray = UBound(arr, n)
	If err.number > 0 Then
		n = n - 1
		Exit For
	End if
Next
On Error Goto 0
NoDim = n
End Function
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-17 20:32

Ok, fixed.

You chaps care to give it a test? viewtopic.php?f=20&t=30914
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: SETTINGS DIAGNOSTIC REPORT

Post by RvdH » 2017-08-18 02:32

Poor handling off the error...i assume you normally start off with a array with no value (that is what dim Something() does) but you are fooling the script to set it 0 and 1,....i thought i explained what the issue is with is with that, and could cause future issues using it like this... guess it is hard to read?

https://www.tutorialspoint.com/vbscript ... arrays.htm
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-18 08:49

It works, doesnt it? :-) If you look through the code Im sure your find LOTS of non-standard or poor coding - Im a novice (at best). :|

The
redim preserve RecordedDomains(0)
redim preserve RecordedAliases(1)
is because I specifically want all values that may be found in the upcoming loops (AliasX.com, AliasY.com, DomainX.com DomainY.com etc) to start specifically at 1 (not zero) so they appear as Alias1, Alias2 etc. The number of 0 and 1 respectively is just because the loops that use and assign the values work slightly differently. (It's true that the 'preserve' in the initial redim statement is overboard/irrelevant but hey it doesnt hurt. )

Ill clean it up later in 1.71 by removing the unnecessary initial "DIM RecordedAliases()" statements. Eventually it will be

Code: Select all

' Set up masked Domains array
   redim RecordedDomains(0)
   redim RecordedAliases(1)
   x = 1
   For....
This works just fine. (The DIM alement only declared non-dynamic arrays - REDIM changes them to dynamic ones so the DIM was wrong to be there in the first place because they were always destined to be dynamic.)

(Sorry, I moved your post to this thread to keep the version history postings of the script as clean as possible without many discussion posts)
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

User avatar
RvdH
Senior user
Senior user
Posts: 855
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Head scratcher: help please

Post by RvdH » 2017-08-18 19:23

I think you misunderstood, you are creating a dynamic array therefore you must define the empty array before adding items to them, otherwise the array doesn't exist (remember the cause of the actual issue with your script as matt described)

A array is zero-indexed, so defining RecordedDomains(0) result in an extra and totally unnecessary loop further on, eg: in DomainReveal() for example
Hence, RecordedAliases(1) result in 2 unnecessary extra loops

The fact the array is empty in RecordedDomains() and RecordedAliases() beforehand has no influence on the the way how AliasX.com, AliasY.com, DomainX.com DomainY.com are displayed once the arrays are filled with actual values
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

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

Re: Head scratcher: help please

Post by jimimaseye » 2017-08-18 20:10

Cheers.

Dont misunderstand me, I am aware that the solution I have coded is not technically and efficiently perfect* - the correct way would be to only increase the array one by one as they are needed (otherwise they should stay as empty/unused from the beginning). However, the worse case scenario as it is is that I have 2x (separately named) array elements defined that is not going to be populated at all (the first element 0) plus an extra 'ready-to-use-but-never-gets-a-value element under 'RecordedAliases' (being redimmed *just in case* theres another value to come without knowing if there is going to be one). But having such a lookup array is like having a lookup table where only one value might be searched for against multiple potential entries and could argue that they are all irrelevant except the only one that's required. Compare to that normal static arrays which are often declared (eg, "Array(100)") on the hope that there's an off-chance that they may be 100 values to go in but often only doing it as a limit rather than an expectation of filling them. This is something you see all the time in code, leaving MANY empty/unfilled element values - many more than my 3.

And given it is only 3, of zero value (instead of a lot more in the 'Array(100)' example) and they are all in memory the overhead will be negligible and *the consequences as good as non-existent whilst instead ultimately achieving the intended goal with minimal fuss and lines of coding. I could recode to lose one of these extra that will never get needed (the higher one of RecordedAliases that will never be populated) but it wouldnt really change anything. Or I could recode to do things properly (to check if the array is a *something* before commencing the loop through them) but that would just mean a lot more code to achieve exactly the same functional results.

In coding there's not always just one way to do things but often only one way to do it perfectly. And the perfect way is often not the implemented way. Personally Im all for an easy life and this was the easiest for me and has the smallest footprint.
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

Post Reply