-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecksum.php
119 lines (110 loc) · 2.85 KB
/
checksum.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
$DBH = new PDO("sqlite:checksum.db");
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$PrepareInsert = "INSERT INTO md5_file (file,md5) VALUES ";
if (isset($_POST['Wfile']))
{
$sql = "DELETE FROM md5_file";
$STH = $DBH->prepare($sql);
$STH->execute();
}
function InsertDB($sql) {
global $DBH;
$STH = $DBH->prepare($sql);
$STH->execute();
}
function SelectDB($file) {
global $DBH;
$sql = "SELECT * FROM md5_file WHERE file = '$file'";
$STH = $DBH->prepare($sql);
$STH->execute();
$row = $STH->fetch();
return $row;
}
$pathLen = 0;
function prePad($level)
{
$ss = "";
for ($ii = 0; $ii < $level; $ii++)
{
$ss = $ss . "| ";
}
return $ss;
}
function myScanDir($dir, $level, $rootLen)
{
global $PrepareInsert;
global $pathLen;
global $i;
if ($handle = opendir($dir)) {
$allFiles = array();
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir . "/" . $entry))
{
$allFiles[] = "D: " . $dir . "/" . $entry;
}
else
{
$allFiles[] = "F: " . $dir . "/" . $entry;
}
}
}
closedir($handle);
natsort($allFiles);
foreach($allFiles as $value)
{
$displayName = substr($value, $rootLen + 4);
$fileName = substr($value, 3);
$linkName = str_replace(" ", "%20", substr($value, $pathLen + 3));
if (is_dir($fileName)) {
echo prePad($level) . $linkName . "<br>\n";
myScanDir($fileName, $level + 1, strlen($fileName));
} else {
if ($displayName=="checksum.db") continue;
$md5file = md5_file($fileName);
echo prePad($level) . "<a href=\"" . $linkName . "\" style=\"text-decoration:none;\">" . $displayName . "</a> Sum: ".$md5file;
$old_MD5 = SelectDB($fileName)[1];
if (!isset($_POST['Wfile']))
if ($old_MD5 != $md5file)
echo " <b><font color='red'>This file has been changed has change: $old_MD5</font></b>";
if (isset($_POST['Wfile']))
{
$PrepareInsert = $PrepareInsert. "('$fileName','$md5file'),";
$i++;
if ($i == 500)
{
InsertDB(substr($PrepareInsert,0,-1));
$PrepareInsert = "INSERT INTO md5_file (file,md5) VALUES ";
$i=1;
}
}
echo "<br>";
}
}
}
}
?><!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Site Map</title>
</head>
<body>
<h1>Site Map</h1>
<form method="post" action="">
Renew this MD5-files to database.
<input type="submit" name="Wfile" value="Save">
</form>
<p style="font-family:'Courier New', Courier, monospace; font-size:small;">
<?php
//Can change to your directory
$root = getcwd();
$pathLen = strlen($root);
myScanDir($root, 0, strlen($root));
if (isset($_POST['Wfile']))
InsertDB(substr($PrepareInsert,0,-1));
?>
</p>
</body>
</html>