-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring offline branch up to speed with master (#1037)
* publish additional docker tags (#975) * Update Romanian translations (#981) * Update tinyfilemanager.php * Prevent logout issue after page was cached (#1004) Logout may not work otherwise, browser reloads cached page from disk instead of sending GET request ?logout=1 to server. * tell git to always commit .php in unix-newlines (#1017) so hopefully we don't get a repeat of #994 (comment) * Check if posix_getpwuid/posix_getgrgid calls were successful (#1023) * use stream_copy_to_stream (#1014) * use stream_copy_to_stream it's simpler, and should be faster. For example, stream_copy_to_stream can use sendfile ( https://man7.org/linux/man-pages/man2/sendfile.2.html ) on operating systems supporting it, which is faster and use less RAM than fread()+fwrite() (because it avoids copying data to/from userland, doing the copy entirely in-kernel~) * fix loop early return, and workaround bug * use feof ref #1016 (comment) * added bengali translation (#1018) * Fix upload of existing files (#1026) * Fix typo. (#1028) * login (Redirecting to Main domain of website instead of tfm.php) fix (#1031) When logged in it takes to the website's main URL. For example, if I have tfm in www.example.com/tfm/index.php (index.php is tfm) then after logging in it redirects to www.example.com and then have to press back on the browser then it takes to www.example.com/tfm/index.php * Add configurable path display modes for better privacy and clarity (#1034) * Resize preview image and implement zoom in/out (#1036) * Resize preview image and implement zoom in/out * Remove redundant class name --------- Co-authored-by: ssams <[email protected]> Co-authored-by: Sergiu Bivol <[email protected]> Co-authored-by: Prasath Mani <[email protected]> Co-authored-by: divinity76 <[email protected]> Co-authored-by: Micha Ober <[email protected]> Co-authored-by: Joy Biswas <[email protected]> Co-authored-by: Micha Ober <[email protected]> Co-authored-by: Caleb Mazalevskis <[email protected]> Co-authored-by: xololunatic <[email protected]> Co-authored-by: DannyDaemonic <[email protected]>
- Loading branch information
1 parent
e179367
commit 15fc685
Showing
4 changed files
with
240 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.php text eol=lf | ||
*.json text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
/** | ||
* H3K | Tiny File Manager V2.5.3 | ||
* @author Prasath Mani | CCP Programmers | ||
* @author CCP Programmers | ||
* @email [email protected] | ||
* @github https://github.com/prasathmani/tinyfilemanager | ||
* @link https://tinyfilemanager.github.io | ||
|
@@ -77,6 +77,12 @@ | |
// Doc - https://www.php.net/manual/en/function.date.php | ||
$datetime_format = 'm/d/Y g:i A'; | ||
|
||
// Path display mode when viewing file information | ||
// 'full' => show full path | ||
// 'relative' => show path relative to root_path | ||
// 'host' => show path on the host | ||
$path_display_mode = 'full'; | ||
|
||
// Allowed file extensions for create and rename files | ||
// e.g. 'txt,html,css,js' | ||
$allowed_file_extensions = ''; | ||
|
@@ -220,7 +226,7 @@ | |
mb_regex_encoding('UTF-8'); | ||
} | ||
|
||
session_cache_limiter(''); | ||
session_cache_limiter('nocache'); // Prevent logout issue after page was cached | ||
session_name(FM_SESSION_ID ); | ||
function session_error_handling_function($code, $msg, $file, $line) { | ||
// Permission denied for default session, try to create a new one | ||
|
@@ -235,7 +241,7 @@ function session_error_handling_function($code, $msg, $file, $line) { | |
restore_error_handler(); | ||
} | ||
|
||
//Genrating CSRF Token | ||
//Generating CSRF Token | ||
if (empty($_SESSION['token'])) { | ||
$_SESSION['token'] = bin2hex(random_bytes(32)); | ||
} | ||
|
@@ -320,11 +326,11 @@ function getClientIP() { | |
if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']]) && verifyToken($_POST['token'])) { | ||
$_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr']; | ||
fm_set_msg(lng('You are logged in')); | ||
fm_redirect(FM_ROOT_URL); | ||
fm_redirect(FM_SELF_URL); | ||
} else { | ||
unset($_SESSION[FM_SESSION_ID]['logged']); | ||
fm_set_msg(lng('Login failed. Invalid username or password'), 'error'); | ||
fm_redirect(FM_ROOT_URL); | ||
fm_redirect(FM_SELF_URL); | ||
} | ||
} else { | ||
fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');; | ||
|
@@ -912,7 +918,6 @@ function get_file_path () { | |
echo json_encode($response); exit(); | ||
} | ||
|
||
$override_file_name = false; | ||
$chunkIndex = $_POST['dzchunkindex']; | ||
$chunkTotal = $_POST['dztotalchunkcount']; | ||
$fullPathInput = fm_clean_path($_REQUEST['fullpath']); | ||
|
@@ -950,11 +955,6 @@ function get_file_path () { | |
$fullPath = $path . '/' . basename($fullPathInput); | ||
$folder = substr($fullPath, 0, strrpos($fullPath, "/")); | ||
|
||
if(file_exists ($fullPath) && !$override_file_name && !$chunks) { | ||
$ext_1 = $ext ? '.'.$ext : ''; | ||
$fullPath = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1; | ||
} | ||
|
||
if (!is_dir($folder)) { | ||
$old = umask(0); | ||
mkdir($folder, 0777, true); | ||
|
@@ -967,7 +967,12 @@ function get_file_path () { | |
if ($out) { | ||
$in = @fopen($tmp_name, "rb"); | ||
if ($in) { | ||
while ($buff = fread($in, 4096)) { fwrite($out, $buff); } | ||
if (PHP_VERSION_ID < 80009) { | ||
// workaround https://bugs.php.net/bug.php?id=81145 | ||
while (!feof($in)) { fwrite($out, fread($in, 4096)); } | ||
} else { | ||
stream_copy_to_stream($in, $out); | ||
} | ||
$response = array ( | ||
'status' => 'success', | ||
'info' => "file upload successful" | ||
|
@@ -995,7 +1000,13 @@ function get_file_path () { | |
} | ||
|
||
if ($chunkIndex == $chunkTotal - 1) { | ||
rename("{$fullPath}.part", $fullPath); | ||
if (file_exists ($fullPath)) { | ||
$ext_1 = $ext ? '.'.$ext : ''; | ||
$fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1; | ||
} else { | ||
$fullPathTarget = $fullPath; | ||
} | ||
rename("{$fullPath}.part", $fullPathTarget); | ||
} | ||
|
||
} else if (move_uploaded_file($tmp_name, $fullPath)) { | ||
|
@@ -1677,7 +1688,8 @@ function getSelected($l) { | |
<div class="col-12"> | ||
<p class="break-word"><b><?php echo lng($view_title) ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p> | ||
<p class="break-word"> | ||
<strong>Full path:</strong> <?php echo fm_enc(fm_convert_win($file_path)) ?><br> | ||
<?php $display_path = fm_get_display_path($file_path); ?> | ||
<strong><?php echo $display_path['label']; ?>:</strong> <?php echo $display_path['path']; ?><br> | ||
<strong>File size:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?><br> | ||
<strong>MIME-type:</strong> <?php echo $mime_type ?><br> | ||
<?php | ||
|
@@ -1776,7 +1788,7 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced | |
} elseif ($is_image) { | ||
// Image content | ||
if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))) { | ||
echo '<p><img src="' . fm_enc($file_url) . '" alt="image" class="preview-img-container" class="preview-img"></p>'; | ||
echo '<p><input type="checkbox" id="preview-img-zoomCheck"><label for="preview-img-zoomCheck"><img src="' . fm_enc($file_url) . '" alt="image" class="preview-img"></label></p>'; | ||
} | ||
} elseif ($is_audio) { | ||
// Audio content | ||
|
@@ -1936,7 +1948,8 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced | |
</h6> | ||
<div class="card-body"> | ||
<p class="card-text"> | ||
Full path: <?php echo $file_path ?><br> | ||
<?php $display_path = fm_get_display_path($file_path); ?> | ||
<?php echo $display_path['label']; ?>: <?php echo $display_path['path']; ?><br> | ||
</p> | ||
<form action="" method="post"> | ||
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>"> | ||
|
@@ -2049,6 +2062,12 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced | |
if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) { | ||
$owner = posix_getpwuid(fileowner($path . '/' . $f)); | ||
$group = posix_getgrgid(filegroup($path . '/' . $f)); | ||
if ($owner === false) { | ||
$owner = array('name' => '?'); | ||
} | ||
if ($group === false) { | ||
$group = array('name' => '?'); | ||
} | ||
} else { | ||
$owner = array('name' => '?'); | ||
$group = array('name' => '?'); | ||
|
@@ -2102,6 +2121,12 @@ class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('Advanced | |
if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) { | ||
$owner = posix_getpwuid(fileowner($path . '/' . $f)); | ||
$group = posix_getgrgid(filegroup($path . '/' . $f)); | ||
if ($owner === false) { | ||
$owner = array('name' => '?'); | ||
} | ||
if ($group === false) { | ||
$group = array('name' => '?'); | ||
} | ||
} else { | ||
$owner = array('name' => '?'); | ||
$group = array('name' => '?'); | ||
|
@@ -2495,6 +2520,30 @@ function fm_get_parent_path($path) | |
return false; | ||
} | ||
|
||
function fm_get_display_path($file_path) | ||
{ | ||
global $path_display_mode, $root_path, $root_url; | ||
switch ($path_display_mode) { | ||
case 'relative': | ||
return array( | ||
'label' => 'Path', | ||
'path' => fm_enc(fm_convert_win(str_replace($root_path, '', $file_path))) | ||
); | ||
case 'host': | ||
$relative_path = str_replace($root_path, '', $file_path); | ||
return array( | ||
'label' => 'Host Path', | ||
'path' => fm_enc(fm_convert_win('/' . $root_url . '/' . ltrim(str_replace('\\', '/', $relative_path), '/'))) | ||
); | ||
case 'full': | ||
default: | ||
return array( | ||
'label' => 'Full Path', | ||
'path' => fm_enc(fm_convert_win($file_path)) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Check file is in exclude list | ||
* @param string $file | ||
|
@@ -3703,7 +3752,9 @@ function fm_show_header() | |
.message.ok { border-color:green;color:green } | ||
.message.error { border-color:red;color:red } | ||
.message.alert { border-color:orange;color:orange } | ||
.preview-img { max-width:100%;max-height:80vh;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC) } | ||
.preview-img { max-width:100%;max-height:80vh;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC);cursor:zoom-in } | ||
input#preview-img-zoomCheck[type=checkbox] { display:none } | ||
input#preview-img-zoomCheck[type=checkbox]:checked ~ label > img { max-width:none;max-height:none;cursor:zoom-out } | ||
.inline-actions > a > i { font-size:1em;margin-left:5px;background:#3785c1;color:#fff;padding:3px 4px;border-radius:3px; } | ||
.preview-video { position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px } | ||
.preview-video video { position:absolute;width:100%;height:100%;left:0;top:0;background:#000 } | ||
|
Oops, something went wrong.