-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFileMD.php
99 lines (90 loc) · 2.61 KB
/
FileMD.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
<?php
//$whiteIpList = ";172.17.150.134;";
if (isset($whiteIpList) && !strpos($whiteIpList, GetClientIP()) >= 0) {
echo '对不起,页面请求失败!';
return;
}
//$proxyIp
DoGetMd5();
function DoGetMd5() {
if (!empty($_POST['d'])) {
$dir = $_POST['d'];
} else if (!empty($_GET['d'])) {
$dir = $_GET['d'];
} else {
echo 'no input';
return;
}
if (!empty($_POST['ignoreDir'])) {
$ignoreDir = $_POST['ignoreDir'];
} else if (!empty($_GET['ignoreDir'])) {
$ignoreDir = $_GET['ignoreDir'];
} else {
$ignoreDir = '';
}
$ignoreDir = explode('|', $ignoreDir);
$ret = array();
LoopDirMd5($dir, $ret, $dir, $ignoreDir);
header('Content-type:text/plain');
foreach ($ret as $key => $value) {
echo str_replace('/', '\\', $key) . ',' . strtoupper($value) . "\n";
}
}
function LoopDirMd5($dir, &$ret, $root, $ignoreDir) {
if (!is_dir($dir)) {
return;
}
// 是否要忽略的目录判断
$isIgnore = false;
foreach ($ignoreDir as $val) {
if ($val === '') {
continue;
}
$compare = '/' . str_replace('\\', '/', $val);
$idx = stripos($dir, $compare);
if ($idx === false) {
$idx = stripos($dir, str_replace('/', '\\', $val));
}
if ($idx !== false) {
$isIgnore = true;
break;
}
}
if ($isIgnore) {
return;
}
if (!($dh = opendir($dir))) {
return;
}
// 移除最后一个斜杠
$chEnd = $dir[strlen($dir) - 1];
if ($chEnd == '/' || $chEnd == '\\') {
$dir = substr($dir, 0, strlen($dir) - 1);
}
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$showname = iconv('gb2312', 'utf-8', $file);
$fullpath = $dir . '/' . $file;
if (is_file($fullpath)) {
$path = str_replace($root, '', $fullpath);
$md5 = md5_file($fullpath);
$ret[$path] = $md5;
} else if (is_dir($fullpath)) {
LoopDirMd5($fullpath, $ret, $root, $ignoreDir);
}
}
}
function GetClientIP() {
$cip = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$cip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// 注意,客户端可以伪造 X-Forwarded-For: 192.168.156.45,从而导致我们得到假IP
$cip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
$cip = $_SERVER['REMOTE_ADDR'];
}
return $cip;
}