hello - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of hello.php

  1. <?php
  2. //Default Configuration
  3. $CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
  4.  
  5. //TFM version
  6. define('VERSION', '2.5.3');
  7.  
  8. //Application Title
  9. define('APP_TITLE', 'Tiny File Manager');
  10.  
  11. // --- EDIT BELOW CONFIGURATION CAREFULLY ---
  12.  
  13. // Auth with login/password
  14. // set true/false to enable/disable it
  15. // Is independent from IP white- and blacklisting
  16. $use_auth = true;
  17.  
  18. // Login user name and password
  19. // Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
  20. // Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
  21. $auth_users = array(
  22.     'admin' => '$2y$10$/K.hjNr84lLNDt8fTXjoI.DBp6PpeyoJ.mGwrrLuCZfAwfSAGqhOW', //admin@123
  23.     'user' => '$2y$10$Fg6Dz8oH9fPoZ2jJan5tZuv6Z4Kp7avtQ9bDfrdRntXtPeiMAZyGO' //12345
  24. );
  25.  
  26. // Readonly users
  27. // e.g. array('users', 'guest', ...)
  28. $readonly_users = array(
  29.     'user'
  30. );
  31.  
  32. // Global readonly, including when auth is not being used
  33. $global_readonly = false;
  34.  
  35. // user specific directories
  36. // array('Username' => 'Directory path', 'Username2' => 'Directory path', ...)
  37. $directories_users = array();
  38.  
  39. // Enable highlight.js (https://highlightjs.org/) on view's page
  40. $use_highlightjs = true;
  41.  
  42. // highlight.js style
  43. // for dark theme use 'ir-black'
  44. $highlightjs_style = 'vs';
  45.  
  46. // Enable ace.js (https://ace.c9.io/) on view's page
  47. $edit_files = true;
  48.  
  49. // Default timezone for date() and time()
  50. // Doc - http://php.net/manual/en/timezones.php
  51. $default_timezone = 'Etc/UTC'; // UTC
  52.  
  53. // Root path for file manager
  54. // use absolute path of directory i.e: '/var/www/folder' or $_SERVER['DOCUMENT_ROOT'].'/folder'
  55. $root_path = $_SERVER['DOCUMENT_ROOT'];
  56.  
  57. // Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
  58. // Will not working if $root_path will be outside of server document root
  59. $root_url = '';
  60.  
  61. // Server hostname. Can set manually if wrong
  62. // $_SERVER['HTTP_HOST'].'/folder'
  63. $http_host = $_SERVER['HTTP_HOST'];
  64.  
  65. // input encoding for iconv
  66. $iconv_input_encoding = 'UTF-8';
  67.  
  68. // date() format for file modification date
  69. // Doc - https://www.php.net/manual/en/function.date.php
  70. $datetime_format = 'm/d/Y g:i A';
  71.  
  72. // Path display mode when viewing file information
  73. // 'full' => show full path
  74. // 'relative' => show path relative to root_path
  75. // 'host' => show path on the host
  76. $path_display_mode = 'full';
  77.  
  78. // Allowed file extensions for create and rename files
  79. // e.g. 'txt,html,css,js'
  80. $allowed_file_extensions = '';
  81.  
  82. // Allowed file extensions for upload files
  83. // e.g. 'gif,png,jpg,html,txt'
  84. $allowed_upload_extensions = '';
  85.  
  86. // Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
  87. // full path, e.g http://example.com/favicon.png
  88. // local path, e.g images/icons/favicon.png
  89. $favicon_path = '';
  90.  
  91. // Files and folders to excluded from listing
  92. // e.g. array('myfile.html', 'personal-folder', '*.php', ...)
  93. $exclude_items = array();
  94.  
  95. // Online office Docs Viewer
  96. // Availabe rules are 'google', 'microsoft' or false
  97. // Google => View documents using Google Docs Viewer
  98. // Microsoft => View documents using Microsoft Web Apps Viewer
  99. // false => disable online doc viewer
  100. $online_viewer = 'google';
  101.  
  102. // Sticky Nav bar
  103. // true => enable sticky header
  104. // false => disable sticky header
  105. $sticky_navbar = true;
  106.  
  107. // Maximum file upload size
  108. // Increase the following values in php.ini to work properly
  109. // memory_limit, upload_max_filesize, post_max_size
  110. $max_upload_size_bytes = 5000000000; // size 5,000,000,000 bytes (~5GB)
  111.  
  112. // chunk size used for upload
  113. // eg. decrease to 1MB if nginx reports problem 413 entity too large
  114. $upload_chunk_size_bytes = 2000000; // chunk size 2,000,000 bytes (~2MB)
  115.  
  116. // Possible rules are 'OFF', 'AND' or 'OR'
  117. // OFF => Don't check connection IP, defaults to OFF
  118. // AND => Connection must be on the whitelist, and not on the blacklist
  119. // OR => Connection must be on the whitelist, or not on the blacklist
  120. $ip_ruleset = 'OFF';
  121.  
  122. // Should users be notified of their block?
  123. $ip_silent = true;
  124.  
  125. // IP-addresses, both ipv4 and ipv6
  126. $ip_whitelist = array(
  127.     '127.0.0.1',    // local ipv4
  128.     '::1'           // local ipv6
  129. );
  130.  
  131. // IP-addresses, both ipv4 and ipv6
  132. $ip_blacklist = array(
  133.     '0.0.0.0',      // non-routable meta ipv4
  134.     '::'            // non-routable meta ipv6
  135. );
  136.  
  137. // if User has the external config file, try to use it to override the default config above [config.php]
  138. // sample config - https://tinyfilemanager.github.io/config-sample.txt
  139. $config_file = __DIR__.'/config.php';
  140. if (is_readable($config_file)) {
  141.     @include($config_file);
  142. }
  143.  
  144. // External CDN resources that can be used in the HTML (replace for GDPR compliance)
  145. $external = array(
  146.     'css-bootstrap' => '<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">',
  147.     'css-dropzone' => '<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css" rel="stylesheet">',
  148.     '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">',
  149.     'css-highlightjs' => '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/' . $highlightjs_style . '.min.css">',
  150.     'js-ace' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.13.1/ace.js"></script>',
  151.     'js-bootstrap' => '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>',
  152.     'js-dropzone' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script>',
  153.     'js-jquery' => '<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>',
  154.     'js-jquery-datatables' => '<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js" crossorigin="anonymous" defer></script>',
  155.     'js-highlightjs' => '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>',
  156.     'pre-jsdelivr' => '<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin/><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"/>',
  157.     'pre-cloudflare' => '<link rel="preconnect" href="https://cdnjs.cloudflare.com" crossorigin/><link rel="dns-prefetch" href="https://cdnjs.cloudflare.com"/>'
  158. );
  159.  
  160. // --- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL ---
  161.  
  162. // max upload file size
  163. define('MAX_UPLOAD_SIZE', $max_upload_size_bytes);
  164.  
  165. // upload chunk size
  166. define('UPLOAD_CHUNK_SIZE', $upload_chunk_size_bytes);
  167.  
  168. // private key and session name to store to the session
  169. if ( !defined( 'FM_SESSION_ID')) {
  170.     define('FM_SESSION_ID', 'filemanager');
  171. }
  172.  
  173. // Configuration
  174. $cfg = new FM_Config();
  175.  
  176. // Default language
  177. $lang = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
  178.  
  179. // Show or hide files and folders that starts with a dot
  180. $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
  181.  
  182. // PHP error reporting - false = Turns off Errors, true = Turns on Errors
  183. $report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
  184.  
  185. // Hide Permissions and Owner cols in file-listing
  186. $hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
  187.  
  188. // Theme
  189. $theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';
  190.  
  191. define('FM_THEME', $theme);
  192.  
  193. //available languages
  194. $lang_list = array(
  195.     'en' => 'English'
  196. );
  197.  
  198. if ($report_errors == true) {
  199.     @ini_set('error_reporting', E_ALL);
  200.     @ini_set('display_errors', 1);
  201. } else {
  202.     @ini_set('error_reporting', E_ALL);
  203.     @ini_set('display_errors', 0);
  204. }
  205.  
  206. // if fm included
  207. if (defined('FM_EMBED')) {
  208.     $use_auth = false;
  209.     $sticky_navbar = false;
  210. } else {
  211.     @set_time_limit(600);
  212.  
  213.     date_default_timezone_set($default_timezone);
  214.  
  215.     ini_set('default_charset', 'UTF-8');
  216.     if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
  217.         mb_internal_encoding('UTF-8');
  218.     }
  219.     if (function_exists('mb_regex_encoding')) {
  220.         mb_regex_encoding('UTF-8');
  221.     }
  222.  
  223.     session_cache_limiter('nocache'); // Prevent logout issue after page was cached
  224.     session_name(FM_SESSION_ID );
  225.     function session_error_handling_function($code, $msg, $file, $line) {
  226.         // Permission denied for default session, try to create a new one
  227.         if ($code == 2) {
  228.             session_abort();
  229.             session_id(session_create_id());
  230.             @session_start();
  231.         }
  232.     }
  233.     set_error_handler('session_error_handling_function');
  234.     session_start();
  235.     restore_error_handler();
  236. }
  237.  
  238. //Generating CSRF Token
  239. if (empty($_SESSION['token'])) {
  240.     if (function_exists('random_bytes')) {
  241.         $_SESSION['token'] = bin2hex(random_bytes(32));
  242.     } else {
  243.             $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32));
  244.     }
  245. }
  246.  
  247. if (empty($auth_users)) {
  248.     $use_auth = false;
  249. }
  250.  
  251. $is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
  252.     || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
  253.  
  254. // update $root_url based on user specific directories
  255. if (isset($_SESSION[FM_SESSION_ID]['logged']) && !empty($directories_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  256.     $wd = fm_clean_path(dirname($_SERVER['PHP_SELF']));
  257.     $root_url =  $root_url.$wd.DIRECTORY_SEPARATOR.$directories_users[$_SESSION[FM_SESSION_ID]['logged']];
  258. }
  259. // clean $root_url
  260. $root_url = fm_clean_path($root_url);
  261.  
  262. // abs path for site
  263. defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
  264. defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
  265.  
  266. // logout
  267. if (isset($_GET['logout'])) {
  268.     unset($_SESSION[FM_SESSION_ID]['logged']);
  269.     unset( $_SESSION['token']); 
  270.     fm_redirect(FM_SELF_URL);
  271. }
  272.  
  273. // Validate connection IP
  274. if ($ip_ruleset != 'OFF') {
  275.     function getClientIP() {
  276.         if (array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)) {
  277.             return  $_SERVER["HTTP_CF_CONNECTING_IP"];
  278.         }else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
  279.             return  $_SERVER["HTTP_X_FORWARDED_FOR"];
  280.         }else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
  281.             return $_SERVER['REMOTE_ADDR'];
  282.         }else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
  283.             return $_SERVER['HTTP_CLIENT_IP'];
  284.         }
  285.         return '';
  286.     }
  287.  
  288.     $clientIp = getClientIP();
  289.     $proceed = false;
  290.     $whitelisted = in_array($clientIp, $ip_whitelist);
  291.     $blacklisted = in_array($clientIp, $ip_blacklist);
  292.  
  293.     if($ip_ruleset == 'AND'){
  294.         if($whitelisted == true && $blacklisted == false){
  295.             $proceed = true;
  296.         }
  297.     } else
  298.     if($ip_ruleset == 'OR'){
  299.          if($whitelisted == true || $blacklisted == false){
  300.             $proceed = true;
  301.         }
  302.     }
  303.  
  304.     if($proceed == false){
  305.         trigger_error('User connection denied from: ' . $clientIp, E_USER_WARNING);
  306.  
  307.         if($ip_silent == false){
  308.             fm_set_msg(lng('Access denied. IP restriction applicable'), 'error');
  309.             fm_show_header_login();
  310.             fm_show_message();
  311.         }
  312.         exit();
  313.     }
  314. }
  315.  
  316. // Checking if the user is logged in or not. If not, it will show the login form.
  317. if ($use_auth) {
  318.     if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  319.         // Logged
  320.     } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'], $_POST['token'])) {
  321.         // Logging In
  322.         sleep(1);
  323.         if(function_exists('password_verify')) {
  324.             if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']]) && verifyToken($_POST['token'])) {
  325.                 $_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr'];
  326.                 fm_set_msg(lng('You are logged in'));
  327.                 fm_redirect(FM_SELF_URL);
  328.             } else {
  329.                 unset($_SESSION[FM_SESSION_ID]['logged']);
  330.                 fm_set_msg(lng('Login failed. Invalid username or password'), 'error');
  331.                 fm_redirect(FM_SELF_URL);
  332.             }
  333.         } else {
  334.             fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');;
  335.         }
  336.     } else {
  337.         // Form
  338.         unset($_SESSION[FM_SESSION_ID]['logged']);
  339.         fm_show_header_login();
  340.         ?>
  341.         <section class="h-100">
  342.             <div class="container h-100">
  343.                 <div class="row justify-content-md-center h-100">
  344.                     <div class="card-wrapper">
  345.                         <div class="card fat <?php echo fm_get_theme(); ?>">
  346.                             <div class="card-body">
  347.                                 <form class="form-signin" action="" method="post" autocomplete="off">
  348.                                     <div class="mb-3">
  349.                                        <div class="brand">
  350.                                             <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">
  351.                                                 <g transform="translate(0.000000,140.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">
  352.                                                     <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"/>
  353.                                                     <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"/>
  354.                                                     <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"/></g>
  355.                                             </svg>
  356.                                         </div>
  357.                                         <div class="text-center">
  358.                                             <h1 class="card-title"><?php echo APP_TITLE; ?></h1>
  359.                                         </div>
  360.                                     </div>
  361.                                     <hr />
  362.                                     <div class="mb-3">
  363.                                         <label for="fm_usr" class="pb-2"><?php echo lng('Username'); ?></label>
  364.                                         <input type="text" class="form-control" id="fm_usr" name="fm_usr" required autofocus>
  365.                                     </div>
  366.  
  367.                                     <div class="mb-3">
  368.                                         <label for="fm_pwd" class="pb-2"><?php echo lng('Password'); ?></label>
  369.                                         <input type="password" class="form-control" id="fm_pwd" name="fm_pwd" required>
  370.                                     </div>
  371.  
  372.                                     <div class="mb-3">
  373.                                         <?php fm_show_message(); ?>
  374.                                     </div>
  375.                                     <input type="hidden" name="token" value="<?php echo htmlentities($_SESSION['token']); ?>" />
  376.                                     <div class="mb-3">
  377.                                         <button type="submit" class="btn btn-success btn-block w-100 mt-4" role="button">
  378.                                             <?php echo lng('Login'); ?>
  379.                                         </button>
  380.                                     </div>
  381.                                 </form>
  382.                             </div>
  383.                         </div>
  384.                         <div class="footer text-center">
  385.                             —— ©
  386.                             <a href="https://tinyfilemanager.github.io/" target="_blank" class="text-decoration-none text-muted" data-version="<?php echo VERSION; ?>">CCP Programmers</a> ——
  387.                         </div>
  388.                     </div>
  389.                 </div>
  390.             </div>
  391.         </section>
  392.  
  393.         <?php
  394.         fm_show_footer_login();
  395.         exit;
  396.     }
  397. }
  398.  
  399. // update root path
  400. if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
  401.     $root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
  402. }
  403.  
  404. // clean and check $root_path
  405. $root_path = rtrim($root_path, '\\/');
  406. $root_path = str_replace('\\', '/', $root_path);
  407. if (!@is_dir($root_path)) {
  408.     echo "<h1>".lng('Root path').\"{$root_path}\" ".lng('not found!')." </h1>";
  409.     exit;
  410. }
  411.  
  412. defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
  413. defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
  414. defined('FM_LANG') || define('FM_LANG', $lang);
  415. defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
  416. defined('FM_UPLOAD_EXTENSION') || define('FM_UPLOAD_EXTENSION', $allowed_upload_extensions);
  417. defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items) : $exclude_items));
  418. defined('FM_DOC_VIEWER') || define('FM_DOC_VIEWER', $online_viewer);
  419. 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)));
  420. define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
  421.  
  422. // always use ?p=
  423. if (!isset($_GET['p']) && empty($_FILES)) {
  424.     fm_redirect(FM_SELF_URL . '?p=');
  425. }
  426.  
  427. // get path
  428. $p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
  429.  
  430. // clean path
  431. $p = fm_clean_path($p);
  432.  
  433. // for ajax request - save
  434. $input = file_get_contents('php://input');
  435. $_POST = (strpos($input, 'ajax') != FALSE && strpos($input, 'save') != FALSE) ? json_decode($input, true) : $_POST;
  436.  
  437. // instead globals vars
  438. define('FM_PATH', $p);
  439. define('FM_USE_AUTH', $use_auth);
  440. define('FM_EDIT_FILE', $edit_files);
  441. defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
  442. defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
  443. defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
  444. defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
  445.  
  446. unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
  447.  
  448. /*************************** ACTIONS ***************************/
  449.  
  450. // Handle all AJAX Request
  451. if ((isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']]) || !FM_USE_AUTH) && isset($_POST['ajax'], $_POST['token']) && !FM_READONLY) {
  452.     if(!verifyToken($_POST['token'])) {
  453.         header('HTTP/1.0 401 Unauthorized');
  454.         die("Invalid Token.");
  455.     }
  456.  
  457.     //search : get list of files from the current folder
  458.     if(isset($_POST['type']) && $_POST['type']=="search") {
  459.         $dir = $_POST['path'] == "." ? '': $_POST['path'];
  460.         $response = scan(fm_clean_path($dir), $_POST['content']);
  461.         echo json_encode($response);
  462.         exit();
  463.     }
  464.  
  465.     // save editor file
  466.     if (isset($_POST['type']) && $_POST['type'] == "save") {
  467.         // get current path
  468.         $path = FM_ROOT_PATH;
  469.         if (FM_PATH != '') {
  470.             $path .= '/' . FM_PATH;
  471.         }
  472.         // check path
  473.         if (!is_dir($path)) {
  474.             fm_redirect(FM_SELF_URL . '?p=');
  475.         }
  476.         $file = $_GET['edit'];
  477.         $file = fm_clean_path($file);
  478.         $file = str_replace('/', '', $file);
  479.         if ($file == '' || !is_file($path . '/' . $file)) {
  480.             fm_set_msg(lng('File not found'), 'error');
  481.             $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  482.         }
  483.         header('X-XSS-Protection:0');
  484.         $file_path = $path . '/' . $file;
  485.  
  486.         $writedata = $_POST['content'];
  487.         $fd = fopen($file_path, "w");
  488.         $write_results = @fwrite($fd, $writedata);
  489.         fclose($fd);
  490.         if ($write_results === false){
  491.             header("HTTP/1.1 500 Internal Server Error");
  492.             die("Could Not Write File! - Check Permissions / Ownership");
  493.         }
  494.         die(true);
  495.     }
  496.  
  497.     // backup files
  498.     if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
  499.         $fileName = fm_clean_path($_POST['file']);
  500.         $fullPath = FM_ROOT_PATH . '/';
  501.         if (!empty($_POST['path'])) {
  502.             $relativeDirPath = fm_clean_path($_POST['path']);
  503.             $fullPath .= "{$relativeDirPath}/";
  504.         }
  505.         $date = date("dMy-His");
  506.         $newFileName = "{$fileName}-{$date}.bak";
  507.         $fullyQualifiedFileName = $fullPath . $fileName;
  508.         try {
  509.             if (!file_exists($fullyQualifiedFileName)) {
  510.                 throw new Exception("File {$fileName} not found");
  511.             }
  512.             if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) {
  513.                 echo "Backup {$newFileName} created";
  514.             } else {
  515.                 throw new Exception("Could not copy file {$fileName}");
  516.             }
  517.         } catch (Exception $e) {
  518.             echo $e->getMessage();
  519.         }
  520.     }
  521.  
  522.     // Save Config
  523.     if (isset($_POST['type']) && $_POST['type'] == "settings") {
  524.         global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme;
  525.         $newLng = $_POST['js-language'];
  526.         fm_get_translations([]);
  527.         if (!array_key_exists($newLng, $lang_list)) {
  528.             $newLng = 'en';
  529.         }
  530.  
  531.         $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
  532.         $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
  533.         $hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
  534.         $te3 = $_POST['js-theme-3'];
  535.  
  536.         if ($cfg->data['lang'] != $newLng) {
  537.             $cfg->data['lang'] = $newLng;
  538.             $lang = $newLng;
  539.         }
  540.         if ($cfg->data['error_reporting'] != $erp) {
  541.             $cfg->data['error_reporting'] = $erp;
  542.             $report_errors = $erp;
  543.         }
  544.         if ($cfg->data['show_hidden'] != $shf) {
  545.             $cfg->data['show_hidden'] = $shf;
  546.             $show_hidden_files = $shf;
  547.         }
  548.         if ($cfg->data['show_hidden'] != $shf) {
  549.             $cfg->data['show_hidden'] = $shf;
  550.             $show_hidden_files = $shf;
  551.         }
  552.         if ($cfg->data['hide_Cols'] != $hco) {
  553.             $cfg->data['hide_Cols'] = $hco;
  554.             $hide_Cols = $hco;
  555.         }
  556.         if ($cfg->data['theme'] != $te3) {
  557.             $cfg->data['theme'] = $te3;
  558.             $theme = $te3;
  559.         }
  560.         $cfg->save();
  561.         echo true;
  562.     }
  563.  
  564.     // new password hash
  565.     if (isset($_POST['type']) && $_POST['type'] == "pwdhash") {
  566.         $res = isset($_POST['inputPassword2']) && !empty($_POST['inputPassword2']) ? password_hash($_POST['inputPassword2'], PASSWORD_DEFAULT) : '';
  567.         echo $res;
  568.     }
  569.  
  570.     //upload using url
  571.     if(isset($_POST['type']) && $_POST['type'] == "upload" && !empty($_REQUEST["uploadurl"])) {
  572.         $path = FM_ROOT_PATH;
  573.         if (FM_PATH != '') {
  574.             $path .= '/' . FM_PATH;
  575.         }
  576.  
  577.          function event_callback ($message) {
  578.             global $callback;
  579.             echo json_encode($message);
  580.         }
  581.  
  582.         function get_file_path () {
  583.             global $path, $fileinfo, $temp_file;
  584.             return $path."/".basename($fileinfo->name);
  585.         }
  586.  
  587.         $url = !empty($_REQUEST["uploadurl"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["uploadurl"])) ? stripslashes($_REQUEST["uploadurl"]) : null;
  588.  
  589.         //prevent 127.* domain and known ports
  590.         $domain = parse_url($url, PHP_URL_HOST);
  591.         $port = parse_url($url, PHP_URL_PORT);
  592.         $knownPorts = [22, 23, 25, 3306];
  593.  
  594.         if (preg_match("/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i", $domain) || in_array($port, $knownPorts)) {
  595.             $err = array("message" => "URL is not allowed");
  596.             event_callback(array("fail" => $err));
  597.             exit();
  598.         }
  599.  
  600.         $use_curl = false;
  601.         $temp_file = tempnam(sys_get_temp_dir(), "upload-");
  602.         $fileinfo = new stdClass();
  603.         $fileinfo->name = trim(basename($url), ".\x00..\x20");
  604.  
  605.         $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  606.         $ext = strtolower(pathinfo($fileinfo->name, PATHINFO_EXTENSION));
  607.         $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  608.  
  609.         $err = false;
  610.  
  611.         if(!$isFileAllowed) {
  612.             $err = array("message" => "File extension is not allowed");
  613.             event_callback(array("fail" => $err));
  614.             exit();
  615.         }
  616.  
  617.         if (!$url) {
  618.             $success = false;
  619.         } else if ($use_curl) {
  620.             @$fp = fopen($temp_file, "w");
  621.             @$ch = curl_init($url);
  622.             curl_setopt($ch, CURLOPT_NOPROGRESS, false );
  623.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  624.             curl_setopt($ch, CURLOPT_FILE, $fp);
  625.             @$success = curl_exec($ch);
  626.             $curl_info = curl_getinfo($ch);
  627.             if (!$success) {
  628.                 $err = array("message" => curl_error($ch));
  629.             }
  630.             @curl_close($ch);
  631.             fclose($fp);
  632.             $fileinfo->size = $curl_info["size_download"];
  633.             $fileinfo->type = $curl_info["content_type"];
  634.         } else {
  635.             $ctx = stream_context_create();
  636.             @$success = copy($url, $temp_file, $ctx);
  637.             if (!$success) {
  638.                 $err = error_get_last();
  639.             }
  640.         }
  641.  
  642.         if ($success) {
  643.             $success = rename($temp_file, strtok(get_file_path(), '?'));
  644.         }
  645.  
  646.         if ($success) {
  647.             event_callback(array("done" => $fileinfo));
  648.         } else {
  649.             unlink($temp_file);
  650.             if (!$err) {
  651.                 $err = array("message" => "Invalid url parameter");
  652.             }
  653.             event_callback(array("fail" => $err));
  654.         }
  655.     }
  656.     exit();
  657. }
  658.  
  659. // Delete file / folder
  660. if (isset($_GET['del'], $_POST['token']) && !FM_READONLY) {
  661.     $del = str_replace( '/', '', fm_clean_path( $_GET['del'] ) );
  662.     if ($del != '' && $del != '..' && $del != '.' && verifyToken($_POST['token'])) {
  663.         $path = FM_ROOT_PATH;
  664.         if (FM_PATH != '') {
  665.             $path .= '/' . FM_PATH;
  666.         }
  667.         $is_dir = is_dir($path . '/' . $del);
  668.         if (fm_rdelete($path . '/' . $del)) {
  669.             $msg = $is_dir ? lng('Folder').' <b>%s</b> '.lng('Deleted') : lng('File').' <b>%s</b> '.lng('Deleted');
  670.             fm_set_msg(sprintf($msg, fm_enc($del)));
  671.         } else {
  672.             $msg = $is_dir ? lng('Folder').' <b>%s</b> '.lng('not deleted') : lng('File').' <b>%s</b> '.lng('not deleted');
  673.             fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
  674.         }
  675.     } else {
  676.         fm_set_msg(lng('Invalid file or folder name'), 'error');
  677.     }
  678.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  679. }
  680.  
  681. // Create a new file/folder
  682. if (isset($_POST['newfilename'], $_POST['newfile'], $_POST['token']) && !FM_READONLY) {
  683.     $type = urldecode($_POST['newfile']);
  684.     $new = str_replace( '/', '', fm_clean_path( strip_tags( $_POST['newfilename'] ) ) );
  685.     if (fm_isvalid_filename($new) && $new != '' && $new != '..' && $new != '.' && verifyToken($_POST['token'])) {
  686.         $path = FM_ROOT_PATH;
  687.         if (FM_PATH != '') {
  688.             $path .= '/' . FM_PATH;
  689.         }
  690.         if ($type == "file") {
  691.             if (!file_exists($path . '/' . $new)) {
  692.                 if(fm_is_valid_ext($new)) {
  693.                     @fopen($path . '/' . $new, 'w') or die('Cannot open file:  ' . $new);
  694.                     fm_set_msg(sprintf(lng('File').' <b>%s</b> '.lng('Created'), fm_enc($new)));
  695.                 } else {
  696.                     fm_set_msg(lng('File extension is not allowed'), 'error');
  697.                 }
  698.             } else {
  699.                 fm_set_msg(sprintf(lng('File').' <b>%s</b> '.lng('already exists'), fm_enc($new)), 'alert');
  700.             }
  701.         } else {
  702.             if (fm_mkdir($path . '/' . $new, false) === true) {
  703.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('Created'), $new));
  704.             } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
  705.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('already exists'), fm_enc($new)), 'alert');
  706.             } else {
  707.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('not created'), fm_enc($new)), 'error');
  708.             }
  709.         }
  710.     } else {
  711.         fm_set_msg(lng('Invalid characters in file or folder name'), 'error');
  712.     }
  713.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  714. }
  715.  
  716. // Copy folder / file
  717. if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
  718.     // from
  719.     $copy = urldecode($_GET['copy']);
  720.     $copy = fm_clean_path($copy);
  721.     // empty path
  722.     if ($copy == '') {
  723.         fm_set_msg(lng('Source path not defined'), 'error');
  724.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  725.     }
  726.     // abs path from
  727.     $from = FM_ROOT_PATH . '/' . $copy;
  728.     // abs path to
  729.     $dest = FM_ROOT_PATH;
  730.     if (FM_PATH != '') {
  731.         $dest .= '/' . FM_PATH;
  732.     }
  733.     $dest .= '/' . basename($from);
  734.     // move?
  735.     $move = isset($_GET['move']);
  736.     $move = fm_clean_path(urldecode($move));
  737.     // copy/move/duplicate
  738.     if ($from != $dest) {
  739.         $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  740.         if ($move) { // Move and to != from so just perform move
  741.             $rename = fm_rename($from, $dest);
  742.             if ($rename) {
  743.                 fm_set_msg(sprintf(lng('Moved from').' <b>%s</b> '.lng('to').' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  744.             } elseif ($rename === null) {
  745.                 fm_set_msg(lng('File or folder with this path already exists'), 'alert');
  746.             } else {
  747.                 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');
  748.             }
  749.         } else { // Not move and to != from so copy with original name
  750.             if (fm_rcopy($from, $dest)) {
  751.                 fm_set_msg(sprintf(lng('Copied from').' <b>%s</b> '.lng('to').' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  752.             } else {
  753.                 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');
  754.             }
  755.         }
  756.     } else {
  757.        if (!$move){ //Not move and to = from so duplicate
  758.             $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  759.             $fn_parts = pathinfo($from);
  760.             $extension_suffix = '';
  761.             if(!is_dir($from)){
  762.                $extension_suffix = '.'.$fn_parts['extension'];
  763.             }
  764.             //Create new name for duplicate
  765.             $fn_duplicate = $fn_parts['dirname'].'/'.$fn_parts['filename'].'-'.date('YmdHis').$extension_suffix;
  766.             $loop_count = 0;
  767.             $max_loop = 1000;
  768.             // Check if a file with the duplicate name already exists, if so, make new name (edge case...)
  769.             while(file_exists($fn_duplicate) & $loop_count < $max_loop){
  770.                $fn_parts = pathinfo($fn_duplicate);
  771.                $fn_duplicate = $fn_parts['dirname'].'/'.$fn_parts['filename'].'-copy'.$extension_suffix;
  772.                $loop_count++;
  773.             }
  774.             if (fm_rcopy($from, $fn_duplicate, False)) {
  775.                 fm_set_msg(sprintf('Copied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)));
  776.             } else {
  777.                 fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)), 'error');
  778.             }
  779.        }
  780.        else{
  781.            fm_set_msg(lng('Paths must be not equal'), 'alert');
  782.        }
  783.     }
  784.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  785. }
  786.  
  787. // Mass copy files/ folders
  788. if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish'], $_POST['token']) && !FM_READONLY) {
  789.  
  790.     if(!verifyToken($_POST['token'])) {
  791.         fm_set_msg(lng('Invalid Token.'), 'error');
  792.     }
  793.     
  794.     // from
  795.     $path = FM_ROOT_PATH;
  796.     if (FM_PATH != '') {
  797.         $path .= '/' . FM_PATH;
  798.     }
  799.     // to
  800.     $copy_to_path = FM_ROOT_PATH;
  801.     $copy_to = fm_clean_path($_POST['copy_to']);
  802.     if ($copy_to != '') {
  803.         $copy_to_path .= '/' . $copy_to;
  804.     }
  805.     if ($path == $copy_to_path) {
  806.         fm_set_msg(lng('Paths must be not equal'), 'alert');
  807.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  808.     }
  809.     if (!is_dir($copy_to_path)) {
  810.         if (!fm_mkdir($copy_to_path, true)) {
  811.             fm_set_msg('Unable to create destination folder', 'error');
  812.             $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  813.         }
  814.     }
  815.     // move?
  816.     $move = isset($_POST['move']);
  817.     // copy/move
  818.     $errors = 0;
  819.     $files = $_POST['file'];
  820.     if (is_array($files) && count($files)) {
  821.         foreach ($files as $f) {
  822.             if ($f != '') {
  823.                 $f = fm_clean_path($f);
  824.                 // abs path from
  825.                 $from = $path . '/' . $f;
  826.                 // abs path to
  827.                 $dest = $copy_to_path . '/' . $f;
  828.                 // do
  829.                 if ($move) {
  830.                     $rename = fm_rename($from, $dest);
  831.                     if ($rename === false) {
  832.                         $errors++;
  833.                     }
  834.                 } else {
  835.                     if (!fm_rcopy($from, $dest)) {
  836.                         $errors++;
  837.                     }
  838.                 }
  839.             }
  840.         }
  841.         if ($errors == 0) {
  842.             $msg = $move 'Selected files and folders moved' : 'Selected files and folders copied';
  843.             fm_set_msg($msg);
  844.         } else {
  845.             $msg = $move 'Error while moving items' : 'Error while copying items';
  846.             fm_set_msg($msg, 'error');
  847.         }
  848.     } else {
  849.         fm_set_msg(lng('Nothing selected'), 'alert');
  850.     }
  851.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  852. }
  853.  
  854. // Rename
  855. if (isset($_POST['rename_from'], $_POST['rename_to'], $_POST['token']) && !FM_READONLY) {
  856.     if(!verifyToken($_POST['token'])) {
  857.         fm_set_msg("Invalid Token.", 'error');
  858.     }
  859.     // old name
  860.     $old = urldecode($_POST['rename_from']);
  861.     $old = fm_clean_path($old);
  862.     $old = str_replace('/', '', $old);
  863.     // new name
  864.     $new = urldecode($_POST['rename_to']);
  865.     $new = fm_clean_path(strip_tags($new));
  866.     $new = str_replace('/', '', $new);
  867.     // path
  868.     $path = FM_ROOT_PATH;
  869.     if (FM_PATH != '') {
  870.         $path .= '/' . FM_PATH;
  871.     }
  872.     // rename
  873.     if (fm_isvalid_filename($new) && $old != '' && $new != '') {
  874.         if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
  875.             fm_set_msg(sprintf(lng('Renamed from').' <b>%s</b> '. lng('to').' <b>%s</b>', fm_enc($old), fm_enc($new)));
  876.         } else {
  877.             fm_set_msg(sprintf(lng('Error while renaming from').' <b>%s</b> '. lng('to').' <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
  878.         }
  879.     } else {
  880.         fm_set_msg(lng('Invalid characters in file name'), 'error');
  881.     }
  882.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  883. }
  884.  
  885. // Download
  886. if (isset($_GET['dl'], $_POST['token'])) {
  887.     if(!verifyToken($_POST['token'])) {
  888.         fm_set_msg("Invalid Token.", 'error');
  889.     }
  890.  
  891.     $dl = urldecode($_GET['dl']);
  892.     $dl = fm_clean_path($dl);
  893.     $dl = str_replace('/', '', $dl);
  894.     $path = FM_ROOT_PATH;
  895.     if (FM_PATH != '') {
  896.         $path .= '/' . FM_PATH;
  897.     }
  898.     if ($dl != '' && is_file($path . '/' . $dl)) {
  899.         fm_download_file($path . '/' . $dl, $dl, 1024);
  900.         exit;
  901.     } else {
  902.         fm_set_msg(lng('File not found'), 'error');
  903.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  904.     }
  905. }
  906.  
  907. // Upload
  908. if (!empty($_FILES) && !FM_READONLY) {
  909.     if(isset($_POST['token'])) {
  910.         if(!verifyToken($_POST['token'])) {
  911.             $response = array ('status' => 'error','info' => "Invalid Token.");
  912.             echo json_encode($response); exit();
  913.         }
  914.     } else {
  915.         $response = array ('status' => 'error','info' => "Token Missing.");
  916.         echo json_encode($response); exit();
  917.     }
  918.  
  919.     $chunkIndex = $_POST['dzchunkindex'];
  920.     $chunkTotal = $_POST['dztotalchunkcount'];
  921.     $fullPathInput = fm_clean_path($_REQUEST['fullpath']);
  922.  
  923.     $f = $_FILES;
  924.     $path = FM_ROOT_PATH;
  925.     $ds = DIRECTORY_SEPARATOR;
  926.     if (FM_PATH != '') {
  927.         $path .= '/' . FM_PATH;
  928.     }
  929.  
  930.     $errors = 0;
  931.     $uploads = 0;
  932.     $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  933.     $response = array (
  934.         'status' => 'error',
  935.         'info'   => 'Oops! Try again'
  936.     );
  937.  
  938.     $filename = $f['file']['name'];
  939.     $tmp_name = $f['file']['tmp_name'];
  940.     $ext = pathinfo($filename, PATHINFO_FILENAME) != '' ? strtolower(pathinfo($filename, PATHINFO_EXTENSION)) : '';
  941.     $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  942.  
  943.     if(!fm_isvalid_filename($filename) && !fm_isvalid_filename($fullPathInput)) {
  944.         $response = array (
  945.             'status'    => 'error',
  946.             'info'      => "Invalid File name!",
  947.         );
  948.         echo json_encode($response); exit();
  949.     }
  950.  
  951.     $targetPath = $path . $ds;
  952.     if ( is_writable($targetPath) ) {
  953.         $fullPath = $path . '/' . basename($fullPathInput);
  954.         $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
  955.  
  956.         if (!is_dir($folder)) {
  957.             $old = umask(0);
  958.             mkdir($folder, 0777, true);
  959.             umask($old);
  960.         }
  961.  
  962.         if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
  963.             if ($chunkTotal){
  964.                 $out = @fopen("{$fullPath}.part", $chunkIndex == 0 ? "wb" : "ab");
  965.                 if ($out) {
  966.                     $in = @fopen($tmp_name, "rb");
  967.                     if ($in) {
  968.                         if (PHP_VERSION_ID < 80009) {
  969.                             // workaround https://bugs.php.net/bug.php?id=81145
  970.                             do {
  971.                                 for (;;) {
  972.                                     $buff = fread($in, 4096);
  973.                                     if ($buff === false || $buff === '') {
  974.                                         break;
  975.                                     }
  976.                                     fwrite($out, $buff);
  977.                                 }
  978.                             } while (!feof($in));
  979.                         } else {
  980.                             stream_copy_to_stream($in, $out);
  981.                         }
  982.                         $response = array (
  983.                             'status'    => 'success',
  984.                             'info' => "file upload successful"
  985.                         );
  986.                     } else {
  987.                         $response = array (
  988.                         'status'    => 'error',
  989.                         'info' => "failed to open output stream",
  990.                         'errorDetails' => error_get_last()
  991.                         );
  992.                     }
  993.                     @fclose($in);
  994.                     @fclose($out);
  995.                     @unlink($tmp_name);
  996.  
  997.                     $response = array (
  998.                         'status'    => 'success',
  999.                         'info' => "file upload successful"
  1000.                     );
  1001.                 } else {
  1002.                     $response = array (
  1003.                         'status'    => 'error',
  1004.                         'info' => "failed to open output stream"
  1005.                         );
  1006.                 }
  1007.  
  1008.                 if ($chunkIndex == $chunkTotal - 1) {
  1009.                     if (file_exists ($fullPath)) {
  1010.                         $ext_1 = $ext '.'.$ext : '';
  1011.                         $fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1;
  1012.                     } else {
  1013.                         $fullPathTarget = $fullPath;
  1014.                     }
  1015.                     rename("{$fullPath}.part", $fullPathTarget);
  1016.                 }
  1017.  
  1018.             } else if (move_uploaded_file($tmp_name, $fullPath)) {
  1019.                 // Be sure that the file has been uploaded
  1020.                 if ( file_exists($fullPath) ) {
  1021.                     $response = array (
  1022.                         'status'    => 'success',
  1023.                         'info' => "file upload successful"
  1024.                     );
  1025.                 } else {
  1026.                     $response = array (
  1027.                         'status' => 'error',
  1028.                         'info'   => 'Couldn\'t upload the requested file.'
  1029.                     );
  1030.                 }
  1031.             } else {
  1032.                 $response = array (
  1033.                     'status'    => 'error',
  1034.                     'info'      => "Error while uploading files. Uploaded files $uploads",
  1035.                 );
  1036.             }
  1037.         }
  1038.     } else {
  1039.         $response = array (
  1040.             'status' => 'error',
  1041.             'info'   => 'The specified folder for upload isn\'t writeable.'
  1042.         );
  1043.     }
  1044.     // Return the response
  1045.     echo json_encode($response);
  1046.     exit();
  1047. }
  1048.  
  1049. // Mass deleting
  1050. if (isset($_POST['group'], $_POST['delete'], $_POST['token']) && !FM_READONLY) {
  1051.  
  1052.     if(!verifyToken($_POST['token'])) {
  1053.         fm_set_msg(lng("Invalid Token."), 'error');
  1054.     }
  1055.  
  1056.     $path = FM_ROOT_PATH;
  1057.     if (FM_PATH != '') {
  1058.         $path .= '/' . FM_PATH;
  1059.     }
  1060.  
  1061.     $errors = 0;
  1062.     $files = $_POST['file'];
  1063.     if (is_array($files) && count($files)) {
  1064.         foreach ($files as $f) {
  1065.             if ($f != '') {
  1066.                 $new_path = $path . '/' . $f;
  1067.                 if (!fm_rdelete($new_path)) {
  1068.                     $errors++;
  1069.                 }
  1070.             }
  1071.         }
  1072.         if ($errors == 0) {
  1073.             fm_set_msg(lng('Selected files and folder deleted'));
  1074.         } else {
  1075.             fm_set_msg(lng('Error while deleting items'), 'error');
  1076.         }
  1077.     } else {
  1078.         fm_set_msg(lng('Nothing selected'), 'alert');
  1079.     }
  1080.  
  1081.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1082. }
  1083.  
  1084. // Pack files zip, tar
  1085. if (isset($_POST['group'], $_POST['token']) && (isset($_POST['zip']) || isset($_POST['tar'])) && !FM_READONLY) {
  1086.  
  1087.     if(!verifyToken($_POST['token'])) {
  1088.         fm_set_msg(lng("Invalid Token."), 'error');
  1089.     }
  1090.  
  1091.     $path = FM_ROOT_PATH;
  1092.     $ext = 'zip';
  1093.     if (FM_PATH != '') {
  1094.         $path .= '/' . FM_PATH;
  1095.     }
  1096.  
  1097.     //set pack type
  1098.     $ext = isset($_POST['tar']) ? 'tar' : 'zip';
  1099.  
  1100.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1101.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1102.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1103.     }
  1104.  
  1105.     $files = $_POST['file'];
  1106.     $sanitized_files = array();
  1107.  
  1108.     // clean path
  1109.     foreach($files as $file){
  1110.         array_push($sanitized_files, fm_clean_path($file));
  1111.     }
  1112.     
  1113.     $files = $sanitized_files;
  1114.     
  1115.     if (!empty($files)) {
  1116.         chdir($path);
  1117.  
  1118.         if (count($files) == 1) {
  1119.             $one_file = reset($files);
  1120.             $one_file = basename($one_file);
  1121.             $zipname = $one_file . '_' . date('ymd_His') . '.'.$ext;
  1122.         } else {
  1123.             $zipname = 'archive_' . date('ymd_His') . '.'.$ext;
  1124.         }
  1125.  
  1126.         if($ext == 'zip') {
  1127.             $zipper = new FM_Zipper();
  1128.             $res = $zipper->create($zipname, $files);
  1129.         } elseif ($ext == 'tar') {
  1130.             $tar = new FM_Zipper_Tar();
  1131.             $res = $tar->create($zipname, $files);
  1132.         }
  1133.  
  1134.         if ($res) {
  1135.             fm_set_msg(sprintf(lng('Archive').' <b>%s</b> '.lng('Created'), fm_enc($zipname)));
  1136.         } else {
  1137.             fm_set_msg(lng('Archive not created'), 'error');
  1138.         }
  1139.     } else {
  1140.         fm_set_msg(lng('Nothing selected'), 'alert');
  1141.     }
  1142.  
  1143.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1144. }
  1145.  
  1146. // Unpack zip, tar
  1147. if (isset($_POST['unzip'], $_POST['token']) && !FM_READONLY) {
  1148.  
  1149.     if(!verifyToken($_POST['token'])) {
  1150.         fm_set_msg(lng("Invalid Token."), 'error');
  1151.     }
  1152.  
  1153.     $unzip = urldecode($_POST['unzip']);
  1154.     $unzip = fm_clean_path($unzip);
  1155.     $unzip = str_replace('/', '', $unzip);
  1156.     $isValid = false;
  1157.  
  1158.     $path = FM_ROOT_PATH;
  1159.     if (FM_PATH != '') {
  1160.         $path .= '/' . FM_PATH;
  1161.     }
  1162.  
  1163.     if ($unzip != '' && is_file($path . '/' . $unzip)) {
  1164.         $zip_path = $path . '/' . $unzip;
  1165.         $ext = pathinfo($zip_path, PATHINFO_EXTENSION);
  1166.         $isValid = true;
  1167.     } else {
  1168.         fm_set_msg(lng('File not found'), 'error');
  1169.     }
  1170.  
  1171.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1172.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1173.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1174.     }
  1175.  
  1176.     if ($isValid) {
  1177.         //to folder
  1178.         $tofolder = '';
  1179.         if (isset($_POST['tofolder'])) {
  1180.             $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
  1181.             if (fm_mkdir($path . '/' . $tofolder, true)) {
  1182.                 $path .= '/' . $tofolder;
  1183.             }
  1184.         }
  1185.  
  1186.         if($ext == "zip") {
  1187.             $zipper = new FM_Zipper();
  1188.             $res = $zipper->unzip($zip_path, $path);
  1189.         } elseif ($ext == "tar") {
  1190.             try {
  1191.                 $gzipper = new PharData($zip_path);
  1192.                 if (@$gzipper->extractTo($path,null, true)) {
  1193.                     $res = true;
  1194.                 } else {
  1195.                     $res = false;
  1196.                 }
  1197.             } catch (Exception $e) {
  1198.                 //TODO:: need to handle the error
  1199.                 $res = true;
  1200.             }
  1201.         }
  1202.  
  1203.         if ($res) {
  1204.             fm_set_msg(lng('Archive unpacked'));
  1205.         } else {
  1206.             fm_set_msg(lng('Archive not unpacked'), 'error');
  1207.         }
  1208.     } else {
  1209.         fm_set_msg(lng('File not found'), 'error');
  1210.     }
  1211.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1212. }
  1213.  
  1214. // Change Perms (not for Windows)
  1215. if (isset($_POST['chmod'], $_POST['token']) && !FM_READONLY && !FM_IS_WIN) {
  1216.  
  1217.     if(!verifyToken($_POST['token'])) {
  1218.         fm_set_msg(lng("Invalid Token."), 'error');
  1219.     }
  1220.     
  1221.     $path = FM_ROOT_PATH;
  1222.     if (FM_PATH != '') {
  1223.         $path .= '/' . FM_PATH;
  1224.     }
  1225.  
  1226.     $file = $_POST['chmod'];
  1227.     $file = fm_clean_path($file);
  1228.     $file = str_replace('/', '', $file);
  1229.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1230.         fm_set_msg(lng('File not found'), 'error');
  1231.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1232.     }
  1233.  
  1234.     $mode = 0;
  1235.     if (!empty($_POST['ur'])) {
  1236.         $mode |= 0400;
  1237.     }
  1238.     if (!empty($_POST['uw'])) {
  1239.         $mode |= 0200;
  1240.     }
  1241.     if (!empty($_POST['ux'])) {
  1242.         $mode |= 0100;
  1243.     }
  1244.     if (!empty($_POST['gr'])) {
  1245.         $mode |= 0040;
  1246.     }
  1247.     if (!empty($_POST['gw'])) {
  1248.         $mode |= 0020;
  1249.     }
  1250.     if (!empty($_POST['gx'])) {
  1251.         $mode |= 0010;
  1252.     }
  1253.     if (!empty($_POST['or'])) {
  1254.         $mode |= 0004;
  1255.     }
  1256.     if (!empty($_POST['ow'])) {
  1257.         $mode |= 0002;
  1258.     }
  1259.     if (!empty($_POST['ox'])) {
  1260.         $mode |= 0001;
  1261.     }
  1262.  
  1263.     if (@chmod($path . '/' . $file, $mode)) {
  1264.         fm_set_msg(lng('Permissions changed'));
  1265.     } else {
  1266.         fm_set_msg(lng('Permissions not changed'), 'error');
  1267.     }
  1268.  
  1269.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1270. }
  1271.  
  1272. /*************************** ACTIONS ***************************/
  1273.  
  1274. // get current path
  1275. $path = FM_ROOT_PATH;
  1276. if (FM_PATH != '') {
  1277.     $path .= '/' . FM_PATH;
  1278. }
  1279.  
  1280. // check path
  1281. if (!is_dir($path)) {
  1282.     fm_redirect(FM_SELF_URL . '?p=');
  1283. }
  1284.  
  1285. // get parent folder
  1286. $parent = fm_get_parent_path(FM_PATH);
  1287.  
  1288. $objects = is_readable($path) ? scandir($path) : array();
  1289. $folders = array();
  1290. $files = array();
  1291. $current_path = array_slice(explode("/",$path), -1)[0];
  1292. if (is_array($objects) && fm_is_exclude_items($current_path)) {
  1293.     foreach ($objects as $file) {
  1294.         if ($file == '.' || $file == '..') {
  1295.             continue;
  1296.         }
  1297.         if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
  1298.             continue;
  1299.         }
  1300.         $new_path = $path . '/' . $file;
  1301.         if (@is_file($new_path) && fm_is_exclude_items($file)) {
  1302.             $files[] = $file;
  1303.         } elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) {
  1304.             $folders[] = $file;
  1305.         }
  1306.     }
  1307. }
  1308.  
  1309. if (!empty($files)) {
  1310.     natcasesort($files);
  1311. }
  1312. if (!empty($folders)) {
  1313.     natcasesort($folders);
  1314. }
  1315.  
  1316. // upload form
  1317. if (isset($_GET['upload']) && !FM_READONLY) {
  1318.     fm_show_header(); // HEADER
  1319.     fm_show_nav_path(FM_PATH); // current path
  1320.     //get the allowed file extensions
  1321.     function getUploadExt() {
  1322.         $extArr = explode(',', FM_UPLOAD_EXTENSION);
  1323.         if(FM_UPLOAD_EXTENSION && $extArr) {
  1324.             array_walk($extArr, function(&$x) {$x = ".$x";});
  1325.             return implode(',', $extArr);
  1326.         }
  1327.         return '';
  1328.     }
  1329.     ?>
  1330.     <?php print_external('css-dropzone'); ?>
  1331.     <div class="path">
  1332.  
  1333.         <div class="card mb-2 fm-upload-wrapper <?php echo fm_get_theme(); ?>">
  1334.             <div class="card-header">
  1335.                 <ul class="nav nav-tabs card-header-tabs">
  1336.                     <li class="nav-item">
  1337.                         <a class="nav-link active" href="#fileUploader" data-target="#fileUploader"><i class="fa fa-arrow-circle-o-up"></i> <?php echo lng('UploadingFiles') ?></a>
  1338.                     </li>
  1339.                     <li class="nav-item">
  1340.                         <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>
  1341.                     </li>
  1342.                 </ul>
  1343.             </div>
  1344.             <div class="card-body">
  1345.                 <p class="card-text">
  1346.                     <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>
  1347.                     <strong><?php echo lng('DestinationFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_PATH)) ?>
  1348.                 </p>
  1349.  
  1350.                 <form action="<?php echo htmlspecialchars(FM_SELF_URL) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
  1351.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1352.                     <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
  1353.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1354.                     <div class="fallback">
  1355.                         <input name="file" type="file" multiple/>
  1356.                     </div>
  1357.                 </form>
  1358.  
  1359.                 <div class="upload-url-wrapper card-tabs-container hidden" id="urlUploader">
  1360.                     <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="">
  1361.                         <input type="hidden" name="type" value="upload" aria-label="hidden" aria-hidden="true">
  1362.                         <input type="url" placeholder="URL" name="uploadurl" required class="form-control" style="width: 80%">
  1363.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1364.                         <button type="submit" class="btn btn-primary ms-3"><?php echo lng('Upload') ?></button>
  1365.                         <div class="lds-facebook"><div></div><div></div><div></div></div>
  1366.                     </form>
  1367.                     <div id="js-url-upload__list" class="col-9 mt-3"></div>
  1368.                 </div>
  1369.             </div>
  1370.         </div>
  1371.     </div>
  1372.     <?php print_external('js-dropzone'); ?>
  1373.     <script>
  1374.         Dropzone.options.fileUploader = {
  1375.             chunking: true,
  1376.             chunkSize: <?php echo UPLOAD_CHUNK_SIZE; ?>,
  1377.             forceChunking: true,
  1378.             retryChunks: true,
  1379.             retryChunksLimit: 3,
  1380.             parallelUploads: 1,
  1381.             parallelChunkUploads: false,
  1382.             timeout: 120000,
  1383.             maxFilesize: "<?php echo MAX_UPLOAD_SIZE; ?>",
  1384.             acceptedFiles : "<?php echo getUploadExt() ?>",
  1385.             init: function () {
  1386.                 this.on("sending", function (file, xhr, formData) {
  1387.                     let _path = (file.fullPath) ? file.fullPath : file.name;
  1388.                     document.getElementById("fullpath").value = _path;
  1389.                     xhr.ontimeout = (function() {
  1390.                         toast('Error: Server Timeout');
  1391.                     });
  1392.                 }).on("success", function (res) {
  1393.                     let _response = JSON.parse(res.xhr.response);
  1394.  
  1395.                     if(_response.status == "error") {
  1396.                         toast(_response.info);
  1397.                     }
  1398.                 }).on("error", function(file, response) {
  1399.                     toast(response);
  1400.                 });
  1401.             }
  1402.         }
  1403.     </script>
  1404.     <?php
  1405.     fm_show_footer();
  1406.     exit;
  1407. }
  1408.  
  1409. // copy form POST
  1410. if (isset($_POST['copy']) && !FM_READONLY) {
  1411.     $copy_files = isset($_POST['file']) ? $_POST['file'] : null;
  1412.     if (!is_array($copy_files) || empty($copy_files)) {
  1413.         fm_set_msg(lng('Nothing selected'), 'alert');
  1414.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1415.     }
  1416.  
  1417.     fm_show_header(); // HEADER
  1418.     fm_show_nav_path(FM_PATH); // current path
  1419.     ?>
  1420.     <div class="path">
  1421.         <div class="card <?php echo fm_get_theme(); ?>">
  1422.             <div class="card-header">
  1423.                 <h6><?php echo lng('Copying') ?></h6>
  1424.             </div>
  1425.             <div class="card-body">
  1426.                 <form action="" method="post">
  1427.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1428.                     <input type="hidden" name="finish" value="1">
  1429.                     <?php
  1430.                     foreach ($copy_files as $cf) {
  1431.                         echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
  1432.                     }
  1433.                     ?>
  1434.                     <p class="break-word"><strong><?php echo lng('Files') ?></strong>: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
  1435.                     <p class="break-word"><strong><?php echo lng('SourceFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
  1436.                         <label for="inp_copy_to"><strong><?php echo lng('DestinationFolder') ?></strong>:</label>
  1437.                         <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
  1438.                     </p>
  1439.                     <p class="custom-checkbox custom-control"><input type="checkbox" name="move" value="1" id="js-move-files" class="custom-control-input"><label for="js-move-files" class="custom-control-label ms-2"> <?php echo lng('Move') ?></label></p>
  1440.                     <p>
  1441.                         <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> 
  1442.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1443.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Copy') ?></button> 
  1444.                     </p>
  1445.                 </form>
  1446.             </div>
  1447.         </div>
  1448.     </div>
  1449.     <?php
  1450.     fm_show_footer();
  1451.     exit;
  1452. }
  1453.  
  1454. // copy form
  1455. if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
  1456.     $copy = $_GET['copy'];
  1457.     $copy = fm_clean_path($copy);
  1458.     if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
  1459.         fm_set_msg(lng('File not found'), 'error');
  1460.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1461.     }
  1462.  
  1463.     fm_show_header(); // HEADER
  1464.     fm_show_nav_path(FM_PATH); // current path
  1465.     ?>
  1466.     <div class="path">
  1467.         <p><b>Copying</b></p>
  1468.         <p class="break-word">
  1469.             <strong>Source path:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
  1470.             <strong>Destination folder:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  1471.         </p>
  1472.         <p>
  1473.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1"><i class="fa fa-check-circle"></i> Copy</a></b>  
  1474.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1&move=1"><i class="fa fa-check-circle"></i> Move</a></b>  
  1475.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="text-danger"><i class="fa fa-times-circle"></i> Cancel</a></b>
  1476.         </p>
  1477.         <p><i><?php echo lng('Select folder') ?></i></p>
  1478.         <ul class="folders break-word">
  1479.             <?php
  1480.             if ($parent !== false) {
  1481.                 ?>
  1482.                 <li><a href="?p=<?php echo urlencode($parent) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
  1483.                 <?php
  1484.             }
  1485.             foreach ($folders as $f) {
  1486.                 ?>
  1487.                 <li>
  1488.                     <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a></li>
  1489.                 <?php
  1490.             }
  1491.             ?>
  1492.         </ul>
  1493.     </div>
  1494.     <?php
  1495.     fm_show_footer();
  1496.     exit;
  1497. }
  1498.  
  1499. if (isset($_GET['settings']) && !FM_READONLY) {
  1500.     fm_show_header(); // HEADER
  1501.     fm_show_nav_path(FM_PATH); // current path
  1502.     global $cfg, $lang, $lang_list;
  1503.     ?>
  1504.  
  1505.     <div class="col-md-8 offset-md-2 pt-3">
  1506.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1507.             <h6 class="card-header d-flex justify-content-between">
  1508.                 <span><i class="fa fa-cog"></i>  <?php echo lng('Settings') ?></span>
  1509.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel')?></a>
  1510.             </h6>
  1511.             <div class="card-body">
  1512.                 <form id="js-settings-form" action="" method="post" data-type="ajax" onsubmit="return save_settings(this)">
  1513.                     <input type="hidden" name="type" value="settings" aria-label="hidden" aria-hidden="true">
  1514.                     <div class="form-group row">
  1515.                         <label for="js-language" class="col-sm-3 col-form-label"><?php echo lng('Language') ?></label>
  1516.                         <div class="col-sm-5">
  1517.                             <select class="form-select" id="js-language" name="js-language">
  1518.                                 <?php
  1519.                                 function getSelected($l) {
  1520.                                     global $lang;
  1521.                                     return ($lang == $l) ? 'selected' : '';
  1522.                                 }
  1523.                                 foreach ($lang_list as $k => $v) {
  1524.                                     echo "<option value='$k' ".getSelected($k).">$v</option>";
  1525.                                 }
  1526.                                 ?>
  1527.                             </select>
  1528.                         </div>
  1529.                     </div>
  1530.                     <div class="mt-3 mb-3 row ">
  1531.                         <label for="js-error-report" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
  1532.                         <div class="col-sm-9">
  1533.                             <div class="form-check form-switch">
  1534.                               <input class="form-check-input" type="checkbox" role="switch" id="js-error-report" name="js-error-report" value="true" <?php echo $report_errors 'checked' : ''; ?> />
  1535.                             </div>
  1536.                         </div>
  1537.                     </div>
  1538.  
  1539.                     <div class="mb-3 row">
  1540.                         <label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
  1541.                         <div class="col-sm-9">
  1542.                             <div class="form-check form-switch">
  1543.                               <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' : ''; ?> />
  1544.                             </div>
  1545.                         </div>
  1546.                     </div>
  1547.  
  1548.                     <div class="mb-3 row">
  1549.                         <label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
  1550.                         <div class="col-sm-9">
  1551.                             <div class="form-check form-switch">
  1552.                               <input class="form-check-input" type="checkbox" role="switch" id="js-hide-cols" name="js-hide-cols" value="true" <?php echo $hide_Cols 'checked' : ''; ?> />
  1553.                             </div>
  1554.                         </div>
  1555.                     </div>
  1556.  
  1557.                     <div class="mb-3 row">
  1558.                         <label for="js-3-1" class="col-sm-3 col-form-label"><?php echo lng('Theme') ?></label>
  1559.                         <div class="col-sm-5">
  1560.                             <select class="form-select w-100" id="js-3-0" name="js-theme-3">
  1561.                                 <option value='light' <?php if($theme == "light"){echo "selected";} ?>><?php echo lng('light') ?></option>
  1562.                                 <option value='dark' <?php if($theme == "dark"){echo "selected";} ?>><?php echo lng('dark') ?></option>
  1563.                             </select>
  1564.                         </div>
  1565.                     </div>
  1566.  
  1567.                     <div class="mb-3 row">
  1568.                         <div class="col-sm-10">
  1569.                             <button type="submit" class="btn btn-success"> <i class="fa fa-check-circle"></i> <?php echo lng('Save'); ?></button>
  1570.                         </div>
  1571.                     </div>
  1572.  
  1573.                 </form>
  1574.             </div>
  1575.         </div>
  1576.     </div>
  1577.     <?php
  1578.     fm_show_footer();
  1579.     exit;
  1580. }
  1581.  
  1582. if (isset($_GET['help'])) {
  1583.     fm_show_header(); // HEADER
  1584.     fm_show_nav_path(FM_PATH); // current path
  1585.     global $cfg, $lang;
  1586.     ?>
  1587.  
  1588.     <div class="col-md-8 offset-md-2 pt-3">
  1589.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1590.             <h6 class="card-header d-flex justify-content-between">
  1591.                 <span><i class="fa fa-exclamation-circle"></i> <?php echo lng('Help') ?></span>
  1592.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel')?></a>
  1593.             </h6>
  1594.             <div class="card-body">
  1595.                 <div class="row">
  1596.                     <div class="col-xs-12 col-sm-6">
  1597.                         <p><h3><a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="app-v-title"> Tiny File Manager <?php echo VERSION; ?></a></h3></p>
  1598.                         <p>Author: Prasath Mani</p>
  1599.                         <p>Mail Us: <a href="mailto:[email protected]">ccpprogrammers[at]gmail.com</a> </p>
  1600.                     </div>
  1601.                     <div class="col-xs-12 col-sm-6">
  1602.                         <div class="card">
  1603.                             <ul class="list-group list-group-flush">
  1604.                                 <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>
  1605.                                 <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>
  1606.                                 <?php if(!FM_READONLY) { ?>
  1607.                                 <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>
  1608.                                 <?php } ?>
  1609.                             </ul>
  1610.                         </div>
  1611.                     </div>
  1612.                 </div>
  1613.                 <div class="row js-new-pwd hidden mt-2">
  1614.                     <div class="col-12">
  1615.                         <form class="form-inline" onsubmit="return new_password_hash(this)" method="POST" action="">
  1616.                             <input type="hidden" name="type" value="pwdhash" aria-label="hidden" aria-hidden="true">
  1617.                             <div class="form-group mb-2">
  1618.                                 <label for="staticEmail2"><?php echo lng('Generate new password hash') ?></label>
  1619.                             </div>
  1620.                             <div class="form-group mx-sm-3 mb-2">
  1621.                                 <label for="inputPassword2" class="sr-only"><?php echo lng('Password') ?></label>
  1622.                                 <input type="text" class="form-control btn-sm" id="inputPassword2" name="inputPassword2" placeholder="<?php echo lng('Password') ?>" required>
  1623.                             </div>
  1624.                             <button type="submit" class="btn btn-success btn-sm mb-2"><?php echo lng('Generate') ?></button>
  1625.                         </form>
  1626.                         <textarea class="form-control" rows="2" readonly id="js-pwd-result"></textarea>
  1627.                     </div>
  1628.                 </div>
  1629.             </div>
  1630.         </div>
  1631.     </div>
  1632.     <?php
  1633.     fm_show_footer();
  1634.     exit;
  1635. }
  1636.  
  1637. // file viewer
  1638. if (isset($_GET['view'])) {
  1639.     $file = $_GET['view'];
  1640.     $file = fm_clean_path($file, false);
  1641.     $file = str_replace('/', '', $file);
  1642.     if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
  1643.         fm_set_msg(lng('File not found'), 'error');
  1644.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1645.     }
  1646.  
  1647.     fm_show_header(); // HEADER
  1648.     fm_show_nav_path(FM_PATH); // current path
  1649.  
  1650.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1651.     $file_path = $path . '/' . $file;
  1652.  
  1653.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1654.     $mime_type = fm_get_mime_type($file_path);
  1655.     $filesize_raw = fm_get_size($file_path);
  1656.     $filesize = fm_get_filesize($filesize_raw);
  1657.  
  1658.     $is_zip = false;
  1659.     $is_gzip = false;
  1660.     $is_image = false;
  1661.     $is_audio = false;
  1662.     $is_video = false;
  1663.     $is_text = false;
  1664.     $is_onlineViewer = false;
  1665.  
  1666.     $view_title = 'File';
  1667.     $filenames = false; // for zip
  1668.     $content = ''; // for text
  1669.     $online_viewer = strtolower(FM_DOC_VIEWER);
  1670.  
  1671.     if($online_viewer && $online_viewer !== 'false' && in_array($ext, fm_get_onlineViewer_exts())){
  1672.         $is_onlineViewer = true;
  1673.     }
  1674.     elseif ($ext == 'zip' || $ext == 'tar') {
  1675.         $is_zip = true;
  1676.         $view_title = 'Archive';
  1677.         $filenames = fm_get_zif_info($file_path, $ext);
  1678.     } elseif (in_array($ext, fm_get_image_exts())) {
  1679.         $is_image = true;
  1680.         $view_title = 'Image';
  1681.     } elseif (in_array($ext, fm_get_audio_exts())) {
  1682.         $is_audio = true;
  1683.         $view_title = 'Audio';
  1684.     } elseif (in_array($ext, fm_get_video_exts())) {
  1685.         $is_video = true;
  1686.         $view_title = 'Video';
  1687.     } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1688.         $is_text = true;
  1689.         $content = file_get_contents($file_path);
  1690.     }
  1691.  
  1692.     ?>
  1693.     <div class="row">
  1694.         <div class="col-12">
  1695.             <p class="break-word"><b><?php echo lng($view_title) ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p>
  1696.             <p class="break-word">
  1697.                 <?php $display_path = fm_get_display_path($file_path); ?>
  1698.                 <strong><?php echo $display_path['label']; ?>:</strong> <?php echo $display_path['path']; ?><br>
  1699.                 <strong>File size:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?><br>
  1700.                 <strong>MIME-type:</strong> <?php echo $mime_type ?><br>
  1701.                 <?php
  1702.                 // ZIP info
  1703.                 if (($is_zip || $is_gzip) && $filenames !== false) {
  1704.                     $total_files = 0;
  1705.                     $total_comp = 0;
  1706.                     $total_uncomp = 0;
  1707.                     foreach ($filenames as $fn) {
  1708.                         if (!$fn['folder']) {
  1709.                             $total_files++;
  1710.                         }
  1711.                         $total_comp += $fn['compressed_size'];
  1712.                         $total_uncomp += $fn['filesize'];
  1713.                     }
  1714.                     ?>
  1715.                     <?php echo lng('Files in archive') ?><?php echo $total_files ?><br>
  1716.                     <?php echo lng('Total size') ?><?php echo fm_get_filesize($total_uncomp) ?><br>
  1717.                     <?php echo lng('Size in archive') ?><?php echo fm_get_filesize($total_comp) ?><br>
  1718.                     <?php echo lng('Compression') ?><?php echo round(($total_comp / max($total_uncomp, 1)) * 100) ?>%<br>
  1719.                     <?php
  1720.                 }
  1721.                 // Image info
  1722.                 if ($is_image) {
  1723.                     $image_size = getimagesize($file_path);
  1724.                     echo '<strong>'.lng('Image size').':</strong> ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
  1725.                 }
  1726.                 // Text info
  1727.                 if ($is_text) {
  1728.                     $is_utf8 = fm_is_utf8($content);
  1729.                     if (function_exists('iconv')) {
  1730.                         if (!$is_utf8) {
  1731.                             $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
  1732.                         }
  1733.                     }
  1734.                     echo '<strong>'.lng('Charset').':</strong> ' . ($is_utf8 'utf-8' : '8 bit') . '<br>';
  1735.                 }
  1736.                 ?>
  1737.             </p>
  1738.             <div class="d-flex align-items-center mb-3">
  1739.                 <form method="post" class="d-inline ms-2" action="?p=<?php echo urlencode(FM_PATH) ?>&dl=<?php echo urlencode($file) ?>">
  1740.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1741.                     <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0"><i class="fa fa-cloud-download"></i> <?php echo lng('Download') ?></button>  
  1742.                 </form>
  1743.                 <b class="ms-2"><a href="<?php echo fm_enc($file_url) ?>" target="_blank"><i class="fa fa-external-link-square"></i> <?php echo lng('Open') ?></a></b>
  1744.                 <?php
  1745.                 // ZIP actions
  1746.                 if (!FM_READONLY && ($is_zip || $is_gzip) && $filenames !== false) {
  1747.                     $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
  1748.                     ?>
  1749.                     <form method="post" class="d-inline ms-2">
  1750.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1751.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1752.                         <button type="submit" class="btn btn-link text-decoration-none fw-bold p-0" style="font-size: 14px;"><i class="fa fa-check-circle"></i> <?php echo lng('UnZip') ?></button>
  1753.                     </form> 
  1754.                     <form method="post" class="d-inline ms-2">
  1755.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1756.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1757.                         <input type="hidden" name="tofolder" value="1">
  1758.                         <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>
  1759.                     </form> 
  1760.                     <?php
  1761.                 }
  1762.                 if ($is_text && !FM_READONLY) {
  1763.                     ?>
  1764.                     <b class="ms-2"><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>" class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo lng('Edit') ?>
  1765.                         </a></b>  
  1766.                     <b class="ms-2"><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace"
  1767.                             class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?>
  1768.                         </a></b>  
  1769.                 <?php } ?>
  1770.                 <b class="ms-2"><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back') ?></a></b>
  1771.             </div>
  1772.             <?php
  1773.             if($is_onlineViewer) {
  1774.                 if($online_viewer == 'google') {
  1775.                     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>';
  1776.                 } else if($online_viewer == 'microsoft') {
  1777.                     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>';
  1778.                 }
  1779.             } elseif ($is_zip) {
  1780.                 // ZIP content
  1781.                 if ($filenames !== false) {
  1782.                     echo '<code class="maxheight">';
  1783.                     foreach ($filenames as $fn) {
  1784.                         if ($fn['folder']) {
  1785.                             echo '<b>' . fm_enc($fn['name']) . '</b><br>';
  1786.                         } else {
  1787.                             echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
  1788.                         }
  1789.                     }
  1790.                     echo '</code>';
  1791.                 } else {
  1792.                     echo '<p>'.lng('Error while fetching archive info').'</p>';
  1793.                 }
  1794.             } elseif ($is_image) {
  1795.                 // Image content
  1796.                 if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))) {
  1797.                     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>';
  1798.                 }
  1799.             } elseif ($is_audio) {
  1800.                 // Audio content
  1801.                 echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
  1802.             } elseif ($is_video) {
  1803.                 // Video content
  1804.                 echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
  1805.             } elseif ($is_text) {
  1806.                 if (FM_USE_HIGHLIGHTJS) {
  1807.                     // highlight
  1808.                     $hljs_classes = array(
  1809.                         'shtml' => 'xml',
  1810.                         'htaccess' => 'apache',
  1811.                         'phtml' => 'php',
  1812.                         'lock' => 'json',
  1813.                         'svg' => 'xml',
  1814.                     );
  1815.                     $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
  1816.                     if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
  1817.                         $hljs_class = 'nohighlight';
  1818.                     }
  1819.                     $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
  1820.                 } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
  1821.                     // php highlight
  1822.                     $content = highlight_string($content, true);
  1823.                 } else {
  1824.                     $content = '<pre>' . fm_enc($content) . '</pre>';
  1825.                 }
  1826.                 echo $content;
  1827.             }
  1828.             ?>
  1829.         </div>
  1830.     </div>
  1831.     <?php
  1832.         fm_show_footer();
  1833.     exit;
  1834. }
  1835.  
  1836. // file editor
  1837. if (isset($_GET['edit']) && !FM_READONLY) {
  1838.     $file = $_GET['edit'];
  1839.     $file = fm_clean_path($file, false);
  1840.     $file = str_replace('/', '', $file);
  1841.     if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
  1842.         fm_set_msg(lng('File not found'), 'error');
  1843.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1844.     }
  1845.     $editFile = ' : <i><b>'. $file. '</b></i>';
  1846.     header('X-XSS-Protection:0');
  1847.     fm_show_header(); // HEADER
  1848.     fm_show_nav_path(FM_PATH); // current path
  1849.  
  1850.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1851.     $file_path = $path . '/' . $file;
  1852.  
  1853.     // normal editer
  1854.     $isNormalEditor = true;
  1855.     if (isset($_GET['env'])) {
  1856.         if ($_GET['env'] == "ace") {
  1857.             $isNormalEditor = false;
  1858.         }
  1859.     }
  1860.  
  1861.     // Save File
  1862.     if (isset($_POST['savedata'])) {
  1863.         $writedata = $_POST['savedata'];
  1864.         $fd = fopen($file_path, "w");
  1865.         @fwrite($fd, $writedata);
  1866.         fclose($fd);
  1867.         fm_set_msg(lng('File Saved Successfully'));
  1868.     }
  1869.  
  1870.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1871.     $mime_type = fm_get_mime_type($file_path);
  1872.     $filesize = filesize($file_path);
  1873.     $is_text = false;
  1874.     $content = ''; // for text
  1875.  
  1876.     if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1877.         $is_text = true;
  1878.         $content = file_get_contents($file_path);
  1879.     }
  1880.  
  1881.     ?>
  1882.     <div class="path">
  1883.         <div class="row">
  1884.             <div class="col-xs-12 col-sm-5 col-lg-6 pt-1">
  1885.                 <div class="btn-toolbar" role="toolbar">
  1886.                     <?php if (!$isNormalEditor) { ?>
  1887.                         <div class="btn-group js-ace-toolbar">
  1888.                             <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>
  1889.                             <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>
  1890.                             <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>
  1891.                             <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>
  1892.                             <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>
  1893.                             <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"><option>-- <?php echo lng('Select Mode') ?> --</option></select>
  1894.                             <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"><option>-- <?php echo lng('Select Theme') ?> --</option></select>
  1895.                             <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"><option>-- <?php echo lng('Select Font Size') ?> --</option></select>
  1896.                         </div>
  1897.                     <?php } ?>
  1898.                 </div>
  1899.             </div>
  1900.             <div class="edit-file-actions col-xs-12 col-sm-7 col-lg-6 text-end pt-1">
  1901.                 <a title="<?php echo lng('Back') ?>" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> <?php echo lng('Back') ?></a>
  1902.                 <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>
  1903.                 <?php if ($is_text) { ?>
  1904.                     <?php if ($isNormalEditor) { ?>
  1905.                         <a title="Advanced" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?></a>
  1906.                         <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
  1907.                         </button>
  1908.                     <?php } else { ?>
  1909.                         <a title="Plain Editor" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> <?php echo lng('NormalEditor') ?></a>
  1910.                         <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') ?>
  1911.                         </button>
  1912.                     <?php } ?>
  1913.                 <?php } ?>
  1914.             </div>
  1915.         </div>
  1916.         <?php
  1917.         if ($is_text && $isNormalEditor) {
  1918.             echo '<textarea class="mt-2" id="normal-editor" rows="33" cols="120" style="width: 99.5%;">' . htmlspecialchars($content) . '</textarea>';
  1919.             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>';
  1920.         } elseif ($is_text) {
  1921.             echo '<div id="editor" contenteditable="true">' . htmlspecialchars($content) . '</div>';
  1922.         } else {
  1923.             fm_set_msg(lng('FILE EXTENSION HAS NOT SUPPORTED'), 'error');
  1924.         }
  1925.         ?>
  1926.     </div>
  1927.     <?php
  1928.     fm_show_footer();
  1929.     exit;
  1930. }
  1931.  
  1932. // chmod (not for Windows)
  1933. if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  1934.     $file = $_GET['chmod'];
  1935.     $file = fm_clean_path($file);
  1936.     $file = str_replace('/', '', $file);
  1937.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1938.         fm_set_msg(lng('File not found'), 'error');
  1939.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1940.     }
  1941.  
  1942.     fm_show_header(); // HEADER
  1943.     fm_show_nav_path(FM_PATH); // current path
  1944.  
  1945.     $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
  1946.     $file_path = $path . '/' . $file;
  1947.  
  1948.     $mode = fileperms($path . '/' . $file);
  1949.     ?>
  1950.     <div class="path">
  1951.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1952.             <h6 class="card-header">
  1953.                 <?php echo lng('ChangePermissions') ?>
  1954.             </h6>
  1955.             <div class="card-body">
  1956.                 <p class="card-text">
  1957.                     <?php $display_path = fm_get_display_path($file_path); ?>
  1958.                     <?php echo $display_path['label']; ?><?php echo $display_path['path']; ?><br>
  1959.                 </p>
  1960.                 <form action="" method="post">
  1961.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1962.                     <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
  1963.  
  1964.                     <table class="table compact-table <?php echo fm_get_theme(); ?>">
  1965.                         <tr>
  1966.                             <td></td>
  1967.                             <td><b><?php echo lng('Owner') ?></b></td>
  1968.                             <td><b><?php echo lng('Group') ?></b></td>
  1969.                             <td><b><?php echo lng('Other') ?></b></td>
  1970.                         </tr>
  1971.                         <tr>
  1972.                             <td style="text-align: right"><b><?php echo lng('Read') ?></b></td>
  1973.                             <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
  1974.                             <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
  1975.                             <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
  1976.                         </tr>
  1977.                         <tr>
  1978.                             <td style="text-align: right"><b><?php echo lng('Write') ?></b></td>
  1979.                             <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
  1980.                             <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
  1981.                             <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
  1982.                         </tr>
  1983.                         <tr>
  1984.                             <td style="text-align: right"><b><?php echo lng('Execute') ?></b></td>
  1985.                             <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
  1986.                             <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
  1987.                             <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
  1988.                         </tr>
  1989.                     </table>
  1990.  
  1991.                     <p>
  1992.                        <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>"> 
  1993.                         <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> 
  1994.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Change') ?></button>
  1995.                     </p>
  1996.                 </form>
  1997.             </div>
  1998.         </div>
  1999.     </div>
  2000.     <?php
  2001.     fm_show_footer();
  2002.     exit;
  2003. }
  2004.  
  2005. // --- TINYFILEMANAGER MAIN ---
  2006. fm_show_header(); // HEADER
  2007. fm_show_nav_path(FM_PATH); // current path
  2008.  
  2009. // show alert messages
  2010. fm_show_message();
  2011.  
  2012. $num_files = count($files);
  2013. $num_folders = count($folders);
  2014. $all_files_size = 0;
  2015. $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white";
  2016. ?>
  2017. <form action="" method="post" class="pt-3">
  2018.     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  2019.     <input type="hidden" name="group" value="1">
  2020.     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  2021.     <div class="table-responsive">
  2022.         <table class="table table-bordered table-hover table-sm <?php echo $tableTheme; ?>" id="main-table">
  2023.             <thead class="thead-white">
  2024.             <tr>
  2025.                 <?php if (!FM_READONLY): ?>
  2026.                     <th style="width:3%" class="custom-checkbox-header">
  2027.                         <div class="custom-control custom-checkbox">
  2028.                             <input type="checkbox" class="custom-control-input" id="js-select-all-items" onclick="checkbox_toggle()">
  2029.                             <label class="custom-control-label" for="js-select-all-items"></label>
  2030.                         </div>
  2031.                     </th><?php endif; ?>
  2032.                 <th><?php echo lng('Name') ?></th>
  2033.                 <th><?php echo lng('Size') ?></th>
  2034.                 <th><?php echo lng('Modified') ?></th>
  2035.                 <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2036.                     <th><?php echo lng('Perms') ?></th>
  2037.                     <th><?php echo lng('Owner') ?></th><?php endif; ?>
  2038.                 <th><?php echo lng('Actions') ?></th>
  2039.             </tr>
  2040.             </thead>
  2041.             <?php
  2042.             // link to parent folder
  2043.             if ($parent !== false) {
  2044.                 ?>
  2045.                 <tr><?php if (!FM_READONLY): ?>
  2046.                     <td class="nosort"></td><?php endif; ?>
  2047.                     <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>
  2048.                     <td class="border-0" data-order></td>
  2049.                     <td class="border-0" data-order></td>
  2050.                     <td class="border-0"></td>
  2051.                     <?php if (!FM_IS_WIN && !$hide_Cols) { ?>
  2052.                         <td class="border-0"></td>
  2053.                         <td class="border-0"></td>
  2054.                     <?php } ?>
  2055.                 </tr>
  2056.                 <?php
  2057.             }
  2058.             $ii = 3399;
  2059.             foreach ($folders as $f) {
  2060.                 $is_link = is_link($path . '/' . $f);
  2061.                 $img = $is_link 'icon-link_folder' : 'fa fa-folder-o';
  2062.                 $modif_raw = filemtime($path . '/' . $f);
  2063.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2064.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2065.                 $filesize_raw = "";
  2066.                 $filesize = lng('Folder');
  2067.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2068.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2069.                     $owner = posix_getpwuid(fileowner($path . '/' . $f));
  2070.                     $group = posix_getgrgid(filegroup($path . '/' . $f));
  2071.                     if ($owner === false) {
  2072.                         $owner = array('name' => '?');
  2073.                     }
  2074.                     if ($group === false) {
  2075.                         $group = array('name' => '?');
  2076.                     }
  2077.                 } else {
  2078.                     $owner = array('name' => '?');
  2079.                     $group = array('name' => '?');
  2080.                 }
  2081.                 ?>
  2082.                 <tr>
  2083.                     <?php if (!FM_READONLY): ?>
  2084.                         <td class="custom-checkbox-td">
  2085.                         <div class="custom-control custom-checkbox">
  2086.                             <input type="checkbox" class="custom-control-input" id="<?php echo $ii ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2087.                             <label class="custom-control-label" for="<?php echo $ii ?>"></label>
  2088.                         </div>
  2089.                         </td><?php endif; ?>
  2090.                     <td data-sort=<?php echo fm_convert_win(fm_enc($f)) ?>>
  2091.                         <div class="filename"><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?>
  2092.                             </a><?php echo($is_link ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div>
  2093.                     </td>
  2094.                     <td data-order="a-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT);?>">
  2095.                         <?php echo $filesize; ?>
  2096.                     </td>
  2097.                     <td data-order="a-<?php echo $date_sorting;?>"><?php echo $modif ?></td>
  2098.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2099.                         <td><?php if (!FM_READONLY): ?><a title="Change Permissions" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  2100.                         </td>
  2101.                         <td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
  2102.                     <?php endif; ?>
  2103.                     <td class="inline-actions"><?php if (!FM_READONLY): ?>
  2104.                             <a title="<?php echo lng('Delete')?>" href="?p=<?php echo urlencode(FM_PATH) ?>&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>
  2105.                             <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>
  2106.                             <a title="<?php echo lng('CopyTo')?>..." href="?p=&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
  2107.                         <?php endif; ?>
  2108.                         <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>
  2109.                     </td>
  2110.                 </tr>
  2111.                 <?php
  2112.                 flush();
  2113.                 $ii++;
  2114.             }
  2115.             $ik = 6070;
  2116.             foreach ($files as $f) {
  2117.                 $is_link = is_link($path . '/' . $f);
  2118.                 $img = $is_link 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
  2119.                 $modif_raw = filemtime($path . '/' . $f);
  2120.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2121.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2122.                 $filesize_raw = fm_get_size($path . '/' . $f);
  2123.                 $filesize = fm_get_filesize($filesize_raw);
  2124.                 $filelink = '?p=' . urlencode(FM_PATH) . '&view=' . urlencode($f);
  2125.                 $all_files_size += $filesize_raw;
  2126.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2127.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2128.                     $owner = posix_getpwuid(fileowner($path . '/' . $f));
  2129.                     $group = posix_getgrgid(filegroup($path . '/' . $f));
  2130.                     if ($owner === false) {
  2131.                         $owner = array('name' => '?');
  2132.                     }
  2133.                     if ($group === false) {
  2134.                         $group = array('name' => '?');
  2135.                     }
  2136.                 } else {
  2137.                     $owner = array('name' => '?');
  2138.                     $group = array('name' => '?');
  2139.                 }
  2140.                 ?>
  2141.                 <tr>
  2142.                     <?php if (!FM_READONLY): ?>
  2143.                         <td class="custom-checkbox-td">
  2144.                         <div class="custom-control custom-checkbox">
  2145.                             <input type="checkbox" class="custom-control-input" id="<?php echo $ik ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2146.                             <label class="custom-control-label" for="<?php echo $ik ?>"></label>
  2147.                         </div>
  2148.                         </td><?php endif; ?>
  2149.                     <td data-sort=<?php echo fm_enc($f) ?>>
  2150.                         <div class="filename">
  2151.                         <?php
  2152.                            if (in_array(strtolower(pathinfo($f, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))): ?>
  2153.                                 <?php $imagePreview = fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f); ?>
  2154.                                 <a href="<?php echo $filelink ?>" data-preview-image="<?php echo $imagePreview ?>" title="<?php echo fm_enc($f) ?>">
  2155.                            <?php else: ?>
  2156.                                 <a href="<?php echo $filelink ?>" title="<?php echo $f ?>">
  2157.                             <?php endif; ?>
  2158.                                     <i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?>
  2159.                                 </a>
  2160.                                 <?php echo($is_link ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  2161.                         </div>
  2162.                     </td>
  2163.                     <td data-order="b-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>"><span title="<?php printf('%s bytes', $filesize_raw) ?>">
  2164.                         <?php echo $filesize; ?>
  2165.                         </span></td>
  2166.                     <td data-order="b-<?php echo $date_sorting;?>"><?php echo $modif ?></td>
  2167.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2168.                         <td><?php if (!FM_READONLY): ?><a title="<?php echo 'Change Permissions' ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  2169.                         </td>
  2170.                         <td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
  2171.                     <?php endif; ?>
  2172.                     <td class="inline-actions">
  2173.                         <?php if (!FM_READONLY): ?>
  2174.                             <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&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>
  2175.                             <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>
  2176.                             <a title="<?php echo lng('CopyTo') ?>..."
  2177.                                href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
  2178.                         <?php endif; ?>
  2179.                         <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>
  2180.                         <a title="<?php echo lng('Download') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&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>
  2181.                     </td>
  2182.                 </tr>
  2183.                 <?php
  2184.                 flush();
  2185.                 $ik++;
  2186.             }
  2187.  
  2188.             if (empty($folders) && empty($files)) { ?>
  2189.                 <tfoot>
  2190.                     <tr><?php if (!FM_READONLY): ?>
  2191.                             <td></td><?php endif; ?>
  2192.                         <td colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>"><em><?php echo lng('Folder is empty') ?></em></td>
  2193.                     </tr>
  2194.                 </tfoot>
  2195.                 <?php
  2196.             } else { ?>
  2197.                 <tfoot>
  2198.                     <tr>
  2199.                         <td class="gray" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' :'7') : (FM_READONLY ? '4' : '5') ?>">
  2200.                             <?php echo lng('FullSize').': <span class="badge text-bg-light border-radius-0">'.fm_get_filesize($all_files_size).'</span>' ?>
  2201.                             <?php echo lng('File').': <span class="badge text-bg-light border-radius-0">'.$num_files.'</span>' ?>
  2202.                             <?php echo lng('Folder').': <span class="badge text-bg-light border-radius-0">'.$num_folders.'</span>' ?>
  2203.                         </td>
  2204.                     </tr>
  2205.                 </tfoot>
  2206.                 <?php } ?>
  2207.         </table>
  2208.     </div>
  2209.  
  2210.     <div class="row">
  2211.         <?php if (!FM_READONLY): ?>
  2212.         <div class="col-xs-12 col-sm-9">
  2213.             <ul class="list-inline footer-action">
  2214.                 <li class="list-inline-item"> <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></li>
  2215.                 <li class="list-inline-item"><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></li>
  2216.                 <li class="list-inline-item"><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></li>
  2217.                 <li class="list-inline-item"><input type="submit" class="hidden" name="delete" id="a-delete" value="Delete" onclick="return confirm('<?php echo lng('Delete selected files and folders?'); ?>')">
  2218.                     <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></li>
  2219.                 <li class="list-inline-item"><input type="submit" class="hidden" name="zip" id="a-zip" value="zip" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2220.                     <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></li>
  2221.                 <li class="list-inline-item"><input type="submit" class="hidden" name="tar" id="a-tar" value="tar" onclick="return confirm('<?php echo lng('Create archive?'); ?>')">
  2222.                     <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></li>
  2223.                 <li class="list-inline-item"><input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
  2224.                     <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></li>
  2225.             </ul>
  2226.         </div>
  2227.         <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>
  2228.         <?php else: ?>
  2229.             <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>
  2230.         <?php endif; ?>
  2231.     </div>
  2232. </form>
  2233.  
  2234. <?php
  2235. fm_show_footer();
  2236.  
  2237. // --- END HTML ---
  2238.  
  2239. // Functions
  2240.  
  2241. /**
  2242.  * It prints the css/js files into html
  2243.  * @param key The key of the external file to print.
  2244.  */
  2245. function print_external($key) {
  2246.     global $external;
  2247.  
  2248.     if(!array_key_exists($key, $external)) {
  2249.         // throw new Exception('Key missing in external: ' . key);
  2250.         echo "<!-- EXTERNAL: MISSING KEY $key -->";
  2251.         return;
  2252.     }
  2253.  
  2254.     echo "$external[$key]";
  2255. }
  2256.  
  2257. /**
  2258.  * Verify CSRF TOKEN and remove after cerify
  2259.  * @param string $token
  2260.  * @return bool
  2261.  */
  2262. function verifyToken($token) 
  2263. {
  2264.     if (hash_equals($_SESSION['token'], $token)) { 
  2265.         return true;
  2266.     }
  2267.     return false;
  2268. }
  2269.  
  2270. /**
  2271.  * Delete  file or folder (recursively)
  2272.  * @param string $path
  2273.  * @return bool
  2274.  */
  2275. function fm_rdelete($path)
  2276. {
  2277.     if (is_link($path)) {
  2278.         return unlink($path);
  2279.     } elseif (is_dir($path)) {
  2280.         $objects = scandir($path);
  2281.         $ok = true;
  2282.         if (is_array($objects)) {
  2283.             foreach ($objects as $file) {
  2284.                 if ($file != '.' && $file != '..') {
  2285.                     if (!fm_rdelete($path . '/' . $file)) {
  2286.                         $ok = false;
  2287.                     }
  2288.                 }
  2289.             }
  2290.         }
  2291.         return ($ok) ? rmdir($path) : false;
  2292.     } elseif (is_file($path)) {
  2293.         return unlink($path);
  2294.     }
  2295.     return false;
  2296. }
  2297.  
  2298. /**
  2299.  * Recursive chmod
  2300.  * @param string $path
  2301.  * @param int $filemode
  2302.  * @param int $dirmode
  2303.  * @return bool
  2304.  * @todo Will use in mass chmod
  2305.  */
  2306. function fm_rchmod($path, $filemode, $dirmode)
  2307. {
  2308.     if (is_dir($path)) {
  2309.         if (!chmod($path, $dirmode)) {
  2310.             return false;
  2311.         }
  2312.         $objects = scandir($path);
  2313.         if (is_array($objects)) {
  2314.             foreach ($objects as $file) {
  2315.                 if ($file != '.' && $file != '..') {
  2316.                     if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
  2317.                         return false;
  2318.                     }
  2319.                 }
  2320.             }
  2321.         }
  2322.         return true;
  2323.     } elseif (is_link($path)) {
  2324.         return true;
  2325.     } elseif (is_file($path)) {
  2326.         return chmod($path, $filemode);
  2327.     }
  2328.     return false;
  2329. }
  2330.  
  2331. /**
  2332.  * Check the file extension which is allowed or not
  2333.  * @param string $filename
  2334.  * @return bool
  2335.  */
  2336. function fm_is_valid_ext($filename)
  2337. {
  2338.     $allowed = (FM_FILE_EXTENSION) ? explode(',', FM_FILE_EXTENSION) : false;
  2339.  
  2340.     $ext = pathinfo($filename, PATHINFO_EXTENSION);
  2341.     $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  2342.  
  2343.     return ($isFileAllowed) ? true : false;
  2344. }
  2345.  
  2346. /**
  2347.  * Safely rename
  2348.  * @param string $old
  2349.  * @param string $new
  2350.  * @return bool|null
  2351.  */
  2352. function fm_rename($old, $new)
  2353. {
  2354.     $isFileAllowed = fm_is_valid_ext($new);
  2355.  
  2356.     if(!is_dir($old)) {
  2357.         if (!$isFileAllowed) return false;
  2358.     }
  2359.  
  2360.     return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
  2361. }
  2362.  
  2363. /**
  2364.  * Copy file or folder (recursively).
  2365.  * @param string $path
  2366.  * @param string $dest
  2367.  * @param bool $upd Update files
  2368.  * @param bool $force Create folder with same names instead file
  2369.  * @return bool
  2370.  */
  2371. function fm_rcopy($path, $dest, $upd = true, $force = true)
  2372. {
  2373.     if (is_dir($path)) {
  2374.         if (!fm_mkdir($dest, $force)) {
  2375.             return false;
  2376.         }
  2377.         $objects = scandir($path);
  2378.         $ok = true;
  2379.         if (is_array($objects)) {
  2380.             foreach ($objects as $file) {
  2381.                 if ($file != '.' && $file != '..') {
  2382.                     if (!fm_rcopy($path . '/' . $file, $dest . '/' . $file)) {
  2383.                         $ok = false;
  2384.                     }
  2385.                 }
  2386.             }
  2387.         }
  2388.         return $ok;
  2389.     } elseif (is_file($path)) {
  2390.         return fm_copy($path, $dest, $upd);
  2391.     }
  2392.     return false;
  2393. }
  2394.  
  2395. /**
  2396.  * Safely create folder
  2397.  * @param string $dir
  2398.  * @param bool $force
  2399.  * @return bool
  2400.  */
  2401. function fm_mkdir($dir, $force)
  2402. {
  2403.     if (file_exists($dir)) {
  2404.         if (is_dir($dir)) {
  2405.             return $dir;
  2406.         } elseif (!$force) {
  2407.             return false;
  2408.         }
  2409.         unlink($dir);
  2410.     }
  2411.     return mkdir($dir, 0777, true);
  2412. }
  2413.  
  2414. /**
  2415.  * Safely copy file
  2416.  * @param string $f1
  2417.  * @param string $f2
  2418.  * @param bool $upd Indicates if file should be updated with new content
  2419.  * @return bool
  2420.  */
  2421. function fm_copy($f1, $f2, $upd)
  2422. {
  2423.     $time1 = filemtime($f1);
  2424.     if (file_exists($f2)) {
  2425.         $time2 = filemtime($f2);
  2426.         if ($time2 >= $time1 && $upd) {
  2427.             return false;
  2428.         }
  2429.     }
  2430.     $ok = copy($f1, $f2);
  2431.     if ($ok) {
  2432.         touch($f2, $time1);
  2433.     }
  2434.     return $ok;
  2435. }
  2436.  
  2437. /**
  2438.  * Get mime type
  2439.  * @param string $file_path
  2440.  * @return mixed|string
  2441.  */
  2442. function fm_get_mime_type($file_path)
  2443. {
  2444.     if (function_exists('finfo_open')) {
  2445.         $finfo = finfo_open(FILEINFO_MIME_TYPE);
  2446.         $mime = finfo_file($finfo, $file_path);
  2447.         finfo_close($finfo);
  2448.         return $mime;
  2449.     } elseif (function_exists('mime_content_type')) {
  2450.         return mime_content_type($file_path);
  2451.     } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
  2452.         $file = escapeshellarg($file_path);
  2453.         $mime = shell_exec('file -bi ' . $file);
  2454.         return $mime;
  2455.     } else {
  2456.         return '--';
  2457.     }
  2458. }
  2459.  
  2460. /**
  2461.  * HTTP Redirect
  2462.  * @param string $url
  2463.  * @param int $code
  2464.  */
  2465. function fm_redirect($url, $code = 302)
  2466. {
  2467.     header('Location: ' . $url, true, $code);
  2468.     exit;
  2469. }
  2470.  
  2471. /**
  2472.  * Path traversal prevention and clean the url
  2473.  * It replaces (consecutive) occurrences of / and \\ with whatever is in DIRECTORY_SEPARATOR, and processes /. and /.. fine.
  2474.  * @param $path
  2475.  * @return string
  2476.  */
  2477. function get_absolute_path($path) {
  2478.     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
  2479.     $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
  2480.     $absolutes = array();
  2481.     foreach ($parts as $part) {
  2482.         if ('.' == $part) continue;
  2483.         if ('..' == $part) {
  2484.             array_pop($absolutes);
  2485.         } else {
  2486.             $absolutes[] = $part;
  2487.         }
  2488.     }
  2489.     return implode(DIRECTORY_SEPARATOR, $absolutes);
  2490. }
  2491.  
  2492. /**
  2493.  * Clean path
  2494.  * @param string $path
  2495.  * @return string
  2496.  */
  2497. function fm_clean_path($path, $trim = true)
  2498. {
  2499.     $path = $trim trim($path) : $path;
  2500.     $path = trim($path, '\\/');
  2501.     $path = str_replace(array('../', '..\\'), '', $path);
  2502.     $path =  get_absolute_path($path);
  2503.     if ($path == '..') {
  2504.         $path = '';
  2505.     }
  2506.     return str_replace('\\', '/', $path);
  2507. }
  2508.  
  2509. /**
  2510.  * Get parent path
  2511.  * @param string $path
  2512.  * @return bool|string
  2513.  */
  2514. function fm_get_parent_path($path)
  2515. {
  2516.     $path = fm_clean_path($path);
  2517.     if ($path != '') {
  2518.         $array = explode('/', $path);
  2519.         if (count($array) > 1) {
  2520.             $array = array_slice($array, 0, -1);
  2521.             return implode('/', $array);
  2522.         }
  2523.         return '';
  2524.     }
  2525.     return false;
  2526. }
  2527.  
  2528. function fm_get_display_path($file_path)
  2529. {
  2530.     global $path_display_mode, $root_path, $root_url;
  2531.     switch ($path_display_mode) {
  2532.         case 'relative':
  2533.             return array(
  2534.                 'label' => 'Path',
  2535.                 'path' => fm_enc(fm_convert_win(str_replace($root_path, '', $file_path)))
  2536.             );
  2537.         case 'host':
  2538.             $relative_path = str_replace($root_path, '', $file_path);
  2539.             return array(
  2540.                 'label' => 'Host Path',
  2541.                 'path' => fm_enc(fm_convert_win('/' . $root_url . '/' . ltrim(str_replace('\\', '/', $relative_path), '/')))
  2542.             );
  2543.         case 'full':
  2544.         default:
  2545.             return array(
  2546.                 'label' => 'Full Path',
  2547.                 'path' => fm_enc(fm_convert_win($file_path))
  2548.             );
  2549.     }
  2550. }
  2551.  
  2552. /**
  2553.  * Check file is in exclude list
  2554.  * @param string $file
  2555.  * @return bool
  2556.  */
  2557. function fm_is_exclude_items($file) {
  2558.     $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
  2559.     if (isset($exclude_items) and sizeof($exclude_items)) {
  2560.         unset($exclude_items);
  2561.     }
  2562.  
  2563.     $exclude_items = FM_EXCLUDE_ITEMS;
  2564.     if (version_compare(PHP_VERSION, '7.0.0', '<')) {
  2565.         $exclude_items = unserialize($exclude_items);
  2566.     }
  2567.     if (!in_array($file, $exclude_items) && !in_array("*.$ext", $exclude_items)) {
  2568.         return true;
  2569.     }
  2570.     return false;
  2571. }
  2572.  
  2573. /**
  2574.  * get language translations from json file
  2575.  * @param int $tr
  2576.  * @return array
  2577.  */
  2578. function fm_get_translations($tr) {
  2579.     try {
  2580.         $content = @file_get_contents('translation.json');
  2581.         if($content !== FALSE) {
  2582.             $lng = json_decode($content, TRUE);
  2583.             global $lang_list;
  2584.             foreach ($lng["language"] as $key => $value)
  2585.             {
  2586.                 $code = $value["code"];
  2587.                 $lang_list[$code] = $value["name"];
  2588.                 if ($tr)
  2589.                     $tr[$code] = $value["translation"];
  2590.             }
  2591.             return $tr;
  2592.         }
  2593.  
  2594.     }
  2595.     catch (Exception $e) {
  2596.         echo $e;
  2597.     }
  2598. }
  2599.  
  2600. /**
  2601.  * @param string $file
  2602.  * Recover all file sizes larger than > 2GB.
  2603.  * Works on php 32bits and 64bits and supports linux
  2604.  * @return int|string
  2605.  */
  2606. function fm_get_size($file)
  2607. {
  2608.     static $iswin;
  2609.     static $isdarwin;
  2610.     if (!isset($iswin)) {
  2611.         $iswin = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
  2612.     }
  2613.     if (!isset($isdarwin)) {
  2614.         $isdarwin = (strtoupper(substr(PHP_OS, 0)) == "DARWIN");
  2615.     }
  2616.  
  2617.     static $exec_works;
  2618.     if (!isset($exec_works)) {
  2619.         $exec_works = (function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC');
  2620.     }
  2621.  
  2622.     // try a shell command
  2623.     if ($exec_works) {
  2624.         $arg = escapeshellarg($file);
  2625.         $cmd = ($iswin) ? "for %F in (\"$file\") do @echo %~zF" : ($isdarwin "stat -f%z $arg" : "stat -c%s $arg");
  2626.         @exec($cmd, $output);
  2627.         if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) {
  2628.             return $size;
  2629.         }
  2630.     }
  2631.  
  2632.     // try the Windows COM interface
  2633.     if ($iswin && class_exists("COM")) {
  2634.         try {
  2635.             $fsobj = new COM('Scripting.FileSystemObject');
  2636.             $f = $fsobj->GetFile( realpath($file) );
  2637.             $size = $f->Size;
  2638.         } catch (Exception $e) {
  2639.             $size = null;
  2640.         }
  2641.         if (ctype_digit($size)) {
  2642.             return $size;
  2643.         }
  2644.     }
  2645.  
  2646.     // if all else fails
  2647.     return filesize($file);
  2648. }
  2649.  
  2650. /**
  2651.  * Get nice filesize
  2652.  * @param int $size
  2653.  * @return string
  2654.  */
  2655. function fm_get_filesize($size)
  2656. {
  2657.     $size = (float) $size;
  2658.     $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  2659.     $power = ($size > 0) ? floor(log($size, 1024)) : 0;
  2660.     $power = ($power > (count($units) - 1)) ? (count($units) - 1) : $power;
  2661.     return sprintf('%s %s', round($size / pow(1024, $power), 2), $units[$power]);
  2662. }
  2663.  
  2664. /**
  2665.  * Get total size of directory tree.
  2666.  *
  2667.  * @param  string $directory Relative or absolute directory name.
  2668.  * @return int Total number of bytes.
  2669.  */
  2670. function fm_get_directorysize($directory) {
  2671.     $bytes = 0;
  2672.     $directory = realpath($directory);
  2673.     if ($directory !== false && $directory != '' && file_exists($directory)){
  2674.         foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)) as $file){
  2675.             $bytes += $file->getSize();
  2676.         }
  2677.     }
  2678.     return $bytes;
  2679. }
  2680.  
  2681. /**
  2682.  * Get info about zip archive
  2683.  * @param string $path
  2684.  * @return array|bool
  2685.  */
  2686. function fm_get_zif_info($path, $ext) {
  2687.     if ($ext == 'zip' && function_exists('zip_open')) {
  2688.         $arch = @zip_open($path);
  2689.         if ($arch) {
  2690.             $filenames = array();
  2691.             while ($zip_entry = @zip_read($arch)) {
  2692.                 $zip_name = @zip_entry_name($zip_entry);
  2693.                 $zip_folder = substr($zip_name, -1) == '/';
  2694.                 $filenames[] = array(
  2695.                     'name' => $zip_name,
  2696.                     'filesize' => @zip_entry_filesize($zip_entry),
  2697.                     'compressed_size' => @zip_entry_compressedsize($zip_entry),
  2698.                     'folder' => $zip_folder
  2699.                     //'compression_method' => zip_entry_compressionmethod($zip_entry),
  2700.                 );
  2701.             }
  2702.             @zip_close($arch);
  2703.             return $filenames;
  2704.         }
  2705.     } elseif($ext == 'tar' && class_exists('PharData')) {
  2706.         $archive = new PharData($path);
  2707.         $filenames = array();
  2708.         foreach(new RecursiveIteratorIterator($archive) as $file) {
  2709.             $parent_info = $file->getPathInfo();
  2710.             $zip_name = str_replace("phar://".$path, '', $file->getPathName());
  2711.             $zip_name = substr($zip_name, ($pos = strpos($zip_name, '/')) !== false ? $pos + 1 : 0);
  2712.             $zip_folder = $parent_info->getFileName();
  2713.             $zip_info = new SplFileInfo($file);
  2714.             $filenames[] = array(
  2715.                 'name' => $zip_name,
  2716.                 'filesize' => $zip_info->getSize(),
  2717.                 'compressed_size' => $file->getCompressedSize(),
  2718.                 'folder' => $zip_folder
  2719.             );
  2720.         }
  2721.         return $filenames;
  2722.     }
  2723.     return false;
  2724. }
  2725.  
  2726. /**
  2727.  * Encode html entities
  2728.  * @param string $text
  2729.  * @return string
  2730.  */
  2731. function fm_enc($text)
  2732. {
  2733.     return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  2734. }
  2735.  
  2736. /**
  2737.  * Prevent XSS attacks
  2738.  * @param string $text
  2739.  * @return string
  2740.  */
  2741. function fm_isvalid_filename($text) {
  2742.     return (strpbrk($text, '/?%*:|"<>') === FALSE) ? true : false;
  2743. }
  2744.  
  2745. /**
  2746.  * Save message in session
  2747.  * @param string $msg
  2748.  * @param string $status
  2749.  */
  2750. function fm_set_msg($msg, $status = 'ok')
  2751. {
  2752.     $_SESSION[FM_SESSION_ID]['message'] = $msg;
  2753.     $_SESSION[FM_SESSION_ID]['status'] = $status;
  2754. }
  2755.  
  2756. /**
  2757.  * Check if string is in UTF-8
  2758.  * @param string $string
  2759.  * @return int
  2760.  */
  2761. function fm_is_utf8($string)
  2762. {
  2763.     return preg_match('//u', $string);
  2764. }
  2765.  
  2766. /**
  2767.  * Convert file name to UTF-8 in Windows
  2768.  * @param string $filename
  2769.  * @return string
  2770.  */
  2771. function fm_convert_win($filename)
  2772. {
  2773.     if (FM_IS_WIN && function_exists('iconv')) {
  2774.         $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
  2775.     }
  2776.     return $filename;
  2777. }
  2778.  
  2779. /**
  2780.  * @param $obj
  2781.  * @return array
  2782.  */
  2783. function fm_object_to_array($obj)
  2784. {
  2785.     if (!is_object($obj) && !is_array($obj)) {
  2786.         return $obj;
  2787.     }
  2788.     if (is_object($obj)) {
  2789.         $obj = get_object_vars($obj);
  2790.     }
  2791.     return array_map('fm_object_to_array', $obj);
  2792. }
  2793.  
  2794. /**
  2795.  * Get CSS classname for file
  2796.  * @param string $path
  2797.  * @return string
  2798.  */
  2799. function fm_get_file_icon_class($path)
  2800. {
  2801.     // get extension
  2802.     $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
  2803.  
  2804.     switch ($ext) {
  2805.         case 'ico':
  2806.         case 'gif':
  2807.         case 'jpg':
  2808.         case 'jpeg':
  2809.         case 'jpc':
  2810.         case 'jp2':
  2811.         case 'jpx':
  2812.         case 'xbm':
  2813.         case 'wbmp':
  2814.         case 'png':
  2815.         case 'bmp':
  2816.         case 'tif':
  2817.         case 'tiff':
  2818.         case 'webp':
  2819.         case 'avif':
  2820.         case 'svg':
  2821.             $img = 'fa fa-picture-o';
  2822.             break;
  2823.         case 'passwd':
  2824.         case 'ftpquota':
  2825.         case 'sql':
  2826.         case 'js':
  2827.         case 'ts':
  2828.         case 'jsx':
  2829.         case 'tsx':
  2830.         case 'hbs':
  2831.         case 'json':
  2832.         case 'sh':
  2833.         case 'config':
  2834.         case 'twig':
  2835.         case 'tpl':
  2836.         case 'md':
  2837.         case 'gitignore':
  2838.         case 'c':
  2839.         case 'cpp':
  2840.         case 'cs':
  2841.         case 'py':
  2842.         case 'rs':
  2843.         case 'map':
  2844.         case 'lock':
  2845.         case 'dtd':
  2846.             $img = 'fa fa-file-code-o';
  2847.             break;
  2848.         case 'txt':
  2849.         case 'ini':
  2850.         case 'conf':
  2851.         case 'log':
  2852.         case 'htaccess':
  2853.         case 'yaml':
  2854.         case 'yml':
  2855.         case 'toml':
  2856.         case 'tmp':
  2857.         case 'top':
  2858.         case 'bot':
  2859.         case 'dat':
  2860.         case 'bak':
  2861.         case 'htpasswd':
  2862.         case 'pl':
  2863.             $img = 'fa fa-file-text-o';
  2864.             break;
  2865.         case 'css':
  2866.         case 'less':
  2867.         case 'sass':
  2868.         case 'scss':
  2869.             $img = 'fa fa-css3';
  2870.             break;
  2871.         case 'bz2':
  2872.         case 'zip':
  2873.         case 'rar':
  2874.         case 'gz':
  2875.         case 'tar':
  2876.         case '7z':
  2877.         case 'xz':
  2878.             $img = 'fa fa-file-archive-o';
  2879.             break;
  2880.         case 'php':
  2881.         case 'php4':
  2882.         case 'php5':
  2883.         case 'phps':
  2884.         case 'phtml':
  2885.             $img = 'fa fa-code';
  2886.             break;
  2887.         case 'htm':
  2888.         case 'html':
  2889.         case 'shtml':
  2890.         case 'xhtml':
  2891.             $img = 'fa fa-html5';
  2892.             break;
  2893.         case 'xml':
  2894.         case 'xsl':
  2895.             $img = 'fa fa-file-excel-o';
  2896.             break;
  2897.         case 'wav':
  2898.         case 'mp3':
  2899.         case 'mp2':
  2900.         case 'm4a':
  2901.         case 'aac':
  2902.         case 'ogg':
  2903.         case 'oga':
  2904.         case 'wma':
  2905.         case 'mka':
  2906.         case 'flac':
  2907.         case 'ac3':
  2908.         case 'tds':
  2909.             $img = 'fa fa-music';
  2910.             break;
  2911.         case 'm3u':
  2912.         case 'm3u8':
  2913.         case 'pls':
  2914.         case 'cue':
  2915.         case 'xspf':
  2916.             $img = 'fa fa-headphones';
  2917.             break;
  2918.         case 'avi':
  2919.         case 'mpg':
  2920.         case 'mpeg':
  2921.         case 'mp4':
  2922.         case 'm4v':
  2923.         case 'flv':
  2924.         case 'f4v':
  2925.         case 'ogm':
  2926.         case 'ogv':
  2927.         case 'mov':
  2928.         case 'mkv':
  2929.         case '3gp':
  2930.         case 'asf':
  2931.         case 'wmv':
  2932.         case 'webm':
  2933.             $img = 'fa fa-file-video-o';
  2934.             break;
  2935.         case 'eml':
  2936.         case 'msg':
  2937.             $img = 'fa fa-envelope-o';
  2938.             break;
  2939.         case 'xls':
  2940.         case 'xlsx':
  2941.         case 'ods':
  2942.             $img = 'fa fa-file-excel-o';
  2943.             break;
  2944.         case 'csv':
  2945.             $img = 'fa fa-file-text-o';
  2946.             break;
  2947.         case 'bak':
  2948.         case 'swp':
  2949.             $img = 'fa fa-clipboard';
  2950.             break;
  2951.         case 'doc':
  2952.         case 'docx':
  2953.         case 'odt':
  2954.             $img = 'fa fa-file-word-o';
  2955.             break;
  2956.         case 'ppt':
  2957.         case 'pptx':
  2958.             $img = 'fa fa-file-powerpoint-o';
  2959.             break;
  2960.         case 'ttf':
  2961.         case 'ttc':
  2962.         case 'otf':
  2963.         case 'woff':
  2964.         case 'woff2':
  2965.         case 'eot':
  2966.         case 'fon':
  2967.             $img = 'fa fa-font';
  2968.             break;
  2969.         case 'pdf':
  2970.             $img = 'fa fa-file-pdf-o';
  2971.             break;
  2972.         case 'psd':
  2973.         case 'ai':
  2974.         case 'eps':
  2975.         case 'fla':
  2976.         case 'swf':
  2977.             $img = 'fa fa-file-image-o';
  2978.             break;
  2979.         case 'exe':
  2980.         case 'msi':
  2981.             $img = 'fa fa-file-o';
  2982.             break;
  2983.         case 'bat':
  2984.             $img = 'fa fa-terminal';
  2985.             break;
  2986.         default:
  2987.             $img = 'fa fa-info-circle';
  2988.     }
  2989.  
  2990.     return $img;
  2991. }
  2992.  
  2993. /**
  2994.  * Get image files extensions
  2995.  * @return array
  2996.  */
  2997. function fm_get_image_exts()
  2998. {
  2999.     return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd', 'svg', 'webp', 'avif');
  3000. }
  3001.  
  3002. /**
  3003.  * Get video files extensions
  3004.  * @return array
  3005.  */
  3006. function fm_get_video_exts()
  3007. {
  3008.     return array('avi', 'webm', 'wmv', 'mp4', 'm4v', 'ogm', 'ogv', 'mov', 'mkv');
  3009. }
  3010.  
  3011. /**
  3012.  * Get audio files extensions
  3013.  * @return array
  3014.  */
  3015. function fm_get_audio_exts()
  3016. {
  3017.     return array('wav', 'mp3', 'ogg', 'm4a');
  3018. }
  3019.  
  3020. /**
  3021.  * Get text file extensions
  3022.  * @return array
  3023.  */
  3024. function fm_get_text_exts()
  3025. {
  3026.     return array(
  3027.         'txt', 'css', 'ini', 'conf', 'log', 'htaccess', 'passwd', 'ftpquota', 'sql', 'js', 'ts', 'jsx', 'tsx', 'mjs', 'json', 'sh', 'config',
  3028.         'php', 'php4', 'php5', 'phps', 'phtml', 'htm', 'html', 'shtml', 'xhtml', 'xml', 'xsl', 'm3u', 'm3u8', 'pls', 'cue', 'bash', 'vue',
  3029.         'eml', 'msg', 'csv', 'bat', 'twig', 'tpl', 'md', 'gitignore', 'less', 'sass', 'scss', 'c', 'cpp', 'cs', 'py', 'go', 'zsh', 'swift',
  3030.         'map', 'lock', 'dtd', 'svg', 'asp', 'aspx', 'asx', 'asmx', 'ashx', 'jsp', 'jspx', 'cgi', 'dockerfile', 'ruby', 'yml', 'yaml', 'toml',
  3031.         'vhost', 'scpt', 'applescript', 'csx', 'cshtml', 'c++', 'coffee', 'cfm', 'rb', 'graphql', 'mustache', 'jinja', 'http', 'handlebars',
  3032.         'java', 'es', 'es6', 'markdown', 'wiki', 'tmp', 'top', 'bot', 'dat', 'bak', 'htpasswd', 'pl'
  3033.     );
  3034. }
  3035.  
  3036. /**
  3037.  * Get mime types of text files
  3038.  * @return array
  3039.  */
  3040. function fm_get_text_mimes()
  3041. {
  3042.     return array(
  3043.         'application/xml',
  3044.         'application/javascript',
  3045.         'application/x-javascript',
  3046.         'image/svg+xml',
  3047.         'message/rfc822',
  3048.         'application/json',
  3049.     );
  3050. }
  3051.  
  3052. /**
  3053.  * Get file names of text files w/o extensions
  3054.  * @return array
  3055.  */
  3056. function fm_get_text_names()
  3057. {
  3058.     return array(
  3059.         'license',
  3060.         'readme',
  3061.         'authors',
  3062.         'contributors',
  3063.         'changelog',
  3064.     );
  3065. }
  3066.  
  3067. /**
  3068.  * Get online docs viewer supported files extensions
  3069.  * @return array
  3070.  */
  3071. function fm_get_onlineViewer_exts()
  3072. {
  3073.     return array('doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx', 'ai', 'psd', 'dxf', 'xps', 'rar', 'odt', 'ods');
  3074. }
  3075.  
  3076. /**
  3077.  * It returns the mime type of a file based on its extension.
  3078.  * @param extension The file extension of the file you want to get the mime type for.
  3079.  * @return string|string[] The mime type of the file.
  3080.  */
  3081. function fm_get_file_mimes($extension)
  3082. {
  3083.     $fileTypes['swf'] = 'application/x-shockwave-flash';
  3084.     $fileTypes['pdf'] = 'application/pdf';
  3085.     $fileTypes['exe'] = 'application/octet-stream';
  3086.     $fileTypes['zip'] = 'application/zip';
  3087.     $fileTypes['doc'] = 'application/msword';
  3088.     $fileTypes['xls'] = 'application/vnd.ms-excel';
  3089.     $fileTypes['ppt'] = 'application/vnd.ms-powerpoint';
  3090.     $fileTypes['gif'] = 'image/gif';
  3091.     $fileTypes['png'] = 'image/png';
  3092.     $fileTypes['jpeg'] = 'image/jpg';
  3093.     $fileTypes['jpg'] = 'image/jpg';
  3094.     $fileTypes['webp'] = 'image/webp';
  3095.     $fileTypes['avif'] = 'image/avif';
  3096.     $fileTypes['rar'] = 'application/rar';
  3097.  
  3098.     $fileTypes['ra'] = 'audio/x-pn-realaudio';
  3099.     $fileTypes['ram'] = 'audio/x-pn-realaudio';
  3100.     $fileTypes['ogg'] = 'audio/x-pn-realaudio';
  3101.  
  3102.     $fileTypes['wav'] = 'video/x-msvideo';
  3103.     $fileTypes['wmv'] = 'video/x-msvideo';
  3104.     $fileTypes['avi'] = 'video/x-msvideo';
  3105.     $fileTypes['asf'] = 'video/x-msvideo';
  3106.     $fileTypes['divx'] = 'video/x-msvideo';
  3107.  
  3108.     $fileTypes['mp3'] = 'audio/mpeg';
  3109.     $fileTypes['mp4'] = 'audio/mpeg';
  3110.     $fileTypes['mpeg'] = 'video/mpeg';
  3111.     $fileTypes['mpg'] = 'video/mpeg';
  3112.     $fileTypes['mpe'] = 'video/mpeg';
  3113.     $fileTypes['mov'] = 'video/quicktime';
  3114.     $fileTypes['swf'] = 'video/quicktime';
  3115.     $fileTypes['3gp'] = 'video/quicktime';
  3116.     $fileTypes['m4a'] = 'video/quicktime';
  3117.     $fileTypes['aac'] = 'video/quicktime';
  3118.     $fileTypes['m3u'] = 'video/quicktime';
  3119.  
  3120.     $fileTypes['php'] = ['application/x-php'];
  3121.     $fileTypes['html'] = ['text/html'];
  3122.     $fileTypes['txt'] = ['text/plain'];
  3123.     //Unknown mime-types should be 'application/octet-stream'
  3124.     if(empty($fileTypes[$extension])) {
  3125.       $fileTypes[$extension] = ['application/octet-stream'];
  3126.     }
  3127.     return $fileTypes[$extension];
  3128. }
  3129.  
  3130. /**
  3131.  * This function scans the files and folder recursively, and return matching files
  3132.  * @param string $dir
  3133.  * @param string $filter
  3134.  * @return array|null
  3135.  */
  3136.  function scan($dir = '', $filter = '') {
  3137.     $path = FM_ROOT_PATH.'/'.$dir;
  3138.      if($path) {
  3139.          $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
  3140.          $rii = new RegexIterator($ite, "/(" . $filter . ")/i");
  3141.  
  3142.          $files = array();
  3143.          foreach ($rii as $file) {
  3144.              if (!$file->isDir()) {
  3145.                  $fileName = $file->getFilename();
  3146.                  $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
  3147.                  $files[] = array(
  3148.                      "name" => $fileName,
  3149.                      "type" => "file",
  3150.                      "path" => $location,
  3151.                  );
  3152.              }
  3153.          }
  3154.          return $files;
  3155.      }
  3156. }
  3157.  
  3158. /**
  3159. * Parameters: downloadFile(File Location, File Name,
  3160. * max speed, is streaming
  3161. * If streaming - videos will show as videos, images as images
  3162. * instead of download prompt
  3163. * https://stackoverflow.com/a/13821992/1164642
  3164. */
  3165. function fm_download_file($fileLocation, $fileName, $chunkSize  = 1024)
  3166. {
  3167.     if (connection_status() != 0)
  3168.         return (false);
  3169.     $extension = pathinfo($fileName, PATHINFO_EXTENSION);
  3170.  
  3171.     $contentType = fm_get_file_mimes($extension);
  3172.  
  3173.     if(is_array($contentType)) {
  3174.         $contentType = implode(' ', $contentType);
  3175.     }
  3176.  
  3177.     $size = filesize($fileLocation);
  3178.  
  3179.     if ($size == 0) {
  3180.         fm_set_msg(lng('Zero byte file! Aborting download'), 'error');
  3181.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3182.  
  3183.         return (false);
  3184.     }
  3185.  
  3186.     @ini_set('magic_quotes_runtime', 0);
  3187.     $fp = fopen("$fileLocation", "rb");
  3188.  
  3189.     if ($fp === false) {
  3190.         fm_set_msg(lng('Cannot open file! Aborting download'), 'error');
  3191.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  3192.         return (false);
  3193.     }
  3194.  
  3195.     // headers
  3196.     header('Content-Description: File Transfer');
  3197.     header('Expires: 0');
  3198.     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  3199.     header('Pragma: public');
  3200.     header("Content-Transfer-Encoding: binary");
  3201.     header("Content-Type: $contentType");
  3202.  
  3203.     $contentDisposition = 'attachment';
  3204.  
  3205.     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  3206.         $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
  3207.         header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3208.     } else {
  3209.         header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
  3210.     }
  3211.  
  3212.     header("Accept-Ranges: bytes");
  3213.     $range = 0;
  3214.  
  3215.     if (isset($_SERVER['HTTP_RANGE'])) {
  3216.         list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
  3217.         str_replace($range, "-", $range);
  3218.         $size2 = $size - 1;
  3219.         $new_length = $size - $range;
  3220.         header("HTTP/1.1 206 Partial Content");
  3221.         header("Content-Length: $new_length");
  3222.         header("Content-Range: bytes $range$size2/$size");
  3223.     } else {
  3224.         $size2 = $size - 1;
  3225.         header("Content-Range: bytes 0-$size2/$size");
  3226.         header("Content-Length: " . $size);
  3227.     }
  3228.     $fileLocation = realpath($fileLocation);
  3229.     while (ob_get_level()) ob_end_clean();
  3230.     readfile($fileLocation);
  3231.  
  3232.     fclose($fp);
  3233.  
  3234.     return ((connection_status() == 0) and !connection_aborted());
  3235. }
  3236.  
  3237. /**
  3238.  * If the theme is dark, return the text-white and bg-dark classes.
  3239.  * @return string the value of the  variable.
  3240.  */
  3241. function fm_get_theme() {
  3242.     $result = '';
  3243.     if(FM_THEME == "dark") {
  3244.         $result = "text-white bg-dark";
  3245.     }
  3246.     return $result;
  3247. }
  3248.  
  3249. /**
  3250.  * Class to work with zip files (using ZipArchive)
  3251.  */
  3252. class FM_Zipper
  3253. {
  3254.     private $zip;
  3255.  
  3256.     public function __construct()
  3257.     {
  3258.         $this->zip = new ZipArchive();
  3259.     }
  3260.  
  3261.     /**
  3262.      * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3263.      * @param string $filename
  3264.      * @param array|string $files
  3265.      * @return bool
  3266.      */
  3267.     public function create($filename, $files)
  3268.     {
  3269.         $res = $this->zip->open($filename, ZipArchive::CREATE);
  3270.         if ($res !== true) {
  3271.             return false;
  3272.         }
  3273.         if (is_array($files)) {
  3274.             foreach ($files as $f) {
  3275.                 $f = fm_clean_path($f);
  3276.                 if (!$this->addFileOrDir($f)) {
  3277.                     $this->zip->close();
  3278.                     return false;
  3279.                 }
  3280.             }
  3281.             $this->zip->close();
  3282.             return true;
  3283.         } else {
  3284.             if ($this->addFileOrDir($files)) {
  3285.                 $this->zip->close();
  3286.                 return true;
  3287.             }
  3288.             return false;
  3289.         }
  3290.     }
  3291.  
  3292.     /**
  3293.      * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3294.      * @param string $filename
  3295.      * @param string $path
  3296.      * @return bool
  3297.      */
  3298.     public function unzip($filename, $path)
  3299.     {
  3300.         $res = $this->zip->open($filename);
  3301.         if ($res !== true) {
  3302.             return false;
  3303.         }
  3304.         if ($this->zip->extractTo($path)) {
  3305.             $this->zip->close();
  3306.             return true;
  3307.         }
  3308.         return false;
  3309.     }
  3310.  
  3311.     /**
  3312.      * Add file/folder to archive
  3313.      * @param string $filename
  3314.      * @return bool
  3315.      */
  3316.     private function addFileOrDir($filename)
  3317.     {
  3318.         if (is_file($filename)) {
  3319.             return $this->zip->addFile($filename);
  3320.         } elseif (is_dir($filename)) {
  3321.             return $this->addDir($filename);
  3322.         }
  3323.         return false;
  3324.     }
  3325.  
  3326.     /**
  3327.      * Add folder recursively
  3328.      * @param string $path
  3329.      * @return bool
  3330.      */
  3331.     private function addDir($path)
  3332.     {
  3333.         if (!$this->zip->addEmptyDir($path)) {
  3334.             return false;
  3335.         }
  3336.         $objects = scandir($path);
  3337.         if (is_array($objects)) {
  3338.             foreach ($objects as $file) {
  3339.                 if ($file != '.' && $file != '..') {
  3340.                     if (is_dir($path . '/' . $file)) {
  3341.                         if (!$this->addDir($path . '/' . $file)) {
  3342.                             return false;
  3343.                         }
  3344.                     } elseif (is_file($path . '/' . $file)) {
  3345.                         if (!$this->zip->addFile($path . '/' . $file)) {
  3346.                             return false;
  3347.                         }
  3348.                     }
  3349.                 }
  3350.             }
  3351.             return true;
  3352.         }
  3353.         return false;
  3354.     }
  3355. }
  3356.  
  3357. /**
  3358.  * Class to work with Tar files (using PharData)
  3359.  */
  3360. class FM_Zipper_Tar
  3361. {
  3362.     private $tar;
  3363.  
  3364.     public function __construct()
  3365.     {
  3366.         $this->tar = null;
  3367.     }
  3368.  
  3369.     /**
  3370.      * Create archive with name $filename and files $files (RELATIVE PATHS!)
  3371.      * @param string $filename
  3372.      * @param array|string $files
  3373.      * @return bool
  3374.      */
  3375.     public function create($filename, $files)
  3376.     {
  3377.         $this->tar = new PharData($filename);
  3378.         if (is_array($files)) {
  3379.             foreach ($files as $f) {
  3380.                 $f = fm_clean_path($f);
  3381.                 if (!$this->addFileOrDir($f)) {
  3382.                     return false;
  3383.                 }
  3384.             }
  3385.             return true;
  3386.         } else {
  3387.             if ($this->addFileOrDir($files)) {
  3388.                 return true;
  3389.             }
  3390.             return false;
  3391.         }
  3392.     }
  3393.  
  3394.     /**
  3395.      * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  3396.      * @param string $filename
  3397.      * @param string $path
  3398.      * @return bool
  3399.      */
  3400.     public function unzip($filename, $path)
  3401.     {
  3402.         $res = $this->tar->open($filename);
  3403.         if ($res !== true) {
  3404.             return false;
  3405.         }
  3406.         if ($this->tar->extractTo($path)) {
  3407.             return true;
  3408.         }
  3409.         return false;
  3410.     }
  3411.  
  3412.     /**
  3413.      * Add file/folder to archive
  3414.      * @param string $filename
  3415.      * @return bool
  3416.      */
  3417.     private function addFileOrDir($filename)
  3418.     {
  3419.         if (is_file($filename)) {
  3420.             try {
  3421.                 $this->tar->addFile($filename);
  3422.                 return true;
  3423.             } catch (Exception $e) {
  3424.                 return false;
  3425.             }
  3426.         } elseif (is_dir($filename)) {
  3427.             return $this->addDir($filename);
  3428.         }
  3429.         return false;
  3430.     }
  3431.  
  3432.     /**
  3433.      * Add folder recursively
  3434.      * @param string $path
  3435.      * @return bool
  3436.      */
  3437.     private function addDir($path)
  3438.     {
  3439.         $objects = scandir($path);
  3440.         if (is_array($objects)) {
  3441.             foreach ($objects as $file) {
  3442.                 if ($file != '.' && $file != '..') {
  3443.                     if (is_dir($path . '/' . $file)) {
  3444.                         if (!$this->addDir($path . '/' . $file)) {
  3445.                             return false;
  3446.                         }
  3447.                     } elseif (is_file($path . '/' . $file)) {
  3448.                         try {
  3449.                             $this->tar->addFile($path . '/' . $file);
  3450.                         } catch (Exception $e) {
  3451.                             return false;
  3452.                         }
  3453.                     }
  3454.                 }
  3455.             }
  3456.             return true;
  3457.         }
  3458.         return false;
  3459.     }
  3460. }
  3461.  
  3462. /**
  3463.  * Save Configuration
  3464.  */
  3465.  class FM_Config
  3466. {
  3467.      var $data;
  3468.  
  3469.     function __construct()
  3470.     {
  3471.         global $root_path, $root_url, $CONFIG;
  3472.         $fm_url = $root_url.$_SERVER["PHP_SELF"];
  3473.         $this->data = array(
  3474.             'lang' => 'en',
  3475.             'error_reporting' => true,
  3476.             'show_hidden' => true
  3477.         );
  3478.         $data = false;
  3479.         if (strlen($CONFIG)) {
  3480.             $data = fm_object_to_array(json_decode($CONFIG));
  3481.         } else {
  3482.             $msg = 'Tiny File Manager<br>Error: Cannot load configuration';
  3483.             if (substr($fm_url, -1) == '/') {
  3484.                 $fm_url = rtrim($fm_url, '/');
  3485.                 $msg .= '<br>';
  3486.                 $msg .= '<br>Seems like you have a trailing slash on the URL.';
  3487.                 $msg .= '<br>Try this link: <a href="' . $fm_url . '">' . $fm_url . '</a>';
  3488.             }
  3489.             die($msg);
  3490.         }
  3491.         if (is_array($data) && count($data)) $this->data = $data;
  3492.         else $this->save();
  3493.     }
  3494.  
  3495.     function save()
  3496.     {
  3497.         $fm_file = __FILE__;
  3498.         $var_name = '$CONFIG';
  3499.         $var_value = var_export(json_encode($this->data), true);
  3500.         $config_string = "<?php" . chr(13) . chr(10) . "//Default Configuration".chr(13) . chr(10)."$var_name = $var_value;" . chr(13) . chr(10);
  3501.         if (is_writable($fm_file)) {
  3502.             $lines = file($fm_file);
  3503.             if ($fh = @fopen($fm_file, "w")) {
  3504.                 @fputs($fh, $config_string, strlen($config_string));
  3505.                 for ($x = 3; $x < count($lines); $x++) {
  3506.                     @fputs($fh, $lines[$x], strlen($lines[$x]));
  3507.                 }
  3508.                 @fclose($fh);
  3509.             }
  3510.         }
  3511.     }
  3512. }
  3513.  
  3514. //--- Templates Functions ---
  3515.  
  3516. /**
  3517.  * Show nav block
  3518.  * @param string $path
  3519.  */
  3520. function fm_show_nav_path($path)
  3521. {
  3522.     global $lang, $sticky_navbar, $editFile;
  3523.     $isStickyNavBar = $sticky_navbar 'fixed-top' : '';
  3524.     $getTheme = fm_get_theme();
  3525.     $getTheme .= " navbar-light";
  3526.     if(FM_THEME == "dark") {
  3527.         $getTheme .= " navbar-dark";
  3528.     } else {
  3529.         $getTheme .= " bg-white";
  3530.     }
  3531.     ?>
  3532.     <nav class="navbar navbar-expand-lg <?php echo $getTheme; ?> mb-4 main-nav <?php echo $isStickyNavBar ?>">
  3533.         <a class="navbar-brand"> <?php echo lng('AppTitle') ?> </a>
  3534.         <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  3535.             <span class="navbar-toggler-icon"></span>
  3536.         </button>
  3537.         <div class="collapse navbar-collapse" id="navbarSupportedContent">
  3538.  
  3539.             <?php
  3540.             $path = fm_clean_path($path);
  3541.             $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
  3542.             $sep = '<i class="bread-crumb"> / </i>';
  3543.             if ($path != '') {
  3544.                 $exploded = explode('/', $path);
  3545.                 $count = count($exploded);
  3546.                 $array = array();
  3547.                 $parent = '';
  3548.                 for ($i = 0; $i < $count; $i++) {
  3549.                     $parent = trim($parent . '/' . $exploded[$i], '/');
  3550.                     $parent_enc = urlencode($parent);
  3551.                     $array[] = "<a href='?p={$parent_enc}'>" . fm_enc(fm_convert_win($exploded[$i])) . "</a>";
  3552.                 }
  3553.                 $root_url .= $sep . implode($sep, $array);
  3554.             }
  3555.             echo '<div class="col-xs-6 col-sm-5">' . $root_url . $editFile . '</div>';
  3556.             ?>
  3557.  
  3558.             <div class="col-xs-6 col-sm-7">
  3559.                 <ul class="navbar-nav justify-content-end <?php echo fm_get_theme();  ?>">
  3560.                     <li class="nav-item mr-2">
  3561.                         <div class="input-group input-group-sm mr-1" style="margin-top:4px;">
  3562.                             <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon2" id="search-addon">
  3563.                             <div class="input-group-append">
  3564.                                 <span class="input-group-text brl-0 brr-0" id="search-addon2"><i class="fa fa-search"></i></span>
  3565.                             </div>
  3566.                             <div class="input-group-append btn-group">
  3567.                                 <span class="input-group-text dropdown-toggle brl-0" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
  3568.                                   <div class="dropdown-menu dropdown-menu-right">
  3569.                                     <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>
  3570.                                   </div>
  3571.                             </div>
  3572.                         </div>
  3573.                     </li>
  3574.                     <?php if (!FM_READONLY): ?>
  3575.                     <li class="nav-item">
  3576.                         <a title="<?php echo lng('Upload') ?>" class="nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&upload"><i class="fa fa-cloud-upload" aria-hidden="true"></i> <?php echo lng('Upload') ?></a>
  3577.                     </li>
  3578.                     <li class="nav-item">
  3579.                         <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>
  3580.                     </li>
  3581.                     <?php endif; ?>
  3582.                     <?php if (FM_USE_AUTH): ?>
  3583.                     <li class="nav-item avatar dropdown">
  3584.                         <a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink-5" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-user-circle"></i> <?php if(isset($_SESSION[FM_SESSION_ID]['logged'])) { echo $_SESSION[FM_SESSION_ID]['logged']; } ?></a>
  3585.                         <div class="dropdown-menu text-small shadow <?php echo fm_get_theme(); ?>" aria-labelledby="navbarDropdownMenuLink-5">
  3586.                             <?php if (!FM_READONLY): ?>
  3587.                             <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3588.                             <?php endif ?>
  3589.                             <a title="<?php echo lng('Help') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&help=2"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> <?php echo lng('Help') ?></a>
  3590.                             <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>
  3591.                         </div>
  3592.                     </li>
  3593.                     <?php else: ?>
  3594.                         <?php if (!FM_READONLY): ?>
  3595.                             <li class="nav-item">
  3596.                                 <a title="<?php echo lng('Settings') ?>" class="dropdown-item nav-link" href="?p=<?php echo urlencode(FM_PATH) ?>&settings=1"><i class="fa fa-cog" aria-hidden="true"></i> <?php echo lng('Settings') ?></a>
  3597.                             </li>
  3598.                         <?php endif; ?>
  3599.                     <?php endif; ?>
  3600.                 </ul>
  3601.             </div>
  3602.         </div>
  3603.     </nav>
  3604.     <?php
  3605. }
  3606.  
  3607. /**
  3608.  * Show alert message from session
  3609.  */
  3610. function fm_show_message()
  3611. {
  3612.     if (isset($_SESSION[FM_SESSION_ID]['message'])) {
  3613.         $class = isset($_SESSION[FM_SESSION_ID]['status']) ? $_SESSION[FM_SESSION_ID]['status'] : 'ok';
  3614.         echo '<p class="message ' . $class . '">' . $_SESSION[FM_SESSION_ID]['message'] . '</p>';
  3615.         unset($_SESSION[FM_SESSION_ID]['message']);
  3616.         unset($_SESSION[FM_SESSION_ID]['status']);
  3617.     }
  3618. }
  3619.  
  3620. /**
  3621.  * Show page header in Login Form
  3622.  */
  3623. function fm_show_header_login()
  3624. {
  3625. $sprites_ver = '20160315';
  3626. header("Content-Type: text/html; charset=utf-8");
  3627. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3628. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3629. header("Pragma: no-cache");
  3630.  
  3631. global $lang, $root_url, $favicon_path;
  3632. ?>
  3633. <!DOCTYPE html>
  3634. <html lang="en">
  3635. <head>
  3636.     <meta charset="utf-8">
  3637.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3638.     <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3639.     <meta name="author" content="CCP Programmers">
  3640.     <meta name="robots" content="noindex, nofollow">
  3641.     <meta name="googlebot" content="noindex">
  3642.     <?php if($favicon_path) { echo '<link rel="icon" href="'.fm_enc($favicon_path).'" type="image/png">'; } ?>
  3643.     <title><?php echo fm_enc(APP_TITLE) ?></title>
  3644.     <?php print_external('pre-jsdelivr'); ?>
  3645.     <?php print_external('css-bootstrap'); ?>
  3646.     <style>
  3647.         body.fm-login-page{ background-color:#f7f9fb;font-size:14px;background-color:#f7f9fb;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");}
  3648.         .fm-login-page .brand{ width:121px;overflow:hidden;margin:0 auto;position:relative;z-index:1}
  3649.         .fm-login-page .brand img{ width:100%}
  3650.         .fm-login-page .card-wrapper{ width:360px;margin-top:10%;margin-left:auto;margin-right:auto;}
  3651.         .fm-login-page .card{ border-color:transparent;box-shadow:0 4px 8px rgba(0,0,0,.05)}
  3652.         .fm-login-page .card-title{ margin-bottom:1.5rem;font-size:24px;font-weight:400;}
  3653.         .fm-login-page .form-control{ border-width:2.3px}
  3654.         .fm-login-page .form-group label{ width:100%}
  3655.         .fm-login-page .btn.btn-block{ padding:12px 10px}
  3656.         .fm-login-page .footer{ margin:40px 0;color:#888;text-align:center}
  3657.         @media screen and (max-width:425px){
  3658.             .fm-login-page .card-wrapper{ width:90%;margin:0 auto;margin-top:10%;}
  3659.         }
  3660.         @media screen and (max-width:320px){
  3661.             .fm-login-page .card.fat{ padding:0}
  3662.             .fm-login-page .card.fat .card-body{ padding:15px}
  3663.         }
  3664.         .message{ padding:4px 7px;border:1px solid #ddd;background-color:#fff}
  3665.         .message.ok{ border-color:green;color:green}
  3666.         .message.error{ border-color:red;color:red}
  3667.         .message.alert{ border-color:orange;color:orange}
  3668.         body.fm-login-page.theme-dark {background-color: #2f2a2a;}
  3669.         .theme-dark svg g, .theme-dark svg path {fill: #ffffff; }
  3670.     </style>
  3671. </head>
  3672. <body class="fm-login-page <?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?>">
  3673. <div id="wrapper" class="container-fluid">
  3674.  
  3675.     <?php
  3676.     }
  3677.  
  3678.     /**
  3679.      * Show page footer in Login Form
  3680.      */
  3681.     function fm_show_footer_login()
  3682.     {
  3683.     ?>
  3684. </div>
  3685. <?php print_external('js-jquery'); ?>
  3686. <?php print_external('js-bootstrap'); ?>
  3687. </body>
  3688. </html>
  3689. <?php
  3690. }
  3691.  
  3692. /**
  3693.  * Show Header after login
  3694.  */
  3695. function fm_show_header()
  3696. {
  3697. $sprites_ver = '20160315';
  3698. header("Content-Type: text/html; charset=utf-8");
  3699. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  3700. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  3701. header("Pragma: no-cache");
  3702.  
  3703. global $lang, $root_url, $sticky_navbar, $favicon_path;
  3704. $isStickyNavBar = $sticky_navbar 'navbar-fixed' : 'navbar-normal';
  3705. ?>
  3706. <!DOCTYPE html>
  3707. <html>
  3708. <head>
  3709.     <meta charset="utf-8">
  3710.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  3711.     <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  3712.     <meta name="author" content="CCP Programmers">
  3713.     <meta name="robots" content="noindex, nofollow">
  3714.     <meta name="googlebot" content="noindex">
  3715.     <?php if($favicon_path) { echo '<link rel="icon" href="'.fm_enc($favicon_path).'" type="image/png">'; } ?>
  3716.     <title><?php echo fm_enc(APP_TITLE) ?></title>
  3717.     <?php print_external('pre-jsdelivr'); ?>
  3718.     <?php print_external('pre-cloudflare'); ?>
  3719.     <?php print_external('css-bootstrap'); ?>
  3720.     <?php print_external('css-font-awesome'); ?>
  3721.     <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  3722.     <?php print_external('css-highlightjs'); ?>
  3723.     <?php endif; ?>
  3724.     <script type="text/javascript">window.csrf = '<?php echo $_SESSION['token']; ?>';</script>
  3725.     <style>
  3726.         html { -moz-osx-font-smoothing: grayscale; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; height: 100%; scroll-behavior: smooth;}
  3727.         *,*::before,*::after { box-sizing: border-box;}
  3728.         body { font-size:15px; color:#222;background:#F7F7F7; }
  3729.         body.navbar-fixed { margin-top:55px; }
  3730.         a, a:hover, a:visited, a:focus { text-decoration:none !important; }
  3731.         .filename, td, th { white-space:nowrap  }
  3732.         .navbar-brand { font-weight:bold; }
  3733.         .nav-item.avatar a { cursor:pointer;text-transform:capitalize; }
  3734.         .nav-item.avatar a > i { font-size:15px; }
  3735.         .nav-item.avatar .dropdown-menu a { font-size:13px; }
  3736.         #search-addon { font-size:12px;border-right-width:0; }
  3737.         .brl-0 { background:transparent;border-left:0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
  3738.         .brr-0 { border-top-right-radius: 0; border-bottom-right-radius: 0; }
  3739.         .bread-crumb { color:#cccccc;font-style:normal; }
  3740.         #main-table { transition: transform .25s cubic-bezier(0.4, 0.5, 0, 1),width 0s .25s;}
  3741.         #main-table .filename a { color:#222222; }
  3742.         .table td, .table th { vertical-align:middle !important; }
  3743.         .table .custom-checkbox-td .custom-control.custom-checkbox, .table .custom-checkbox-header .custom-control.custom-checkbox { min-width:18px; display: flex;align-items: center; justify-content: center; }
  3744.         .table-sm td, .table-sm th { padding:.4rem; }
  3745.         .table-bordered td, .table-bordered th { border:1px solid #f1f1f1; }
  3746.         .hidden { display:none  }
  3747.         pre.with-hljs { padding:0; overflow: hidden;  }
  3748.         pre.with-hljs code { margin:0;border:0;overflow:scroll;  }
  3749.         code.maxheight, pre.maxheight { max-height:512px  }
  3750.         .fa.fa-caret-right { font-size:1.2em;margin:0 4px;vertical-align:middle;color:#ececec  }
  3751.         .fa.fa-home { font-size:1.3em;vertical-align:bottom  }
  3752.         .path { margin-bottom:10px  }
  3753.         form.dropzone { min-height:200px;border:2px dashed #007bff;line-height:6rem; }
  3754.         .right { text-align:right  }
  3755.         .center, .close, .login-form, .preview-img-container { text-align:center  }
  3756.         .message { padding:4px 7px;border:1px solid #ddd;background-color:#fff  }
  3757.         .message.ok { border-color:green;color:green  }
  3758.         .message.error { border-color:red;color:red  }
  3759.         .message.alert { border-color:orange;color:orange  }
  3760.         .preview-img { max-width:100%;max-height:80vh;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC);cursor:zoom-in }
  3761.         input#preview-img-zoomCheck[type=checkbox] { display:none }
  3762.         input#preview-img-zoomCheck[type=checkbox]:checked ~ label > img { max-width:none;max-height:none;cursor:zoom-out }
  3763.         .inline-actions > a > i { font-size:1em;margin-left:5px;background:#3785c1;color:#fff;padding:3px 4px;border-radius:3px; }
  3764.         .preview-video { position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px  }
  3765.         .preview-video video { position:absolute;width:100%;height:100%;left:0;top:0;background:#000  }
  3766.         .compact-table { border:0;width:auto  }
  3767.         .compact-table td, .compact-table th { width:100px;border:0;text-align:center  }
  3768.         .compact-table tr:hover td { background-color:#fff  }
  3769.         .filename { max-width:420px;overflow:hidden;text-overflow:ellipsis  }
  3770.         .break-word { word-wrap:break-word;margin-left:30px  }
  3771.         .break-word.float-left a { color:#7d7d7d  }
  3772.         .break-word + .float-right { padding-right:30px;position:relative  }
  3773.         .break-word + .float-right > a { color:#7d7d7d;font-size:1.2em;margin-right:4px  }
  3774.         #editor { position:absolute;right:15px;top:100px;bottom:15px;left:15px  }
  3775.         @media (max-width:481px) {
  3776.             #editor { top:150px; }
  3777.         }
  3778.         #normal-editor { border-radius:3px;border-width:2px;padding:10px;outline:none; }
  3779.         .btn-2 { padding:4px 10px;font-size:small; }
  3780.         li.file:before,li.folder:before { font:normal normal normal 14px/1 FontAwesome;content:"\f016";margin-right:5px }
  3781.         li.folder:before { content:"\f114" }
  3782.         i.fa.fa-folder-o { color:#0157b3 }
  3783.         i.fa.fa-picture-o { color:#26b99a }
  3784.         i.fa.fa-file-archive-o { color:#da7d7d }
  3785.         .btn-2 i.fa.fa-file-archive-o { color:inherit }
  3786.         i.fa.fa-css3 { color:#f36fa0 }
  3787.         i.fa.fa-file-code-o { color:#007bff }
  3788.         i.fa.fa-code { color:#cc4b4c }
  3789.         i.fa.fa-file-text-o { color:#0096e6 }
  3790.         i.fa.fa-html5 { color:#d75e72 }
  3791.         i.fa.fa-file-excel-o { color:#09c55d }
  3792.         i.fa.fa-file-powerpoint-o { color:#f6712e }
  3793.         i.go-back { font-size:1.2em;color:#007bff; }
  3794.         .main-nav { padding:0.2rem 1rem;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)  }
  3795.         .dataTables_filter { display:none; }
  3796.         table.dataTable thead .sorting { cursor:pointer;background-repeat:no-repeat;background-position:center right;background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7XQMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC'); }
  3797.         table.dataTable thead .sorting_asc { cursor:pointer;background-repeat:no-repeat;background-position:center right;background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg=='); }
  3798.         table.dataTable thead .sorting_desc { cursor:pointer;background-repeat:no-repeat;background-position:center right;background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII='); }
  3799.         table.dataTable thead tr:first-child th.custom-checkbox-header:first-child { background-image:none; }
  3800.         .footer-action li { margin-bottom:10px; }
  3801.         .app-v-title { font-size:24px;font-weight:300;letter-spacing:-.5px;text-transform:uppercase; }
  3802.         hr.custom-hr { border-top:1px dashed #8c8b8b;border-bottom:1px dashed #fff; }
  3803.         #snackbar { visibility:hidden;min-width:250px;margin-left:-125px;background-color:#333;color:#fff;text-align:center;border-radius:2px;padding:16px;position:fixed;z-index:1;left:50%;bottom:30px;font-size:17px; }
  3804.         #snackbar.show { visibility:visible;-webkit-animation:fadein 0.5s, fadeout 0.5s 2.5s;animation:fadein 0.5s, fadeout 0.5s 2.5s; }
  3805.         @-webkit-keyframes fadein { from { bottom:0;opacity:0; }
  3806.         to { bottom:30px;opacity:1; }
  3807.         }
  3808.         @keyframes fadein { from { bottom:0;opacity:0; }
  3809.         to { bottom:30px;opacity:1; }
  3810.         }
  3811.         @-webkit-keyframes fadeout { from { bottom:30px;opacity:1; }
  3812.         to { bottom:0;opacity:0; }
  3813.         }
  3814.         @keyframes fadeout { from { bottom:30px;opacity:1; }
  3815.         to { bottom:0;opacity:0; }
  3816.         }
  3817.         #main-table span.badge { border-bottom:2px solid #f8f9fa }
  3818.         #main-table span.badge:nth-child(1) { border-color:#df4227 }
  3819.         #main-table span.badge:nth-child(2) { border-color:#f8b600 }
  3820.         #main-table span.badge:nth-child(3) { border-color:#00bd60 }
  3821.         #main-table span.badge:nth-child(4) { border-color:#4581ff }
  3822.         #main-table span.badge:nth-child(5) { border-color:#ac68fc }
  3823.         #main-table span.badge:nth-child(6) { border-color:#45c3d2 }
  3824.         @media only screen and (min-device-width:768px) and (max-device-width:1024px) and (orientation:landscape) and (-webkit-min-device-pixel-ratio:2) { .navbar-collapse .col-xs-6 { padding:0; }
  3825.         }
  3826.         .btn.active.focus,.btn.active:focus,.btn.focus,.btn.focus:active,.btn:active:focus,.btn:focus { outline:0!important;outline-offset:0!important;background-image:none!important;-webkit-box-shadow:none!important;box-shadow:none!important }
  3827.         .lds-facebook { display:none;position:relative;width:64px;height:64px }
  3828.         .lds-facebook div,.lds-facebook.show-me { display:inline-block }
  3829.         .lds-facebook div { position:absolute;left:6px;width:13px;background:#007bff;animation:lds-facebook 1.2s cubic-bezier(0,.5,.5,1) infinite }
  3830.         .lds-facebook div:nth-child(1) { left:6px;animation-delay:-.24s }
  3831.         .lds-facebook div:nth-child(2) { left:26px;animation-delay:-.12s }
  3832.         .lds-facebook div:nth-child(3) { left:45px;animation-delay:0s }
  3833.         @keyframes lds-facebook { 0% { top:6px;height:51px }
  3834.         100%,50% { top:19px;height:26px }
  3835.         }
  3836.         ul#search-wrapper { padding-left: 0;border: 1px solid #ecececcc; } ul#search-wrapper li { list-style: none; padding: 5px;border-bottom: 1px solid #ecececcc; }
  3837.         ul#search-wrapper li:nth-child(odd){ background: #f9f9f9cc;}
  3838.         .c-preview-img { max-width: 300px; }
  3839.         .border-radius-0 { border-radius: 0; }
  3840.         .float-right { float: right; }
  3841.         .table-hover>tbody>tr:hover>td:first-child { border-left: 1px solid #1b77fd; }
  3842.         #main-table tr.even { background-color: #F8F9Fa; }
  3843.         .filename>a>i {margin-right: 3px;}
  3844.     </style>
  3845.     <?php
  3846.     if (FM_THEME == "dark"): ?>
  3847.         <style>
  3848.             :root {
  3849.                 --bs-bg-opacity: 1;
  3850.                 --bg-color: #f3daa6;
  3851.                 --bs-dark-rgb: 28, 36, 41 !important;
  3852.                 --bs-bg-opacity: 1;
  3853.             }
  3854.             .table-dark { --bs-table-bg: 28, 36, 41 !important; }
  3855.             .btn-primary { --bs-btn-bg: #26566c; --bs-btn-border-color: #26566c; }
  3856.             body.theme-dark { background-image: linear-gradient(90deg, #1c2429, #263238); color: #CFD8DC; }
  3857.             .list-group .list-group-item { background: #343a40; }
  3858.             .theme-dark .navbar-nav i, .navbar-nav .dropdown-toggle, .break-word { color: #CFD8DC; }
  3859.             a, a:hover, a:visited, a:active, #main-table .filename a, i.fa.fa-folder-o, i.go-back { color: var(--bg-color); }
  3860.             ul#search-wrapper li:nth-child(odd) { background: #212a2f; }
  3861.             .theme-dark .btn-outline-primary { color: #b8e59c; border-color: #b8e59c; }
  3862.             .theme-dark .btn-outline-primary:hover, .theme-dark .btn-outline-primary:active { background-color: #2d4121;}
  3863.             .theme-dark input.form-control { background-color: #101518; color: #CFD8DC; }
  3864.             .theme-dark .dropzone { background: transparent; }
  3865.             .theme-dark .inline-actions > a > i { background: #79755e; }
  3866.             .theme-dark .text-white { color: #CFD8DC !important; }
  3867.             .theme-dark .table-bordered td, .table-bordered th { border-color: #343434; }
  3868.             .theme-dark .table-bordered td .custom-control-input, .theme-dark .table-bordered th .custom-control-input { opacity: 0.678; }
  3869.             .message { background-color: #212529; }
  3870.             .compact-table tr:hover td { background-color: #3d3d3d; }
  3871.             #main-table tr.even { background-color: #21292f; }
  3872.             form.dropzone { border-color: #79755e; }
  3873.         </style>
  3874.     <?php endif; ?>
  3875. </head>
  3876. <body class="<?php echo (FM_THEME == "dark") ? 'theme-dark' : ''; ?> <?php echo $isStickyNavBar; ?>">
  3877. <div id="wrapper" class="container-fluid">
  3878.     <!-- New Item creation -->
  3879.     <div class="modal fade" id="createNewItem" tabindex="-1" role="dialog" data-bs-backdrop="static" data-bs-keyboard="false" aria-labelledby="newItemModalLabel" aria-hidden="true">
  3880.         <div class="modal-dialog" role="document">
  3881.             <form class="modal-content <?php echo fm_get_theme(); ?>" method="post">
  3882.                 <div class="modal-header">
  3883.                     <h5 class="modal-title" id="newItemModalLabel"><i class="fa fa-plus-square fa-fw"></i><?php echo lng('CreateNewItem') ?></h5>
  3884.                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  3885.                 </div>
  3886.                 <div class="modal-body">
  3887.                     <p><label for="newfile"><?php echo lng('ItemType') ?> </label></p>
  3888.                     <div class="form-check form-check-inline">
  3889.                       <input class="form-check-input" type="radio" name="newfile" id="customRadioInline1" name="newfile" value="file">
  3890.                       <label class="form-check-label" for="customRadioInline1"><?php echo lng('File') ?></label>
  3891.                     </div>
  3892.                     <div class="form-check form-check-inline">
  3893.                       <input class="form-check-input" type="radio" name="newfile" id="customRadioInline2" value="folder" checked>
  3894.                       <label class="form-check-label" for="customRadioInline2"><?php echo lng('Folder') ?></label>
  3895.                     </div>
  3896.  
  3897.                     <p class="mt-3"><label for="newfilename"><?php echo lng('ItemName') ?> </label></p>
  3898.                     <input type="text" name="newfilename" id="newfilename" value="" class="form-control" placeholder="<?php echo lng('Enter here...') ?>" required>
  3899.                 </div>
  3900.                 <div class="modal-footer">
  3901.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  3902.                     <button type="button" class="btn btn-outline-primary" data-bs-dismiss="modal"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></button>
  3903.                     <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('CreateNow') ?></button>
  3904.                 </div>
  3905.             </form>
  3906.         </div>
  3907.     </div>
  3908.  
  3909.     <!-- Advance Search Modal -->
  3910.     <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
  3911.       <div class="modal-dialog modal-lg" role="document">
  3912.         <div class="modal-content <?php echo fm_get_theme(); ?>">
  3913.           <div class="modal-header">
  3914.             <h5 class="modal-title col-10" id="searchModalLabel">
  3915.                 <div class="input-group mb-3">
  3916.                   <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>
  3917.                   <span class="input-group-text" id="search-addon3"><i class="fa fa-search"></i></span>
  3918.                 </div>
  3919.             </h5>
  3920.             <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  3921.           </div>
  3922.           <div class="modal-body">
  3923.             <form action="" method="post">
  3924.                 <div class="lds-facebook"><div></div><div></div><div></div></div>
  3925.                 <ul id="search-wrapper">
  3926.                     <p class="m-2"><?php echo lng('Search file in folder and subfolders...') ?></p>
  3927.                 </ul>
  3928.             </form>
  3929.           </div>
  3930.         </div>
  3931.       </div>
  3932.     </div>
  3933.  
  3934.     <!--Rename Modal -->
  3935.     <div class="modal modal-alert" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="renameDailog">
  3936.       <div class="modal-dialog" role="document">
  3937.         <form class="modal-content rounded-3 shadow <?php echo fm_get_theme(); ?>" method="post" autocomplete="off">
  3938.           <div class="modal-body p-4 text-center">
  3939.             <h5 class="mb-3"><?php echo lng('Are you sure want to rename?') ?></h5>
  3940.             <p class="mb-1">
  3941.                 <input type="text" name="rename_to" id="js-rename-to" class="form-control" placeholder="<?php echo lng('Enter new file name') ?>" required>
  3942.                 <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  3943.                 <input type="hidden" name="rename_from" id="js-rename-from">
  3944.             </p>
  3945.           </div>
  3946.           <div class="modal-footer flex-nowrap p-0">
  3947.             <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>
  3948.             <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>
  3949.           </div>
  3950.         </form>
  3951.       </div>
  3952.     </div>
  3953.  
  3954.     <!-- Confirm Modal -->
  3955.     <script type="text/html" id="js-tpl-confirm">
  3956.         <div class="modal modal-alert confirmDailog" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" role="dialog" id="confirmDailog-<%this.id%>">
  3957.           <div class="modal-dialog" role="document">
  3958.             <form class="modal-content rounded-3 shadow <?php echo fm_get_theme(); ?>" method="post" autocomplete="off" action="<%this.action%>">
  3959.               <div class="modal-body p-4 text-center">
  3960.                 <h5 class="mb-2"><?php echo lng('Are you sure want to') ?> <%this.title%> ?</h5>
  3961.                 <p class="mb-1"><%this.content%></p>
  3962.               </div>
  3963.               <div class="modal-footer flex-nowrap p-0">
  3964.                 <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>
  3965.                 <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  3966.                 <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>
  3967.               </div>
  3968.             </form>
  3969.           </div>
  3970.         </div>
  3971.     </script>
  3972.  
  3973.     <?php
  3974.     }
  3975.  
  3976.     /**
  3977.      * Show page footer after login
  3978.      */
  3979.     function fm_show_footer()
  3980.     {
  3981.     ?>
  3982. </div>
  3983. <?php print_external('js-jquery'); ?>
  3984. <?php print_external('js-bootstrap'); ?>
  3985. <?php print_external('js-jquery-datatables'); ?>
  3986. <?php if (FM_USE_HIGHLIGHTJS && isset($_GET['view'])): ?>
  3987.     <?php print_external('js-highlightjs'); ?>
  3988.     <script>hljs.highlightAll(); var isHighlightingEnabled = true;</script>
  3989. <?php endif; ?>
  3990. <script>
  3991.     function template(html,options){
  3992.         var re=/<\%([^\%>]+)?\%>/g,reExp=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,code='var r=[];\n',cursor=0,match;var add=function(line,js){js?(code+=line.match(reExp)?line+'\n':'r.push('+line+');\n'):(code+=line!=''?'r.push("'+line.replace(/"/g,'\\"')+'");\n':'');return add}
  3993.         while(match=re.exec(html)){add(html.slice(cursor,match.index))(match[1],!0);cursor=match.index+match[0].length}
  3994.         add(html.substr(cursor,html.length-cursor));code+='return r.join("");';return new Function(code.replace(/[\r\t\n]/g,'')).apply(options)
  3995.     }
  3996.     function rename(e, t) { if(t) { $("#js-rename-from").val(t);$("#js-rename-to").val(t); $("#renameDailog").modal('show'); } }
  3997.     function change_checkboxes(e, t) { for (var n = e.length - 1; n >= 0; n--) e[n].checked = "boolean" == typeof t ? t : !e[n].checked }
  3998.     function get_checkboxes() { for (var e = document.getElementsByName("file[]"), t = [], n = e.length - 1; n >= 0; n--) (e[n].type = "checkbox") && t.push(e[n]); return t }
  3999.     function select_all() { change_checkboxes(get_checkboxes(), !0) }
  4000.     function unselect_all() { change_checkboxes(get_checkboxes(), !1) }
  4001.     function invert_all() { change_checkboxes(get_checkboxes()) }
  4002.     function checkbox_toggle() { var e = get_checkboxes(); e.push(this), change_checkboxes(e) }
  4003.     function backup(e, t) { // Create file backup with .bck
  4004.         var n = new XMLHttpRequest,
  4005.             a = "path=" + e + "&file=" + t + "&token="+ window.csrf +"&type=backup&ajax=true";
  4006.         return n.open("POST", "", !0), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.onreadystatechange = function () {
  4007.             4 == n.readyState && 200 == n.status && toast(n.responseText)
  4008.         }, n.send(a), !1
  4009.     }
  4010.     // Toast message
  4011.     function toast(txt) { var x = document.getElementById("snackbar");x.innerHTML=txt;x.className = "show";setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000); }
  4012.     // Save file
  4013.     function edit_save(e, t) {
  4014.         var n = "ace" == t ? editor.getSession().getValue() : document.getElementById("normal-editor").value;
  4015.         if (typeof n !== 'undefined' && n !== null) {
  4016.             if (true) {
  4017.                 var data = {ajax: true, content: n, type: 'save', token: window.csrf};
  4018.  
  4019.                 $.ajax({
  4020.                     type: "POST",
  4021.                     url: window.location,
  4022.                     data: JSON.stringify(data),
  4023.                     contentType: "application/json; charset=utf-8",
  4024.                     success: function(mes){toast("Saved Successfully"); window.onbeforeunload = function() {return}},
  4025.                     failure: function(mes) {toast("Error: try again");},
  4026.                     error: function(mes) {toast(`<p style="background-color:red">${mes.responseText}</p>`);}
  4027.                 });
  4028.             } else {
  4029.                 var a = document.createElement("form");
  4030.                 a.setAttribute("method", "POST"), a.setAttribute("action", "");
  4031.                 var o = document.createElement("textarea");
  4032.                 o.setAttribute("type", "textarea"), o.setAttribute("name", "savedata");
  4033.                 let cx = document.createElement("input"); cx.setAttribute("type", "hidden");cx.setAttribute("name", "token");cx.setAttribute("value", window.csrf);
  4034.                 var c = document.createTextNode(n);
  4035.                 o.appendChild(c), a.appendChild(o), a.appendChild(cx), document.body.appendChild(a), a.submit()
  4036.             }
  4037.         }
  4038.     }
  4039.     function show_new_pwd() { $(".js-new-pwd").toggleClass('hidden'); }
  4040.     // Save Settings
  4041.     function save_settings($this) {
  4042.         let form = $($this);
  4043.         $.ajax({
  4044.             type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&token="+ window.csrf +"&ajax="+true,
  4045.             success: function (data) {if(data) { window.location.reload();}}
  4046.         }); return false;
  4047.     }
  4048.     //Create new password hash
  4049.     function new_password_hash($this) {
  4050.         let form = $($this), $pwd = $("#js-pwd-result"); $pwd.val('');
  4051.         $.ajax({
  4052.             type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&token="+ window.csrf +"&ajax="+true,
  4053.             success: function (data) { if(data) { $pwd.val(data); } }
  4054.         }); return false;
  4055.     }
  4056.     // Upload files using URL @param {Object}
  4057.     function upload_from_url($this) {
  4058.         let form = $($this), resultWrapper = $("div#js-url-upload__list");
  4059.         $.ajax({
  4060.             type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&token="+ window.csrf +"&ajax="+true,
  4061.             beforeSend: function() { form.find("input[name=uploadurl]").attr("disabled","disabled"); form.find("button").hide(); form.find(".lds-facebook").addClass('show-me'); },
  4062.             success: function (data) {
  4063.                 if(data) {
  4064.                     data = JSON.parse(data);
  4065.                     if(data.done) {
  4066.                         resultWrapper.append('<div class="alert alert-success row">Uploaded Successful: '+data.done.name+'</div>'); form.find("input[name=uploadurl]").val('');
  4067.                     } else if(data['fail']) { resultWrapper.append('<div class="alert alert-danger row">Error: '+data.fail.message+'</div>'); }
  4068.                     form.find("input[name=uploadurl]").removeAttr("disabled");form.find("button").show();form.find(".lds-facebook").removeClass('show-me');
  4069.                 }
  4070.             },
  4071.             error: function(xhr) {
  4072.                 form.find("input[name=uploadurl]").removeAttr("disabled");form.find("button").show();form.find(".lds-facebook").removeClass('show-me');console.error(xhr);
  4073.             }
  4074.         }); return false;
  4075.     }
  4076.     // Search template
  4077.     function search_template(data) {
  4078.         var response = "";
  4079.         $.each(data, function (key, val) {
  4080.             response += `<li><a href="?p=${val.path}&view=${val.name}">${val.path}/${val.name}</a></li>`;
  4081.         });
  4082.         return response;
  4083.     }
  4084.     // Advance search
  4085.     function fm_search() {
  4086.         var searchTxt = $("input#advanced-search").val(), searchWrapper = $("ul#search-wrapper"), path = $("#js-search-modal").attr("href"), _html = "", $loader = $("div.lds-facebook");
  4087.         if(!!searchTxt && searchTxt.length > 2 && path) {
  4088.             var data = {ajax: true, content: searchTxt, path:path, type: 'search', token: window.csrf };
  4089.             $.ajax({
  4090.                 type: "POST",
  4091.                 url: window.location,
  4092.                 data: data,
  4093.                 beforeSend: function() {
  4094.                     searchWrapper.html('');
  4095.                     $loader.addClass('show-me');
  4096.                 },
  4097.                 success: function(data){
  4098.                     $loader.removeClass('show-me');
  4099.                     data = JSON.parse(data);
  4100.                     if(data && data.length) {
  4101.                         _html = search_template(data);
  4102.                         searchWrapper.html(_html);
  4103.                     } else { searchWrapper.html('<p class="m-2">No result found!<p>'); }
  4104.                 },
  4105.                 error: function(xhr) { $loader.removeClass('show-me'); searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>'); },
  4106.                 failure: function(mes) { $loader.removeClass('show-me'); searchWrapper.html('<p class="m-2">ERROR: Try again later!</p>');}
  4107.             });
  4108.         } else { searchWrapper.html("OOPS: minimum 3 characters required!"); }
  4109.     }
  4110.  
  4111.     // action confirm dailog modal
  4112.     function confirmDailog(e, id = 0, title = "Action", content = "", action = null) {
  4113.         e.preventDefault();
  4114.         const tplObj = {id, title, content: decodeURIComponent(content.replace(/\+/g, ' ')), action};
  4115.         let tpl = $("#js-tpl-confirm").html();
  4116.         $(".modal.confirmDailog").remove();
  4117.         $('#wrapper').append(template(tpl,tplObj));
  4118.         const $confirmDailog = $("#confirmDailog-"+tplObj.id);
  4119.         $confirmDailog.modal('show');
  4120.         return false;
  4121.     }
  4122.     
  4123.  
  4124.     // on mouse hover image preview
  4125.     !function(s){s.previewImage=function(e){var o=s(document),t=".previewImage",a=s.extend({xOffset:20,yOffset:-20,fadeIn:"fast",css:{padding:"5px",border:"1px solid #cccccc","background-color":"#fff"},eventSelector:"[data-preview-image]",dataKey:"previewImage",overlayId:"preview-image-plugin-overlay"},e);return o.off(t),o.on("mouseover"+t,a.eventSelector,function(e){s("p#"+a.overlayId).remove();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)));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)}),o.on("mouseout"+t,a.eventSelector,function(){s("#"+a.overlayId).remove()}),o.on("mousemove"+t,a.eventSelector,function(e){s("#"+a.overlayId).css("top",e.pageY+a.yOffset+"px").css("left",e.pageX+a.xOffset+"px")}),this},s.previewImage()}(jQuery);
  4126.  
  4127.     // Dom Ready Events
  4128.     $(document).ready( function () {
  4129.         // dataTable init
  4130.         var $table = $('#main-table'),
  4131.             tableLng = $table.find('th').length,
  4132.             _targets = (tableLng && tableLng == 7 ) ? [0, 4,5,6] : tableLng == 5 ? [0,4] : [3];
  4133.             mainTable = $('#main-table').DataTable({paging: false, info: false, order: [], columnDefs: [{targets: _targets, orderable: false}]
  4134.         });
  4135.         // filter table
  4136.         $('#search-addon').on( 'keyup', function () {
  4137.             mainTable.search( this.value ).draw();
  4138.         });
  4139.         $("input#advanced-search").on('keyup', function (e) {
  4140.             if (e.keyCode === 13) { fm_search(); }
  4141.         });
  4142.         $('#search-addon3').on( 'click', function () { fm_search(); });
  4143.         //upload nav tabs
  4144.         $(".fm-upload-wrapper .card-header-tabs").on("click", 'a', function(e){
  4145.             e.preventDefault();let target=$(this).data('target');
  4146.             $(".fm-upload-wrapper .card-header-tabs a").removeClass('active');$(this).addClass('active');
  4147.             $(".fm-upload-wrapper .card-tabs-container").addClass('hidden');$(target).removeClass('hidden');
  4148.         });
  4149.     });
  4150. </script>
  4151. <?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE && !FM_READONLY):
  4152.         
  4153.         $ext = pathinfo($_GET["edit"], PATHINFO_EXTENSION);
  4154.         $ext =  $ext == "js" ? "javascript" :  $ext;
  4155.         ?>
  4156.     <?php print_external('js-ace'); ?>
  4157.     <script>
  4158.         var editor = ace.edit("editor");
  4159.         editor.getSession().setMode( {path:"ace/mode/<?php echo $ext; ?>", inline:true} );
  4160.         //editor.setTheme("ace/theme/twilight"); //Dark Theme
  4161.         editor.setShowPrintMargin(false); // Hide the vertical ruler
  4162.         function ace_commend (cmd) { editor.commands.exec(cmd, editor); }
  4163.         editor.commands.addCommands([{
  4164.             name: 'save', bindKey: {win: 'Ctrl-S',  mac: 'Command-S'},
  4165.             exec: function(editor) { edit_save(this, 'ace'); }
  4166.         }]);
  4167.         function renderThemeMode() {
  4168.             var $modeEl = $("select#js-ace-mode"), $themeEl = $("select#js-ace-theme"), $fontSizeEl = $("select#js-ace-fontSize"), optionNode = function(type, arr){ var $Option = ""; $.each(arr, function(i, val) { $Option += "<option value='"+type+i+"'>" + val + "</option>"; }); return $Option; },
  4169.                 _data = {"aceTheme":{"bright":{"chrome":"Chrome","clouds":"Clouds","crimson_editor":"Crimson Editor","dawn":"Dawn","dreamweaver":"Dreamweaver","eclipse":"Eclipse","github":"GitHub","iplastic":"IPlastic","solarized_light":"Solarized Light","textmate":"TextMate","tomorrow":"Tomorrow","xcode":"XCode","kuroir":"Kuroir","katzenmilch":"KatzenMilch","sqlserver":"SQL Server"},"dark":{"ambiance":"Ambiance","chaos":"Chaos","clouds_midnight":"Clouds Midnight","dracula":"Dracula","cobalt":"Cobalt","gruvbox":"Gruvbox","gob":"Green on Black","idle_fingers":"idle Fingers","kr_theme":"krTheme","merbivore":"Merbivore","merbivore_soft":"Merbivore Soft","mono_industrial":"Mono Industrial","monokai":"Monokai","pastel_on_dark":"Pastel on dark","solarized_dark":"Solarized Dark","terminal":"Terminal","tomorrow_night":"Tomorrow Night","tomorrow_night_blue":"Tomorrow Night Blue","tomorrow_night_bright":"Tomorrow Night Bright","tomorrow_night_eighties":"Tomorrow Night 80s","twilight":"Twilight","vibrant_ink":"Vibrant Ink"}},"aceMode":{"javascript":"JavaScript","abap":"ABAP","abc":"ABC","actionscript":"ActionScript","ada":"ADA","apache_conf":"Apache Conf","asciidoc":"AsciiDoc","asl":"ASL","assembly_x86":"Assembly x86","autohotkey":"AutoHotKey","apex":"Apex","batchfile":"BatchFile","bro":"Bro","c_cpp":"C and C++","c9search":"C9Search","cirru":"Cirru","clojure":"Clojure","cobol":"Cobol","coffee":"CoffeeScript","coldfusion":"ColdFusion","csharp":"C#","csound_document":"Csound Document","csound_orchestra":"Csound","csound_score":"Csound Score","css":"CSS","curly":"Curly","d":"D","dart":"Dart","diff":"Diff","dockerfile":"Dockerfile","dot":"Dot","drools":"Drools","edifact":"Edifact","eiffel":"Eiffel","ejs":"EJS","elixir":"Elixir","elm":"Elm","erlang":"Erlang","forth":"Forth","fortran":"Fortran","fsharp":"FSharp","fsl":"FSL","ftl":"FreeMarker","gcode":"Gcode","gherkin":"Gherkin","gitignore":"Gitignore","glsl":"Glsl","gobstones":"Gobstones","golang":"Go","graphqlschema":"GraphQLSchema","groovy":"Groovy","haml":"HAML","handlebars":"Handlebars","haskell":"Haskell","haskell_cabal":"Haskell Cabal","haxe":"haXe","hjson":"Hjson","html":"HTML","html_elixir":"HTML (Elixir)","html_ruby":"HTML (Ruby)","ini":"INI","io":"Io","jack":"Jack","jade":"Jade","java":"Java","json":"JSON","jsoniq":"JSONiq","jsp":"JSP","jssm":"JSSM","jsx":"JSX","julia":"Julia","kotlin":"Kotlin","latex":"LaTeX","less":"LESS","liquid":"Liquid","lisp":"Lisp","livescript":"LiveScript","logiql":"LogiQL","lsl":"LSL","lua":"Lua","luapage":"LuaPage","lucene":"Lucene","makefile":"Makefile","markdown":"Markdown","mask":"Mask","matlab":"MATLAB","maze":"Maze","mel":"MEL","mixal":"MIXAL","mushcode":"MUSHCode","mysql":"MySQL","nix":"Nix","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","pascal":"Pascal","perl":"Perl","perl6":"Perl 6","pgsql":"pgSQL","php_laravel_blade":"PHP (Blade Template)","php":"PHP","puppet":"Puppet","pig":"Pig","powershell":"Powershell","praat":"Praat","prolog":"Prolog","properties":"Properties","protobuf":"Protobuf","python":"Python","r":"R","razor":"Razor","rdoc":"RDoc","red":"Red","rhtml":"RHTML","rst":"RST","ruby":"Ruby","rust":"Rust","sass":"SASS","scad":"SCAD","scala":"Scala","scheme":"Scheme","scss":"SCSS","sh":"SH","sjs":"SJS","slim":"Slim","smarty":"Smarty","snippets":"snippets","soy_template":"Soy Template","space":"Space","sql":"SQL","sqlserver":"SQLServer","stylus":"Stylus","svg":"SVG","swift":"Swift","tcl":"Tcl","terraform":"Terraform","tex":"Tex","text":"Text","textile":"Textile","toml":"Toml","tsx":"TSX","twig":"Twig","typescript":"Typescript","vala":"Vala","vbscript":"VBScript","velocity":"Velocity","verilog":"Verilog","vhdl":"VHDL","visualforce":"Visualforce","wollok":"Wollok","xml":"XML","xquery":"XQuery","yaml":"YAML","django":"Django"},"fontSize":{8:8,10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,20:20,22:22,24:24,26:26,30:30}};
  4170.             if(_data && _data.aceMode) { $modeEl.html(optionNode("ace/mode/", _data.aceMode)); }
  4171.             if(_data && _data.aceTheme) { var lightTheme = optionNode("ace/theme/", _data.aceTheme.bright), darkTheme = optionNode("ace/theme/", _data.aceTheme.dark); $themeEl.html("<optgroup label=\"Bright\">"+lightTheme+"</optgroup><optgroup label=\"Dark\">"+darkTheme+"</optgroup>");}
  4172.             if(_data && _data.fontSize) { $fontSizeEl.html(optionNode("", _data.fontSize)); }
  4173.             $modeEl.val( editor.getSession().$modeId );
  4174.             $themeEl.val( editor.getTheme() );
  4175.             $fontSizeEl.val(12).change(); //set default font size in drop down
  4176.         }
  4177.  
  4178.         $(function(){
  4179.             renderThemeMode();
  4180.             $(".js-ace-toolbar").on("click", 'button', function(e){
  4181.                 e.preventDefault();
  4182.                 let cmdValue = $(this).attr("data-cmd"), editorOption = $(this).attr("data-option");
  4183.                 if(cmdValue && cmdValue != "none") {
  4184.                     ace_commend(cmdValue);
  4185.                 } else if(editorOption) {
  4186.                     if(editorOption == "fullscreen") {
  4187.                         (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)
  4188.                         &&(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());
  4189.                     } else if(editorOption == "wrap") {
  4190.                         let wrapStatus = (editor.getSession().getUseWrapMode()) ? false : true;
  4191.                         editor.getSession().setUseWrapMode(wrapStatus);
  4192.                     }
  4193.                 }
  4194.             });
  4195.             $("select#js-ace-mode, select#js-ace-theme, select#js-ace-fontSize").on("change", function(e){
  4196.                 e.preventDefault();
  4197.                 let selectedValue = $(this).val(), selectionType = $(this).attr("data-type");
  4198.                 if(selectedValue && selectionType == "mode") {
  4199.                     editor.getSession().setMode(selectedValue);
  4200.                 } else if(selectedValue && selectionType == "theme") {
  4201.                     editor.setTheme(selectedValue);
  4202.                 }else if(selectedValue && selectionType == "fontSize") {
  4203.                     editor.setFontSize(parseInt(selectedValue));
  4204.                 }
  4205.             });
  4206.         });
  4207.     </script>
  4208. <?php endif; ?>
  4209. <div id="snackbar"></div>
  4210. </body>
  4211. </html>
  4212. <?php
  4213. }
  4214.  
  4215. /**
  4216.  * Language Translation System
  4217.  * @param string $txt
  4218.  * @return string
  4219.  */
  4220. function lng($txt) {
  4221.     global $lang;
  4222.  
  4223.     // English Language
  4224.     $tr['en']['AppName']        = 'Tiny File Manager';      $tr['en']['AppTitle']           = 'File Manager';
  4225.     $tr['en']['Login']          = 'Sign in';                $tr['en']['Username']           = 'Username';
  4226.     $tr['en']['Password']       = 'Password';               $tr['en']['Logout']             = 'Sign Out';
  4227.     $tr['en']['Move']           = 'Move';                   $tr['en']['Copy']               = 'Copy';
  4228.     $tr['en']['Save']           = 'Save';                   $tr['en']['SelectAll']          = 'Select all';
  4229.     $tr['en']['UnSelectAll']    = 'Unselect all';           $tr['en']['File']               = 'File';
  4230.     $tr['en']['Back']           = 'Back';                   $tr['en']['Size']               = 'Size';
  4231.     $tr['en']['Perms']          = 'Perms';                  $tr['en']['Modified']           = 'Modified';
  4232.     $tr['en']['Owner']          = 'Owner';                  $tr['en']['Search']             = 'Search';
  4233.     $tr['en']['NewItem']        = 'New Item';               $tr['en']['Folder']             = 'Folder';
  4234.     $tr['en']['Delete']         = 'Delete';                 $tr['en']['Rename']             = 'Rename';
  4235.     $tr['en']['CopyTo']         = 'Copy to';                $tr['en']['DirectLink']         = 'Direct link';
  4236.     $tr['en']['UploadingFiles'] = 'Upload Files';           $tr['en']['ChangePermissions']  = 'Change Permissions';
  4237.     $tr['en']['Copying']        = 'Copying';                $tr['en']['CreateNewItem']      = 'Create New Item';
  4238.     $tr['en']['Name']           = 'Name';                   $tr['en']['AdvancedEditor']     = 'Advanced Editor';
  4239.     $tr['en']['Actions']        = 'Actions';                $tr['en']['Folder is empty']    = 'Folder is empty';
  4240.     $tr['en']['Upload']         = 'Upload';                 $tr['en']['Cancel']             = 'Cancel';
  4241.     $tr['en']['InvertSelection']= 'Invert Selection';       $tr['en']['DestinationFolder']  = 'Destination Folder';
  4242.     $tr['en']['ItemType']       = 'Item Type';              $tr['en']['ItemName']           = 'Item Name';
  4243.     $tr['en']['CreateNow']      = 'Create Now';             $tr['en']['Download']           = 'Download';
  4244.     $tr['en']['Open']           = 'Open';                   $tr['en']['UnZip']              = 'UnZip';
  4245.     $tr['en']['UnZipToFolder']  = 'UnZip to folder';        $tr['en']['Edit']               = 'Edit';
  4246.     $tr['en']['NormalEditor']   = 'Normal Editor';          $tr['en']['BackUp']             = 'Back Up';
  4247.     $tr['en']['SourceFolder']   = 'Source Folder';          $tr['en']['Files']              = 'Files';
  4248.     $tr['en']['Move']           = 'Move';                   $tr['en']['Change']             = 'Change';
  4249.     $tr['en']['Settings']       = 'Settings';               $tr['en']['Language']           = 'Language';        
  4250.     $tr['en']['ErrorReporting'] = 'Error Reporting';        $tr['en']['ShowHiddenFiles']    = 'Show Hidden Files';
  4251.     $tr['en']['Help']           = 'Help';                   $tr['en']['Created']            = 'Created';
  4252.     $tr['en']['Help Documents'] = 'Help Documents';         $tr['en']['Report Issue']       = 'Report Issue';
  4253.     $tr['en']['Generate']       = 'Generate';               $tr['en']['FullSize']           = 'Full Size';              
  4254.     $tr['en']['HideColumns']    = 'Hide Perms/Owner columns';$tr['en']['You are logged in'] = 'You are logged in';
  4255.     $tr['en']['Nothing selected']   = 'Nothing selected';   $tr['en']['Paths must be not equal']    = 'Paths must be not equal';
  4256.     $tr['en']['Renamed from']       = 'Renamed from';       $tr['en']['Archive not unpacked']       = 'Archive not unpacked';
  4257.     $tr['en']['Deleted']            = 'Deleted';            $tr['en']['Archive not created']        = 'Archive not created';
  4258.     $tr['en']['Copied from']        = 'Copied from';        $tr['en']['Permissions changed']        = 'Permissions changed';
  4259.     $tr['en']['to']                 = 'to';                 $tr['en']['Saved Successfully']         = 'Saved Successfully';
  4260.     $tr['en']['not found!']         = 'not found!';         $tr['en']['File Saved Successfully']    = 'File Saved Successfully';
  4261.     $tr['en']['Archive']            = 'Archive';            $tr['en']['Permissions not changed']    = 'Permissions not changed';
  4262.     $tr['en']['Select folder']      = 'Select folder';      $tr['en']['Source path not defined']    = 'Source path not defined';
  4263.     $tr['en']['already exists']     = 'already exists';     $tr['en']['Error while moving from']    = 'Error while moving from';
  4264.     $tr['en']['Create archive?']    = 'Create archive?';    $tr['en']['Invalid file or folder name']    = 'Invalid file or folder name';
  4265.     $tr['en']['Archive unpacked']   = 'Archive unpacked';   $tr['en']['File extension is not allowed']  = 'File extension is not allowed';
  4266.     $tr['en']['Root path']          = 'Root path';          $tr['en']['Error while renaming from']  = 'Error while renaming from';
  4267.     $tr['en']['File not found']     = 'File not found';     $tr['en']['Error while deleting items'] = 'Error while deleting items';
  4268.     $tr['en']['Moved from']         = 'Moved from';         $tr['en']['Generate new password hash'] = 'Generate new password hash';
  4269.     $tr['en']['Login failed. Invalid username or password'] = 'Login failed. Invalid username or password';
  4270.     $tr['en']['password_hash not supported, Upgrade PHP version'] = 'password_hash not supported, Upgrade PHP version';
  4271.     $tr['en']['Advanced Search']    = 'Advanced Search';    $tr['en']['Error while copying from']    = 'Error while copying from';
  4272.     $tr['en']['Invalid characters in file name']                = 'Invalid characters in file name';
  4273.     $tr['en']['FILE EXTENSION HAS NOT SUPPORTED']               = 'FILE EXTENSION HAS NOT SUPPORTED';
  4274.     $tr['en']['Selected files and folder deleted']              = 'Selected files and folder deleted';
  4275.     $tr['en']['Error while fetching archive info']              = 'Error while fetching archive info';
  4276.     $tr['en']['Delete selected files and folders?']             = 'Delete selected files and folders?';
  4277.     $tr['en']['Search file in folder and subfolders...']        = 'Search file in folder and subfolders...';
  4278.     $tr['en']['Access denied. IP restriction applicable']       = 'Access denied. IP restriction applicable';
  4279.     $tr['en']['Invalid characters in file or folder name']      = 'Invalid characters in file or folder name';
  4280.     $tr['en']['Operations with archives are not available']     = 'Operations with archives are not available';
  4281.     $tr['en']['File or folder with this path already exists']   = 'File or folder with this path already exists';
  4282.  
  4283.     $i18n = fm_get_translations($tr);
  4284.     $tr = $i18n $i18n : $tr;
  4285.  
  4286.     if (!strlen($lang)) $lang = 'en';
  4287.     if (isset($tr[$lang][$txt])) return fm_enc($tr[$lang][$txt]);
  4288.     else if (isset($tr['en'][$txt])) return fm_enc($tr['en'][$txt]);
  4289.     else return "$txt";
  4290. }
  4291.  
  4292. ?>
File Description
  • hello
  • PHP Code
  • 01 Mar-2024
  • 195.81 Kb
You can Share it: