/*
* Jirafeau, your web file repository
* Copyright (C) 2008 Julien "axolotl" BERNARD <axolotl@magieeternelle.org>
- * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
+ * Copyright (C) 2015 Jerome Jutteau <jerome@jutteau.fr>
* Copyright (C) 2015 Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
*
* This program is free software: you can redistribute it and/or modify
/** 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
*/
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);
}
*/
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;
}
/**
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<br>litespeed_workaround=true');
+ }
+
+ if ($cfg['one_time_download'] && $cfg['litespeed_workaround']) {
+ add_error(t('INCOMPATIBLE_OPTIONS_W'), 'one_time_download=true<br>litespeed_workaround=true');
+ }
}
/**
echo t('LS_FILES');
}
echo '</legend>';
- echo '<table border="1" width="1100">';
+ echo '<table>';
echo '<tr>';
- echo '<th>' . t('FILENAME') . '</th>';
- echo '<th>' . t('TYPE') . '</th>';
- echo '<th>' . t('SIZE') . '</th>';
- echo '<th>' . t('EXPIRE') . '</th>';
- echo '<th>' . t('ONETIME') . '</th>';
- echo '<th>' . t('UPLOAD_DATE') . '</th>';
- echo '<th>' . t('ORIGIN') . '</th>';
+ echo '<th></th>';
echo '<th>' . t('ACTION') . '</th>';
echo '</tr>';
echo '<tr>';
echo '<td>' .
'<strong><a id="upload_link" href="f.php?h='. jirafeau_escape($node) .'" title="' .
- t('DL_PAGE') . '">' . jirafeau_escape($l['file_name']) . '</a></strong>';
- echo '</td>';
- echo '<td>' . jirafeau_escape($l['mime_type']) . '</td>';
- echo '<td>' . jirafeau_human_size($l['file_size']) . '</td>';
- echo '<td>' . ($l['time'] == -1 ? '∞' : jirafeau_get_datetimefield($l['time'])) . '</td>';
- echo '<td>';
- if ($l['onetime'] == 'O') {
- echo 'Y';
- } else {
- echo 'N';
- }
- echo '</td>';
- echo '<td>' . jirafeau_get_datetimefield($l['upload_date']) . '</td>';
- echo '<td>' . $l['ip'] . '</td>';
- echo '<td>' .
- '<form method="post">' .
+ t('DL_PAGE') . '">' . jirafeau_escape($l['file_name']) . '</a></strong><br/>';
+ echo t('TYPE') . ': ' . jirafeau_escape($l['mime_type']) . '<br/>';
+ echo t('SIZE') . ': ' . jirafeau_human_size($l['file_size']) . '<br>';
+ echo t('EXPIRE') . ': ' . ($l['time'] == -1 ? '∞' : jirafeau_get_datetimefield($l['time'])) . '<br/>';
+ echo t('ONETIME') . ': ' . ($l['onetime'] == 'O' ? 'Yes' : 'No') . '<br/>';
+ echo t('UPLOAD_DATE') . ': ' . jirafeau_get_datetimefield($l['upload_date']) . '<br/>';
+ echo t('ORIGIN') . ': ' . $l['ip'] . '<br/>';
+ echo '</td><td>';
+ echo '<form method="post">' .
'<input type = "hidden" name = "action" value = "download"/>' .
'<input type = "hidden" name = "link" value = "' . $node . '"/>' .
jirafeau_admin_csrf_field() .
return;
}
+ /* touch empty data file */
+ $w_path = $p . $ref . '_data';
+ touch($w_path);
+
/* md5 password or empty */
$password = '';
if (!empty($key)) {
$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. */
{
return "<input type='hidden' name='admin_csrf' value='". $_SESSION['admin_csrf'] . "'/>";
}
+
+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;
+}