NAT Policy - how to log disconnected server ip

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

Moderator: Qbik Staff

NAT Policy - how to log disconnected server ip

Postby sawi » Oct 11 13 3:31 am

Hi Qbik Wingate Team

I doing test on wingate trial at my test server.
I enable NAT Policy (add new policy -> any nat controller -> client connect)
so I add some {{Session.ServerPort}} & {{Session.ServerIp}} to whitelist, if server port & ip not in the list, it will be disconnected.

so what can i do to log all disconnected connection (log all disconnected {{Session.ServerPort}} & {{Session.ServerIp}} ) ?

thanks :)
sawi
Senior Member
 
Posts: 129
Joined: Mar 26 09 4:49 pm

Re: NAT Policy - how to log disconnected server ip

Postby adrien » Oct 29 13 3:32 pm

Hi

When the connection is terminated, the session logs a termination reason of "terminated in event handler". These are logged only at debug level though.

Alternatively you can use the Lua Script policy item to open a file, write to it and then close it.

Or a SQL policy item to insert a record into a database. In fact this may be easiest.

Regards

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

Re: NAT Policy - how to log disconnected server ip

Postby sawi » Oct 29 13 8:37 pm

thanks Adrien.

I'm not so good in programming, so I had try several Lua script test, but failed to successfully get what i want.

this is example what i had do.

this line already there when i drag Lua script from policy toolbox :
Code: Select all
--return true or false depending on whether you wish the
--'Yes' or 'No' path to be taken
function filter(User, Session, Event)
   return true;
end


so below that line i add this line :
Code: Select all
local file = io.open("NATlog.txt", "a")
file:write("Session.ServerIP")
file:close()


when i open the log file, it's succesfully read & write, but it don't write a server ip address, it only show the text "Session.ServerIP", not the server ip address that disconnected by policy.

maybe somebody can show me the correct programming code.
thanks for reading n helping :)
sawi
Senior Member
 
Posts: 129
Joined: Mar 26 09 4:49 pm

Re: NAT Policy - how to log disconnected server ip

Postby adrien » Oct 29 13 10:42 pm

Hi

in script languages, normally anything in quotes is taken literally (actually called a literal). So it prints the text in quotes. If you want to print the value of the variable, take away the quotes, e.g.

Code: Select all
local file = io.open("NATlog.txt", "a")
file:write(Session.ServerIP)
file:close()


If you want to put them each on their own line, you could do something like

Code: Select all
local file = io.open("NATlog.txt", "a")
line = Session.ServerIP.."\n";
file:write(line)
file:close()


Regards

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


Return to WinGate

Who is online

Users browsing this forum: No registered users and 6 guests

cron