-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwatcher.php
87 lines (69 loc) · 1.58 KB
/
watcher.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
<?php
function getIPAddress()
{
// IP logging
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals)
$ip = getenv(REMOTE_ADDR);
else
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
}
function redirect()
{
$url = parameterValidator();
header( "Location: " . $url, TRUE, 301 );
}
function referred()
{
if(isset($_SERVER['HTTP_REFERER']))
$referred = $_SERVER['HTTP_REFERER'];
else
$referred = "NULL";
}
function parameter()
{
if (isset($_GET['s']) && $_GET['s'] != "")
return $_GET['s'];
else
exit;
}
function parameterValidator()
{
//Check if parameter() supplied is URL or URN
if(filter_var(parameter(), FILTER_VALIDATE_URL))
$url = parameter();
else
{
$protocol = "http://"; //assuming protocol is HTTP
$url = $protocol . parameter();
}
return $url;
}
function userAgent()
{
return $_SERVER['HTTP_USER_AGENT'];
}
function watcher()
{
$logFilename="log.txt"; //log file
$log=fopen("$logFilename", "a+");
$pattern = "/\btxt\b/i"; // only txt files
$date=date("l dS of F Y h:i:s A");
$ip = getIPAddress();
$userAgent = userAgent();
$referred = referred();
$param = parameter();
$data =
"Logged IP address: $ip, " .
"User-Agent: $userAgent, " .
"Referred by: $referred, " .
"Parameter: $param, " .
"Date logged: $date " .
"\n";
if(preg_match($pattern, $logFilename))
fputs($log, $data);
fclose($log); //close log
redirect();
}
?>