php-cs-fixer fix --rules=@PSR2 .
Signed-off-by: Jerome Jutteau <jerome@jutteau.fr>
## New Releases
* If the release is not done for security purposes: create a new issue and freeze next-release branch for at least week.
+* Make sure to run `php-cs-fixer fix --rules=@PSR2 .` and commit.
* Compare the [»next-release« branch to »master«](https://gitlab.com/mojo42/Jirafeau/compare/master...next-release)
* Add a list of noteworthy features and bugfixes to `CHANGELOG.md`
* Add eventual upgrade procedure to `CHANGELOG.md`
}
} else {
/* 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');
- echo '<div class="error"><p>'.
+ if (empty($cfg['admin_password']) && empty($cfg['admin_http_auth_user'])) {
+ require(JIRAFEAU_ROOT . 'lib/template/header.php');
+ echo '<div class="error"><p>'.
t('NO_ADMIN') .
'</p></div>';
- require(JIRAFEAU_ROOT.'lib/template/footer.php');
- exit;
- }
+ require(JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
- /* Unlog if asked. */
- if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
- jirafeau_admin_session_end();
- }
+ /* Unlog if asked. */
+ if (jirafeau_admin_session_logged() && isset($_POST['action']) && (strcmp($_POST['action'], 'logout') == 0)) {
+ jirafeau_admin_session_end();
+ }
- if (!jirafeau_admin_session_logged()) {
- /* Test HTTP authentification. */
- if (!empty($cfg['admin_http_auth_user']) &&
+ if (!jirafeau_admin_session_logged()) {
+ /* Test HTTP authentification. */
+ if (!empty($cfg['admin_http_auth_user']) &&
$cfg['admin_http_auth_user'] == $_SERVER['PHP_AUTH_USER']) {
- jirafeau_admin_session_start();
- }
- /* Test web password authentification. */
- else if (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
- if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
- jirafeau_admin_session_start();
- } else {
- require(JIRAFEAU_ROOT . 'lib/template/header.php');
- echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
- require(JIRAFEAU_ROOT.'lib/template/footer.php');
- exit;
- }
- }
- /* Admin password prompt form. */
- else {
- require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
+ jirafeau_admin_session_start();
+ }
+ /* Test web password authentification. */
+ elseif (!empty($cfg['admin_password']) && isset($_POST['admin_password'])) {
+ if ($cfg['admin_password'] === hash('sha256', $_POST['admin_password'])) {
+ jirafeau_admin_session_start();
+ } else {
+ require(JIRAFEAU_ROOT . 'lib/template/header.php');
+ echo '<div class="error"><p>'. t('BAD_PSW') . '</p></div>';
+ require(JIRAFEAU_ROOT.'lib/template/footer.php');
+ exit;
+ }
+ }
+ /* Admin password prompt form. */
+ else {
+ require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?>
<form method="post" class="form login">
<fieldset>
<table>
</form>
<?php
require(JIRAFEAU_ROOT.'lib/template/footer.php');
- exit;
- }
- }
+ exit;
+ }
+ }
- /* Operations may take a long time.
- * Be sure PHP's safe mode is off.
- */
- @set_time_limit(0);
+ /* Operations may take a long time.
+ * Be sure PHP's safe mode is off.
+ */
+ @set_time_limit(0);
- /* Show admin interface if not downloading a file. */
- if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
- require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?><h2><?php echo t('ADMIN_INTERFACE'); ?></h2><?php
+ /* Show admin interface if not downloading a file. */
+ if (!(isset($_POST['action']) && strcmp($_POST['action'], 'download') == 0)) {
+ require(JIRAFEAU_ROOT . 'lib/template/header.php'); ?><h2><?php echo t('ADMIN_INTERFACE'); ?></h2><?php
?><h2>(version <?php echo JIRAFEAU_VERSION ?>)</h2><?php
?><div id = "admin">
<input type = "submit" value = "<?php echo t('LOGOUT'); ?>" />
</form>
</fieldset></div><?php
- }
+ }
- /* Check for actions */
- if (isset($_POST['action'])) {
- if (strcmp($_POST['action'], 'clean') == 0) {
- $total = jirafeau_admin_clean();
- echo '<div class="message">' . NL;
- echo '<p>';
- echo t('CLEANED_FILES_CNT') . ' : ' . $total;
- echo '</p></div>';
- } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
- $total = jirafeau_admin_clean_async();
- echo '<div class="message">' . NL;
- echo '<p>';
- echo t('CLEANED_FILES_CNT') . ' : ' . $total;
- echo '</p></div>';
- } elseif (strcmp($_POST['action'], 'size') == 0) {
- $size = jirafeau_dir_size($cfg['var_root']);
- $human_size = jirafeau_human_size($size);
- echo '<div class="message">' . NL;
- echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
- echo '</div>';
- } elseif (strcmp($_POST['action'], 'list') == 0) {
- jirafeau_admin_list("", "", "");
- } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
- jirafeau_admin_list($_POST['name'], "", "");
- } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
- jirafeau_admin_list("", $_POST['hash'], "");
- } elseif (strcmp($_POST['action'], 'search_link') == 0) {
- jirafeau_admin_list("", "", $_POST['link']);
- } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
- jirafeau_delete_link($_POST['link']);
- echo '<div class="message">' . NL;
- echo '<p>' . t('LINK_DELETED') . '</p></div>';
- } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
- $count = jirafeau_delete_file($_POST['hash']);
- echo '<div class="message">' . NL;
- echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
- } elseif (strcmp($_POST['action'], 'download') == 0) {
- $l = jirafeau_get_link($_POST['link']);
- if (!count($l)) {
- return;
- }
- $p = s2p($l['hash']);
- header('Content-Length: ' . $l['file_size']);
- header('Content-Type: ' . $l['mime_type']);
- header('Content-Disposition: attachment; filename="' .
+ /* Check for actions */
+ if (isset($_POST['action'])) {
+ if (strcmp($_POST['action'], 'clean') == 0) {
+ $total = jirafeau_admin_clean();
+ echo '<div class="message">' . NL;
+ echo '<p>';
+ echo t('CLEANED_FILES_CNT') . ' : ' . $total;
+ echo '</p></div>';
+ } elseif (strcmp($_POST['action'], 'clean_async') == 0) {
+ $total = jirafeau_admin_clean_async();
+ echo '<div class="message">' . NL;
+ echo '<p>';
+ echo t('CLEANED_FILES_CNT') . ' : ' . $total;
+ echo '</p></div>';
+ } elseif (strcmp($_POST['action'], 'size') == 0) {
+ $size = jirafeau_dir_size($cfg['var_root']);
+ $human_size = jirafeau_human_size($size);
+ echo '<div class="message">' . NL;
+ echo '<p>' . t('SIZE_DATA') . ': ' . $human_size .'</p>';
+ echo '</div>';
+ } elseif (strcmp($_POST['action'], 'list') == 0) {
+ jirafeau_admin_list("", "", "");
+ } elseif (strcmp($_POST['action'], 'search_by_name') == 0) {
+ jirafeau_admin_list($_POST['name'], "", "");
+ } elseif (strcmp($_POST['action'], 'search_by_file_hash') == 0) {
+ jirafeau_admin_list("", $_POST['hash'], "");
+ } elseif (strcmp($_POST['action'], 'search_link') == 0) {
+ jirafeau_admin_list("", "", $_POST['link']);
+ } elseif (strcmp($_POST['action'], 'delete_link') == 0) {
+ jirafeau_delete_link($_POST['link']);
+ echo '<div class="message">' . NL;
+ echo '<p>' . t('LINK_DELETED') . '</p></div>';
+ } elseif (strcmp($_POST['action'], 'delete_file') == 0) {
+ $count = jirafeau_delete_file($_POST['hash']);
+ echo '<div class="message">' . NL;
+ echo '<p>' . t('DELETED_LINKS') . ' : ' . $count . '</p></div>';
+ } elseif (strcmp($_POST['action'], 'download') == 0) {
+ $l = jirafeau_get_link($_POST['link']);
+ if (!count($l)) {
+ return;
+ }
+ $p = s2p($l['hash']);
+ header('Content-Length: ' . $l['file_size']);
+ header('Content-Type: ' . $l['mime_type']);
+ header('Content-Disposition: attachment; filename="' .
$l['file_name'] . '"');
- if (file_exists(VAR_FILES . $p . $l['hash'])) {
- $r = fopen(VAR_FILES . $p . $l['hash'], 'r');
- while (!feof($r)) {
- print fread($r, 1024);
- }
- fclose($r);
- }
- exit;
- }
- }
+ if (file_exists(VAR_FILES . $p . $l['hash'])) {
+ $r = fopen(VAR_FILES . $p . $l['hash'], 'r');
+ while (!feof($r)) {
+ print fread($r, 1024);
+ }
+ fclose($r);
+ }
+ exit;
+ }
+ }
require(JIRAFEAU_ROOT.'lib/template/footer.php');
}
echo '&k=' . urlencode($crypt_key);
} ?>';
document.getElementById('submit_preview').submit ();"/><?php
-
}
echo '</td></tr></table></fieldset></form></div>';
require(JIRAFEAU_ROOT.'lib/template/footer.php');
echo '&k=' . urlencode($crypt_key);
} ?>';
document.getElementById('submit_post').submit ();"/><?php
-
}
echo '</td></tr>';
echo '</table></fieldset></form></div>';
}
}
/* Read encrypted file. */
-else if ($link['crypted']) {
+elseif ($link['crypted']) {
/* Init module */
$m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
/* Extract key and iv. */
exit;
}
}
-}
-else {
+} else {
jirafeau_fatal_error(t('ACCESS_KO'), $cfg);
}
<input type="file" id="file_select" size="30"
onchange="control_selected_file_size(<?php echo $cfg['maximal_upload_size'] ?>, '<?php
if ($cfg['maximal_upload_size'] >= 1024) {
- echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . number_format($cfg['maximal_upload_size']/1024, 2) . " GB.";
- } else if ($cfg['maximal_upload_size'] > 0) {
- echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB.";
+ echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . number_format($cfg['maximal_upload_size']/1024, 2) . " GB.";
+ } elseif ($cfg['maximal_upload_size'] > 0) {
+ echo t('2_BIG') . ', ' . t('FILE_LIM') . " " . $cfg['maximal_upload_size'] . " MB.";
}
?>')"/>
</p>
if ($cfg['maximal_upload_size'] >= 1024) {
echo '<p class="config">' . t('FILE_LIM');
echo " " . number_format($cfg['maximal_upload_size'] / 1024, 2) . " GB.</p>";
- } else if ($cfg['maximal_upload_size'] > 0) {
+ } elseif ($cfg['maximal_upload_size'] > 0) {
echo '<p class="config">' . t('FILE_LIM');
echo " " . $cfg['maximal_upload_size'] . " MB.</p>";
} else {
- echo '<p class="config"></p>';
+ echo '<p class="config"></p>';
}
?>
?>
<input type="hidden" id="upload_password" name="upload_password" value="<?php echo $_SESSION['user_upload_password'] ?>"/>
<?php
-
} else {
?>
<input type="hidden" id="upload_password" name="upload_password" value=""/>
<?php
-
}
?>
<input type="submit" id="send" value="<?php echo t('SEND'); ?>"
<input type = "submit" value = "<?php echo t('LOGOUT'); ?>" />
</form>
<?php
-
}
?>
<td class = "field"><input type = "text" name = "web_root"
id = "input_web_root" value = "<?php
echo(empty($cfg['web_root']) ?
- $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__),
- '', $_SERVER['REQUEST_URI']) : $cfg['web_root']);
+ $_SERVER['HTTP_HOST'] . str_replace(
+ basename(__FILE__),
+ '',
+ $_SERVER['REQUEST_URI']
+ ) : $cfg['web_root']);
?>" size = "40" /></td>
</tr> <tr> <td class = "info" colspan = "2"><?php
echo t('DATA_DIR_EXPLAINATION');
* By default, files are hashed through md5 but other methods are available.
*
* Possible values are 'md5', 'md5_outside' and 'random'.
- *
+ *
* With 'md5' option, the whole file is hashed through md5. This is the default.
* With 'md5_outside', hash is computed using:
* - md5 of the first part of the file,
switch (strtoupper($modifier)) {
case 'P':
$bytes *= 1024;
+ // no break
case 'T':
$bytes *= 1024;
+ // no break
case 'G':
$bytes *= 1024;
+ // no break
case 'M':
$bytes *= 1024;
+ // no break
case 'K':
$bytes *= 1024;
}
*/
function jirafeau_get_max_upload_size_bytes()
{
- return min(jirafeau_ini_to_bytes(ini_get('post_max_size')),
- jirafeau_ini_to_bytes(ini_get('upload_max_filesize')));
+ return min(
+ jirafeau_ini_to_bytes(ini_get('post_max_size')),
+ jirafeau_ini_to_bytes(ini_get('upload_max_filesize'))
+ );
}
/**
/* create link file */
$link_tmp_name = VAR_LINKS . $hash . rand(0, 10000) . '.tmp';
$handle = fopen($link_tmp_name, 'w');
- fwrite($handle,
- $name . NL. $mime_type . NL. $size . NL. $password . NL. $time .
+ fwrite(
+ $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 ? 'C' : '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);
$l = s2p("$hash_link");
/* Store informations. */
$p .= $ref;
$handle = fopen($p, 'w');
- fwrite($handle,
- str_replace(NL, '', trim($filename)) . NL .
+ fwrite(
+ $handle,
+ str_replace(NL, '', trim($filename)) . NL .
str_replace(NL, '', trim($type)) . NL . $password . NL .
$time . NL . ($one_time ? 'O' : 'R') . NL . $ip . NL .
- time() . NL . $code . NL);
+ time() . NL . $code . NL
+ );
fclose($handle);
return $ref . NL . $code ;
/* Update async file. */
$code = jirafeau_gen_random(4);
$handle = fopen(VAR_ASYNC . $p . $ref, 'w');
- fwrite($handle,
- $a['file_name'] . NL. $a['mime_type'] . NL. $a['key'] . NL .
+ fwrite(
+ $handle,
+ $a['file_name'] . NL. $a['mime_type'] . NL. $a['key'] . NL .
$a['time'] . NL . $a['onetime'] . NL . $a['ip'] . NL .
- time() . NL . $code . NL);
+ time() . NL . $code . NL
+ );
fclose($handle);
return $code;
}
/* Create link. */
$link_tmp_name = VAR_LINKS . $hash . rand(0, 10000) . '.tmp';
$handle = fopen($link_tmp_name, 'w');
- fwrite($handle,
- $a['file_name'] . NL . $a['mime_type'] . NL . $size . NL .
+ fwrite(
+ $handle,
+ $a['file_name'] . NL . $a['mime_type'] . NL . $size . NL .
$a['key'] . NL . $a['time'] . NL . $hash . NL . $a['onetime'] . NL .
- time() . NL . $a['ip'] . NL . $delete_link_code . NL . ($crypted ? 'C' : 'O'));
+ time() . NL . $a['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);
$l = s2p("$hash_link");
* Check if Jirafeau has a restriction on the IP address for uploading.
* @return true if uploading is IP restricted, false otherwise.
*/
-function jirafeau_upload_has_ip_restriction($cfg) {
+function jirafeau_upload_has_ip_restriction($cfg)
+{
return count($cfg['upload_ip']) > 0;
}
* @param $password password to be challenged
* @return true if access is valid, false otherwise.
*/
-function jirafeau_challenge_upload ($cfg, $ip, $password)
+function jirafeau_challenge_upload($cfg, $ip, $password)
{
return jirafeau_challenge_upload_ip_without_password($cfg, $ip) ||
(!jirafeau_has_upload_password($cfg) && !jirafeau_upload_has_ip_restriction($cfg)) ||
return "FIX ME";
}
-function t_visitor_langs() {
+function t_visitor_langs()
+{
$visitor_langs = t_parse_accept_language();
array_push($visitor_langs, "en");
return $visitor_langs;
}
-function t_parse_accept_language() {
+function t_parse_accept_language()
+{
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return [];
}
return $langs;
}
-function t_in($string_id, $lang) {
+function t_in($string_id, $lang)
+{
$trans = t_get_json($lang);
if ($trans === false) {
return false;
return $trans[$string_id];
}
-function t_get_raw_json($lang) {
+function t_get_raw_json($lang)
+{
$filename = str_replace("-", "_", $lang);
if (preg_match('/[^A-Za-z_\w]/', $filename)) {
return false;
return $json;
}
-function t_get_json($lang) {
+function t_get_json($lang)
+{
$raw_j = t_get_raw_json($lang);
$array = json_decode($raw_j, true);
if ($array === null) {
return $array;
}
-function json_lang_generator($lang) {
+function json_lang_generator($lang)
+{
$r = false;
if ($lang === null) {
$lang_config = $GLOBALS['cfg']['lang'];
if ($lang_config != "auto") {
$r = t_get_raw_json($lang_config);
} else {
- foreach(t_visitor_langs() as $lang) {
+ foreach (t_visitor_langs() as $lang) {
$r = t_get_raw_json($lang);
if (!($r === false)) {
break;
}
// Setup debug mode
-if ($cfg['debug'] === true)
-{
+if ($cfg['debug'] === true) {
@error_reporting(E_ALL);
-}
-else
-{
+} else {
@error_reporting(0);
}
define('JIRAFEAU_YEAR', 31536000); // JIRAFEAU_DAY * 365
// set UTC as default timezone for all date/time functions
-date_default_timezone_set ('UTC');
+date_default_timezone_set('UTC');
/* Upload file */
if (isset($_FILES['file']) && is_writable(VAR_FILES)
&& is_writable(VAR_LINKS)) {
- if (isset ($_POST['upload_password'])) {
+ if (isset($_POST['upload_password'])) {
if (!jirafeau_challenge_upload($cfg, get_ip_address($cfg), $_POST['upload_password'])) {
echo 'Error 3: Invalid password';
exit;
exit;
}
- $res = jirafeau_upload($_FILES['file'],
- isset($_POST['one_time_download']),
- $key, $time, get_ip_address($cfg),
- $cfg['enable_crypt'], $cfg['link_name_length'],
- $cfg['file_hash']);
+ $res = jirafeau_upload(
+ $_FILES['file'],
+ isset($_POST['one_time_download']),
+ $key,
+ $time,
+ get_ip_address($cfg),
+ $cfg['enable_crypt'],
+ $cfg['link_name_length'],
+ $cfg['file_hash']
+ );
if (empty($res) || $res['error']['has_error']) {
echo 'Error 6 ' . $res['error']['why'];
$curl $proxy "$2"
fi
<?php
-
} else {
echo 'Error 12';
exit;
}
/* Initialize an asynchronous upload. */
elseif (isset($_GET['init_async'])) {
- if (isset($_POST['upload_password'])){
+ if (isset($_POST['upload_password'])) {
if (!jirafeau_challenge_upload($cfg, get_ip_address($cfg), $_POST['upload_password'])) {
echo 'Error 20: Invalid password';
exit;
break;
}
}
- echo jirafeau_async_init($_POST['filename'],
- $type,
- isset($_POST['one_time_download']),
- $key,
- $time,
- get_ip_address($cfg));
+ echo jirafeau_async_init(
+ $_POST['filename'],
+ $type,
+ isset($_POST['one_time_download']),
+ $key,
+ $time,
+ get_ip_address($cfg)
+ );
}
/* Continue an asynchronous upload. */
elseif (isset($_GET['push_async'])) {
|| (!isset($_POST['code']))) {
echo 'Error 23';
} else {
- echo jirafeau_async_push($_POST['ref'],
- $_FILES['data'],
- $_POST['code'],
- $cfg['maximal_upload_size']);
+ echo jirafeau_async_push(
+ $_POST['ref'],
+ $_FILES['data'],
+ $_POST['code'],
+ $cfg['maximal_upload_size']
+ );
}
}
/* Finalize an asynchronous upload. */