Latest security changes

This commit is contained in:
Prasath Mani 2017-07-27 14:42:07 +05:30
parent 6de0fca10f
commit 115b20dd9f

View file

@ -56,6 +56,9 @@ $http_host = $_SERVER['HTTP_HOST'];
// input encoding for iconv // input encoding for iconv
$iconv_input_encoding = 'CP1251'; $iconv_input_encoding = 'CP1251';
// date() format for file modification date
$datetime_format = 'd.m.y H:i';
//--- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL //--- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL
// if fm included // if fm included
@ -90,7 +93,7 @@ $is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['
$root_path = rtrim($root_path, '\\/'); $root_path = rtrim($root_path, '\\/');
$root_path = str_replace('\\', '/', $root_path); $root_path = str_replace('\\', '/', $root_path);
if (!@is_dir($root_path)) { if (!@is_dir($root_path)) {
echo "<h1>Root path &quot;{$root_path}&quot; not found!</h1>"; echo "<h1>Root path \"{$root_path}\" not found!</h1>";
exit; exit;
} }
@ -116,33 +119,22 @@ if (isset($_GET['img'])) {
// Auth // Auth
if ($use_auth) { if ($use_auth) {
$languages = fm_get_available_langs();
if (isset($_SESSION['logged'], $auth_users[$_SESSION['logged']])) { if (isset($_SESSION['logged'], $auth_users[$_SESSION['logged']])) {
// Logged // Logged
$lang = (isset($_SESSION['lang']) && in_array($_SESSION['lang'], $languages)) ? $_SESSION['lang'] : $lang;
} elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'])) { } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'])) {
// Logging In // Logging In
sleep(1); sleep(1);
if (isset($auth_users[$_POST['fm_usr']]) && md5($_POST['fm_pwd']) === $auth_users[$_POST['fm_usr']]) { if (isset($auth_users[$_POST['fm_usr']]) && md5($_POST['fm_pwd']) === $auth_users[$_POST['fm_usr']]) {
$_SESSION['logged'] = $_POST['fm_usr']; $_SESSION['logged'] = $_POST['fm_usr'];
if (isset($_POST['lang']) && in_array($_POST['lang'], $languages)) { fm_set_msg('You are logged in');
$_SESSION['lang'] = $_POST['lang'];
$lang = $_POST['lang'];
} elseif (defined('FM_LANG')) {
$lang = FM_LANG;
}
fm_set_msg(fm_t('You are logged in', $lang));
fm_redirect(FM_SELF_URL . '?p='); fm_redirect(FM_SELF_URL . '?p=');
} else { } else {
unset($_SESSION['logged']); unset($_SESSION['logged']);
fm_set_msg(fm_t('Wrong password', $lang), 'error'); fm_set_msg('Wrong password', 'error');
fm_redirect(FM_SELF_URL); fm_redirect(FM_SELF_URL);
} }
} else { } else {
// Form // Form
if (defined('FM_LANG')) {
$lang = FM_LANG;
}
unset($_SESSION['logged']); unset($_SESSION['logged']);
fm_show_header(); fm_show_header();
fm_show_message(); fm_show_message();
@ -184,11 +176,10 @@ $p = fm_clean_path($p);
// instead globals vars // instead globals vars
define('FM_PATH', $p); define('FM_PATH', $p);
define('FM_USE_AUTH', $use_auth); define('FM_USE_AUTH', $use_auth);
define('FM_ICONV_INPUT_ENC', $iconv_input_encoding); defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
define('FM_USE_HIGHLIGHTJS', $use_highlightjs); defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style); defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
define('FM_EDIT_FILE', $edit_files); defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style); unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
@ -235,14 +226,14 @@ if (isset($_GET['del']) && !FM_READONLY) {
} }
$is_dir = is_dir($path . '/' . $del); $is_dir = is_dir($path . '/' . $del);
if (fm_rdelete($path . '/' . $del)) { if (fm_rdelete($path . '/' . $del)) {
$msg = $is_dir ? fm_t('Folder <b>%s</b> deleted') : fm_t('File <b>%s</b> deleted'); $msg = $is_dir ? 'Folder <b>%s</b> deleted' : 'File <b>%s</b> deleted';
fm_set_msg(sprintf($msg, $del)); fm_set_msg(sprintf($msg, $del));
} else { } else {
$msg = $is_dir ? fm_t('Folder <b>%s</b> not deleted') : fm_t('File <b>%s</b> not deleted'); $msg = $is_dir ? 'Folder <b>%s</b> not deleted' : 'File <b>%s</b> not deleted';
fm_set_msg(sprintf($msg, $del), 'error'); fm_set_msg(sprintf($msg, $del), 'error');
} }
} else { } else {
fm_set_msg(fm_t('Wrong file or folder name'), 'error'); fm_set_msg('Wrong file or folder name', 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -275,7 +266,7 @@ if (isset($_GET['new']) && isset($_GET['type']) && !FM_READONLY) {
} }
} }
} else { } else {
fm_set_msg(fm_t('Wrong folder name'), 'error'); fm_set_msg('Wrong folder name', 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -287,7 +278,7 @@ if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
$copy = fm_clean_path($copy); $copy = fm_clean_path($copy);
// empty path // empty path
if ($copy == '') { if ($copy == '') {
fm_set_msg(fm_t('Source path not defined'), 'error'); fm_set_msg('Source path not defined', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
// abs path from // abs path from
@ -306,21 +297,21 @@ if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
if ($move) { if ($move) {
$rename = fm_rename($from, $dest); $rename = fm_rename($from, $dest);
if ($rename) { if ($rename) {
fm_set_msg(sprintf(fm_t('Moved from <b>%s</b> to <b>%s</b>'), $copy, $msg_from)); fm_set_msg(sprintf('Moved from <b>%s</b> to <b>%s</b>', $copy, $msg_from));
} elseif ($rename === null) { } elseif ($rename === null) {
fm_set_msg(fm_t('File or folder with this path already exists'), 'alert'); fm_set_msg('File or folder with this path already exists', 'alert');
} else { } else {
fm_set_msg(sprintf(fm_t('Error while moving from <b>%s</b> to <b>%s</b>'), $copy, $msg_from), 'error'); fm_set_msg(sprintf('Error while moving from <b>%s</b> to <b>%s</b>', $copy, $msg_from), 'error');
} }
} else { } else {
if (fm_rcopy($from, $dest)) { if (fm_rcopy($from, $dest)) {
fm_set_msg(sprintf(fm_t('Copyied from <b>%s</b> to <b>%s</b>'), $copy, $msg_from)); fm_set_msg(sprintf('Copyied from <b>%s</b> to <b>%s</b>', $copy, $msg_from));
} else { } else {
fm_set_msg(sprintf(fm_t('Error while copying from <b>%s</b> to <b>%s</b>'), $copy, $msg_from), 'error'); fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', $copy, $msg_from), 'error');
} }
} }
} else { } else {
fm_set_msg(fm_t('Paths must be not equal'), 'alert'); fm_set_msg('Paths must be not equal', 'alert');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -339,12 +330,12 @@ if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish']) && !FM_READONLY)
$copy_to_path .= '/' . $copy_to; $copy_to_path .= '/' . $copy_to;
} }
if ($path == $copy_to_path) { if ($path == $copy_to_path) {
fm_set_msg(fm_t('Paths must be not equal'), 'alert'); fm_set_msg('Paths must be not equal', 'alert');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
if (!is_dir($copy_to_path)) { if (!is_dir($copy_to_path)) {
if (!fm_mkdir($copy_to_path, true)) { if (!fm_mkdir($copy_to_path, true)) {
fm_set_msg(fm_t('Unable to create destination folder'), 'error'); fm_set_msg('Unable to create destination folder', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
} }
@ -374,14 +365,14 @@ if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish']) && !FM_READONLY)
} }
} }
if ($errors == 0) { if ($errors == 0) {
$msg = $move ? fm_t('Selected files and folders moved') : fm_t('Selected files and folders copied'); $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
fm_set_msg($msg); fm_set_msg($msg);
} else { } else {
$msg = $move ? fm_t('Error while moving items') : fm_t('Error while copying items'); $msg = $move ? 'Error while moving items' : 'Error while copying items';
fm_set_msg($msg, 'error'); fm_set_msg($msg, 'error');
} }
} else { } else {
fm_set_msg(fm_t('Nothing selected'), 'alert'); fm_set_msg('Nothing selected', 'alert');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -404,12 +395,12 @@ if (isset($_GET['ren'], $_GET['to']) && !FM_READONLY) {
// rename // rename
if ($old != '' && $new != '') { if ($old != '' && $new != '') {
if (fm_rename($path . '/' . $old, $path . '/' . $new)) { if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
fm_set_msg(sprintf(fm_t('Renamed from <b>%s</b> to <b>%s</b>'), $old, $new)); fm_set_msg(sprintf('Renamed from <b>%s</b> to <b>%s</b>', $old, $new));
} else { } else {
fm_set_msg(sprintf(fm_t('Error while renaming from <b>%s</b> to <b>%s</b>'), $old, $new), 'error'); fm_set_msg(sprintf('Error while renaming from <b>%s</b> to <b>%s</b>', $old, $new), 'error');
} }
} else { } else {
fm_set_msg(fm_t('Names not set'), 'error'); fm_set_msg('Names not set', 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -436,7 +427,7 @@ if (isset($_GET['dl'])) {
readfile($path . '/' . $dl); readfile($path . '/' . $dl);
exit; exit;
} else { } else {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
} }
@ -464,11 +455,11 @@ if (isset($_POST['upl']) && !FM_READONLY) {
} }
if ($errors == 0 && $uploads > 0) { if ($errors == 0 && $uploads > 0) {
fm_set_msg(sprintf(fm_t('All files uploaded to <b>%s</b>'), $path)); fm_set_msg(sprintf('All files uploaded to <b>%s</b>', $path));
} elseif ($errors == 0 && $uploads == 0) { } elseif ($errors == 0 && $uploads == 0) {
fm_set_msg(fm_t('Nothing uploaded'), 'alert'); fm_set_msg('Nothing uploaded', 'alert');
} else { } else {
fm_set_msg(sprintf(fm_t('Error while uploading files. Uploaded files: %s'), $uploads), 'error'); fm_set_msg(sprintf('Error while uploading files. Uploaded files: %s', $uploads), 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
@ -493,12 +484,12 @@ if (isset($_POST['group'], $_POST['delete']) && !FM_READONLY) {
} }
} }
if ($errors == 0) { if ($errors == 0) {
fm_set_msg(fm_t('Selected files and folder deleted')); fm_set_msg('Selected files and folder deleted');
} else { } else {
fm_set_msg(fm_t('Error while deleting items'), 'error'); fm_set_msg('Error while deleting items', 'error');
} }
} else { } else {
fm_set_msg(fm_t('Nothing selected'), 'alert'); fm_set_msg('Nothing selected', 'alert');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
@ -512,7 +503,7 @@ if (isset($_POST['group'], $_POST['zip']) && !FM_READONLY) {
} }
if (!class_exists('ZipArchive')) { if (!class_exists('ZipArchive')) {
fm_set_msg(fm_t('Operations with archives are not available'), 'error'); fm_set_msg('Operations with archives are not available', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -532,12 +523,12 @@ if (isset($_POST['group'], $_POST['zip']) && !FM_READONLY) {
$res = $zipper->create($zipname, $files); $res = $zipper->create($zipname, $files);
if ($res) { if ($res) {
fm_set_msg(sprintf(fm_t('Archive <b>%s</b> created'), $zipname)); fm_set_msg(sprintf('Archive <b>%s</b> created', $zipname));
} else { } else {
fm_set_msg(fm_t('Archive not created'), 'error'); fm_set_msg('Archive not created', 'error');
} }
} else { } else {
fm_set_msg(fm_t('Nothing selected'), 'alert'); fm_set_msg('Nothing selected', 'alert');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
@ -555,7 +546,7 @@ if (isset($_GET['unzip']) && !FM_READONLY) {
} }
if (!class_exists('ZipArchive')) { if (!class_exists('ZipArchive')) {
fm_set_msg(fm_t('Operations with archives are not available'), 'error'); fm_set_msg('Operations with archives are not available', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -575,13 +566,13 @@ if (isset($_GET['unzip']) && !FM_READONLY) {
$res = $zipper->unzip($zip_path, $path); $res = $zipper->unzip($zip_path, $path);
if ($res) { if ($res) {
fm_set_msg(fm_t('Archive unpacked')); fm_set_msg('Archive unpacked');
} else { } else {
fm_set_msg(fm_t('Archive not unpacked'), 'error'); fm_set_msg('Archive not unpacked', 'error');
} }
} else { } else {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -597,7 +588,7 @@ if (isset($_POST['chmod']) && !FM_READONLY && !FM_IS_WIN) {
$file = fm_clean_path($file); $file = fm_clean_path($file);
$file = str_replace('/', '', $file); $file = str_replace('/', '', $file);
if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) { if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -631,9 +622,9 @@ if (isset($_POST['chmod']) && !FM_READONLY && !FM_IS_WIN) {
} }
if (@chmod($path . '/' . $file, $mode)) { if (@chmod($path . '/' . $file, $mode)) {
fm_set_msg(fm_t('Permissions changed')); fm_set_msg('Permissions changed');
} else { } else {
fm_set_msg(fm_t('Permissions not changed'), 'error'); fm_set_msg('Permissions not changed', 'error');
} }
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
@ -688,8 +679,8 @@ if (isset($_GET['upload']) && !FM_READONLY) {
fm_show_nav_path(FM_PATH); // current path fm_show_nav_path(FM_PATH); // current path
?> ?>
<div class="path"> <div class="path">
<p><b><?php echo fm_t('Uploading files') ?></b></p> <p><b>Uploading files</b></p>
<p class="break-word"><?php echo fm_t('Destination folder:') ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?></p> <p class="break-word">Destination folder: <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?></p>
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>"> <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
<input type="hidden" name="upl" value="1"> <input type="hidden" name="upl" value="1">
@ -714,7 +705,7 @@ if (isset($_GET['upload']) && !FM_READONLY) {
if (isset($_POST['copy']) && !FM_READONLY) { if (isset($_POST['copy']) && !FM_READONLY) {
$copy_files = $_POST['file']; $copy_files = $_POST['file'];
if (!is_array($copy_files) || empty($copy_files)) { if (!is_array($copy_files) || empty($copy_files)) {
fm_set_msg(fm_t('Nothing selected'), 'alert'); fm_set_msg('Nothing selected', 'alert');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -722,7 +713,7 @@ if (isset($_POST['copy']) && !FM_READONLY) {
fm_show_nav_path(FM_PATH); // current path fm_show_nav_path(FM_PATH); // current path
?> ?>
<div class="path"> <div class="path">
<p><b><?php echo fm_t('Copying') ?></b></p> <p><b>Copying</b></p>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>"> <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
<input type="hidden" name="finish" value="1"> <input type="hidden" name="finish" value="1">
@ -753,7 +744,7 @@ if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
$copy = $_GET['copy']; $copy = $_GET['copy'];
$copy = fm_clean_path($copy); $copy = fm_clean_path($copy);
if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) { if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -761,10 +752,10 @@ if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
fm_show_nav_path(FM_PATH); // current path fm_show_nav_path(FM_PATH); // current path
?> ?>
<div class="path"> <div class="path">
<p><b><?php echo fm_t('Copying') ?></b></p> <p><b>Copying</b></p>
<p class="break-word"> <p class="break-word">
<?php echo fm_t('Source path:') ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . $copy) ?><br> Source path: <?php echo fm_convert_win(FM_ROOT_PATH . '/' . $copy) ?><br>
<?php echo fm_t('Destination folder:') ?> <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?> Destination folder: <?php echo fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH) ?>
</p> </p>
<p> <p>
<b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1"><i class="fa fa-check-circle"></i> <?php echo fm_t('Copy') ?></a></b> &nbsp; <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1"><i class="fa fa-check-circle"></i> <?php echo fm_t('Copy') ?></a></b> &nbsp;
@ -798,7 +789,7 @@ if (isset($_GET['view'])) {
$file = fm_clean_path($file); $file = fm_clean_path($file);
$file = str_replace('/', '', $file); $file = str_replace('/', '', $file);
if ($file == '' || !is_file($path . '/' . $file)) { if ($file == '' || !is_file($path . '/' . $file)) {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -842,11 +833,11 @@ if (isset($_GET['view'])) {
?> ?>
<div class="path"> <div class="path">
<p class="break-word"><b><?php echo fm_t($view_title) ?> <?php echo fm_convert_win($file) ?></b></p> <p class="break-word"><b><?php echo $view_title ?> "<?php echo fm_convert_win($file) ?>"</b></p>
<p class="break-word"> <p class="break-word">
<?php echo fm_t('Full path:') ?> <?php echo fm_convert_win($file_path) ?><br> Full path: <?php echo fm_convert_win($file_path) ?><br>
<?php echo fm_t('File size:') ?> <?php echo fm_get_filesize($filesize) ?> (<?php echo sprintf(fm_t('%s byte'), $filesize) ?>)<br> File size: <?php echo fm_get_filesize($filesize) ?><?php if ($filesize >= 1000): ?> (<?php echo sprintf('%s bytes', $filesize) ?>)<?php endif; ?><br>
<?php echo fm_t('MIME-type:') ?> <?php echo $mime_type ?><br> MIME-type: <?php echo $mime_type ?><br>
<?php <?php
// ZIP info // ZIP info
if ($is_zip && $filenames !== false) { if ($is_zip && $filenames !== false) {
@ -861,16 +852,16 @@ if (isset($_GET['view'])) {
$total_uncomp += $fn['filesize']; $total_uncomp += $fn['filesize'];
} }
?> ?>
<?php echo fm_t('Files in archive:') ?> <?php echo $total_files ?><br> Files in archive: <?php echo $total_files ?><br>
<?php echo fm_t('Total size:') ?> <?php echo fm_get_filesize($total_uncomp) ?><br> Total size: <?php echo fm_get_filesize($total_uncomp) ?><br>
<?php echo fm_t('Size in archive:') ?> <?php echo fm_get_filesize($total_comp) ?><br> Size in archive: <?php echo fm_get_filesize($total_comp) ?><br>
<?php echo fm_t('Compression:') ?> <?php echo round(($total_comp / $total_uncomp) * 100) ?>%<br> Compression: <?php echo round(($total_comp / $total_uncomp) * 100) ?>%<br>
<?php <?php
} }
// Image info // Image info
if ($is_image) { if ($is_image) {
$image_size = getimagesize($file_path); $image_size = getimagesize($file_path);
echo fm_t('Image sizes:') . ' ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>'; echo 'Image sizes: ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
} }
// Text info // Text info
if ($is_text) { if ($is_text) {
@ -880,7 +871,7 @@ if (isset($_GET['view'])) {
$content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content); $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
} }
} }
echo fm_t('Charset:') . ' ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>'; echo 'Charset: ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>';
} }
?> ?>
</p> </p>
@ -921,7 +912,7 @@ if (isset($_GET['view'])) {
} }
echo '</code>'; echo '</code>';
} else { } else {
echo '<p>' . fm_t('Error while fetching archive info') . '</p>'; echo '<p>Error while fetching archive info</p>';
} }
} elseif ($is_image) { } elseif ($is_image) {
// Image content // Image content
@ -1044,7 +1035,7 @@ if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
$file = fm_clean_path($file); $file = fm_clean_path($file);
$file = str_replace('/', '', $file); $file = str_replace('/', '', $file);
if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) { if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
fm_set_msg(fm_t('File not found'), 'error'); fm_set_msg('File not found', 'error');
fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH)); fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
} }
@ -1058,9 +1049,9 @@ if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
?> ?>
<div class="path"> <div class="path">
<p><b><?php echo fm_t('Change Permissions') ?></b></p> <p><b>Change Permissions</b></p>
<p> <p>
<?php echo fm_t('Full path:') ?> <?php echo $file_path ?><br> Full path: <?php echo $file_path ?><br>
</p> </p>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>"> <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
@ -1069,24 +1060,24 @@ if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
<table class="compact-table"> <table class="compact-table">
<tr> <tr>
<td></td> <td></td>
<td><b><?php echo fm_t('Owner') ?></b></td> <td><b>Owner</b></td>
<td><b><?php echo fm_t('Group') ?></b></td> <td><b>Group</b></td>
<td><b><?php echo fm_t('Other') ?></b></td> <td><b>Other</b></td>
</tr> </tr>
<tr> <tr>
<td style="text-align: right"><b><?php echo fm_t('Read') ?></b></td> <td style="text-align: right"><b>Read</b></td>
<td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
</tr> </tr>
<tr> <tr>
<td style="text-align: right"><b><?php echo fm_t('Write') ?></b></td> <td style="text-align: right"><b>Write</b></td>
<td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
</tr> </tr>
<tr> <tr>
<td style="text-align: right"><b><?php echo fm_t('Execute') ?></b></td> <td style="text-align: right"><b>Execute</b></td>
<td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
<td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td> <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
@ -1135,8 +1126,8 @@ if ($parent !== false) {
} }
foreach ($folders as $f) { foreach ($folders as $f) {
$is_link = is_link($path . '/' . $f); $is_link = is_link($path . '/' . $f);
$img = $is_link ? 'fa fa-folder' : 'fa fa-folder-o'; $img = $is_link ? 'icon-link_folder' : 'icon-folder';
$modif = date("d.m.y H:i", filemtime($path . '/' . $f)); $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
$perms = substr(decoct(fileperms($path . '/' . $f)), -4); $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) { if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
$owner = posix_getpwuid(fileowner($path . '/' . $f)); $owner = posix_getpwuid(fileowner($path . '/' . $f));
@ -1185,7 +1176,7 @@ foreach ($files as $f) {
<tr> <tr>
<?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?> <?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?>
<td><div class="filename"><a href="<?php echo $filelink ?>" title="<?php echo fm_t('File info') ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td> <td><div class="filename"><a href="<?php echo $filelink ?>" title="<?php echo fm_t('File info') ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td>
<td><span title="<?php printf(fm_t('%s byte'), $filesize_raw) ?>"><?php echo $filesize ?></span></td> <td><span title="<?php printf(fm_t('%s bytes'), $filesize_raw) ?>"><?php echo $filesize ?></span></td>
<td><?php echo $modif ?></td> <td><?php echo $modif ?></td>
<?php if (!FM_IS_WIN): ?> <?php if (!FM_IS_WIN): ?>
<td><?php if (!FM_READONLY): ?><a title="<?php echo fm_t('Change Permissions') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td> <td><?php if (!FM_READONLY): ?><a title="<?php echo fm_t('Change Permissions') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td>
@ -1211,7 +1202,7 @@ if (empty($folders) && empty($files)) {
} else { } else {
?> ?>
<tr><?php if (!FM_READONLY): ?><td class="gray"></td><?php endif; ?><td class="gray" colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"> <tr><?php if (!FM_READONLY): ?><td class="gray"></td><?php endif; ?><td class="gray" colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>">
<?php echo fm_t('Full size:') ?> <span title="<?php printf(fm_t('%s byte'), $all_files_size) ?>"><?php echo fm_get_filesize($all_files_size) ?></span>, <?php echo fm_t('Full size:') ?> <span title="<?php printf(fm_t('%s bytes'), $all_files_size) ?>"><?php echo fm_get_filesize($all_files_size) ?></span>,
<?php echo fm_t('files:') ?> <?php echo $num_files ?>, <?php echo fm_t('files:') ?> <?php echo $num_files ?>,
<?php echo fm_t('folders:') ?> <?php echo $num_folders ?> <?php echo fm_t('folders:') ?> <?php echo $num_folders ?>
</td></tr> </td></tr>
@ -1463,13 +1454,15 @@ function fm_get_parent_path($path)
function fm_get_filesize($size) function fm_get_filesize($size)
{ {
if ($size < 1000) { if ($size < 1000) {
return sprintf(fm_t('%s byte'), $size); return sprintf('%s B', $size);
} elseif (($size / 1024) < 1000) { } elseif (($size / 1024) < 1000) {
return sprintf(fm_t('%s KB'), round(($size / 1024), 1)); return sprintf('%s KiB', round(($size / 1024), 2));
} elseif (($size / 1024 / 1024) < 1000) { } elseif (($size / 1024 / 1024) < 1000) {
return sprintf(fm_t('%s MB'), round(($size / 1024 / 1024), 1)); return sprintf('%s MiB', round(($size / 1024 / 1024), 2));
} elseif (($size / 1024 / 1024 / 1024) < 1000) {
return sprintf('%s GiB', round(($size / 1024 / 1024 / 1024), 2));
} else { } else {
return sprintf(fm_t('%s GB'), round(($size / 1024 / 1024 / 1024), 1)); return sprintf('%s TiB', round(($size / 1024 / 1024 / 1024 / 1024), 2));
} }
} }