From: Blackeye <14815724-Blackstareye@users.noreply.gitlab.com>
Date: Mon, 19 Aug 2024 12:35:12 +0000 (+0000)
Subject: Merge branch 'next-release' into 'f_modularization_wip_rebased'
X-Git-Url: https://git.p6c8.net/jirafeau_project.git/commitdiff_plain/d00f70e3fa9a3a15bf4d9ba09eaa11bb8868bda7?ds=inline;hp=-c
Merge branch 'next-release' into 'f_modularization_wip_rebased'
# Conflicts:
# index.php
---
d00f70e3fa9a3a15bf4d9ba09eaa11bb8868bda7
diff --combined README.md
index a5b2352,4fff851..f343ed9
--- a/README.md
+++ b/README.md
@@@ -63,7 -63,7 +63,7 @@@ Jirafeau project won't evolve to a fil
## Installation
This shows how to install Jirafeau by your own, it's quite simple but you can
- also use a [docker image](https://hub.docker.com/r/mojo42/jirafeau/) or build
+ also use a [docker image](https://gitlab.com/jirafeau/Jirafeau/container_registry/) or build
it yourself. Check [docker folder](docker/README.md) for more informations.
System requirements:
@@@ -311,6 -311,4 +311,6 @@@ Feel free to create an [issue](https://
### Can I buy you a coffee?
-You can [drop few bucks for Jérôme Jutteau](https://www.paypal.com/paypalme/jeromejutteau).
+You can [drop few bucks for Jérôme Jutteau](https://www.paypal.com/paypalme/jeromejutteau)
+
+Many Thanks <3
diff --combined index.php
index fd8586d,b7e2606..43bb81d
--- a/index.php
+++ b/index.php
@@@ -25,7 -25,7 +25,7 @@@ require(JIRAFEAU_ROOT . 'lib/settings.p
require(JIRAFEAU_ROOT . 'lib/functions.php');
require(JIRAFEAU_ROOT . 'lib/lang.php');
- if ($cfg['download_password_requirement'] === "generated"){
+ if ($cfg['download_password_requirement'] === "generated") {
$download_pass = jirafeau_gen_download_pass($cfg['download_password_gen_len'], $cfg['download_password_gen_chars']);
}
@@@ -101,8 -101,70 +101,8 @@@ elseif (true === jirafeau_challenge_upl
}
?>
-
@@@ -150,24 -212,70 +150,24 @@@
echo ' />';
}
- if ($cfg['download_password_requirement'] === 'generated'){
+ if ($cfg['download_password_requirement'] === 'generated') {
echo '';
- }else{
+ } else {
echo '
| ';
echo ' |
';
}?>
|
- |
+
+
+ |
'
. date_format($ts, 'Y-m-d H:i') . ' (GMT)';
@@@ -447,62 -446,25 +446,62 @@@ function jirafeau_upload($file, $one_ti
'link' => '',
'delete_link' => ''));
}
+ jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, $link_name_length, $file_hash_method);
+}
- /* array representing no error */
- $noerr = array('has_error' => false, 'why' => '');
-
+/**
+ *
+ * @param bool $crypt_module_enabled
+ * @param string $file_path
+ * @return array [bool, string]
+ */
+function jirafeau_handle_add_file_encryption($crypt_module_enabled, $file_path) {
/* Crypt file if option is enabled. */
$crypted = false;
$crypt_key = '';
- if ($crypt == true && !(extension_loaded('sodium') == true)) {
+ if ($crypt_module_enabled == true && !(extension_loaded('sodium') == true)) {
error_log("PHP extension sodium not loaded, won't encrypt in Jirafeau");
}
- if ($crypt == true && extension_loaded('sodium') == true) {
- $crypt_key = jirafeau_encrypt_file($file['tmp_name'], $file['tmp_name'].'crypt');
+ if ($crypt_module_enabled == true && extension_loaded('sodium') == true) {
+ $crypt_key = jirafeau_encrypt_file($file_path, $file_path.'crypt');
if (strlen($crypt_key) > 0) {
- if (rename($file['tmp_name'].'crypt', $file['tmp_name']) === true) {
+ if (rename($file_path.'crypt', $file_path) === true) {
$crypted = true;
}
}
}
+ return [$crypted, $crypt_key];
+}
+
+/**
+ * adds an uploaded or copy/linked local file
+ * @param $file the file struct given by $_FILE[]
+ * @param $one_time_download is the file a one time download ?
+ * @param $key if not empty, protect the file with this key
+ * @param $time the time of validity of the file
+ * @param $ip uploader's ip
+ * @param $crypt boolean asking to crypt or not
+ * @param $link_name_length size of the link name
+ * @param $is_upload, determines if the file is uploaded or local - it controls which file-functions are used
+ * @return array an array containing some information
+ * 'error' => information on possible errors
+ * 'link' => the link name of the uploaded file
+ * 'delete_link' => the link code to delete file
+ */
+function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, $link_name_length, $file_hash_method, $is_upload = true)
+{
+ // TODO needs to be adapted
+ $move_operation = $is_upload ? 'move_uploaded_file' : 'symlink';
+
+ /* array representing no error */
+ $noerr = array('has_error' => false, 'why' => '');
+
+ $crypted = false;
+ $crypt_key = '';
+ list($crypted, $crypt_key) = jirafeau_handle_add_file_encryption($crypt, $file['tmp_name']);
+
+
/* file information */
$hash = jirafeau_hash_file($file_hash_method, $file['tmp_name']);
$name = str_replace(NL, '', trim($file['name']));
@@@ -515,11 -477,7 +514,11 @@@
if (file_exists(VAR_FILES . $p . $hash)) {
$rc = unlink($file['tmp_name']);
} elseif ((file_exists(VAR_FILES . $p) || @mkdir(VAR_FILES . $p, 0755, true))
- && move_uploaded_file($file['tmp_name'], VAR_FILES . $p . $hash)) {
+ &&
+ //move_uploaded_file($file['tmp_name'], VAR_FILES . $p . $hash))
+ $move_operation($file['tmp_name'], VAR_FILES . $p . $hash))
+ {
+
$rc = true;
}
if (!$rc) {
@@@ -558,7 -516,7 +557,7 @@@
$handle,
$name . NL. $mime_type . NL. $size . NL. $password . NL. $time .
NL . $hash. NL . ($one_time_download ? 'O' : 'R') . NL . time() .
- NL . $ip . NL. $delete_link_code . NL . ($crypted ? 'C2' : 'O')
+ NL . $ip . NL. $delete_link_code . NL . ($crypted ? 'C' : 'O')
);
fclose($handle);
$hash_link = substr(base_16_to_64(md5_file($link_tmp_name)), 0, $link_name_length);
@@@ -590,37 -548,6 +589,37 @@@
'crypt_key' => $crypt_key);
}
+
+function jirafeau_admin_list_table ($name, $file_hash, $link_hash, $visitor_function = null) {
+ echo '
';
+}
+
+
+
+
+
/**
* Tells if a mime-type is viewable in a browser
* @param $mime the mime type
@@@ -745,79 -672,103 +744,79 @@@ function jirafeau_get_link($hash
}
/**
- * List files in admin interface.
+ * List files ii folder in admin interface.
*/
function jirafeau_admin_list($name, $file_hash, $link_hash)
{
- echo '
';
+ };
+ jirafeau_admin_list_table($name, $file_hash, $link_hash, $function);
}
/**
@@@ -1058,8 -1009,8 +1057,8 @@@ function jirafeau_async_delete($ref
function jirafeau_async_init($filename, $type, $one_time, $key, $time, $ip)
{
/* Create temporary folder. */
- $ref;
- $p;
+ $ref = '';
+ $p = '';
$code = jirafeau_gen_random(4);
do {
$ref = jirafeau_gen_random(32);
@@@ -1287,7 -1238,7 +1286,7 @@@ function jirafeau_encrypt_file($fp_src
$enc = sodium_crypto_secretstream_xchacha20poly1305_push($crypt_state, $to_enc);
if (fwrite($w, $enc) === false) {
- return '';
+ return '';
}
}
@@@ -1768,229 -1719,3 +1767,229 @@@ function jirafeau_write_download_stats(
fwrite($handle, $count . NL . time() . NL . $ip);
fclose($handle);
}
+
+function jirafeau_create_upload_finished_box($preview = true) {
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 'minute',
+ 'label' => '1_MIN'
+ ),
+ array(
+ 'value' => 'hour',
+ 'label' => '1_H'
+ ),
+ array(
+ 'value' => 'day',
+ 'label' => '1_D'
+ ),
+ array(
+ 'value' => 'week',
+ 'label' => '1_W'
+ ),
+ array(
+ 'value' => 'fortnight',
+ 'label' => '2_W'
+ ),
+ array(
+ 'value' => 'month',
+ 'label' => '1_M'
+ ),
+ array(
+ 'value' => 'quarter',
+ 'label' => '1_Q'
+ ),
+ array(
+ 'value' => 'year',
+ 'label' => '1_Y'
+ ),
+ array(
+ 'value' => 'none',
+ 'label' => 'NONE'
+ )
+ );
+}
+
+
+
+ /**
+ *
+ * creates the time selection field
+ * @param mixed $cfg
+ * @return void
+ */
+ function jirafeau_create_selection_array($cfg) {
+ echo
+ '
';
+ }
+
+ function jirafeau_datestr_to_int ($time_str) {
+ $time = time();
+ switch ($time_str) {
+ case 'minute':
+ $time += JIRAFEAU_MINUTE;
+ break;
+ case 'hour':
+ $time += JIRAFEAU_HOUR;
+ break;
+ case 'day':
+ $time += JIRAFEAU_DAY;
+ break;
+ case 'week':
+ $time += JIRAFEAU_WEEK;
+ break;
+ case 'fortnight':
+ $time += JIRAFEAU_FORTNIGHT;
+ break;
+ case 'month':
+ $time += JIRAFEAU_MONTH;
+ break;
+ case 'quarter':
+ $time += JIRAFEAU_QUARTER;
+ break;
+ case 'year':
+ $time += JIRAFEAU_YEAR;
+ break;
+ default:
+ $time = JIRAFEAU_INFINITY;
+ break;
+ }
+ return $time;
+}
+
+
+
+
+/**
+ * links or copy a local file
+ * TODO: boolean in config for linking
+ * @param string $filepath
+ * @param $one_time_download is the file a one time download ?
+ * @param $key if not empty, protect the file with this key
+ * @param $time the time of validity of the file
+ * @param $ip uploader's ip
+ * @param $crypt boolean asking to crypt or not
+ * @param $link_name_length size of the link name
+ * @returns an array containing some information
+ * 'error' => information on possible errors
+ * 'link' => the link name of the uploaded file
+ * 'delete_link' => the link code to delete file
+ */
+function jirafeau_copy_local_file($local_file_path, $one_time_download, $key, $time, $ip, $crypt, $link_name_length, $file_hash_method) {
+
+ if (!file_exists($local_file_path)) {
+ return (array(
+ 'error' =>
+ array('has_error' => true,
+ 'why' => t('INTERNAL_ERROR_FILE_NOT_EXIST')),
+ 'link' =>'',
+ 'delete_link' => ''));
+ }
+ if(
+ // sanity check if file can be opened
+ $file = fopen($local_file_path, "r")
+ )
+ {
+ // close file pointer - it's not needed here
+ fclose($file);
+ $time_in_int = jirafeau_datestr_to_int($time);
+ return jirafeau_add_file(
+ jirafeau_create_file_array($local_file_path),
+ $one_time_download,
+ $key,
+ $time_in_int,
+ $ip,
+ $crypt,
+ $link_name_length,
+ $file_hash_method,
+ false
+ );
+ }
+ else {
+ return (array(
+ 'error' =>
+ array('has_error' => true,
+ 'why' => t('INTERNAL_ERROR_FP_OPEN_LOCAL')),
+ 'link' =>'',
+ 'delete_link' => ''));
+ }
+
+}
+
+
+function jirafeau_create_file_array($file_path) {
+ return
+ [
+ 'type' => mime_content_type($file_path),
+ 'tmp_name' => $file_path,
+ 'name' => basename($file_path),
+ 'size' => filesize($file_path),
+ ];
+}
diff --combined script.php
index 95888b5,8ebcce3..6ef117e
--- a/script.php
+++ b/script.php
@@@ -81,22 -81,51 +81,22 @@@ if (isset($_FILES['file']) && is_writab
$key = '';
if (isset($_POST['key'])) {
$key = $_POST['key'];
- if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
- if (!preg_match($cfg['download_password_policy_regex'], $key)){
+ if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+ if (!preg_match($cfg['download_password_policy_regex'], $key)) {
echo 'Error 14: The download password is not complying to the security standards.';
exit;
}
}
- }elseif ($cfg['download_password_requirement'] !== 'optional'){
+ } elseif ($cfg['download_password_requirement'] !== 'optional') {
echo 'Error 13: The parameter password is required.';
exit;
}
- $time = time();
if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) {
echo 'Error 4: The parameter time is invalid.';
exit;
} else {
- switch ($_POST['time']) {
- case 'minute':
- $time += JIRAFEAU_MINUTE;
- break;
- case 'hour':
- $time += JIRAFEAU_HOUR;
- break;
- case 'day':
- $time += JIRAFEAU_DAY;
- break;
- case 'week':
- $time += JIRAFEAU_WEEK;
- break;
- case 'fortnight':
- $time += JIRAFEAU_FORTNIGHT;
- break;
- case 'month':
- $time += JIRAFEAU_MONTH;
- break;
- case 'quarter':
- $time += JIRAFEAU_QUARTER;
- break;
- case 'year':
- $time += JIRAFEAU_YEAR;
- break;
- default:
- $time = JIRAFEAU_INFINITY;
- break;
- }
+ $time = jirafeau_datestr_to_int($_POST['time']);
}
// Check file size
@@@ -146,13 -175,13 +146,13 @@@
$key = '';
if (isset($_POST['key'])) {
$key = $_POST['key'];
- if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
- if (!preg_match($cfg['download_password_policy_regex'], $key)){
+ if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+ if (!preg_match($cfg['download_password_policy_regex'], $key)) {
echo 'Error 14: The download password is not complying to the security standards.';
exit;
}
}
- }elseif ($cfg['download_password_requirement'] !== 'optional'){
+ } elseif ($cfg['download_password_requirement'] !== 'optional') {
echo 'Error 13: The parameter password is required.';
exit;
}
@@@ -422,13 -451,13 +422,13 @@@ elseif (isset($_GET['init_async']))
$key = '';
if (isset($_POST['key'])) {
$key = $_POST['key'];
- if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex'){
- if (!preg_match($cfg['download_password_policy_regex'], $key)){
+ if ($cfg['download_password_requirement'] !== 'generated' && $cfg['download_password_policy'] === 'regex') {
+ if (!preg_match($cfg['download_password_policy_regex'], $key)) {
echo 'Error 14: The download password is not complying to the security standards.';
exit;
}
}
- }elseif ($cfg['download_password_requirement'] !== 'optional'){
+ } elseif ($cfg['download_password_requirement'] !== 'optional') {
echo 'Error 13: The parameter password is required.';
exit;
}
@@@ -439,11 -468,40 +439,11 @@@
exit;
}
- $time = time();
if (!isset($_POST['time']) || !$cfg['availabilities'][$_POST['time']]) {
echo 'Error 22';
exit;
} else {
- switch ($_POST['time']) {
- case 'minute':
- $time += JIRAFEAU_MINUTE;
- break;
- case 'hour':
- $time += JIRAFEAU_HOUR;
- break;
- case 'day':
- $time += JIRAFEAU_DAY;
- break;
- case 'week':
- $time += JIRAFEAU_WEEK;
- break;
- case 'fortnight':
- $time += JIRAFEAU_FORTNIGHT;
- break;
- case 'month':
- $time += JIRAFEAU_MONTH;
- break;
- case 'quarter':
- $time += JIRAFEAU_QUARTER;
- break;
- case 'year':
- $time += JIRAFEAU_YEAR;
- break;
- default:
- $time = JIRAFEAU_INFINITY;
- break;
- }
+ $time = jirafeau_datestr_to_int($_POST['time']);
}
if ($cfg['store_uploader_ip']) {