NoPaste

XmasCLOUD

von uname

SNIPPET_TEXT:
  1. <?php
  2. //Default Configuration
  3. $CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
  4.  
  5. /**
  6.  * H3K | Tiny File Manager V2.5.2
  7.  * @author Prasath Mani | CCP Programmers
  8.  * @email ccpprogrammers@gmail.com
  9.  * @github https://github.com/prasathmani/tinyfilemanager
  10.  * @link https://tinyfilemanager.github.io
  11.  */
  12.  
  13.  
  14.  
  15. //TFM version
  16. define('VERSION', '2.5.2');
  17.  
  18. //Application Title
  19. //define('APP_TITLE', 'Tiny File Manager');
  20. define('APP_TITLE', 'XmasCLOUD'); // XmasCLOUD
  21.  
  22.  
  23.  
  24. // --- EDIT BELOW CONFIGURATION CAREFULLY ---
  25.  
  26. // Auth with login/password
  27. // set true/false to enable/disable it
  28. // Is independent from IP white- and blacklisting
  29. $use_auth = false; // xmascloud
  30.  
  31. // Login user name and password
  32. // Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
  33. // Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
  34. $auth_users = array(
  35.     'admin' => '$2y$10$/K.hjNr84lLNDt8fTXjoI.DBp6PpeyoJ.mGwrrLuCZfAwfSAGqhOW', //admin@123
  36.     'user' => '$2y$10$Fg6Dz8oH9fPoZ2jJan5tZuv6Z4Kp7avtQ9bDfrdRntXtPeiMAZyGO' //12345
  37. );
  38.  
  39. // Readonly users
  40. // e.g. array('users', 'guest', ...)
  41. $readonly_users = array(
  42.     'user'
  43. );
  44.  
  45. // Global readonly, including when auth is not being used
  46. $global_readonly = false; // XmasCLOUD
  47.  
  48. // user specific directories
  49. // array('Username' => 'Directory path', 'Username2' => 'Directory path', ...)
  50. $directories_users = array();
  51.  
  52. // Enable highlight.js (https://highlightjs.org/) on view's page
  53. $use_highlightjs = true;
  54.  
  55. // highlight.js style
  56. // for dark theme use 'ir-black'
  57. $highlightjs_style = 'vs';
  58.  
  59. // Enable ace.js (https://ace.c9.io/) on view's page
  60. $edit_files = true;
  61.  
  62. // Default timezone for date() and time()
  63. // Doc - http://php.net/manual/en/timezones.php
  64. //$default_timezone = 'Etc/UTC'; // UTC
  65. $default_timezone = "Europe/Berlin"; // XmasCLOUD
  66.  
  67. // Root path for file manager
  68. // use absolute path of directory i.e: '/var/www/folder' or $_SERVER['DOCUMENT_ROOT'].'/folder'
  69. // $root_path = $_SERVER['DOCUMENT_ROOT'];
  70. $root_path = $_SERVER['DOCUMENT_ROOT'] . '/xmascloud/'; // XmasCLOUD
  71.  
  72.  
  73. // Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
  74. // Will not working if $root_path will be outside of server document root
  75. $root_url = 'xmascloud'; // XmasCLOUD
  76.  
  77. // Server hostname. Can set manually if wrong
  78. // $_SERVER['HTTP_HOST'].'/folder'
  79. $http_host = $_SERVER['HTTP_HOST'];
  80.  
  81. // input encoding for iconv
  82. $iconv_input_encoding = 'UTF-8';
  83.  
  84. // date() format for file modification date
  85. // Doc - https://www.php.net/manual/en/function.date.php
  86. $datetime_format = 'm/d/Y g:i A';
  87.  
  88. // Allowed file extensions for create and rename files
  89. // e.g. 'txt,html,css,js'
  90. // $allowed_file_extensions = '';  // XmasCLOUD
  91. $allowed_file_extensions = 'webm,jpg,png,bmp,ico,csv,dbf,dif,doc,docm,docx,dot,dotm,dotx,emf,emf,gif,htm,html,mht,mhtml,mp3,mp4 ,odp ,ods,odt,pdf,pot,potm,potx,ppa,ppam,pps,ppsm,ppsx,ppt,pptm,pptx,prm,rtf,rtf,slk,thmx,tif,txt,wmf,wmv,wps,xla,xlam,xls,xlsb,xlsm,xlsx,xlt,xltm,xltx,xlw,xml,xps,xps';
  92.  
  93.  
  94. // Allowed file extensions for upload files
  95. // e.g. 'gif,png,jpg,html,txt'
  96. // $allowed_upload_extensions = ''; // XmasCLOUD
  97. $allowed_upload_extensions = 'webm,jpg,png,bmp,ico,csv,dbf,dif,doc,docm,docx,dot,dotm,dotx,emf,emf,gif,htm,html,mht,mhtml,mp3,mp4 ,odp ,ods,odt,pdf,pot,potm,potx,ppa,ppam,pps,ppsm,ppsx,ppt,pptm,pptx,prm,rtf,rtf,slk,thmx,tif,txt,wmf,wmv,wps,xla,xlam,xls,xlsb,xlsm,xlsx,xlt,xltm,xltx,xlw,xml,xps,xps';
  98.  
  99.  
  100. // Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
  101. // full path, e.g http://example.com/favicon.png
  102. // local path, e.g images/icons/favicon.png
  103. $favicon_path = '';
  104.  
  105. // Files and folders to excluded from listing
  106. // e.g. array('myfile.html', 'personal-folder', '*.php', ...)
  107. $exclude_items = array();
  108.  
  109. // Online office Docs Viewer
  110. // Availabe rules are 'google', 'microsoft' or false
  111. // Google => View documents using Google Docs Viewer
  112. // Microsoft => View documents using Microsoft Web Apps Viewer
  113. // false => disable online doc viewer
  114. $online_viewer = false; // xmascloud
  115.  
  116. // Sticky Nav bar
  117. // true => enable sticky header
  118. // false => disable sticky header
  119. $sticky_navbar = true;
  120.  
  121. // Maximum file upload size
  122. // Increase the following values in php.ini to work properly
  123. // memory_limit, upload_max_filesize, post_max_size
  124. $max_upload_size_bytes = 5000000000; // size 5,000,000,000 bytes (~5GB)
  125.  
  126. // Possible rules are 'OFF', 'AND' or 'OR'
  127. // OFF => Don't check connection IP, defaults to OFF
  128. // AND => Connection must be on the whitelist, and not on the blacklist
  129. // OR => Connection must be on the whitelist, or not on the blacklist
  130. $ip_ruleset = 'OFF';
  131.  
  132. // Should users be notified of their block?
  133. $ip_silent = true;
  134.  
  135. // IP-addresses, both ipv4 and ipv6
  136. $ip_whitelist = array(
  137.     '127.0.0.1',    // local ipv4
  138.     '::1'           // local ipv6
  139. );
  140.  
  141. // IP-addresses, both ipv4 and ipv6
  142. $ip_blacklist = array(
  143.     '0.0.0.0',      // non-routable meta ipv4
  144.     '::'            // non-routable meta ipv6
  145. );
  146.  
  147. // if User has the external config file, try to use it to override the default config above [config.php]
  148. // sample config - https://tinyfilemanager.github.io/config-sample.txt
  149. $config_file = __DIR__.'/config.php';
  150. if (is_readable($config_file)) {
  151.     @include($config_file);
  152. }
  153.  
  154. // --- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL ---
  155.  
  156. // max upload file size
  157. define('MAX_UPLOAD_SIZE', $max_upload_size_bytes);
  158.  
  159. // private key and session name to store to the session
  160. if ( !defined( 'FM_SESSION_ID')) {
  161.     define('FM_SESSION_ID', 'filemanager');
  162. }
  163.  
  164. // Configuration
  165. $cfg = new FM_Config();
  166.  
  167. // Default language
  168. $lang = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
  169.  
  170. // Show or hide files and folders that starts with a dot
  171. $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
  172.  
  173. // PHP error reporting - false = Turns off Errors, true = Turns on Errors
  174. $report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
  175.  
  176. // Hide Permissions and Owner cols in file-listing
  177. $hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
  178.  
  179. // Theme
  180. $theme = isset($cfg->data['theme']) ? $cfg->data['theme'] : 'light';
  181.  
  182. define('FM_THEME', $theme);
  183.  
  184. //available languages
  185. $lang_list = array(
  186.     'en' => 'English'
  187. );
  188.  
  189. if ($report_errors == true) {
  190.     @ini_set('error_reporting', E_ALL);
  191.     @ini_set('display_errors', 1);
  192. } else {
  193.     @ini_set('error_reporting', E_ALL);
  194.     @ini_set('display_errors', 0);
  195. }
  196.  
  197. // if fm included
  198. if (defined('FM_EMBED')) {
  199.     $use_auth = false;
  200.     $sticky_navbar = false;
  201. } else {
  202.     @set_time_limit(600);
  203.  
  204.     date_default_timezone_set($default_timezone);
  205.  
  206.     ini_set('default_charset', 'UTF-8');
  207.     if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
  208.         mb_internal_encoding('UTF-8');
  209.     }
  210.     if (function_exists('mb_regex_encoding')) {
  211.         mb_regex_encoding('UTF-8');
  212.     }
  213.  
  214.     session_name(FM_SESSION_ID );
  215.     function session_error_handling_function($code, $msg, $file, $line) {
  216.         // Permission denied for default session, try to create a new one
  217.         if ($code == 2) {
  218.             session_abort();
  219.             session_id(session_create_id());
  220.             @session_start();
  221.         }
  222.     }
  223.     set_error_handler('session_error_handling_function');
  224.     session_start();
  225. }
  226.  
  227. //Genrating CSRF Token
  228. if (empty($_SESSION['token'])) {
  229.     $_SESSION['token'] = bin2hex(random_bytes(32));
  230. }
  231.  
  232. if (empty($auth_users)) {
  233.     $use_auth = false;
  234. }
  235.  
  236. $is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
  237.     || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
  238.  
  239. // update $root_url based on user specific directories
  240. if (isset($_SESSION[FM_SESSION_ID]['logged']) && !empty($directories_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  241.     $wd = fm_clean_path(dirname($_SERVER['PHP_SELF']));
  242.     $root_url =  $root_url.$wd.DIRECTORY_SEPARATOR.$directories_users[$_SESSION[FM_SESSION_ID]['logged']];
  243. }
  244. // clean $root_url
  245. $root_url = fm_clean_path($root_url);
  246.  
  247. // abs path for site
  248. defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
  249. defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
  250.  
  251. // logout
  252. if (isset($_GET['logout'])) {
  253.     unset($_SESSION[FM_SESSION_ID]['logged']);
  254.     unset( $_SESSION['token']);
  255.     fm_redirect(FM_SELF_URL);
  256. }
  257.  
  258. // Validate connection IP
  259. if ($ip_ruleset != 'OFF') {
  260.     function getClientIP() {
  261.         if (array_key_exists('HTTP_CF_CONNECTING_IP', $_SERVER)) {
  262.             return  $_SERVER["HTTP_CF_CONNECTING_IP"];
  263.         }else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
  264.             return  $_SERVER["HTTP_X_FORWARDED_FOR"];
  265.         }else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
  266.             return $_SERVER['REMOTE_ADDR'];
  267.         }else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
  268.             return $_SERVER['HTTP_CLIENT_IP'];
  269.         }
  270.         return '';
  271.     }
  272.  
  273.     $clientIp = getClientIP();
  274.     $proceed = false;
  275.     $whitelisted = in_array($clientIp, $ip_whitelist);
  276.     $blacklisted = in_array($clientIp, $ip_blacklist);
  277.  
  278.     if($ip_ruleset == 'AND'){
  279.         if($whitelisted == true && $blacklisted == false){
  280.             $proceed = true;
  281.         }
  282.     } else
  283.     if($ip_ruleset == 'OR'){
  284.          if($whitelisted == true || $blacklisted == false){
  285.             $proceed = true;
  286.         }
  287.     }
  288.  
  289.     if($proceed == false){
  290.         trigger_error('User connection denied from: ' . $clientIp, E_USER_WARNING);
  291.  
  292.         if($ip_silent == false){
  293.             fm_set_msg(lng('Access denied. IP restriction applicable'), 'error');
  294.             fm_show_header_login();
  295.             fm_show_message();
  296.         }
  297.         exit();
  298.     }
  299. }
  300.  
  301. // Checking if the user is logged in or not. If not, it will show the login form.
  302. if ($use_auth) {
  303.     if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  304.         // Logged
  305.     } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'], $_POST['token'])) {
  306.         // Logging In
  307.         sleep(1);
  308.         if(function_exists('password_verify')) {
  309.             if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']]) && verifyToken($_POST['token'])) {
  310.                 $_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr'];
  311.                 fm_set_msg(lng('You are logged in'));
  312.                 fm_redirect(FM_ROOT_URL . $_SERVER['REQUEST_URI']);
  313.             } else {
  314.                 unset($_SESSION[FM_SESSION_ID]['logged']);
  315.                 fm_set_msg(lng('Login failed. Invalid username or password'), 'error');
  316.                 fm_redirect(FM_ROOT_URL . $_SERVER['REQUEST_URI']);
  317.             }
  318.         } else {
  319.             fm_set_msg(lng('password_hash not supported, Upgrade PHP version'), 'error');;
  320.         }
  321.     } else {
  322.         // Form
  323.         unset($_SESSION[FM_SESSION_ID]['logged']);
  324.         fm_show_header_login();
  325.         ?>
  326.         <section class="h-100">
  327.             <div class="container h-100">
  328.                 <div class="row justify-content-md-center h-100">
  329.                     <div class="card-wrapper">
  330.                         <div class="card fat <?php echo fm_get_theme(); ?>">
  331.                             <div class="card-body">
  332.                                 <form class="form-signin" action="" method="post" autocomplete="off">
  333.                                     <div class="mb-3">
  334.                                        <div class="brand">
  335.                                             <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">
  336.                                                 <g transform="translate(0.000000,140.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">
  337.                                                     <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"/>
  338.                                                     <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"/>
  339.                                                     <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>
  340.                                             </svg>
  341.                                         </div>
  342.                                         <div class="text-center">
  343.                                             <h1 class="card-title"><?php echo APP_TITLE; ?></h1>
  344.                                         </div>
  345.                                     </div>
  346.                                     <hr />
  347.                                     <div class="mb-3">
  348.                                         <label for="fm_usr" class="pb-2"><?php echo lng('Username'); ?></label>
  349.                                         <input type="text" class="form-control" id="fm_usr" name="fm_usr" required autofocus>
  350.                                     </div>
  351.  
  352.                                     <div class="mb-3">
  353.                                         <label for="fm_pwd" class="pb-2"><?php echo lng('Password'); ?></label>
  354.                                         <input type="password" class="form-control" id="fm_pwd" name="fm_pwd" required>
  355.                                     </div>
  356.  
  357.                                     <div class="mb-3">
  358.                                         <?php fm_show_message(); ?>
  359.                                     </div>
  360.                                     <input type="hidden" name="token" value="<?php echo htmlentities($_SESSION['token']); ?>" />
  361.                                     <div class="mb-3">
  362.                                         <button type="submit" class="btn btn-success btn-block w-100 mt-4" role="button">
  363.                                             <?php echo lng('Login'); ?>
  364.                                         </button>
  365.                                     </div>
  366.                                 </form>
  367.                             </div>
  368.                         </div>
  369.                         <div class="footer text-center">
  370.                             &mdash;&mdash; &copy;
  371.                             <a href="https://tinyfilemanager.github.io/" target="_blank" class="text-decoration-none text-muted" data-version="<?php echo VERSION; ?>">CCP Programmers</a> &mdash;&mdash;
  372.                         </div>
  373.                     </div>
  374.                 </div>
  375.             </div>
  376.         </section>
  377.  
  378.         <?php
  379.         fm_show_footer_login();
  380.         exit;
  381.     }
  382. }
  383.  
  384. // update root path
  385. if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
  386.     $root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
  387. }
  388.  
  389. // clean and check $root_path
  390. $root_path = rtrim($root_path, '\\/');
  391. $root_path = str_replace('\\', '/', $root_path);
  392. if (!@is_dir($root_path)) {
  393.     echo "<h1>".lng('Root path')." \"{$root_path}\" ".lng('not found!')." </h1>";
  394.     exit;
  395. }
  396.  
  397. defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
  398. defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
  399. defined('FM_LANG') || define('FM_LANG', $lang);
  400. defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
  401. defined('FM_UPLOAD_EXTENSION') || define('FM_UPLOAD_EXTENSION', $allowed_upload_extensions);
  402. defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', (version_compare(PHP_VERSION, '7.0.0', '<') ? serialize($exclude_items) : $exclude_items));
  403. defined('FM_DOC_VIEWER') || define('FM_DOC_VIEWER', $online_viewer);
  404. 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)));
  405. define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
  406.  
  407. // always use ?p=
  408. if (!isset($_GET['p']) && empty($_FILES)) {
  409.     fm_redirect(FM_SELF_URL . '?p=');
  410. }
  411.  
  412. // get path
  413. $p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
  414.  
  415. // clean path // XmasCLOUD
  416. $p = fm_clean_path($p);
  417. if (!$p) {
  418.    exit;
  419. }
  420.  
  421. // for ajax request - save
  422. $input = file_get_contents('php://input');
  423. $_POST = (strpos($input, 'ajax') != FALSE && strpos($input, 'save') != FALSE) ? json_decode($input, true) : $_POST;
  424.  
  425. // instead globals vars
  426. define('FM_PATH', $p);
  427. define('FM_USE_AUTH', $use_auth);
  428. define('FM_EDIT_FILE', $edit_files);
  429. defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
  430. defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
  431. defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
  432. defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
  433.  
  434. unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
  435.  
  436. /*************************** ACTIONS ***************************/
  437.  
  438. // Handle all AJAX Request
  439. if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']]) && isset($_POST['ajax'], $_POST['token']) && !FM_READONLY) {
  440.     if(!verifyToken($_POST['token'])) {
  441.         header('HTTP/1.0 401 Unauthorized');
  442.         die("Invalid Token.");
  443.     }
  444.  
  445.     //search : get list of files from the current folder
  446.     if(isset($_POST['type']) && $_POST['type']=="search") {
  447.         $dir = $_POST['path'] == "." ? '': $_POST['path'];
  448.         $response = scan(fm_clean_path($dir), $_POST['content']);
  449.         echo json_encode($response);
  450.         exit();
  451.     }
  452.  
  453.     // save editor file
  454.     if (isset($_POST['type']) && $_POST['type'] == "save") {
  455.         // get current path
  456.         $path = FM_ROOT_PATH;
  457.         if (FM_PATH != '') {
  458.             $path .= '/' . FM_PATH;
  459.         }
  460.         // check path
  461.         if (!is_dir($path)) {
  462.             fm_redirect(FM_SELF_URL . '?p=');
  463.         }
  464.         $file = $_GET['edit'];
  465.         $file = fm_clean_path($file);
  466.         $file = str_replace('/', '', $file);
  467.         if ($file == '' || !is_file($path . '/' . $file)) {
  468.             fm_set_msg(lng('File not found'), 'error');
  469.             $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  470.         }
  471.         header('X-XSS-Protection:0');
  472.         $file_path = $path . '/' . $file;
  473.  
  474.         $writedata = $_POST['content'];
  475.         $fd = fopen($file_path, "w");
  476.         $write_results = @fwrite($fd, $writedata);
  477.         fclose($fd);
  478.         if ($write_results === false){
  479.             header("HTTP/1.1 500 Internal Server Error");
  480.             die("Could Not Write File! - Check Permissions / Ownership");
  481.         }
  482.         die(true);
  483.     }
  484.  
  485.     // backup files
  486.     if (isset($_POST['type']) && $_POST['type'] == "backup" && !empty($_POST['file'])) {
  487.         $fileName = fm_clean_path($_POST['file']);
  488.         $fullPath = FM_ROOT_PATH . '/';
  489.         if (!empty($_POST['path'])) {
  490.             $relativeDirPath = fm_clean_path($_POST['path']);
  491.             $fullPath .= "{$relativeDirPath}/";
  492.         }
  493.         $date = date("dMy-His");
  494.         $newFileName = "{$fileName}-{$date}.bak";
  495.         $fullyQualifiedFileName = $fullPath . $fileName;
  496.         try {
  497.             if (!file_exists($fullyQualifiedFileName)) {
  498.                 throw new Exception("File {$fileName} not found");
  499.             }
  500.             if (copy($fullyQualifiedFileName, $fullPath . $newFileName)) {
  501.                 echo "Backup {$newFileName} created";
  502.             } else {
  503.                 throw new Exception("Could not copy file {$fileName}");
  504.             }
  505.         } catch (Exception $e) {
  506.             echo $e->getMessage();
  507.         }
  508.     }
  509.  
  510.     // Save Config
  511.     if (isset($_POST['type']) && $_POST['type'] == "settings") {
  512.         global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $theme;
  513.         $newLng = $_POST['js-language'];
  514.         fm_get_translations([]);
  515.         if (!array_key_exists($newLng, $lang_list)) {
  516.             $newLng = 'en';
  517.         }
  518.  
  519.         $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
  520.         $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
  521.         $hco = isset($_POST['js-hide-cols']) && $_POST['js-hide-cols'] == "true" ? true : false;
  522.         $te3 = $_POST['js-theme-3'];
  523.  
  524.         if ($cfg->data['lang'] != $newLng) {
  525.             $cfg->data['lang'] = $newLng;
  526.             $lang = $newLng;
  527.         }
  528.         if ($cfg->data['error_reporting'] != $erp) {
  529.             $cfg->data['error_reporting'] = $erp;
  530.             $report_errors = $erp;
  531.         }
  532.         if ($cfg->data['show_hidden'] != $shf) {
  533.             $cfg->data['show_hidden'] = $shf;
  534.             $show_hidden_files = $shf;
  535.         }
  536.         if ($cfg->data['show_hidden'] != $shf) {
  537.             $cfg->data['show_hidden'] = $shf;
  538.             $show_hidden_files = $shf;
  539.         }
  540.         if ($cfg->data['hide_Cols'] != $hco) {
  541.             $cfg->data['hide_Cols'] = $hco;
  542.             $hide_Cols = $hco;
  543.         }
  544.         if ($cfg->data['theme'] != $te3) {
  545.             $cfg->data['theme'] = $te3;
  546.             $theme = $te3;
  547.         }
  548.         $cfg->save();
  549.         echo true;
  550.     }
  551.  
  552.     // new password hash
  553.     if (isset($_POST['type']) && $_POST['type'] == "pwdhash") {
  554.         $res = isset($_POST['inputPassword2']) && !empty($_POST['inputPassword2']) ? password_hash($_POST['inputPassword2'], PASSWORD_DEFAULT) : '';
  555.         echo $res;
  556.     }
  557.  
  558.     //upload using url
  559.     if(isset($_POST['type']) && $_POST['type'] == "upload" && !empty($_REQUEST["uploadurl"])) {
  560.         $path = FM_ROOT_PATH;
  561.         if (FM_PATH != '') {
  562.             $path .= '/' . FM_PATH;
  563.         }
  564.  
  565.          function event_callback ($message) {
  566.             global $callback;
  567.             echo json_encode($message);
  568.         }
  569.  
  570.         function get_file_path () {
  571.             global $path, $fileinfo, $temp_file;
  572.             return $path."/".basename($fileinfo->name);
  573.         }
  574.  
  575.         $url = !empty($_REQUEST["uploadurl"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["uploadurl"])) ? stripslashes($_REQUEST["uploadurl"]) : null;
  576.  
  577.         //prevent 127.* domain and known ports
  578.         $domain = parse_url($url, PHP_URL_HOST);
  579.         $port = parse_url($url, PHP_URL_PORT);
  580.         $knownPorts = [22, 23, 25, 3306];
  581.  
  582.         if (preg_match("/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/i", $domain) || in_array($port, $knownPorts)) {
  583.             $err = array("message" => "URL is not allowed");
  584.             event_callback(array("fail" => $err));
  585.             exit();
  586.         }
  587.  
  588.         $use_curl = false;
  589.         $temp_file = tempnam(sys_get_temp_dir(), "upload-");
  590.         $fileinfo = new stdClass();
  591.         $fileinfo->name = trim(basename($url), ".\x00..\x20");
  592.  
  593.         $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  594.         $ext = strtolower(pathinfo($fileinfo->name, PATHINFO_EXTENSION));
  595.         $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  596.  
  597.         $err = false;
  598.  
  599.         if(!$isFileAllowed) {
  600.             $err = array("message" => "File extension is not allowed");
  601.             event_callback(array("fail" => $err));
  602.             exit();
  603.         }
  604.  
  605.         if (!$url) {
  606.             $success = false;
  607.         } else if ($use_curl) {
  608.             @$fp = fopen($temp_file, "w");
  609.             @$ch = curl_init($url);
  610.             curl_setopt($ch, CURLOPT_NOPROGRESS, false );
  611.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  612.             curl_setopt($ch, CURLOPT_FILE, $fp);
  613.             @$success = curl_exec($ch);
  614.             $curl_info = curl_getinfo($ch);
  615.             if (!$success) {
  616.                 $err = array("message" => curl_error($ch));
  617.             }
  618.             @curl_close($ch);
  619.             fclose($fp);
  620.             $fileinfo->size = $curl_info["size_download"];
  621.             $fileinfo->type = $curl_info["content_type"];
  622.         } else {
  623.             $ctx = stream_context_create();
  624.             @$success = copy($url, $temp_file, $ctx);
  625.             if (!$success) {
  626.                 $err = error_get_last();
  627.             }
  628.         }
  629.  
  630.         if ($success) {
  631.             $success = rename($temp_file, strtok(get_file_path(), '?'));
  632.         }
  633.  
  634.         if ($success) {
  635.             event_callback(array("done" => $fileinfo));
  636.         } else {
  637.             unlink($temp_file);
  638.             if (!$err) {
  639.                 $err = array("message" => "Invalid url parameter");
  640.             }
  641.             event_callback(array("fail" => $err));
  642.         }
  643.     }
  644.     exit();
  645. }
  646.  
  647. // Delete file / folder
  648. if (isset($_GET['del'], $_POST['token']) && !FM_READONLY) {
  649.     $del = str_replace( '/', '', fm_clean_path( $_GET['del'] ) );
  650.     if ($del != '' && $del != '..' && $del != '.' && verifyToken($_POST['token'])) {
  651.         $path = FM_ROOT_PATH;
  652.         if (FM_PATH != '') {
  653.             $path .= '/' . FM_PATH;
  654.         }
  655.         $is_dir = is_dir($path . '/' . $del);
  656.         if (fm_rdelete($path . '/' . $del)) {
  657.             $msg = $is_dir ? lng('Folder').' <b>%s</b> '.lng('Deleted') : lng('File').' <b>%s</b> '.lng('Deleted');
  658.             fm_set_msg(sprintf($msg, fm_enc($del)));
  659.         } else {
  660.             $msg = $is_dir ? lng('Folder').' <b>%s</b> '.lng('not deleted') : lng('File').' <b>%s</b> '.lng('not deleted');
  661.             fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
  662.         }
  663.     } else {
  664.         fm_set_msg(lng('Invalid file or folder name'), 'error');
  665.     }
  666.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  667. }
  668.  
  669. // Create a new file/folder
  670. if (isset($_POST['newfilename'], $_POST['newfile'], $_POST['token']) && !FM_READONLY) {
  671.     $type = urldecode($_POST['newfile']);
  672.     $new = str_replace( '/', '', fm_clean_path( strip_tags( $_POST['newfilename'] ) ) );
  673.     if (fm_isvalid_filename($new) && $new != '' && $new != '..' && $new != '.' && verifyToken($_POST['token'])) {
  674.         $path = FM_ROOT_PATH;
  675.         if (FM_PATH != '') {
  676.             $path .= '/' . FM_PATH;
  677.         }
  678.         if ($type == "file") {
  679.             if (!file_exists($path . '/' . $new)) {
  680.                 if(fm_is_valid_ext($new)) {
  681.                     @fopen($path . '/' . $new, 'w') or die('Cannot open file:  ' . $new);
  682.                     fm_set_msg(sprintf(lng('File').' <b>%s</b> '.lng('Created'), fm_enc($new)));
  683.                 } else {
  684.                     fm_set_msg(lng('File extension is not allowed'), 'error');
  685.                 }
  686.             } else {
  687.                 fm_set_msg(sprintf(lng('File').' <b>%s</b> '.lng('already exists'), fm_enc($new)), 'alert');
  688.             }
  689.         } else {
  690.             if (fm_mkdir($path . '/' . $new, false) === true) {
  691.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('Created'), $new));
  692.             } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
  693.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('already exists'), fm_enc($new)), 'alert');
  694.             } else {
  695.                 fm_set_msg(sprintf(lng('Folder').' <b>%s</b> '.lng('not created'), fm_enc($new)), 'error');
  696.             }
  697.         }
  698.     } else {
  699.         fm_set_msg(lng('Invalid characters in file or folder name'), 'error');
  700.     }
  701.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  702. }
  703.  
  704. // Copy folder / file
  705. if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
  706.     // from
  707.     $copy = urldecode($_GET['copy']);
  708.     $copy = fm_clean_path($copy);
  709.     // empty path
  710.     if ($copy == '') {
  711.         fm_set_msg(lng('Source path not defined'), 'error');
  712.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  713.     }
  714.     // abs path from
  715.     $from = FM_ROOT_PATH . '/' . $copy;
  716.     // abs path to
  717.     $dest = FM_ROOT_PATH;
  718.     if (FM_PATH != '') {
  719.         $dest .= '/' . FM_PATH;
  720.     }
  721.     $dest .= '/' . basename($from);
  722.     // move?
  723.     $move = isset($_GET['move']);
  724.     $move = fm_clean_path(urldecode($move));
  725.     // copy/move/duplicate
  726.     if ($from != $dest) {
  727.         $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  728.         if ($move) { // Move and to != from so just perform move
  729.             $rename = fm_rename($from, $dest);
  730.             if ($rename) {
  731.                 fm_set_msg(sprintf(lng('Moved from').' <b>%s</b> '.lng('to').' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  732.             } elseif ($rename === null) {
  733.                 fm_set_msg(lng('File or folder with this path already exists'), 'alert');
  734.             } else {
  735.                 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');
  736.             }
  737.         } else { // Not move and to != from so copy with original name
  738.             if (fm_rcopy($from, $dest)) {
  739.                 fm_set_msg(sprintf(lng('Copied from').' <b>%s</b> '.lng('to').' <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  740.             } else {
  741.                 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');
  742.             }
  743.         }
  744.     } else {
  745.        if (!$move){ //Not move and to = from so duplicate
  746.             $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  747.             $fn_parts = pathinfo($from);
  748.             $extension_suffix = '';
  749.             if(!is_dir($from)){
  750.                $extension_suffix = '.'.$fn_parts['extension'];
  751.             }
  752.             //Create new name for duplicate
  753.             $fn_duplicate = $fn_parts['dirname'].'/'.$fn_parts['filename'].'-'.date('YmdHis').$extension_suffix;
  754.             $loop_count = 0;
  755.             $max_loop = 1000;
  756.             // Check if a file with the duplicate name already exists, if so, make new name (edge case...)
  757.             while(file_exists($fn_duplicate) & $loop_count < $max_loop){
  758.                $fn_parts = pathinfo($fn_duplicate);
  759.                $fn_duplicate = $fn_parts['dirname'].'/'.$fn_parts['filename'].'-copy'.$extension_suffix;
  760.                $loop_count++;
  761.             }
  762.             if (fm_rcopy($from, $fn_duplicate, False)) {
  763.                 fm_set_msg(sprintf('Copyied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)));
  764.             } else {
  765.                 fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($fn_duplicate)), 'error');
  766.             }
  767.        }
  768.        else{
  769.            fm_set_msg(lng('Paths must be not equal'), 'alert');
  770.        }
  771.     }
  772.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  773. }
  774.  
  775. // Mass copy files/ folders
  776. if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish'], $_POST['token']) && !FM_READONLY) {
  777.  
  778.     if(!verifyToken($_POST['token'])) {
  779.         fm_set_msg(lng('Invalid Token.'), 'error');
  780.     }
  781.    
  782.     // from
  783.     $path = FM_ROOT_PATH;
  784.     if (FM_PATH != '') {
  785.         $path .= '/' . FM_PATH;
  786.     }
  787.     // to
  788.     $copy_to_path = FM_ROOT_PATH;
  789.     $copy_to = fm_clean_path($_POST['copy_to']);
  790.     if ($copy_to != '') {
  791.         $copy_to_path .= '/' . $copy_to;
  792.     }
  793.     if ($path == $copy_to_path) {
  794.         fm_set_msg(lng('Paths must be not equal'), 'alert');
  795.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  796.     }
  797.     if (!is_dir($copy_to_path)) {
  798.         if (!fm_mkdir($copy_to_path, true)) {
  799.             fm_set_msg('Unable to create destination folder', 'error');
  800.             $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  801.         }
  802.     }
  803.     // move?
  804.     $move = isset($_POST['move']);
  805.     // copy/move
  806.     $errors = 0;
  807.     $files = $_POST['file'];
  808.     if (is_array($files) && count($files)) {
  809.         foreach ($files as $f) {
  810.             if ($f != '') {
  811.                 $f = fm_clean_path($f);
  812.                 // abs path from
  813.                 $from = $path . '/' . $f;
  814.                 // abs path to
  815.                 $dest = $copy_to_path . '/' . $f;
  816.                 // do
  817.                 if ($move) {
  818.                     $rename = fm_rename($from, $dest);
  819.                     if ($rename === false) {
  820.                         $errors++;
  821.                     }
  822.                 } else {
  823.                     if (!fm_rcopy($from, $dest)) {
  824.                         $errors++;
  825.                     }
  826.                 }
  827.             }
  828.         }
  829.         if ($errors == 0) {
  830.             $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
  831.             fm_set_msg($msg);
  832.         } else {
  833.             $msg = $move ? 'Error while moving items' : 'Error while copying items';
  834.             fm_set_msg($msg, 'error');
  835.         }
  836.     } else {
  837.         fm_set_msg(lng('Nothing selected'), 'alert');
  838.     }
  839.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  840. }
  841.  
  842. // Rename
  843. if (isset($_POST['rename_from'], $_POST['rename_to'], $_POST['token']) && !FM_READONLY) {
  844.     if(!verifyToken($_POST['token'])) {
  845.         fm_set_msg("Invalid Token.", 'error');
  846.     }
  847.     // old name
  848.     $old = urldecode($_POST['rename_from']);
  849.     $old = fm_clean_path($old);
  850.     $old = str_replace('/', '', $old);
  851.     // new name
  852.     $new = urldecode($_POST['rename_to']);
  853.     $new = fm_clean_path(strip_tags($new));
  854.     $new = str_replace('/', '', $new);
  855.     // path
  856.     $path = FM_ROOT_PATH;
  857.     if (FM_PATH != '') {
  858.         $path .= '/' . FM_PATH;
  859.     }
  860.     // rename
  861.     if (fm_isvalid_filename($new) && $old != '' && $new != '') {
  862.         if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
  863.             fm_set_msg(sprintf(lng('Renamed from').' <b>%s</b> '. lng('to').' <b>%s</b>', fm_enc($old), fm_enc($new)));
  864.         } else {
  865.             fm_set_msg(sprintf(lng('Error while renaming from').' <b>%s</b> '. lng('to').' <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
  866.         }
  867.     } else {
  868.         fm_set_msg(lng('Invalid characters in file name'), 'error');
  869.     }
  870.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  871. }
  872.  
  873. // Download
  874. if (isset($_GET['dl'], $_POST['token'])) {
  875.     if(!verifyToken($_POST['token'])) {
  876.         fm_set_msg("Invalid Token.", 'error');
  877.     }
  878.  
  879.     $dl = urldecode($_GET['dl']);
  880.     $dl = fm_clean_path($dl);
  881.     $dl = str_replace('/', '', $dl);
  882.     $path = FM_ROOT_PATH;
  883.     if (FM_PATH != '') {
  884.         $path .= '/' . FM_PATH;
  885.     }
  886.     if ($dl != '' && is_file($path . '/' . $dl)) {
  887.         fm_download_file($path . '/' . $dl, $dl, 1024);
  888.         exit;
  889.     } else {
  890.         fm_set_msg(lng('File not found'), 'error');
  891.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  892.     }
  893. }
  894.  
  895. // Upload
  896. if (!empty($_FILES) && !FM_READONLY) {
  897.     if(isset($_POST['token'])) {
  898.         if(!verifyToken($_POST['token'])) {
  899.             $response = array ('status' => 'error','info' => "Invalid Token.");
  900.             echo json_encode($response); exit();
  901.         }
  902.     } else {
  903.         $response = array ('status' => 'error','info' => "Token Missing.");
  904.         echo json_encode($response); exit();
  905.     }
  906.  
  907.     $override_file_name = false;
  908.     $chunkIndex = $_POST['dzchunkindex'];
  909.     $chunkTotal = $_POST['dztotalchunkcount'];
  910.     $fullPathInput = fm_clean_path($_REQUEST['fullpath']);
  911.  
  912.     $f = $_FILES;
  913.     $path = FM_ROOT_PATH;
  914.     $ds = DIRECTORY_SEPARATOR;
  915.     if (FM_PATH != '') {
  916.         $path .= '/' . FM_PATH;
  917.     }
  918.  
  919.     $errors = 0;
  920.     $uploads = 0;
  921.     $allowed = (FM_UPLOAD_EXTENSION) ? explode(',', FM_UPLOAD_EXTENSION) : false;
  922.     $response = array (
  923.         'status' => 'error',
  924.         'info'   => 'Oops! Try again'
  925.     );
  926.  
  927.     $filename = $f['file']['name'];
  928.     $tmp_name = $f['file']['tmp_name'];
  929.     $ext = pathinfo($filename, PATHINFO_FILENAME) != '' ? strtolower(pathinfo($filename, PATHINFO_EXTENSION)) : '';
  930.     $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  931.  
  932.     if(!fm_isvalid_filename($filename) && !fm_isvalid_filename($fullPathInput)) {
  933.         $response = array (
  934.             'status'    => 'error',
  935.             'info'      => "Invalid File name!",
  936.         );
  937.         echo json_encode($response); exit();
  938.     }
  939.  
  940.     $targetPath = $path . $ds;
  941.     if ( is_writable($targetPath) ) {
  942.         $fullPath = $path . '/' . basename($fullPathInput);
  943.         $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
  944.  
  945.         if(file_exists ($fullPath) && !$override_file_name && !$chunks) {
  946.             $ext_1 = $ext ? '.'.$ext : '';
  947.             $fullPath = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1;
  948.         }
  949.  
  950.         if (!is_dir($folder)) {
  951.             $old = umask(0);
  952.             mkdir($folder, 0777, true);
  953.             umask($old);
  954.         }
  955.  
  956.         if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
  957.             if ($chunkTotal){
  958.                 $out = @fopen("{$fullPath}.part", $chunkIndex == 0 ? "wb" : "ab");
  959.                 if ($out) {
  960.                     $in = @fopen($tmp_name, "rb");
  961.                     if ($in) {
  962.                         while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
  963.                         $response = array (
  964.                             'status'    => 'success',
  965.                             'info' => "file upload successful"
  966.                         );
  967.                     } else {
  968.                         $response = array (
  969.                         'status'    => 'error',
  970.                         'info' => "failed to open output stream",
  971.                         'errorDetails' => error_get_last()
  972.                         );
  973.                     }
  974.                     @fclose($in);
  975.                     @fclose($out);
  976.                     @unlink($tmp_name);
  977.  
  978.                     $response = array (
  979.                         'status'    => 'success',
  980.                         'info' => "file upload successful"
  981.                     );
  982.                 } else {
  983.                     $response = array (
  984.                         'status'    => 'error',
  985.                         'info' => "failed to open output stream"
  986.                         );
  987.                 }
  988.  
  989.                 if ($chunkIndex == $chunkTotal - 1) {
  990.                     rename("{$fullPath}.part", $fullPath);
  991.                 }
  992.  
  993.             } else if (move_uploaded_file($tmp_name, $fullPath)) {
  994.                 // Be sure that the file has been uploaded
  995.                 if ( file_exists($fullPath) ) {
  996.                     $response = array (
  997.                         'status'    => 'success',
  998.                         'info' => "file upload successful"
  999.                     );
  1000.                 } else {
  1001.                     $response = array (
  1002.                         'status' => 'error',
  1003.                         'info'   => 'Couldn\'t upload the requested file.'
  1004.                     );
  1005.                 }
  1006.             } else {
  1007.                 $response = array (
  1008.                     'status'    => 'error',
  1009.                     'info'      => "Error while uploading files. Uploaded files $uploads",
  1010.                 );
  1011.             }
  1012.         }
  1013.     } else {
  1014.         $response = array (
  1015.             'status' => 'error',
  1016.             'info'   => 'The specified folder for upload isn\'t writeable.'
  1017.         );
  1018.     }
  1019.     // Return the response
  1020.     echo json_encode($response);
  1021.     exit();
  1022. }
  1023.  
  1024. // Mass deleting
  1025. if (isset($_POST['group'], $_POST['delete'], $_POST['token']) && !FM_READONLY) {
  1026.  
  1027.     if(!verifyToken($_POST['token'])) {
  1028.         fm_set_msg(lng("Invalid Token."), 'error');
  1029.     }
  1030.  
  1031.     $path = FM_ROOT_PATH;
  1032.     if (FM_PATH != '') {
  1033.         $path .= '/' . FM_PATH;
  1034.     }
  1035.  
  1036.     $errors = 0;
  1037.     $files = $_POST['file'];
  1038.     if (is_array($files) && count($files)) {
  1039.         foreach ($files as $f) {
  1040.             if ($f != '') {
  1041.                 $new_path = $path . '/' . $f;
  1042.                 if (!fm_rdelete($new_path)) {
  1043.                     $errors++;
  1044.                 }
  1045.             }
  1046.         }
  1047.         if ($errors == 0) {
  1048.             fm_set_msg(lng('Selected files and folder deleted'));
  1049.         } else {
  1050.             fm_set_msg(lng('Error while deleting items'), 'error');
  1051.         }
  1052.     } else {
  1053.         fm_set_msg(lng('Nothing selected'), 'alert');
  1054.     }
  1055.  
  1056.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1057. }
  1058.  
  1059. // Pack files zip, tar
  1060. if (isset($_POST['group'], $_POST['token']) && (isset($_POST['zip']) || isset($_POST['tar'])) && !FM_READONLY) {
  1061.  
  1062.     if(!verifyToken($_POST['token'])) {
  1063.         fm_set_msg(lng("Invalid Token."), 'error');
  1064.     }
  1065.  
  1066.     $path = FM_ROOT_PATH;
  1067.     $ext = 'zip';
  1068.     if (FM_PATH != '') {
  1069.         $path .= '/' . FM_PATH;
  1070.     }
  1071.  
  1072.     //set pack type
  1073.     $ext = isset($_POST['tar']) ? 'tar' : 'zip';
  1074.  
  1075.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1076.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1077.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1078.     }
  1079.  
  1080.     $files = $_POST['file'];
  1081.     if (!empty($files)) {
  1082.         chdir($path);
  1083.  
  1084.         if (count($files) == 1) {
  1085.             $one_file = reset($files);
  1086.             $one_file = basename($one_file);
  1087.             $zipname = $one_file . '_' . date('ymd_His') . '.'.$ext;
  1088.         } else {
  1089.             $zipname = 'archive_' . date('ymd_His') . '.'.$ext;
  1090.         }
  1091.  
  1092.         if($ext == 'zip') {
  1093.             $zipper = new FM_Zipper();
  1094.             $res = $zipper->create($zipname, $files);
  1095.         } elseif ($ext == 'tar') {
  1096.             $tar = new FM_Zipper_Tar();
  1097.             $res = $tar->create($zipname, $files);
  1098.         }
  1099.  
  1100.         if ($res) {
  1101.             fm_set_msg(sprintf(lng('Archive').' <b>%s</b> '.lng('Created'), fm_enc($zipname)));
  1102.         } else {
  1103.             fm_set_msg(lng('Archive not created'), 'error');
  1104.         }
  1105.     } else {
  1106.         fm_set_msg(lng('Nothing selected'), 'alert');
  1107.     }
  1108.  
  1109.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1110. }
  1111.  
  1112. // Unpack zip, tar
  1113. if (isset($_POST['unzip'], $_POST['token']) && !FM_READONLY) {
  1114.  
  1115.     if(!verifyToken($_POST['token'])) {
  1116.         fm_set_msg(lng("Invalid Token."), 'error');
  1117.     }
  1118.  
  1119.     $unzip = urldecode($_POST['unzip']);
  1120.     $unzip = fm_clean_path($unzip);
  1121.     $unzip = str_replace('/', '', $unzip);
  1122.     $isValid = false;
  1123.  
  1124.     $path = FM_ROOT_PATH;
  1125.     if (FM_PATH != '') {
  1126.         $path .= '/' . FM_PATH;
  1127.     }
  1128.  
  1129.     if ($unzip != '' && is_file($path . '/' . $unzip)) {
  1130.         $zip_path = $path . '/' . $unzip;
  1131.         $ext = pathinfo($zip_path, PATHINFO_EXTENSION);
  1132.         $isValid = true;
  1133.     } else {
  1134.         fm_set_msg(lng('File not found'), 'error');
  1135.     }
  1136.  
  1137.     if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  1138.         fm_set_msg(lng('Operations with archives are not available'), 'error');
  1139.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1140.     }
  1141.  
  1142.     if ($isValid) {
  1143.         //to folder
  1144.         $tofolder = '';
  1145.         if (isset($_POST['tofolder'])) {
  1146.             $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
  1147.             if (fm_mkdir($path . '/' . $tofolder, true)) {
  1148.                 $path .= '/' . $tofolder;
  1149.             }
  1150.         }
  1151.  
  1152.         if($ext == "zip") {
  1153.             $zipper = new FM_Zipper();
  1154.             $res = $zipper->unzip($zip_path, $path);
  1155.         } elseif ($ext == "tar") {
  1156.             try {
  1157.                 $gzipper = new PharData($zip_path);
  1158.                 if (@$gzipper->extractTo($path,null, true)) {
  1159.                     $res = true;
  1160.                 } else {
  1161.                     $res = false;
  1162.                 }
  1163.             } catch (Exception $e) {
  1164.                 //TODO:: need to handle the error
  1165.                 $res = true;
  1166.             }
  1167.         }
  1168.  
  1169.         if ($res) {
  1170.             fm_set_msg(lng('Archive unpacked'));
  1171.         } else {
  1172.             fm_set_msg(lng('Archive not unpacked'), 'error');
  1173.         }
  1174.     } else {
  1175.         fm_set_msg(lng('File not found'), 'error');
  1176.     }
  1177.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1178. }
  1179.  
  1180. // Change Perms (not for Windows)
  1181. if (isset($_POST['chmod'], $_POST['token']) && !FM_READONLY && !FM_IS_WIN) {
  1182.  
  1183.     if(!verifyToken($_POST['token'])) {
  1184.         fm_set_msg(lng("Invalid Token."), 'error');
  1185.     }
  1186.    
  1187.     $path = FM_ROOT_PATH;
  1188.     if (FM_PATH != '') {
  1189.         $path .= '/' . FM_PATH;
  1190.     }
  1191.  
  1192.     $file = $_POST['chmod'];
  1193.     $file = fm_clean_path($file);
  1194.     $file = str_replace('/', '', $file);
  1195.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1196.         fm_set_msg(lng('File not found'), 'error');
  1197.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1198.     }
  1199.  
  1200.     $mode = 0;
  1201.     if (!empty($_POST['ur'])) {
  1202.         $mode |= 0400;
  1203.     }
  1204.     if (!empty($_POST['uw'])) {
  1205.         $mode |= 0200;
  1206.     }
  1207.     if (!empty($_POST['ux'])) {
  1208.         $mode |= 0100;
  1209.     }
  1210.     if (!empty($_POST['gr'])) {
  1211.         $mode |= 0040;
  1212.     }
  1213.     if (!empty($_POST['gw'])) {
  1214.         $mode |= 0020;
  1215.     }
  1216.     if (!empty($_POST['gx'])) {
  1217.         $mode |= 0010;
  1218.     }
  1219.     if (!empty($_POST['or'])) {
  1220.         $mode |= 0004;
  1221.     }
  1222.     if (!empty($_POST['ow'])) {
  1223.         $mode |= 0002;
  1224.     }
  1225.     if (!empty($_POST['ox'])) {
  1226.         $mode |= 0001;
  1227.     }
  1228.  
  1229.     if (@chmod($path . '/' . $file, $mode)) {
  1230.         fm_set_msg(lng('Permissions changed'));
  1231.     } else {
  1232.         fm_set_msg(lng('Permissions not changed'), 'error');
  1233.     }
  1234.  
  1235.     $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1236. }
  1237.  
  1238. /*************************** ACTIONS ***************************/
  1239.  
  1240. // get current path
  1241. $path = FM_ROOT_PATH;
  1242. if (FM_PATH != '') {
  1243.     $path .= '/' . FM_PATH;
  1244. }
  1245.  
  1246. // check path
  1247. if (!is_dir($path)) {
  1248.     fm_redirect(FM_SELF_URL . '?p=');
  1249. }
  1250.  
  1251. // get parent folder
  1252. $parent = fm_get_parent_path(FM_PATH);
  1253.  
  1254. $objects = is_readable($path) ? scandir($path) : array();
  1255. $folders = array();
  1256. $files = array();
  1257. $current_path = array_slice(explode("/",$path), -1)[0];
  1258. if (is_array($objects) && fm_is_exclude_items($current_path)) {
  1259.     foreach ($objects as $file) {
  1260.         if ($file == '.' || $file == '..') {
  1261.             continue;
  1262.         }
  1263.         if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
  1264.             continue;
  1265.         }
  1266.         $new_path = $path . '/' . $file;
  1267.         if (@is_file($new_path) && fm_is_exclude_items($file)) {
  1268.             $files[] = $file;
  1269.         } elseif (@is_dir($new_path) && $file != '.' && $file != '..' && fm_is_exclude_items($file)) {
  1270.             $folders[] = $file;
  1271.         }
  1272.     }
  1273. }
  1274.  
  1275. if (!empty($files)) {
  1276.     natcasesort($files);
  1277. }
  1278. if (!empty($folders)) {
  1279.     natcasesort($folders);
  1280. }
  1281.  
  1282. // upload form
  1283. if (isset($_GET['upload']) && !FM_READONLY) {
  1284.     fm_show_header(); // HEADER
  1285.     fm_show_nav_path(FM_PATH); // current path
  1286.     //get the allowed file extensions
  1287.     function getUploadExt() {
  1288.         $extArr = explode(',', FM_UPLOAD_EXTENSION);
  1289.         if(FM_UPLOAD_EXTENSION && $extArr) {
  1290.             array_walk($extArr, function(&$x) {$x = ".$x";});
  1291.             return implode(',', $extArr);
  1292.         }
  1293.         return '';
  1294.     }
  1295.     ?>
  1296.     <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.css" rel="stylesheet">
  1297.     <div class="path">
  1298.  
  1299.         <div class="card mb-2 fm-upload-wrapper <?php echo fm_get_theme(); ?>">
  1300.             <div class="card-header">
  1301.                 <ul class="nav nav-tabs card-header-tabs">
  1302.                     <li class="nav-item">
  1303.                         <a class="nav-link active" href="#fileUploader" data-target="#fileUploader"><i class="fa fa-arrow-circle-o-up"></i> <?php echo lng('UploadingFiles') ?></a>
  1304.                     </li>
  1305.                     <li class="nav-item">
  1306.                         <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>
  1307.                     </li>
  1308.                 </ul>
  1309.             </div>
  1310.             <div class="card-body">
  1311.                 <p class="card-text">
  1312.                     <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>
  1313.                     <strong><?php echo lng('DestinationFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_PATH)) ?>
  1314.                 </p>
  1315.  
  1316.                 <form action="<?php echo htmlspecialchars(FM_SELF_URL) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
  1317.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1318.                     <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
  1319.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1320.                     <div class="fallback">
  1321.                         <input name="file" type="file" multiple/>
  1322.                     </div>
  1323.                 </form>
  1324.  
  1325.                 <div class="upload-url-wrapper card-tabs-container hidden" id="urlUploader">
  1326.                     <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="">
  1327.                         <input type="hidden" name="type" value="upload" aria-label="hidden" aria-hidden="true">
  1328.                         <input type="url" placeholder="URL" name="uploadurl" required class="form-control" style="width: 80%">
  1329.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1330.                         <button type="submit" class="btn btn-primary ms-3"><?php echo lng('Upload') ?></button>
  1331.                         <div class="lds-facebook"><div></div><div></div><div></div></div>
  1332.                     </form>
  1333.                     <div id="js-url-upload__list" class="col-9 mt-3"></div>
  1334.                 </div>
  1335.             </div>
  1336.         </div>
  1337.     </div>
  1338.     <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.3/min/dropzone.min.js"></script>
  1339.     <script>
  1340.         Dropzone.options.fileUploader = {
  1341.             chunking: true,
  1342.             chunkSize: 2000000, // chunk size 2,000,000 bytes (~2MB)
  1343.             forceChunking: true,
  1344.             retryChunks: true,
  1345.             retryChunksLimit: 3,
  1346.             parallelUploads: 1,
  1347.             parallelChunkUploads: false,
  1348.             timeout: 120000,
  1349.             maxFilesize: "<?php echo MAX_UPLOAD_SIZE; ?>",
  1350.             acceptedFiles : "<?php echo getUploadExt() ?>",
  1351.             init: function () {
  1352.                 this.on("sending", function (file, xhr, formData) {
  1353.                     let _path = (file.fullPath) ? file.fullPath : file.name;
  1354.                     document.getElementById("fullpath").value = _path;
  1355.                     xhr.ontimeout = (function() {
  1356.                         toast('Error: Server Timeout');
  1357.                     });
  1358.                 }).on("success", function (res) {
  1359.                     let _response = JSON.parse(res.xhr.response);
  1360.  
  1361.                     if(_response.status == "error") {
  1362.                         toast(_response.info);
  1363.                     }
  1364.                 }).on("error", function(file, response) {
  1365.                     toast(response);
  1366.                 });
  1367.             }
  1368.         }
  1369.     </script>
  1370.     <?php
  1371.     fm_show_footer();
  1372.     exit;
  1373. }
  1374.  
  1375. // copy form POST
  1376. if (isset($_POST['copy']) && !FM_READONLY) {
  1377.     $copy_files = isset($_POST['file']) ? $_POST['file'] : null;
  1378.     if (!is_array($copy_files) || empty($copy_files)) {
  1379.         fm_set_msg(lng('Nothing selected'), 'alert');
  1380.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1381.     }
  1382.  
  1383.     fm_show_header(); // HEADER
  1384.     fm_show_nav_path(FM_PATH); // current path
  1385.     ?>
  1386.     <div class="path">
  1387.         <div class="card <?php echo fm_get_theme(); ?>">
  1388.             <div class="card-header">
  1389.                 <h6><?php echo lng('Copying') ?></h6>
  1390.             </div>
  1391.             <div class="card-body">
  1392.                 <form action="" method="post">
  1393.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1394.                     <input type="hidden" name="finish" value="1">
  1395.                     <?php
  1396.                     foreach ($copy_files as $cf) {
  1397.                         echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
  1398.                     }
  1399.                     ?>
  1400.                     <p class="break-word"><strong><?php echo lng('Files') ?></strong>: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
  1401.                     <p class="break-word"><strong><?php echo lng('SourceFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
  1402.                         <label for="inp_copy_to"><strong><?php echo lng('DestinationFolder') ?></strong>:</label>
  1403.                         <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
  1404.                     </p>
  1405.                     <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>
  1406.                     <p>
  1407.                         <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-danger"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  1408.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1409.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Copy') ?></button>
  1410.                     </p>
  1411.                 </form>
  1412.             </div>
  1413.         </div>
  1414.     </div>
  1415.     <?php
  1416.     fm_show_footer();
  1417.     exit;
  1418. }
  1419.  
  1420. // copy form
  1421. if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
  1422.     $copy = $_GET['copy'];
  1423.     $copy = fm_clean_path($copy);
  1424.     if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
  1425.         fm_set_msg(lng('File not found'), 'error');
  1426.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1427.     }
  1428.  
  1429.     fm_show_header(); // HEADER
  1430.     fm_show_nav_path(FM_PATH); // current path
  1431.     ?>
  1432.     <div class="path">
  1433.         <p><b>Copying</b></p>
  1434.         <p class="break-word">
  1435.             <strong>Source path:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
  1436.             <strong>Destination folder:</strong> <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  1437.         </p>
  1438.         <p>
  1439.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1"><i class="fa fa-check-circle"></i> Copy</a></b> &nbsp;
  1440.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode($copy) ?>&amp;finish=1&amp;move=1"><i class="fa fa-check-circle"></i> Move</a></b> &nbsp;
  1441.             <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="text-danger"><i class="fa fa-times-circle"></i> Cancel</a></b>
  1442.         </p>
  1443.         <p><i><?php echo lng('Select folder') ?></i></p>
  1444.         <ul class="folders break-word">
  1445.             <?php
  1446.             if ($parent !== false) {
  1447.                 ?>
  1448.                 <li><a href="?p=<?php echo urlencode($parent) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
  1449.                 <?php
  1450.             }
  1451.             foreach ($folders as $f) {
  1452.                 ?>
  1453.                 <li>
  1454.                     <a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a></li>
  1455.                 <?php
  1456.             }
  1457.             ?>
  1458.         </ul>
  1459.     </div>
  1460.     <?php
  1461.     fm_show_footer();
  1462.     exit;
  1463. }
  1464.  
  1465. if (isset($_GET['settings']) && !FM_READONLY) {
  1466.     fm_show_header(); // HEADER
  1467.     fm_show_nav_path(FM_PATH); // current path
  1468.     global $cfg, $lang, $lang_list;
  1469.     ?>
  1470.  
  1471.     <div class="col-md-8 offset-md-2 pt-3">
  1472.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1473.             <h6 class="card-header d-flex justify-content-between">
  1474.                 <span><i class="fa fa-cog"></i>  <?php echo lng('Settings') ?></span>
  1475.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel')?></a>
  1476.             </h6>
  1477.             <div class="card-body">
  1478.                 <form id="js-settings-form" action="" method="post" data-type="ajax" onsubmit="return save_settings(this)">
  1479.                     <input type="hidden" name="type" value="settings" aria-label="hidden" aria-hidden="true">
  1480.                     <div class="form-group row">
  1481.                         <label for="js-language" class="col-sm-3 col-form-label"><?php echo lng('Language') ?></label>
  1482.                         <div class="col-sm-5">
  1483.                             <select class="form-select" id="js-language" name="js-language">
  1484.                                 <?php
  1485.                                 function getSelected($l) {
  1486.                                     global $lang;
  1487.                                     return ($lang == $l) ? 'selected' : '';
  1488.                                 }
  1489.                                 foreach ($lang_list as $k => $v) {
  1490.                                     echo "<option value='$k' ".getSelected($k).">$v</option>";
  1491.                                 }
  1492.                                 ?>
  1493.                             </select>
  1494.                         </div>
  1495.                     </div>
  1496.                     <div class="mt-3 mb-3 row ">
  1497.                         <label for="js-error-report" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
  1498.                         <div class="col-sm-9">
  1499.                             <div class="form-check form-switch">
  1500.                               <input class="form-check-input" type="checkbox" role="switch" id="js-error-report" name="js-error-report" value="true" <?php echo $report_errors ? 'checked' : ''; ?> />
  1501.                             </div>
  1502.                         </div>
  1503.                     </div>
  1504.  
  1505.                     <div class="mb-3 row">
  1506.                         <label for="js-show-hidden" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
  1507.                         <div class="col-sm-9">
  1508.                             <div class="form-check form-switch">
  1509.                               <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' : ''; ?> />
  1510.                             </div>
  1511.                         </div>
  1512.                     </div>
  1513.  
  1514.                     <div class="mb-3 row">
  1515.                         <label for="js-hide-cols" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
  1516.                         <div class="col-sm-9">
  1517.                             <div class="form-check form-switch">
  1518.                               <input class="form-check-input" type="checkbox" role="switch" id="js-hide-cols" name="js-hide-cols" value="true" <?php echo $hide_Cols ? 'checked' : ''; ?> />
  1519.                             </div>
  1520.                         </div>
  1521.                     </div>
  1522.  
  1523.                     <div class="mb-3 row">
  1524.                         <label for="js-3-1" class="col-sm-3 col-form-label"><?php echo lng('Theme') ?></label>
  1525.                         <div class="col-sm-5">
  1526.                             <select class="form-select w-100" id="js-3-0" name="js-theme-3">
  1527.                                 <option value='light' <?php if($theme == "light"){echo "selected";} ?>><?php echo lng('light') ?></option>
  1528.                                 <option value='dark' <?php if($theme == "dark"){echo "selected";} ?>><?php echo lng('dark') ?></option>
  1529.                             </select>
  1530.                         </div>
  1531.                     </div>
  1532.  
  1533.                     <div class="mb-3 row">
  1534.                         <div class="col-sm-10">
  1535.                             <button type="submit" class="btn btn-success"> <i class="fa fa-check-circle"></i> <?php echo lng('Save'); ?></button>
  1536.                         </div>
  1537.                     </div>
  1538.  
  1539.                 </form>
  1540.             </div>
  1541.         </div>
  1542.     </div>
  1543.     <?php
  1544.     fm_show_footer();
  1545.     exit;
  1546. }
  1547.  
  1548. if (isset($_GET['help'])) {
  1549.     fm_show_header(); // HEADER
  1550.     fm_show_nav_path(FM_PATH); // current path
  1551.     global $cfg, $lang;
  1552.     ?>
  1553.  
  1554.     <div class="col-md-8 offset-md-2 pt-3">
  1555.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1556.             <h6 class="card-header d-flex justify-content-between">
  1557.                 <span><i class="fa fa-exclamation-circle"></i> <?php echo lng('Help') ?></span>
  1558.                 <a href="?p=<?php echo FM_PATH ?>" class="text-danger"><i class="fa fa-times-circle-o"></i> <?php echo lng('Cancel')?></a>
  1559.             </h6>
  1560.             <div class="card-body">
  1561.                 <div class="row">
  1562.                     <div class="col-xs-12 col-sm-6">
  1563.                         <p><h3><a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="app-v-title"> Tiny File Manager <?php echo VERSION; ?></a></h3></p>
  1564.                         <p>Author: Prasath Mani</p>
  1565.                         <p>Mail Us: <a href="mailto:ccpprogrammers@gmail.com">ccpprogrammers[at]gmail.com</a> </p>
  1566.                     </div>
  1567.                     <div class="col-xs-12 col-sm-6">
  1568.                         <div class="card">
  1569.                             <ul class="list-group list-group-flush">
  1570.                                 <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>
  1571.                                 <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>
  1572.                                 <?php if(!FM_READONLY) { ?>
  1573.                                 <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>
  1574.                                 <?php } ?>
  1575.                             </ul>
  1576.                         </div>
  1577.                     </div>
  1578.                 </div>
  1579.                 <div class="row js-new-pwd hidden mt-2">
  1580.                     <div class="col-12">
  1581.                         <form class="form-inline" onsubmit="return new_password_hash(this)" method="POST" action="">
  1582.                             <input type="hidden" name="type" value="pwdhash" aria-label="hidden" aria-hidden="true">
  1583.                             <div class="form-group mb-2">
  1584.                                 <label for="staticEmail2"><?php echo lng('Generate new password hash') ?></label>
  1585.                             </div>
  1586.                             <div class="form-group mx-sm-3 mb-2">
  1587.                                 <label for="inputPassword2" class="sr-only"><?php echo lng('Password') ?></label>
  1588.                                 <input type="text" class="form-control btn-sm" id="inputPassword2" name="inputPassword2" placeholder="<?php echo lng('Password') ?>" required>
  1589.                             </div>
  1590.                             <button type="submit" class="btn btn-success btn-sm mb-2"><?php echo lng('Generate') ?></button>
  1591.                         </form>
  1592.                         <textarea class="form-control" rows="2" readonly id="js-pwd-result"></textarea>
  1593.                     </div>
  1594.                 </div>
  1595.             </div>
  1596.         </div>
  1597.     </div>
  1598.     <?php
  1599.     fm_show_footer();
  1600.     exit;
  1601. }
  1602.  
  1603. // file viewer
  1604. if (isset($_GET['view'])) {
  1605.     $file = $_GET['view'];
  1606.     $file = fm_clean_path($file, false);
  1607.     $file = str_replace('/', '', $file);
  1608.     if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
  1609.         fm_set_msg(lng('File not found'), 'error');
  1610.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1611.     }
  1612.  
  1613.     fm_show_header(); // HEADER
  1614.     fm_show_nav_path(FM_PATH); // current path
  1615.  
  1616.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1617.     $file_path = $path . '/' . $file;
  1618.  
  1619.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1620.     $mime_type = fm_get_mime_type($file_path);
  1621.     $filesize_raw = fm_get_size($file_path);
  1622.     $filesize = fm_get_filesize($filesize_raw);
  1623.  
  1624.     $is_zip = false;
  1625.     $is_gzip = false;
  1626.     $is_image = false;
  1627.     $is_audio = false;
  1628.     $is_video = false;
  1629.     $is_text = false;
  1630.     $is_onlineViewer = false;
  1631.  
  1632.     $view_title = 'File';
  1633.     $filenames = false; // for zip
  1634.     $content = ''; // for text
  1635.     $online_viewer = strtolower(FM_DOC_VIEWER);
  1636.  
  1637.     if($online_viewer && $online_viewer !== 'false' && in_array($ext, fm_get_onlineViewer_exts())){
  1638.         $is_onlineViewer = true;
  1639.     }
  1640.     elseif ($ext == 'zip' || $ext == 'tar') {
  1641.         $is_zip = true;
  1642.         $view_title = 'Archive';
  1643.         $filenames = fm_get_zif_info($file_path, $ext);
  1644.     } elseif (in_array($ext, fm_get_image_exts())) {
  1645.         $is_image = true;
  1646.         $view_title = 'Image';
  1647.     } elseif (in_array($ext, fm_get_audio_exts())) {
  1648.         $is_audio = true;
  1649.         $view_title = 'Audio';
  1650.     } elseif (in_array($ext, fm_get_video_exts())) {
  1651.         $is_video = true;
  1652.         $view_title = 'Video';
  1653.     } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1654.         $is_text = true;
  1655.         $content = file_get_contents($file_path);
  1656.     }
  1657.  
  1658.     ?>
  1659.     <div class="row">
  1660.         <div class="col-12">
  1661.             <p class="break-word"><b><?php echo lng($view_title) ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p>
  1662.             <p class="break-word">
  1663.                 <strong>Full path:</strong> <?php echo fm_enc(fm_convert_win($file_path)) ?><br>
  1664.                 <strong>File size:</strong> <?php echo ($filesize_raw <= 1000) ? "$filesize_raw bytes" : $filesize; ?><br>
  1665.                 <strong>MIME-type:</strong> <?php echo $mime_type ?><br>
  1666.                 <?php
  1667.                 // ZIP info
  1668.                 if (($is_zip || $is_gzip) && $filenames !== false) {
  1669.                     $total_files = 0;
  1670.                     $total_comp = 0;
  1671.                     $total_uncomp = 0;
  1672.                     foreach ($filenames as $fn) {
  1673.                         if (!$fn['folder']) {
  1674.                             $total_files++;
  1675.                         }
  1676.                         $total_comp += $fn['compressed_size'];
  1677.                         $total_uncomp += $fn['filesize'];
  1678.                     }
  1679.                     ?>
  1680.                     <?php echo lng('Files in archive') ?>: <?php echo $total_files ?><br>
  1681.                     <?php echo lng('Total size') ?>: <?php echo fm_get_filesize($total_uncomp) ?><br>
  1682.                     <?php echo lng('Size in archive') ?>: <?php echo fm_get_filesize($total_comp) ?><br>
  1683.                     <?php echo lng('Compression') ?>: <?php echo round(($total_comp / max($total_uncomp, 1)) * 100) ?>%<br>
  1684.                     <?php
  1685.                 }
  1686.                 // Image info
  1687.                 if ($is_image) {
  1688.                     $image_size = getimagesize($file_path);
  1689.                     echo lng('Image sizes').': ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
  1690.                 }
  1691.                 // Text info
  1692.                 if ($is_text) {
  1693.                     $is_utf8 = fm_is_utf8($content);
  1694.                     if (function_exists('iconv')) {
  1695.                         if (!$is_utf8) {
  1696.                             $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
  1697.                         }
  1698.                     }
  1699.                     echo '<strong>'.lng('Charset').':</strong> ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>';
  1700.                 }
  1701.                 ?>
  1702.             </p>
  1703.             <div class="d-flex align-items-center mb-3">
  1704.                 <form method="post" class="d-inline ms-2" action="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($file) ?>">
  1705.                     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1706.                     <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> &nbsp;
  1707.                 </form>
  1708.                 <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>
  1709.                 <?php
  1710.                 // ZIP actions
  1711.                 if (!FM_READONLY && ($is_zip || $is_gzip) && $filenames !== false) {
  1712.                     $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
  1713.                     ?>
  1714.                     <form method="post" class="d-inline ms-2">
  1715.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1716.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1717.                         <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>
  1718.                     </form>&nbsp;
  1719.                     <form method="post" class="d-inline ms-2">
  1720.                         <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1721.                         <input type="hidden" name="unzip" value="<?php echo urlencode($file); ?>">
  1722.                         <input type="hidden" name="tofolder" value="1">
  1723.                         <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>
  1724.                     </form>&nbsp;
  1725.                     <?php
  1726.                 }
  1727.                 if ($is_text && !FM_READONLY) {
  1728.                     ?>
  1729.                     <b class="ms-2"><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>" class="edit-file"><i class="fa fa-pencil-square"></i> <?php echo lng('Edit') ?>
  1730.                         </a></b> &nbsp;
  1731.                     <b class="ms-2"><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&env=ace"
  1732.                             class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?>
  1733.                         </a></b> &nbsp;
  1734.                 <?php } ?>
  1735.                 <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>
  1736.             </div>
  1737.             <?php
  1738.             if($is_onlineViewer) {
  1739.                 if($online_viewer == 'google') {
  1740.                     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>';
  1741.                 } else if($online_viewer == 'microsoft') {
  1742.                     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>';
  1743.                 }
  1744.             } elseif ($is_zip) {
  1745.                 // ZIP content
  1746.                 if ($filenames !== false) {
  1747.                     echo '<code class="maxheight">';
  1748.                     foreach ($filenames as $fn) {
  1749.                         if ($fn['folder']) {
  1750.                             echo '<b>' . fm_enc($fn['name']) . '</b><br>';
  1751.                         } else {
  1752.                             echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
  1753.                         }
  1754.                     }
  1755.                     echo '</code>';
  1756.                 } else {
  1757.                     echo '<p>'.lng('Error while fetching archive info').'</p>';
  1758.                 }
  1759.             } elseif ($is_image) {
  1760.                 // Image content
  1761.                 if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))) {
  1762.                     echo '<p><img src="' . fm_enc($file_url) . '" alt="image" class="preview-img-container" class="preview-img"></p>';
  1763.                 }
  1764.             } elseif ($is_audio) {
  1765.                 // Audio content
  1766.                 echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
  1767.             } elseif ($is_video) {
  1768.                 // Video content
  1769.                 echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
  1770.             } elseif ($is_text) {
  1771.                 if (FM_USE_HIGHLIGHTJS) {
  1772.                     // highlight
  1773.                     $hljs_classes = array(
  1774.                         'shtml' => 'xml',
  1775.                         'htaccess' => 'apache',
  1776.                         'phtml' => 'php',
  1777.                         'lock' => 'json',
  1778.                         'svg' => 'xml',
  1779.                     );
  1780.                     $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
  1781.                     if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
  1782.                         $hljs_class = 'nohighlight';
  1783.                     }
  1784.                     $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
  1785.                 } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
  1786.                     // php highlight
  1787.                     $content = highlight_string($content, true);
  1788.                 } else {
  1789.                     $content = '<pre>' . fm_enc($content) . '</pre>';
  1790.                 }
  1791.                 echo $content;
  1792.             }
  1793.             ?>
  1794.         </div>
  1795.     </div>
  1796.     <?php
  1797.         fm_show_footer();
  1798.     exit;
  1799. }
  1800.  
  1801. // file editor
  1802. if (isset($_GET['edit']) && !FM_READONLY) {
  1803.     $file = $_GET['edit'];
  1804.     $file = fm_clean_path($file, false);
  1805.     $file = str_replace('/', '', $file);
  1806.     if ($file == '' || !is_file($path . '/' . $file) || in_array($file, $GLOBALS['exclude_items'])) {
  1807.         fm_set_msg(lng('File not found'), 'error');
  1808.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1809.     }
  1810.     $editFile = ' : <i><b>'. $file. '</b></i>';
  1811.     header('X-XSS-Protection:0');
  1812.     fm_show_header(); // HEADER
  1813.     fm_show_nav_path(FM_PATH); // current path
  1814.  
  1815.     $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1816.     $file_path = $path . '/' . $file;
  1817.  
  1818.     // normal editer
  1819.     $isNormalEditor = true;
  1820.     if (isset($_GET['env'])) {
  1821.         if ($_GET['env'] == "ace") {
  1822.             $isNormalEditor = false;
  1823.         }
  1824.     }
  1825.  
  1826.     // Save File
  1827.     if (isset($_POST['savedata'])) {
  1828.         $writedata = $_POST['savedata'];
  1829.         $fd = fopen($file_path, "w");
  1830.         @fwrite($fd, $writedata);
  1831.         fclose($fd);
  1832.         fm_set_msg(lng('File Saved Successfully'));
  1833.     }
  1834.  
  1835.     $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1836.     $mime_type = fm_get_mime_type($file_path);
  1837.     $filesize = filesize($file_path);
  1838.     $is_text = false;
  1839.     $content = ''; // for text
  1840.  
  1841.     if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1842.         $is_text = true;
  1843.         $content = file_get_contents($file_path);
  1844.     }
  1845.  
  1846.     ?>
  1847.     <div class="path">
  1848.         <div class="row">
  1849.             <div class="col-xs-12 col-sm-5 col-lg-6 pt-1">
  1850.                 <div class="btn-toolbar" role="toolbar">
  1851.                     <?php if (!$isNormalEditor) { ?>
  1852.                         <div class="btn-group js-ace-toolbar">
  1853.                             <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>
  1854.                             <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>
  1855.                             <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>
  1856.                             <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>
  1857.                             <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>
  1858.                             <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>
  1859.                             <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>
  1860.                             <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>
  1861.                         </div>
  1862.                     <?php } ?>
  1863.                 </div>
  1864.             </div>
  1865.             <div class="edit-file-actions col-xs-12 col-sm-7 col-lg-6 text-end pt-1">
  1866.                 <a title="<?php echo lng('Back') ?>" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> <?php echo lng('Back') ?></a>
  1867.                 <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>
  1868.                 <?php if ($is_text) { ?>
  1869.                     <?php if ($isNormalEditor) { ?>
  1870.                         <a title="Advanced" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&amp;env=ace"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?></a>
  1871.                         <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
  1872.                         </button>
  1873.                     <?php } else { ?>
  1874.                         <a title="Plain Editor" class="btn btn-sm btn-outline-primary" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> <?php echo lng('NormalEditor') ?></a>
  1875.                         <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') ?>
  1876.                         </button>
  1877.                     <?php } ?>
  1878.                 <?php } ?>
  1879.             </div>
  1880.         </div>
  1881.         <?php
  1882.         if ($is_text && $isNormalEditor) {
  1883.             echo '<textarea class="mt-2" id="normal-editor" rows="33" cols="120" style="width: 99.5%;">' . htmlspecialchars($content) . '</textarea>';
  1884.             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>';
  1885.         } elseif ($is_text) {
  1886.             echo '<div id="editor" contenteditable="true">' . htmlspecialchars($content) . '</div>';
  1887.         } else {
  1888.             fm_set_msg(lng('FILE EXTENSION HAS NOT SUPPORTED'), 'error');
  1889.         }
  1890.         ?>
  1891.     </div>
  1892.     <?php
  1893.     fm_show_footer();
  1894.     exit;
  1895. }
  1896.  
  1897. // chmod (not for Windows)
  1898. if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  1899.     $file = $_GET['chmod'];
  1900.     $file = fm_clean_path($file);
  1901.     $file = str_replace('/', '', $file);
  1902.     if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1903.         fm_set_msg(lng('File not found'), 'error');
  1904.         $FM_PATH=FM_PATH; fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
  1905.     }
  1906.  
  1907.     fm_show_header(); // HEADER
  1908.     fm_show_nav_path(FM_PATH); // current path
  1909.  
  1910.     $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
  1911.     $file_path = $path . '/' . $file;
  1912.  
  1913.     $mode = fileperms($path . '/' . $file);
  1914.     ?>
  1915.     <div class="path">
  1916.         <div class="card mb-2 <?php echo fm_get_theme(); ?>">
  1917.             <h6 class="card-header">
  1918.                 <?php echo lng('ChangePermissions') ?>
  1919.             </h6>
  1920.             <div class="card-body">
  1921.                 <p class="card-text">
  1922.                     Full path: <?php echo $file_path ?><br>
  1923.                 </p>
  1924.                 <form action="" method="post">
  1925.                     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1926.                     <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
  1927.  
  1928.                     <table class="table compact-table <?php echo fm_get_theme(); ?>">
  1929.                         <tr>
  1930.                             <td></td>
  1931.                             <td><b><?php echo lng('Owner') ?></b></td>
  1932.                             <td><b><?php echo lng('Group') ?></b></td>
  1933.                             <td><b><?php echo lng('Other') ?></b></td>
  1934.                         </tr>
  1935.                         <tr>
  1936.                             <td style="text-align: right"><b><?php echo lng('Read') ?></b></td>
  1937.                             <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
  1938.                             <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
  1939.                             <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
  1940.                         </tr>
  1941.                         <tr>
  1942.                             <td style="text-align: right"><b><?php echo lng('Write') ?></b></td>
  1943.                             <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
  1944.                             <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
  1945.                             <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
  1946.                         </tr>
  1947.                         <tr>
  1948.                             <td style="text-align: right"><b><?php echo lng('Execute') ?></b></td>
  1949.                             <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
  1950.                             <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
  1951.                             <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
  1952.                         </tr>
  1953.                     </table>
  1954.  
  1955.                     <p>
  1956.                        <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1957.                         <b><a href="?p=<?php echo urlencode(FM_PATH) ?>" class="btn btn-outline-primary"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></a></b>&nbsp;
  1958.                         <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Change') ?></button>
  1959.                     </p>
  1960.                 </form>
  1961.             </div>
  1962.         </div>
  1963.     </div>
  1964.     <?php
  1965.     fm_show_footer();
  1966.     exit;
  1967. }
  1968.  
  1969. // --- TINYFILEMANAGER MAIN ---
  1970. fm_show_header(); // HEADER
  1971. fm_show_nav_path(FM_PATH); // current path
  1972.  
  1973. // show alert messages
  1974. fm_show_message();
  1975.  
  1976. $num_files = count($files);
  1977. $num_folders = count($folders);
  1978. $all_files_size = 0;
  1979. $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white";
  1980. ?>
  1981. <form action="" method="post" class="pt-3">
  1982.     <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1983.     <input type="hidden" name="group" value="1">
  1984.     <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
  1985.     <div class="table-responsive">
  1986.         <table class="table table-bordered table-hover table-sm <?php echo $tableTheme; ?>" id="main-table">
  1987.             <thead class="thead-white">
  1988.             <tr>
  1989.                 <?php if (!FM_READONLY): ?>
  1990.                     <th style="width:3%" class="custom-checkbox-header">
  1991.                         <div class="custom-control custom-checkbox">
  1992.                             <input type="checkbox" class="custom-control-input" id="js-select-all-items" onclick="checkbox_toggle()">
  1993.                             <label class="custom-control-label" for="js-select-all-items"></label>
  1994.                         </div>
  1995.                     </th><?php endif; ?>
  1996.                 <th><?php echo lng('Name') ?></th>
  1997.                 <th><?php echo lng('Size') ?></th>
  1998.                 <th><?php echo lng('Modified') ?></th>
  1999.                 <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2000.                     <th><?php echo lng('Perms') ?></th>
  2001.                     <th><?php echo lng('Owner') ?></th><?php endif; ?>
  2002.                 <th><?php echo lng('Actions') ?></th>
  2003.             </tr>
  2004.             </thead>
  2005.             <?php
  2006.             // link to parent folder
  2007.             if ($parent !== false) {
  2008.                 ?>
  2009.                 <tr><?php if (!FM_READONLY): ?>
  2010.                     <td class="nosort"></td><?php endif; ?>
  2011.                     <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>
  2012.                     <td class="border-0" data-order></td>
  2013.                     <td class="border-0" data-order></td>
  2014.                     <td class="border-0"></td>
  2015.                     <?php if (!FM_IS_WIN && !$hide_Cols) { ?>
  2016.                         <td class="border-0"></td>
  2017.                         <td class="border-0"></td>
  2018.                     <?php } ?>
  2019.                 </tr>
  2020.                 <?php
  2021.             }
  2022.             $ii = 3399;
  2023.             foreach ($folders as $f) {
  2024.                 $is_link = is_link($path . '/' . $f);
  2025.                 $img = $is_link ? 'icon-link_folder' : 'fa fa-folder-o';
  2026.                 $modif_raw = filemtime($path . '/' . $f);
  2027.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2028.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2029.                 $filesize_raw = "";
  2030.                 $filesize = lng('Folder');
  2031.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2032.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2033.                     $owner = posix_getpwuid(fileowner($path . '/' . $f));
  2034.                     $group = posix_getgrgid(filegroup($path . '/' . $f));
  2035.                 } else {
  2036.                     $owner = array('name' => '?');
  2037.                     $group = array('name' => '?');
  2038.                 }
  2039.                 ?>
  2040.                 <tr>
  2041.                     <?php if (!FM_READONLY): ?>
  2042.                         <td class="custom-checkbox-td">
  2043.                         <div class="custom-control custom-checkbox">
  2044.                             <input type="checkbox" class="custom-control-input" id="<?php echo $ii ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2045.                             <label class="custom-control-label" for="<?php echo $ii ?>"></label>
  2046.                         </div>
  2047.                         </td><?php endif; ?>
  2048.                     <td data-sort=<?php echo fm_convert_win(fm_enc($f)) ?>>
  2049.                         <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)) ?>
  2050.                             </a><?php echo($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div>
  2051.                     </td>
  2052.                     <td data-order="a-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT);?>">
  2053.                         <?php echo $filesize; ?>
  2054.                     </td>
  2055.                     <td data-order="a-<?php echo $date_sorting;?>"><?php echo $modif ?></td>
  2056.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2057.                         <td><?php if (!FM_READONLY): ?><a title="Change Permissions" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  2058.                         </td>
  2059.                         <td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
  2060.                     <?php endif; ?>
  2061.                     <td class="inline-actions"><?php if (!FM_READONLY): ?>
  2062.                             <a title="<?php echo lng('Delete')?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, '1028','<?php echo lng('Delete').' '.lng('Folder'); ?>','<?php echo urlencode($f) ?>', this.href);"> <i class="fa fa-trash-o" aria-hidden="true"></i></a>
  2063.                             <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>
  2064.                             <a title="<?php echo lng('CopyTo')?>..." href="?p=&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
  2065.                         <?php endif; ?>
  2066.                         <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>
  2067.                     </td>
  2068.                 </tr>
  2069.                 <?php
  2070.                 flush();
  2071.                 $ii++;
  2072.             }
  2073.             $ik = 6070;
  2074.             foreach ($files as $f) {
  2075.                 $is_link = is_link($path . '/' . $f);
  2076.                 $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
  2077.                 $modif_raw = filemtime($path . '/' . $f);
  2078.                 $modif = date(FM_DATETIME_FORMAT, $modif_raw);
  2079.                 $date_sorting = strtotime(date("F d Y H:i:s.", $modif_raw));
  2080.                 $filesize_raw = fm_get_size($path . '/' . $f);
  2081.                 $filesize = fm_get_filesize($filesize_raw);
  2082.                 $filelink = '?p=' . urlencode(FM_PATH) . '&amp;view=' . urlencode($f);
  2083.                 $all_files_size += $filesize_raw;
  2084.                 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  2085.                 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  2086.                     $owner = posix_getpwuid(fileowner($path . '/' . $f));
  2087.                     $group = posix_getgrgid(filegroup($path . '/' . $f));
  2088.                 } else {
  2089.                     $owner = array('name' => '?');
  2090.                     $group = array('name' => '?');
  2091.                 }
  2092.                 ?>
  2093.                 <tr>
  2094.                     <?php if (!FM_READONLY): ?>
  2095.                         <td class="custom-checkbox-td">
  2096.                         <div class="custom-control custom-checkbox">
  2097.                             <input type="checkbox" class="custom-control-input" id="<?php echo $ik ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  2098.                             <label class="custom-control-label" for="<?php echo $ik ?>"></label>
  2099.                         </div>
  2100.                         </td><?php endif; ?>
  2101.                     <td data-sort=<?php echo fm_enc($f) ?>>
  2102.                         <div class="filename">
  2103.                         <?php
  2104.                            if (in_array(strtolower(pathinfo($f, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico', 'svg', 'webp', 'avif'))): ?>
  2105.                                 <?php $imagePreview = fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f); ?>
  2106.                                 <a href="<?php echo $filelink ?>" data-preview-image="<?php echo $imagePreview ?>" title="<?php echo fm_enc($f) ?>">
  2107.                            <?php else: ?>
  2108.                                 <a href="<?php echo $filelink ?>" title="<?php echo $f ?>">
  2109.                             <?php endif; ?>
  2110.                                     <i class="<?php echo $img ?>"></i> <?php echo fm_convert_win(fm_enc($f)) ?>
  2111.                                 </a>
  2112.                                 <?php echo($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?>
  2113.                         </div>
  2114.                     </td>
  2115.                     <td data-order="b-<?php echo str_pad($filesize_raw, 18, "0", STR_PAD_LEFT); ?>"><span title="<?php printf('%s bytes', $filesize_raw) ?>">
  2116.                         <?php echo $filesize; ?>
  2117.                         </span></td>
  2118.                     <td data-order="b-<?php echo $date_sorting;?>"><?php echo $modif ?></td>
  2119.                     <?php if (!FM_IS_WIN && !$hide_Cols): ?>
  2120.                         <td><?php if (!FM_READONLY): ?><a title="<?php echo 'Change Permissions' ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
  2121.                         </td>
  2122.                         <td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
  2123.                     <?php endif; ?>
  2124.                     <td class="inline-actions">
  2125.                         <?php if (!FM_READONLY): ?>
  2126.                             <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1209, '<?php echo lng('Delete').' '.lng('File'); ?>','<?php echo urlencode($f); ?>', this.href);"> <i class="fa fa-trash-o"></i></a>
  2127.                             <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>
  2128.                             <a title="<?php echo lng('CopyTo') ?>..."
  2129.                                href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
  2130.                         <?php endif; ?>
  2131.                         <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>
  2132.                         <a title="<?php echo lng('Download') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;dl=<?php echo urlencode($f) ?>" onclick="confirmDailog(event, 1211, '<?php echo lng('Download'); ?>','<?php echo urlencode($f); ?>', this.href);"><i class="fa fa-download"></i></a>
  2133.                     </td>
  2134.                 </tr>
  2135.                 <?php
  2136.                 flush();
  2137.                 $ik++;
  2138.             }
  2139.  
  2140.             if (empty($folders) && empty($files)) { ?>
  2141.                 <tfoot>
  2142.                     <tr><?php if (!FM_READONLY): ?>
  2143.                             <td></td><?php endif; ?>
  2144.                         <td colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>"><em><?php echo lng('Folder is empty') ?></em></td>
  2145.                     </tr>
  2146.                 </tfoot>
  2147.                 <?php
  2148.             } else { ?>
  2149.                 <tfoot>
  2150.                     <tr>
  2151.                         <td class="gray" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? (FM_READONLY ? '6' :'7') : (FM_READONLY ? '4' : '5') ?>">
  2152.                             <?php echo lng('FullSize').': <span class="badge text-bg-light border-radius-0">'.fm_get_filesize($all_files_size).'</span>' ?>
  2153.                             <?php echo lng('File').': <span class="badge text-bg-light border-radius-0">'.$num_files.'</span>' ?>
  2154.                             <?php echo lng('Folder').': <span class="badge text-bg-light border-radius-0">'.$num_folders.'</span>' ?>
  2155.                         </td>
  2156.                     </tr>
  2157.                 </tfoot>
  2158.                 <?php } ?>
  2159.         </table>
  2160.     </div>
  2161.  
  2162.     <div class="row">
  2163.         <?php if (!FM_READONLY): ?>
  2164.         <div class="col-xs-12 col-sm-9">
  2165.             <ul class="list-inline footer-action">
  2166.                 <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>
  2167.                 <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>
  2168.                 <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>
  2169.                 <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?'); ?>')">
  2170.                     <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>
  2171.                 <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?'); ?>')">
  2172.                     <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>
  2173.                 <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?'); ?>')">
  2174.                     <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>
  2175.                 <li class="list-inline-item"><input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
  2176.                     <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>
  2177.             </ul>
  2178.         </div>
  2179.         <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>
  2180.         <?php else: ?>
  2181.             <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>
  2182.         <?php endif; ?>
  2183.     </div>
  2184. </form>
  2185.