matomo-log-analytics icon indicating copy to clipboard operation
matomo-log-analytics copied to clipboard

Detecting if website is using cloudflare

Open grzech1983 opened this issue 8 years ago • 2 comments

Hello,

does someone experienced issues with importing logs from sites which are using CloudFlare? I'm hosting services provider which is using Piwik as statistics application for clients websites. Some of clients are using CloudFlare for their websites. Hosting services are Windows IIS server based with added "CF-Connecting-IP" log param. If client is using CloudFlare at the end of each line in IIS website log file is being shown real customer IP address. If not then this column is empty. I'm wondering if someone else experienced similar scenario? IMHO this could be handled by having some condition statements like if "CF-Connecting-IP" contains IP then use it as viewer IP address else use "c-ip" column.

What do you think about it?

Thanks

grzech1983 avatar Jan 04 '17 21:01 grzech1983

This can be hacked (and probably done in much better way) by adding:

        'CF-Connecting-IP': '"?(?P<ip2>[\w*.:-]*)"?'

to fields array

right after:

'time-taken': '(?P<generation_time_secs>[.\d]+)',

and then just replace hit.ip field by using:

            if not format.get('ip2'):
                hit.ip = format.get('ip')
            else:
                hit.ip = format.get('ip2')
            try:
                hit.length = int(format.get('length'))

grzech1983 avatar Jan 05 '17 12:01 grzech1983

@grzech1983

  1. Would you mind posting a pull request with your change? It looks legitimate to me
  2. Could you paste here a short example log file from Cloudflare?

mattab avatar Jun 20 '17 01:06 mattab