Country IP

Use this forum to post questions relating to WinGate, feature requests, technical or configuration problems

Moderator: Qbik Staff

Country IP

Postby JR Africa » Sep 04 18 11:34 pm

I have sent this to Qbik support direct and was wondering if anyone in the community has managed to successfully extract IpToCountry.CountryForIP from the Message.GetHeader("X-SF-Originating-IP") and compare it to a data list lookup.
While I know it is a chore to get the originating IP from a message header the main issue here is that I want to be able to parse this info without physically inputting the IP address, but rather by using Wingates embedded symbols.

I can obtain the IP address from Message.GetHeader("X-SF-Originating-IP").

When I try and put it into the IPToCountry.CountryForIp function it unfortunately looks at me like I’m mad.

I have tried the following to parse the information :

I have tried using the policy directly via

{{IPToCountry.CountryForIp({{Message.GetHeader("X-SF-Originating-IP")}})}} – ERROR : unable to convert IpToCountryManager to Text

I have also attempted to set a session variable using Javascript
function filter(Session, Envelope, Message, Event)
{
Session.SetData("IncMailIP",Message.GetHeader("X-SF-Originating-IP"));
if(Session.GetData("IncMailIP")==Message.GetHeader("X-SF-Originating-IP"))
{
return true;
}
}

And then call this via the policy
{{IPToCountry.CountryForIp({{Session.GetData("IncMailIP")}})}} – ERROR : unable to convert IpToCountryManager to Text

I have tried numerous variations
{{IPToCountry.CountryForIp(Message.GetHeader("X-SF-Originating-IP"))}}
{{IPToCountry.CountryForIp(Session.GetData("IncMailIP"))}}

The policy just doesn’t seem to want to accept any other form of input other than a direct string.

Anyone have any joy with this ?

Thanks
J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Sep 05 18 7:01 pm

Hi

you shouldn't nest (or need to nest) {{ ... }}

basically where you see


some text including {{ something }} in it

then the value of something is converted into text and replaces the whole statement in {{ }} to yield an over-all string (textual) result.

so in a list lookup item, it's lookng up text, so if this is the result of some execution of script, you would have the outer-most {{ ... }}

{{IPToCountry.CountryForIp({{Message.GetHeader("X-SF-Originating-IP")}})}}

would be

{{ IPToCountry.CountryForIp(Message.GetHeader("X-SF-Originating-IP")) }}

And if X-SF-Originating-IP is an ip address then you should get the 2 character country code for it from this.

Regards

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Sep 06 18 7:36 pm

Hi Adrien

Already tried that variation unfortunately got the same error. See attached image.

J
Attachments
123.jpg
123.jpg (33.25 KiB) Viewed 610 times
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Sep 06 18 11:48 pm

that looks like a bug in WinGate then. It must be reporting the wrong type when returning the country code.
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Sep 07 18 6:50 pm

Thanks Adrien. Please keep me posted if it is a bug.

I would appreciate a hotfix for this if poss.

J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Sep 10 18 10:28 am

Hi

I checked the code and the types are correct in the registration of the function and results.

So that makes me suspect the schema script runtime interpreter is not seeing the member accessing (function call). You could try putting parentheses around the whole call, e.g.

{{ ( IPToCountry.CountryForIp(Message.GetHeader("X-SF-Originating-IP")) ) }}

That will force it to tie the IPToCountry object to the call to CountryForIp

Regards

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Sep 11 18 8:28 pm

Hi Adrien

Still didn't work unfortunately. See attached.

J
Attachments
2.jpg
2.jpg (46.68 KiB) Viewed 591 times
1.jpg
1.jpg (28.98 KiB) Viewed 591 times
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Sep 12 18 10:24 am

Hi

what sort of license are you using? It's restricted to enterprise only, and the function will return an error if your license doesn't support it.

That error probably wouldn't be seen because it's embedded in a string in this case.

Regards

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Sep 12 18 6:23 pm

Hi Adrien

Sum total 43 user enterprise licence.

Is there any chance you can attach a policy that will work with this scenario from your test environment so I can import into my system and test ?

All I need as you can see is to return a country code from Message.GetHeader("X-SF-Originating-IP"), and if you indicate it should be working as intended I must be doing something wrong somewhere.

I have tried everything Adrien, and nothing works as it should.

Thanks
J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Sep 14 18 1:49 pm

Hi

Sorry to mess you around. I did a full debug on this, stepping through the script interpreter which is fairly involved.

I found a bug in the IPToCountry module which is causing this problem.

So sorry it's taken so long to track this down.

I'll do another build and send you a link.

Regards

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby adrien » Sep 14 18 3:15 pm

adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Sep 26 18 5:06 pm

Thanks Adrien

Am away on business atm so will give it a go when I get back.

J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby JR Africa » Oct 02 18 9:44 pm

Hi Adrien

Installed the patch and it is now returning a value.

There appears to be a small glitch however in that it is returning the country code with a preceding space.

i.e. instead of returning "ZA" it is returning " ZA" and this is causing the data list lookup to fail.

Can you check if this is the case your side ?

Thanks
J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Oct 09 18 2:54 pm

Hi

check there's no space preceding the {{ in the list lookup item.

Regards

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland

Re: Country IP

Postby JR Africa » Oct 17 18 6:34 pm

Hi Adrien

No spacing in {{Message.GetHeader("X-SF-Originating-IP")}} - {{IPToCountry.CountryForIp(Message.GetHeader("X-SF-Originating-IP"))}}

I bypassed the issue by using wildcards.

J
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby JR Africa » Oct 17 18 6:36 pm

On the plus side using this new feature I successfully block approximately 95% of spam, phishing and all the other crap that comes through mail.

Good job on the IPToCountry.CountryForIp module.
JR Africa
 
Posts: 33
Joined: Aug 31 12 2:20 am

Re: Country IP

Postby adrien » Oct 18 18 2:02 pm

great! thanks for the update.

I'm still not sure where the space is coming from for you. We use this feature a lot and don't get spaces.

Wherever you see an edit field which takes script items wrapped in {{ }} then anything outside the {{ }} is copied to the output verbatim.

So for example if we had e.g. Session.ClientIp is 192.168.0.1, then

BOB_IP{{Session.ClientIp}}

would resolve to

BOB_IP192.168.0.1

So the most likely source of the space is an extraneous space outside of a {{ }} pair somewhere.

Cheers

Adrien
adrien
Qbik Staff
 
Posts: 5245
Joined: Sep 03 03 2:54 pm
Location: Auckland


Return to WinGate

Who is online

Users browsing this forum: adrien, Bing [Bot] and 6 guests