-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
78 lines (71 loc) · 2.18 KB
/
index.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
<?php
// config here
include 'config.php';
include 'curl.php';
$queryString = $_SERVER['QUERY_STRING'];
$arrExplode = explode('info:', $queryString);
// no info:: found
if (count($arrExplode) == 2) {
$url = $arrExplode['1'];
$isok = 1;
} else {
$url = 'null';
$isok = 0;
}
if(!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = $_SERVER["HTTP_CLIENT_IP"];
} elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (!empty($_SERVER["REMOTE_ADDR"])) {
$ip = $_SERVER["REMOTE_ADDR"];
} else {
$ip = "0.0.0.0";
}
$time = date("Y-m-d H:i:s", time()+3600*4);
$userAgent = $_SERVER['HTTP_USER_AGENT'];
if (!$userAgent) {
$userAgent = "NullUserAgent";
}
//Ignore site list
$search = array(
'localhost',
);
$replace = array(
'',
);
if(str_replace($search, $replace, $url) != $url) {
$title = 'Ignore';
} else {
$curl = new PCurl();
$curl->setUrl($url);
$title = $curl->getTitle();
}
// uuid
if (strstr($_SERVER['HTTP_USER_AGENT'], '@@@', TRUE) !==FALSE) {
$uuid = strstr($_SERVER['HTTP_USER_AGENT'], '@@@', TRUE);
} else {
$uuid = NULL;
}
//log to my db
$conn = mysql_connect($mysqlHost, $mysqlUser, $mysqlPwd);
if (!$conn) {
exit('Cannot connect to mysql '.mysql_errno());
}
mysql_select_db('google');
mysql_query("set names 'utf8'");
$timeFile = date("Y-m-d H:i:s", time()-300);
$sqlFive= "select count(*) as num from chromeurllog where time > '$timeFile' and url = '$url'";
$resFive = mysql_query($sqlFive);
while ($row = mysql_fetch_assoc($resFive)) {
// repeat log a same url in many time in 5 minutes
if ($row['num'] > 0 ) {
exit('Repeat');
}
}
if (is_null($uuid)) {
$sql = sprintf("insert into chromeurllog (url, time, ip, querystring, isok, title, useragent) values ('%s' , '%s', '%s', '%s', '%s', '%s', '%s')", $url, $time, $ip, $queryString, $isok, $title, $userAgent);
} else {
$sql = sprintf("insert into chromeurllog (url, time, ip, querystring, isok, title, useragent, chromeuuid) values ('%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $url, $time, $ip, $queryString, $isok, $title, $userAgent, $uuid);
}
mysql_query($sql);
mysql_close($conn);