From ea13ecd5272b130c028b76b91b2a05ea65fd565b Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Mon, 14 Oct 2024 16:26:16 +0200 Subject: [PATCH] Fixed every error detected by php-cs-fixer (except the single_space_around_construct type) --- admin.php | 9 +- index.php | 30 +++---- install.php | 2 +- lib/functions.js.php | 24 +++-- lib/functions.php | 193 +++++++++++++++++++--------------------- lib/template/header.php | 4 +- script.php | 6 +- 7 files changed, 133 insertions(+), 135 deletions(-) diff --git a/admin.php b/admin.php index a6bacd3..f8270a2 100644 --- a/admin.php +++ b/admin.php @@ -37,17 +37,18 @@ if (php_sapi_name() == "cli") { if ($cfg['installation_done'] == false) { die("Installation not completed yet.\n"); } - if ((count($argv)>1) && $argv[1]=="clean_expired") { + if ((count($argv) > 1) && $argv[1] == 'clean_expired') { $total = jirafeau_admin_clean(); echo "$total expired files deleted.\n"; - } elseif ((count($argv)>1) && $argv[1]=="clean_async") { + } elseif ((count($argv) > 1) && $argv[1] == 'clean_async') { $total = jirafeau_admin_clean_async(); echo "$total old unfinished transfers deleted.\n"; } else { die("No command found. Should be admin.php .\n"); } -// Second check: Challenge by IP -} elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) { +} +/* Second check: Challenge by IP */ +elseif (true === jirafeau_challenge_admin_ip($cfg, get_ip_address($cfg))) { /* Disable admin interface if we have a empty admin password. */ if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) { require(JIRAFEAU_ROOT . 'lib/template/header.php'); diff --git a/index.php b/index.php index da6ee2f..435e059 100644 --- a/index.php +++ b/index.php @@ -130,7 +130,7 @@ elseif (true === jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) { 0) { echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB."; } @@ -143,26 +143,26 @@ elseif (true === jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) { if ($cfg['one_time_download']) { echo '' . t('ONE_TIME_DL') . ':'; echo ''; } - if ($cfg['download_password_requirement'] === 'generated') { - echo ''; - } else { - echo ''; - echo ''; - }?> +if ($cfg['download_password_requirement'] === 'generated') { + echo ''; +} else { + echo ''; + echo ''; +}?> diff --git a/install.php b/install.php index 2550aa6..ebda6f5 100644 --- a/install.php +++ b/install.php @@ -153,7 +153,7 @@ break; 'abcdefghijklmnopqrstuvwxyz' . '0123456789'; $len_alphanum = strlen($alphanum); $var = 'var-'; - for ($i = 0; $i . */ - function template_js_preview_link() { +function template_js_preview_link() +{ ?> if (!!document.getElementById('preview_link')) { @@ -44,8 +45,9 @@ } } // Download page var download_link_href = 'f.php?h=' + reference; @@ -60,7 +62,8 @@ function template_js_download_page() { } // Email link var b = encodeURIComponent(" \"" + filename + "\":") + "%0D" + "%0A"; @@ -72,7 +75,8 @@ function template_js_email_link() { } // Delete link var delete_link_href = 'f.php?h=' + reference + '&d=' + delete_code; @@ -80,7 +84,8 @@ function template_js_delete_link() { document.getElementById('delete_link_text').innerHTML = web_root + delete_link_href; // Direct download link var direct_download_link_href = 'f.php?h=' + reference + '&d=1'; @@ -91,8 +96,9 @@ function template_js_delete_link() { document.getElementById('direct_link').href = direct_download_link_href; document.getElementById('direct_link_text').innerHTML = web_root + direct_download_link_href; // Validity date if (isEmpty(date)) @@ -111,7 +117,7 @@ function template_js_delete_link() { document.getElementById('date').style.display = ''; } ' . date_format($ts, 'Y-m-d H:i') . ' (GMT)'; - + return $content; } @@ -397,7 +397,7 @@ function jirafeau_hash_file($method, $file_path) function jirafeau_md5_outside($file_path) { $out = false; - $handle = fopen($file_path, "r"); + $handle = fopen($file_path, 'r'); if ($handle === false) { return false; } @@ -450,12 +450,13 @@ function jirafeau_upload($file, $one_time_download, $key, $time, $ip, $crypt, $l } /** - * - * @param bool $crypt_module_enabled - * @param string $file_path + * + * @param bool $crypt_module_enabled + * @param string $file_path * @return array [bool, string] */ -function jirafeau_handle_add_file_encryption($crypt_module_enabled, $file_path) { +function jirafeau_handle_add_file_encryption($crypt_module_enabled, $file_path) +{ /* Crypt file if option is enabled. */ $crypted = false; $crypt_key = ''; @@ -501,7 +502,6 @@ function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, $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'])); @@ -513,12 +513,9 @@ function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, $p = s2p("$hash"); 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_operation($file['tmp_name'], VAR_FILES . $p . $hash)) - { - + } elseif ( + (file_exists(VAR_FILES . $p) || @mkdir(VAR_FILES . $p, 0755, true)) && + $move_operation($file['tmp_name'], VAR_FILES . $p . $hash)) { $rc = true; } if (!$rc) { @@ -526,7 +523,7 @@ function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, 'error' => array('has_error' => true, 'why' => t('INTERNAL_ERROR_DEL')), - 'link' =>'', + 'link' => '', 'delete_link' => '')); } @@ -580,7 +577,7 @@ function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, 'error' => array('has_error' => true, 'why' => t('Internal error during file creation. ')), - 'link' =>'', + 'link' => '', 'delete_link' => ''); } return array( 'error' => $noerr, @@ -589,8 +586,8 @@ function jirafeau_add_file($file, $one_time_download, $key, $time, $ip, $crypt, 'crypt_key' => $crypt_key); } - -function jirafeau_admin_list_table ($name, $file_hash, $link_hash, $visitor_function = null) { +function jirafeau_admin_list_table($name, $file_hash, $link_hash, $visitor_function = null) +{ echo '
'; if (!empty($name)) { echo t('FILENAME') . ": " . jirafeau_escape($name); @@ -616,10 +613,6 @@ function jirafeau_admin_list_table ($name, $file_hash, $link_hash, $visitor_func echo '
'; } - - - - /** * Tells if a mime-type is viewable in a browser * @param $mime the mime type @@ -748,8 +741,8 @@ function jirafeau_get_link($hash) */ function jirafeau_admin_list($name, $file_hash, $link_hash) { - $function = function($name, $file_hash, $link_hash) { - /* Get all links files. */ + $function = function ($name, $file_hash, $link_hash) { + /* Get all links files. */ $stack = array(VAR_LINKS); while (($d = array_shift($stack)) && $d != null) { $dir = scandir($d); @@ -785,8 +778,7 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) if (!$l['crypted'] && !$l['crypted_legacy']) { echo'' . jirafeau_escape($l['file_name']) . ''; - } - else { + } else { echo jirafeau_escape($l['file_name']); } @@ -829,8 +821,9 @@ function jirafeau_admin_list($name, $file_hash, $link_hash) } } } - }; - jirafeau_admin_list_table($name, $file_hash, $link_hash, $function); + }; + + jirafeau_admin_list_table($name, $file_hash, $link_hash, $function); } /** @@ -1341,7 +1334,7 @@ function jirafeau_decrypt_file($fp_src, $fp_dst, $k) for ($i = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES; $i < $fs; $i += JIRAFEAU_SODIUM_CHUNKSIZE + SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES) { $to_dec = fread($r, JIRAFEAU_SODIUM_CHUNKSIZE + SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES); [$dec, $crypt_tag] = sodium_crypto_secretstream_xchacha20poly1305_pull($crypt_state, $to_dec); - + if (fwrite($w, $dec) === false) { return false; } @@ -1758,7 +1751,7 @@ function jirafeau_get_download_stats($hash) $filename = VAR_LINKS . s2p("$hash") . $hash . '_download'; if (!file_exists($filename)) { - return array('count'=>0); + return array('count' => 0); } $c = file($filename); @@ -1782,7 +1775,8 @@ function jirafeau_write_download_stats($hash, $ip) fclose($handle); } -function jirafeau_create_upload_finished_box($preview = true) { +function jirafeau_create_upload_finished_box($preview = true) +{ ?>
@@ -1798,8 +1792,8 @@ function jirafeau_create_upload_finished_box($preview = true) {

- +

@@ -1809,7 +1803,8 @@ function jirafeau_create_upload_finished_box($preview = true) {

+ } + ?>

@@ -1834,77 +1829,76 @@ function jirafeau_create_upload_finished_box($preview = true) {

- 'minute', - 'label' => '1_MIN' + 'value' => 'minute', + 'label' => '1_MIN' ), array( - 'value' => 'hour', - 'label' => '1_H' + 'value' => 'hour', + 'label' => '1_H' ), array( - 'value' => 'day', - 'label' => '1_D' + 'value' => 'day', + 'label' => '1_D' ), array( - 'value' => 'week', - 'label' => '1_W' + 'value' => 'week', + 'label' => '1_W' ), array( 'value' => 'fortnight', 'label' => '2_W' ), array( - 'value' => 'month', - 'label' => '1_M' + 'value' => 'month', + 'label' => '1_M' ), array( - 'value' => 'quarter', - 'label' => '1_Q' + 'value' => 'quarter', + 'label' => '1_Q' ), array( - 'value' => 'year', - 'label' => '1_Y' + 'value' => 'year', + 'label' => '1_Y' ), array( - 'value' => 'none', - 'label' => 'NONE' + 'value' => 'none', + 'label' => 'NONE' ) - ); + ); } +/** + * + * creates the time selection field + * @param mixed $cfg + * @return void + */ +function jirafeau_create_selection_array($cfg) +{ + echo ''; - - - $expirationTimeOptions = jirafeau_get_expiration_time_options(); - - foreach ($expirationTimeOptions as $expirationTimeOption) { - $selected = ($expirationTimeOption['value'] === $cfg['availability_default'])? 'selected="selected"' : ''; - if (true === $cfg['availabilities'][$expirationTimeOption['value']]) { - echo ''; - } + foreach ($expirationTimeOptions as $expirationTimeOption) { + $selected = ($expirationTimeOption['value'] === $cfg['availability_default']) ? 'selected="selected"' : ''; + if (true === $cfg['availabilities'][$expirationTimeOption['value']]) { + echo ''; } - echo ''; - } + } + + echo ''; +} - function jirafeau_datestr_to_int ($time_str) { +function jirafeau_datestr_to_int($time_str) +{ $time = time(); switch ($time_str) { case 'minute': @@ -1931,7 +1925,7 @@ function jirafeau_get_expiration_time_options() { case 'year': $time += JIRAFEAU_YEAR; break; - default: + default: $time = JIRAFEAU_INFINITY; break; } @@ -1942,10 +1936,10 @@ function jirafeau_get_expiration_time_options() { /** - * links or copy a local file + * 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 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 @@ -1956,21 +1950,20 @@ function jirafeau_get_expiration_time_options() { * '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) { - +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' =>'', + 'link' => '', 'delete_link' => '')); } - if( + if ( // sanity check if file can be opened - $file = fopen($local_file_path, "r") - ) - { + $file = fopen($local_file_path, 'r') + ) { // close file pointer - it's not needed here fclose($file); $time_in_int = jirafeau_datestr_to_int($time); @@ -1985,25 +1978,23 @@ function jirafeau_copy_local_file($local_file_path, $one_time_download, $key, $t $file_hash_method, false ); - } - else { + } else { return (array( 'error' => array('has_error' => true, 'why' => t('INTERNAL_ERROR_FP_OPEN_LOCAL')), - 'link' =>'', + '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), +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 --git a/lib/template/header.php b/lib/template/header.php index 8be36c7..93f7e18 100644 --- a/lib/template/header.php +++ b/lib/template/header.php @@ -6,7 +6,7 @@ header('x-ua-compatible: ie=edge'); - <?php echo (true === empty($cfg['title']))? t('JI_WEB_RE') : $cfg['title']; ?> + <?php echo (true === empty($cfg['title'])) ? t('JI_WEB_RE') : $cfg['title']; ?> @@ -17,6 +17,6 @@ header('x-ua-compatible: ie=edge');

- +

diff --git a/script.php b/script.php index c0cee68..5f3bc6f 100644 --- a/script.php +++ b/script.php @@ -175,7 +175,7 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES) } if (strlen($d) > 0 && $d == $link['link_code']) { jirafeau_delete_link($link_name); - echo "Ok"; + echo 'Ok'; exit; } if ($link['time'] != JIRAFEAU_INFINITY && time() > $link['time']) { @@ -217,8 +217,8 @@ if (isset($_FILES['file']) && is_writable(VAR_FILES) } elseif (isset($_GET['get_version'])) { echo JIRAFEAU_VERSION; } elseif (isset($_GET['lang'])) { - $l=$_GET['lang']; - if ($l == "bash") { + $l = $_GET['lang']; + if ($l == 'bash') { ?> #!/bin/bash -- 2.34.1