Skip to content

Commit 0c92b26

Browse files
committed
first working version of visitor counter - try to identify a user with
- Browser-Fingerpring - IP Those data gets converted to "useless" string via SHA1 with current Date in the strings. That results a value which makes the user not traceable between the days. Data gets collected with a 1x1 transparent pixel.
1 parent 26eb8fe commit 0c92b26

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed

customization/www_content/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
</script>
8787
</head>
8888
<body>
89+
<img src="../vc_counter.php" />
8990
<div id="page">
9091
<!--====================================Navigation================================================================-->
9192
<nav id="top_nav">
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/******** Config File for download statistics *****/
4+
5+
// Everything must be inside the function, because within the dirlisting
6+
// the globals term does not work correct :(
7+
8+
function vc_get_config () {
9+
10+
$config = array (
11+
12+
"SQLITE_FILE" => "sqlite:/opt/piratebox/share/vc_statistics.sqlite",
13+
"HTML_TEMPLATE_FILE" => "content/vc_statistics.html.php" ,
14+
"sortBy" => "day" ,
15+
"sortOrder" => 'DESV' , # ASC, DESC
16+
"top_max" => "5", #Display top n on option "top"
17+
"output_type" => "html" , # Display HTML per default or only JSON
18+
"list_type" => "top" , #Display "all" or only "top" on default
19+
20+
);
21+
return $config ;
22+
}
23+
24+
global $config;
25+
26+
?>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
require_once "vc.conf.php";
4+
5+
6+
function vc_do_db_connect() {
7+
$config = vc_get_config();
8+
if ( ! $db = new PDO ( $config['SQLITE_FILE'] ) ) {
9+
print_r ( $db->errorInfo() ) ;
10+
die ( "Error, couldn't open database " );
11+
}
12+
13+
$sth = $db->prepare ( 'CREATE TABLE IF NOT EXISTS vc_statistics ( day text, visitor text, PRIMARY KEY ( day , visitor ) ON CONFLICT IGNORE )');
14+
if ( !$sth ) {
15+
print_r ( $db->errorInfo());
16+
die ( "statement error" );
17+
}
18+
19+
if ( ! $sth->execute () )
20+
die ( "Error creating table: ". $sth->errorInfo ());
21+
22+
return $db;
23+
}
24+
25+
26+
function vc_save_visitor ( $visitor_key , $debug = false ) {
27+
if ( !$debug ) {
28+
error_reporting(0);
29+
}
30+
31+
if ( date ( 'Y') < 2013 ) {
32+
if ( $debug ) print "not saving because system-year less then 2013";
33+
return false;
34+
}
35+
$db= vc_do_db_connect();
36+
37+
$sth = $db->prepare ( 'INSERT OR IGNORE INTO vc_statistics ( day , visitor ) VALUES ( :day , :visitor )');
38+
39+
if ( !$sth ) {
40+
print_r ( $db->errorInfo());
41+
die ( "statement error" );
42+
}
43+
44+
45+
$sth->bindParam ( ':day' , date ( 'Y-m-d' ) );
46+
$sth->bindParam ( ':visitor', $visitor_key );
47+
48+
if ( ! $sth->execute () ) {
49+
if ( $debug )
50+
print_r ( $sth->errorInfo() );
51+
}
52+
53+
}
54+
55+
56+
57+
function vc_read_stat_sum_per_day_only ( $day="%" ) {
58+
$config = dl_get_config();
59+
return dl_read_stat_sum_per_day ($day , $config["sortBy"] , $config["sortOrder"] , "all" , $config["top_max"] );
60+
61+
}
62+
63+
function vc_read_stat_sum_per_day ($path="%" , $sortBy , $sort, $type="all" , $limit ) {
64+
65+
$config = vc_get_config();
66+
if ( ! isset ( $sortBy ) )
67+
$sortBy=$config["sortBy"];
68+
69+
if ( ! isset ( $sort ) )
70+
$sort=$config["sortOrder"];
71+
72+
if ( ! isset ( $limit ))
73+
$limit=$config["top_max"];
74+
75+
76+
$db = vc_do_db_connect();
77+
78+
if ( $type == "all" ) {
79+
$sth = $db->prepare ( " SELECT day, count( visitor) FROM vc_statistics WHERE day LIKE :day ORDER by $sortBy $sort GROUP BY day ");
80+
} elseif ( $type == "top" ) {
81+
$sth = $db->prepare ( " SELECT day, count(visitor) FROM vc_statistics WHERE day LIKE :day ORDER by $sortBy $sort GROUP BY day LIMIT 1 , :max ");
82+
$sth->bindParam (':max' , $limit, PDO::PARAM_INT );
83+
}
84+
85+
if ( $sth ) {
86+
$generic_day = "";
87+
if ( $day == "%" ) {
88+
$generic_day = "%" ;
89+
} else {
90+
$generic_day = $day.'%' ;
91+
}
92+
$sth->bindParam ( ':day' , $generic_day );
93+
if ( ! $sth->execute() ) {
94+
print_r ( $sth->errorInfo() );
95+
die ( "Error executing statement ");
96+
}
97+
$result = $sth->fetchAll();
98+
# Tidy array up, I only want named keys
99+
foreach ( $result as &$line ) {
100+
unset ( $line[0] );
101+
unset ( $line[1] );
102+
}
103+
return $result;
104+
105+
} else {
106+
print_r ($db->errorInfo());
107+
die ("\n no valid statement could be found");
108+
}
109+
110+
}
111+
112+
?>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
$debug = false;
4+
5+
if ( ! isset ($_GET['debug']) ) {
6+
7+
Header("Content-type: image/gif");
8+
Header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
9+
Header("Cache-Control: no-cache");
10+
Header("Cache-Control: must-revalidate");
11+
12+
// This prints the raw 1 pixel gif to the browser
13+
// make sure this is one long line!
14+
15+
printf ("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
16+
17+
} else {
18+
$debug = true;
19+
}
20+
21+
22+
$date = date ( 'Y-m-d' );
23+
24+
#Encrypt combination of IP + Date + Useragend. So one user only have a specific string per day
25+
$client_string = $_ENV['REMOTE_ADDR'] . $_ENV['HTTP_USER_AGENT'] . $date ;
26+
27+
$sha = sha1($client_string);
28+
29+
include ("vc.func.php");
30+
31+
vc_save_visitor ( $sha , $debug );
32+
33+
34+
?>

0 commit comments

Comments
 (0)