summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2016-05-05 08:21:21 +0200
committerczaks <marcin@6irc.net>2016-05-05 08:22:19 +0200
commitdcf5d699bd6ce5770ebd515cc14219f3015dd63a (patch)
treeeac498723113cfcea08c64d228858adce4005f1f
parent97681613274c35061bcbd8d14e03600d5fb18345 (diff)
simplify the md5 execution logic
-rw-r--r--inc/api.php7
-rw-r--r--inc/config.php4
-rw-r--r--post.php44
3 files changed, 30 insertions, 25 deletions
diff --git a/inc/api.php b/inc/api.php
index 57e4d367..9483200e 100644
--- a/inc/api.php
+++ b/inc/api.php
@@ -92,7 +92,12 @@ class Api {
$dotPos = strrpos($file->file, '.');
$apiPost['ext'] = substr($file->file, $dotPos);
$apiPost['tim'] = substr($file->file, 0, $dotPos);
- $apiPost['md5'] = base64_encode(hex2bin($post->filehash));
+ 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));
+ }
}
private function translatePost($post, $threadsPage = false) {
diff --git a/inc/config.php b/inc/config.php
index c0e967af..b92c4ac0 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -807,8 +807,8 @@
// Set this to true if you're using a BSD
$config['bsd_md5'] = false;
- // Set this to true if you're having problems with image duplicated error and bsd_md5 doesn't help.
- $config['php_md5'] = false;
+ // Set this to true if you're using Linux and you can execute `md5sum` binary.
+ $config['gnu_md5'] = false;
// Number of posts in a "View Last X Posts" page
$config['noko50_count'] = 50;
diff --git a/post.php b/post.php
index 729170a7..5c755a3c 100644
--- a/post.php
+++ b/post.php
@@ -572,7 +572,12 @@ if (isset($_POST['delete'])) {
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) {
if ($post['op'] && $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
$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'];
if (!is_readable($upload))
error($config['error']['nomove']);
+
+ if ($md5cmd) {
+ $output = shell_exec_error($md5cmd . " < " . escapeshellarg($upload));
+ $output = explode(' ', $output);
+ $hash = $output[0];
+ }
+ else {
+ $hash = md5_file($upload);
+ }
+
+ $file['hash'] = $hash;
+ $allhashes .= $hash;
}
-
- $md5cmd = $config['bsd_md5'] ? 'md5 -r' : 'md5sum';
- if (!$config['php_md5'] && $output = shell_exec_error("cat $filenames | $md5cmd")) {
- $explodedvar = explode(' ', $output);
- $hash = $explodedvar[0];
+ if (count ($post['files']) == 1) {
$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);
}
}