Author Topic: Macro for logging visitor's IP (using Cloudflare)  (Read 1080 times)

0 Members and 1 Guest are viewing this topic.

Offline sergio

  • Occasional poster
  • *
  • Posts: 26
    • View Profile
Macro for logging visitor's IP (using Cloudflare)
« on: October 28, 2017, 03:29:01 PM »
Hi there! I'm needing some help setting up a macro, to be able to see my visitors IP on the HFS's log. Since I'm using Cloudflare, I currently only see (in the HFS's log) the external IP of Cloudflare, and not the real visitor's IP. Reading the Cloudflare help, I see Cloudflare adds two useful "HTTP headers", like "CF-Connecting-IP:" and "X-Forwarded-For:". Those headers contain the visitors IP. If I only could parse those headers on the HFS's log, that would be awesome. I only need that: reading the "X-Forwarded-For:" value from the HTTP header, and register that on the HFS's log. Cheers!...

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1861
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #1 on: October 29, 2017, 08:07:49 PM »
to query an header entrance there is this macro  {.header|xxxxxxxx.}

Quote
{.add to log| request
   Cloudflare IP       : %ip%
   CF-Connecting-IP : {.header|CF-Connecting-IP.}
   X-Forwarded-For  : {.header|X-Forwarded-For.}
.}

Offline sergio

  • Occasional poster
  • *
  • Posts: 26
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #2 on: October 30, 2017, 06:33:53 PM »
Thanks Mars.

I enter the code at the beginning of the head tag
Is it the right place?

works well. But when it is entered by direct link, it does not work.
example, mihfs.com/file.zip
How is this resolved?

Code: [Select]
<head>
{.add to log| request
   Cloudflare IP       : %ip%
   CF-Connecting-IP : {.header|CF-Connecting-IP.}
   X-Forwarded-For  : {.header|X-Forwarded-For.}
.}
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>{.!HFS.} %folder%</title>
<link rel="stylesheet" href="/?mode=section&id=style.css" type="text/css">
    <script type="text/javascript" src="/?mode=jquery"></script>
<link rel="shortcut icon" href="/favicon.ico">
<style class='trash-me'>
.onlyscript, button[onclick] { display:none; }
</style>
    <script>
    // this object will store some %symbols% in the javascript space, so that libs can read them
    HFS = { folder:'{.js encode|%folder%.}', number:%number%, paged:{.!option.paged.} };
    </script>
<script type="text/javascript" src="/?mode=section&id=lib.js"></script>
</head>

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1861
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #3 on: October 31, 2017, 02:38:09 PM »
I did not understand what's wrong.

did you get information for the last two lines or are they blank as below?

15:01:38 127.0.0.1:2243 request
>    Cloudflare IP       : 127.0.0.1
>    CF-Connecting-IP :
>    X-Forwarded-For  :

on the hfs-log, do a right click and select "requests dump" in the "log what" list  and  you must obtain the list of the complete header as in the log

Offline sergio

  • Occasional poster
  • *
  • Posts: 26
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #4 on: October 31, 2017, 03:45:33 PM »
if I enter http://myhfs.com

register the 2 ip correctly

15:01:38 127.0.0.1:2243 request
>    Cloudflare IP       : 127.0.0.1
>    CF-Connecting-IP :   correctly
>    X-Forwarded-For  :   correctly


if enter link direct http://myhfs.com/file.zip

only register IP Cloudflare.
it no longer appears:

15:01:38 127.0.0.1:2243 request
>    Cloudflare IP       : 127.0.0.1
>    CF-Connecting-IP :   correctly
>    X-Forwarded-For  :   correctly

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1861
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #5 on: October 31, 2017, 03:51:39 PM »
I suppose that  http://myhfs.com/file.zip is a direct access to hfs without going through Cloudflare, if it is so, then the headers are not initiated and remain empty

compare the dump requests obtained in the hfs log for both cases, directly  by http://myhfs.com/file.zip and trough Cloudflare

Offline sergio

  • Occasional poster
  • *
  • Posts: 26
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #6 on: October 31, 2017, 06:25:02 PM »
I just verified that activating in hfs  "Requests dump" register IP Cloudflare and visitor correctly. without the need to add the previous code.
I had not noticed that option.

problem solved.

Thanks Mars for your great help.

Offline rejetto

  • Administrator
  • Tireless poster
  • *
  • Posts: 12903
    • View Profile
Re: Macro for logging visitor's IP (using Cloudflare)
« Reply #7 on: November 04, 2017, 11:21:04 PM »
hi guys,
HFS actually supports the x-forwarded-for header.
There's an option that has no part in the GUI, but it is editable in your HFS.INI file.
Search for "forwarded-mask", and put the IP of cloudflare (that you see in the log).