X-Git-Url: https://git.p6c8.net/jirafeau_project.git/blobdiff_plain/93d7dffa6e851ee8e2c1c0708c78caff3fa35dd7..refs/heads/f_modularization_wip:/lib/functions.php?ds=inline
diff --git a/lib/functions.php b/lib/functions.php
index b6672fb..1d0241e 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -447,25 +447,62 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l
'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']));
@@ -478,7 +515,11 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l
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) {
@@ -517,7 +558,7 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l
$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);
@@ -549,6 +590,37 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l
'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
@@ -673,103 +745,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);
}
/**
@@ -879,7 +927,7 @@ function jirafeau_fileperms($path)
function jirafeau_admin_bug_report($cfg)
{
$out = "