mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-27 17:00:52 +01:00
simplify the md5 execution logic
This commit is contained in:
parent
9768161327
commit
dcf5d699bd
@ -92,8 +92,13 @@ class Api {
|
|||||||
$dotPos = strrpos($file->file, '.');
|
$dotPos = strrpos($file->file, '.');
|
||||||
$apiPost['ext'] = substr($file->file, $dotPos);
|
$apiPost['ext'] = substr($file->file, $dotPos);
|
||||||
$apiPost['tim'] = substr($file->file, 0, $dotPos);
|
$apiPost['tim'] = substr($file->file, 0, $dotPos);
|
||||||
|
if (isset ($file->hash) && $post->filehash) {
|
||||||
|
$apiPost['md5'] = base64_encode(hex2bin($file->hash));
|
||||||
|
}
|
||||||
|
else if (isset ($post->filehash) && $post->filehash) {
|
||||||
$apiPost['md5'] = base64_encode(hex2bin($post->filehash));
|
$apiPost['md5'] = base64_encode(hex2bin($post->filehash));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function translatePost($post, $threadsPage = false) {
|
private function translatePost($post, $threadsPage = false) {
|
||||||
global $config, $board;
|
global $config, $board;
|
||||||
|
@ -807,8 +807,8 @@
|
|||||||
// Set this to true if you're using a BSD
|
// Set this to true if you're using a BSD
|
||||||
$config['bsd_md5'] = false;
|
$config['bsd_md5'] = false;
|
||||||
|
|
||||||
// Set this to true if you're having problems with image duplicated error and bsd_md5 doesn't help.
|
// Set this to true if you're using Linux and you can execute `md5sum` binary.
|
||||||
$config['php_md5'] = false;
|
$config['gnu_md5'] = false;
|
||||||
|
|
||||||
// Number of posts in a "View Last X Posts" page
|
// Number of posts in a "View Last X Posts" page
|
||||||
$config['noko50_count'] = 50;
|
$config['noko50_count'] = 50;
|
||||||
|
40
post.php
40
post.php
@ -572,7 +572,12 @@ if (isset($_POST['delete'])) {
|
|||||||
|
|
||||||
|
|
||||||
if ($post['has_file']) {
|
if ($post['has_file']) {
|
||||||
$fnarray = array();
|
$md5cmd = false;
|
||||||
|
if ($config['bsd_md5']) $md5cmd = 'md5 -r';
|
||||||
|
if ($config['gnu_md5']) $md5cmd = 'md5sum';
|
||||||
|
|
||||||
|
$allhashes = '';
|
||||||
|
|
||||||
foreach ($post['files'] as $key => &$file) {
|
foreach ($post['files'] as $key => &$file) {
|
||||||
if ($post['op'] && $config['allowed_ext_op']) {
|
if ($post['op'] && $config['allowed_ext_op']) {
|
||||||
if (!in_array($file['extension'], $config['allowed_ext_op']))
|
if (!in_array($file['extension'], $config['allowed_ext_op']))
|
||||||
@ -586,34 +591,29 @@ if (isset($_POST['delete'])) {
|
|||||||
// Truncate filename if it is too long
|
// Truncate filename if it is too long
|
||||||
$file['filename'] = mb_substr($file['filename'], 0, $config['max_filename_len']);
|
$file['filename'] = mb_substr($file['filename'], 0, $config['max_filename_len']);
|
||||||
|
|
||||||
if (!isset($filenames)) {
|
|
||||||
$filenames = escapeshellarg($file['tmp_name']);
|
|
||||||
} else {
|
|
||||||
$filenames .= (' ' . escapeshellarg($file['tmp_name']));
|
|
||||||
}
|
|
||||||
|
|
||||||
$fnarray[] = $file['tmp_name'];
|
|
||||||
|
|
||||||
$upload = $file['tmp_name'];
|
$upload = $file['tmp_name'];
|
||||||
|
|
||||||
if (!is_readable($upload))
|
if (!is_readable($upload))
|
||||||
error($config['error']['nomove']);
|
error($config['error']['nomove']);
|
||||||
|
|
||||||
|
if ($md5cmd) {
|
||||||
|
$output = shell_exec_error($md5cmd . " < " . escapeshellarg($upload));
|
||||||
|
$output = explode(' ', $output);
|
||||||
|
$hash = $output[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$hash = md5_file($upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
$md5cmd = $config['bsd_md5'] ? 'md5 -r' : 'md5sum';
|
$file['hash'] = $hash;
|
||||||
|
$allhashes .= $hash;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$config['php_md5'] && $output = shell_exec_error("cat $filenames | $md5cmd")) {
|
if (count ($post['files']) == 1) {
|
||||||
$explodedvar = explode(' ', $output);
|
|
||||||
$hash = $explodedvar[0];
|
|
||||||
$post['filehash'] = $hash;
|
$post['filehash'] = $hash;
|
||||||
} elseif ($config['max_images'] === 1) {
|
|
||||||
$post['filehash'] = md5_file($upload);
|
|
||||||
} else {
|
|
||||||
$str_to_hash = '';
|
|
||||||
foreach ($fnarray as $i => $f) {
|
|
||||||
$str_to_hash .= file_get_contents($f);
|
|
||||||
}
|
}
|
||||||
$post['filehash'] = md5($str_to_hash);
|
else {
|
||||||
|
$post['filehash'] = md5($allhashes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user