Posts: 30
Threads: 6
Joined: Jun 2020
Reputation:
1
Location: Mexico
I have a dll which in Audit records user activity and IP, using WebApplication.IP. This under delphi 10.2.3 and IW15.x
A new application using same audit (Delphi 12.2 IW16.2), reports under WebApplication.IP our internal server rather than user IP.
Should I use a diferent routine?
Posts: 30
Threads: 6
Joined: Jun 2020
Reputation:
1
Location: Mexico
Since we have an internal proxy, we obtained it this way:
function TIWUserSession.DameHeaderHTTP(const ANombre: string): string;
var
i, p: Integer;
Linea: string;
begin
Result:='';
for i:=0 to WebApplication.Request.RawHeaders.Count-1 do
begin
Linea:=WebApplication.Request.RawHeaders[i];
p:=Pos(':',Linea);
if (p>0) and SameText(Trim(Copy(Linea,1,p-1)),ANombre) then
begin
Result:=Trim(Copy(Linea,p+1,MaxInt));
Exit;
end;
end;
end;
function TIWUserSession.DameIPCliente: string;
var
IPRemota, XFF: string;
p: Integer;
begin
IPRemota:=WebApplication.Request.RemoteAddr;
Result:=IPRemota;
if IPRemota='XXX.XXX.XXX.XXX' then //internal proxy IP
begin
XFF:=DameHeaderHTTP('X-Forwarded-For');
// Si hubiera varios valores, toma el último agregado por el proxy.
p:=LastDelimiter(',',XFF);
if p>0 then
XFF:=Trim(Copy(XFF,p+1,MaxInt))
else
XFF:=Trim(XFF);
if XFF<>'' then
Result:=XFF;
end;
end;