-
Notifications
You must be signed in to change notification settings - Fork 0
/
sweeptemp.php
103 lines (86 loc) · 3.08 KB
/
sweeptemp.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
<?
/* OXID SweepTemp
Author: [email protected]
Licence: GPLv3
*/
$tmp_folder = 'tmp';
$tmp_garbage = Array();
$tmp_smarty = Array();
//alowed_ips
$allowed_ips = array(
'111.222.333.444',
'555.666.777.888',
'999.111.222.333'
);
//Function to determine ip
Class ServerInfo
{
public $servervars;
public function __construct($servervars)
{
$this->servervars = $servervars;
}
function getClientIP()
{
$ipaddress = 'UNKNOWN'; // Set the ipaddress to unknown
if ($this->servervars['HTTP_CLIENT_IP']) // Start capturing his ip
{
$ipaddress = $this->servervars['HTTP_CLIENT_IP'];
} elseif ($this->servervars['HTTP_X_FORWARDED_FOR']) {
$ipaddress = $this->servervars['HTTP_X_FORWARDED_FOR'];
} elseif ($this->servervars['HTTP_X_FORWARDED']) {
$ipaddress = $this->servervars['HTTP_X_FORWARDED'];
} elseif ($this->servervars['HTTP_FORWARDED_FOR']) {
$ipaddress = $this->servervars['HTTP_FORWARDED_FOR'];
} elseif ($this->servervars['HTTP_FORWARDED']) {
$ipaddress = $this->servervars['HTTP_FORWARDED'];
} elseif ($this->servervars['REMOTE_ADDR']) {
$ipaddress = $this->servervars['REMOTE_ADDR'];
}
return $ipaddress;
}
}
$myServerInfo = new ServerInfo($_SERVER);
if (!in_array($myServerInfo->getClientIP(), $allowed_ips)) {
exit('Your IP is not allowed to sweep!');
}
//Define the Files to sweep by Regex
$tmp_garbage[] = '^[0-9a-z\^\%A-Z_]*oxforgotpw[0-9a-z\^\%A-Z_]*\.php$';
$tmp_garbage[] = '^[0-9a-z\^%A-Z_]*oxcontent[0-9]*oxbaseshop\.php$';
$tmp_garbage[] = '^[0-9a-z\^\%A-Z_]*\.tpl\.php$';
$tmp_garbage[] = '^[0-9a-z\^\%A-Z_]*sort[0-9a-z\^\%A-Z_]*\.tpl\.php$';
$tmp_garbage[] = '^[0-9a-z\^\%A-Z_]*basket[0-9a-z\^\%A-Z_]*\.tpl\.php$';
$tmp_garbage[] = '^[0-9a-z\^%A-Z_]*\_i18n\.txt$';
$tmp_garbage[] = '^[0-9a-z\^%A-Z_]*\_allfields\_1\.txt$';
$tmp_garbage[] = '^oxpec\_[0-9a-z\^%A-Z_]*seo\.txt$';
$tmp_garbage[] = '^oxpec\_[0-9a-z\^%A-Z_]*allviews\.txt$';
$tmp_garbage[] = '^oxpec\_[0-9a-z\^%A-Z_]*\_allfields\_\.txt$';
$tmp_garbage[] = '^oxpec\_langcache\_[0-9a-z\^%A-Z_]*\_default\.txt$';
$tmp_garbage[] = '^oxpec\_[0-9a-z\^%A-Z_]*Cache\.txt$';
$tmp_garbage[] = '^oxpec\_menu\_[0-9a-z\^%A-Z_]*\_xml\.txt$';
$tmp_garbage[] = '^oxpec\_oxuser\_[0-9a-z\^%A-Z_]*\.txt$';
$tmp_garbage[] = '^oxpec\_oxshops\_[0-9a-z\^%A-Z_]*\.txt$';
//Scan folder and delete
$files = scandir($tmp_folder . '/');
$count = 0;
foreach ($tmp_garbage as $regex) {
foreach ($files as $file) {
if (preg_match('/' . $regex . '/', $file) && file_exists($tmp_folder . '/' . $file)) {
unlink($tmp_folder . '/' . $file);
$count++;
}
}
}
// Sweep Smarty-TMP
//Define the Files to sweep by Regex
$smartyfiles = scandir($tmp_folder . '/smarty/');
$smartycount = 0;
foreach ($smartyfiles as $file) {
if ($file != '.' && $file != '..') {
unlink($tmp_folder . '/smarty/' . $file);
$smartycount++;
}
}
echo $count . ' Temp-File(s) deleted!';
echo ' // ' . $smartycount . ' Smarty-Tempfile(s) deleted!';
?>