GeoIp anti spam script problem

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
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

GeoIp anti spam script problem

Post by bagu » 2013-05-15 15:26

Hello,

I use this script :

Code: Select all

Sub OnClientConnect(oClient)
   Dim geoip
   Dim Country
   Result.Value = 0
   set geoip = CreateObject("GeoIPCOMEx.GeoIPEx")
   geoip.set_db_path("D:\hMailServer\Geoip\")
   geoip.find_by_addr(oClient.IPAddress)
   country = GeoIP.country_code

   If (country = "CN" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "NG" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "UA" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "RU" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "TR" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "PL" ) Then  ' Reject this country
      Result.Value = 1
   End if
   If (country = "LT" ) Then  ' Reject this country
      Result.Value = 1
   End if

   If (Result.Value = 1 ) Then  ' Rejected
      EventLog.Write("Geo-IP rejected:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34)+geoip.country_code+" "+geoip.country_name)
   End if
To reject many spam.
But, i still receive .cn mails, and an error happen :

Code: Select all

"ERROR"	3964	"2013-05-15 10:09:24.870"	"Script Error: Source: (null) - Error: 80004005 - Description: (null) - Line: 325 Column: 3 - Code: (null)"
"ERROR"	4108	"2013-05-15 10:09:24.870"	"Script Error: Source: (null) - Error: 80004005 - Description: (null) - Line: 325 Column: 3 - Code: (null)"
Line 325 is : geoip.set_db_path("D:\hMailServer\Geoip\")
The folders exists, and i have GeoIP.dat inside it.
I have put GeoIpComEx.dll in system32 and syswow64, and i have set the com objet (following docs)

So, why i get this error ?
Thanks.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 16:36

please check that you uncommented the End Sub of Sub OnClientConnect(oClient)
i.e. the leading quote shoud be removed so you have

End Sub

not

' End Sub

if that doesn't work then please show the complete contents of your eventhandlers.vbs file

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 16:41

Sub is correctly ended ;)

Code: Select all

   If (Result.Value = 1 ) Then  ' Rejected
      EventLog.Write("Geo-IP rejected:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34)+geoip.country_code+" "+geoip.country_name)
   End if
End Sub
Here is my whole vbs : http://pastebin.com/kfgTpUiJ
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 17:15

is D:\hMailServer\ where your hmailserver program installation is located.

if not try putting the geoip.dat file under the hmailserver program path.

mine is placed in c:\program files (x86)\hmailserver\geoip\

just about to look at your vbs file...

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 17:18

Path are correct for both geoip and hmailserver.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 17:20

clutching at straws but did you reboot your system after installing the dll

and did you do a syntax check after reloading the scripts.

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 17:27

Yes, reboot have been done.

Yes syntax is ok.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 17:57

I assume you are on 64 bit windows since you have syswow64 and that windows IS running in 64bit.
I also assume you followed the 64bit dcom registration process.

however, just in case.

Copy GeoIpComEx.dll to the "system32" folder

Then open up a DOS command line and run
C:\> cd pathto\system32
C:\WINNT\system32> regsvr32 GeoIpComEx.dll

and see if that makes a difference

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 18:00

Already done, i followed the docs.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 18:14

which docs, the one in the zip download or the one in the pdf download for 64bit dcom registration?

on 64bit it should have been the one in the pdf download for dcom registration.

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 18:18

That's it.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 18:46

Lets us know how sucessful it was in stopping spam

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 18:48

When i say that's it, i mean, that it's the pdf docs i follow...Not it work ;)

I register the com successfuly
I made the com object folowing the pdf doc
I have the correct geoip.dat file
I have the right path
I have reboot

As you can see, i have done every tests wich can be made easy. And every tests have been done before i post here.
The line witch don't work is the path line.

So, there may be an error somewhere, but it's not easy to find where. (every easy tests have been done before the post)
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 19:24

do the permissions for geoip.dat allow access from hmailserver?

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 19:28

also suggest you download latest geoip file again just in case it corrupted on download

http://geolite.maxmind.com/download/geo ... oIP.dat.gz

and you did unzip it didn't you.

I know these are elementary suggestions but at the moment I have no other ideas as to what is causing the problem.

and do run the 32bit regsrv just in case...

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 19:37

Already done...3 time (with 2 browsers different and with command line tool to be sure)
Md5 checksum are the same for the 3 files.

Everything should work.

Regsvr and reboot done to be sure.
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 20:24

what I can tell you is I copied just your code for geoip and ran it through my hms.

even though the path to geoip.dat was wrong it doesn't throw a visible error, even with debugging on.

using correct path it works and picks up the country (wrote a check to event log).
So I would suggest the vbs code is fine and there must be something wrong with your dll or its registration

So I can only suggest that you re-install the dll (after downloading it again) and re-do the com registration of it.

And

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 21:10

Please try the following

copy the GeoIpComEx.dll to c:\windows\syswow64 ( I think you already did that )

run command prompt as administrator

cd windows\system32

regsvr32.exe /u GeoIpComEx.dll

cd windows\syswow64

regsvr32.exe GeoIpComEx.dll

hopefully that will do it.

User avatar
bagu
Normal user
Normal user
Posts: 211
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: GeoIp anti spam script problem

Post by bagu » 2013-05-15 21:56

Already do that.

But...I found the problem.
I have a security problem with the com object.
After setting it again, it work fine.

I also have re-write the script to make it shorter.

Code: Select all

Sub OnClientConnect(oClient)
   Dim geoip
   Dim Country
   Result.Value = 0
   set geoip = CreateObject("GeoIPCOMEx.GeoIPEx")
   geoip.set_db_path("D:\hMailServer\Geoip\")
   geoip.find_by_addr(oClient.IPAddress)
   country = GeoIP.country_code
   If oClient.IPAddress<>"" then
      Select Case country
      Case "CN","NG","UA","RU","TR","PL","LT","BY"
         Result.Value = 1
         EventLog.Write("Geo-IP rejected:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34)+geoip.country_code+" "+geoip.country_name)
      Case Else
         Result.Value = 0
         EventLog.Write("Geo-IP OK:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34)+geoip.country_code+" "+geoip.country_name)
      End Select
   End If
   Set geoip = Nothing
End Sub
hMailServer 5.6.8 With SpamAssassin 3.4.2

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: GeoIp anti spam script problem

Post by percepts » 2013-05-15 22:10

Glad you got it resolved.

I just discovered that windows\syswow64 is actually where 32bit dlls are stored. And the dll is a 32bit dll and most importantly that regsrv32 in syswow64 is for registering 32bit dlls. And that system32 is for 64bit and regsrv32 in system32 is for registering 64bit dlls.

I had always thought they were the other way round which is what must have caused me problems when I originally setup my w7 box. I think I got it working more by luck than judgement.

The maxmind instructions for 64bit could be a lot better and that 64bit com+ registering PDF procedure shouldn't be necessary.

It would have helped if I had known what WOW64 actually meant. i.e. Windows on Windows64 (or to put it more meaningfully, Windows 32 bit running under windows 64 bit. Then the MS naming makes more sense.

Post Reply