-
Notifications
You must be signed in to change notification settings - Fork 0
/
click.php
166 lines (159 loc) · 6.16 KB
/
click.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* ClickHeat : Enregistrement d'un clic suivi / Logging of a tracked click
*
* @author Yvan Taviaud - LabsMedia - www.labsmedia.com
* @since 27/10/2006
*/
/* Remove all "//" to enable debugging. Don't forget to disable this when you're done! */
// error_reporting(E_ALL);
// restore_error_handler();
// ini_set('display_errors', 1);
/* First of all, check if we are inside PhpMyVisites */
if (strpos(str_replace('\\', '/', __FILE__), 'plugins/ClickHeat/libs') !== false)
{
define('PIWIK_INCLUDE_PATH', str_replace('/plugins/ClickHeat/libs', '', str_replace('\\', '/', dirname(__FILE__))));
define('CLICKHEAT_ROOT', PIWIK_INCLUDE_PATH.'/libs/clickheat/');
define('IS_PIWIK_MODULE', true);
define('CLICKHEAT_CONFIG', PIWIK_INCLUDE_PATH.'/config/clickheat.php');
}
else
{
define('CLICKHEAT_ROOT', './');
define('IS_PIWIK_MODULE', false);
define('CLICKHEAT_CONFIG', CLICKHEAT_ROOT.'config/config.php');
}
/* Include config file */
include CLICKHEAT_CONFIG;
/* Check parameters */
if (!isset($clickheatConf) || !isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['w']) || !isset($_GET['g']) || !isset($_GET['s']) || !isset($_GET['b']) || !isset($_GET['c']))
{
exit('Parameters or config error');
}
/* Check referers */
if (is_array($clickheatConf['referers']))
{
if (!isset($_SERVER['HTTP_REFERER']))
{
exit('No domain in referer');
}
$referer = parse_url($_SERVER['HTTP_REFERER']);
if (!in_array($referer['host'], $clickheatConf['referers']))
{
exit('Forbidden domain ('.$referer['host'].'), change or remove security settings in the config panel to allow this one');
}
}
function cleanStrings($str)
{
if (function_exists('mb_strtolower'))
{
$str = mb_strtolower($str, 'utf-8');
}
else
{
$str = strtolower($str);
}
/* strtr() correctly handles multibyte */
$str = strtr($str, array('à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ā' => 'a', 'ă' => 'a', 'ą' => 'a', 'ç' => 'c', 'ć' => 'c', 'ĉ' => 'c', 'ċ' => 'c', 'č' => 'c', 'ď' => 'd', 'đ' => 'd', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ē' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ę' => 'e', 'ě' => 'e', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g', 'ĥ' => 'h', 'ħ' => 'h', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ĩ' => 'i', 'ī' => 'i', 'ĭ' => 'i', 'į' => 'i', 'ı' => 'i', 'ij' => 'i', 'ĵ' => 'j', 'ķ' => 'k', 'ĸ' => 'k', 'ĺ' => 'l', 'ļ' => 'l', 'ľ' => 'l', 'ŀ' => 'l', 'ł' => 'l', 'ñ' => 'n', 'ń' => 'n', 'ņ' => 'n', 'ň' => 'n', 'ʼn' => 'n', 'ŋ' => 'n', 'ð' => 'o', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ō' => 'o', 'ŏ' => 'o', 'ő' => 'o', 'œ' => 'o', 'ø' => 'o', 'ŕ' => 'r', 'ř' => 'r', 'ś' => 's', 'ŝ' => 's', 'ş' => 's', 'š' => 's', 'ſ' => 's', 'ţ' => 't', 'ť' => 't', 'ŧ' => 't', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ũ' => 'u', 'ū' => 'u', 'ŭ' => 'u', 'ů' => 'u', 'ű' => 'u', 'ų' => 'u', 'ŵ' => 'w', 'ý' => 'y', 'ÿ' => 'y', 'ŷ' => 'y', 'ź' => 'z', 'ż' => 'z', 'ž' => 'z'));
return substr(preg_replace('/[^a-z_0-9\-]+/', '.', $str), 0, 250);
}
/* Check if group, site and browser are letters-only */
$site = cleanStrings($_GET['s']);
$group = cleanStrings($_GET['g']);
if ($group === '')
{
exit('No group specified (clickHeatGroup empty)');
}
/* Check group */
if (is_array($clickheatConf['groups']))
{
if (!in_array($group, $clickheatConf['groups']))
{
exit('Forbidden group ('.$group.'), change or remove security settings in the config panel to allow this one');
}
}
$browser = preg_replace('/[^a-z]+/', '', strtolower($_GET['b']));
if ($browser === '')
{
exit('Browser empty');
}
$final = ltrim($site.','.$group, ',');
/* Limit file size */
if ($clickheatConf['filesize'] !== 0)
{
if (file_exists($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log') && filesize($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log') > $clickheatConf['filesize'])
{
exit('Filesize reached limit');
}
}
/* Logging the click */
$f = fopen($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log', 'a');
if (!is_resource($f))
{
/* Can't open the log, let's try to create the directory */
if (!is_dir(dirname($clickheatConf['logPath'])))
{
if (!mkdir(dirname($clickheatConf['logPath'])))
{
exit('Cannot create log directory: '.$clickheatConf['logPath']);
}
}
if (!is_dir($clickheatConf['logPath'].$final))
{
if (!mkdir($clickheatConf['logPath'].$final))
{
exit('Cannot create log directory: '.$clickheatConf['logPath'].$final);
}
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] !== '')
{
$f = fopen($clickheatConf['logPath'].$final.'/url.txt', 'w');
fputs($f, str_replace('debugclickheat', '', $_SERVER['HTTP_REFERER']).'>0>0>0');
fclose($f);
}
}
$f = fopen($clickheatConf['logPath'].$final.'/'.date('Y-m-d').'.log', 'a');
}
if (is_resource($f))
{
$logMe = true;
if (isset($_COOKIE['clickheat-admin']))
{
echo 'OK, but click not logged as you selected it in the admin panel ("Log my clicks/Enregistrer mes clics")';
$logMe = false;
}
elseif (IS_PIWIK_MODULE === true)
{
$site = (string) (int) $site; // prevents path injection
if (file_exists(PIWIK_INCLUDE_PATH.'/tmp/cache/tracker/'.$site.'.php'))
{
include(PIWIK_INCLUDE_PATH.'/tmp/cache/tracker/'.$site.'.php');
if (isset($content['excluded_ips']))
{
include(PIWIK_INCLUDE_PATH.'/core/Common.php');
include(PIWIK_INCLUDE_PATH.'/core/IP.php');
$ip = Piwik_IP::P2N(isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
if (Piwik_IP::isIpInRange($ip, $content['excluded_ips']) === true)
{
echo 'OK, but click not logged as you prevent this IP to be tracked in Piwik\'s configuration';
$logMe = false;
}
}
}
}
if ($logMe === true)
{
echo 'OK';
fputs($f, ((int) $_GET['x']).'|'.((int) $_GET['y']).'|'.((int) $_GET['w']).'|'.$browser.'|'.((int) $_GET['c'])."\n");
}
fclose($f);
}
else
{
echo 'KO, file not writable';
}
/* Temporary debug for Labsmedia.com, don't worry about this :-) */
if ($_SERVER['SERVER_NAME'] === 'www.labsmedia.com')
{
error_log("------------------------\n".var_export($_SERVER, true).var_export($_GET, true)."\n", 3, $clickheatConf['logPath'].'debug-bad-clicks.log');
}
?>