Browse Source

Refactor post.php: split upload file hashing to a function

pull/107/head
Zankaria 3 months ago
parent
commit
799072d692
  1. 49
      post.php

49
post.php

@ -5,6 +5,39 @@
require_once 'inc/bootstrap.php';
/**
* Utility functions
*/
/**
* Get the md5 hash of the file.
*
* @param [type] $config instance configuration.
* @param [type] $file file to the the md5 of.
* @return string|false
*/
function md5_hash_of_file($config, $file) {
$cmd = false;
if ($config['bsd_md5']) {
$cmd = '/sbin/md5 -r';
}
if ($config['gnu_md5']) {
$cmd = 'md5sum';
}
if ($cmd) {
$output = shell_exec_error($cmd . " " . escapeshellarg($file));
$output = explode(' ', $output);
return $output[0];
} else {
return md5_file($file);
}
}
/**
* Method handling functions
*/
$dropped_post = false;
function handle_nntpchan()
@ -1007,14 +1040,6 @@ function handle_post()
$post['tracked_cites'] = markup($post['body'], true);
if ($post['has_file']) {
$md5cmd = false;
if ($config['bsd_md5']) {
$md5cmd = '/sbin/md5 -r';
}
if ($config['gnu_md5']) {
$md5cmd = 'md5sum';
}
$allhashes = '';
foreach ($post['files'] as $key => &$file) {
@ -1037,13 +1062,7 @@ function handle_post()
error($config['error']['nomove']);
}
if ($md5cmd) {
$output = shell_exec_error($md5cmd . " " . escapeshellarg($upload));
$output = explode(' ', $output);
$hash = $output[0];
} else {
$hash = md5_file($upload);
}
$hash = md5_hash_of_file($config, $upload);
$file['hash'] = $hash;
$allhashes .= $hash;

Loading…
Cancel
Save