Welcome! Log In Create A New Profile

Dirty: Script to ignore Dynamic IP Adresses

Posted by gerdw 
gerdw [ # ]
February 08, 2012 02:59PM
I have a customer who has an dynamic ip, 10 PCs and hundreds of Users. The default profile gave them the piwik monitored site as a startpage, so they falsify the piwik statistic.

It was not (easy) possible to change this for existing users, nor could i set the ignore cookie stable for all Users.

I set up the script bellow on the server which is run every hour by cron.

It compares the Dynamic IP the Customer has (dyndns.org) with the IP stored in the Piwik konfiguration and updates it when needed.

I know that this is realy dirty but it might help someone.

Please note the security risk of putting the piwik mysql-pw in the script in cleartext.




#!/bin/sh

# This Script checks an Dynamic-IP and writes it into the Piwik-DB in order to ignore requests
# from that IP
#
# This will overwrite the List of IP-Adresses to be ignored in Piwik!!
#
# Only Testest with Piwik 1.6 on Debian
# Use at your own Risk
# Be carefull with the Access rights to this script as the piwik-db-passsword has to be put in
# Plaintext into this Script.
#
# gw@gi-it.de
#
# GPLed

host="127.0.0.1"
username="piwikusername"
password="piwik-mysql-password"
dbname="piwik-db-name"
sitename="site-name-to-ignore"
dynipname="myhostname.dyndns.org"

logger "Update DynIP $sitename in Piwik-DB:"

altip=`mysql -p$password -u $username -D $dbname --execute="SELECT excluded_ips from site WHERE name = '$sitename' \g \q" | tail -n 1`
logger "Old-IP: $altip"
neuip=`host $dynipname | awk '{print $3}'`
logger "New-IP: $neuip"

if [ "$neuip" = "$altip" ] ; then
logger "Nothing to do"
exit 1
else
logger "Update IP in Piwik-DB"
mysql -p$password -u $username -D $dbname --execute="update site SET excluded_ips='$neuip' WHERE name = '$sitename' \g \q"
logger "Test Success..."
altip=`mysql -p$password -u $username -D $dbname --execute="SELECT excluded_ips from site WHERE name = '$sitename' \g \q" | tail -n 1`
if [ "$neuip" = "$altip" ] ; then
logger "Update successfull"
exit 0
else
logger "Error while updating"
exit 2
fi
fi



Edited 1 time(s). Last edit at 02/08/2012 03:00PM by gerdw.
sirtet [ # ]
January 02, 2013 05:31PM
Nice! seems like the only solution so far.

I wrote a summary of all "exclude traffic by hostname"- related posts over at
Make Global list of Excluded IPs accept domains ?
in that post, there's also a solution mentioned using a shell-script.
So maybe add new posts there.
Sorry, only registered users may post in this forum.

Click here to login

Free Forum support is provided by the Piwik Community. If you require any urgent or professional help, contact Piwik Professional Services team!