-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd5checksum.php
59 lines (51 loc) · 1.57 KB
/
md5checksum.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
<?php
/**
* md5checksum.php - compute and check MD5 message digest
*
* author : Sammy Tahtah
*/
$options = getopt("c:", array("check:"));
function md5_checksum($file) {
if (is_file($file)) {
return md5_file($file)." ".$file;
} else {
error_log( '"'.$file.'"'." is not a valid path to a file.");
}
return null;
}
function read_filelist($filelist) {
$md5hash;
$path;
foreach (file($filelist, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES) as $line) {
$md5hash = substr($line, 0, strpos($line, " "));
$path = substr($line, strpos($line, " ") + 2);
$line = md5_checksum($path);
if (!empty($line)) {
if (!strcmp($md5hash, substr($line, 0, strpos($line, " "))))
echo $path.": OK ";
else
echo "\r\n[FAIL] ".$path."\r\n";
}
}
}
function read_array_filelist($files) {
foreach ($files as $file) {
if (is_file($file))
read_filelist($file);
else
error_log($file." is not a valid file.");
}
}
if (isset($argv[1]) && empty($options))
echo md5_checksum($argv[1])."\n";
elseif (!empty($options) && (!empty($options['c']) ||
!empty($options['check']))) {
if (is_file($options['c']) || is_file($options['check']))
(is_file($options['c']) ? read_filelist($options['c']) :
read_filelist($options['check']));
else
(!empty($options['c']) ? read_array_filelist($options['c']) :
read_array_filelist($options['check']));
} else
echo "md5checksum.php [OPTION] [FILE]\r\n\r\nPrint or check MD5 (128 bits) checksums.\r\n-c, --check\r\n\tread MD5 sums from FILE and compare it to the related files.\r\n\r\n";
?>