$block_size = 8;
$p = '';
for ($i = 0; $i < strlen($s); $i++) {
- $p .= $s{$i};
+ $p .= $s[$i];
if (($i + 1) % $block_size == 0) {
$p .= '/';
}
# Convert long hex string to bin.
$size = strlen($num);
for ($i = 0; $i < $size; $i++) {
- $b .= $hex2bin{hexdec($num{$i})};
+ $b .= $hex2bin[hexdec($num[$i])];
}
# Convert long bin to base 64.
$size *= 4;
for ($i = $size - 6; $i >= 0; $i -= 6) {
- $o = $m{bindec(substr($b, $i, 6))} . $o;
+ $o = $m[bindec(substr($b, $i, 6))] . $o;
}
# Some few bits remaining ?
if ($i < 0 && $i > -6) {
- $o = $m{bindec(substr($b, 0, $i + 6))} . $o;
+ $o = $m[bindec(substr($b, 0, $i + 6))] . $o;
}
return $o;
}
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");
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/>';
+ if (strlen($l['ip']) > 0) {
+ echo t('ORIGIN') . ': ' . $l['ip'] . '<br/>';
+ }
echo '</td><td>';
echo '<form method="post">' .
'<input type = "hidden" name = "action" value = "download"/>' .
}
return $count;
}
+
+/**
+ * Better strval function for debug purposes
+ */
+function jirafeau_strval($value)
+{
+ if (gettype($value) == "boolean") {
+ return $value ? 'true' : 'false';
+ }
+ return strval($value);
+}
+
+/**
+ * Show file/folder permissions
+ */
+function jirafeau_fileperms($path)
+{
+ $out = substr(sprintf("%o", @fileperms($path)), -4) . ", ";
+ $out .= "read " . (is_readable($path) ? "OK" : "KO") . ", ";
+ $out .= "write " . (is_writable($path) ? "OK" : "KO");
+ return $out;
+}
+
+/**
+ * Show some useful informations for bug reporting.
+ */
+function jirafeau_admin_bug_report($cfg)
+{
+ $out = "<fieldset><legend>" . t('REPORTING_AN_ISSUE') . "</legend>";
+ $out .= "If you have a problem related to Jirafeau, please <a href='https://gitlab.com/mojo42/Jirafeau/-/issues'>open an issue</a>, explain your problem in english and copy-paste the following content:<br/><br/><code>";
+
+ $out .= "# Jirafeau<br/>";
+ $out .= "- version: " . JIRAFEAU_VERSION . "<br/>";
+ $jirafeau_options = [
+ 'debug',
+ 'file_hash',
+ 'litespeed_workaround',
+ 'store_uploader_ip',
+ 'installation_done',
+ 'enable_crypt',
+ 'preview',
+ 'maximal_upload_size',
+ 'store_uploader_ip'
+ ];
+ foreach ($jirafeau_options as &$o) {
+ $v = $cfg[$o];
+ $out .= "- $o: " . jirafeau_strval($v) . " (" . gettype($v) . ")<br/>";
+ }
+ $out .= "<br/>";
+
+ $out .= "# PHP options<br/>";
+ $out .= "- php version: " . phpversion() . "<br/>";
+ $out .= "- mcrypt version: " . phpversion('mcrypt') . "<br/>";
+ $php_options = [
+ 'post_max_size',
+ 'upload_max_filesize',
+ 'safe_mode',
+ 'max_execution_time',
+ 'max_input_time'
+ ];
+ foreach ($php_options as &$o) {
+ $v = ini_get($o);
+ $out .= "- $o: " . jirafeau_strval($v) . " (" . gettype($v). ")<br/>";
+ }
+ $out .= "- can set_time_limit: " . (set_time_limit(0) ? "yes" : "no") . "<br/>";
+ $out .= "<br/>";
+
+ $out .= "# File permissions<br/>";
+ $out .= "- 'var' folder permissions: " . jirafeau_fileperms($cfg['var_root']) . "<br/>";
+ $out .= "- 'file' folder permissions: " . jirafeau_fileperms(VAR_FILES) . "<br/>";
+ $out .= "- 'links' folder permissions: " . jirafeau_fileperms(VAR_LINKS) . "<br/>";
+ $out .= "- 'async' folder permissions: " . jirafeau_fileperms(VAR_ASYNC) . "<br/>";
+ $out .= "<br/>";
+
+ $out .= "# Server details<br/>";
+ $out .= "- server software: " . $_SERVER["SERVER_SOFTWARE"] . "<br/>";
+ $out .= "<br/>";
+
+ $out .= "# OS details<br/>";
+ $out .= "- OS: " . php_uname() . "<br/>";
+ $out .= "<br/>";
+
+ $out .= "# Browser details<br/>";
+ $out .= "<script type='text/javascript' lang='Javascript'>
+ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
+ document.write('- html5 support: ' + (check_html5_file_api() ? 'yes' : 'no') + '<br/>');
+ document.write('- user agent: ' + navigator.userAgent + '<br/>');
+ // @license-end
+ </script>";
+ $out .= "<br/>";
+
+ $out .= "# Memory<br/>";
+ $out .= "- memory_get_peak_usage: " . jirafeau_human_size(memory_get_peak_usage()) . "<br/>";
+
+ $out .= "</code></fieldset>";
+ return $out;
+}
+
/**
* Read async transfert informations
* @return array containing informations.
/* 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 $size;
}
+
+function jirafeau_export_cfg($cfg)
+{
+ $content = '<?php' . NL;
+ $content .= '/* This file was generated by the install process. ' .
+ 'You can edit it. Please see config.original.php to understand the ' .
+ 'configuration items. */' . NL;
+ $content .= '$cfg = ' . var_export($cfg, true) . ';';
+
+ $fileWrite = file_put_contents(JIRAFEAU_CFG, $content);
+
+ if (false === $fileWrite) {
+ jirafeau_fatal_error(t('Can not write local configuration file'));
+ }
+}
+
+function jirafeau_mkdir($path)
+{
+ return !(!file_exists($path) && !@mkdir($path, 0755));
+}
+
+/**
+ * Returns true whether the path is writable or we manage to make it
+ * so, which essentially is the same thing.
+ * @param $path is the file or directory to be tested.
+ * @return true if $path is writable.
+ */
+function jirafeau_is_writable($path)
+{
+ /* "@" gets rid of error messages. */
+ return is_writable($path) || @chmod($path, 0777);
+}
+
+function jirafeau_check_var_dir($path)
+{
+ $mkdir_str1 = t('CANNOT_CREATE_DIR') . ':';
+ $mkdir_str2 = t('MANUAL_CREATE');
+ $write_str1 = t('DIR_NOT_W') . ':';
+ $write_str2 = t('You should give the write permission to the web server on ' .
+ 'this directory.');
+ $solution_str = t('HERE_SOLUTION') . ':';
+
+ if (!jirafeau_mkdir($path) || !jirafeau_is_writable($path)) {
+ return array('has_error' => true,
+ 'why' => $mkdir_str1 . '<br /><code>' .
+ $path . '</code><br />' . $solution_str .
+ '<br />' . $mkdir_str2);
+ }
+
+ foreach (array('files', 'links', 'async') as $subdir) {
+ $subpath = $path.$subdir;
+
+ if (!jirafeau_mkdir($subpath) || !jirafeau_is_writable($subpath)) {
+ return array('has_error' => true,
+ 'why' => $mkdir_str1 . '<br /><code>' .
+ $subpath . '</code><br />' . $solution_str .
+ '<br />' . $mkdir_str2);
+ }
+ }
+
+ return array('has_error' => false, 'why' => '');
+}
+
+function jirafeau_add_ending_slash($path)
+{
+ return $path . ((substr($path, -1) == '/') ? '' : '/');
+}
+
+function jirafeau_default_web_root()
+{
+ return $_SERVER['HTTP_HOST'] . str_replace(basename(__FILE__), '', $_SERVER['REQUEST_URI']);
+}