Lathoz

Untitled

May 22nd, 2026
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 225.97 KB | None | 0 0
  1. <?php
  2. //Default Configuration
  3. $CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
  4.  
  5. /**
  6.  * H3K ~ Tiny File Manager V2.6
  7.  * @author CCP Programmers
  8.  * @github https://github.com/prasathmani/tinyfilemanager
  9.  * @link https://tinyfilemanager.github.io
  10.  */
  11.  
  12. //TFM version
  13. define('VERSION', '2.6');
  14.  
  15. //Application Title
  16. define('APP_TITLE', 'Tiny File Manager');
  17.  
  18. // --- EDIT BELOW CONFIGURATION CAREFULLY ---
  19.  
  20. // Auth with login/password
  21. // set true/false to enable/disable it
  22. // Is independent from IP white- and blacklisting
  23. $use_auth = true;
  24.  
  25. // Login user name and password
  26. // Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
  27. // Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
  28. $auth_users = array(
  29.     'admin' => '$2y$10$/K.hjNr84lLNDt8fTXjoI.DBp6PpeyoJ.mGwrrLuCZfAwfSAGqhOW', //admin@123
  30.     'user' => '$2y$10$Fg6Dz8oH9fPoZ2jJan5tZuv6Z4Kp7avtQ9bDfrdRntXtPeiMAZyGO' //12345
  31. );
  32.  
  33. // Readonly users
  34. // e.g. array('users', 'guest', ...)
  35. $readonly_users = array(
  36.     'user'
  37. );
  38.  
  39. // Global readonly, including when auth is not being used
  40. $global_readonly = false;
  41.  
  42. // user specific directories
  43. // array('Username' => 'Directory path', 'Username2' => 'Directory path', ...)
  44. $directories_users = array();
  45.  
  46. // Enable highlight.js (https://highlightjs.org/) on view's page
  47. $use_highlightjs = true;
  48.  
  49. // highlight.js style
  50. // for dark theme use 'ir-black'
  51. $highlightjs_style = 'vs';
  52.  
  53. // Enable ace.js (https://ace.c9.io/) on view's page
  54. $edit_files = true;
  55.  
  56. // Default timezone for date() and time()
  57. // Doc - http://php.net/manual/en/timezones.php
  58. $default_timezone = 'Etc/UTC'; // UTC
  59.  
  60. // Root path for file manager
  61. // use absolute path of directory i.e: '/var/www/folder' or $_SERVER['DOCUMENT_ROOT'].'/folder'
  62. //make sure update $root_url in next section
  63. $root_path = $_SERVER['DOCUMENT_ROOT'];
  64.  
  65. // Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
  66. // Will not working if $root_path will be outside of server document root
  67. $root_url = '';
  68.  
  69. // Server hostname. Can set manually if wrong
  70. // $_SERVER['HTTP_HOST'].'/folder'
  71. $http_host = $_SERVER['HTTP_HOST'];
  72.  
  73. // input encoding for iconv
  74. $iconv_input_encoding = 'UTF-8';
  75.  
  76. // date() format for file modification date
  77. // Doc - https://www.php.net/manual/en/function.date.php
  78. $datetime_format = 'm/d/Y g:i A';
  79.  
  80. // Path display mode when viewing file information
  81. // 'full' => show full path
  82. // 'relative' => show path relative to root_path
  83. // 'host' => show path on the host
  84. $path_display_mode = 'full';
  85.  
  86. // Allowed file extensions for create and rename files
  87. // e.g. 'txt,html,css,js'
  88. $allowed_file_extensions = '';
  89.  
  90. // Allowed file extensions for upload files
  91. // e.g. 'gif,png,jpg,html,txt'
  92. $allowed_upload_extensions = '';
  93.  
  94. // Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
  95. // full path, e.g http://example.com/favicon.png
  96. // local path, e.g images/icons/favicon.png
  97. $favicon_path = '';
  98.  
  99. // Files and folders to excluded from listing
  100. // e.g. array('myfile.html', 'personal-folder', '*.php', '/path/to/folder', ...)
  101. $exclude_items = array();
  102.  
  103. // Online office Docs Viewer
  104. // Available rules are 'google', 'microsoft' or false
  105. // Google => View documents using Google Docs Viewer
  106. // Microsoft => View documents using Microsoft Web Apps Viewer
  107. // false => disable online doc viewer
  108. $online_viewer = 'google';
  109.  
  110. // Sticky Nav bar
  111. // true => enable sticky header
  112. // false => disable sticky header
  113. $sticky_navbar = true;
  114.  
  115. // Maximum file upload size
  116. // Increase the following values in php.ini to work properly
  117. // memory_limit, upload_max_filesize, post_max_size
  118. $max_upload_size_bytes = 5000000000; // size 5,000,000,000 bytes (~5GB)
  119.  
  120. // chunk size used for upload
  121. // eg. decrease to 1MB if nginx reports problem 413 entity too large
  122. $upload_chunk_size_bytes = 2000000; // chunk size 2,000,000 bytes (~2MB)
  123.  
  124. // Possible rules are 'OFF', 'AND' or 'OR'
  125. // OFF => Don't check connection IP, defaults to OFF
  126. // AND => Connection must be on the whitelist, and not on the blacklist
  127. // OR => Connection must be on the whitelist, or not on the blacklist
  128. $ip_ruleset = 'OFF';
  129.  
  130. // Should users be notified of their block?
  131. $ip_silent = true;
  132.  
  133. // IP-addresses, both ipv4 and ipv6
  134. $ip_whitelist = array(
  135.     '127.0.0.1',    // local ipv4
  136.     '::1'           // local ipv6
  137. );
  138.  
  139. // IP-addresses, both ipv4 and ipv6
  140. $ip_blacklist = array(
  141.     '0.0.0.0',      // non-routable meta ipv4
  142.     '::'            // non-routable meta ipv6
  143. );
  144.  
  145. // if User has the external config file, try to use it to override the default config above [config.php]
  146. // sample config - https://tinyfilemanager.github.io/config-sample.txt
  147. $config_file = __DIR__ . '/config.php';
  148. if (is_readable($config_file)) {
  149.     @include($config_file);
  150. }
  151.  
  152. // External CDN resources that can be used in the HTML (replace for GDPR compliance)
  153. $external = array(
  154.     'css-bootstrap' => '<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">',
  155.     'css-dropzone' => '<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css" rel="stylesheet">',
  156.     'css-font-awesome' => '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymous">',
  157.     'css-highlightjs' => '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/' . $highlightjs_style . '.min.css">',
  158.     'js-ace' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/ace.js"></script>',
  159.     'js-bootstrap' => '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>',
  160.     'js-dropzone' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script>',
  161.     'js-jquery' => '<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>',
  162.     'js-jquery-datatables' => '<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js" crossorigin="anonymous" defer></script>',
  163.     'js-highlightjs' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>',
  164.     'pre-jsdelivr' => '<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin/><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"/>',
  165.     'pre-cloudflare' => '<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin/><link rel="dns-prefetch" href="https://cdnjs.cloudflare.com"/>'
  166. );
  167.  
  168. // --- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL ---
  169.  
  170. // max upload file size
  171. define('MAX_UPLOAD_SIZE', $max_upload_size_bytes);
  172.  
  173. // upload chunk size
  174. define('UPLOAD_CHUNK_SIZE', $upload_chunk_size_bytes);
  175.  
  176. // private key and session name to store to the session
  177. if (!defined('FM_SESSION_ID')) {
  178.     define('FM_SESSION_ID', 'filemanager');
  179. }
  180.  
  181. // Configuration
  182. $cfg = new FM_Config();
  183.  
  184. // Default language
  185. $lang = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
  186.  
  187. // Show or hide files and folders that starts with a dot
  188. $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
  189.  
  190. // PHP error reporting - false = Turns off Errors, true = Turns on Errors
  191. $report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
  192.  
  193. // Hide Permissions and Owner cols in file-listing
  194. $hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
  195.  
  196. // Theme
  197. $theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';
  198.  
  199. define('FM_THEME', $theme);
  200.  
  201. //available languages
  202. $lang_list = array(
  203.     'en' => 'English'
  204. );
  205.  
  206. if ($report_errors == true) {
  207.     @ini_set('error_reporting', E_ALL);
  208.     @ini_set('display_errors', 1);
  209. } else {
  210.     @ini_set('error_reporting', E_ALL);
  211.     @ini_set('display_errors', 0);
  212. }
  213.  
  214. // if fm included
  215. if (defined('FM_EMBED')) {
  216.     $use_auth = false;
  217.     $sticky_navbar = false;
  218. } else {
  219.     @set_time_limit(600);
  220.  
  221.     date_default_timezone_set($default_timezone);
  222.  
  223.     ini_set('default_charset', 'UTF-8');
  224.     if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
  225.         mb_internal_encoding('UTF-8');
  226.     }
  227.     if (function_exists('mb_regex_encoding')) {
  228.         mb_regex_encoding('UTF-8');
  229.     }
  230.  
  231.     session_cache_limiter('nocache'); // Prevent logout issue after page was cached
  232.     session_name(FM_SESSION_ID);
  233.     function session_error_handling_function($code, $msg, $file, $line)
  234.     {
  235.         // Permission denied for default session, try to create a new one
  236.         if ($code == 2) {
  237.             session_abort();
  238.             session_id(session_create_id());
  239.             @session_start();
  240.         }
  241.     }
  242.     set_error_handler('session_error_handling_function');
  243.     session_start();
  244.     restore_error_handler();
  245. }
  246.  
  247. //Generating CSRF Token
  248. if (empty($_SESSION['token'])) {
  249.     if (function_exists('random_bytes')) {
  250.         $_SESSION['token'] = bin2hex(random_bytes(32));
  251.     } else {
  252.         $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32));
  253.     }
  254. }
  255.  
  256. if (empty($auth_users)) {
  257.     $use_auth = false;
  258. }
  259.  
  260. $is_https = isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on' || $_SERVER['HTTPS'] == 1)
  261.     || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
  262.  
  263. // update $root_url based on user specific directories
  264. if (isset($_SESSION[FM_SESSION_ID]['logged']) && !empty($directories_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  265.     $wd = fm_clean_path(dirname($_SERVER['PHP_SELF']));
  266.     $root_url =  $root_url . $wd . DIRECTORY_SEPARATOR . $directories_users[$_SESSION[FM_SESSION_ID]['logged']];
  267. }
  268. // clean $root_url
  269. $root_url = fm_clean_path($root_url);
  270.  
  271. // abs path for site
  272. defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
  273. defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
  274.  
  275. // logout
  276. if (isset($_GET['logout'])) {
  277.     unset($_SESSION[FM_SESSION_ID]['logged']);
  278.     unset($_SESSION['token']);
  279.     fm_redirect(FM_SELF_URL);
  280. }
  281.  
  282. // Validate connection IP
  283. if ($ip_ruleset != 'OFF') {
  284.     function getClientIP()
  285.     {
  286.         if (array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)) {
  287.             return  $_SERVER["HTTP_CF_CONNECTING_IP"];
  288.         } else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
  289.             return  $_SERVER["HTTP_X_FORWARDED_FOR"];
  290.         } else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
  291.             return $_SERVER['REMOTE_ADDR'];
  292.         } else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
  293.             return $_SERVER['HTTP_CLIENT_IP'];
  294.         }
  295.         return '';
  296.     }
  297.  
  298.     $clientIp = getClientIP();
  299.     $proceed = false;
  300.     $whitelisted = in_array($clientIp, $ip_whitelist);
  301.     $blacklisted = in_array($clientIp, $ip_blacklist);
  302.  
  303.     if ($ip_ruleset == 'AND') {
  304.         if ($whitelisted == true && $blacklisted == false) {
  305.             $proceed = true;
  306.         }
  307.     } else
  308.     if ($ip_ruleset == 'OR') {
  309.         if ($whitelisted == true || $blacklisted == false) {
  310.             $proceed = true;
  311.         }
  312.     }
  313.  
  314.     if ($proceed == false) {
  315.         trigger_error('User connection denied from: ' . $clientIp, E_USER_WARNING);
  316.  
  317.         if ($ip_silent == false) {
  318.             fm_set_msg(lng('Access denied. IP restriction applicable'), 'error');
  319.             fm_show_header_login();
  320.             fm_show_message();
  321.         }
  322.         exit();
  323.     }
  324. }
  325.  
  326. // Checking if the user is logged in or not. If not, it will show the login form.
  327. if ($use_auth) {
  328.     if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  329.         // Logged
  330.     } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'], $_POST['token'])) {
  331.         // Logging In
  332.         sleep(1);
  333.         if (function_exists('password_verify')) {
  334.             if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']]) && verifyToken($_POST['token'])) {
  335.                 $_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr'];
  336.                 fm_set_msg(lng('You are logged in'));
  337.                 fm_redirect(FM_SELF_URL);
  338.             } else {
  339.                 unset($_SESSION[FM_SESSION_ID]['logged']);
  340.                 fm_set_msg(lng('Login failed. Invalid username or password'), 'error');
  341.                 fm_redirect(FM_SELF_URL);
  342.             }
  343.         } else {
  344.             fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');;
  345.         }
  346.     } else {
  347.         // Form
  348.         unset($_SESSION[FM_SESSION_ID]['logged']);
  349.         fm_show_header_login();
  350. ?>
  351.         <section class="h-100">
  352.             <div class="container h-100">
  353.                 <div class="row justify-content-md-center align-content-center h-100vh">
  354.                     <div class="card-wrapper">
  355.                         <div class="card fat" data-bs-theme="<?php echo FM_THEME; ?>">
  356.                             <div class="card-body">
  357.                                 <form class="form-signin" action="" method="post" autocomplete="off">
  358.                                     <div class="mb-3">
  359.                                         <div class="brand">
  360.                                             <svg version="1.0" xmlns="http://www.w3.org/2000/svg" M1008 width="100%" height="80px" viewBox="0 0 238.000000 140.000000" aria-label="H3K Tiny File Manager">
  361.                                                 <g transform="translate(0.000000,140.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">
  362.                                                     <path d="M160 700 l0 -600 110 0 110 0 0 260 0 260 70 0 70 0 0 -260 0 -260 110 0 110 0 0 600 0 600 -110 0 -110 0 0 -260 0 -260 -70 0 -70 0 0 260 0 260 -110 0 -110 0 0 -600z" />
  363.                                                     <path fill="#003500" d="M1008 1227 l-108 -72 0 -117 0 -118 110 0 110 0 0 110 0 110 70 0 70 0 0 -180 0 -180 -125 0 c-69 0 -125 -3 -125 -6 0 -3 23 -39 52 -80 l52 -74 73 0 73 0 0 -185 0 -185 -70 0 -70 0 0 115 0 115 -110 0 -110 0 0 -190 0 -190 181 0 181 0 109 73 108 72 1 181 0 181 -69 48 -68 49 68 50 69 49 0 249 0 248 -182 -1 -183 0 -107 -72z" />
  364.                                                     <path d="M1640 700 l0 -600 110 0 110 0 0 208 0 208 35 34 35 34 35 -34 35 -34 0 -208 0 -208 110 0 110 0 0 212 0 213 -87 87 -88 88 88 88 87 87 0 213 0 212 -110 0 -110 0 0 -208 0 -208 -70 -69 -70 -69 0 277 0 277 -110 0 -110 0 0 -600z" />
  365.                                                 </g>
  366.                                             </svg>
  367.                                         </div>
  368.                                         <div class="text-center">
  369.                                             <h1 class="card-title"><?php echo APP_TITLE; ?></h1>
  370.                                         </div>
  371.                                     </div>
  372.                                     <hr />
  373.                                     <div class="mb-3">
  374.                                         <label for="fm_usr" class="pb-2"><?php echo lng('Username'); ?></label>
  375.                                         <input type="text" class="form-control" id="fm_usr" name="fm_usr" required autofocus>
  376.                                     </div>
  377.  
  378.                                     <div class="mb-3">
  379.                                         <label for="fm_pwd" class="pb-2"><?php echo lng('Password'); ?></label>
  380.                                         <input type="password" class="form-control" id="fm_pwd" name="fm_pwd" required>
  381.                                     </div>
  382.  
  383.                                     <div class="mb-3">
  384.                                         <?php fm_show_message(); ?>
  385.                                     </div>
  386.                                     <input type="hidden" name="token" value="<?php echo htmlentities($_SESSION['token']); ?>" />
  387.                                     <div class="mb-3">
  388.                                         <button type="submit" class="btn btn-success btn-block w-100 mt-4" role="button">
  389.                                             <?php echo lng('Login'); ?>
  390.                                         </button>
  391.                                     </div>
  392.                                 </form>
  393.                             </div>
  394.                         </div>
  395.                         <div class="footer text-center">
  396.                             &mdash;&mdash; &copy;
  397.                             <a href="https://tinyfilemanager.github.io/" target="_blank" class="text-decoration-none text-muted" data-version="<?php echo VERSION; ?>">CCP Programmers</a> &mdash;&mdash;
  398.                         </div>
  399.                     </div>
  400.                 </div>
  401.             </div>
  402.         </section>
  403.  
  404.     <?php
  405.         fm_show_footer_login();
  406.         exit;
  407.     }
  408. }
  409.  
  410. // update root path
  411. if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
  412.     $root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
  413. }
  414.  
  415. // clean and check $root_path
  416. $root_path = rtrim($root_path, '\\/');
  417. $root_path = str_replace('\\', '/', $root_path);
  418. if (!@is_dir($root_path)) {
  419.     echo "<h1>" . lng('Root path') . " \"{$root_path}\" " . lng('not found!') . " </h1>";
  420.     exit;
  421. }
  422.  
  423. defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
  424. defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
  425. defined('FM_LANG') || define('FM_LANG', $lang);
  426. defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
  427. defined('FM_UPLOAD_EXTENSION') || define('FM_UPLOAD_EXTENSION', $allowed_upload_extensions);
  428. defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items) : $exclude_items));
  429. defined('FM_DOC_VIEWER') || define('FM_DOC_VIEWER', $online_viewer);
  430. define('FM_READONLY', $global_readonly || ($use_auth && !empty($readonly_users) && isset($_SESSION[FM_SESSION_ID]['logged']) && in_array($_SESSION[FM_SESSION_ID]['logged'], $readonly_users)));
  431. define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
  432.  
  433. // always use ?p=
  434. if (!isset($_GET['p']) && empty($_FILES)) {
  435.     fm_redirect(FM_SELF_URL . '?p=');
  436. }
  437.  
  438. // get path
  439. $p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
  440.  
  441. // clean path
  442. $p = fm_clean_path($p);
  443.  
  444. // for ajax request - save
  445. $input = file_get_contents('php://input');
  446. $_POST = (strpos($input, 'ajax') != FALSE && strpos($input, 'save') != FALSE) ? json_decode($input, true) : $_POST;
  447.  
  448. // instead globals vars
  449. define('FM_PATH', $p);
  450. define('FM_USE_AUTH', $use_auth);
  451. define('FM_EDIT_FILE', $edit_files);
  452. defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
  453. defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
  454. defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
  455. defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
  456.  
  457. unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
  458.  
  459. /*************************** ACTIONS ***************************/
  460.  
  461. // Handle all AJAX Request
  462. if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']]) || !FM_USE_AUTH) && isset($_POST['ajax'], $_POST['token'])) {
  463.     if (!verifyToken($_POST['token'])) {
  464.         header('HTTP/1.0 401 Unauthorized');
  465.         die("Invalid Token.");
  466.     }
  467.  
  468.     //search : get list of files from the current folder
  469.     if (isset($_POST['type']) && $_POST['type'] == "search") {
  470.         $dir = $_POST['path'] == "." ? '' : $_POST['path'];
  471.         $response = scan(fm_clean_path($dir), $_POST['content']);
  472.         echo json_encode($response);
  473.         exit();
  474.     }
  475.  
  476.     if(FM_READONLY){
  477.         exit();
  478.     }
  479.  
  480.     // save editor file
  481.     if (isset($_POST['type']) && $_POST['type'] == "save") {
  482.         // get current path
  483.         $path = FM_ROOT_PATH;
  484.         if (FM_PATH != '') {
  485.             $path .= '/' . FM_PATH;
  486.         }
  487.         // check path
  488.         if (!is_dir($path)) {
  489.             fm_redirect(FM_SELF_URL . '?p=');
  490.         }
  491.         $file = $_GET['edit'];
  492.         $file = fm_clean_path($file);
  493.         $file = str_replace('/', '', $file);
  494.         if ($file == '' || !is_file($path . '/' . $file)) {
  495.             fm_set_msg(lng('File not found'), 'error');
  496.             $FM_PATH = FM_PATH;
  497.             fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  498.         }
  499.         header('X-XSS-Protection:0');
  500.         $file_path = $path . '/' . $file;
  501.  
  502.         $writedata = $_POST['content'];
  503.         $fd = fopen($file_path, "w");
  504.         $write_results = @fwrite($fd, $writedata);
  505.         fclose($fd);
  506.         if ($write_results === false) {
  507.             header("HTTP/1.1 500 Internal Server Error");
  508.             die("Could Not Write File! - Check Permissions / Ownership");
  509.         }
  510.         die(true);
  511.     }
  512.  
  513.     // backup files
  514.     if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
  515.         $fileName = fm_clean_path($_POST['file']);
  516.         $fullPath = FM_ROOT_PATH . '/';
  517.         if (!empty($_POST['path'])) {
  518.             $relativeDirPath = fm_clean_path($_POST['path']);
  519.             $fullPath .= "{$relativeDirPath}/";
  520.         }
  521.         $date = date("dMy-His");
  522.         $newFileName = "{$fileName}-{$date}.bak";
  523.         $fullyQualifiedFileName = $fullPath . $fileName;
  524.         try {
  525.             if (!file_exists($fullyQualifiedFileName)) {
  526.                 throw new Exception("File {$fileName} not found");
  527.             }
  528.             if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) {
  529.                 echo "Backup {$newFileName} created";
  530.             } else {
  531.                 throw new Exception("Could not copy file {$fileName}");
  532.             }
  533.         } catch (Exception $e) {
  534.             echo $e->getMessage();
  535.         }
  536.     }
  537.  
  538.     // Save Config
  539.     if (isset($_POST['type']) && $_POST['type'] == "settings") {
  540.         global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme;
  541.         $newLng = $_POST['js-language'];
  542.         fm_get_translations([]);
  543.         if (!array_key_exists($newLng, $lang_list)) {
  544.             $newLng = 'en';
  545.         }
  546.  
  547.         $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
  548.         $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
  549.         $hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
  550.         $te3 = $_POST['js-theme-3'];
  551.  
  552.         if ($cfg->data['lang'] != $newLng) {
  553.             $cfg->data['lang'] = $newLng;
  554.             $lang = $newLng;
  555.         }
  556.         if ($cfg->data['error_reporting'] != $erp) {
  557.             $cfg->data['error_reporting'] = $erp;
  558.             $report_errors = $erp;
  559.         }
  560.         if ($cfg->data['show_hidden'] != $shf) {
  561.             $cfg->data['show_hidden'] = $shf;
  562.             $show_hidden_files = $shf;
  563.         }
  564.         if ($cfg->data['show_hidden'] != $shf) {
  565.             $cfg->data['show_hidden'] = $shf;
  566.             $show_hidden_files = $shf;
  567.         }
  568.         if ($cfg->data['hide_Cols'] != $hco) {
  569.             $cfg->data['hide_Cols'] = $hco;
  570.             $hide_Cols = $hco;
  571.         }
  572.         if ($cfg->data['theme'] != $te3) {
  573.             $cfg->data['theme'] = $te3;
  574.             $theme = $te3;
  575.         }
  576.         $cfg->save();
  577.         echo true;
  578.     }
  579.  
  580.     // new password hash
  581.     if (isset($_POST['type']) && $_POST['type'] == "pwdhash") {
  582.         $res = isset($_POST['inputPassword2']) && !empty($_POST['inputPassword2']) ? password_hash($_POST['inputPassword2'], PASSWORD_DEFAULT) : '';
  583.         echo $res;
  584.     }
  585.  
  586.     //upload using url
  587.     if (isset($_POST['type']) && $_POST['type'] == "upload" && !empty($_REQUEST["uploadurl"])) {
  588.         $path = FM_ROOT_PATH;
  589.         if (FM_PATH != '') {
  590.             $path .= '/' . FM_PATH;
  591.         }
  592.  
  593.         function event_callback($message)
  594.         {
  595.             global $callback;
  596.             echo json_encode($message);
  597.         }
  598.  
  599.         function get_file_path()
  600.         {
  601.             global $path, $fileinfo, $temp_file;
  602.             return $path . "/" . basename($fileinfo->name);
  603.         }
  604.  
  605.         $url = !empty($_REQUEST["uploadurl"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["uploadurl"])) ? stripslashes($_REQUEST["uploadurl"]) : null;
  606.  
  607.         //prevent 127.* domain and known ports
  608.         $domain = parse_url($url, PHP_URL_HOST);
  609.         $port = parse_url($url, PHP_URL_PORT);
  610.         $knownPorts = [22, 23, 25, 3306];
  611.  
  612.         if (preg_match("/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i", $domain) || in_array($port, $knownPorts)) {
  613.             $err = array("message" => "URL is not allowed");
  614.             event_callback(array("fail" => $err));
  615.             exit();
  616.         }
  617.  
  618.         $use_curl = false;
  619.         $temp_file = tempnam(sys_get_temp_dir(), "upload-");
  620.         $fileinfo = new stdClass();
  621.         $fileinfo->name = trim(urldecode(basename($url)), ".\x00..\x20");
  622.  
  623.         $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  624.         $ext = strtolower(pathinfo($fileinfo->name, PATHINFO_EXTENSION));
  625.         $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  626.  
  627.         $err = false;
  628.  
  629.         if (!$isFileAllowed) {
  630.             $err = array("message" => "File extension is not allowed");
  631.             event_callback(array("fail" => $err));
  632.             exit();
  633.         }
  634.  
  635.         if (!$url) {
  636.             $success = false;
  637.         } else if ($use_curl) {
  638.             @$fp = fopen($temp_file, "w");
  639.             @$ch = curl_init($url);
  640.             curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  641.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  642.             curl_setopt($ch, CURLOPT_FILE, $fp);
  643.             @$success = curl_exec($ch);
  644.             $curl_info = curl_getinfo($ch);
  645.             if (!$success) {
  646.                 $err = array("message" => curl_error($ch));
  647.             }
  648.             @curl_close($ch);
  649.             fclose($fp);
  650.             $fileinfo->size = $curl_info["size_download"];
  651.             $fileinfo->type = $curl_info["content_type"];
  652.         } else {
  653.             $ctx = stream_context_create();
  654.             @$success = copy($url, $temp_file, $ctx);
  655.             if (!$success) {
  656.                 $err = error_get_last();
  657.             }
  658.         }
  659.  
  660.         if ($success) {
  661.             $success = rename($temp_file, strtok(get_file_path(), '?'));
  662.         }
  663.  
  664.         if ($success) {
  665.             event_callback(array("done" => $fileinfo));
  666.         } else {
  667.             unlink($temp_file);
  668.             if (!$err) {
  669.                 $err = array("message" => "Invalid url parameter");
  670.             }
  671.             event_callback(array("fail" => $err));
  672.         }
  673.     }
  674.     exit();
  675. }
  676.  
  677. // Delete file / folder
  678. if (isset($_GET['del'], $_POST['token']) && !FM_READONLY) {
  679.     $del = str_replace('/', '', fm_clean_path($_GET['del']));
  680.     if ($del != '' && $del != '..' && $del != '.' && verifyToken($_POST['token'])) {
  681.         $path = FM_ROOT_PATH;
  682.         if (FM_PATH != '') {
  683.             $path .= '/' . FM_PATH;
  684.         }
  685.         $is_dir = is_dir($path . '/' . $del);
  686.         if (fm_rdelete($path . '/' . $del)) {
  687.             $msg = $is_dir ? lng('Folder') . ' <b>%s</b> ' . lng('Deleted') : lng('File') . ' <b>%s</b> ' . lng('Deleted');
  688.             fm_set_msg(sprintf($msg, fm_enc($del)));
  689.         } else {
  690.             $msg = $is_dir ? lng('Folder') . ' <b>%s</b> ' . lng('not deleted') : lng('File') . ' <b>%s</b> ' . lng('not deleted');
  691.             fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
  692.         }
  693.     } else {
  694.         fm_set_msg(lng('Invalid file or folder name'), 'error');
  695.     }
  696.     $FM_PATH = FM_PATH;
  697.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  698. }
  699.  
  700. // Create a new file/folder
  701. if (isset($_POST['newfilename'], $_POST['newfile'], $_POST['token']) && !FM_READONLY) {
  702.     $type = urldecode($_POST['newfile']);
  703.     $new = str_replace('/', '', fm_clean_path(strip_tags($_POST['newfilename'])));
  704.     if (fm_isvalid_filename($new) && $new != '' && $new != '..' && $new != '.' && verifyToken($_POST['token'])) {
  705.         $path = FM_ROOT_PATH;
  706.         if (FM_PATH != '') {
  707.             $path .= '/' . FM_PATH;
  708.         }
  709.         if ($type == "file") {
  710.             if (!file_exists($path . '/' . $new)) {
  711.                 if (fm_is_valid_ext($new)) {
  712.                     @fopen($path . '/' . $new, 'w') or die('Cannot open file:  ' . $new);
  713.                     fm_set_msg(sprintf(lng('File') . ' <b>%s</b> ' . lng('Created'), fm_enc($new)));
  714.                 } else {
  715.                     fm_set_msg(lng('File extension is not allowed'), 'error');
  716.                 }
  717.             } else {
  718.                 fm_set_msg(sprintf(lng('File') . ' <b>%s</b> ' . lng('already exists'), fm_enc($new)), 'alert');
  719.             }
  720.         } else {
  721.             if (fm_mkdir($path . '/' . $new, false) === true) {
  722.                 fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('Created'), $new));
  723.             } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
  724.                 fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('already exists'), fm_enc($new)), 'alert');
  725.             } else {
  726.                 fm_set_msg(sprintf(lng('Folder') . ' <b>%s</b> ' . lng('not created'), fm_enc($new)), 'error');
  727.             }
  728.         }
  729.     } else {
  730.         fm_set_msg(lng('Invalid characters in file or folder name'), 'error');
  731.     }
  732.     $FM_PATH = FM_PATH;
  733.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  734. }
  735.  
  736. // Copy folder / file
  737. if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
  738.     // from
  739.     $copy = urldecode($_GET['copy']);
  740.     $copy = fm_clean_path($copy);
  741.     // empty path
  742.     if ($copy == '') {
  743.         fm_set_msg(lng('Source path not defined'), 'error');
  744.         $FM_PATH = FM_PATH;
  745.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  746.     }
  747.     // abs path from
  748.     $from = FM_ROOT_PATH . '/' . $copy;
  749.     // abs path to
  750.     $dest = FM_ROOT_PATH;
  751.     if (FM_PATH != '') {
  752.         $dest .= '/' . FM_PATH;
  753.     }
  754.     $dest .= '/' . basename($from);
  755.     // move?
  756.     $move = isset($_GET['move']);
  757.     $move = fm_clean_path(urldecode($move));
  758.     // copy/move/duplicate
  759.     if ($from != $dest) {
  760.         $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  761.         if ($move) { // Move and to != from so just perform move
  762.             $rename = fm_rename($from, $dest);
  763.             if ($rename) {
  764.                 fm_set_msg(sprintf(lng('Moved from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  765.             } elseif ($rename === null) {
  766.                 fm_set_msg(lng('File or folder with this path already exists'), 'alert');
  767.             } else {
  768.                 fm_set_msg(sprintf(lng('Error while moving from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  769.             }
  770.         } else { // Not move and to != from so copy with original name
  771.             if (fm_rcopy($from, $dest)) {
  772.                 fm_set_msg(sprintf(lng('Copied from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  773.             } else {
  774.                 fm_set_msg(sprintf(lng('Error while copying from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  775.             }
  776.         }
  777.     } else {
  778.         if (!$move) { //Not move and to = from so duplicate
  779.             $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  780.             $fn_parts = pathinfo($from);
  781.             $extension_suffix = '';
  782.             if (!is_dir($from)) {
  783.                 $extension_suffix = '.' . $fn_parts['extension'];
  784.             }
  785.             //Create new name for duplicate
  786.             $fn_duplicate = $fn_parts['dirname'] . '/' . $fn_parts['filename'] . '-' . date('YmdHis') . $extension_suffix;
  787.             $loop_count = 0;
  788.             $max_loop = 1000;
  789.             // Check if a file with the duplicate name already exists, if so, make new name (edge case...)
  790.             while (file_exists($fn_duplicate) & $loop_count < $max_loop) {
  791.                 $fn_parts = pathinfo($fn_duplicate);
  792.                 $fn_duplicate = $fn_parts['dirname'] . '/' . $fn_parts['filename'] . '-copy' . $extension_suffix;
  793.                 $loop_count++;
  794.             }
  795.             if (fm_rcopy($from, $fn_duplicate, False)) {
  796.                 fm_set_msg(sprintf('Copied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)));
  797.             } else {
  798.                 fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)), 'error');
  799.             }
  800.         } else {
  801.             fm_set_msg(lng('Paths must be not equal'), 'alert');
  802.         }
  803.     }
  804.     $FM_PATH = FM_PATH;
  805.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  806. }
  807.  
  808. // Mass copy files/ folders
  809. if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish'], $_POST['token']) && !FM_READONLY) {
  810.  
  811.     if (!verifyToken($_POST['token'])) {
  812.         fm_set_msg(lng('Invalid Token.'), 'error');
  813.         die("Invalid Token.");
  814.     }
  815.  
  816.     // from
  817.     $path = FM_ROOT_PATH;
  818.     if (FM_PATH != '') {
  819.         $path .= '/' . FM_PATH;
  820.     }
  821.     // to
  822.     $copy_to_path = FM_ROOT_PATH;
  823.     $copy_to = fm_clean_path($_POST['copy_to']);
  824.     if ($copy_to != '') {
  825.         $copy_to_path .= '/' . $copy_to;
  826.     }
  827.     if ($path == $copy_to_path) {
  828.         fm_set_msg(lng('Paths must be not equal'), 'alert');
  829.         $FM_PATH = FM_PATH;
  830.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  831.     }
  832.     if (!is_dir($copy_to_path)) {
  833.         if (!fm_mkdir($copy_to_path, true)) {
  834.             fm_set_msg('Unable to create destination folder', 'error');
  835.             $FM_PATH = FM_PATH;
  836.             fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  837.         }
  838.     }
  839.     // move?
  840.     $move = isset($_POST['move']);
  841.     // copy/move
  842.     $errors = 0;
  843.     $files = $_POST['file'];
  844.     if (is_array($files) && count($files)) {
  845.         foreach ($files as $f) {
  846.             if ($f != '') {
  847.                 $f = fm_clean_path($f);
  848.                 // abs path from
  849.                 $from = $path . '/' . $f;
  850.                 // abs path to
  851.                 $dest = $copy_to_path . '/' . $f;
  852.                 // do
  853.                 if ($move) {
  854.                     $rename = fm_rename($from, $dest);
  855.                     if ($rename === false) {
  856.                         $errors++;
  857.                     }
  858.                 } else {
  859.                     if (!fm_rcopy($from, $dest)) {
  860.                         $errors++;
  861.                     }
  862.                 }
  863.             }
  864.         }
  865.         if ($errors == 0) {
  866.             $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
  867.             fm_set_msg($msg);
  868.         } else {
  869.             $msg = $move ? 'Error while moving items' : 'Error while copying items';
  870.             fm_set_msg($msg, 'error');
  871.         }
  872.     } else {
  873.         fm_set_msg(lng('Nothing selected'), 'alert');
  874.     }
  875.     $FM_PATH = FM_PATH;
  876.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  877. }
  878.  
  879. // Rename
  880. if (isset($_POST['rename_from'], $_POST['rename_to'], $_POST['token']) && !FM_READONLY) {
  881.     if (!verifyToken($_POST['token'])) {
  882.         fm_set_msg("Invalid Token.", 'error');
  883.         die("Invalid Token.");
  884.     }
  885.     // old name
  886.     $old = urldecode($_POST['rename_from']);
  887.     $old = fm_clean_path($old);
  888.     $old = str_replace('/', '', $old);
  889.     // new name
  890.     $new = urldecode($_POST['rename_to']);
  891.     $new = fm_clean_path(strip_tags($new));
  892.     $new = str_replace('/', '', $new);
  893.     // path
  894.     $path = FM_ROOT_PATH;
  895.     if (FM_PATH != '') {
  896.         $path .= '/' . FM_PATH;
  897.     }
  898.     // rename
  899.     if (fm_isvalid_filename($new) && $old != '' && $new != '') {
  900.         if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
  901.             fm_set_msg(sprintf(lng('Renamed from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($old), fm_enc($new)));
  902.         } else {
  903.             fm_set_msg(sprintf(lng('Error while renaming from') . ' <b>%s</b> ' . lng('to') . ' <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
  904.         }
  905.     } else {
  906.         fm_set_msg(lng('Invalid characters in file name'), 'error');
  907.     }
  908.     $FM_PATH = FM_PATH;
  909.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  910. }
  911.  
  912. // Download
  913. if (isset($_GET['dl'], $_POST['token'])) {
  914.     // Verify the token to ensure it's valid
  915.     if (!verifyToken($_POST['token'])) {
  916.         fm_set_msg("Invalid Token.", 'error');
  917.         exit;
  918.     }
  919.  
  920.     // Clean the download file path
  921.     $dl = urldecode($_GET['dl']);
  922.     $dl = fm_clean_path($dl);
  923.     $dl = str_replace('/', '', $dl); // Prevent directory traversal attacks
  924.  
  925.     // Define the file path
  926.     $path = FM_ROOT_PATH;
  927.     if (FM_PATH != '') {
  928.         $path .= '/' . FM_PATH;
  929.     }
  930.  
  931.     // Check if the file exists and is valid
  932.     if ($dl != '' && is_file($path . '/' . $dl)) {
  933.         // Close the session to prevent session locking
  934.         if (session_status() === PHP_SESSION_ACTIVE) {
  935.             session_write_close();
  936.         }
  937.  
  938.         // Call the download function
  939.         fm_download_file($path . '/' . $dl, $dl, 1024); // Download with a buffer size of 1024 bytes
  940.         exit;
  941.     } else {
  942.         // Handle the case where the file is not found
  943.         fm_set_msg(lng('File not found'), 'error');
  944.         $FM_PATH = FM_PATH;
  945.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  946.     }
  947. }
  948.  
  949. // Upload
  950. if (!empty($_FILES) && !FM_READONLY) {
  951.     if (isset($_POST['token'])) {
  952.         if (!verifyToken($_POST['token'])) {
  953.             $response = array('status' => 'error', 'info' => "Invalid Token.");
  954.             echo json_encode($response);
  955.             exit();
  956.         }
  957.     } else {
  958.         $response = array('status' => 'error', 'info' => "Token Missing.");
  959.         echo json_encode($response);
  960.         exit();
  961.     }
  962.  
  963.     $chunkIndex = $_POST['dzchunkindex'];
  964.     $chunkTotal = $_POST['dztotalchunkcount'];
  965.     $fullPathInput = fm_clean_path($_REQUEST['fullpath']);
  966.  
  967.     $f = $_FILES;
  968.     $path = FM_ROOT_PATH;
  969.     $ds = DIRECTORY_SEPARATOR;
  970.     if (FM_PATH != '') {
  971.         $path .= '/' . FM_PATH;
  972.     }
  973.  
  974.     $errors = 0;
  975.     $uploads = 0;
  976.     $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  977.     $response = array(
  978.         'status' => 'error',
  979.         'info'   => 'Oops! Try again'
  980.     );
  981.  
  982.     $filename = $f['file']['name'];
  983.     $tmp_name = $f['file']['tmp_name'];
  984.     $ext = pathinfo($filename, PATHINFO_FILENAME) != '' ? strtolower(pathinfo($filename, PATHINFO_EXTENSION)) : '';
  985.     $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  986.  
  987.     if (!fm_isvalid_filename($filename) && !fm_isvalid_filename($fullPathInput)) {
  988.         $response = array(
  989.             'status'    => 'error',
  990.             'info'      => "Invalid File name!",
  991.         );
  992.         echo json_encode($response);
  993.         exit();
  994.     }
  995.  
  996.     $targetPath = $path . $ds;
  997.     if (is_writable($targetPath)) {
  998.         $fullPath = $path . '/' . $fullPathInput;
  999.         $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
  1000.  
  1001.         if (!is_dir($folder)) {
  1002.             $old = umask(0);
  1003.             mkdir($folder, 0777, true);
  1004.             umask($old);
  1005.         }
  1006.  
  1007.         if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
  1008.             if ($chunkTotal) {
  1009.                 $out = @fopen("{$fullPath}.part", $chunkIndex == 0 ? "wb" : "ab");
  1010.                 if ($out) {
  1011.                     $in = @fopen($tmp_name, "rb");
  1012.                     if ($in) {
  1013.                         if (PHP_VERSION_ID < 80009) {
  1014.                             // workaround https://bugs.php.net/bug.php?id=81145
  1015.                             do {
  1016.                                 for (;;) {
  1017.                                     $buff = fread($in, 4096);
  1018.                                     if ($buff === false || $buff === '') {
  1019.                                         break;
  1020.                                     }
  1021.                                     fwrite($out, $buff);
  1022.                                 }
  1023.                             } while (!feof($in));
  1024.                         } else {
  1025.                             stream_copy_to_stream($in, $out);
  1026.                         }
  1027.                         $response = array(
  1028.                             'status'    => 'success',
  1029.                             'info' => "file upload successful"
  1030.                         );
  1031.                     } else {
  1032.                         $response = array(
  1033.                             'status'    => 'error',
  1034.                             'info' => "failed to open output stream",
  1035.                             'errorDetails' => error_get_last()
  1036.                         );
  1037.                     }
  1038.                     @fclose($in);
  1039.                     @fclose($out);
  1040.                     @unlink($tmp_name);
  1041.  
  1042.                     $response = array(
  1043.                         'status'    => 'success',
  1044.                         'info' => "file upload successful"
  1045.                     );
  1046.                 } else {
  1047.                     $response = array(
  1048.                         'status'    => 'error',
  1049.                         'info' => "failed to open output stream"
  1050.                     );
  1051.                 }
  1052.  
  1053.                 if ($chunkIndex == $chunkTotal - 1) {
  1054.                     if (file_exists($fullPath)) {
  1055.                         $ext_1 = $ext ? '.' . $ext : '';
  1056.                         $fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) . '_' . date('ymdHis') . $ext_1;
  1057.                     } else {
  1058.                         $fullPathTarget = $fullPath;
  1059.                     }
  1060.                     rename("{$fullPath}.part", $fullPathTarget);
  1061.                 }
  1062.             } else if (move_uploaded_file($tmp_name, $fullPath)) {
  1063.                 // Be sure that the file has been uploaded
  1064.                 if (file_exists($fullPath)) {
  1065.                     $response = array(
  1066.                         'status'    => 'success',
  1067.                         'info' => "file upload successful"
  1068.                     );
  1069.                 } else {
  1070.                     $response = array(
  1071.                         'status' => 'error',
  1072.                         'info'   => 'Couldn\'t upload the requested file.'
  1073.                     );
  1074.                 }
  1075.             } else {
  1076.                 $response = array(
  1077.                     'status'    => 'error',
  1078.                     'info'      => "Error while uploading files. Uploaded files $uploads",
  1079.                 );
  1080.             }
  1081.         }
  1082.     } else {
  1083.         $response = array(
  1084.             'status' => 'error',
  1085.             'info'   => 'The specified folder for upload isn\'t writeable.'
  1086.         );
  1087.     }
  1088.     // Return the response
  1089.     echo json_encode($response);
  1090.     exit();
  1091. }
  1092.  
  1093. // Mass deleting
  1094. if (isset($_POST['group'], $_POST['delete'], $_POST['token']) && !FM_READONLY) {
  1095.  
  1096.     if (!verifyToken($_POST['token'])) {
  1097.         fm_set_msg(lng("Invalid Token."), 'error');
  1098.         die("Invalid Token.");
  1099.     }
  1100.  
  1101.     $path = FM_ROOT_PATH;
  1102.     if (FM_PATH != '') {
  1103.         $path .= '/' . FM_PATH;
  1104.     }
  1105.  
  1106.     $errors = 0;
  1107.     $files = $_POST['file'];
  1108.     if (is_array($files) && count($files)) {
  1109.         foreach ($files as $f) {
  1110.             if ($f != '') {
  1111.                 $new_path = $path . '/' . $f;
  1112.                 if (!fm_rdelete($new_path)) {
  1113.                     $errors++;
  1114.                 }
  1115.             }
  1116.         }
  1117.         if ($errors == 0) {
  1118.             fm_set_msg(lng('Selected files and folder deleted'));
  1119.         } else {
  1120.             fm_set_msg(lng('Error while deleting items'), 'error');
  1121.         }
  1122.     } else {
  1123.         fm_set_msg(lng('Nothing selected'), 'alert');
  1124.     }
  1125.  
  1126.     $FM_PATH = FM_PATH;
  1127.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1128. }
  1129.  
  1130. // Pack files zip, tar
  1131. if (isset($_POST['group'], $_POST['token']) && (isset($_POST['zip']) || isset($_POST['tar'])) && !FM_READONLY) {
  1132.  
  1133.     if (!verifyToken($_POST['token'])) {
  1134.         fm_set_msg(lng("Invalid Token."), 'error');
  1135.         die("Invalid Token.");
  1136.     }
  1137.  
  1138.     $path = FM_ROOT_PATH;
  1139.     $ext = 'zip';
  1140.     if (FM_PATH != '') {
  1141.         $path .= '/' . FM_PATH;
  1142.     }
  1143.  
  1144.     //set pack type
  1145.     $ext = isset($_POST['tar']) ? 'tar' : 'zip';
  1146.  
  1147.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1148.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1149.         $FM_PATH = FM_PATH;
  1150.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1151.     }
  1152.  
  1153.     $files = $_POST['file'];
  1154.     $sanitized_files = array();
  1155.  
  1156.     // clean path
  1157.     foreach ($files as $file) {
  1158.         array_push($sanitized_files, fm_clean_path($file));
  1159.     }
  1160.  
  1161.     $files = $sanitized_files;
  1162.  
  1163.     if (!empty($files)) {
  1164.         chdir($path);
  1165.  
  1166.         if (count($files) == 1) {
  1167.             $one_file = reset($files);
  1168.             $one_file = basename($one_file);
  1169.             $zipname = $one_file . '_' . date('ymd_His') . '.' . $ext;
  1170.         } else {
  1171.             $zipname = 'archive_' . date('ymd_His') . '.' . $ext;
  1172.         }
  1173.  
  1174.         if ($ext == 'zip') {
  1175.             $zipper = new FM_Zipper();
  1176.             $res = $zipper->create($zipname, $files);
  1177.         } elseif ($ext == 'tar') {
  1178.             $tar = new FM_Zipper_Tar();
  1179.             $res = $tar->create($zipname, $files);
  1180.         }
  1181.  
  1182.         if ($res) {
  1183.             fm_set_msg(sprintf(lng('Archive') . ' <b>%s</b> ' . lng('Created'), fm_enc($zipname)));
  1184.         } else {
  1185.             fm_set_msg(lng('Archive not created'), 'error');
  1186.         }
  1187.     } else {
  1188.         fm_set_msg(lng('Nothing selected'), 'alert');
  1189.     }
  1190.  
  1191.     $FM_PATH = FM_PATH;
  1192.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1193. }
  1194.  
  1195. // Unpack zip, tar
  1196. if (isset($_POST['unzip'], $_POST['token']) && !FM_READONLY) {
  1197.  
  1198.     if (!verifyToken($_POST['token'])) {
  1199.         fm_set_msg(lng("Invalid Token."), 'error');
  1200.         die("Invalid Token.");
  1201.     }
  1202.  
  1203.     $unzip = urldecode($_POST['unzip']);
  1204.     $unzip = fm_clean_path($unzip);
  1205.     $unzip = str_replace('/', '', $unzip);
  1206.     $isValid = false;
  1207.  
  1208.     $path = FM_ROOT_PATH;
  1209.     if (FM_PATH != '') {
  1210.         $path .= '/' . FM_PATH;
  1211.     }
  1212.  
  1213.     if ($unzip != '' && is_file($path . '/' . $unzip)) {
  1214.         $zip_path = $path . '/' . $unzip;
  1215.         $ext = pathinfo($zip_path, PATHINFO_EXTENSION);
  1216.         $isValid = true;
  1217.     } else {
  1218.         fm_set_msg(lng('File not found'), 'error');
  1219.     }
  1220.  
  1221.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1222.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1223.         $FM_PATH = FM_PATH;
  1224.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1225.     }
  1226.  
  1227.     if ($isValid) {
  1228.         //to folder
  1229.         $tofolder = '';
  1230.         if (isset($_POST['tofolder'])) {
  1231.             $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
  1232.             if (fm_mkdir($path . '/' . $tofolder, true)) {
  1233.                 $path .= '/' . $tofolder;
  1234.             }
  1235.         }
  1236.  
  1237.         if ($ext == "zip") {
  1238.             $zipper = new FM_Zipper();
  1239.             $res = $zipper->unzip($zip_path, $path);
  1240.         } elseif ($ext == "tar") {
  1241.             try {
  1242.                 $gzipper = new PharData($zip_path);
  1243.                 if (@$gzipper->extractTo($path, null, true)) {
  1244.                     $res = true;
  1245.                 } else {
  1246.                     $res = false;
  1247.                 }
  1248.             } catch (Exception $e) {
  1249.                 //TODO:: need to handle the error
  1250.                 $res = true;
  1251.             }
  1252.         }
  1253.  
  1254.         if ($res) {
  1255.             fm_set_msg(lng('Archive unpacked'));
  1256.         } else {
  1257.             fm_set_msg(lng('Archive not unpacked'), 'error');
  1258.         }
  1259.     } else {
  1260.         fm_set_msg(lng('File not found'), 'error');
  1261.     }
  1262.     $FM_PATH = FM_PATH;
  1263.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1264. }
  1265.  
  1266. // Change Perms (not for Windows)
  1267. if (isset($_POST['chmod'], $_POST['token']) && !FM_READONLY && !FM_IS_WIN) {
  1268.  
  1269.     if (!verifyToken($_POST['token'])) {
  1270.         fm_set_msg(lng("Invalid Token."), 'error');
  1271.         die("Invalid Token.");
  1272.     }
  1273.  
  1274.     $path = FM_ROOT_PATH;
  1275.     if (FM_PATH != '') {
  1276.         $path .= '/' . FM_PATH;
  1277.     }
  1278.  
  1279.     $file = $_POST['chmod'];
  1280.     $file = fm_clean_path($file);
  1281.     $file = str_replace('/', '', $file);
  1282.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1283.         fm_set_msg(lng('File not found'), 'error');
  1284.         $FM_PATH = FM_PATH;
  1285.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1286.     }
  1287.  
  1288.     $mode = 0;
  1289.     if (!empty($_POST['ur'])) {
  1290.         $mode |= 0400;
  1291.     }
  1292.     if (!empty($_POST['uw'])) {
  1293.         $mode |= 0200;
  1294.     }
  1295.     if (!empty($_POST['ux'])) {
  1296.         $mode |= 0100;
  1297.     }
  1298.     if (!empty($_POST['gr'])) {
  1299.         $mode |= 0040;
  1300.     }
  1301.     if (!empty($_POST['gw'])) {
  1302.         $mode |= 0020;
  1303.     }
  1304.     if (!empty($_POST['gx'])) {
  1305.         $mode |= 0010;
  1306.     }
  1307.     if (!empty($_POST['or'])) {
  1308.         $mode |= 0004;
  1309.     }
  1310.     if (!empty($_POST['ow'])) {
  1311.         $mode |= 0002;
  1312.     }
  1313.     if (!empty($_POST['ox'])) {
  1314.         $mode |= 0001;
  1315.     }
  1316.  
  1317.     if (@chmod($path . '/' . $file, $mode)) {
  1318.         fm_set_msg(lng('Permissions changed'));
  1319.     } else {
  1320.         fm_set_msg(lng('Permissions not changed'), 'error');
  1321.     }
  1322.  
  1323.     $FM_PATH = FM_PATH;
  1324.     fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1325. }
  1326.  
  1327. /*************************** ACTIONS ***************************/
  1328.  
  1329. // get current path
  1330. $path = FM_ROOT_PATH;
  1331. if (FM_PATH != '') {
  1332.     $path .= '/' . FM_PATH;
  1333. }
  1334.  
  1335. // check path
  1336. if (!is_dir($path)) {
  1337.     fm_redirect(FM_SELF_URL . '?p=');
  1338. }
  1339.  
  1340. // get parent folder
  1341. $parent = fm_get_parent_path(FM_PATH);
  1342.  
  1343. $objects = is_readable($path) ? scandir($path) : array();
  1344. $folders = array();
  1345. $files = array();
  1346. $current_path = array_slice(explode("/", $path), -1)[0];
  1347. if (is_array($objects) && fm_is_exclude_items($current_path, $path)) {
  1348.     foreach ($objects as $file) {
  1349.         if ($file == '.' || $file == '..') {
  1350.             continue;
  1351.         }
  1352.         if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
  1353.             continue;
  1354.         }
  1355.         $new_path = $path . '/' . $file;
  1356.         if (@is_file($new_path) && fm_is_exclude_items($file, $new_path)) {
  1357.             $files[] = $file;
  1358.         } elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file, $new_path)) {
  1359.             $folders[] = $file;
  1360.         }
  1361.     }
  1362. }
  1363.  
  1364. if (!empty($files)) {
  1365.     natcasesort($files);
  1366. }
  1367. if (!empty($folders)) {
  1368.     natcasesort($folders);
  1369. }
  1370.  
  1371. // upload form
  1372. if (isset($_GET['upload']) && !FM_READONLY) {
  1373.     fm_show_header(); // HEADER
  1374.     fm_show_nav_path(FM_PATH); // current path
  1375.     //get the allowed file extensions
  1376.     function getUploadExt()
  1377.     {
  1378.         $extArr = explode(',', FM_UPLOAD_EXTENSION);
  1379.         if (FM_UPLOAD_EXTENSION && $extArr) {
  1380.             array_walk($extArr, function (&$x) {
  1381.                 $x = ".$x";
  1382.             });
  1383.             return implode(',', $extArr);
  1384.         }
  1385.         return '';
  1386.     }
  1387.     ?>
  1388.     <?php print_external('css-dropzone'); ?>
  1389.     <div class="path">
  1390.  
  1391.         <div class="card mb-2 fm-upload-wrapper" data-bs-theme="<?php echo FM_THEME; ?>">
  1392.             <div class="card-header">
  1393.                 <ul class="nav nav-tabs card-header-tabs">
  1394.                     <li class="nav-item">
  1395.                         <a class="nav-link active" href="#fileUploader" data-target="#fileUploader"><i class="fa fa-arrow-circle-o-up"></i> <?php echo lng('UploadingFiles') ?></a>
  1396.                     </li>
  1397.                     <li class="nav-item">
  1398.                         <a class="nav-link" href="#urlUploader" class="js-url-upload" data-target="#urlUploader"><i class="fa fa-link"></i> <?php echo lng('Upload from URL') ?></a>
  1399.                     </li>
  1400.                 </ul>
  1401.             </div>
  1402.             <div class="card-body">
  1403.                 <p class="card-text">
  1404.                     <a href="?p=<?php echo FM_PATH ?>" class="float-right"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back') ?></a>
  1405.                     <strong><?php echo lng('DestinationFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_PATH)) ?>
  1406.                 </p>
  1407.  
  1408.                 <form action="<?php echo htmlspecialchars(FM_SELF_URL) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
  1409.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1410.                     <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
  1411.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1412.                     <div class="fallback">
  1413.                         <input name="file" type="file" multiple />
  1414.                     </div>
  1415.                 </form>
  1416.  
  1417.                 <div class="upload-url-wrapper card-tabs-container hidden" id="urlUploader">
  1418.                     <form id="js-form-url-upload" class="row row-cols-lg-auto g-3 align-items-center" onsubmit="return upload_from_url(this);" method="POST" action="">
  1419.                         <input type="hidden" name="type" value="upload" aria-label="hidden" aria-hidden="true">
  1420.                         <input type="url" placeholder="URL" name="uploadurl" required class="form-control" style="width: 80%">
  1421.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1422.                         <button type="submit" class="btn btn-primary ms-3"><?php echo lng('Upload') ?></button>
  1423.                         <div class="lds-facebook">
  1424.                             <div></div>
  1425.                             <div></div>
  1426.                             <div></div>
  1427.                         </div>
  1428.                     </form>
  1429.                     <div id="js-url-upload__list" class="col-9 mt-3"></div>
  1430.                 </div>
  1431.             </div>
  1432.         </div>
  1433.     </div>
  1434.     <?php print_external('js-dropzone'); ?>
  1435.     <script>
  1436.         Dropzone.options.fileUploader = {
  1437.             chunking: true,
  1438.             chunkSize: <?php echo UPLOAD_CHUNK_SIZE; ?>,
  1439.             forceChunking: true,
  1440.             retryChunks: true,
  1441.             retryChunksLimit: 3,
  1442.             parallelUploads: 1,
  1443.             parallelChunkUploads: false,
  1444.             timeout: 120000,
  1445.             maxFilesize: "<?php echo MAX_UPLOAD_SIZE; ?>",
  1446.             acceptedFiles: "<?php echo getUploadExt() ?>",
  1447.             init: function() {
  1448.                 this.on("sending", function(file, xhr, formData) {
  1449.                     let _path = (file.fullPath) ? file.fullPath : file.name;
  1450.                     document.getElementById("fullpath").value = _path;
  1451.                     xhr.ontimeout = (function() {
  1452.                         toast('Error: Server Timeout');
  1453.                     });
  1454.                 }).on("success", function(res) {
  1455.                     try {
  1456.                         let _response = JSON.parse(res.xhr.response);
  1457.  
  1458.                         if (_response.status == "error") {
  1459.                             toast(_response.info);
  1460.                         }
  1461.                     } catch (e) {
  1462.                         toast("Error: Invalid JSON response");
  1463.                     }
  1464.                 }).on("error", function(file, response) {
  1465.                     toast(response);
  1466.                 });
  1467.             }
  1468.         }
  1469.     </script>
  1470. <?php
  1471.     fm_show_footer();
  1472.     exit;
  1473. }
  1474.  
  1475. // copy form POST
  1476. if (isset($_POST['copy']) && !FM_READONLY) {
  1477.     $copy_files = isset($_POST['file']) ? $_POST['file'] : null;
  1478.     if (!is_array($copy_files) || empty($copy_files)) {
  1479.         fm_set_msg(lng('Nothing selected'), 'alert');
  1480.         $FM_PATH = FM_PATH;
  1481.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1482.     }
  1483.  
  1484.     fm_show_header(); // HEADER
  1485.     fm_show_nav_path(FM_PATH); // current path
  1486. ?>
  1487.     <div class="path">
  1488.         <div class="card" data-bs-theme="<?php echo FM_THEME; ?>">
  1489.             <div class="card-header">
  1490.                 <h6><?php echo lng('Copying') ?></h6>
  1491.             </div>
  1492.             <div class="card-body">
  1493.                 <form action="" method="post">
  1494.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1495.                     <input type="hidden" name="finish" value="1">
  1496.                     <?php
  1497.                     foreach ($copy_files as $cf) {
  1498.                         echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
  1499.                     }
  1500.                     ?>
  1501.                     <p class="break-word"><strong><?php echo lng('Files') ?></strong>: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
  1502.                     <p class="break-word"><strong><?php echo lng('SourceFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
  1503.                         <label for="inp_copy_to"><strong><?php echo lng('DestinationFolder') ?></strong>:</label>
  1504.                         <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
  1505.                     </p>
  1506.                     <p class="custom-checkbox custom-control"><input type="checkbox" name="move" value="1" id="js-move-files" class="custom-control-input">
  1507.                         <label for="js-move-files" class="custom-control-label ms-2"><?php echo lng('Move') ?></label>
  1508.                     </p>
  1509.                     <p>
  1510.                         <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-danger"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  1511.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1512.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Copy') ?></button>
  1513.                     </p>
  1514.                 </form>
  1515.             </div>
  1516.         </div>
  1517.     </div>
  1518. <?php
  1519.     fm_show_footer();
  1520.     exit;
  1521. }
  1522.  
  1523. // copy form
  1524. if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
  1525.     $copy = $_GET['copy'];
  1526.     $copy = fm_clean_path($copy);
  1527.     if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
  1528.         fm_set_msg(lng('File not found'), 'error');
  1529.         $FM_PATH = FM_PATH;
  1530.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1531.     }
  1532.  
  1533.     fm_show_header(); // HEADER
  1534.     fm_show_nav_path(FM_PATH); // current path
  1535. ?>
  1536.     <div class="path">
  1537.         <p><b>Copying</b></p>
  1538.         <p class="break-word">
  1539.             <strong>Source path:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
  1540.             <strong>Destination folder:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  1541.         </p>
  1542.         <p>
  1543.             <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> Copy</a></b> &nbsp;
  1544.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1&amp;move=1"><i class="fa fa-check-circle"></i> Move</a></b> &nbsp;
  1545.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="text-danger"><i class="fa fa-times-circle"></i> Cancel</a></b>
  1546.         </p>
  1547.         <p><i><?php echo lng('Select folder') ?></i></p>
  1548.         <ul class="folders break-word">
  1549.             <?php
  1550.             if ($parent !== false) {
  1551.             ?>
  1552.                 <li><a href="?p=<?php echo urlencode($parent) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
  1553.             <?php
  1554.             }
  1555.             foreach ($folders as $f) {
  1556.             ?>
  1557.                 <li>
  1558.                     <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a>
  1559.                 </li>
  1560.             <?php
  1561.             }
  1562.             ?>
  1563.         </ul>
  1564.     </div>
  1565. <?php
  1566.     fm_show_footer();
  1567.     exit;
  1568. }
  1569.  
  1570. if (isset($_GET['settings']) && !FM_READONLY) {
  1571.     fm_show_header(); // HEADER
  1572.     fm_show_nav_path(FM_PATH); // current path
  1573.     global $cfg, $lang, $lang_list;
  1574. ?>
  1575.  
  1576.     <div class="col-md-8 offset-md-2 pt-3">
  1577.         <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  1578.             <h6 class="card-header d-flex justify-content-between">
  1579.                 <span><i class="fa fa-cog"></i> <?php echo lng('Settings') ?></span>
  1580.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel') ?></a>
  1581.             </h6>
  1582.             <div class="card-body">
  1583.                 <form id="js-settings-form" action="" method="post" data-type="ajax" onsubmit="return save_settings(this)">
  1584.                     <input type="hidden" name="type" value="settings" aria-label="hidden" aria-hidden="true">
  1585.                     <div class="form-group row">
  1586.                         <label for="js-language" class="col-sm-3 col-form-label"><?php echo lng('Language') ?></label>
  1587.                         <div class="col-sm-5">
  1588.                             <select class="form-select" id="js-language" name="js-language">
  1589.                                 <?php
  1590.                                 function getSelected($l)
  1591.                                 {
  1592.                                     global $lang;
  1593.                                     return ($lang == $l) ? 'selected' : '';
  1594.                                 }
  1595.                                 foreach ($lang_list as $k => $v) {
  1596.                                     echo "<option value='$k' " . getSelected($k) . ">$v</option>";
  1597.                                 }
  1598.                                 ?>
  1599.                             </select>
  1600.                         </div>
  1601.                     </div>
  1602.                     <div class="mt-3 mb-3 row ">
  1603.                         <label for="js-error-report" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
  1604.                         <div class="col-sm-9">
  1605.                             <div class="form-check form-switch">
  1606.                                 <input class="form-check-input" type="checkbox" role="switch" id="js-error-report" name="js-error-report" value="true" <?php echo $report_errors ? 'checked' : ''; ?> />
  1607.                             </div>
  1608.                         </div>
  1609.                     </div>
  1610.  
  1611.                     <div class="mb-3 row">
  1612.                         <label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
  1613.                         <div class="col-sm-9">
  1614.                             <div class="form-check form-switch">
  1615.                                 <input class="form-check-input" type="checkbox" role="switch" id="js-show-hidden" name="js-show-hidden" value="true" <?php echo $show_hidden_files ? 'checked' : ''; ?> />
  1616.                             </div>
  1617.                         </div>
  1618.                     </div>
  1619.  
  1620.                     <div class="mb-3 row">
  1621.                         <label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
  1622.                         <div class="col-sm-9">
  1623.                             <div class="form-check form-switch">
  1624.                                 <input class="form-check-input" type="checkbox" role="switch" id="js-hide-cols" name="js-hide-cols" value="true" <?php echo $hide_Cols ? 'checked' : ''; ?> />
  1625.                             </div>
  1626.                         </div>
  1627.                     </div>
  1628.  
  1629.                     <div class="mb-3 row">
  1630.                         <label for="js-3-1" class="col-sm-3 col-form-label"><?php echo lng('Theme') ?></label>
  1631.                         <div class="col-sm-5">
  1632.                             <select class="form-select w-100 text-capitalize" id="js-3-0" name="js-theme-3">
  1633.                                 <option value='light' <?php if ($theme == "light") {
  1634.                                                             echo "selected";
  1635.                                                         } ?>>
  1636.                                     <?php echo lng('light') ?>
  1637.                                 </option>
  1638.                                 <option value='dark' <?php if ($theme == "dark") {
  1639.                                                             echo "selected";
  1640.                                                         } ?>>
  1641.                                     <?php echo lng('dark') ?>
  1642.                                 </option>
  1643.                             </select>
  1644.                         </div>
  1645.                     </div>
  1646.  
  1647.                     <div class="mb-3 row">
  1648.                         <div class="col-sm-10">
  1649.                             <button type="submit" class="btn btn-success"> <i class="fa fa-check-circle"></i> <?php echo lng('Save'); ?></button>
  1650.                         </div>
  1651.                     </div>
  1652.  
  1653.                     <small class="text-body-secondary">* <?php echo lng('Sometimes the save action may not work on the first try, so please attempt it again') ?>.</small>
  1654.                 </form>
  1655.             </div>
  1656.         </div>
  1657.     </div>
  1658. <?php
  1659.     fm_show_footer();
  1660.     exit;
  1661. }
  1662.  
  1663. if (isset($_GET['help'])) {
  1664.     fm_show_header(); // HEADER
  1665.     fm_show_nav_path(FM_PATH); // current path
  1666.     global $cfg, $lang;
  1667. ?>
  1668.  
  1669.     <div class="col-md-8 offset-md-2 pt-3">
  1670.         <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  1671.             <h6 class="card-header d-flex justify-content-between">
  1672.                 <span><i class="fa fa-exclamation-circle"></i> <?php echo lng('Help') ?></span>
  1673.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel') ?></a>
  1674.             </h6>
  1675.             <div class="card-body">
  1676.                 <div class="row">
  1677.                     <div class="col-xs-12 col-sm-6">
  1678.                         <p>
  1679.                         <h3><a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="app-v-title"> Tiny File Manager <?php echo VERSION; ?></a></h3>
  1680.                         </p>
  1681.                         <p>Author: PRAŚATH MANİ</p>
  1682.                         <p>Mail Us: <a href="mailto:[email protected]">ccpprogrammers [at] gmail [dot] com</a> </p>
  1683.                     </div>
  1684.                     <div class="col-xs-12 col-sm-6">
  1685.                         <div class="card">
  1686.                             <ul class="list-group list-group-flush">
  1687.                                 <li class="list-group-item"><a href="https://github.com/prasathmani/tinyfilemanager/wiki" target="_blank"><i class="fa fa-question-circle"></i> <?php echo lng('Help Documents') ?> </a> </li>
  1688.                                 <li class="list-group-item"><a href="https://github.com/prasathmani/tinyfilemanager/issues" target="_blank"><i class="fa fa-bug"></i> <?php echo lng('Report Issue') ?></a></li>
  1689.                                 <?php if (!FM_READONLY) { ?>
  1690.                                     <li class="list-group-item"><a href="javascript:show_new_pwd();"><i class="fa fa-lock"></i> <?php echo lng('Generate new password hash') ?></a></li>
  1691.                                 <?php } ?>
  1692.                             </ul>
  1693.                         </div>
  1694.                     </div>
  1695.                 </div>
  1696.                 <div class="row js-new-pwd hidden mt-2">
  1697.                     <div class="col-12">
  1698.                         <form class="form-inline" onsubmit="return new_password_hash(this)" method="POST" action="">
  1699.                             <input type="hidden" name="type" value="pwdhash" aria-label="hidden" aria-hidden="true">
  1700.                             <div class="form-group mb-2">
  1701.                                 <label for="staticEmail2"><?php echo lng('Generate new password hash') ?></label>
  1702.                             </div>
  1703.                             <div class="form-group mx-sm-3 mb-2">
  1704.                                 <label for="inputPassword2" class="sr-only"><?php echo lng('Password') ?></label>
  1705.                                 <input type="text" class="form-control btn-sm" id="inputPassword2" name="inputPassword2" placeholder="<?php echo lng('Password') ?>" required>
  1706.                             </div>
  1707.                             <button type="submit" class="btn btn-success btn-sm mb-2"><?php echo lng('Generate') ?></button>
  1708.                         </form>
  1709.                         <textarea class="form-control" rows="2" readonly id="js-pwd-result"></textarea>
  1710.                     </div>
  1711.                 </div>
  1712.             </div>
  1713.         </div>
  1714.     </div>
  1715. <?php
  1716.     fm_show_footer();
  1717.     exit;
  1718. }
  1719.  
  1720. // file viewer
  1721. if (isset($_GET['view'])) {
  1722.     $file = $_GET['view'];
  1723.     $file = fm_clean_path($file, false);
  1724.     $file = str_replace('/', '', $file);
  1725.     if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
  1726.         fm_set_msg(lng('File not found'), 'error');
  1727.         $FM_PATH = FM_PATH;
  1728.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1729.     }
  1730.  
  1731.     fm_show_header(); // HEADER
  1732.     fm_show_nav_path(FM_PATH); // current path
  1733.  
  1734.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1735.     $file_path = $path . '/' . $file;
  1736.  
  1737.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1738.     $mime_type = fm_get_mime_type($file_path);
  1739.     $filesize_raw = fm_get_size($file_path);
  1740.     $filesize = fm_get_filesize($filesize_raw);
  1741.  
  1742.     $is_zip = false;
  1743.     $is_gzip = false;
  1744.     $is_image = false;
  1745.     $is_audio = false;
  1746.     $is_video = false;
  1747.     $is_text = false;
  1748.     $is_onlineViewer = false;
  1749.  
  1750.     $view_title = 'File';
  1751.     $filenames = false; // for zip
  1752.     $content = ''; // for text
  1753.     $online_viewer = strtolower(FM_DOC_VIEWER);
  1754.  
  1755.     if ($online_viewer && $online_viewer !== 'false' && in_array($ext, fm_get_onlineViewer_exts())) {
  1756.         $is_onlineViewer = true;
  1757.     } elseif ($ext == 'zip' || $ext == 'tar') {
  1758.         $is_zip = true;
  1759.         $view_title = 'Archive';
  1760.         $filenames = fm_get_zif_info($file_path, $ext);
  1761.     } elseif (in_array($ext, fm_get_image_exts())) {
  1762.         $is_image = true;
  1763.         $view_title = 'Image';
  1764.     } elseif (in_array($ext, fm_get_audio_exts())) {
  1765.         $is_audio = true;
  1766.         $view_title = 'Audio';
  1767.     } elseif (in_array($ext, fm_get_video_exts())) {
  1768.         $is_video = true;
  1769.         $view_title = 'Video';
  1770.     } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1771.         $is_text = true;
  1772.         $content = file_get_contents($file_path);
  1773.     }
  1774.  
  1775. ?>
  1776.     <div class="row">
  1777.         <div class="col-12">
  1778.             <ul class="list-group w-50 my-3" data-bs-theme="<?php echo FM_THEME; ?>">
  1779.                 <li class="list-group-item active" aria-current="true"><strong><?php echo lng($view_title) ?>:</strong> <?php echo fm_enc(fm_convert_win($file)) ?></li>
  1780.                 <?php $display_path = fm_get_display_path($file_path); ?>
  1781.                 <li class="list-group-item"><strong><?php echo $display_path['label']; ?>:</strong> <?php echo $display_path['path']; ?></li>
  1782.                 <li class="list-group-item"><strong><?php echo lng('Date Modified') ?>:</strong> <?php echo date(FM_DATETIME_FORMAT, filemtime($file_path)); ?></li>
  1783.                 <li class="list-group-item"><strong><?php echo lng('File size') ?>:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?></li>
  1784.                 <li class="list-group-item"><strong><?php echo lng('MIME-type') ?>:</strong> <?php echo $mime_type ?></li>
  1785.                 <?php
  1786.                 // ZIP info
  1787.                 if (($is_zip || $is_gzip) && $filenames !== false) {
  1788.                     $total_files = 0;
  1789.                     $total_comp = 0;
  1790.                     $total_uncomp = 0;
  1791.                     foreach ($filenames as $fn) {
  1792.                         if (!$fn['folder']) {
  1793.                             $total_files++;
  1794.                         }
  1795.                         $total_comp += $fn['compressed_size'];
  1796.                         $total_uncomp += $fn['filesize'];
  1797.                     }
  1798.                 ?>
  1799.                     <li class="list-group-item"><?php echo lng('Files in archive') ?>: <?php echo $total_files ?></li>
  1800.                     <li class="list-group-item"><?php echo lng('Total size') ?>: <?php echo fm_get_filesize($total_uncomp) ?></li>
  1801.                     <li class="list-group-item"> <?php echo lng('Size in archive') ?>: <?php echo fm_get_filesize($total_comp) ?></li>
  1802.                     <li class="list-group-item"><?php echo lng('Compression') ?>: <?php echo round(($total_comp / max($total_uncomp, 1)) * 100) ?>%</li>
  1803.                 <?php
  1804.                 }
  1805.                 // Image info
  1806.                 if ($is_image) {
  1807.                     $image_size = getimagesize($file_path);
  1808.                     echo '<li class="list-group-item"><strong>' . lng('Image size') . ':</strong> ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '</li>';
  1809.                 }
  1810.                 // Text info
  1811.                 if ($is_text) {
  1812.                     $is_utf8 = fm_is_utf8($content);
  1813.                     if (function_exists('iconv')) {
  1814.                         if (!$is_utf8) {
  1815.                             $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
  1816.                         }
  1817.                     }
  1818.                     echo '<li class="list-group-item"><strong>' . lng('Charset') . ':</strong> ' . ($is_utf8 ? 'utf-8' : '8 bit') . '</li>';
  1819.                 }
  1820.                 ?>
  1821.             </ul>
  1822.             <div class="btn-group btn-group-sm flex-wrap" role="group">
  1823.                 <form method="post" class="d-inline mb-0 btn btn-outline-primary" action="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($file) ?>">
  1824.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1825.                     <button type="submit" class="btn btn-link btn-sm text-decoration-none fw-bold p-0"><i class="fa fa-cloud-download"></i> <?php echo lng('Download') ?></button> &nbsp;
  1826.                 </form>
  1827.                 <?php if (!FM_READONLY): ?>
  1828.                     <a class="fw-bold btn btn-outline-primary" title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($file) ?>" onclick="confirmDailog(event, 1209, '<?php echo lng('Delete') . ' ' . lng('File'); ?>','<?php echo urlencode($file); ?>', this.href);"> <i class="fa fa-trash"></i> Delete</a>
  1829.                 <?php endif; ?>
  1830.                 <a class="fw-bold btn btn-outline-primary" href="<?php echo fm_enc($file_url) ?>" target="_blank"><i class="fa fa-external-link-square"></i> <?php echo lng('Open') ?></a></b>
  1831.                 <?php
  1832.                 // ZIP actions
  1833.                 if (!FM_READONLY && ($is_zip || $is_gzip) && $filenames !== false) {
  1834.                     $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
  1835.                 ?>
  1836.                     <form method="post" class="d-inline btn btn-outline-primary mb-0">
  1837.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1838.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1839.                         <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0 border-0" style="font-size: 14px;"><i class="fa fa-check-circle"></i> <?php echo lng('UnZip') ?></button>
  1840.                     </form>
  1841.                     <form method="post" class="d-inline btn btn-outline-primary mb-0">
  1842.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1843.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1844.                         <input type="hidden" name="tofolder" value="1">
  1845.                         <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0" style="font-size: 14px;" title="UnZip to <?php echo fm_enc($zip_name) ?>"><i class="fa fa-check-circle"></i> <?php echo lng('UnZipToFolder') ?></button>
  1846.                     </form>
  1847.                 <?php
  1848.                 }
  1849.                 if ($is_text && !FM_READONLY) {
  1850.                 ?>
  1851.                     <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>" class="edit-file">
  1852.                         <i class="fa fa-pencil-square"></i> <?php echo lng('Edit') ?>
  1853.                     </a>
  1854.                     <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&env=ace"
  1855.                         class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo lng('AdvancedEditor') ?>
  1856.                     </a>
  1857.                 <?php } ?>
  1858.                 <a class="fw-bold btn btn-outline-primary" href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back') ?></a>
  1859.             </div>
  1860.             <div class="row mt-3">
  1861.                 <?php
  1862.                 if ($is_onlineViewer) {
  1863.                     if ($online_viewer == 'google') {
  1864.                         echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px"></iframe>';
  1865.                     } else if ($online_viewer == 'microsoft') {
  1866.                         echo '<iframe src="https://view.officeapps.live.com/op/embed.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px"></iframe>';
  1867.                     }
  1868.                 } elseif ($is_zip) {
  1869.                     // ZIP content
  1870.                     if ($filenames !== false) {
  1871.                         echo '<code class="maxheight">';
  1872.                         foreach ($filenames as $fn) {
  1873.                             if ($fn['folder']) {
  1874.                                 echo '<b>' . fm_enc($fn['name']) . '</b><br>';
  1875.                             } else {
  1876.                                 echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
  1877.                             }
  1878.                         }
  1879.                         echo '</code>';
  1880.                     } else {
  1881.                         echo '<p>' . lng('Error while fetching archive info') . '</p>';
  1882.                     }
  1883.                 } elseif ($is_image) {
  1884.                     // Image content
  1885.                     if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))) {
  1886.                         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>';
  1887.                     }
  1888.                 } elseif ($is_audio) {
  1889.                     // Audio content
  1890.                     echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
  1891.                 } elseif ($is_video) {
  1892.                     // Video content
  1893.                     echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
  1894.                 } elseif ($is_text) {
  1895.                     if (FM_USE_HIGHLIGHTJS) {
  1896.                         // highlight
  1897.                         $hljs_classes = array(
  1898.                             'shtml' => 'xml',
  1899.                             'htaccess' => 'apache',
  1900.                             'phtml' => 'php',
  1901.                             'lock' => 'json',
  1902.                             'svg' => 'xml',
  1903.                         );
  1904.                         $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
  1905.                         if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
  1906.                             $hljs_class = 'nohighlight';
  1907.                         }
  1908.                         $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
  1909.                     } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
  1910.                         // php highlight
  1911.                         $content = highlight_string($content, true);
  1912.                     } else {
  1913.                         $content = '<pre>' . fm_enc($content) . '</pre>';
  1914.                     }
  1915.                     echo $content;
  1916.                 }
  1917.                 ?>
  1918.             </div>
  1919.         </div>
  1920.     </div>
  1921. <?php
  1922.     fm_show_footer();
  1923.     exit;
  1924. }
  1925.  
  1926. // file editor
  1927. if (isset($_GET['edit']) && !FM_READONLY) {
  1928.     $file = $_GET['edit'];
  1929.     $file = fm_clean_path($file, false);
  1930.     $file = str_replace('/', '', $file);
  1931.     if ($file == '' || !is_file($path . '/' . $file) || !fm_is_exclude_items($file, $path . '/' . $file)) {
  1932.         fm_set_msg(lng('File not found'), 'error');
  1933.         $FM_PATH = FM_PATH;
  1934.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1935.     }
  1936.     $editFile = ' : <i><b>' . $file . '</b></i>';
  1937.     header('X-XSS-Protection:0');
  1938.     fm_show_header(); // HEADER
  1939.     fm_show_nav_path(FM_PATH); // current path
  1940.  
  1941.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1942.     $file_path = $path . '/' . $file;
  1943.  
  1944.     // normal editer
  1945.     $isNormalEditor = true;
  1946.     if (isset($_GET['env'])) {
  1947.         if ($_GET['env'] == "ace") {
  1948.             $isNormalEditor = false;
  1949.         }
  1950.     }
  1951.  
  1952.     // Save File
  1953.     if (isset($_POST['savedata'])) {
  1954.         $writedata = $_POST['savedata'];
  1955.         $fd = fopen($file_path, "w");
  1956.         @fwrite($fd, $writedata);
  1957.         fclose($fd);
  1958.         fm_set_msg(lng('File Saved Successfully'));
  1959.     }
  1960.  
  1961.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1962.     $mime_type = fm_get_mime_type($file_path);
  1963.     $filesize = filesize($file_path);
  1964.     $is_text = false;
  1965.     $content = ''; // for text
  1966.  
  1967.     if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1968.         $is_text = true;
  1969.         $content = file_get_contents($file_path);
  1970.     }
  1971.  
  1972. ?>
  1973.     <div class="path">
  1974.         <div class="row">
  1975.             <div class="col-xs-12 col-sm-5 col-lg-6 pt-1">
  1976.                 <div class="btn-toolbar" role="toolbar">
  1977.                     <?php if (!$isNormalEditor) { ?>
  1978.                         <div class="btn-group js-ace-toolbar">
  1979.                             <button data-cmd="none" data-option="fullscreen" class="btn btn-sm btn-outline-secondary" id="js-ace-fullscreen" title="<?php echo lng('Fullscreen') ?>"><i class="fa fa-expand" title="<?php echo lng('Fullscreen') ?>"></i></button>
  1980.                             <button data-cmd="find" class="btn btn-sm btn-outline-secondary" id="js-ace-search" title="<?php echo lng('Search') ?>"><i class="fa fa-search" title="<?php echo lng('Search') ?>"></i></button>
  1981.                             <button data-cmd="undo" class="btn btn-sm btn-outline-secondary" id="js-ace-undo" title="<?php echo lng('Undo') ?>"><i class="fa fa-undo" title="<?php echo lng('Undo') ?>"></i></button>
  1982.                             <button data-cmd="redo" class="btn btn-sm btn-outline-secondary" id="js-ace-redo" title="<?php echo lng('Redo') ?>"><i class="fa fa-repeat" title="<?php echo lng('Redo') ?>"></i></button>
  1983.                             <button data-cmd="none" data-option="wrap" class="btn btn-sm btn-outline-secondary" id="js-ace-wordWrap" title="<?php echo lng('Word Wrap') ?>"><i class="fa fa-text-width" title="<?php echo lng('Word Wrap') ?>"></i></button>
  1984.                             <select id="js-ace-mode" data-type="mode" title="<?php echo lng('Select Document Type') ?>" class="btn-outline-secondary border-start-0 d-none d-md-block">
  1985.                                 <option>-- <?php echo lng('Select Mode') ?> --</option>
  1986.                             </select>
  1987.                             <select id="js-ace-theme" data-type="theme" title="<?php echo lng('Select Theme') ?>" class="btn-outline-secondary border-start-0 d-none d-lg-block">
  1988.                                 <option>-- <?php echo lng('Select Theme') ?> --</option>
  1989.                             </select>
  1990.                             <select id="js-ace-fontSize" data-type="fontSize" title="<?php echo lng('Select Font Size') ?>" class="btn-outline-secondary border-start-0 d-none d-lg-block">
  1991.                                 <option>-- <?php echo lng('Select Font Size') ?> --</option>
  1992.                             </select>
  1993.                         </div>
  1994.                     <?php } ?>
  1995.                 </div>
  1996.             </div>
  1997.             <div class="edit-file-actions col-xs-12 col-sm-7 col-lg-6 text-end pt-1">
  1998.                 <div class="btn-group">
  1999.                     <a title=" <?php echo lng('Back') ?>" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> <?php echo lng('Back') ?></a>
  2000.                     <a title="<?php echo lng('BackUp') ?>" class="btn btn-sm btn-outline-primary" href="javascript:void(0);" onclick="backup('<?php echo urlencode(trim(FM_PATH)) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-database"></i> <?php echo lng('BackUp') ?></a>
  2001.                     <?php if ($is_text) { ?>
  2002.                         <?php if ($isNormalEditor) { ?>
  2003.                             <a title="Advanced" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&amp;env=ace"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?></a>
  2004.                             <button type="button" class="btn btn-sm btn-success" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'nrl')"><i class="fa fa-floppy-o"></i> Save
  2005.                             </button>
  2006.                         <?php } else { ?>
  2007.                             <a title="Plain Editor" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> <?php echo lng('NormalEditor') ?></a>
  2008.                             <button type="button" class="btn btn-sm btn-success" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'ace')"><i class="fa fa-floppy-o"></i> <?php echo lng('Save') ?>
  2009.                             </button>
  2010.                         <?php } ?>
  2011.                     <?php } ?>
  2012.                 </div>
  2013.             </div>
  2014.         </div>
  2015.         <?php
  2016.         if ($is_text && $isNormalEditor) {
  2017.             echo '<textarea class="mt-2" id="normal-editor" rows="33" cols="120" style="width: 99.5%;">' . htmlspecialchars($content) . '</textarea>';
  2018.             echo '<script>document.addEventListener("keydown", function(e) {if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)  && e.keyCode == 83) { e.preventDefault();edit_save(this,"nrl");}}, false);</script>';
  2019.         } elseif ($is_text) {
  2020.             echo '<div id="editor" contenteditable="true">' . htmlspecialchars($content) . '</div>';
  2021.         } else {
  2022.             fm_set_msg(lng('FILE EXTENSION IS NOT SUPPORTED'), 'error');
  2023.         }
  2024.         ?>
  2025.     </div>
  2026. <?php
  2027.     fm_show_footer();
  2028.     exit;
  2029. }
  2030.  
  2031. // chmod (not for Windows)
  2032. if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  2033.     $file = $_GET['chmod'];
  2034.     $file = fm_clean_path($file);
  2035.     $file = str_replace('/', '', $file);
  2036.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  2037.         fm_set_msg(lng('File not found'), 'error');
  2038.         $FM_PATH = FM_PATH;
  2039.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  2040.     }
  2041.  
  2042.     fm_show_header(); // HEADER
  2043.     fm_show_nav_path(FM_PATH); // current path
  2044.  
  2045.     $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
  2046.     $file_path = $path . '/' . $file;
  2047.  
  2048.     $mode = fileperms($path . '/' . $file);
  2049. ?>
  2050.     <div class="path">
  2051.         <div class="card mb-2" data-bs-theme="<?php echo FM_THEME; ?>">
  2052.             <h6 class="card-header">
  2053.                 <?php echo lng('ChangePermissions') ?>
  2054.             </h6>
  2055.             <div class="card-body">
  2056.                 <p class="card-text">
  2057.                     <?php $display_path = fm_get_display_path($file_path); ?>
  2058.                     <?php echo $display_path['label']; ?>: <?php echo $display_path['path']; ?><br>
  2059.                 </p>
  2060.                 <form action="" method="post">
  2061.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  2062.                     <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
  2063.  
  2064.                     <table class="table compact-table" data-bs-theme="<?php echo FM_THEME; ?>">
  2065.                         <tr>
  2066.                             <td></td>
  2067.                             <td><b><?php echo lng('Owner') ?></b></td>
  2068.                             <td><b><?php echo lng('Group') ?></b></td>
  2069.                             <td><b><?php echo lng('Other') ?></b></td>
  2070.                         </tr>
  2071.                         <tr>
  2072.                             <td style="text-align: right"><b><?php echo lng('Read') ?></b></td>
  2073.                             <td><label><input type="checkbox" name="ur" value="1" <?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
  2074.                             <td><label><input type="checkbox" name="gr" value="1" <?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
  2075.                             <td><label><input type="checkbox" name="or" value="1" <?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
  2076.                         </tr>
  2077.                         <tr>
  2078.                             <td style="text-align: right"><b><?php echo lng('Write') ?></b></td>
  2079.                             <td><label><input type="checkbox" name="uw" value="1" <?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
  2080.                             <td><label><input type="checkbox" name="gw" value="1" <?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
  2081.                             <td><label><input type="checkbox" name="ow" value="1" <?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
  2082.                         </tr>
  2083.                         <tr>
  2084.                             <td style="text-align: right"><b><?php echo lng('Execute') ?></b></td>
  2085.                             <td><label><input type="checkbox" name="ux" value="1" <?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
  2086.                             <td><label><input type="checkbox" name="gx" value="1" <?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
  2087.                             <td><label><input type="checkbox" name="ox" value="1" <?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
  2088.                         </tr>
  2089.                     </table>
  2090.  
  2091.                     <p>
  2092.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  2093.                         <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-primary"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  2094.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Change') ?></button>
  2095.                     </p>
  2096.                 </form>
  2097.             </div>
  2098.         </div>
  2099.     </div>
  2100. <?php
  2101.     fm_show_footer();
  2102.     exit;
  2103. }
  2104.  
  2105. // --- TINYFILEMANAGER MAIN ---
  2106. fm_show_header(); // HEADER
  2107. fm_show_nav_path(FM_PATH); // current path
  2108.  
  2109. // show alert messages
  2110. fm_show_message();
  2111.  
  2112. $num_files = count($files);
  2113. $num_folders = count($folders);
  2114. $all_files_size = 0;
  2115. ?>
  2116. <form action="" method="post" class="pt-3">
  2117.     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  2118.     <input type="hidden" name="group" value="1">
  2119.     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  2120.     <div class="table-responsive">
  2121.         <table class="table table-bordered table-hover table-sm" id="main-table" data-bs-theme="<?php echo FM_THEME; ?>">
  2122.             <thead class="thead-white">
  2123.                 <tr>
  2124.                     <?php if (!FM_READONLY): ?>
  2125.                         <th style="width:3%" class="custom-checkbox-header">
  2126.                             <div class="custom-control custom-checkbox">
  2127.                                 <input type="checkbox" class="custom-control-input" id="js-select-all-items" onclick="checkbox_toggle()">
  2128.                                 <label class="custom-control-label" for="js-select-all-items"></label>
  2129.                             </div>
  2130.                         </th><?php endif; ?>
  2131.                     <th><?php echo lng('Name') ?></th>
  2132.                     <th><?php echo lng('Size') ?></th>
  2133.                     <th><?php echo lng('Modified') ?></th>
  2134.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2135.                         <th><?php echo lng('Perms') ?></th>
  2136.                         <th><?php echo lng('Owner') ?></th><?php endif; ?>
  2137.                     <th><?php echo lng('Actions') ?></th>
  2138.                 </tr>
  2139.             </thead>
  2140.             <?php
  2141.             // link to parent folder
  2142.             if ($parent !== false) {
  2143.             ?>
  2144.                 <tr><?php if (!FM_READONLY): ?>
  2145.                         <td class="nosort"></td><?php endif; ?>
  2146.                     <td class="border-0" data-sort><a href="?p=<?php echo urlencode($parent) ?>"><i class="fa fa-chevron-circle-left go-back"></i> ..</a></td>
  2147.                     <td class="border-0" data-order></td>
  2148.                     <td class="border-0" data-order></td>
  2149.                     <td class="border-0"></td>
  2150.                     <?php if (!FM_IS_WIN && !$hide_Cols) { ?>
  2151.                         <td class="border-0"></td>
  2152.                         <td class="border-0"></td>
  2153.                     <?php } ?>
  2154.                 </tr>
  2155.             <?php
  2156.             }
  2157.             $ii = 3399;
  2158.             foreach ($folders as $f) {
  2159.                 $is_link = is_link($path . '/' . $f);
  2160.                 $img = $is_link ? 'icon-link_folder' : 'fa fa-folder-o';
  2161.                 $modif_raw = filemtime($path . '/' . $f);
  2162.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2163.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2164.                 $filesize_raw = "";
  2165.                 $filesize = lng('Folder');
  2166.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2167.                 $owner = array('name' => '?');
  2168.                 $group = array('name' => '?');
  2169.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2170.                     try {
  2171.                         $owner_id = fileowner($path . '/' . $f);
  2172.                         if ($owner_id != 0) {
  2173.                             $owner_info = posix_getpwuid($owner_id);
  2174.                             if ($owner_info) {
  2175.                                 $owner =  $owner_info;
  2176.                             }
  2177.                         }
  2178.                         $group_id = filegroup($path . '/' . $f);
  2179.                         $group_info = posix_getgrgid($group_id);
  2180.                         if ($group_info) {
  2181.                             $group =  $group_info;
  2182.                         }
  2183.                     } catch (Exception $e) {
  2184.                         error_log("exception:" . $e->getMessage());
  2185.                     }
  2186.                 }
  2187.             ?>
  2188.                 <tr>
  2189.                     <?php if (!FM_READONLY): ?>
  2190.                         <td class="custom-checkbox-td">
  2191.                             <div class="custom-control custom-checkbox">
  2192.                                 <input type="checkbox" class="custom-control-input" id="<?php echo $ii ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2193.                                 <label class="custom-control-label" for="<?php echo $ii ?>"></label>
  2194.                             </div>
  2195.                         </td>
  2196.                     <?php endif; ?>
  2197.                     <td data-sort=<?php echo fm_convert_win(fm_enc($f)) ?>>
  2198.                         <div class="filename">
  2199.                             <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?></a>
  2200.                             <?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  2201.                         </div>
  2202.                     </td>
  2203.                     <td data-order="a-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>">
  2204.                         <?php echo $filesize; ?>
  2205.                     </td>
  2206.                     <td data-order="a-<?php echo $date_sorting; ?>"><?php echo $modif ?></td>
  2207.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2208.                         <td>
  2209.                             <?php if (!FM_READONLY): ?><a title="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; ?>
  2210.                         </td>
  2211.                         <td>
  2212.                             <?php echo $owner['name'] . ':' . $group['name'] ?>
  2213.                         </td>
  2214.                     <?php endif; ?>
  2215.                     <td class="inline-actions"><?php if (!FM_READONLY): ?>
  2216.                             <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, '1028','<?php echo lng('Delete') . ' ' . lng('Folder'); ?>','<?php echo urlencode($f) ?>', this.href);"> <i class="fa fa-trash-o" aria-hidden="true"></i></a>
  2217.                             <a title="<?php echo lng('Rename') ?>" href="#" onclick="rename('<?php echo fm_enc(addslashes(FM_PATH)) ?>', '<?php echo fm_enc(addslashes($f)) ?>');return false;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
  2218.                             <a title="<?php echo lng('CopyTo') ?>..." href="?p=&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
  2219.                         <?php endif; ?>
  2220.                         <a title="<?php echo lng('DirectLink') ?>" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f . '/') ?>" target="_blank"><i class="fa fa-link" aria-hidden="true"></i></a>
  2221.                     </td>
  2222.                 </tr>
  2223.             <?php
  2224.                 flush();
  2225.                 $ii++;
  2226.             }
  2227.             $ik = 8002;
  2228.             foreach ($files as $f) {
  2229.                 $is_link = is_link($path . '/' . $f);
  2230.                 $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
  2231.                 $modif_raw = filemtime($path . '/' . $f);
  2232.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2233.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2234.                 $filesize_raw = fm_get_size($path . '/' . $f);
  2235.                 $filesize = fm_get_filesize($filesize_raw);
  2236.                 $filelink = '?p=' . urlencode(FM_PATH) . '&amp;view=' . urlencode($f);
  2237.                 $all_files_size += $filesize_raw;
  2238.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2239.                 $owner = array('name' => '?');
  2240.                 $group = array('name' => '?');
  2241.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2242.                     try {
  2243.                         $owner_id = fileowner($path . '/' . $f);
  2244.                         if ($owner_id != 0) {
  2245.                             $owner_info = posix_getpwuid($owner_id);
  2246.                             if ($owner_info) {
  2247.                                 $owner =  $owner_info;
  2248.                             }
  2249.                         }
  2250.                         $group_id = filegroup($path . '/' . $f);
  2251.                         $group_info = posix_getgrgid($group_id);
  2252.                         if ($group_info) {
  2253.                             $group =  $group_info;
  2254.                         }
  2255.                     } catch (Exception $e) {
  2256.                         error_log("exception:" . $e->getMessage());
  2257.                     }
  2258.                 }
  2259.             ?>
  2260.                 <tr>
  2261.                     <?php if (!FM_READONLY): ?>
  2262.                         <td class="custom-checkbox-td">
  2263.                             <div class="custom-control custom-checkbox">
  2264.                                 <input type="checkbox" class="custom-control-input" id="<?php echo $ik ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2265.                                 <label class="custom-control-label" for="<?php echo $ik ?>"></label>
  2266.                             </div>
  2267.                         </td><?php endif; ?>
  2268.                     <td data-sort=<?php echo fm_enc($f) ?>>
  2269.                         <div class="filename">
  2270.                             <?php
  2271.                             if (in_array(strtolower(pathinfo($f, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))): ?>
  2272.                                 <?php $imagePreview = fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f); ?>
  2273.                                 <a href="<?php echo $filelink ?>" data-preview-image="<?php echo $imagePreview ?>" title="<?php echo fm_enc($f) ?>">
  2274.                                 <?php else: ?>
  2275.                                     <a href="<?php echo $filelink ?>" title="<?php echo $f ?>">
  2276.                                     <?php endif; ?>
  2277.                                     <i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?>
  2278.                                     </a>
  2279.                                     <?php echo ($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  2280.                         </div>
  2281.                     </td>
  2282.                     <td data-order="b-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>"><span title="<?php printf('%s bytes', $filesize_raw) ?>">
  2283.                             <?php echo $filesize; ?>
  2284.                         </span></td>
  2285.                     <td data-order="b-<?php echo $date_sorting; ?>"><?php echo $modif ?></td>
  2286.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2287.                         <td><?php if (!FM_READONLY): ?><a title="<?php echo '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; ?>
  2288.                         </td>
  2289.                         <td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
  2290.                     <?php endif; ?>
  2291.                     <td class="inline-actions">
  2292.                         <?php if (!FM_READONLY): ?>
  2293.                             <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1209, '<?php echo lng('Delete') . ' ' . lng('File'); ?>','<?php echo urlencode($f); ?>', this.href);"> <i class="fa fa-trash-o"></i></a>
  2294.                             <a title="<?php echo lng('Rename') ?>" href="#" onclick="rename('<?php echo fm_enc(addslashes(FM_PATH)) ?>', '<?php echo fm_enc(addslashes($f)) ?>');return false;"><i class="fa fa-pencil-square-o"></i></a>
  2295.                             <a title="<?php echo lng('CopyTo') ?>..."
  2296.                                 href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
  2297.                         <?php endif; ?>
  2298.                         <a title="<?php echo lng('DirectLink') ?>" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f) ?>" target="_blank"><i class="fa fa-link"></i></a>
  2299.                         <a title="<?php echo lng('Download') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1211, '<?php echo lng('Download'); ?>','<?php echo urlencode($f); ?>', this.href);"><i class="fa fa-download"></i></a>
  2300.                     </td>
  2301.                 </tr>
  2302.             <?php
  2303.                 flush();
  2304.                 $ik++;
  2305.             }
  2306.  
  2307.             if (empty($folders) && empty($files)) { ?>
  2308.                 <tfoot>
  2309.                     <tr><?php if (!FM_READONLY): ?>
  2310.                             <td></td><?php endif; ?>
  2311.                         <td colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>"><em><?php echo lng('Folder is empty') ?></em></td>
  2312.                     </tr>
  2313.                 </tfoot>
  2314.             <?php
  2315.             } else { ?>
  2316.                 <tfoot>
  2317.                     <tr>
  2318.                         <td class="gray fs-7" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' : '7') : (FM_READONLY ? '4' : '5') ?>">
  2319.                             <?php echo lng('FullSize') . ': <span class="badge text-bg-light border-radius-0">' . fm_get_filesize($all_files_size) . '</span>' ?>
  2320.                             <?php echo lng('File') . ': <span class="badge text-bg-light border-radius-0">' . $num_files . '</span>' ?>
  2321.                             <?php echo lng('Folder') . ': <span class="badge text-bg-light border-radius-0">' . $num_folders . '</span>' ?>
  2322.                         </td>
  2323.                     </tr>
  2324.                 </tfoot>
  2325.             <?php } ?>
  2326.         </table>
  2327.     </div>
  2328.  
  2329.     <div class="row">
  2330.         <?php if (!FM_READONLY): ?>
  2331.             <div class="col-xs-12 col-sm-9">
  2332.                 <div class="btn-group flex-wrap" data-toggle="buttons" role="toolbar">
  2333.                     <a href="#/select-all" class="btn btn-small btn-outline-primary btn-2" onclick="select_all();return false;"><i class="fa fa-check-square"></i> <?php echo lng('SelectAll') ?> </a>
  2334.                     <a href="#/unselect-all" class="btn btn-small btn-outline-primary btn-2" onclick="unselect_all();return false;"><i class="fa fa-window-close"></i> <?php echo lng('UnSelectAll') ?> </a>
  2335.                     <a href="#/invert-all" class="btn btn-small btn-outline-primary btn-2" onclick="invert_all();return false;"><i class="fa fa-th-list"></i> <?php echo lng('InvertSelection') ?> </a>
  2336.                     <input type="submit" class="hidden" name="delete" id="a-delete" value="Delete" onclick="return confirm('<?php echo lng('Delete selected files and folders?'); ?>')">
  2337.                     <a href="javascript:document.getElementById('a-delete').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-trash"></i> <?php echo lng('Delete') ?> </a>
  2338.                     <input type="submit" class="hidden" name="zip" id="a-zip" value="zip" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2339.                     <a href="javascript:document.getElementById('a-zip').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-file-archive-o"></i> <?php echo lng('Zip') ?> </a>
  2340.                     <input type="submit" class="hidden" name="tar" id="a-tar" value="tar" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2341.                     <a href="javascript:document.getElementById('a-tar').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-file-archive-o"></i> <?php echo lng('Tar') ?> </a>
  2342.                     <input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
  2343.                     <a href="javascript:document.getElementById('a-copy').click();" class="btn btn-small btn-outline-primary btn-2"><i class="fa fa-files-o"></i> <?php echo lng('Copy') ?> </a>
  2344.                 </div>
  2345.             </div>
  2346.             <div class="col-3 d-none d-sm-block"><a href="https://tinyfilemanager.github.io" target="_blank" class="float-right text-muted">Tiny File Manager <?php echo VERSION; ?></a></div>
  2347.         <?php else: ?>
  2348.             <div class="col-12"><a href="https://tinyfilemanager.github.io" target="_blank" class="float-right text-muted">Tiny File Manager <?php echo VERSION; ?></a></div>
  2349.         <?php endif; ?>
  2350.     </div>
  2351. </form>
  2352.  
  2353. <?php
  2354. fm_show_footer();
  2355.  
  2356. // --- END HTML ---
  2357.  
  2358. // Functions
  2359.  
  2360. /**
  2361.  * It prints the css/js files into html
  2362.  * @param key The key of the external file to print.
  2363.  */
  2364. function print_external($key)
  2365. {
  2366.     global $external;
  2367.  
  2368.     if (!array_key_exists($key, $external)) {
  2369.         // throw new Exception('Key missing in external: ' . key);
  2370.         echo "<!-- EXTERNAL: MISSING KEY $key -->";
  2371.         return;
  2372.     }
  2373.  
  2374.     echo "$external[$key]";
  2375. }
  2376.  
  2377. /**
  2378.  * Verify CSRF TOKEN and remove after certified
  2379.  * @param string $token
  2380.  * @return bool
  2381.  */
  2382. function verifyToken($token)
  2383. {
  2384.     if (hash_equals($_SESSION['token'], $token)) {
  2385.         return true;
  2386.     }
  2387.     return false;
  2388. }
  2389.  
  2390. /**
  2391.  * Delete  file or folder (recursively)
  2392.  * @param string $path
  2393.  * @return bool
  2394.  */
  2395. function fm_rdelete($path)
  2396. {
  2397.     if (is_link($path)) {
  2398.         return unlink($path);
  2399.     } elseif (is_dir($path)) {
  2400.         $objects = scandir($path);
  2401.         $ok = true;
  2402.         if (is_array($objects)) {
  2403.             foreach ($objects as $file) {
  2404.                 if ($file != '.' && $file != '..') {
  2405.                     if (!fm_rdelete($path . '/' . $file)) {
  2406.                         $ok = false;
  2407.                     }
  2408.                 }
  2409.             }
  2410.         }
  2411.         return ($ok) ? rmdir($path) : false;
  2412.     } elseif (is_file($path)) {
  2413.         return unlink($path);
  2414.     }
  2415.     return false;
  2416. }
  2417.  
  2418. /**
  2419.  * Recursive chmod
  2420.  * @param string $path
  2421.  * @param int $filemode
  2422.  * @param int $dirmode
  2423.  * @return bool
  2424.  * @todo Will use in mass chmod
  2425.  */
  2426. function fm_rchmod($path, $filemode, $dirmode)
  2427. {
  2428.     if (is_dir($path)) {
  2429.         if (!chmod($path, $dirmode)) {
  2430.             return false;
  2431.         }
  2432.         $objects = scandir($path);
  2433.         if (is_array($objects)) {
  2434.             foreach ($objects as $file) {
  2435.                 if ($file != '.' && $file != '..') {
  2436.                     if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
  2437.                         return false;
  2438.                     }
  2439.                 }
  2440.             }
  2441.         }
  2442.         return true;
  2443.     } elseif (is_link($path)) {
  2444.         return true;
  2445.     } elseif (is_file($path)) {
  2446.         return chmod($path, $filemode);
  2447.     }
  2448.     return false;
  2449. }
  2450.  
  2451. /**
  2452.  * Check the file extension which is allowed or not
  2453.  * @param string $filename
  2454.  * @return bool
  2455.  */
  2456. function fm_is_valid_ext($filename)
  2457. {
  2458.     $allowed = (FM_FILE_EXTENSION) ? explode(',', FM_FILE_EXTENSION) : false;
  2459.  
  2460.     $ext = pathinfo($filename, PATHINFO_EXTENSION);
  2461.     $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  2462.  
  2463.     return ($isFileAllowed) ? true : false;
  2464. }
  2465.  
  2466. /**
  2467.  * Safely rename
  2468.  * @param string $old
  2469.  * @param string $new
  2470.  * @return bool|null
  2471.  */
  2472. function fm_rename($old, $new)
  2473. {
  2474.     $isFileAllowed = fm_is_valid_ext($new);
  2475.  
  2476.     if (!is_dir($old)) {
  2477.         if (!$isFileAllowed) return false;
  2478.     }
  2479.  
  2480.     return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
  2481. }
  2482.  
  2483. /**
  2484.  * Copy file or folder (recursively).
  2485.  * @param string $path
  2486.  * @param string $dest
  2487.  * @param bool $upd Update files
  2488.  * @param bool $force Create folder with same names instead file
  2489.  * @return bool
  2490.  */
  2491. function fm_rcopy($path, $dest, $upd = true, $force = true)
  2492. {
  2493.     if (!is_dir($path) && !is_file($path)) {
  2494.         return false;
  2495.     }
  2496.  
  2497.     if (is_dir($path)) {
  2498.         if (!fm_mkdir($dest, $force)) {
  2499.             return false;
  2500.         }
  2501.  
  2502.         $objects = array_diff(scandir($path), ['.', '..']);
  2503.  
  2504.         foreach ($objects as $file) {
  2505.             if (!fm_rcopy("$path/$file", "$dest/$file", $upd, $force)) {
  2506.                 return false;
  2507.             }
  2508.         }
  2509.  
  2510.         return true;
  2511.     }
  2512.  
  2513.     // Handle file copying
  2514.     return fm_copy($path, $dest, $upd);
  2515. }
  2516.  
  2517.  
  2518. /**
  2519.  * Safely create folder
  2520.  * @param string $dir
  2521.  * @param bool $force
  2522.  * @return bool
  2523.  */
  2524. function fm_mkdir($dir, $force)
  2525. {
  2526.     if (file_exists($dir)) {
  2527.         if (is_dir($dir)) {
  2528.             return $dir;
  2529.         } elseif (!$force) {
  2530.             return false;
  2531.         }
  2532.         unlink($dir);
  2533.     }
  2534.     return mkdir($dir, 0777, true);
  2535. }
  2536.  
  2537. /**
  2538.  * Safely copy file
  2539.  * @param string $f1
  2540.  * @param string $f2
  2541.  * @param bool $upd Indicates if file should be updated with new content
  2542.  * @return bool
  2543.  */
  2544. function fm_copy($f1, $f2, $upd)
  2545. {
  2546.     $time1 = filemtime($f1);
  2547.     if (file_exists($f2)) {
  2548.         $time2 = filemtime($f2);
  2549.         if ($time2 >= $time1 && $upd) {
  2550.             return false;
  2551.         }
  2552.     }
  2553.     $ok = copy($f1, $f2);
  2554.     if ($ok) {
  2555.         touch($f2, $time1);
  2556.     }
  2557.     return $ok;
  2558. }
  2559.  
  2560. /**
  2561.  * Get mime type
  2562.  * @param string $file_path
  2563.  * @return mixed|string
  2564.  */
  2565. function fm_get_mime_type($file_path)
  2566. {
  2567.     if (function_exists('finfo_open')) {
  2568.         $finfo = finfo_open(FILEINFO_MIME_TYPE);
  2569.         $mime = finfo_file($finfo, $file_path);
  2570.         finfo_close($finfo);
  2571.         return $mime;
  2572.     } elseif (function_exists('mime_content_type')) {
  2573.         return mime_content_type($file_path);
  2574.     } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
  2575.         $file = escapeshellarg($file_path);
  2576.         $mime = shell_exec('file -bi ' . $file);
  2577.         return $mime;
  2578.     } else {
  2579.         return '--';
  2580.     }
  2581. }
  2582.  
  2583. /**
  2584.  * HTTP Redirect
  2585.  * @param string $url
  2586.  * @param int $code
  2587.  */
  2588. function fm_redirect($url, $code = 302)
  2589. {
  2590.     header('Location: ' . $url, true, $code);
  2591.     exit;
  2592. }
  2593.  
  2594. /**
  2595.  * Path traversal prevention and clean the url
  2596.  * It replaces (consecutive) occurrences of / and \\ with whatever is in DIRECTORY_SEPARATOR, and processes /. and /.. fine.
  2597.  * @param $path
  2598.  * @return string
  2599.  */
  2600. function get_absolute_path($path)
  2601. {
  2602.     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
  2603.     $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
  2604.     $absolutes = array();
  2605.     foreach ($parts as $part) {
  2606.         if ('.' == $part) continue;
  2607.         if ('..' == $part) {
  2608.             array_pop($absolutes);
  2609.         } else {
  2610.             $absolutes[] = $part;
  2611.         }
  2612.     }
  2613.     return implode(DIRECTORY_SEPARATOR, $absolutes);
  2614. }
  2615.  
  2616. /**
  2617.  * Clean path
  2618.  * @param string $path
  2619.  * @return string
  2620.  */
  2621. function fm_clean_path($path, $trim = true)
  2622. {
  2623.     $path = $trim ? trim($path) : $path;
  2624.     $path = trim($path, '\\/');
  2625.     $path = str_replace(array('../', '..\\'), '', $path);
  2626.     $path =  get_absolute_path($path);
  2627.     if ($path == '..') {
  2628.         $path = '';
  2629.     }
  2630.     return str_replace('\\', '/', $path);
  2631. }
  2632.  
  2633. /**
  2634.  * Get parent path
  2635.  * @param string $path
  2636.  * @return bool|string
  2637.  */
  2638. function fm_get_parent_path($path)
  2639. {
  2640.     $path = fm_clean_path($path);
  2641.     if ($path != '') {
  2642.         $array = explode('/', $path);
  2643.         if (count($array) > 1) {
  2644.             $array = array_slice($array, 0, -1);
  2645.             return implode('/', $array);
  2646.         }
  2647.         return '';
  2648.     }
  2649.     return false;
  2650. }
  2651.  
  2652. function fm_get_display_path($file_path)
  2653. {
  2654.     global $path_display_mode, $root_path, $root_url;
  2655.     switch ($path_display_mode) {
  2656.         case 'relative':
  2657.             return array(
  2658.                 'label' => 'Path',
  2659.                 'path' => fm_enc(fm_convert_win(str_replace($root_path, '', $file_path)))
  2660.             );
  2661.         case 'host':
  2662.             $relative_path = str_replace($root_path, '', $file_path);
  2663.             return array(
  2664.                 'label' => 'Host Path',
  2665.                 'path' => fm_enc(fm_convert_win('/' . $root_url . '/' . ltrim(str_replace('\\', '/', $relative_path), '/')))
  2666.             );
  2667.         case 'full':
  2668.         default:
  2669.             return array(
  2670.                 'label' => 'Full Path',
  2671.                 'path' => fm_enc(fm_convert_win($file_path))
  2672.             );
  2673.     }
  2674. }
  2675.  
  2676. /**
  2677.  * Check file is in exclude list
  2678.  * @param string $name The name of the file/folder
  2679.  * @param string $path The full path of the file/folder
  2680.  * @return bool
  2681.  */
  2682. function fm_is_exclude_items($name, $path)
  2683. {
  2684.     $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
  2685.     if (isset($exclude_items) and sizeof($exclude_items)) {
  2686.         unset($exclude_items);
  2687.     }
  2688.  
  2689.     $exclude_items = FM_EXCLUDE_ITEMS;
  2690.     if (version_compare(PHP_VERSION, '7.0.0', '<')) {
  2691.         $exclude_items = unserialize($exclude_items);
  2692.     }
  2693.     if (!in_array($name, $exclude_items) && !in_array("*.$ext", $exclude_items) && !in_array($path, $exclude_items)) {
  2694.         return true;
  2695.     }
  2696.     return false;
  2697. }
  2698.  
  2699. /**
  2700.  * get language translations from json file
  2701.  * @param int $tr
  2702.  * @return array
  2703.  */
  2704. function fm_get_translations($tr)
  2705. {
  2706.     try {
  2707.         $content = @file_get_contents('translation.json');
  2708.         if ($content !== FALSE) {
  2709.             $lng = json_decode($content, TRUE);
  2710.             global $lang_list;
  2711.             foreach ($lng["language"] as $key => $value) {
  2712.                 $code = $value["code"];
  2713.                 $lang_list[$code] = $value["name"];
  2714.                 if ($tr)
  2715.                     $tr[$code] = $value["translation"];
  2716.             }
  2717.             return $tr;
  2718.         }
  2719.     } catch (Exception $e) {
  2720.         echo $e;
  2721.     }
  2722. }
  2723.  
  2724. /**
  2725.  * @param string $file
  2726.  * Recover all file sizes larger than > 2GB.
  2727.  * Works on php 32bits and 64bits and supports linux
  2728.  * @return int|string
  2729.  */
  2730. function fm_get_size($file)
  2731. {
  2732.     static $iswin = null;
  2733.     static $isdarwin = null;
  2734.     static $exec_works = null;
  2735.  
  2736.     // Set static variables once
  2737.     if ($iswin === null) {
  2738.         $iswin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
  2739.         $isdarwin = strtoupper(PHP_OS) === 'DARWIN';
  2740.         $exec_works = function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') === 'EXEC';
  2741.     }
  2742.  
  2743.     // Attempt shell command if exec is available
  2744.     if ($exec_works) {
  2745.         $arg = escapeshellarg($file);
  2746.         $cmd = $iswin ? "for %F in (\"$file\") do @echo %~zF" : ($isdarwin ? "stat -f%z $arg" : "stat -c%s $arg");
  2747.         @exec($cmd, $output);
  2748.  
  2749.         if (!empty($output) && ctype_digit($size = trim(implode("\n", $output)))) {
  2750.             return $size;
  2751.         }
  2752.     }
  2753.  
  2754.     // Attempt Windows COM interface for Windows systems
  2755.     if ($iswin && class_exists('COM')) {
  2756.         try {
  2757.             $fsobj = new COM('Scripting.FileSystemObject');
  2758.             $f = $fsobj->GetFile(realpath($file));
  2759.             if (ctype_digit($size = $f->Size)) {
  2760.                 return $size;
  2761.             }
  2762.         } catch (Exception $e) {
  2763.             // COM failed, fallback to filesize
  2764.         }
  2765.     }
  2766.  
  2767.     // Default to PHP's filesize function
  2768.     return filesize($file);
  2769. }
  2770.  
  2771.  
  2772. /**
  2773.  * Get nice filesize
  2774.  * @param int $size
  2775.  * @return string
  2776.  */
  2777. function fm_get_filesize($size)
  2778. {
  2779.     $size = (float) $size;
  2780.     $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  2781.     $power = ($size > 0) ? floor(log($size, 1024)) : 0;
  2782.     $power = ($power > (count($units) - 1)) ? (count($units) - 1) : $power;
  2783.     return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]);
  2784. }
  2785.  
  2786. /**
  2787.  * Get info about zip archive
  2788.  * @param string $path
  2789.  * @return array|bool
  2790.  */
  2791. function fm_get_zif_info($path, $ext)
  2792. {
  2793.     if ($ext == 'zip' && function_exists('zip_open')) {
  2794.         $arch = @zip_open($path);
  2795.         if ($arch) {
  2796.             $filenames = array();
  2797.             while ($zip_entry = @zip_read($arch)) {
  2798.                 $zip_name = @zip_entry_name($zip_entry);
  2799.                 $zip_folder = substr($zip_name, -1) == '/';
  2800.                 $filenames[] = array(
  2801.                     'name' => $zip_name,
  2802.                     'filesize' => @zip_entry_filesize($zip_entry),
  2803.                     'compressed_size' => @zip_entry_compressedsize($zip_entry),
  2804.                     'folder' => $zip_folder
  2805.                     //'compression_method' => zip_entry_compressionmethod($zip_entry),
  2806.                 );
  2807.             }
  2808.             @zip_close($arch);
  2809.             return $filenames;
  2810.         }
  2811.     } elseif ($ext == 'tar' && class_exists('PharData')) {
  2812.         $archive = new PharData($path);
  2813.         $filenames = array();
  2814.         foreach (new RecursiveIteratorIterator($archive) as $file) {
  2815.             $parent_info = $file->getPathInfo();
  2816.             $zip_name = str_replace("phar://" . $path, '', $file->getPathName());
  2817.             $zip_name = substr($zip_name, ($pos = strpos($zip_name, '/')) !== false ? $pos + 1 : 0);
  2818.             $zip_folder = $parent_info->getFileName();
  2819.             $zip_info = new SplFileInfo($file);
  2820.             $filenames[] = array(
  2821.                 'name' => $zip_name,
  2822.                 'filesize' => $zip_info->getSize(),
  2823.                 'compressed_size' => $file->getCompressedSize(),
  2824.                 'folder' => $zip_folder
  2825.             );
  2826.         }
  2827.         return $filenames;
  2828.     }
  2829.     return false;
  2830. }
  2831.  
  2832. /**
  2833.  * Encode html entities
  2834.  * @param string $text
  2835.  * @return string
  2836.  */
  2837. function fm_enc($text)
  2838. {
  2839.     return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  2840. }
  2841.  
  2842. /**
  2843.  * Prevent XSS attacks
  2844.  * @param string $text
  2845.  * @return string
  2846.  */
  2847. function fm_isvalid_filename($text)
  2848. {
  2849.     return (strpbrk($text, '/?%*:|"<>') === FALSE) ? true : false;
  2850. }
  2851.  
  2852. /**
  2853.  * Save message in session
  2854.  * @param string $msg
  2855.  * @param string $status
  2856.  */
  2857. function fm_set_msg($msg, $status = 'ok')
  2858. {
  2859.     $_SESSION[FM_SESSION_ID]['message'] = $msg;
  2860.     $_SESSION[FM_SESSION_ID]['status'] = $status;
  2861. }
  2862.  
  2863. /**
  2864.  * Check if string is in UTF-8
  2865.  * @param string $string
  2866.  * @return int
  2867.  */
  2868. function fm_is_utf8($string)
  2869. {
  2870.     return preg_match('//u', $string);
  2871. }
  2872.  
  2873. /**
  2874.  * Convert file name to UTF-8 in Windows
  2875.  * @param string $filename
  2876.  * @return string
  2877.  */
  2878. function fm_convert_win($filename)
  2879. {
  2880.     if (FM_IS_WIN && function_exists('iconv')) {
  2881.         $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
  2882.     }
  2883.     return $filename;
  2884. }
  2885.  
  2886. /**
  2887.  * @param $obj
  2888.  * @return array
  2889.  */
  2890. function fm_object_to_array($obj)
  2891. {
  2892.     if (!is_object($obj) && !is_array($obj)) {
  2893.         return $obj;
  2894.     }
  2895.     if (is_object($obj)) {
  2896.         $obj = get_object_vars($obj);
  2897.     }
  2898.     return array_map('fm_object_to_array', $obj);
  2899. }
  2900.  
  2901. /**
  2902.  * Get CSS classname for file
  2903.  * @param string $path
  2904.  * @return string
  2905.  */
  2906. function fm_get_file_icon_class($path)
  2907. {
  2908.     // get extension
  2909.     $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
  2910.  
  2911.     switch ($ext) {
  2912.         case 'ico':
  2913.         case 'gif':
  2914.         case 'jpg':
  2915.         case 'jpeg':
  2916.         case 'jpc':
  2917.         case 'jp2':
  2918.         case 'jpx':
  2919.         case 'xbm':
  2920.         case 'wbmp':
  2921.         case 'png':
  2922.         case 'bmp':
  2923.         case 'tif':
  2924.         case 'tiff':
  2925.         case 'webp':
  2926.         case 'avif':
  2927.         case 'svg':
  2928.             $img = 'fa fa-picture-o';
  2929.             break;
  2930.         case 'passwd':
  2931.         case 'ftpquota':
  2932.         case 'sql':
  2933.         case 'js':
  2934.         case 'ts':
  2935.         case 'jsx':
  2936.         case 'tsx':
  2937.         case 'hbs':
  2938.         case 'json':
  2939.         case 'sh':
  2940.         case 'config':
  2941.         case 'twig':
  2942.         case 'tpl':
  2943.         case 'md':
  2944.         case 'gitignore':
  2945.         case 'c':
  2946.         case 'cpp':
  2947.         case 'cs':
  2948.         case 'py':
  2949.         case 'rs':
  2950.         case 'map':
  2951.         case 'lock':
  2952.         case 'dtd':
  2953.         case 'ps1':
  2954.             $img = 'fa fa-file-code-o';
  2955.             break;
  2956.         case 'txt':
  2957.         case 'ini':
  2958.         case 'conf':
  2959.         case 'log':
  2960.         case 'htaccess':
  2961.         case 'yaml':
  2962.         case 'yml':
  2963.         case 'toml':
  2964.         case 'tmp':
  2965.         case 'top':
  2966.         case 'bot':
  2967.         case 'dat':
  2968.         case 'bak':
  2969.         case 'htpasswd':
  2970.         case 'pl':
  2971.             $img = 'fa fa-file-text-o';
  2972.             break;
  2973.         case 'css':
  2974.         case 'less':
  2975.         case 'sass':
  2976.         case 'scss':
  2977.             $img = 'fa fa-css3';
  2978.             break;
  2979.         case 'bz2':
  2980.         case 'tbz2':
  2981.         case 'tbz':
  2982.         case 'zip':
  2983.         case 'rar':
  2984.         case 'gz':
  2985.         case 'tgz':
  2986.         case 'tar':
  2987.         case '7z':
  2988.         case 'xz':
  2989.         case 'txz':
  2990.         case 'zst':
  2991.         case 'tzst':
  2992.             $img = 'fa fa-file-archive-o';
  2993.             break;
  2994.         case 'php':
  2995.         case 'php4':
  2996.         case 'php5':
  2997.         case 'phps':
  2998.         case 'phtml':
  2999.             $img = 'fa fa-code';
  3000.             break;
  3001.         case 'htm':
  3002.         case 'html':
  3003.         case 'shtml':
  3004.         case 'xhtml':
  3005.             $img = 'fa fa-html5';
  3006.             break;
  3007.         case 'xml':
  3008.         case 'xsl':
  3009.             $img = 'fa fa-file-excel-o';
  3010.             break;
  3011.         case 'wav':
  3012.         case 'mp3':
  3013.         case 'mp2':
  3014.         case 'm4a':
  3015.         case 'aac':
  3016.         case 'ogg':
  3017.         case 'oga':
  3018.         case 'wma':
  3019.         case 'mka':
  3020.         case 'flac':
  3021.         case 'ac3':
  3022.         case 'tds':
  3023.             $img = 'fa fa-music';
  3024.             break;
  3025.         case 'm3u':
  3026.         case 'm3u8':
  3027.         case 'pls':
  3028.         case 'cue':
  3029.         case 'xspf':
  3030.             $img = 'fa fa-headphones';
  3031.             break;
  3032.         case 'avi':
  3033.         case 'mpg':
  3034.         case 'mpeg':
  3035.         case 'mp4':
  3036.         case 'm4v':
  3037.         case 'flv':
  3038.         case 'f4v':
  3039.         case 'ogm':
  3040.         case 'ogv':
  3041.         case 'mov':
  3042.         case 'mkv':
  3043.         case '3gp':
  3044.         case 'asf':
  3045.         case 'wmv':
  3046.         case 'webm':
  3047.             $img = 'fa fa-file-video-o';
  3048.             break;
  3049.         case 'eml':
  3050.         case 'msg':
  3051.             $img = 'fa fa-envelope-o';
  3052.             break;
  3053.         case 'xls':
  3054.         case 'xlsx':
  3055.         case 'ods':
  3056.             $img = 'fa fa-file-excel-o';
  3057.             break;
  3058.         case 'csv':
  3059.             $img = 'fa fa-file-text-o';
  3060.             break;
  3061.         case 'bak':
  3062.         case 'swp':
  3063.             $img = 'fa fa-clipboard';
  3064.             break;
  3065.         case 'doc':
  3066.         case 'docx':
  3067.         case 'odt':
  3068.             $img = 'fa fa-file-word-o';
  3069.             break;
  3070.         case 'ppt':
  3071.         case 'pptx':
  3072.             $img = 'fa fa-file-powerpoint-o';
  3073.             break;
  3074.         case 'ttf':
  3075.         case 'ttc':
  3076.         case 'otf':
  3077.         case 'woff':
  3078.         case 'woff2':
  3079.         case 'eot':
  3080.         case 'fon':
  3081.             $img = 'fa fa-font';
  3082.             break;
  3083.         case 'pdf':
  3084.             $img = 'fa fa-file-pdf-o';
  3085.             break;
  3086.         case 'psd':
  3087.         case 'ai':
  3088.         case 'eps':
  3089.         case 'fla':
  3090.         case 'swf':
  3091.             $img = 'fa fa-file-image-o';
  3092.             break;
  3093.         case 'exe':
  3094.         case 'msi':
  3095.             $img = 'fa fa-file-o';
  3096.             break;
  3097.         case 'bat':
  3098.             $img = 'fa fa-terminal';
  3099.             break;
  3100.         default:
  3101.             $img = 'fa fa-info-circle';
  3102.     }
  3103.  
  3104.     return $img;
  3105. }
  3106.  
  3107. /**
  3108.  * Get image files extensions
  3109.  * @return array
  3110.  */
  3111. function fm_get_image_exts()
  3112. {
  3113.     return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd', 'svg', 'webp', 'avif');
  3114. }
  3115.  
  3116. /**
  3117.  * Get video files extensions
  3118.  * @return array
  3119.  */
  3120. function fm_get_video_exts()
  3121. {
  3122.     return array('avi', 'webm', 'wmv', 'mp4', 'm4v', 'ogm', 'ogv', 'mov', 'mkv');
  3123. }
  3124.  
  3125. /**
  3126.  * Get audio files extensions
  3127.  * @return array
  3128.  */
  3129. function fm_get_audio_exts()
  3130. {
  3131.     return array('wav', 'mp3', 'ogg', 'm4a');
  3132. }
  3133.  
  3134. /**
  3135.  * Get text file extensions
  3136.  * @return array
  3137.  */
  3138. function fm_get_text_exts()
  3139. {
  3140.     return array(
  3141.         'txt',
  3142.         'css',
  3143.         'ini',
  3144.         'conf',
  3145.         'log',
  3146.         'htaccess',
  3147.         'passwd',
  3148.         'ftpquota',
  3149.         'sql',
  3150.         'js',
  3151.         'ts',
  3152.         'jsx',
  3153.         'tsx',
  3154.         'mjs',
  3155.         'json',
  3156.         'sh',
  3157.         'config',
  3158.         'php',
  3159.         'php4',
  3160.         'php5',
  3161.         'phps',
  3162.         'phtml',
  3163.         'htm',
  3164.         'html',
  3165.         'shtml',
  3166.         'xhtml',
  3167.         'xml',
  3168.         'xsl',
  3169.         'm3u',
  3170.         'm3u8',
  3171.         'pls',
  3172.         'cue',
  3173.         'bash',
  3174.         'vue',
  3175.         'eml',
  3176.         'msg',
  3177.         'csv',
  3178.         'bat',
  3179.         'twig',
  3180.         'tpl',
  3181.         'md',
  3182.         'gitignore',
  3183.         'less',
  3184.         'sass',
  3185.         'scss',
  3186.         'c',
  3187.         'cpp',
  3188.         'cs',
  3189.         'py',
  3190.         'go',
  3191.         'zsh',
  3192.         'swift',
  3193.         'map',
  3194.         'lock',
  3195.         'dtd',
  3196.         'svg',
  3197.         'asp',
  3198.         'aspx',
  3199.         'asx',
  3200.         'asmx',
  3201.         'ashx',
  3202.         'jsp',
  3203.         'jspx',
  3204.         'cgi',
  3205.         'dockerfile',
  3206.         'ruby',
  3207.         'yml',
  3208.         'yaml',
  3209.         'toml',
  3210.         'vhost',
  3211.         'scpt',
  3212.         'applescript',
  3213.         'csx',
  3214.         'cshtml',
  3215.         'c++',
  3216.         'coffee',
  3217.         'cfm',
  3218.         'rb',
  3219.         'graphql',
  3220.         'mustache',
  3221.         'jinja',
  3222.         'http',
  3223.         'handlebars',
  3224.         'java',
  3225.         'es',
  3226.         'es6',
  3227.         'markdown',
  3228.         'wiki',
  3229.         'tmp',
  3230.         'top',
  3231.         'bot',
  3232.         'dat',
  3233.         'bak',
  3234.         'htpasswd',
  3235.         'pl',
  3236.         'ps1'
  3237.     );
  3238. }
  3239.  
  3240. /**
  3241.  * Get mime types of text files
  3242.  * @return array
  3243.  */
  3244. function fm_get_text_mimes()
  3245. {
  3246.     return array(
  3247.         'application/xml',
  3248.         'application/javascript',
  3249.         'application/x-javascript',
  3250.         'image/svg+xml',
  3251.         'message/rfc822',
  3252.         'application/json',
  3253.     );
  3254. }
  3255.  
  3256. /**
  3257.  * Get file names of text files w/o extensions
  3258.  * @return array
  3259.  */
  3260. function fm_get_text_names()
  3261. {
  3262.     return array(
  3263.         'license',
  3264.         'readme',
  3265.         'authors',
  3266.         'contributors',
  3267.         'changelog',
  3268.     );
  3269. }
  3270.  
  3271. /**
  3272.  * Get online docs viewer supported files extensions
  3273.  * @return array
  3274.  */
  3275. function fm_get_onlineViewer_exts()
  3276. {
  3277.     return array('doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx', 'ai', 'psd', 'dxf', 'xps', 'rar', 'odt', 'ods');
  3278. }
  3279.  
  3280. /**
  3281.  * It returns the mime type of a file based on its extension.
  3282.  * @param extension The file extension of the file you want to get the mime type for.
  3283.  * @return string|string[] The mime type of the file.
  3284.  */
  3285. function fm_get_file_mimes($extension)
  3286. {
  3287.     $fileTypes['swf'] = 'application/x-shockwave-flash';
  3288.     $fileTypes['pdf'] = 'application/pdf';
  3289.     $fileTypes['exe'] = 'application/octet-stream';
  3290.     $fileTypes['zip'] = 'application/zip';
  3291.     $fileTypes['doc'] = 'application/msword';
  3292.     $fileTypes['xls'] = 'application/vnd.ms-excel';
  3293.     $fileTypes['ppt'] = 'application/vnd.ms-powerpoint';
  3294.     $fileTypes['gif'] = 'image/gif';
  3295.     $fileTypes['png'] = 'image/png';
  3296.     $fileTypes['jpeg'] = 'image/jpg';
  3297.     $fileTypes['jpg'] = 'image/jpg';
  3298.     $fileTypes['webp'] = 'image/webp';
  3299.     $fileTypes['avif'] = 'image/avif';
  3300.     $fileTypes['rar'] = 'application/rar';
  3301.  
  3302.     $fileTypes['ra'] = 'audio/x-pn-realaudio';
  3303.     $fileTypes['ram'] = 'audio/x-pn-realaudio';
  3304.     $fileTypes['ogg'] = 'audio/x-pn-realaudio';
  3305.  
  3306.     $fileTypes['wav'] = 'video/x-msvideo';
  3307.     $fileTypes['wmv'] = 'video/x-msvideo';
  3308.     $fileTypes['avi'] = 'video/x-msvideo';
  3309.     $fileTypes['asf'] = 'video/x-msvideo';
  3310.     $fileTypes['divx'] = 'video/x-msvideo';
  3311.  
  3312.     $fileTypes['mp3'] = 'audio/mpeg';
  3313.     $fileTypes['mp4'] = 'video/mp4';
  3314.     $fileTypes['mpeg'] = 'video/mpeg';
  3315.     $fileTypes['mpg'] = 'video/mpeg';
  3316.     $fileTypes['mpe'] = 'video/mpeg';
  3317.     $fileTypes['mov'] = 'video/quicktime';
  3318.     $fileTypes['swf'] = 'video/quicktime';
  3319.     $fileTypes['3gp'] = 'video/quicktime';
  3320.     $fileTypes['m4a'] = 'video/quicktime';
  3321.     $fileTypes['aac'] = 'video/quicktime';
  3322.     $fileTypes['m3u'] = 'video/quicktime';
  3323.  
  3324.     $fileTypes['php'] = ['application/x-php'];
  3325.     $fileTypes['html'] = ['text/html'];
  3326.     $fileTypes['txt'] = ['text/plain'];
  3327.     //Unknown mime-types should be 'application/octet-stream'
  3328.     if (empty($fileTypes[$extension])) {
  3329.         $fileTypes[$extension] = ['application/octet-stream'];
  3330.     }
  3331.     return $fileTypes[$extension];
  3332. }
  3333.  
  3334. /**
  3335.  * This function scans the files and folder recursively, and return matching files
  3336.  * @param string $dir
  3337.  * @param string $filter
  3338.  * @return array|null
  3339.  */
  3340. function scan($dir = '', $filter = '')
  3341. {
  3342.     $path = FM_ROOT_PATH . '/' . $dir;
  3343.     if ($path) {
  3344.         $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
  3345.         $rii = new RegexIterator($ite, "/(" . $filter . ")/i");
  3346.  
  3347.         $files = array();
  3348.         foreach ($rii as $file) {
  3349.             if (!$file->isDir()) {
  3350.                 $fileName = $file->getFilename();
  3351.                 $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
  3352.                 $files[] = array(
  3353.                     "name" => $fileName,
  3354.                     "type" => "file",
  3355.                     "path" => $location,
  3356.                 );
  3357.             }
  3358.         }
  3359.         return $files;
  3360.     }
  3361. }
  3362.  
  3363. /**
  3364.  * Parameters: downloadFile(File Location, File Name,
  3365.  * max speed, is streaming
  3366.  * If streaming - videos will show as videos, images as images
  3367.  * instead of download prompt
  3368.  * https://stackoverflow.com/a/13821992/1164642
  3369.  */
  3370. function fm_download_file($fileLocation, $fileName, $chunkSize  = 1024)
  3371. {
  3372.     if (connection_status() != 0)
  3373.         return (false);
  3374.     $extension = pathinfo($fileName, PATHINFO_EXTENSION);
  3375.  
  3376.     $contentType = fm_get_file_mimes($extension);
  3377.  
  3378.     if (is_array($contentType)) {
  3379.         $contentType = implode(' ', $contentType);
  3380.     }
  3381.  
  3382.     $size = filesize($fileLocation);
  3383.  
  3384.     if ($size == 0) {
  3385.         fm_set_msg(lng('Zero byte file! Aborting download'), 'error');
  3386.         $FM_PATH = FM_PATH;
  3387.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3388.  
  3389.         return (false);
  3390.     }
  3391.  
  3392.     @ini_set('magic_quotes_runtime', 0);
  3393.     $fp = fopen("$fileLocation", "rb");
  3394.  
  3395.     if ($fp === false) {
  3396.         fm_set_msg(lng('Cannot open file! Aborting download'), 'error');
  3397.         $FM_PATH = FM_PATH;
  3398.         fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3399.         return (false);
  3400.     }
  3401.  
  3402.     // headers
  3403.     header('Content-Description: File Transfer');
  3404.     header('Expires: 0');
  3405.     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  3406.     header('Pragma: public');
  3407.     header("Content-Transfer-Encoding: binary");
  3408.     header("Content-Type: $contentType");
  3409.  
  3410.     $contentDisposition = 'attachment';
  3411.  
  3412.     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  3413.         $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
  3414.         header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3415.     } else {
  3416.         header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3417.     }
  3418.  
  3419.     header("Accept-Ranges: bytes");
  3420.     $range = 0;
  3421.  
  3422.     if (isset($_SERVER['HTTP_RANGE'])) {
  3423.         list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
  3424.         str_replace($range, "-", $range);
  3425.         $size2 = $size - 1;
  3426.         $new_length = $size - $range;
  3427.         header("HTTP/1.1 206 Partial Content");
  3428.         header("Content-Length: $new_length");
  3429.         header("Content-Range: bytes $range$size2/$size");
  3430.     } else {
  3431.         $size2 = $size - 1;
  3432.         header("Content-Range: bytes 0-$size2/$size");
  3433.         header("Content-Length: " . $size);
  3434.     }
  3435.     $fileLocation = realpath($fileLocation);
  3436.     while (ob_get_level()) ob_end_clean();
  3437.     readfile($fileLocation);
  3438.  
  3439.     fclose($fp);
  3440.  
  3441.     return ((connection_status() == 0) and !connection_aborted());
  3442. }
  3443.  
  3444. /**
  3445.  * Class to work with zip files (using ZipArchive)
  3446.  */
  3447. class FM_Zipper
  3448. {
  3449.     private $zip;
  3450.  
  3451.     public function __construct()
  3452.     {
  3453.         $this->zip = new ZipArchive();
  3454.     }
  3455.  
  3456.     /**
  3457.      * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3458.      * @param string $filename
  3459.      * @param array|string $files
  3460.      * @return bool
  3461.      */
  3462.     public function create($filename, $files)
  3463.     {
  3464.         $res = $this->zip->open($filename, ZipArchive::CREATE);
  3465.         if ($res !== true) {
  3466.             return false;
  3467.         }
  3468.         if (is_array($files)) {
  3469.             foreach ($files as $f) {
  3470.                 $f = fm_clean_path($f);
  3471.                 if (!$this->addFileOrDir($f)) {
  3472.                     $this->zip->close();
  3473.                     return false;
  3474.                 }
  3475.             }
  3476.             $this->zip->close();
  3477.             return true;
  3478.         } else {
  3479.             if ($this->addFileOrDir($files)) {
  3480.                 $this->zip->close();
  3481.                 return true;
  3482.             }
  3483.             return false;
  3484.         }
  3485.     }
  3486.  
  3487.     /**
  3488.      * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3489.      * @param string $filename
  3490.      * @param string $path
  3491.      * @return bool
  3492.      */
  3493.     public function unzip($filename, $path)
  3494.     {
  3495.         $res = $this->zip->open($filename);
  3496.         if ($res !== true) {
  3497.             return false;
  3498.         }
  3499.         if ($this->zip->extractTo($path)) {
  3500.             $this->zip->close();
  3501.             return true;
  3502.         }
  3503.         return false;
  3504.     }
  3505.  
  3506.     /**
  3507.      * Add file/folder to archive
  3508.      * @param string $filename
  3509.      * @return bool
  3510.      */
  3511.     private function addFileOrDir($filename)
  3512.     {
  3513.         if (is_file($filename)) {
  3514.             return $this->zip->addFile($filename);
  3515.         } elseif (is_dir($filename)) {
  3516.             return $this->addDir($filename);
  3517.         }
  3518.         return false;
  3519.     }
  3520.  
  3521.     /**
  3522.      * Add folder recursively
  3523.      * @param string $path
  3524.      * @return bool
  3525.      */
  3526.     private function addDir($path)
  3527.     {
  3528.         if (!$this->zip->addEmptyDir($path)) {
  3529.             return false;
  3530.         }
  3531.         $objects = scandir($path);
  3532.         if (is_array($objects)) {
  3533.             foreach ($objects as $file) {
  3534.                 if ($file != '.' && $file != '..') {
  3535.                     if (is_dir($path . '/' . $file)) {
  3536.                         if (!$this->addDir($path . '/' . $file)) {
  3537.                             return false;
  3538.                         }
  3539.                     } elseif (is_file($path . '/' . $file)) {
  3540.                         if (!$this->zip->addFile($path . '/' . $file)) {
  3541.                             return false;
  3542.                         }
  3543.                     }
  3544.                 }
  3545.             }
  3546.             return true;
  3547.         }
  3548.         return false;
  3549.     }
  3550. }
  3551.  
  3552. /**
  3553.  * Class to work with Tar files (using PharData)
  3554.  */
  3555. class FM_Zipper_Tar
  3556. {
  3557.     private $tar;
  3558.  
  3559.     public function __construct()
  3560.     {
  3561.         $this->tar = null;
  3562.     }
  3563.  
  3564.     /**
  3565.      * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3566.      * @param string $filename
  3567.      * @param array|string $files
  3568.      * @return bool
  3569.      */
  3570.     public function create($filename, $files)
  3571.     {
  3572.         $this->tar = new PharData($filename);
  3573.         if (is_array($files)) {
  3574.             foreach ($files as $f) {
  3575.                 $f = fm_clean_path($f);
  3576.                 if (!$this->addFileOrDir($f)) {
  3577.                     return false;
  3578.                 }
  3579.             }
  3580.             return true;
  3581.         } else {
  3582.             if ($this->addFileOrDir($files)) {
  3583.                 return true;
  3584.             }
  3585.             return false;
  3586.         }
  3587.     }
  3588.  
  3589.     /**
  3590.      * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3591.      * @param string $filename
  3592.      * @param string $path
  3593.      * @return bool
  3594.      */
  3595.     public function unzip($filename, $path)
  3596.     {
  3597.         $res = $this->tar->open($filename);
  3598.         if ($res !== true) {
  3599.             return false;
  3600.         }
  3601.         if ($this->tar->extractTo($path)) {
  3602.             return true;
  3603.         }
  3604.         return false;
  3605.     }
  3606.  
  3607.     /**
  3608.      * Add file/folder to archive
  3609.      * @param string $filename
  3610.      * @return bool
  3611.      */
  3612.     private function addFileOrDir($filename)
  3613.     {
  3614.         if (is_file($filename)) {
  3615.             try {
  3616.                 $this->tar->addFile($filename);
  3617.                 return true;
  3618.             } catch (Exception $e) {
  3619.                 return false;
  3620.             }
  3621.         } elseif (is_dir($filename)) {
  3622.             return $this->addDir($filename);
  3623.         }
  3624.         return false;
  3625.     }
  3626.  
  3627.     /**
  3628.      * Add folder recursively
  3629.      * @param string $path
  3630.      * @return bool
  3631.      */
  3632.     private function addDir($path)
  3633.     {
  3634.         $objects = scandir($path);
  3635.         if (is_array($objects)) {
  3636.             foreach ($objects as $file) {
  3637.                 if ($file != '.' && $file != '..') {
  3638.                     if (is_dir($path . '/' . $file)) {
  3639.                         if (!$this->addDir($path . '/' . $file)) {
  3640.                             return false;
  3641.                         }
  3642.                     } elseif (is_file($path . '/' . $file)) {
  3643.                         try {
  3644.                             $this->tar->addFile($path . '/' . $file);
  3645.                         } catch (Exception $e) {
  3646.                             return false;
  3647.                         }
  3648.                     }
  3649.                 }
  3650.             }
  3651.             return true;
  3652.         }
  3653.         return false;
  3654.     }
  3655. }
  3656.  
  3657. /**
  3658.  * Save Configuration
  3659.  */
  3660. class FM_Config
  3661. {
  3662.     var $data;
  3663.  
  3664.     function __construct()
  3665.     {
  3666.         global $root_path, $root_url, $CONFIG;
  3667.         $fm_url = $root_url . $_SERVER["PHP_SELF"];
  3668.         $this->data = array(
  3669.             'lang' => 'en',
  3670.             'error_reporting' => true,
  3671.             'show_hidden' => true
  3672.         );
  3673.         $data = false;
  3674.         if (strlen($CONFIG)) {
  3675.             $data = fm_object_to_array(json_decode($CONFIG));
  3676.         } else {
  3677.             $msg = 'Tiny File Manager<br>Error: Cannot load configuration';
  3678.             if (substr($fm_url, -1) == '/') {
  3679.                 $fm_url = rtrim($fm_url, '/');
  3680.                 $msg .= '<br>';
  3681.                 $msg .= '<br>Seems like you have a trailing slash on the URL.';
  3682.                 $msg .= '<br>Try this link: <a href="' . $fm_url . '">' . $fm_url . '</a>';
  3683.             }
  3684.             die($msg);
  3685.         }
  3686.         if (is_array($data) && count($data)) $this->data = $data;
  3687.         else $this->save();
  3688.     }
  3689.  
  3690.     function save()
  3691.     {
  3692.         global $config_file;
  3693.         $fm_file = is_readable($config_file) ? $config_file : __FILE__;
  3694.         $var_name = '$CONFIG';
  3695.         $var_value = var_export(json_encode($this->data), true);
  3696.         $config_string = "<?php" . chr(13) . chr(10) . "//Default Configuration" . chr(13) . chr(10) . "$var_name = $var_value;" . chr(13) . chr(10);
  3697.         if (is_writable($fm_file)) {
  3698.             $lines = file($fm_file);
  3699.             if ($fh = @fopen($fm_file, "w")) {
  3700.                 @fputs($fh, $config_string, strlen($config_string));
  3701.                 for ($x = 3; $x < count($lines); $x++) {
  3702.                     @fputs($fh, $lines[$x], strlen($lines[$x]));
  3703.                 }
  3704.                 @fclose($fh);
  3705.             }
  3706.         }
  3707.     }
  3708. }
  3709.  
  3710. //--- Templates Functions ---
  3711.  
  3712. /**
  3713.  * Show nav block
  3714.  * @param string $path
  3715.  */
  3716. function fm_show_nav_path($path)
  3717. {
  3718.     global $lang, $sticky_navbar, $editFile;
  3719.     $isStickyNavBar = $sticky_navbar ? 'fixed-top' : '';
  3720. ?>
  3721.     <nav class="navbar navbar-expand-lg mb-4 main-nav <?php echo $isStickyNavBar ?> bg-body-tertiary" data-bs-theme="<?php echo FM_THEME; ?>">
  3722.         <a class="navbar-brand"> <?php echo lng('AppTitle') ?> </a>
  3723.         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  3724.             <span class="navbar-toggler-icon"></span>
  3725.         </button>
  3726.         <div class="collapse navbar-collapse" id="navbarSupportedContent">
  3727.  
  3728.             <?php
  3729.             $path = fm_clean_path($path);
  3730.             $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
  3731.             $sep = '<i class="bread-crumb"> / </i>';
  3732.             if ($path != '') {
  3733.                 $exploded = explode('/', $path);
  3734.                 $count = count($exploded);
  3735.                 $array = array();
  3736.                 $parent = '';
  3737.                 for ($i = 0; $i < $count; $i++) {
  3738.                     $parent = trim($parent . '/' . $exploded[$i], '/');
  3739.                     $parent_enc = urlencode($parent);
  3740.                     $array[] = "<a href='?p={$parent_enc}'>" . fm_enc(fm_convert_win($exploded[$i])) . "</a>";
  3741.                 }
  3742.                 $root_url .= $sep . implode($sep, $array);
  3743.             }
  3744.             echo '<div class="col-xs-6 col-sm-5">' . $root_url . $editFile . '</div>';
  3745.             ?>
  3746.  
  3747.             <div class="col-xs-6 col-sm-7">
  3748.                 <ul class="navbar-nav justify-content-end" data-bs-theme="<?php echo FM_THEME; ?>">
  3749.                     <li class="nav-item mr-2">
  3750.                         <div class="input-group input-group-sm mr-1" style="margin-top:4px;">
  3751.                             <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon2" id="search-addon">
  3752.                             <div class="input-group-append">
  3753.                                 <span class="input-group-text brl-0 brr-0" id="search-addon2"><i class="fa fa-search"></i></span>
  3754.                             </div>
  3755.                             <div class="input-group-append btn-group">
  3756.                                 <span class="input-group-text dropdown-toggle brl-0" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
  3757.                                 <div class="dropdown-menu dropdown-menu-right">
  3758.                                     <a class="dropdown-item" href="<?php echo $path2 = $path ? $path : '.'; ?>" id="js-search-modal" data-bs-toggle="modal" data-bs-target="#searchModal"><?php echo lng('Advanced Search') ?></a>
  3759.                                 </div>
  3760.                             </div>
  3761.                         </div>
  3762.                     </li>
  3763.                     <?php if (!FM_READONLY): ?>
  3764.                         <li class="nav-item">
  3765.                             <a title="<?php echo lng('Upload') ?>" class="nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;upload"><i class="fa fa-cloud-upload" aria-hidden="true"></i> <?php echo lng('Upload') ?></a>
  3766.                         </li>
  3767.                         <li class="nav-item">
  3768.                             <a title="<?php echo lng('NewItem') ?>" class="nav-link" href="#createNewItem" data-bs-toggle="modal" data-bs-target="#createNewItem"><i class="fa fa-plus-square"></i> <?php echo lng('NewItem') ?></a>
  3769.                         </li>
  3770.                     <?php endif; ?>
  3771.                     <?php if (FM_USE_AUTH): ?>
  3772.                         <li class="nav-item avatar dropdown">
  3773.                             <a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink-5" data-bs-toggle="dropdown" aria-expanded="false">
  3774.                                 <i class="fa fa-user-circle"></i>
  3775.                             </a>
  3776.  
  3777.                             <div class="dropdown-menu dropdown-menu-end text-small shadow" aria-labelledby="navbarDropdownMenuLink-5" data-bs-theme="<?php echo FM_THEME; ?>">
  3778.                                 <?php if (!FM_READONLY): ?>
  3779.                                     <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3780.                                 <?php endif ?>
  3781.                                 <a title="<?php echo lng('Help') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;help=2"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> <?php echo lng('Help') ?></a>
  3782.                                 <a title="<?php echo lng('Logout') ?>" class="dropdown-item nav-link" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i> <?php echo lng('Logout') ?></a>
  3783.                             </div>
  3784.                         </li>
  3785.                     <?php else: ?>
  3786.                         <?php if (!FM_READONLY): ?>
  3787.                             <li class="nav-item">
  3788.                                 <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3789.                             </li>
  3790.                         <?php endif; ?>
  3791.                     <?php endif; ?>
  3792.                 </ul>
  3793.             </div>
  3794.         </div>
  3795.     </nav>
  3796. <?php
  3797. }
  3798.  
  3799. /**
  3800.  * Show alert message from session
  3801.  */
  3802. function fm_show_message()
  3803. {
  3804.     if (isset($_SESSION[FM_SESSION_ID]['message'])) {
  3805.         $class = isset($_SESSION[FM_SESSION_ID]['status']) ? $_SESSION[FM_SESSION_ID]['status'] : 'ok';
  3806.         echo '<p class="message ' . $class . '">' . $_SESSION[FM_SESSION_ID]['message'] . '</p>';
  3807.         unset($_SESSION[FM_SESSION_ID]['message']);
  3808.         unset($_SESSION[FM_SESSION_ID]['status']);
  3809.     }
  3810. }
  3811.  
  3812. /**
  3813.  * Show page header in Login Form
  3814.  */
  3815. function fm_show_header_login()
  3816. {
  3817.     header("Content-Type: text/html; charset=utf-8");
  3818.     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3819.     header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3820.     header("Pragma: no-cache");
  3821.  
  3822.     global $favicon_path;
  3823. ?>
  3824.     <!DOCTYPE html>
  3825.     <html lang="en" data-bs-theme="<?php echo (FM_THEME == "dark") ? 'dark' : 'light' ?>">
  3826.  
  3827.     <head>
  3828.         <meta charset="utf-8">
  3829.         <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3830.         <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3831.         <meta name="author" content="CCP Programmers">
  3832.         <meta name="robots" content="noindex, nofollow">
  3833.         <meta name="googlebot" content="noindex">
  3834.         <?php if ($favicon_path) {
  3835.             echo '<link rel="icon" href="' . fm_enc($favicon_path) . '" type="image/png">';
  3836.         } ?>
  3837.         <title><?php echo fm_enc(APP_TITLE) ?></title>
  3838.         <?php print_external('pre-jsdelivr'); ?>
  3839.         <?php print_external('css-bootstrap'); ?>
  3840.         <style>
  3841.             body.fm-login-page {
  3842.                 background-color: #f7f9fb;
  3843.                 font-size: 14px;
  3844.                 background-color: #f7f9fb;
  3845.                 background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 304 304' width='304' height='304'%3E%3Cpath fill='%23e2e9f1' fill-opacity='0.4' d='M44.1 224a5 5 0 1 1 0 2H0v-2h44.1zm160 48a5 5 0 1 1 0 2H82v-2h122.1zm57.8-46a5 5 0 1 1 0-2H304v2h-42.1zm0 16a5 5 0 1 1 0-2H304v2h-42.1zm6.2-114a5 5 0 1 1 0 2h-86.2a5 5 0 1 1 0-2h86.2zm-256-48a5 5 0 1 1 0 2H0v-2h12.1zm185.8 34a5 5 0 1 1 0-2h86.2a5 5 0 1 1 0 2h-86.2zM258 12.1a5 5 0 1 1-2 0V0h2v12.1zm-64 208a5 5 0 1 1-2 0v-54.2a5 5 0 1 1 2 0v54.2zm48-198.2V80h62v2h-64V21.9a5 5 0 1 1 2 0zm16 16V64h46v2h-48V37.9a5 5 0 1 1 2 0zm-128 96V208h16v12.1a5 5 0 1 1-2 0V210h-16v-76.1a5 5 0 1 1 2 0zm-5.9-21.9a5 5 0 1 1 0 2H114v48H85.9a5 5 0 1 1 0-2H112v-48h12.1zm-6.2 130a5 5 0 1 1 0-2H176v-74.1a5 5 0 1 1 2 0V242h-60.1zm-16-64a5 5 0 1 1 0-2H114v48h10.1a5 5 0 1 1 0 2H112v-48h-10.1zM66 284.1a5 5 0 1 1-2 0V274H50v30h-2v-32h18v12.1zM236.1 176a5 5 0 1 1 0 2H226v94h48v32h-2v-30h-48v-98h12.1zm25.8-30a5 5 0 1 1 0-2H274v44.1a5 5 0 1 1-2 0V146h-10.1zm-64 96a5 5 0 1 1 0-2H208v-80h16v-14h-42.1a5 5 0 1 1 0-2H226v18h-16v80h-12.1zm86.2-210a5 5 0 1 1 0 2H272V0h2v32h10.1zM98 101.9V146H53.9a5 5 0 1 1 0-2H96v-42.1a5 5 0 1 1 2 0zM53.9 34a5 5 0 1 1 0-2H80V0h2v34H53.9zm60.1 3.9V66H82v64H69.9a5 5 0 1 1 0-2H80V64h32V37.9a5 5 0 1 1 2 0zM101.9 82a5 5 0 1 1 0-2H128V37.9a5 5 0 1 1 2 0V82h-28.1zm16-64a5 5 0 1 1 0-2H146v44.1a5 5 0 1 1-2 0V18h-26.1zm102.2 270a5 5 0 1 1 0 2H98v14h-2v-16h124.1zM242 149.9V160h16v34h-16v62h48v48h-2v-46h-48v-66h16v-30h-16v-12.1a5 5 0 1 1 2 0zM53.9 18a5 5 0 1 1 0-2H64V2H48V0h18v18H53.9zm112 32a5 5 0 1 1 0-2H192V0h50v2h-48v48h-28.1zm-48-48a5 5 0 0 1-9.8-2h2.07a3 3 0 1 0 5.66 0H178v34h-18V21.9a5 5 0 1 1 2 0V32h14V2h-58.1zm0 96a5 5 0 1 1 0-2H137l32-32h39V21.9a5 5 0 1 1 2 0V66h-40.17l-32 32H117.9zm28.1 90.1a5 5 0 1 1-2 0v-76.51L175.59 80H224V21.9a5 5 0 1 1 2 0V82h-49.59L146 112.41v75.69zm16 32a5 5 0 1 1-2 0v-99.51L184.59 96H300.1a5 5 0 0 1 3.9-3.9v2.07a3 3 0 0 0 0 5.66v2.07a5 5 0 0 1-3.9-3.9H185.41L162 121.41v98.69zm-144-64a5 5 0 1 1-2 0v-3.51l48-48V48h32V0h2v50H66v55.41l-48 48v2.69zM50 53.9v43.51l-48 48V208h26.1a5 5 0 1 1 0 2H0v-65.41l48-48V53.9a5 5 0 1 1 2 0zm-16 16V89.41l-34 34v-2.82l32-32V69.9a5 5 0 1 1 2 0zM12.1 32a5 5 0 1 1 0 2H9.41L0 43.41V40.6L8.59 32h3.51zm265.8 18a5 5 0 1 1 0-2h18.69l7.41-7.41v2.82L297.41 50H277.9zm-16 160a5 5 0 1 1 0-2H288v-71.41l16-16v2.82l-14 14V210h-28.1zm-208 32a5 5 0 1 1 0-2H64v-22.59L40.59 194H21.9a5 5 0 1 1 0-2H41.41L66 216.59V242H53.9zm150.2 14a5 5 0 1 1 0 2H96v-56.6L56.6 162H37.9a5 5 0 1 1 0-2h19.5L98 200.6V256h106.1zm-150.2 2a5 5 0 1 1 0-2H80v-46.59L48.59 178H21.9a5 5 0 1 1 0-2H49.41L82 208.59V258H53.9zM34 39.8v1.61L9.41 66H0v-2h8.59L32 40.59V0h2v39.8zM2 300.1a5 5 0 0 1 3.9 3.9H3.83A3 3 0 0 0 0 302.17V256h18v48h-2v-46H2v42.1zM34 241v63h-2v-62H0v-2h34v1zM17 18H0v-2h16V0h2v18h-1zm273-2h14v2h-16V0h2v16zm-32 273v15h-2v-14h-14v14h-2v-16h18v1zM0 92.1A5.02 5.02 0 0 1 6 97a5 5 0 0 1-6 4.9v-2.07a3 3 0 1 0 0-5.66V92.1zM80 272h2v32h-2v-32zm37.9 32h-2.07a3 3 0 0 0-5.66 0h-2.07a5 5 0 0 1 9.8 0zM5.9 0A5.02 5.02 0 0 1 0 5.9V3.83A3 3 0 0 0 3.83 0H5.9zm294.2 0h2.07A3 3 0 0 0 304 3.83V5.9a5 5 0 0 1-3.9-5.9zm3.9 300.1v2.07a3 3 0 0 0-1.83 1.83h-2.07a5 5 0 0 1 3.9-3.9zM97 100a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-48 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 96a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-144a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-96 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm96 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-32 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM49 36a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-32 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM33 68a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 240a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm80-176a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 48a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm112 176a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 180a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 84a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'%3E%3C/path%3E%3C/svg%3E");
  3846.             }
  3847.  
  3848.             .fm-login-page .brand {
  3849.                 width: 121px;
  3850.                 overflow: hidden;
  3851.                 margin: 0 auto;
  3852.                 position: relative;
  3853.                 z-index: 1
  3854.             }
  3855.  
  3856.             .fm-login-page .brand img {
  3857.                 width: 100%
  3858.             }
  3859.  
  3860.             .fm-login-page .card-wrapper {
  3861.                 width: 360px;
  3862.             }
  3863.  
  3864.             .fm-login-page .card {
  3865.                 border-color: transparent;
  3866.                 box-shadow: 0 4px 8px rgba(0, 0, 0, .05)
  3867.             }
  3868.  
  3869.             .fm-login-page .card-title {
  3870.                 margin-bottom: 1.5rem;
  3871.                 font-size: 24px;
  3872.                 font-weight: 400;
  3873.             }
  3874.  
  3875.             .fm-login-page .form-control {
  3876.                 border-width: 2.3px
  3877.             }
  3878.  
  3879.             .fm-login-page .form-group label {
  3880.                 width: 100%
  3881.             }
  3882.  
  3883.             .fm-login-page .btn.btn-block {
  3884.                 padding: 12px 10px
  3885.             }
  3886.  
  3887.             .fm-login-page .footer {
  3888.                 margin: 20px 0;
  3889.                 color: #888;
  3890.                 text-align: center
  3891.             }
  3892.  
  3893.             @media screen and (max-width:425px) {
  3894.                 .fm-login-page .card-wrapper {
  3895.                     width: 90%;
  3896.                     margin: 0 auto;
  3897.                     margin-top: 10%;
  3898.                 }
  3899.             }
  3900.  
  3901.             @media screen and (max-width:320px) {
  3902.                 .fm-login-page .card.fat {
  3903.                     padding: 0
  3904.                 }
  3905.  
  3906.                 .fm-login-page .card.fat .card-body {
  3907.                     padding: 15px
  3908.                 }
  3909.             }
  3910.  
  3911.             .message {
  3912.                 padding: 4px 7px;
  3913.                 border: 1px solid #ddd;
  3914.                 background-color: #fff
  3915.             }
  3916.  
  3917.             .message.ok {
  3918.                 border-color: green;
  3919.                 color: green
  3920.             }
  3921.  
  3922.             .message.error {
  3923.                 border-color: red;
  3924.                 color: red
  3925.             }
  3926.  
  3927.             .message.alert {
  3928.                 border-color: orange;
  3929.                 color: orange
  3930.             }
  3931.  
  3932.             body.fm-login-page.theme-dark {
  3933.                 background-color: #2f2a2a;
  3934.             }
  3935.  
  3936.             .theme-dark svg g,
  3937.             .theme-dark svg path {
  3938.                 fill: #ffffff;
  3939.             }
  3940.  
  3941.             .theme-dark .form-control {
  3942.                 color: #fff;
  3943.                 background-color: #403e3e;
  3944.             }
  3945.  
  3946.             .h-100vh {
  3947.                 min-height: 100vh;
  3948.             }
  3949.         </style>
  3950.     </head>
  3951.  
  3952.     <body class="fm-login-page <?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?>">
  3953.         <div id="wrapper" class="container-fluid">
  3954.  
  3955.         <?php
  3956.     }
  3957.  
  3958.     /**
  3959.      * Show page footer in Login Form
  3960.      */
  3961.     function fm_show_footer_login()
  3962.     {
  3963.         ?>
  3964.         </div>
  3965.         <?php print_external('js-jquery'); ?>
  3966.         <?php print_external('js-bootstrap'); ?>
  3967.     </body>
  3968.  
  3969.     </html>
  3970.  
  3971. <?php
  3972.     }
  3973.  
  3974.     /**
  3975.      * Show Header after login
  3976.      */
  3977.     function fm_show_header()
  3978.     {
  3979.         header("Content-Type: text/html; charset=utf-8");
  3980.         header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3981.         header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3982.         header("Pragma: no-cache");
  3983.  
  3984.         global $sticky_navbar, $favicon_path;
  3985.         $isStickyNavBar = $sticky_navbar ? 'navbar-fixed' : 'navbar-normal';
  3986. ?>
  3987.     <!DOCTYPE html>
  3988.     <html data-bs-theme="<?php echo FM_THEME; ?>">
  3989.  
  3990.     <head>
  3991.         <meta charset="utf-8">
  3992.         <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3993.         <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3994.         <meta name="author" content="CCP Programmers">
  3995.         <meta name="robots" content="noindex, nofollow">
  3996.         <meta name="googlebot" content="noindex">
  3997.         <?php if ($favicon_path) {
  3998.             echo '<link rel="icon" href="' . fm_enc($favicon_path) . '" type="image/png">';
  3999.         } ?>
  4000.         <title><?php echo fm_enc(APP_TITLE) ?> | <?php echo (isset($_GET['view']) ? $_GET['view'] : ((isset($_GET['edit'])) ? $_GET['edit'] : "H3K")); ?></title>
  4001.         <?php print_external('pre-jsdelivr'); ?>
  4002.         <?php print_external('pre-cloudflare'); ?>
  4003.         <?php print_external('css-bootstrap'); ?>
  4004.         <?php print_external('css-font-awesome'); ?>
  4005.         <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  4006.             <?php print_external('css-highlightjs'); ?>
  4007.         <?php endif; ?>
  4008.         <script type="text/javascript">
  4009.             window.csrf = '<?php echo $_SESSION['token']; ?>';
  4010.         </script>
  4011.         <style>
  4012.             html {
  4013.                 -moz-osx-font-smoothing: grayscale;
  4014.                 -webkit-font-smoothing: antialiased;
  4015.                 text-rendering: optimizeLegibility;
  4016.                 height: 100%;
  4017.                 scroll-behavior: smooth;
  4018.             }
  4019.  
  4020.             *,
  4021.             *::before,
  4022.             *::after {
  4023.                 box-sizing: border-box;
  4024.             }
  4025.  
  4026.             body {
  4027.                 font-size: 15px;
  4028.                 color: #222;
  4029.                 background: #F7F7F7;
  4030.             }
  4031.  
  4032.             body.navbar-fixed {
  4033.                 margin-top: 55px;
  4034.             }
  4035.  
  4036.             a,
  4037.             a:hover,
  4038.             a:visited,
  4039.             a:focus {
  4040.                 text-decoration: none !important;
  4041.             }
  4042.  
  4043.             .filename,
  4044.             td,
  4045.             th {
  4046.                 white-space: nowrap
  4047.             }
  4048.  
  4049.             .navbar-brand {
  4050.                 font-weight: bold;
  4051.             }
  4052.  
  4053.             .nav-item.avatar a {
  4054.                 cursor: pointer;
  4055.                 text-transform: capitalize;
  4056.             }
  4057.  
  4058.             .nav-item.avatar a>i {
  4059.                 font-size: 15px;
  4060.             }
  4061.  
  4062.             .nav-item.avatar .dropdown-menu a {
  4063.                 font-size: 13px;
  4064.             }
  4065.  
  4066.             #search-addon {
  4067.                 font-size: 12px;
  4068.                 border-right-width: 0;
  4069.             }
  4070.  
  4071.             .brl-0 {
  4072.                 background: transparent;
  4073.                 border-left: 0;
  4074.                 border-top-left-radius: 0;
  4075.                 border-bottom-left-radius: 0;
  4076.             }
  4077.  
  4078.             .brr-0 {
  4079.                 border-top-right-radius: 0;
  4080.                 border-bottom-right-radius: 0;
  4081.             }
  4082.  
  4083.             .bread-crumb {
  4084.                 color: #cccccc;
  4085.                 font-style: normal;
  4086.             }
  4087.  
  4088.             #main-table {
  4089.                 transition: transform .25s cubic-bezier(0.4, 0.5, 0, 1), width 0s .25s;
  4090.             }
  4091.  
  4092.             #main-table .filename a {
  4093.                 color: #222222;
  4094.             }
  4095.  
  4096.             .table td,
  4097.             .table th {
  4098.                 vertical-align: middle !important;
  4099.             }
  4100.  
  4101.             .table .custom-checkbox-td .custom-control.custom-checkbox,
  4102.             .table .custom-checkbox-header .custom-control.custom-checkbox {
  4103.                 min-width: 18px;
  4104.                 display: flex;
  4105.                 align-items: center;
  4106.                 justify-content: center;
  4107.             }
  4108.  
  4109.             .table-sm td,
  4110.             .table-sm th {
  4111.                 padding: .4rem;
  4112.             }
  4113.  
  4114.             .table-bordered td,
  4115.             .table-bordered th {
  4116.                 border: 1px solid #f1f1f1;
  4117.             }
  4118.  
  4119.             .hidden {
  4120.                 display: none
  4121.             }
  4122.  
  4123.             pre.with-hljs {
  4124.                 padding: 0;
  4125.                 overflow: hidden;
  4126.             }
  4127.  
  4128.             pre.with-hljs code {
  4129.                 margin: 0;
  4130.                 border: 0;
  4131.                 overflow: scroll;
  4132.             }
  4133.  
  4134.             code.maxheight,
  4135.             pre.maxheight {
  4136.                 max-height: 512px
  4137.             }
  4138.  
  4139.             .fa.fa-caret-right {
  4140.                 font-size: 1.2em;
  4141.                 margin: 0 4px;
  4142.                 vertical-align: middle;
  4143.                 color: #ececec
  4144.             }
  4145.  
  4146.             .fa.fa-home {
  4147.                 font-size: 1.3em;
  4148.                 vertical-align: bottom
  4149.             }
  4150.  
  4151.             .path {
  4152.                 margin-bottom: 10px
  4153.             }
  4154.  
  4155.             form.dropzone {
  4156.                 min-height: 200px;
  4157.                 border: 2px dashed #007bff;
  4158.                 line-height: 6rem;
  4159.             }
  4160.  
  4161.             .right {
  4162.                 text-align: right
  4163.             }
  4164.  
  4165.             .center,
  4166.             .close,
  4167.             .login-form,
  4168.             .preview-img-container {
  4169.                 text-align: center
  4170.             }
  4171.  
  4172.             .message {
  4173.                 padding: 4px 7px;
  4174.                 border: 1px solid #ddd;
  4175.                 background-color: #fff
  4176.             }
  4177.  
  4178.             .message.ok {
  4179.                 border-color: green;
  4180.                 color: green
  4181.             }
  4182.  
  4183.             .message.error {
  4184.                 border-color: red;
  4185.                 color: red
  4186.             }
  4187.  
  4188.             .message.alert {
  4189.                 border-color: orange;
  4190.                 color: orange
  4191.             }
  4192.  
  4193.             .preview-img {
  4194.                 max-width: 100%;
  4195.                 max-height: 80vh;
  4196.                 background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC);
  4197.                 cursor: zoom-in
  4198.             }
  4199.  
  4200.             input#preview-img-zoomCheck[type=checkbox] {
  4201.                 display: none
  4202.             }
  4203.  
  4204.             input#preview-img-zoomCheck[type=checkbox]:checked~label>img {
  4205.                 max-width: none;
  4206.                 max-height: none;
  4207.                 cursor: zoom-out
  4208.             }
  4209.  
  4210.             .inline-actions>a>i {
  4211.                 font-size: 1em;
  4212.                 margin-left: 5px;
  4213.                 background: #3785c1;
  4214.                 color: #fff;
  4215.                 padding: 3px 4px;
  4216.                 border-radius: 3px;
  4217.             }
  4218.  
  4219.             .preview-video {
  4220.                 position: relative;
  4221.                 max-width: 100%;
  4222.                 height: 0;
  4223.                 padding-bottom: 62.5%;
  4224.                 margin-bottom: 10px
  4225.             }
  4226.  
  4227.             .preview-video video {
  4228.                 position: absolute;
  4229.                 width: 100%;
  4230.                 height: 100%;
  4231.                 left: 0;
  4232.                 top: 0;
  4233.                 background: #000
  4234.             }
  4235.  
  4236.             .compact-table {
  4237.                 border: 0;
  4238.                 width: auto
  4239.             }
  4240.  
  4241.             .compact-table td,
  4242.             .compact-table th {
  4243.                 width: 100px;
  4244.                 border: 0;
  4245.                 text-align: center
  4246.             }
  4247.  
  4248.             .compact-table tr:hover td {
  4249.                 background-color: #fff
  4250.             }
  4251.  
  4252.             .filename {
  4253.                 max-width: 420px;
  4254.                 overflow: hidden;
  4255.                 text-overflow: ellipsis
  4256.             }
  4257.  
  4258.             .break-word {
  4259.                 word-wrap: break-word;
  4260.                 margin-left: 30px
  4261.             }
  4262.  
  4263.             .break-word.float-left a {
  4264.                 color: #7d7d7d
  4265.             }
  4266.  
  4267.             .break-word+.float-right {
  4268.                 padding-right: 30px;
  4269.                 position: relative
  4270.             }
  4271.  
  4272.             .break-word+.float-right>a {
  4273.                 color: #7d7d7d;
  4274.                 font-size: 1.2em;
  4275.                 margin-right: 4px
  4276.             }
  4277.  
  4278.             #editor {
  4279.                 position: absolute;
  4280.                 right: 15px;
  4281.                 top: 100px;
  4282.                 bottom: 15px;
  4283.                 left: 15px
  4284.             }
  4285.  
  4286.             @media (max-width:481px) {
  4287.                 #editor {
  4288.                     top: 150px;
  4289.                 }
  4290.             }
  4291.  
  4292.             #normal-editor {
  4293.                 border-radius: 3px;
  4294.                 border-width: 2px;
  4295.                 padding: 10px;
  4296.                 outline: none;
  4297.             }
  4298.  
  4299.             .btn-2 {
  4300.                 padding: 4px 10px;
  4301.                 font-size: small;
  4302.             }
  4303.  
  4304.             li.file:before,
  4305.             li.folder:before {
  4306.                 font: normal normal normal 14px/1 FontAwesome;
  4307.                 content: "\f016";
  4308.                 margin-right: 5px
  4309.             }
  4310.  
  4311.             li.folder:before {
  4312.                 content: "\f114"
  4313.             }
  4314.  
  4315.             i.fa.fa-folder-o {
  4316.                 color: #0157b3
  4317.             }
  4318.  
  4319.             i.fa.fa-picture-o {
  4320.                 color: #26b99a
  4321.             }
  4322.  
  4323.             i.fa.fa-file-archive-o {
  4324.                 color: #da7d7d
  4325.             }
  4326.  
  4327.             .btn-2 i.fa.fa-file-archive-o {
  4328.                 color: inherit
  4329.             }
  4330.  
  4331.             i.fa.fa-css3 {
  4332.                 color: #f36fa0
  4333.             }
  4334.  
  4335.             i.fa.fa-file-code-o {
  4336.                 color: #007bff
  4337.             }
  4338.  
  4339.             i.fa.fa-code {
  4340.                 color: #cc4b4c
  4341.             }
  4342.  
  4343.             i.fa.fa-file-text-o {
  4344.                 color: #0096e6
  4345.             }
  4346.  
  4347.             i.fa.fa-html5 {
  4348.                 color: #d75e72
  4349.             }
  4350.  
  4351.             i.fa.fa-file-excel-o {
  4352.                 color: #09c55d
  4353.             }
  4354.  
  4355.             i.fa.fa-file-powerpoint-o {
  4356.                 color: #f6712e
  4357.             }
  4358.  
  4359.             i.go-back {
  4360.                 font-size: 1.2em;
  4361.                 color: #007bff;
  4362.             }
  4363.  
  4364.             .main-nav {
  4365.                 padding: 0.2rem 1rem;
  4366.                 box-shadow: 0 4px 5px 0 rgba(0, 0, 0, .14), 0 1px 10px 0 rgba(0, 0, 0, .12), 0 2px 4px -1px rgba(0, 0, 0, .2)
  4367.             }
  4368.  
  4369.             .dataTables_filter {
  4370.                 display: none;
  4371.             }
  4372.  
  4373.             table.dataTable thead .sorting {
  4374.                 cursor: pointer;
  4375.                 background-repeat: no-repeat;
  4376.                 background-position: center right;
  4377.                 background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7XQMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC');
  4378.             }
  4379.  
  4380.             table.dataTable thead .sorting_asc {
  4381.                 cursor: pointer;
  4382.                 background-repeat: no-repeat;
  4383.                 background-position: center right;
  4384.                 background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg==');
  4385.             }
  4386.  
  4387.             table.dataTable thead .sorting_desc {
  4388.                 cursor: pointer;
  4389.                 background-repeat: no-repeat;
  4390.                 background-position: center right;
  4391.                 background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII=');
  4392.             }
  4393.  
  4394.             table.dataTable thead tr:first-child th.custom-checkbox-header:first-child {
  4395.                 background-image: none;
  4396.             }
  4397.  
  4398.             .footer-action li {
  4399.                 margin-bottom: 10px;
  4400.             }
  4401.  
  4402.             .app-v-title {
  4403.                 font-size: 24px;
  4404.                 font-weight: 300;
  4405.                 letter-spacing: -.5px;
  4406.                 text-transform: uppercase;
  4407.             }
  4408.  
  4409.             hr.custom-hr {
  4410.                 border-top: 1px dashed #8c8b8b;
  4411.                 border-bottom: 1px dashed #fff;
  4412.             }
  4413.  
  4414.             #snackbar {
  4415.                 visibility: hidden;
  4416.                 min-width: 250px;
  4417.                 margin-left: -125px;
  4418.                 background-color: #333;
  4419.                 color: #fff;
  4420.                 text-align: center;
  4421.                 border-radius: 2px;
  4422.                 padding: 16px;
  4423.                 position: fixed;
  4424.                 z-index: 1;
  4425.                 left: 50%;
  4426.                 bottom: 30px;
  4427.                 font-size: 17px;
  4428.             }
  4429.  
  4430.             #snackbar.show {
  4431.                 visibility: visible;
  4432.                 -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  4433.                 animation: fadein 0.5s, fadeout 0.5s 2.5s;
  4434.             }
  4435.  
  4436.             @-webkit-keyframes fadein {
  4437.                 from {
  4438.                     bottom: 0;
  4439.                     opacity: 0;
  4440.                 }
  4441.  
  4442.                 to {
  4443.                     bottom: 30px;
  4444.                     opacity: 1;
  4445.                 }
  4446.             }
  4447.  
  4448.             @keyframes fadein {
  4449.                 from {
  4450.                     bottom: 0;
  4451.                     opacity: 0;
  4452.                 }
  4453.  
  4454.                 to {
  4455.                     bottom: 30px;
  4456.                     opacity: 1;
  4457.                 }
  4458.             }
  4459.  
  4460.             @-webkit-keyframes fadeout {
  4461.                 from {
  4462.                     bottom: 30px;
  4463.                     opacity: 1;
  4464.                 }
  4465.  
  4466.                 to {
  4467.                     bottom: 0;
  4468.                     opacity: 0;
  4469.                 }
  4470.             }
  4471.  
  4472.             @keyframes fadeout {
  4473.                 from {
  4474.                     bottom: 30px;
  4475.                     opacity: 1;
  4476.                 }
  4477.  
  4478.                 to {
  4479.                     bottom: 0;
  4480.                     opacity: 0;
  4481.                 }
  4482.             }
  4483.  
  4484.             #main-table span.badge {
  4485.                 border-bottom: 2px solid #f8f9fa
  4486.             }
  4487.  
  4488.             #main-table span.badge:nth-child(1) {
  4489.                 border-color: #df4227
  4490.             }
  4491.  
  4492.             #main-table span.badge:nth-child(2) {
  4493.                 border-color: #f8b600
  4494.             }
  4495.  
  4496.             #main-table span.badge:nth-child(3) {
  4497.                 border-color: #00bd60
  4498.             }
  4499.  
  4500.             #main-table span.badge:nth-child(4) {
  4501.                 border-color: #4581ff
  4502.             }
  4503.  
  4504.             #main-table span.badge:nth-child(5) {
  4505.                 border-color: #ac68fc
  4506.             }
  4507.  
  4508.             #main-table span.badge:nth-child(6) {
  4509.                 border-color: #45c3d2
  4510.             }
  4511.  
  4512.             @media only screen and (min-device-width:768px) and (max-device-width:1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio:2) {
  4513.                 .navbar-collapse .col-xs-6 {
  4514.                     padding: 0;
  4515.                 }
  4516.             }
  4517.  
  4518.             .btn.active.focus,
  4519.             .btn.active:focus,
  4520.             .btn.focus,
  4521.             .btn.focus:active,
  4522.             .btn:active:focus,
  4523.             .btn:focus {
  4524.                 outline: 0 !important;
  4525.                 outline-offset: 0 !important;
  4526.                 background-image: none !important;
  4527.                 -webkit-box-shadow: none !important;
  4528.                 box-shadow: none !important
  4529.             }
  4530.  
  4531.             .lds-facebook {
  4532.                 display: none;
  4533.                 position: relative;
  4534.                 width: 64px;
  4535.                 height: 64px
  4536.             }
  4537.  
  4538.             .lds-facebook div,
  4539.             .lds-facebook.show-me {
  4540.                 display: inline-block
  4541.             }
  4542.  
  4543.             .lds-facebook div {
  4544.                 position: absolute;
  4545.                 left: 6px;
  4546.                 width: 13px;
  4547.                 background: #007bff;
  4548.                 animation: lds-facebook 1.2s cubic-bezier(0, .5, .5, 1) infinite
  4549.             }
  4550.  
  4551.             .lds-facebook div:nth-child(1) {
  4552.                 left: 6px;
  4553.                 animation-delay: -.24s
  4554.             }
  4555.  
  4556.             .lds-facebook div:nth-child(2) {
  4557.                 left: 26px;
  4558.                 animation-delay: -.12s
  4559.             }
  4560.  
  4561.             .lds-facebook div:nth-child(3) {
  4562.                 left: 45px;
  4563.                 animation-delay: 0s
  4564.             }
  4565.  
  4566.             @keyframes lds-facebook {
  4567.                 0% {
  4568.                     top: 6px;
  4569.                     height: 51px
  4570.                 }
  4571.  
  4572.                 100%,
  4573.                 50% {
  4574.                     top: 19px;
  4575.                     height: 26px
  4576.                 }
  4577.             }
  4578.  
  4579.             ul#search-wrapper {
  4580.                 padding-left: 0;
  4581.                 border: 1px solid #ecececcc;
  4582.             }
  4583.  
  4584.             ul#search-wrapper li {
  4585.                 list-style: none;
  4586.                 padding: 5px;
  4587.                 border-bottom: 1px solid #ecececcc;
  4588.             }
  4589.  
  4590.             ul#search-wrapper li:nth-child(odd) {
  4591.                 background: #f9f9f9cc;
  4592.             }
  4593.  
  4594.             .c-preview-img {
  4595.                 max-width: 300px;
  4596.             }
  4597.  
  4598.             .border-radius-0 {
  4599.                 border-radius: 0;
  4600.             }
  4601.  
  4602.             .float-right {
  4603.                 float: right;
  4604.             }
  4605.  
  4606.             .table-hover>tbody>tr:hover>td:first-child {
  4607.                 border-left: 1px solid #1b77fd;
  4608.             }
  4609.  
  4610.             #main-table tr.even {
  4611.                 background-color: #F8F9Fa;
  4612.             }
  4613.  
  4614.             .filename>a>i {
  4615.                 margin-right: 3px;
  4616.             }
  4617.  
  4618.             .fs-7 {
  4619.                 font-size: 14px;
  4620.             }
  4621.         </style>
  4622.         <?php
  4623.         if (FM_THEME == "dark"): ?>
  4624.             <style>
  4625.                 :root {
  4626.                     --bs-bg-opacity: 1;
  4627.                     --bg-color: #f3daa6;
  4628.                     --bs-dark-rgb: 28, 36, 41 !important;
  4629.                     --bs-bg-opacity: 1;
  4630.                 }
  4631.  
  4632.                 body.theme-dark {
  4633.                     background-image: linear-gradient(90deg, #1c2429, #263238);
  4634.                     color: #CFD8DC;
  4635.                 }
  4636.  
  4637.                 .list-group .list-group-item {
  4638.                     background: #343a40;
  4639.                 }
  4640.  
  4641.                 .theme-dark .navbar-nav i,
  4642.                 .navbar-nav .dropdown-toggle,
  4643.                 .break-word {
  4644.                     color: #CFD8DC;
  4645.                 }
  4646.  
  4647.                 a,
  4648.                 a:hover,
  4649.                 a:visited,
  4650.                 a:active,
  4651.                 #main-table .filename a,
  4652.                 i.fa.fa-folder-o,
  4653.                 i.go-back {
  4654.                     color: var(--bg-color);
  4655.                 }
  4656.  
  4657.                 ul#search-wrapper li:nth-child(odd) {
  4658.                     background: #212a2f;
  4659.                 }
  4660.  
  4661.                 .theme-dark .btn-outline-primary {
  4662.                     color: #b8e59c;
  4663.                     border-color: #b8e59c;
  4664.                 }
  4665.  
  4666.                 .theme-dark .btn-outline-primary:hover,
  4667.                 .theme-dark .btn-outline-primary:active {
  4668.                     background-color: #2d4121;
  4669.                 }
  4670.  
  4671.                 .theme-dark input.form-control {
  4672.                     background-color: #101518;
  4673.                     color: #CFD8DC;
  4674.                 }
  4675.  
  4676.                 .theme-dark .dropzone {
  4677.                     background: transparent;
  4678.                 }
  4679.  
  4680.                 .theme-dark .inline-actions>a>i {
  4681.                     background: #79755e;
  4682.                 }
  4683.  
  4684.                 .theme-dark .text-white {
  4685.                     color: #CFD8DC !important;
  4686.                 }
  4687.  
  4688.                 .theme-dark .table-bordered td,
  4689.                 .table-bordered th {
  4690.                     border-color: #343434;
  4691.                 }
  4692.  
  4693.                 .theme-dark .table-bordered td .custom-control-input,
  4694.                 .theme-dark .table-bordered th .custom-control-input {
  4695.                     opacity: 0.678;
  4696.                 }
  4697.  
  4698.                 .message {
  4699.                     background-color: #212529;
  4700.                 }
  4701.  
  4702.                 form.dropzone {
  4703.                     border-color: #79755e;
  4704.                 }
  4705.             </style>
  4706.         <?php endif; ?>
  4707.     </head>
  4708.  
  4709.     <body class="<?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?> <?php echo $isStickyNavBar; ?>">
  4710.         <div id="wrapper" class="container-fluid">
  4711.             <!-- New Item creation -->
  4712.             <div class="modal fade" id="createNewItem" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false" aria-labelledby="newItemModalLabel" aria-hidden="true" data-bs-theme="<?php echo FM_THEME; ?>">
  4713.                 <div class="modal-dialog" role="document">
  4714.                     <form class="modal-content" method="post">
  4715.                         <div class="modal-header">
  4716.                             <h5 class="modal-title" id="newItemModalLabel"><i class="fa fa-plus-square fa-fw"></i><?php echo lng('CreateNewItem') ?></h5>
  4717.                             <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  4718.                         </div>
  4719.                         <div class="modal-body">
  4720.                             <p><label for="newfile"><?php echo lng('ItemType') ?> </label></p>
  4721.                             <div class="form-check form-check-inline">
  4722.                                 <input class="form-check-input" type="radio" name="newfile" id="customRadioInline1" name="newfile" value="file">
  4723.                                 <label class="form-check-label" for="customRadioInline1"><?php echo lng('File') ?></label>
  4724.                             </div>
  4725.                             <div class="form-check form-check-inline">
  4726.                                 <input class="form-check-input" type="radio" name="newfile" id="customRadioInline2" value="folder" checked>
  4727.                                 <label class="form-check-label" for="customRadioInline2"><?php echo lng('Folder') ?></label>
  4728.                             </div>
  4729.  
  4730.                             <p class="mt-3"><label for="newfilename"><?php echo lng('ItemName') ?> </label></p>
  4731.                             <input type="text" name="newfilename" id="newfilename" value="" class="form-control" placeholder="<?php echo lng('Enter here...') ?>" required>
  4732.                         </div>
  4733.                         <div class="modal-footer">
  4734.                             <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4735.                             <button type="button" class="btn btn-outline-primary" data-bs-dismiss="modal"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></button>
  4736.                             <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('CreateNow') ?></button>
  4737.                         </div>
  4738.                     </form>
  4739.                 </div>
  4740.             </div>
  4741.  
  4742.             <!-- Advance Search Modal -->
  4743.             <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true" data-bs-theme="<?php echo FM_THEME; ?>">
  4744.                 <div class="modal-dialog modal-lg" role="document">
  4745.                     <div class="modal-content">
  4746.                         <div class="modal-header">
  4747.                             <h5 class="modal-title col-10" id="searchModalLabel">
  4748.                                 <div class="input-group mb-3">
  4749.                                     <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?> <?php echo lng('a files') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon3" id="advanced-search" autofocus required>
  4750.                                     <span class="input-group-text" id="search-addon3"><i class="fa fa-search"></i></span>
  4751.                                 </div>
  4752.                             </h5>
  4753.                             <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  4754.                         </div>
  4755.                         <div class="modal-body">
  4756.                             <form action="" method="post">
  4757.                                 <div class="lds-facebook">
  4758.                                     <div></div>
  4759.                                     <div></div>
  4760.                                     <div></div>
  4761.                                 </div>
  4762.                                 <ul id="search-wrapper">
  4763.                                     <p class="m-2"><?php echo lng('Search file in folder and subfolders...') ?></p>
  4764.                                 </ul>
  4765.                             </form>
  4766.                         </div>
  4767.                     </div>
  4768.                 </div>
  4769.             </div>
  4770.  
  4771.             <!--Rename Modal -->
  4772.             <div class="modal modal-alert" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="renameDailog" data-bs-theme="<?php echo FM_THEME; ?>">
  4773.                 <div class="modal-dialog" role="document">
  4774.                     <form class="modal-content rounded-3 shadow" method="post" autocomplete="off">
  4775.                         <div class="modal-body p-4 text-center">
  4776.                             <h5 class="mb-3"><?php echo lng('Are you sure want to rename?') ?></h5>
  4777.                             <p class="mb-1">
  4778.                                 <input type="text" name="rename_to" id="js-rename-to" class="form-control" placeholder="<?php echo lng('Enter new file name') ?>" required>
  4779.                                 <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4780.                                 <input type="hidden" name="rename_from" id="js-rename-from">
  4781.                             </p>
  4782.                         </div>
  4783.                         <div class="modal-footer flex-nowrap p-0">
  4784.                             <button type="button" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0 border-end" data-bs-dismiss="modal"><?php echo lng('Cancel') ?></button>
  4785.                             <button type="submit" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0"><strong><?php echo lng('Okay') ?></strong></button>
  4786.                         </div>
  4787.                     </form>
  4788.                 </div>
  4789.             </div>
  4790.  
  4791.             <!-- Confirm Modal -->
  4792.             <script type="text/html" id="js-tpl-confirm">
  4793.                 <div class="modal modal-alert confirmDailog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="confirmDailog-<%this.id%>" data-bs-theme="<?php echo FM_THEME; ?>">
  4794.                     <div class="modal-dialog" role="document">
  4795.                         <form class="modal-content rounded-3 shadow" method="post" autocomplete="off" action="<%this.action%>">
  4796.                             <div class="modal-body p-4 text-center">
  4797.                                 <h5 class="mb-2"><?php echo lng('Are you sure want to') ?> <%this.title%> ?</h5>
  4798.                                 <p class="mb-1"><%this.content%></p>
  4799.                             </div>
  4800.                             <div class="modal-footer flex-nowrap p-0">
  4801.                                 <button type="button" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0 border-end" data-bs-dismiss="modal"><?php echo lng('Cancel') ?></button>
  4802.                                 <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  4803.                                 <button type="submit" class="btn btn-lg btn-link fs-6 text-decoration-none col-6 m-0 rounded-0" data-bs-dismiss="modal"><strong><?php echo lng('Okay') ?></strong></button>
  4804.                             </div>
  4805.                         </form>
  4806.                     </div>
  4807.                 </div>
  4808.             </script>
  4809.         <?php
  4810.     }
  4811.  
  4812.     /**
  4813.      * Show page footer after login
  4814.      */
  4815.     function fm_show_footer()
  4816.     {
  4817.         ?>
  4818.         </div>
  4819.         <?php print_external('js-jquery'); ?>
  4820.         <?php print_external('js-bootstrap'); ?>
  4821.         <?php print_external('js-jquery-datatables'); ?>
  4822.         <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  4823.             <?php print_external('js-highlightjs'); ?>
  4824.             <script>
  4825.                 hljs.highlightAll();
  4826.                 var isHighlightingEnabled = true;
  4827.             </script>
  4828.         <?php endif; ?>
  4829.         <script>
  4830.             function template(html, options) {
  4831.                 var re = /<\%([^\%>]+)?\%>/g,
  4832.                     reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,
  4833.                     code = 'var r=[];\n',
  4834.                     cursor = 0,
  4835.                     match;
  4836.                 var add = function(line, js) {
  4837.                     js ? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
  4838.                     return add
  4839.                 }
  4840.                 while (match = re.exec(html)) {
  4841.                     add(html.slice(cursor, match.index))(match[1], !0);
  4842.                     cursor = match.index + match[0].length
  4843.                 }
  4844.                 add(html.substr(cursor, html.length - cursor));
  4845.                 code += 'return r.join("");';
  4846.                 return new Function(code.replace(/[\r\t\n]/g, '')).apply(options)
  4847.             }
  4848.  
  4849.             function rename(e, t) {
  4850.                 if (t) {
  4851.                     $("#js-rename-from").val(t);
  4852.                     $("#js-rename-to").val(t);
  4853.                     $("#renameDailog").modal('show');
  4854.                 }
  4855.             }
  4856.  
  4857.             function change_checkboxes(e, t) {
  4858.                 for (var n = e.length - 1; n >= 0; n--) e[n].checked = "boolean" == typeof t ? t : !e[n].checked
  4859.             }
  4860.  
  4861.             function get_checkboxes() {
  4862.                 for (var e = document.getElementsByName("file[]"), t = [], n = e.length - 1; n >= 0; n--)(e[n].type = "checkbox") && t.push(e[n]);
  4863.                 return t
  4864.             }
  4865.  
  4866.             function select_all() {
  4867.                 change_checkboxes(get_checkboxes(), !0)
  4868.             }
  4869.  
  4870.             function unselect_all() {
  4871.                 change_checkboxes(get_checkboxes(), !1)
  4872.             }
  4873.  
  4874.             function invert_all() {
  4875.                 change_checkboxes(get_checkboxes())
  4876.             }
  4877.  
  4878.             function checkbox_toggle() {
  4879.                 var e = get_checkboxes();
  4880.                 e.push(this), change_checkboxes(e)
  4881.             }
  4882.  
  4883.             // Create file backup with .bck
  4884.             function backup(e, t) {
  4885.                 var n = new XMLHttpRequest,
  4886.                     a = "path=" + e + "&file=" + t + "&token=" + window.csrf + "&type=backup&ajax=true";
  4887.                 return n.open("POST", "", !0), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.onreadystatechange = function() {
  4888.                     4 == n.readyState && 200 == n.status && toast(n.responseText)
  4889.                 }, n.send(a), !1
  4890.             }
  4891.  
  4892.             // Toast message
  4893.             function toast(txt) {
  4894.                 var x = document.getElementById("snackbar");
  4895.                 x.innerHTML = txt;
  4896.                 x.className = "show";
  4897.                 setTimeout(function() {
  4898.                     x.className = x.className.replace("show", "");
  4899.                 }, 3000);
  4900.             }
  4901.  
  4902.             // Save file
  4903.             function edit_save(e, t) {
  4904.                 var n = "ace" == t ? editor.getSession().getValue() : document.getElementById("normal-editor").value;
  4905.                 if (typeof n !== 'undefined' && n !== null) {
  4906.                     if (true) {
  4907.                         var data = {
  4908.                             ajax: true,
  4909.                             content: n,
  4910.                             type: 'save',
  4911.                             token: window.csrf
  4912.                         };
  4913.  
  4914.                         $.ajax({
  4915.                             type: "POST",
  4916.                             url: window.location,
  4917.                             data: JSON.stringify(data),
  4918.                             contentType: "application/json; charset=utf-8",
  4919.                             success: function(mes) {
  4920.                                 toast("Saved Successfully");
  4921.                                 window.onbeforeunload = function() {
  4922.                                     return
  4923.                                 }
  4924.                             },
  4925.                             failure: function(mes) {
  4926.                                 toast("Error: try again");
  4927.                             },
  4928.                             error: function(mes) {
  4929.                                 toast(`<p style="background-color:red">${mes.responseText}</p>`);
  4930.                             }
  4931.                         });
  4932.                     } else {
  4933.                         var a = document.createElement("form");
  4934.                         a.setAttribute("method", "POST"), a.setAttribute("action", "");
  4935.                         var o = document.createElement("textarea");
  4936.                         o.setAttribute("type", "textarea"), o.setAttribute("name", "savedata");
  4937.                         let cx = document.createElement("input");
  4938.                         cx.setAttribute("type", "hidden");
  4939.                         cx.setAttribute("name", "token");
  4940.                         cx.setAttribute("value", window.csrf);
  4941.                         var c = document.createTextNode(n);
  4942.                         o.appendChild(c), a.appendChild(o), a.appendChild(cx), document.body.appendChild(a), a.submit()
  4943.                     }
  4944.                 }
  4945.             }
  4946.  
  4947.             function show_new_pwd() {
  4948.                 $(".js-new-pwd").toggleClass('hidden');
  4949.             }
  4950.  
  4951.             // Save Settings
  4952.             function save_settings($this) {
  4953.                 let form = $($this);
  4954.                 $.ajax({
  4955.                     type: form.attr('method'),
  4956.                     url: form.attr('action'),
  4957.                     data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4958.                     success: function(data) {
  4959.                         if (data) {
  4960.                             window.location.reload();
  4961.                         }
  4962.                     }
  4963.                 });
  4964.                 return false;
  4965.             }
  4966.  
  4967.             //Create new password hash
  4968.             function new_password_hash($this) {
  4969.                 let form = $($this),
  4970.                     $pwd = $("#js-pwd-result");
  4971.                 $pwd.val('');
  4972.                 $.ajax({
  4973.                     type: form.attr('method'),
  4974.                     url: form.attr('action'),
  4975.                     data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4976.                     success: function(data) {
  4977.                         if (data) {
  4978.                             $pwd.val(data);
  4979.                         }
  4980.                     }
  4981.                 });
  4982.                 return false;
  4983.             }
  4984.  
  4985.             // Upload files using URL @param {Object}
  4986.             function upload_from_url($this) {
  4987.                 let form = $($this),
  4988.                     resultWrapper = $("div#js-url-upload__list");
  4989.                 $.ajax({
  4990.                     type: form.attr('method'),
  4991.                     url: form.attr('action'),
  4992.                     data: form.serialize() + "&token=" + window.csrf + "&ajax=" + true,
  4993.                     beforeSend: function() {
  4994.                         form.find("input[name=uploadurl]").attr("disabled", "disabled");
  4995.                         form.find("button").hide();
  4996.                         form.find(".lds-facebook").addClass('show-me');
  4997.                     },
  4998.                     success: function(data) {
  4999.                         if (data) {
  5000.                             data = JSON.parse(data);
  5001.                             if (data.done) {
  5002.                                 resultWrapper.append('<div class="alert alert-success row">Uploaded Successful: ' + data.done.name + '</div>');
  5003.                                 form.find("input[name=uploadurl]").val('');
  5004.                             } else if (data['fail']) {
  5005.                                 resultWrapper.append('<div class="alert alert-danger row">Error: ' + data.fail.message + '</div>');
  5006.                             }
  5007.                             form.find("input[name=uploadurl]").removeAttr("disabled");
  5008.                             form.find("button").show();
  5009.                             form.find(".lds-facebook").removeClass('show-me');
  5010.                         }
  5011.                     },
  5012.                     error: function(xhr) {
  5013.                         form.find("input[name=uploadurl]").removeAttr("disabled");
  5014.                         form.find("button").show();
  5015.                         form.find(".lds-facebook").removeClass('show-me');
  5016.                         console.error(xhr);
  5017.                     }
  5018.                 });
  5019.                 return false;
  5020.             }
  5021.  
  5022.             // Search template
  5023.             function search_template(data) {
  5024.                 var response = "";
  5025.                 $.each(data, function(key, val) {
  5026.                     response += `<li><a href="?p=${val.path}&view=${val.name}">${val.path}/${val.name}</a></li>`;
  5027.                 });
  5028.                 return response;
  5029.             }
  5030.  
  5031.             // Advance search
  5032.             function fm_search() {
  5033.                 var searchTxt = $("input#advanced-search").val(),
  5034.                     searchWrapper = $("ul#search-wrapper"),
  5035.                     path = $("#js-search-modal").attr("href"),
  5036.                     _html = "",
  5037.                     $loader = $("div.lds-facebook");
  5038.                 if (!!searchTxt && searchTxt.length > 2 && path) {
  5039.                     var data = {
  5040.                         ajax: true,
  5041.                         content: searchTxt,
  5042.                         path: path,
  5043.                         type: 'search',
  5044.                         token: window.csrf
  5045.                     };
  5046.                     $.ajax({
  5047.                         type: "POST",
  5048.                         url: window.location,
  5049.                         data: data,
  5050.                         beforeSend: function() {
  5051.                             searchWrapper.html('');
  5052.                             $loader.addClass('show-me');
  5053.                         },
  5054.                         success: function(data) {
  5055.                             $loader.removeClass('show-me');
  5056.                             data = JSON.parse(data);
  5057.                             if (data && data.length) {
  5058.                                 _html = search_template(data);
  5059.                                 searchWrapper.html(_html);
  5060.                             } else {
  5061.                                 searchWrapper.html('<p class="m-2">No result found!<p>');
  5062.                             }
  5063.                         },
  5064.                         error: function(xhr) {
  5065.                             $loader.removeClass('show-me');
  5066.                             searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>');
  5067.                         },
  5068.                         failure: function(mes) {
  5069.                             $loader.removeClass('show-me');
  5070.                             searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>');
  5071.                         }
  5072.                     });
  5073.                 } else {
  5074.                     searchWrapper.html("OOPS: minimum 3 characters required!");
  5075.                 }
  5076.             }
  5077.  
  5078.             // action confirm dailog modal
  5079.             function confirmDailog(e, id = 0, title = "Action", content = "", action = null) {
  5080.                 e.preventDefault();
  5081.                 const tplObj = {
  5082.                     id,
  5083.                     title,
  5084.                     content: decodeURIComponent(content.replace(/\+/g, ' ')),
  5085.                     action
  5086.                 };
  5087.                 let tpl = $("#js-tpl-confirm").html();
  5088.                 $(".modal.confirmDailog").remove();
  5089.                 $('#wrapper').append(template(tpl, tplObj));
  5090.                 const $confirmDailog = $("#confirmDailog-" + tplObj.id);
  5091.                 $confirmDailog.modal('show');
  5092.                 return false;
  5093.             }
  5094.  
  5095.             // on mouse hover image preview
  5096.             ! function(s) {
  5097.                 s.previewImage = function(e) {
  5098.                     var o = s(document),
  5099.                         t = ".previewImage",
  5100.                         a = s.extend({
  5101.                             xOffset: 20,
  5102.                             yOffset: -20,
  5103.                             fadeIn: "fast",
  5104.                             css: {
  5105.                                 padding: "5px",
  5106.                                 border: "1px solid #cccccc",
  5107.                                 "background-color": "#fff"
  5108.                             },
  5109.                             eventSelector: "[data-preview-image]",
  5110.                             dataKey: "previewImage",
  5111.                             overlayId: "preview-image-plugin-overlay"
  5112.                         }, e);
  5113.                     return o.off(t), o.on("mouseover" + t, a.eventSelector, function(e) {
  5114.                         s("p#" + a.overlayId).remove();
  5115.                         var o = s("<p>").attr("id", a.overlayId).css("position", "absolute").css("display", "none").append(s('<img class="c-preview-img">').attr("src", s(this).data(a.dataKey)));
  5116.                         a.css && o.css(a.css), s("body").append(o), o.css("top", e.pageY + a.yOffset + "px").css("left", e.pageX + a.xOffset + "px").fadeIn(a.fadeIn)
  5117.                     }), o.on("mouseout" + t, a.eventSelector, function() {
  5118.                         s("#" + a.overlayId).remove()
  5119.                     }), o.on("mousemove" + t, a.eventSelector, function(e) {
  5120.                         s("#" + a.overlayId).css("top", e.pageY + a.yOffset + "px").css("left", e.pageX + a.xOffset + "px")
  5121.                     }), this
  5122.                 }, s.previewImage()
  5123.             }(jQuery);
  5124.  
  5125.             // Dom Ready Events
  5126.             $(document).ready(function() {
  5127.                 // dataTable init
  5128.                 var $table = $('#main-table'),
  5129.                     tableLng = $table.find('th').length,
  5130.                     _targets = (tableLng && tableLng == 7) ? [0, 4, 5, 6] : tableLng == 5 ? [0, 4] : [3];
  5131.                 mainTable = $('#main-table').DataTable({
  5132.                     paging: false,
  5133.                     info: false,
  5134.                     order: [],
  5135.                     columnDefs: [{
  5136.                         targets: _targets,
  5137.                         orderable: false
  5138.                     }]
  5139.                 });
  5140.  
  5141.                 // filter table
  5142.                 $('#search-addon').on('keyup', function() {
  5143.                     mainTable.search(this.value).draw();
  5144.                 });
  5145.  
  5146.                 $("input#advanced-search").on('keyup', function(e) {
  5147.                     if (e.keyCode === 13) {
  5148.                         fm_search();
  5149.                     }
  5150.                 });
  5151.  
  5152.                 $('#search-addon3').on('click', function() {
  5153.                     fm_search();
  5154.                 });
  5155.  
  5156.                 //upload nav tabs
  5157.                 $(".fm-upload-wrapper .card-header-tabs").on("click", 'a', function(e) {
  5158.                     e.preventDefault();
  5159.                     let target = $(this).data('target');
  5160.                     $(".fm-upload-wrapper .card-header-tabs a").removeClass('active');
  5161.                     $(this).addClass('active');
  5162.                     $(".fm-upload-wrapper .card-tabs-container").addClass('hidden');
  5163.                     $(target).removeClass('hidden');
  5164.                 });
  5165.             });
  5166.         </script>
  5167.  
  5168.         <?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE && !FM_READONLY):
  5169.             $ext = pathinfo($_GET["edit"], PATHINFO_EXTENSION);
  5170.             $ext =  $ext == "js" ? "javascript" :  $ext;
  5171.         ?>
  5172.             <?php print_external('js-ace'); ?>
  5173.             <script>
  5174.                 var editor = ace.edit("editor");
  5175.                 editor.getSession().setMode({
  5176.                     path: "ace/mode/<?php echo $ext; ?>",
  5177.                     inline: true
  5178.                 });
  5179.                 //editor.setTheme("ace/theme/twilight"); // Dark Theme
  5180.                 editor.setShowPrintMargin(false); // Hide the vertical ruler
  5181.                 function ace_commend(cmd) {
  5182.                     editor.commands.exec(cmd, editor);
  5183.                 }
  5184.                 editor.commands.addCommands([{
  5185.                     name: 'save',
  5186.                     bindKey: {
  5187.                         win: 'Ctrl-S',
  5188.                         mac: 'Command-S'
  5189.                     },
  5190.                     exec: function(editor) {
  5191.                         edit_save(this, 'ace');
  5192.                     }
  5193.                 }]);
  5194.  
  5195.                 function renderThemeMode() {
  5196.                     var $modeEl = $("select#js-ace-mode"),
  5197.                         $themeEl = $("select#js-ace-theme"),
  5198.                         $fontSizeEl = $("select#js-ace-fontSize"),
  5199.                         optionNode = function(type, arr) {
  5200.                             var $Option = "";
  5201.                             $.each(arr, function(i, val) {
  5202.                                 $Option += "<option value='" + type + i + "'>" + val + "</option>";
  5203.                             });
  5204.                             return $Option;
  5205.                         },
  5206.                         _data = {
  5207.                             "aceTheme": {
  5208.                                 "bright": {
  5209.                                     "chrome": "Chrome",
  5210.                                     "clouds": "Clouds",
  5211.                                     "crimson_editor": "Crimson Editor",
  5212.                                     "dawn": "Dawn",
  5213.                                     "dreamweaver": "Dreamweaver",
  5214.                                     "eclipse": "Eclipse",
  5215.                                     "github": "GitHub",
  5216.                                     "iplastic": "IPlastic",
  5217.                                     "solarized_light": "Solarized Light",
  5218.                                     "textmate": "TextMate",
  5219.                                     "tomorrow": "Tomorrow",
  5220.                                     "xcode": "XCode",
  5221.                                     "kuroir": "Kuroir",
  5222.                                     "katzenmilch": "KatzenMilch",
  5223.                                     "sqlserver": "SQL Server"
  5224.                                 },
  5225.                                 "dark": {
  5226.                                     "ambiance": "Ambiance",
  5227.                                     "chaos": "Chaos",
  5228.                                     "clouds_midnight": "Clouds Midnight",
  5229.                                     "dracula": "Dracula",
  5230.                                     "cobalt": "Cobalt",
  5231.                                     "gruvbox": "Gruvbox",
  5232.                                     "gob": "Green on Black",
  5233.                                     "idle_fingers": "idle Fingers",
  5234.                                     "kr_theme": "krTheme",
  5235.                                     "merbivore": "Merbivore",
  5236.                                     "merbivore_soft": "Merbivore Soft",
  5237.                                     "mono_industrial": "Mono Industrial",
  5238.                                     "monokai": "Monokai",
  5239.                                     "pastel_on_dark": "Pastel on dark",
  5240.                                     "solarized_dark": "Solarized Dark",
  5241.                                     "terminal": "Terminal",
  5242.                                     "tomorrow_night": "Tomorrow Night",
  5243.                                     "tomorrow_night_blue": "Tomorrow Night Blue",
  5244.                                     "tomorrow_night_bright": "Tomorrow Night Bright",
  5245.                                     "tomorrow_night_eighties": "Tomorrow Night 80s",
  5246.                                     "twilight": "Twilight",
  5247.                                     "vibrant_ink": "Vibrant Ink"
  5248.                                 }
  5249.                             },
  5250.                             "aceMode": {
  5251.                                 "javascript": "JavaScript",
  5252.                                 "abap": "ABAP",
  5253.                                 "abc": "ABC",
  5254.                                 "actionscript": "ActionScript",
  5255.                                 "ada": "ADA",
  5256.                                 "apache_conf": "Apache Conf",
  5257.                                 "asciidoc": "AsciiDoc",
  5258.                                 "asl": "ASL",
  5259.                                 "assembly_x86": "Assembly x86",
  5260.                                 "autohotkey": "AutoHotKey",
  5261.                                 "apex": "Apex",
  5262.                                 "batchfile": "BatchFile",
  5263.                                 "bro": "Bro",
  5264.                                 "c_cpp": "C and C++",
  5265.                                 "c9search": "C9Search",
  5266.                                 "cirru": "Cirru",
  5267.                                 "clojure": "Clojure",
  5268.                                 "cobol": "Cobol",
  5269.                                 "coffee": "CoffeeScript",
  5270.                                 "coldfusion": "ColdFusion",
  5271.                                 "csharp": "C#",
  5272.                                 "csound_document": "Csound Document",
  5273.                                 "csound_orchestra": "Csound",
  5274.                                 "csound_score": "Csound Score",
  5275.                                 "css": "CSS",
  5276.                                 "curly": "Curly",
  5277.                                 "d": "D",
  5278.                                 "dart": "Dart",
  5279.                                 "diff": "Diff",
  5280.                                 "dockerfile": "Dockerfile",
  5281.                                 "dot": "Dot",
  5282.                                 "drools": "Drools",
  5283.                                 "edifact": "Edifact",
  5284.                                 "eiffel": "Eiffel",
  5285.                                 "ejs": "EJS",
  5286.                                 "elixir": "Elixir",
  5287.                                 "elm": "Elm",
  5288.                                 "erlang": "Erlang",
  5289.                                 "forth": "Forth",
  5290.                                 "fortran": "Fortran",
  5291.                                 "fsharp": "FSharp",
  5292.                                 "fsl": "FSL",
  5293.                                 "ftl": "FreeMarker",
  5294.                                 "gcode": "Gcode",
  5295.                                 "gherkin": "Gherkin",
  5296.                                 "gitignore": "Gitignore",
  5297.                                 "glsl": "Glsl",
  5298.                                 "gobstones": "Gobstones",
  5299.                                 "golang": "Go",
  5300.                                 "graphqlschema": "GraphQLSchema",
  5301.                                 "groovy": "Groovy",
  5302.                                 "haml": "HAML",
  5303.                                 "handlebars": "Handlebars",
  5304.                                 "haskell": "Haskell",
  5305.                                 "haskell_cabal": "Haskell Cabal",
  5306.                                 "haxe": "haXe",
  5307.                                 "hjson": "Hjson",
  5308.                                 "html": "HTML",
  5309.                                 "html_elixir": "HTML (Elixir)",
  5310.                                 "html_ruby": "HTML (Ruby)",
  5311.                                 "ini": "INI",
  5312.                                 "io": "Io",
  5313.                                 "jack": "Jack",
  5314.                                 "jade": "Jade",
  5315.                                 "java": "Java",
  5316.                                 "json": "JSON",
  5317.                                 "jsoniq": "JSONiq",
  5318.                                 "jsp": "JSP",
  5319.                                 "jssm": "JSSM",
  5320.                                 "jsx": "JSX",
  5321.                                 "julia": "Julia",
  5322.                                 "kotlin": "Kotlin",
  5323.                                 "latex": "LaTeX",
  5324.                                 "less": "LESS",
  5325.                                 "liquid": "Liquid",
  5326.                                 "lisp": "Lisp",
  5327.                                 "livescript": "LiveScript",
  5328.                                 "logiql": "LogiQL",
  5329.                                 "lsl": "LSL",
  5330.                                 "lua": "Lua",
  5331.                                 "luapage": "LuaPage",
  5332.                                 "lucene": "Lucene",
  5333.                                 "makefile": "Makefile",
  5334.                                 "markdown": "Markdown",
  5335.                                 "mask": "Mask",
  5336.                                 "matlab": "MATLAB",
  5337.                                 "maze": "Maze",
  5338.                                 "mel": "MEL",
  5339.                                 "mixal": "MIXAL",
  5340.                                 "mushcode": "MUSHCode",
  5341.                                 "mysql": "MySQL",
  5342.                                 "nix": "Nix",
  5343.                                 "nsis": "NSIS",
  5344.                                 "objectivec": "Objective-C",
  5345.                                 "ocaml": "OCaml",
  5346.                                 "pascal": "Pascal",
  5347.                                 "perl": "Perl",
  5348.                                 "perl6": "Perl 6",
  5349.                                 "pgsql": "pgSQL",
  5350.                                 "php_laravel_blade": "PHP (Blade Template)",
  5351.                                 "php": "PHP",
  5352.                                 "puppet": "Puppet",
  5353.                                 "pig": "Pig",
  5354.                                 "powershell": "Powershell",
  5355.                                 "praat": "Praat",
  5356.                                 "prolog": "Prolog",
  5357.                                 "properties": "Properties",
  5358.                                 "protobuf": "Protobuf",
  5359.                                 "python": "Python",
  5360.                                 "r": "R",
  5361.                                 "razor": "Razor",
  5362.                                 "rdoc": "RDoc",
  5363.                                 "red": "Red",
  5364.                                 "rhtml": "RHTML",
  5365.                                 "rst": "RST",
  5366.                                 "ruby": "Ruby",
  5367.                                 "rust": "Rust",
  5368.                                 "sass": "SASS",
  5369.                                 "scad": "SCAD",
  5370.                                 "scala": "Scala",
  5371.                                 "scheme": "Scheme",
  5372.                                 "scss": "SCSS",
  5373.                                 "sh": "SH",
  5374.                                 "sjs": "SJS",
  5375.                                 "slim": "Slim",
  5376.                                 "smarty": "Smarty",
  5377.                                 "snippets": "snippets",
  5378.                                 "soy_template": "Soy Template",
  5379.                                 "space": "Space",
  5380.                                 "sql": "SQL",
  5381.                                 "sqlserver": "SQLServer",
  5382.                                 "stylus": "Stylus",
  5383.                                 "svg": "SVG",
  5384.                                 "swift": "Swift",
  5385.                                 "tcl": "Tcl",
  5386.                                 "terraform": "Terraform",
  5387.                                 "tex": "Tex",
  5388.                                 "text": "Text",
  5389.                                 "textile": "Textile",
  5390.                                 "toml": "Toml",
  5391.                                 "tsx": "TSX",
  5392.                                 "twig": "Twig",
  5393.                                 "typescript": "Typescript",
  5394.                                 "vala": "Vala",
  5395.                                 "vbscript": "VBScript",
  5396.                                 "velocity": "Velocity",
  5397.                                 "verilog": "Verilog",
  5398.                                 "vhdl": "VHDL",
  5399.                                 "visualforce": "Visualforce",
  5400.                                 "wollok": "Wollok",
  5401.                                 "xml": "XML",
  5402.                                 "xquery": "XQuery",
  5403.                                 "yaml": "YAML",
  5404.                                 "django": "Django"
  5405.                             },
  5406.                             "fontSize": {
  5407.                                 8: 8,
  5408.                                 10: 10,
  5409.                                 11: 11,
  5410.                                 12: 12,
  5411.                                 13: 13,
  5412.                                 14: 14,
  5413.                                 15: 15,
  5414.                                 16: 16,
  5415.                                 17: 17,
  5416.                                 18: 18,
  5417.                                 20: 20,
  5418.                                 22: 22,
  5419.                                 24: 24,
  5420.                                 26: 26,
  5421.                                 30: 30
  5422.                             }
  5423.                         };
  5424.                     if (_data && _data.aceMode) {
  5425.                         $modeEl.html(optionNode("ace/mode/", _data.aceMode));
  5426.                     }
  5427.                     if (_data && _data.aceTheme) {
  5428.                         var lightTheme = optionNode("ace/theme/", _data.aceTheme.bright),
  5429.                             darkTheme = optionNode("ace/theme/", _data.aceTheme.dark);
  5430.                         $themeEl.html("<optgroup label=\"Bright\">" + lightTheme + "</optgroup><optgroup label=\"Dark\">" + darkTheme + "</optgroup>");
  5431.                     }
  5432.                     if (_data && _data.fontSize) {
  5433.                         $fontSizeEl.html(optionNode("", _data.fontSize));
  5434.                     }
  5435.                     $modeEl.val(editor.getSession().$modeId);
  5436.                     $themeEl.val(editor.getTheme());
  5437.                     $(function() {
  5438.                         //set default font size in drop down
  5439.                         $fontSizeEl.val(12).change();
  5440.                     });
  5441.                 }
  5442.  
  5443.                 $(function() {
  5444.                     renderThemeMode();
  5445.                     $(".js-ace-toolbar").on("click", 'button', function(e) {
  5446.                         e.preventDefault();
  5447.                         let cmdValue = $(this).attr("data-cmd"),
  5448.                             editorOption = $(this).attr("data-option");
  5449.                         if (cmdValue && cmdValue != "none") {
  5450.                             ace_commend(cmdValue);
  5451.                         } else if (editorOption) {
  5452.                             if (editorOption == "fullscreen") {
  5453.                                 (void 0 !== document.fullScreenElement && null === document.fullScreenElement || void 0 !== document.msFullscreenElement && null === document.msFullscreenElement || void 0 !== document.mozFullScreen && !document.mozFullScreen || void 0 !== document.webkitIsFullScreen && !document.webkitIsFullScreen) &&
  5454.                                 (editor.container.requestFullScreen ? editor.container.requestFullScreen() : editor.container.mozRequestFullScreen ? editor.container.mozRequestFullScreen() : editor.container.webkitRequestFullScreen ? editor.container.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT) : editor.container.msRequestFullscreen && editor.container.msRequestFullscreen());
  5455.                             } else if (editorOption == "wrap") {
  5456.                                 let wrapStatus = (editor.getSession().getUseWrapMode()) ? false : true;
  5457.                                 editor.getSession().setUseWrapMode(wrapStatus);
  5458.                             }
  5459.                         }
  5460.                     });
  5461.  
  5462.                     $("select#js-ace-mode, select#js-ace-theme, select#js-ace-fontSize").on("change", function(e) {
  5463.                         e.preventDefault();
  5464.                         let selectedValue = $(this).val(),
  5465.                             selectionType = $(this).attr("data-type");
  5466.                         if (selectedValue && selectionType == "mode") {
  5467.                             editor.getSession().setMode(selectedValue);
  5468.                         } else if (selectedValue && selectionType == "theme") {
  5469.                             editor.setTheme(selectedValue);
  5470.                         } else if (selectedValue && selectionType == "fontSize") {
  5471.                             editor.setFontSize(parseInt(selectedValue));
  5472.                         }
  5473.                     });
  5474.                 });
  5475.             </script>
  5476.         <?php endif; ?>
  5477.         <div id="snackbar"></div>
  5478.     </body>
  5479.  
  5480.     </html>
  5481. <?php
  5482.     }
  5483.  
  5484.     /**
  5485.      * Language Translation System
  5486.      * @param string $txt
  5487.      * @return string
  5488.      */
  5489.     function lng($txt)
  5490.     {
  5491.         global $lang;
  5492.  
  5493.         // English Language
  5494.         $tr['en']['AppName']        = 'Tiny File Manager';
  5495.         $tr['en']['AppTitle']       = 'File Manager';
  5496.         $tr['en']['Login']          = 'Sign in';
  5497.         $tr['en']['Username']       = 'Username';
  5498.         $tr['en']['Password']       = 'Password';
  5499.         $tr['en']['Logout']         = 'Sign Out';
  5500.         $tr['en']['Move']           = 'Move';
  5501.         $tr['en']['Copy']           = 'Copy';
  5502.         $tr['en']['Save']           = 'Save';
  5503.         $tr['en']['SelectAll']      = 'Select all';
  5504.         $tr['en']['UnSelectAll']    = 'Unselect all';
  5505.         $tr['en']['File']           = 'File';
  5506.         $tr['en']['Back']           = 'Back';
  5507.         $tr['en']['Size']           = 'Size';
  5508.         $tr['en']['Perms']          = 'Perms';
  5509.         $tr['en']['Modified']       = 'Modified';
  5510.         $tr['en']['Owner']          = 'Owner';
  5511.         $tr['en']['Search']         = 'Search';
  5512.         $tr['en']['NewItem']        = 'New Item';
  5513.         $tr['en']['Folder']         = 'Folder';
  5514.         $tr['en']['Delete']         = 'Delete';
  5515.         $tr['en']['Rename']         = 'Rename';
  5516.         $tr['en']['CopyTo']         = 'Copy to';
  5517.         $tr['en']['DirectLink']     = 'Direct link';
  5518.         $tr['en']['UploadingFiles'] = 'Upload Files';
  5519.         $tr['en']['ChangePermissions']  = 'Change Permissions';
  5520.         $tr['en']['Copying']        = 'Copying';
  5521.         $tr['en']['CreateNewItem']  = 'Create New Item';
  5522.         $tr['en']['Name']           = 'Name';
  5523.         $tr['en']['AdvancedEditor'] = 'Advanced Editor';
  5524.         $tr['en']['Actions']        = 'Actions';
  5525.         $tr['en']['Folder is empty'] = 'Folder is empty';
  5526.         $tr['en']['Upload']         = 'Upload';
  5527.         $tr['en']['Cancel']         = 'Cancel';
  5528.         $tr['en']['InvertSelection'] = 'Invert Selection';
  5529.         $tr['en']['DestinationFolder']  = 'Destination Folder';
  5530.         $tr['en']['ItemType']       = 'Item Type';
  5531.         $tr['en']['ItemName']       = 'Item Name';
  5532.         $tr['en']['CreateNow']      = 'Create Now';
  5533.         $tr['en']['Download']       = 'Download';
  5534.         $tr['en']['Open']           = 'Open';
  5535.         $tr['en']['UnZip']          = 'UnZip';
  5536.         $tr['en']['UnZipToFolder']  = 'UnZip to folder';
  5537.         $tr['en']['Edit']           = 'Edit';
  5538.         $tr['en']['NormalEditor']   = 'Normal Editor';
  5539.         $tr['en']['BackUp']         = 'Back Up';
  5540.         $tr['en']['SourceFolder']   = 'Source Folder';
  5541.         $tr['en']['Files']          = 'Files';
  5542.         $tr['en']['Move']           = 'Move';
  5543.         $tr['en']['Change']         = 'Change';
  5544.         $tr['en']['Settings']       = 'Settings';
  5545.         $tr['en']['Language']       = 'Language';
  5546.         $tr['en']['ErrorReporting'] = 'Error Reporting';
  5547.         $tr['en']['ShowHiddenFiles'] = 'Show Hidden Files';
  5548.         $tr['en']['Help']           = 'Help';
  5549.         $tr['en']['Created']        = 'Created';
  5550.         $tr['en']['Help Documents'] = 'Help Documents';
  5551.         $tr['en']['Report Issue']   = 'Report Issue';
  5552.         $tr['en']['Generate']       = 'Generate';
  5553.         $tr['en']['FullSize']       = 'Full Size';
  5554.         $tr['en']['HideColumns']    = 'Hide Perms/Owner columns';
  5555.         $tr['en']['You are logged in'] = 'You are logged in';
  5556.         $tr['en']['Nothing selected']  = 'Nothing selected';
  5557.         $tr['en']['Paths must be not equal']    = 'Paths must be not equal';
  5558.         $tr['en']['Renamed from']       = 'Renamed from';
  5559.         $tr['en']['Archive not unpacked'] = 'Archive not unpacked';
  5560.         $tr['en']['Deleted']            = 'Deleted';
  5561.         $tr['en']['Archive not created'] = 'Archive not created';
  5562.         $tr['en']['Copied from']        = 'Copied from';
  5563.         $tr['en']['Permissions changed'] = 'Permissions changed';
  5564.         $tr['en']['to']                 = 'to';
  5565.         $tr['en']['Saved Successfully'] = 'Saved Successfully';
  5566.         $tr['en']['not found!']         = 'not found!';
  5567.         $tr['en']['File Saved Successfully']    = 'File Saved Successfully';
  5568.         $tr['en']['Archive']            = 'Archive';
  5569.         $tr['en']['Permissions not changed']    = 'Permissions not changed';
  5570.         $tr['en']['Select folder']      = 'Select folder';
  5571.         $tr['en']['Source path not defined']    = 'Source path not defined';
  5572.         $tr['en']['already exists']     = 'already exists';
  5573.         $tr['en']['Error while moving from']    = 'Error while moving from';
  5574.         $tr['en']['Create archive?']    = 'Create archive?';
  5575.         $tr['en']['Invalid file or folder name']    = 'Invalid file or folder name';
  5576.         $tr['en']['Archive unpacked']   = 'Archive unpacked';
  5577.         $tr['en']['File extension is not allowed']  = 'File extension is not allowed';
  5578.         $tr['en']['Root path']          = 'Root path';
  5579.         $tr['en']['Error while renaming from']  = 'Error while renaming from';
  5580.         $tr['en']['File not found']     = 'File not found';
  5581.         $tr['en']['Error while deleting items'] = 'Error while deleting items';
  5582.         $tr['en']['Moved from']         = 'Moved from';
  5583.         $tr['en']['Generate new password hash'] = 'Generate new password hash';
  5584.         $tr['en']['Login failed. Invalid username or password'] = 'Login failed. Invalid username or password';
  5585.         $tr['en']['password_hash not supported, Upgrade PHP version'] = 'password_hash not supported, Upgrade PHP version';
  5586.         $tr['en']['Advanced Search']    = 'Advanced Search';
  5587.         $tr['en']['Error while copying from']    = 'Error while copying from';
  5588.         $tr['en']['Invalid characters in file name']                = 'Invalid characters in file name';
  5589.         $tr['en']['FILE EXTENSION IS NOT SUPPORTED']                = 'FILE EXTENSION IS NOT SUPPORTED';
  5590.         $tr['en']['Selected files and folder deleted']              = 'Selected files and folder deleted';
  5591.         $tr['en']['Error while fetching archive info']              = 'Error while fetching archive info';
  5592.         $tr['en']['Delete selected files and folders?']             = 'Delete selected files and folders?';
  5593.         $tr['en']['Search file in folder and subfolders...']        = 'Search file in folder and subfolders...';
  5594.         $tr['en']['Access denied. IP restriction applicable']       = 'Access denied. IP restriction applicable';
  5595.         $tr['en']['Invalid characters in file or folder name']      = 'Invalid characters in file or folder name';
  5596.         $tr['en']['Operations with archives are not available']     = 'Operations with archives are not available';
  5597.         $tr['en']['File or folder with this path already exists']   = 'File or folder with this path already exists';
  5598.         $tr['en']['Are you sure want to rename?']                   = 'Are you sure want to rename?';
  5599.         $tr['en']['Are you sure want to']                           = 'Are you sure want to';
  5600.         $tr['en']['Date Modified']                                  = 'Date Modified';
  5601.         $tr['en']['File size']                                      = 'File size';
  5602.         $tr['en']['MIME-type']                                      = 'MIME-type';
  5603.  
  5604.         $i18n = fm_get_translations($tr);
  5605.         $tr = $i18n ? $i18n : $tr;
  5606.  
  5607.         if (!strlen($lang)) $lang = 'en';
  5608.         if (isset($tr[$lang][$txt])) return fm_enc($tr[$lang][$txt]);
  5609.         else if (isset($tr['en'][$txt])) return fm_enc($tr['en'][$txt]);
  5610.         else return "$txt";
  5611.     }
  5612.  
  5613. ?>
  5614.  
Add Comment
Please, Sign In to add comment