X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/ecfc8a70b8f33915e53ef2fc9ab14e77daa96e72..d9bd5ba08bc665d25049a87f6b8663c2a5c8aca3:/lib/functions.php?ds=sidebyside diff --git a/lib/functions.php b/lib/functions.php index 4e22796..ae3516a 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2,7 +2,7 @@ /* * Jirafeau, your web file repository * Copyright (C) 2008 Julien "axolotl" BERNARD - * Copyright (C) 2015 Jerome Jutteau + * Copyright (C) 2015 Jerome Jutteau * Copyright (C) 2015 Nicola Spanti (RyDroid) * * This program is free software: you can redistribute it and/or modify @@ -321,7 +321,7 @@ function jirafeau_delete_file($hash) /** hash file's content - * @param $method hash method, see 'file_hash' option. 'md5' or 'md5_outside'. + * @param $method hash method, see 'file_hash' option. Valid methods are 'md5', 'md5_outside' or 'random' * @param $file_path file to hash * @returns hash string */ @@ -332,6 +332,8 @@ function jirafeau_hash_file($method, $file_path) return jirafeau_md5_outside($file_path); case 'md5': return md5_file($file_path); + case 'random': + return jirafeau_gen_random(32); } return md5_file($file_path); } @@ -343,22 +345,30 @@ function jirafeau_hash_file($method, $file_path) */ function jirafeau_md5_outside($file_path) { - $size = filesize($file_path); - if ($size === false) { - $size = 0; - } + $out = false; $handle = fopen($file_path, "r"); if ($handle === false) { return false; } + $size = filesize($file_path); + if ($size === false) { + goto err; + } $first = fread($handle, 64); if ($first === false) { - return false; + goto err; + } + if (fseek($handle, $size < 64 ? 0 : $size - 64) == -1) { + goto err; } - fseek($handle, $size < 64 ? 0 : $size - 64); $last = fread($handle, 64); + if ($last === false) { + goto err; + } + $out = md5($first . $last . $size); + err: fclose($handle); - return md5($first . $last . $size); + return $out; } /** @@ -559,6 +569,14 @@ function check_errors($cfg) if (!is_writable(VAR_ASYNC)) { add_error(t('ASYNC_DIR_W'), VAR_ASYNC); } + + if ($cfg['enable_crypt'] && $cfg['litespeed_workaround']) { + add_error(t('INCOMPATIBLE_OPTIONS_W'), 'enable_crypt=true
litespeed_workaround=true'); + } + + if ($cfg['one_time_download'] && $cfg['litespeed_workaround']) { + add_error(t('INCOMPATIBLE_OPTIONS_W'), 'one_time_download=true
litespeed_workaround=true'); + } } /** @@ -609,15 +627,9 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) echo t('LS_FILES'); } echo ''; - echo ''; + echo '
'; echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; echo ''; echo ''; @@ -654,22 +666,15 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) echo ''; echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
' . t('FILENAME') . '' . t('TYPE') . '' . t('SIZE') . '' . t('EXPIRE') . '' . t('ONETIME') . '' . t('UPLOAD_DATE') . '' . t('ORIGIN') . '' . t('ACTION') . '
' . '' . jirafeau_escape($l['file_name']) . ''; - echo '' . jirafeau_escape($l['mime_type']) . '' . jirafeau_human_size($l['file_size']) . '' . ($l['time'] == -1 ? '∞' : jirafeau_get_datetimefield($l['time'])) . ''; - if ($l['onetime'] == 'O') { - echo 'Y'; - } else { - echo 'N'; - } - echo '' . jirafeau_get_datetimefield($l['upload_date']) . '' . $l['ip'] . '' . - '
' . + t('DL_PAGE') . '">' . jirafeau_escape($l['file_name']) . '
'; + echo t('TYPE') . ': ' . jirafeau_escape($l['mime_type']) . '
'; + echo t('SIZE') . ': ' . jirafeau_human_size($l['file_size']) . '
'; + echo t('EXPIRE') . ': ' . ($l['time'] == -1 ? '∞' : jirafeau_get_datetimefield($l['time'])) . '
'; + echo t('ONETIME') . ': ' . ($l['onetime'] == 'O' ? 'Yes' : 'No') . '
'; + echo t('UPLOAD_DATE') . ': ' . jirafeau_get_datetimefield($l['upload_date']) . '
'; + echo t('ORIGIN') . ': ' . $l['ip'] . '
'; + echo '
'; + echo '' . '' . '' . jirafeau_admin_csrf_field() . @@ -848,6 +853,10 @@ function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip) return; } + /* touch empty data file */ + $w_path = $p . $ref . '_data'; + touch($w_path); + /* md5 password or empty */ $password = ''; if (!empty($key)) { @@ -995,7 +1004,7 @@ function jirafeau_async_end($ref, $code, $crypt, $link_name_length, $file_hash_m $l = s2p("$hash_link"); if (!@mkdir(VAR_LINKS . $l, 0755, true) || !rename($link_tmp_name, VAR_LINKS . $l . $hash_link)) { - echo "Error"; + return 'Error'; } /* Clean async upload. */ @@ -1326,3 +1335,12 @@ function jirafeau_admin_csrf_field() { return ""; } + +function jirafeau_dir_size($dir) +{ + $size = 0; + foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $entry) { + $size += is_file($entry) ? filesize($entry) : jirafeau_dir_size($entry); + } + return $size; +}