forked from leftypol/leftypol
Refactor post.php: split upload file hashing to a function
This commit is contained in:
parent
8faf20f7ff
commit
799072d692
1 changed files with 34 additions and 15 deletions
49
post.php
49
post.php
|
@ -5,6 +5,39 @@
|
||||||
|
|
||||||
require_once 'inc/bootstrap.php';
|
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;
|
$dropped_post = false;
|
||||||
|
|
||||||
function handle_nntpchan()
|
function handle_nntpchan()
|
||||||
|
@ -1007,14 +1040,6 @@ function handle_post()
|
||||||
$post['tracked_cites'] = markup($post['body'], true);
|
$post['tracked_cites'] = markup($post['body'], true);
|
||||||
|
|
||||||
if ($post['has_file']) {
|
if ($post['has_file']) {
|
||||||
$md5cmd = false;
|
|
||||||
if ($config['bsd_md5']) {
|
|
||||||
$md5cmd = '/sbin/md5 -r';
|
|
||||||
}
|
|
||||||
if ($config['gnu_md5']) {
|
|
||||||
$md5cmd = 'md5sum';
|
|
||||||
}
|
|
||||||
|
|
||||||
$allhashes = '';
|
$allhashes = '';
|
||||||
|
|
||||||
foreach ($post['files'] as $key => &$file) {
|
foreach ($post['files'] as $key => &$file) {
|
||||||
|
@ -1037,13 +1062,7 @@ function handle_post()
|
||||||
error($config['error']['nomove']);
|
error($config['error']['nomove']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($md5cmd) {
|
$hash = md5_hash_of_file($config, $upload);
|
||||||
$output = shell_exec_error($md5cmd . " " . escapeshellarg($upload));
|
|
||||||
$output = explode(' ', $output);
|
|
||||||
$hash = $output[0];
|
|
||||||
} else {
|
|
||||||
$hash = md5_file($upload);
|
|
||||||
}
|
|
||||||
|
|
||||||
$file['hash'] = $hash;
|
$file['hash'] = $hash;
|
||||||
$allhashes .= $hash;
|
$allhashes .= $hash;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue