Guest User

Untitled

a guest
Mar 27th, 2019
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 139.74 KB | None | 0 0
  1. <?php
  2. //Default Configuration
  3. $CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false}';
  4.  
  5. /**
  6. * H3K | Tiny File Manager V2.3.3
  7. * CCP Programmers | ccpprogrammers@gmail.com
  8. * https://tinyfilemanager.github.io
  9. */
  10.  
  11. //TFM version
  12. define('VERSION', '2.3.3');
  13.  
  14. // Auth with login/password (set true/false to enable/disable it)
  15. $use_auth = true;
  16.  
  17. // Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
  18. // Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
  19. $auth_users = array(
  20. 'admin' => '$2y$10$/K.hjNr84lLNDt8fTXjoI.DBp6PpeyoJ.mGwrrLuCZfAwfSAGqhOW', //admin@123
  21. 'user' => '$2y$10$Fg6Dz8oH9fPoZ2jJan5tZuv6Z4Kp7avtQ9bDfrdRntXtPeiMAZyGO' //12345
  22. );
  23.  
  24. // Readonly users (username array)
  25. $readonly_users = array(
  26. 'user'
  27. );
  28.  
  29. // user specific directories
  30. // array('Username' => 'Directory path', 'Username2' => 'Directory path', ...)
  31. $directories_users = array();
  32.  
  33. // Enable highlight.js (https://highlightjs.org/) on view's page
  34. $use_highlightjs = true;
  35.  
  36. // highlight.js style
  37. $highlightjs_style = 'vs';
  38.  
  39. // Enable ace.js (https://ace.c9.io/) on view's page
  40. $edit_files = true;
  41.  
  42. // Default timezone for date() and time() - http://php.net/manual/en/timezones.php
  43. $default_timezone = 'Etc/UTC'; // UTC
  44.  
  45. // Root path for file manager
  46. $root_path = $_SERVER['DOCUMENT_ROOT'];
  47.  
  48. // Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
  49. // Will not working if $root_path will be outside of server document root
  50. $root_url = '';
  51.  
  52. // Server hostname. Can set manually if wrong
  53. $http_host = $_SERVER['HTTP_HOST'];
  54.  
  55. // input encoding for iconv
  56. $iconv_input_encoding = 'UTF-8';
  57.  
  58. // date() format for file modification date
  59. $datetime_format = 'd.m.y H:i';
  60.  
  61. // allowed file extensions for upload and rename
  62. $allowed_extensions = ''; // 'gif,png,jpg'
  63.  
  64. // Array of files and folders excluded from listing
  65. $GLOBALS['exclude_items'] = array();
  66.  
  67. // Google Docs Viewer
  68. $GLOBALS['online_viewer'] = true;
  69.  
  70. //Sticky Nav bar
  71. $sticky_navbar = true;
  72.  
  73. //max upload file size
  74. define('MAX_UPLOAD_SIZE', '2048');
  75.  
  76. // private key and session name to store to the session
  77. if ( !defined( 'FM_SESSION_ID')) {
  78. define('FM_SESSION_ID', 'filemanager');
  79. }
  80.  
  81. //Configuration
  82. $cfg = new FM_Config();
  83.  
  84. // Default language
  85. $lang = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
  86.  
  87. // Show or hide files and folders that starts with a dot
  88. $show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
  89.  
  90. // PHP error reporting - false = Turns off Errors, true = Turns on Errors
  91. $report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
  92.  
  93. //available languages
  94. $lang_list = array(
  95. 'en' => 'English'
  96. );
  97.  
  98. //--- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL
  99.  
  100. if ($report_errors == true) {
  101. @ini_set('error_reporting', E_ALL);
  102. @ini_set('display_errors', 1);
  103. } else {
  104. @ini_set('error_reporting', E_ALL);
  105. @ini_set('display_errors', 0);
  106. }
  107.  
  108. // Set Cookie
  109. setcookie('fm_cache', true, 2147483647, "/");
  110.  
  111. // if fm included
  112. if (defined('FM_EMBED')) {
  113. $use_auth = false;
  114. $sticky_navbar = false;
  115. } else {
  116. @set_time_limit(600);
  117.  
  118. date_default_timezone_set($default_timezone);
  119.  
  120. ini_set('default_charset', 'UTF-8');
  121. if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
  122. mb_internal_encoding('UTF-8');
  123. }
  124. if (function_exists('mb_regex_encoding')) {
  125. mb_regex_encoding('UTF-8');
  126. }
  127.  
  128. session_cache_limiter('');
  129. session_name(FM_SESSION_ID );
  130. @session_start();
  131. }
  132.  
  133. if (empty($auth_users)) {
  134. $use_auth = false;
  135. }
  136.  
  137. $is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
  138. || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
  139.  
  140. // update $root_url based on user specific directories
  141. if (isset($_SESSION[FM_SESSION_ID]['logged']) && !empty($directories_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  142. $wd = fm_clean_path(dirname($_SERVER['PHP_SELF']));
  143. $root_url = $root_url.$wd.DIRECTORY_SEPARATOR.$directories_users[$_SESSION[FM_SESSION_ID]['logged']];
  144. }
  145. // clean $root_url
  146. $root_url = fm_clean_path($root_url);
  147.  
  148. // abs path for site
  149. defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
  150. defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
  151.  
  152. // logout
  153. if (isset($_GET['logout'])) {
  154. unset($_SESSION[FM_SESSION_ID]['logged']);
  155. fm_redirect(FM_SELF_URL);
  156. }
  157.  
  158. // Show image here
  159. if (isset($_GET['img'])) {
  160. fm_show_image($_GET['img']);
  161. }
  162.  
  163. // Auth
  164. if ($use_auth) {
  165. if (isset($_SESSION[FM_SESSION_ID]['logged'], $auth_users[$_SESSION[FM_SESSION_ID]['logged']])) {
  166. // Logged
  167. } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'])) {
  168. // Logging In
  169. sleep(1);
  170. if(function_exists('password_verify')) {
  171. if (isset($auth_users[$_POST['fm_usr']]) && isset($_POST['fm_pwd']) && password_verify($_POST['fm_pwd'], $auth_users[$_POST['fm_usr']])) {
  172. $_SESSION[FM_SESSION_ID]['logged'] = $_POST['fm_usr'];
  173. fm_set_msg('You are logged in');
  174. fm_redirect(FM_SELF_URL . '?p=');
  175. } else {
  176. unset($_SESSION[FM_SESSION_ID]['logged']);
  177. fm_set_msg('Login failed. Invalid username or password', 'error');
  178. fm_redirect(FM_SELF_URL);
  179. }
  180. } else {
  181. fm_set_msg('password_hash not supported, Upgrade PHP version', 'error');;
  182. }
  183. } else {
  184. // Form
  185. unset($_SESSION[FM_SESSION_ID]['logged']);
  186. fm_show_header_login();
  187. fm_show_message();
  188. ?>
  189. <section class="h-100">
  190. <div class="container h-100">
  191. <div class="row justify-content-md-center h-100">
  192. <div class="card-wrapper">
  193. <div class="brand">
  194. <svg version="1.0" xmlns="http://www.w3.org/2000/svg" M1008 width="100%" height="121px" viewBox="0 0 238.000000 140.000000" aria-label="H3K Tiny File Manager">
  195. <g transform="translate(0.000000,140.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none">
  196. <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"/>
  197. <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"/>
  198. <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>
  199. </svg>
  200. </div>
  201. <div class="text-center">
  202. <h1 class="card-title"><?php echo lng('AppName'); ?></h1>
  203. </div>
  204. <div class="card fat">
  205. <div class="card-body">
  206. <form class="form-signin" action="" method="post" autocomplete="off">
  207. <div class="form-group">
  208. <label for="fm_usr"><?php echo lng('Username'); ?></label>
  209. <input type="text" class="form-control" id="fm_usr" name="fm_usr" required autofocus>
  210. </div>
  211.  
  212. <div class="form-group">
  213. <label for="fm_pwd"><?php echo lng('Password'); ?></label>
  214. <input type="password" class="form-control" id="fm_pwd" name="fm_pwd" required>
  215. </div>
  216.  
  217. <div class="form-group">
  218. <div class="custom-checkbox custom-control">
  219. <input type="checkbox" name="remember" id="remember" class="custom-control-input">
  220. <label for="remember" class="custom-control-label"><?php echo lng('RememberMe'); ?></label>
  221. </div>
  222. </div>
  223.  
  224. <div class="form-group">
  225. <button type="submit" class="btn btn-success btn-block" role="button">
  226. <?php echo lng('Login'); ?>
  227. </button>
  228. </div>
  229. </form>
  230. </div>
  231. </div>
  232. <div class="footer text-center">
  233. &mdash;&mdash; &copy;
  234. <?php if(!isset($_COOKIE['fm_cache'])) { ?> <img src="https://logs-01.loggly.com/inputs/d8bad570-def7-44d4-922c-a8680d936ae6.gif?s=1" /> <?php } ?>
  235. <a href="https://tinyfilemanager.github.io/" target="_blank" class="text-muted" data-version="<?php echo VERSION; ?>">CCP Programmers</a> &mdash;&mdash;
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. </section>
  241.  
  242. <?php
  243. fm_show_footer_login();
  244. exit;
  245. }
  246. }
  247.  
  248. // update root path
  249. if ($use_auth && isset($_SESSION[FM_SESSION_ID]['logged'])) {
  250. $root_path = isset($directories_users[$_SESSION[FM_SESSION_ID]['logged']]) ? $directories_users[$_SESSION[FM_SESSION_ID]['logged']] : $root_path;
  251. }
  252.  
  253. // clean and check $root_path
  254. $root_path = rtrim($root_path, '\\/');
  255. $root_path = str_replace('\\', '/', $root_path);
  256. if (!@is_dir($root_path)) {
  257. echo "<h1>Root path \"{$root_path}\" not found!</h1>";
  258. exit;
  259. }
  260.  
  261. defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
  262. defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
  263. defined('FM_LANG') || define('FM_LANG', $lang);
  264. defined('FM_EXTENSION') || define('FM_EXTENSION', $allowed_extensions);
  265. define('FM_READONLY', $use_auth && !empty($readonly_users) && isset($_SESSION[FM_SESSION_ID]['logged']) && in_array($_SESSION[FM_SESSION_ID]['logged'], $readonly_users));
  266. define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
  267.  
  268. // always use ?p=
  269. if (!isset($_GET['p']) && empty($_FILES)) {
  270. fm_redirect(FM_SELF_URL . '?p=');
  271. }
  272.  
  273. // get path
  274. $p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
  275.  
  276. // clean path
  277. $p = fm_clean_path($p);
  278.  
  279. // instead globals vars
  280. define('FM_PATH', $p);
  281. define('FM_USE_AUTH', $use_auth);
  282. define('FM_EDIT_FILE', $edit_files);
  283. defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
  284. defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
  285. defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
  286. defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
  287.  
  288. unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
  289.  
  290. /*************************** ACTIONS ***************************/
  291.  
  292. // AJAX Request
  293. if (isset($_POST['ajax']) && !FM_READONLY) {
  294.  
  295. // backup files
  296. if (isset($_POST['type']) && $_POST['type'] == "backup") {
  297. $file = $_POST['file'];
  298. $path = $_POST['path'];
  299. $date = date("dMy-His");
  300. $newFile = $file . '-' . $date . '.bak';
  301. copy($path . '/' . $file, $path . '/' . $newFile) or die("Unable to backup");
  302. echo "Backup $newFile Created";
  303. }
  304.  
  305. // Save Config
  306. if (isset($_POST['type']) && $_POST['type'] == "settings") {
  307. global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list;
  308. $newLng = $_POST['js-language'];
  309. fm_get_translations([]);
  310. if (!array_key_exists($newLng, $lang_list)) {
  311. $newLng = 'en';
  312. }
  313.  
  314. $erp = isset($_POST['js-error-report']) && $_POST['js-error-report'] == "true" ? true : false;
  315. $shf = isset($_POST['js-show-hidden']) && $_POST['js-show-hidden'] == "true" ? true : false;
  316.  
  317. if ($cfg->data['lang'] != $newLng) {
  318. $cfg->data['lang'] = $newLng;
  319. $lang = $newLng;
  320. }
  321. if ($cfg->data['error_reporting'] != $erp) {
  322. $cfg->data['error_reporting'] = $erp;
  323. $report_errors = $erp;
  324. }
  325. if ($cfg->data['show_hidden'] != $shf) {
  326. $cfg->data['show_hidden'] = $shf;
  327. $show_hidden_files = $shf;
  328. }
  329. $cfg->save();
  330. echo true;
  331. }
  332.  
  333. // new password hash
  334. if (isset($_POST['type']) && $_POST['type'] == "pwdhash") {
  335. $res = isset($_POST['inputPassword2']) && !empty($_POST['inputPassword2']) ? password_hash($_POST['inputPassword2'], PASSWORD_DEFAULT) : '';
  336. echo $res;
  337. }
  338.  
  339. //upload using url
  340. if(isset($_POST['type']) && $_POST['type'] == "upload" && !empty($_REQUEST["uploadurl"])) {
  341. $path = FM_ROOT_PATH;
  342. if (FM_PATH != '') {
  343. $path .= '/' . FM_PATH;
  344. }
  345.  
  346. $url = !empty($_REQUEST["uploadurl"]) && preg_match("|^http(s)?://.+$|", stripslashes($_REQUEST["uploadurl"])) ? stripslashes($_REQUEST["uploadurl"]) : null;
  347. $use_curl = false;
  348. $temp_file = tempnam(sys_get_temp_dir(), "upload-");
  349. $fileinfo = new stdClass();
  350. $fileinfo->name = trim(basename($url), ".\x00..\x20");
  351.  
  352. function event_callback ($message) {
  353. global $callback;
  354. echo json_encode($message);
  355. }
  356.  
  357. function get_file_path () {
  358. global $path, $fileinfo, $temp_file;
  359. return $path."/".basename($fileinfo->name);
  360. }
  361.  
  362. $err = false;
  363. if (!$url) {
  364. $success = false;
  365. } else if ($use_curl) {
  366. @$fp = fopen($temp_file, "w");
  367. @$ch = curl_init($url);
  368. curl_setopt($ch, CURLOPT_NOPROGRESS, false );
  369. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  370. curl_setopt($ch, CURLOPT_FILE, $fp);
  371. @$success = curl_exec($ch);
  372. $curl_info = curl_getinfo($ch);
  373. if (!$success) {
  374. $err = array("message" => curl_error($ch));
  375. }
  376. @curl_close($ch);
  377. fclose($fp);
  378. $fileinfo->size = $curl_info["size_download"];
  379. $fileinfo->type = $curl_info["content_type"];
  380. } else {
  381. $ctx = stream_context_create();
  382. @$success = copy($url, $temp_file, $ctx);
  383. if (!$success) {
  384. $err = error_get_last();
  385. }
  386. }
  387.  
  388. if ($success) {
  389. $success = rename($temp_file, get_file_path());
  390. }
  391.  
  392. if ($success) {
  393. event_callback(array("done" => $fileinfo));
  394. } else {
  395. unlink($temp_file);
  396. if (!$err) {
  397. $err = array("message" => "Invalid url parameter");
  398. }
  399. event_callback(array("fail" => $err));
  400. }
  401. }
  402.  
  403. exit();
  404. }
  405.  
  406. // Delete file / folder
  407. if (isset($_GET['del']) && !FM_READONLY) {
  408. $del = str_replace( '/', '', fm_clean_path( $_GET['del'] ) );
  409. if ($del != '' && $del != '..' && $del != '.') {
  410. $path = FM_ROOT_PATH;
  411. if (FM_PATH != '') {
  412. $path .= '/' . FM_PATH;
  413. }
  414. $is_dir = is_dir($path . '/' . $del);
  415. if (fm_rdelete($path . '/' . $del)) {
  416. $msg = $is_dir ? 'Folder <b>%s</b> deleted' : 'File <b>%s</b> deleted';
  417. fm_set_msg(sprintf($msg, fm_enc($del)));
  418. } else {
  419. $msg = $is_dir ? 'Folder <b>%s</b> not deleted' : 'File <b>%s</b> not deleted';
  420. fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
  421. }
  422. } else {
  423. fm_set_msg('Wrong file or folder name', 'error');
  424. }
  425. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  426. }
  427.  
  428. // Create folder
  429. if (isset($_GET['new']) && isset($_GET['type']) && !FM_READONLY) {
  430. $type = $_GET['type'];
  431. $new = str_replace( '/', '', fm_clean_path( strip_tags( $_GET['new'] ) ) );
  432. if ($new != '' && $new != '..' && $new != '.') {
  433. $path = FM_ROOT_PATH;
  434. if (FM_PATH != '') {
  435. $path .= '/' . FM_PATH;
  436. }
  437. if ($_GET['type'] == "file") {
  438. if (!file_exists($path . '/' . $new)) {
  439. @fopen($path . '/' . $new, 'w') or die('Cannot open file: ' . $new);
  440. fm_set_msg(sprintf('File <b>%s</b> created', fm_enc($new)));
  441. } else {
  442. fm_set_msg(sprintf('File <b>%s</b> already exists', fm_enc($new)), 'alert');
  443. }
  444. } else {
  445. if (fm_mkdir($path . '/' . $new, false) === true) {
  446. fm_set_msg(sprintf('Folder <b>%s</b> created', $new));
  447. } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
  448. fm_set_msg(sprintf('Folder <b>%s</b> already exists', fm_enc($new)), 'alert');
  449. } else {
  450. fm_set_msg(sprintf('Folder <b>%s</b> not created', fm_enc($new)), 'error');
  451. }
  452. }
  453. } else {
  454. fm_set_msg('Wrong folder name', 'error');
  455. }
  456. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  457. }
  458.  
  459. // Copy folder / file
  460. if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
  461. // from
  462. $copy = $_GET['copy'];
  463. $copy = fm_clean_path($copy);
  464. // empty path
  465. if ($copy == '') {
  466. fm_set_msg('Source path not defined', 'error');
  467. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  468. }
  469. // abs path from
  470. $from = FM_ROOT_PATH . '/' . $copy;
  471. // abs path to
  472. $dest = FM_ROOT_PATH;
  473. if (FM_PATH != '') {
  474. $dest .= '/' . FM_PATH;
  475. }
  476. $dest .= '/' . basename($from);
  477. // move?
  478. $move = isset($_GET['move']);
  479. // copy/move
  480. if ($from != $dest) {
  481. $msg_from = trim(FM_PATH . '/' . basename($from), '/');
  482. if ($move) {
  483. $rename = fm_rename($from, $dest);
  484. if ($rename) {
  485. fm_set_msg(sprintf('Moved from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  486. } elseif ($rename === null) {
  487. fm_set_msg('File or folder with this path already exists', 'alert');
  488. } else {
  489. fm_set_msg(sprintf('Error while moving from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  490. }
  491. } else {
  492. if (fm_rcopy($from, $dest)) {
  493. fm_set_msg(sprintf('Copyied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
  494. } else {
  495. fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
  496. }
  497. }
  498. } else {
  499. fm_set_msg('Paths must be not equal', 'alert');
  500. }
  501. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  502. }
  503.  
  504. // Mass copy files/ folders
  505. if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish']) && !FM_READONLY) {
  506. // from
  507. $path = FM_ROOT_PATH;
  508. if (FM_PATH != '') {
  509. $path .= '/' . FM_PATH;
  510. }
  511. // to
  512. $copy_to_path = FM_ROOT_PATH;
  513. $copy_to = fm_clean_path($_POST['copy_to']);
  514. if ($copy_to != '') {
  515. $copy_to_path .= '/' . $copy_to;
  516. }
  517. if ($path == $copy_to_path) {
  518. fm_set_msg('Paths must be not equal', 'alert');
  519. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  520. }
  521. if (!is_dir($copy_to_path)) {
  522. if (!fm_mkdir($copy_to_path, true)) {
  523. fm_set_msg('Unable to create destination folder', 'error');
  524. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  525. }
  526. }
  527. // move?
  528. $move = isset($_POST['move']);
  529. // copy/move
  530. $errors = 0;
  531. $files = $_POST['file'];
  532. if (is_array($files) && count($files)) {
  533. foreach ($files as $f) {
  534. if ($f != '') {
  535. // abs path from
  536. $from = $path . '/' . $f;
  537. // abs path to
  538. $dest = $copy_to_path . '/' . $f;
  539. // do
  540. if ($move) {
  541. $rename = fm_rename($from, $dest);
  542. if ($rename === false) {
  543. $errors++;
  544. }
  545. } else {
  546. if (!fm_rcopy($from, $dest)) {
  547. $errors++;
  548. }
  549. }
  550. }
  551. }
  552. if ($errors == 0) {
  553. $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
  554. fm_set_msg($msg);
  555. } else {
  556. $msg = $move ? 'Error while moving items' : 'Error while copying items';
  557. fm_set_msg($msg, 'error');
  558. }
  559. } else {
  560. fm_set_msg('Nothing selected', 'alert');
  561. }
  562. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  563. }
  564.  
  565. // Rename
  566. if (isset($_GET['ren'], $_GET['to']) && !FM_READONLY) {
  567. // old name
  568. $old = $_GET['ren'];
  569. $old = fm_clean_path($old);
  570. $old = str_replace('/', '', $old);
  571. // new name
  572. $new = $_GET['to'];
  573. $new = fm_clean_path($new);
  574. $new = str_replace('/', '', $new);
  575. // path
  576. $path = FM_ROOT_PATH;
  577. if (FM_PATH != '') {
  578. $path .= '/' . FM_PATH;
  579. }
  580. // rename
  581. if ($old != '' && $new != '') {
  582. if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
  583. fm_set_msg(sprintf('Renamed from <b>%s</b> to <b>%s</b>', fm_enc($old), fm_enc($new)));
  584. } else {
  585. fm_set_msg(sprintf('Error while renaming from <b>%s</b> to <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
  586. }
  587. } else {
  588. fm_set_msg('Names not set', 'error');
  589. }
  590. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  591. }
  592.  
  593. // Download
  594. if (isset($_GET['dl'])) {
  595. $dl = $_GET['dl'];
  596. $dl = fm_clean_path($dl);
  597. $dl = str_replace('/', '', $dl);
  598. $path = FM_ROOT_PATH;
  599. if (FM_PATH != '') {
  600. $path .= '/' . FM_PATH;
  601. }
  602. if ($dl != '' && is_file($path . '/' . $dl)) {
  603. header('Content-Description: File Transfer');
  604. header('Content-Type: application/octet-stream');
  605. header('Content-Disposition: attachment; filename="' . basename($path . '/' . $dl) . '"');
  606. header('Content-Transfer-Encoding: binary');
  607. header('Connection: Keep-Alive');
  608. header('Expires: 0');
  609. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  610. header('Pragma: public');
  611. header('Content-Length: ' . filesize($path . '/' . $dl));
  612. ob_end_clean();
  613. readfile($path . '/' . $dl);
  614. exit;
  615. } else {
  616. fm_set_msg('File not found', 'error');
  617. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  618. }
  619. }
  620.  
  621. // Upload
  622. if (!empty($_FILES) && !FM_READONLY) {
  623. $f = $_FILES;
  624. $path = FM_ROOT_PATH;
  625. $ds = DIRECTORY_SEPARATOR;
  626. if (FM_PATH != '') {
  627. $path .= '/' . FM_PATH;
  628. }
  629.  
  630. $errors = 0;
  631. $uploads = 0;
  632. $total = count($f['file']['name']);
  633. $allowed = (FM_EXTENSION) ? explode(',', FM_EXTENSION) : false;
  634.  
  635. $filename = $f['file']['name'];
  636. $tmp_name = $f['file']['tmp_name'];
  637. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  638. $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  639.  
  640. $targetPath = $path . $ds;
  641. $fullPath = $path . '/' . $_REQUEST['fullpath'];
  642. $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
  643.  
  644. if(file_exists ($fullPath)) {
  645. $ext_1 = $ext ? '.'.$ext : '';
  646. $fullPath = str_replace($ext_1, '', $fullPath) .'_'. date('ymdHis'). $ext_1;
  647. }
  648.  
  649. if (!is_dir($folder)) {
  650. $old = umask(0);
  651. mkdir($folder, 0777, true);
  652. umask($old);
  653. }
  654.  
  655. if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
  656. if (move_uploaded_file($tmp_name, $fullPath)) {
  657. die('Successfully uploaded');
  658. } else {
  659. die(sprintf('Error while uploading files. Uploaded files: %s', $uploads));
  660. }
  661. }
  662. exit();
  663. }
  664.  
  665. // Mass deleting
  666. if (isset($_POST['group'], $_POST['delete']) && !FM_READONLY) {
  667. $path = FM_ROOT_PATH;
  668. if (FM_PATH != '') {
  669. $path .= '/' . FM_PATH;
  670. }
  671.  
  672. $errors = 0;
  673. $files = $_POST['file'];
  674. if (is_array($files) && count($files)) {
  675. foreach ($files as $f) {
  676. if ($f != '') {
  677. $new_path = $path . '/' . $f;
  678. if (!fm_rdelete($new_path)) {
  679. $errors++;
  680. }
  681. }
  682. }
  683. if ($errors == 0) {
  684. fm_set_msg('Selected files and folder deleted');
  685. } else {
  686. fm_set_msg('Error while deleting items', 'error');
  687. }
  688. } else {
  689. fm_set_msg('Nothing selected', 'alert');
  690. }
  691.  
  692. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  693. }
  694.  
  695. // Pack files
  696. if (isset($_POST['group']) && (isset($_POST['zip']) || isset($_POST['tar'])) && !FM_READONLY) {
  697. $path = FM_ROOT_PATH;
  698. $ext = 'zip';
  699. if (FM_PATH != '') {
  700. $path .= '/' . FM_PATH;
  701. }
  702.  
  703. //set pack type
  704. $ext = isset($_POST['tar']) ? 'tar' : 'zip';
  705.  
  706.  
  707. if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  708. fm_set_msg('Operations with archives are not available', 'error');
  709. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  710. }
  711.  
  712. $files = $_POST['file'];
  713. if (!empty($files)) {
  714. chdir($path);
  715.  
  716. if (count($files) == 1) {
  717. $one_file = reset($files);
  718. $one_file = basename($one_file);
  719. $zipname = $one_file . '_' . date('ymd_His') . '.'.$ext;
  720. } else {
  721. $zipname = 'archive_' . date('ymd_His') . '.'.$ext;
  722. }
  723.  
  724. if($ext == 'zip') {
  725. $zipper = new FM_Zipper();
  726. $res = $zipper->create($zipname, $files);
  727. } elseif ($ext == 'tar') {
  728. $tar = new FM_Zipper_Tar();
  729. $res = $tar->create($zipname, $files);
  730. }
  731.  
  732. if ($res) {
  733. fm_set_msg(sprintf('Archive <b>%s</b> created', fm_enc($zipname)));
  734. } else {
  735. fm_set_msg('Archive not created', 'error');
  736. }
  737. } else {
  738. fm_set_msg('Nothing selected', 'alert');
  739. }
  740.  
  741. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  742. }
  743.  
  744. // Unpack
  745. if (isset($_GET['unzip']) && !FM_READONLY) {
  746. $unzip = $_GET['unzip'];
  747. $unzip = fm_clean_path($unzip);
  748. $unzip = str_replace('/', '', $unzip);
  749. $isValid = false;
  750.  
  751. $path = FM_ROOT_PATH;
  752. if (FM_PATH != '') {
  753. $path .= '/' . FM_PATH;
  754. }
  755.  
  756. if ($unzip != '' && is_file($path . '/' . $unzip)) {
  757. $zip_path = $path . '/' . $unzip;
  758. $ext = pathinfo($zip_path, PATHINFO_EXTENSION);
  759. $isValid = true;
  760. } else {
  761. fm_set_msg('File not found', 'error');
  762. }
  763.  
  764.  
  765. if (($ext == "zip" && !class_exists('ZipArchive')) || ($ext == "tar" && !class_exists('PharData'))) {
  766. fm_set_msg('Operations with archives are not available', 'error');
  767. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  768. }
  769.  
  770. if ($isValid) {
  771. //to folder
  772. $tofolder = '';
  773. if (isset($_GET['tofolder'])) {
  774. $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
  775. if (fm_mkdir($path . '/' . $tofolder, true)) {
  776. $path .= '/' . $tofolder;
  777. }
  778. }
  779.  
  780. if($ext == "zip") {
  781. $zipper = new FM_Zipper();
  782. $res = $zipper->unzip($zip_path, $path);
  783. } elseif ($ext == "tar") {
  784. $gzipper = new PharData($zip_path);
  785. $res = $gzipper->extractTo($path);
  786. }
  787.  
  788. if ($res) {
  789. fm_set_msg('Archive unpacked');
  790. } else {
  791. fm_set_msg('Archive not unpacked', 'error');
  792. }
  793.  
  794. } else {
  795. fm_set_msg('File not found', 'error');
  796. }
  797. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  798. }
  799.  
  800. // Change Perms (not for Windows)
  801. if (isset($_POST['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  802. $path = FM_ROOT_PATH;
  803. if (FM_PATH != '') {
  804. $path .= '/' . FM_PATH;
  805. }
  806.  
  807. $file = $_POST['chmod'];
  808. $file = fm_clean_path($file);
  809. $file = str_replace('/', '', $file);
  810. if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  811. fm_set_msg('File not found', 'error');
  812. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  813. }
  814.  
  815. $mode = 0;
  816. if (!empty($_POST['ur'])) {
  817. $mode |= 0400;
  818. }
  819. if (!empty($_POST['uw'])) {
  820. $mode |= 0200;
  821. }
  822. if (!empty($_POST['ux'])) {
  823. $mode |= 0100;
  824. }
  825. if (!empty($_POST['gr'])) {
  826. $mode |= 0040;
  827. }
  828. if (!empty($_POST['gw'])) {
  829. $mode |= 0020;
  830. }
  831. if (!empty($_POST['gx'])) {
  832. $mode |= 0010;
  833. }
  834. if (!empty($_POST['or'])) {
  835. $mode |= 0004;
  836. }
  837. if (!empty($_POST['ow'])) {
  838. $mode |= 0002;
  839. }
  840. if (!empty($_POST['ox'])) {
  841. $mode |= 0001;
  842. }
  843.  
  844. if (@chmod($path . '/' . $file, $mode)) {
  845. fm_set_msg('Permissions changed');
  846. } else {
  847. fm_set_msg('Permissions not changed', 'error');
  848. }
  849.  
  850. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  851. }
  852.  
  853. /*************************** /ACTIONS ***************************/
  854.  
  855. // get current path
  856. $path = FM_ROOT_PATH;
  857. if (FM_PATH != '') {
  858. $path .= '/' . FM_PATH;
  859. }
  860.  
  861. // check path
  862. if (!is_dir($path)) {
  863. fm_redirect(FM_SELF_URL . '?p=');
  864. }
  865.  
  866. // get parent folder
  867. $parent = fm_get_parent_path(FM_PATH);
  868.  
  869. $objects = is_readable($path) ? scandir($path) : array();
  870. $folders = array();
  871. $files = array();
  872. if (is_array($objects)) {
  873. foreach ($objects as $file) {
  874. if ($file == '.' || $file == '..' && in_array($file, $GLOBALS['exclude_items'])) {
  875. continue;
  876. }
  877. if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
  878. continue;
  879. }
  880. $new_path = $path . '/' . $file;
  881. if (@is_file($new_path) && !in_array($file, $GLOBALS['exclude_items'])) {
  882. $files[] = $file;
  883. } elseif (@is_dir($new_path) && $file != '.' && $file != '..' && !in_array($file, $GLOBALS['exclude_items'])) {
  884. $folders[] = $file;
  885. }
  886. }
  887. }
  888.  
  889. if (!empty($files)) {
  890. natcasesort($files);
  891. }
  892. if (!empty($folders)) {
  893. natcasesort($folders);
  894. }
  895.  
  896. // upload form
  897. if (isset($_GET['upload']) && !FM_READONLY) {
  898. fm_show_header(); // HEADER
  899. fm_show_nav_path(FM_PATH); // current path
  900. ?>
  901.  
  902. <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.css" rel="stylesheet">
  903. <div class="path">
  904.  
  905. <div class="card mb-2 fm-upload-wrapper">
  906. <div class="card-header">
  907. <ul class="nav nav-tabs card-header-tabs">
  908. <li class="nav-item">
  909. <a class="nav-link active" href="#fileUploader" data-target="#fileUploader"><i class="fa fa-arrow-circle-o-up"></i> <?php echo lng('UploadingFiles') ?></a>
  910. </li>
  911. <li class="nav-item">
  912. <a class="nav-link" href="#urlUploader" class="js-url-upload" data-target="#urlUploader"><i class="fa fa-link"></i> Upload from URL</a>
  913. </li>
  914. </ul>
  915. </div>
  916. <div class="card-body">
  917. <p class="card-text">
  918. <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>
  919. <?php echo lng('DestinationFolder') ?>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  920. </p>
  921.  
  922. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
  923. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  924. <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
  925. <div class="fallback">
  926. <input name="file" type="file" multiple/>
  927. </div>
  928. </form>
  929.  
  930. <div class="upload-url-wrapper card-tabs-container hidden" id="urlUploader">
  931. <form id="js-form-url-upload" class="form-inline" onsubmit="return upload_from_url(this);" method="POST" action="">
  932. <input type="hidden" name="type" value="upload" aria-label="hidden" aria-hidden="true">
  933. <input type="url" placeholder="URL" name="uploadurl" required class="form-control" style="width: 80%">
  934. <button type="submit" class="btn btn-primary ml-3"><?php echo lng('Upload') ?></button>
  935. <div class="lds-facebook"><div></div><div></div><div></div></div>
  936. </form>
  937. <div id="js-url-upload__list" class="col-9 mt-3"></div>
  938. </div>
  939. </div>
  940. </div>
  941. </div>
  942. <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.js"></script>
  943. <script>
  944. Dropzone.options.fileUploader = {
  945. timeout: 120000,
  946. maxFilesize: <?php echo MAX_UPLOAD_SIZE; ?>,
  947. init: function () {
  948. this.on("sending", function (file, xhr, formData) {
  949. let _path = (file.fullPath) ? file.fullPath : file.name;
  950. document.getElementById("fullpath").value = _path;
  951. xhr.ontimeout = (function() {
  952. alert('Error: Server Timeout');
  953. });
  954. }).on("success", function (res) {
  955. console.log('Upload Status >> ', res.status);
  956. }).on("error", function(file, response) {
  957. alert(response);
  958. });
  959. }
  960. }
  961. </script>
  962. <?php
  963. fm_show_footer();
  964. exit;
  965. }
  966.  
  967. // copy form POST
  968. if (isset($_POST['copy']) && !FM_READONLY) {
  969. $copy_files = $_POST['file'];
  970. if (!is_array($copy_files) || empty($copy_files)) {
  971. fm_set_msg('Nothing selected', 'alert');
  972. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  973. }
  974.  
  975. fm_show_header(); // HEADER
  976. fm_show_nav_path(FM_PATH); // current path
  977. ?>
  978. <div class="path">
  979. <div class="card">
  980. <div class="card-header">
  981. <h6><?php echo lng('Copying') ?></h6>
  982. </div>
  983. <div class="card-body">
  984. <form action="" method="post">
  985. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  986. <input type="hidden" name="finish" value="1">
  987. <?php
  988. foreach ($copy_files as $cf) {
  989. echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
  990. }
  991. ?>
  992. <p class="break-word"><?php echo lng('Files') ?>: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
  993. <p class="break-word"><?php echo lng('SourceFolder') ?>: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
  994. <label for="inp_copy_to"><?php echo lng('DestinationFolder') ?>:</label>
  995. <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
  996. </p>
  997. <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>
  998. <p>
  999. <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Copy') ?></button> &nbsp;
  1000. <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>
  1001. </p>
  1002. </form>
  1003. </div>
  1004. </div>
  1005. </div>
  1006. <?php
  1007. fm_show_footer();
  1008. exit;
  1009. }
  1010.  
  1011. // copy form
  1012. if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
  1013. $copy = $_GET['copy'];
  1014. $copy = fm_clean_path($copy);
  1015. if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
  1016. fm_set_msg('File not found', 'error');
  1017. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  1018. }
  1019.  
  1020. fm_show_header(); // HEADER
  1021. fm_show_nav_path(FM_PATH); // current path
  1022. ?>
  1023. <div class="path">
  1024. <p><b>Copying</b></p>
  1025. <p class="break-word">
  1026. Source path: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
  1027. Destination folder: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
  1028. </p>
  1029. <p>
  1030. <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;
  1031. <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;
  1032. <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> Cancel</a></b>
  1033. </p>
  1034. <p><i>Select folder</i></p>
  1035. <ul class="folders break-word">
  1036. <?php
  1037. if ($parent !== false) {
  1038. ?>
  1039. <li><a href="?p=<?php echo urlencode($parent) ?>&amp;copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
  1040. <?php
  1041. }
  1042. foreach ($folders as $f) {
  1043. ?>
  1044. <li>
  1045. <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>
  1046. <?php
  1047. }
  1048. ?>
  1049. </ul>
  1050. </div>
  1051. <?php
  1052. fm_show_footer();
  1053. exit;
  1054. }
  1055.  
  1056. if (isset($_GET['settings']) && !FM_READONLY) {
  1057. fm_show_header(); // HEADER
  1058. fm_show_nav_path(FM_PATH); // current path
  1059. global $cfg, $lang, $lang_list;
  1060. ?>
  1061.  
  1062. <div class="col-md-8 offset-md-2 pt-3">
  1063. <div class="card mb-2">
  1064. <h6 class="card-header">
  1065. <i class="fa fa-cog"></i> <?php echo lng('Settings') ?>
  1066. <a href="?p=<?php echo FM_PATH ?>" class="float-right"><i class="fa fa-window-close"></i> <?php echo lng('Cancel')?></a>
  1067. </h6>
  1068. <div class="card-body">
  1069. <form id="js-settings-form" action="" method="post" data-type="ajax" onsubmit="return save_settings(this)">
  1070. <input type="hidden" name="type" value="settings" aria-label="hidden" aria-hidden="true">
  1071. <div class="form-group row">
  1072. <label for="js-language" class="col-sm-3 col-form-label"><?php echo lng('Language') ?></label>
  1073. <div class="col-sm-5">
  1074. <select class="form-control" id="js-language" name="js-language">
  1075. <?php
  1076. function getSelected($l) {
  1077. global $lang;
  1078. return ($lang == $l) ? 'selected' : '';
  1079. }
  1080. foreach ($lang_list as $k => $v) {
  1081. echo "<option value='$k' ".getSelected($k).">$v</option>";
  1082. }
  1083. ?>
  1084. </select>
  1085. </div>
  1086. </div>
  1087. <?php
  1088. //get ON/OFF and active class
  1089. function getChecked($conf, $val, $txt) {
  1090. if($conf== 1 && $val ==1) {
  1091. return $txt;
  1092. } else if($conf == '' && $val == '') {
  1093. return $txt;
  1094. } else {
  1095. return '';
  1096. }
  1097. }
  1098. ?>
  1099. <div class="form-group row">
  1100. <label for="js-err-rpt-1" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
  1101. <div class="col-sm-9">
  1102. <div class="btn-group btn-group-toggle" data-toggle="buttons">
  1103. <label class="btn btn-secondary <?php echo getChecked($report_errors, 1, 'active') ?>">
  1104. <input type="radio" name="js-error-report" id="js-err-rpt-1" autocomplete="off" value="true" <?php echo getChecked($report_errors, 1, 'checked') ?> > ON
  1105. </label>
  1106. <label class="btn btn-secondary <?php echo getChecked($report_errors, '', 'active') ?>">
  1107. <input type="radio" name="js-error-report" id="js-err-rpt-0" autocomplete="off" value="false" <?php echo getChecked($report_errors, '', 'checked') ?> > OFF
  1108. </label>
  1109. </div>
  1110. </div>
  1111. </div>
  1112.  
  1113. <div class="form-group row">
  1114. <label for="js-hdn-1" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
  1115. <div class="col-sm-9">
  1116. <div class="btn-group btn-group-toggle" data-toggle="buttons">
  1117. <label class="btn btn-secondary <?php echo getChecked($show_hidden_files, 1, 'active') ?>">
  1118. <input type="radio" name="js-show-hidden" id="js-hdn-1" autocomplete="off" value="true" <?php echo getChecked($show_hidden_files, 1, 'checked') ?> > ON
  1119. </label>
  1120. <label class="btn btn-secondary <?php echo getChecked($show_hidden_files, '', 'active') ?>">
  1121. <input type="radio" name="js-show-hidden" id="js-hdn-0" autocomplete="off" value="false" <?php echo getChecked($show_hidden_files, '', 'checked') ?> > OFF
  1122. </label>
  1123. </div>
  1124. </div>
  1125. </div>
  1126.  
  1127. <div class="form-group row">
  1128. <div class="col-sm-10">
  1129. <button type="submit" class="btn btn-success"> <i class="fa fa-check-circle"></i> <?php echo lng('Save'); ?></button>
  1130. </div>
  1131. </div>
  1132.  
  1133. </form>
  1134. </div>
  1135. </div>
  1136. </div>
  1137. <?php
  1138. fm_show_footer();
  1139. exit;
  1140. }
  1141.  
  1142. if (isset($_GET['help'])) {
  1143. fm_show_header(); // HEADER
  1144. fm_show_nav_path(FM_PATH); // current path
  1145. global $cfg, $lang;
  1146. ?>
  1147.  
  1148. <div class="col-md-8 offset-md-2 pt-3">
  1149. <div class="card mb-2">
  1150. <h6 class="card-header">
  1151. <i class="fa fa-exclamation-circle"></i> <?php echo lng('Help') ?>
  1152. <a href="?p=<?php echo FM_PATH ?>" class="float-right"><i class="fa fa-window-close"></i> <?php echo lng('Cancel')?></a>
  1153. </h6>
  1154. <div class="card-body">
  1155. <div class="row">
  1156. <div class="col-xs-12 col-sm-6">
  1157. <p><h3><a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="app-v-title"> Tiny File Manager <?php echo VERSION; ?></a></h3></p>
  1158. <p>Author: Prasath Mani</p>
  1159. <p>Mail Us: <a href="mailto:ccpprogrammers@gmail.com">ccpprogrammers[at]gmail.com</a> </p>
  1160. </div>
  1161. <div class="col-xs-12 col-sm-6">
  1162. <div class="card">
  1163. <ul class="list-group list-group-flush">
  1164. <li class="list-group-item"><a href="https://tinyfilemanager.github.io/" target="_blank"><i class="fa fa-question-circle"></i> Help Documents</a> </li>
  1165. <li class="list-group-item"><a href="https://github.com/prasathmani/tinyfilemanager/issues" target="_blank"><i class="fa fa-bug"></i> Report Issue</a></li>
  1166. <li class="list-group-item"><a href="javascript:latest_release_info('<?php echo VERSION; ?>');" target="_blank"><i class="fa fa-link"></i> Check Latest Version</a></li>
  1167. <?php if(!FM_READONLY) { ?>
  1168. <li class="list-group-item"><a href="javascript:show_new_pwd();" target="_blank"><i class="fa fa-lock"></i> Generate new password hash</a></li>
  1169. <?php } ?>
  1170. </ul>
  1171. </div>
  1172. </div>
  1173. </div>
  1174. <div class="row js-new-pwd hidden mt-2">
  1175. <div class="col-12">
  1176. <form class="form-inline" onsubmit="return new_password_hash(this)" method="POST" action="">
  1177. <input type="hidden" name="type" value="pwdhash" aria-label="hidden" aria-hidden="true">
  1178. <div class="form-group mb-2">
  1179. <label for="staticEmail2">Generate new password hash</label>
  1180. </div>
  1181. <div class="form-group mx-sm-3 mb-2">
  1182. <label for="inputPassword2" class="sr-only">Password</label>
  1183. <input type="text" class="form-control btn-sm" id="inputPassword2" name="inputPassword2" placeholder="Password" required>
  1184. </div>
  1185. <button type="submit" class="btn btn-success btn-sm mb-2">Generate</button>
  1186. </form>
  1187. <textarea class="form-control" rows="2" readonly id="js-pwd-result"></textarea>
  1188. </div>
  1189. </div>
  1190. </div>
  1191. </div>
  1192. </div>
  1193. <?php
  1194. fm_show_footer();
  1195. exit;
  1196. }
  1197.  
  1198. // file viewer
  1199. if (isset($_GET['view'])) {
  1200. $file = $_GET['view'];
  1201. $file = fm_clean_path($file);
  1202. $file = str_replace('/', '', $file);
  1203. if ($file == '' || !is_file($path . '/' . $file)) {
  1204. fm_set_msg('File not found', 'error');
  1205. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  1206. }
  1207.  
  1208. fm_show_header(); // HEADER
  1209. fm_show_nav_path(FM_PATH); // current path
  1210.  
  1211. $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1212. $file_path = $path . '/' . $file;
  1213.  
  1214. $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1215. $mime_type = fm_get_mime_type($file_path);
  1216. $filesize = fm_get_filesize(filesize($file_path));
  1217.  
  1218. $is_zip = false;
  1219. $is_gzip = false;
  1220. $is_image = false;
  1221. $is_audio = false;
  1222. $is_video = false;
  1223. $is_text = false;
  1224. $is_onlineViewer = false;
  1225.  
  1226. $view_title = 'File';
  1227. $filenames = false; // for zip
  1228. $content = ''; // for text
  1229.  
  1230. if($GLOBALS['online_viewer'] && in_array($ext, fm_get_onlineViewer_exts())){
  1231. $is_onlineViewer = true;
  1232. }
  1233. elseif ($ext == 'zip' || $ext == 'tar') {
  1234. $is_zip = true;
  1235. $view_title = 'Archive';
  1236. $filenames = fm_get_zif_info($file_path, $ext);
  1237. } elseif (in_array($ext, fm_get_image_exts())) {
  1238. $is_image = true;
  1239. $view_title = 'Image';
  1240. } elseif (in_array($ext, fm_get_audio_exts())) {
  1241. $is_audio = true;
  1242. $view_title = 'Audio';
  1243. } elseif (in_array($ext, fm_get_video_exts())) {
  1244. $is_video = true;
  1245. $view_title = 'Video';
  1246. } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1247. $is_text = true;
  1248. $content = file_get_contents($file_path);
  1249. }
  1250.  
  1251. ?>
  1252. <div class="row">
  1253. <div class="col-12">
  1254. <p class="break-word"><b><?php echo $view_title ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p>
  1255. <p class="break-word">
  1256. Full path: <?php echo fm_enc(fm_convert_win($file_path)) ?><br>
  1257. File
  1258. size: <?php echo fm_get_filesize($filesize) ?><?php if ($filesize >= 1000): ?> (<?php echo sprintf('%s bytes', $filesize) ?>)<?php endif; ?>
  1259. <br>
  1260. MIME-type: <?php echo $mime_type ?><br>
  1261. <?php
  1262. // ZIP info
  1263. if (($is_zip || $is_gzip) && $filenames !== false) {
  1264. $total_files = 0;
  1265. $total_comp = 0;
  1266. $total_uncomp = 0;
  1267. foreach ($filenames as $fn) {
  1268. if (!$fn['folder']) {
  1269. $total_files++;
  1270. }
  1271. $total_comp += $fn['compressed_size'];
  1272. $total_uncomp += $fn['filesize'];
  1273. }
  1274. ?>
  1275. Files in archive: <?php echo $total_files ?><br>
  1276. Total size: <?php echo fm_get_filesize($total_uncomp) ?><br>
  1277. Size in archive: <?php echo fm_get_filesize($total_comp) ?><br>
  1278. Compression: <?php echo round(($total_comp / $total_uncomp) * 100) ?>%<br>
  1279. <?php
  1280. }
  1281. // Image info
  1282. if ($is_image) {
  1283. $image_size = getimagesize($file_path);
  1284. echo 'Image sizes: ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
  1285. }
  1286. // Text info
  1287. if ($is_text) {
  1288. $is_utf8 = fm_is_utf8($content);
  1289. if (function_exists('iconv')) {
  1290. if (!$is_utf8) {
  1291. $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
  1292. }
  1293. }
  1294. echo 'Charset: ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>';
  1295. }
  1296. ?>
  1297. </p>
  1298. <p>
  1299. <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;
  1300. <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>
  1301. &nbsp;
  1302. <?php
  1303. // ZIP actions
  1304. if (!FM_READONLY && ($is_zip || $is_gzip) && $filenames !== false) {
  1305. $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
  1306. ?>
  1307. <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;
  1308. <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>
  1309. <?php echo lng('UnZipToFolder') ?></a></b> &nbsp;
  1310. <?php
  1311. }
  1312. if ($is_text && !FM_READONLY) {
  1313. ?>
  1314. <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') ?></a></b> &nbsp;
  1315. <b><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&amp;edit=<?php echo urlencode($file) ?>&env=ace" class="edit-file"><i class="fa fa-pencil-square-o"></i> <?php echo lng('AdvancedEditor') ?></a></b> &nbsp;
  1316. <?php } ?>
  1317. <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>
  1318. </p>
  1319. <?php
  1320. if($is_onlineViewer) {
  1321. // Google docs viewer
  1322. 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>';
  1323. } elseif ($is_zip) {
  1324. // ZIP content
  1325. if ($filenames !== false) {
  1326. echo '<code class="maxheight">';
  1327. foreach ($filenames as $fn) {
  1328. if ($fn['folder']) {
  1329. echo '<b>' . fm_enc($fn['name']) . '</b><br>';
  1330. } else {
  1331. echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
  1332. }
  1333. }
  1334. echo '</code>';
  1335. } else {
  1336. echo '<p>Error while fetching archive info</p>';
  1337. }
  1338. } elseif ($is_image) {
  1339. // Image content
  1340. if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico'))) {
  1341. echo '<p><img src="' . fm_enc($file_url) . '" alt="" class="preview-img"></p>';
  1342. }
  1343. } elseif ($is_audio) {
  1344. // Audio content
  1345. echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
  1346. } elseif ($is_video) {
  1347. // Video content
  1348. echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
  1349. } elseif ($is_text) {
  1350. if (FM_USE_HIGHLIGHTJS) {
  1351. // highlight
  1352. $hljs_classes = array(
  1353. 'shtml' => 'xml',
  1354. 'htaccess' => 'apache',
  1355. 'phtml' => 'php',
  1356. 'lock' => 'json',
  1357. 'svg' => 'xml',
  1358. );
  1359. $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
  1360. if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
  1361. $hljs_class = 'nohighlight';
  1362. }
  1363. $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
  1364. } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
  1365. // php highlight
  1366. $content = highlight_string($content, true);
  1367. } else {
  1368. $content = '<pre>' . fm_enc($content) . '</pre>';
  1369. }
  1370. echo $content;
  1371. }
  1372. ?>
  1373. </div>
  1374. </div>
  1375. <?php
  1376. fm_show_footer();
  1377. exit;
  1378. }
  1379.  
  1380. // file editor
  1381. if (isset($_GET['edit'])) {
  1382. $file = $_GET['edit'];
  1383. $file = fm_clean_path($file);
  1384. $file = str_replace('/', '', $file);
  1385. if ($file == '' || !is_file($path . '/' . $file)) {
  1386. fm_set_msg('File not found', 'error');
  1387. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  1388. }
  1389. header('X-XSS-Protection:0');
  1390. fm_show_header(); // HEADER
  1391. fm_show_nav_path(FM_PATH); // current path
  1392.  
  1393. $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
  1394. $file_path = $path . '/' . $file;
  1395.  
  1396. // normal editer
  1397. $isNormalEditor = true;
  1398. if (isset($_GET['env'])) {
  1399. if ($_GET['env'] == "ace") {
  1400. $isNormalEditor = false;
  1401. }
  1402. }
  1403.  
  1404. // Save File
  1405. if (isset($_POST['savedata'])) {
  1406. $writedata = $_POST['savedata'];
  1407. $fd = fopen($file_path, "w");
  1408. @fwrite($fd, $writedata);
  1409. fclose($fd);
  1410. fm_set_msg('File Saved Successfully', 'alert');
  1411. }
  1412.  
  1413. $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
  1414. $mime_type = fm_get_mime_type($file_path);
  1415. $filesize = filesize($file_path);
  1416. $is_text = false;
  1417. $content = ''; // for text
  1418.  
  1419. if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
  1420. $is_text = true;
  1421. $content = file_get_contents($file_path);
  1422. }
  1423.  
  1424. ?>
  1425. <div class="path">
  1426. <div class="row">
  1427. <div class="col-xs-12 col-sm-5 col-lg-6 pt-1">
  1428. <div class="btn-toolbar" role="toolbar">
  1429. <?php if (!$isNormalEditor) { ?>
  1430. <div class="btn-group js-ace-toolbar">
  1431. <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>
  1432. <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>
  1433. <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>
  1434. <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>
  1435. <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>
  1436. <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>
  1437. <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>
  1438. <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>
  1439. </div>
  1440. <?php } ?>
  1441. </div>
  1442. </div>
  1443. <div class="edit-file-actions col-xs-12 col-sm-7 col-lg-6 text-right pt-1">
  1444. <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>
  1445. <a title="Backup" class="btn btn-sm btn-outline-primary" href="javascript:backup('<?php echo urlencode($path) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-database"></i> <?php echo lng('BackUp') ?></a>
  1446. <?php if ($is_text) { ?>
  1447. <?php if ($isNormalEditor) { ?>
  1448. <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>
  1449. <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
  1450. </button>
  1451. <?php } else { ?>
  1452. <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>
  1453. <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') ?>
  1454. </button>
  1455. <?php } ?>
  1456. <?php } ?>
  1457. </div>
  1458. </div>
  1459. <?php
  1460. if ($is_text && $isNormalEditor) {
  1461. echo '<textarea class="mt-2" id="normal-editor" rows="33" cols="120" style="width: 99.5%;">' . htmlspecialchars($content) . '</textarea>';
  1462. } elseif ($is_text) {
  1463. echo '<div id="editor" contenteditable="true">' . htmlspecialchars($content) . '</div>';
  1464. } else {
  1465. fm_set_msg('FILE EXTENSION HAS NOT SUPPORTED', 'error');
  1466. }
  1467. ?>
  1468. </div>
  1469. <?php
  1470. fm_show_footer();
  1471. exit;
  1472. }
  1473.  
  1474. // chmod (not for Windows)
  1475. if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
  1476. $file = $_GET['chmod'];
  1477. $file = fm_clean_path($file);
  1478. $file = str_replace('/', '', $file);
  1479. if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
  1480. fm_set_msg('File not found', 'error');
  1481. fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
  1482. }
  1483.  
  1484. fm_show_header(); // HEADER
  1485. fm_show_nav_path(FM_PATH); // current path
  1486.  
  1487. $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
  1488. $file_path = $path . '/' . $file;
  1489.  
  1490. $mode = fileperms($path . '/' . $file);
  1491.  
  1492. ?>
  1493. <div class="path">
  1494. <div class="card mb-2">
  1495. <h6 class="card-header">
  1496. <?php echo lng('ChangePermissions') ?>
  1497. </h6>
  1498. <div class="card-body">
  1499. <p class="card-text">
  1500. Full path: <?php echo $file_path ?><br>
  1501. </p>
  1502. <form action="" method="post">
  1503. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1504. <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
  1505.  
  1506. <table class="table compact-table">
  1507. <tr>
  1508. <td></td>
  1509. <td><b><?php echo lng('Owner') ?></b></td>
  1510. <td><b><?php echo lng('Group') ?></b></td>
  1511. <td><b><?php echo lng('Other') ?></b></td>
  1512. </tr>
  1513. <tr>
  1514. <td style="text-align: right"><b><?php echo lng('Read') ?></b></td>
  1515. <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
  1516. <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
  1517. <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
  1518. </tr>
  1519. <tr>
  1520. <td style="text-align: right"><b><?php echo lng('Write') ?></b></td>
  1521. <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
  1522. <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
  1523. <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
  1524. </tr>
  1525. <tr>
  1526. <td style="text-align: right"><b><?php echo lng('Execute') ?></b></td>
  1527. <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
  1528. <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
  1529. <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
  1530. </tr>
  1531. </table>
  1532.  
  1533. <p>
  1534. <button type="submit" class="btn btn-success"><i class="fa fa-check-circle"></i> <?php echo lng('Change') ?></button> &nbsp;
  1535. <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>
  1536. </p>
  1537. </form>
  1538. </div>
  1539. </div>
  1540. </div>
  1541. <?php
  1542. fm_show_footer();
  1543. exit;
  1544. }
  1545.  
  1546. //--- FILEMANAGER MAIN
  1547. fm_show_header(); // HEADER
  1548. fm_show_nav_path(FM_PATH); // current path
  1549.  
  1550. // messages
  1551. fm_show_message();
  1552.  
  1553. $num_files = count($files);
  1554. $num_folders = count($folders);
  1555. $all_files_size = 0;
  1556. ?>
  1557. <form action="" method="post" class="pt-3">
  1558. <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
  1559. <input type="hidden" name="group" value="1">
  1560. <div class="table-responsive">
  1561. <table class="table table-bordered table-hover table-sm bg-white" id="main-table">
  1562. <thead class="thead-white">
  1563. <tr>
  1564. <?php if (!FM_READONLY): ?>
  1565. <th style="width:3%" class="custom-checkbox-header">
  1566. <div class="custom-control custom-checkbox">
  1567. <input type="checkbox" class="custom-control-input" id="js-select-all-items" onclick="checkbox_toggle()">
  1568. <label class="custom-control-label" for="js-select-all-items"></label>
  1569. </div>
  1570. </th><?php endif; ?>
  1571. <th><?php echo lng('Name') ?></th>
  1572. <th><?php echo lng('Size') ?></th>
  1573. <th><?php echo lng('Modified') ?></th>
  1574. <?php if (!FM_IS_WIN): ?>
  1575. <th><?php echo lng('Perms') ?></th>
  1576. <th><?php echo lng('Owner') ?></th><?php endif; ?>
  1577. <th><?php echo lng('Actions') ?></th>
  1578. </tr>
  1579. </thead>
  1580. <?php
  1581. // link to parent folder
  1582. if ($parent !== false) {
  1583. ?>
  1584. <tr><?php if (!FM_READONLY): ?>
  1585. <td class="nosort"></td><?php endif; ?>
  1586. <td class="border-0"><a href="?p=<?php echo urlencode($parent) ?>"><i class="fa fa-chevron-circle-left go-back"></i> ..</a></td>
  1587. <td class="border-0"></td>
  1588. <td class="border-0"></td>
  1589. <td class="border-0"></td>
  1590. <?php if (!FM_IS_WIN) { ?>
  1591. <td class="border-0"></td>
  1592. <td class="border-0"></td>
  1593. <?php } ?>
  1594. </tr>
  1595. <?php
  1596. }
  1597. $ii = 3399;
  1598. foreach ($folders as $f) {
  1599. $is_link = is_link($path . '/' . $f);
  1600. $img = $is_link ? 'icon-link_folder' : 'fa fa-folder-o';
  1601. $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
  1602. $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  1603. if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  1604. $owner = posix_getpwuid(fileowner($path . '/' . $f));
  1605. $group = posix_getgrgid(filegroup($path . '/' . $f));
  1606. } else {
  1607. $owner = array('name' => '?');
  1608. $group = array('name' => '?');
  1609. }
  1610. ?>
  1611. <tr>
  1612. <?php if (!FM_READONLY): ?>
  1613. <td class="custom-checkbox-td">
  1614. <div class="custom-control custom-checkbox">
  1615. <input type="checkbox" class="custom-control-input" id="<?php echo $ii ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  1616. <label class="custom-control-label" for="<?php echo $ii ?>"></label>
  1617. </div>
  1618. </td><?php endif; ?>
  1619. <td>
  1620. <div class="filename"><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?>
  1621. </a><?php echo($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div>
  1622. </td>
  1623. <td><?php echo lng('Folder') ?></td>
  1624. <td><?php echo $modif ?></td>
  1625. <?php if (!FM_IS_WIN): ?>
  1626. <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; ?>
  1627. </td>
  1628. <td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
  1629. <?php endif; ?>
  1630. <td class="inline-actions"><?php if (!FM_READONLY): ?>
  1631. <a title="<?php echo lng('Delete')?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="return confirm('Delete folder?');"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
  1632. <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>
  1633. <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>
  1634. <?php endif; ?>
  1635. <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>
  1636. </td>
  1637. </tr>
  1638. <?php
  1639. flush();
  1640. $ii++;
  1641. }
  1642. $ik = 6070;
  1643. foreach ($files as $f) {
  1644. $is_link = is_link($path . '/' . $f);
  1645. $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
  1646. $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
  1647. $filesize_raw = fm_get_size($path . '/' . $f);
  1648. $filesize = fm_get_filesize($filesize_raw);
  1649. $filelink = '?p=' . urlencode(FM_PATH) . '&amp;view=' . urlencode($f);
  1650. $all_files_size += $filesize_raw;
  1651. $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
  1652. if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
  1653. $owner = posix_getpwuid(fileowner($path . '/' . $f));
  1654. $group = posix_getgrgid(filegroup($path . '/' . $f));
  1655. } else {
  1656. $owner = array('name' => '?');
  1657. $group = array('name' => '?');
  1658. }
  1659. ?>
  1660. <tr>
  1661. <?php if (!FM_READONLY): ?>
  1662. <td class="custom-checkbox-td">
  1663. <div class="custom-control custom-checkbox">
  1664. <input type="checkbox" class="custom-control-input" id="<?php echo $ik ?>" name="file[]" value="<?php echo fm_enc($f) ?>">
  1665. <label class="custom-control-label" for="<?php echo $ik ?>"></label>
  1666. </div>
  1667. </td><?php endif; ?>
  1668. <td>
  1669. <div class="filename"><a href="<?php echo $filelink ?>" title="File info"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?>
  1670. </a><?php echo($is_link ? ' &rarr; <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div>
  1671. </td>
  1672. <td><span title="<?php printf('%s bytes', $filesize_raw) ?>"><?php echo $filesize ?></span></td>
  1673. <td><?php echo $modif ?></td>
  1674. <?php if (!FM_IS_WIN): ?>
  1675. <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; ?>
  1676. </td>
  1677. <td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
  1678. <?php endif; ?>
  1679. <td class="inline-actions">
  1680. <?php if (!FM_READONLY): ?>
  1681. <a title="<?php echo lng('Delete') ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;del=<?php echo urlencode($f) ?>" onclick="return confirm('Delete file?');"><i class="fa fa-trash-o"></i></a>
  1682. <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>
  1683. <a title="<?php echo lng('CopyTo') ?>..."
  1684. href="?p=<?php echo urlencode(FM_PATH) ?>&amp;copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
  1685. <?php endif; ?>
  1686. <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>
  1687. <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>
  1688. </td>
  1689. </tr>
  1690. <?php
  1691. flush();
  1692. $ik++;
  1693. }
  1694.  
  1695. if (empty($folders) && empty($files)) {
  1696. ?>
  1697. <tfoot>
  1698. <tr><?php if (!FM_READONLY): ?>
  1699. <td></td><?php endif; ?>
  1700. <td colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"><em><?php echo 'Folder is empty' ?></em></td>
  1701. </tr>
  1702. </tfoot>
  1703. <?php
  1704. } else {
  1705. ?>
  1706. <tfoot>
  1707. <tr><?php if (!FM_READONLY): ?>
  1708. <td class="gray"></td><?php endif; ?>
  1709. <td class="gray" colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>">
  1710. Full size: <span title="<?php printf('%s bytes', $all_files_size) ?>"><?php echo '<span class="badge badge-light">'.fm_get_filesize($all_files_size).'</span>' ?></span>,
  1711. <?php echo lng('File').': <span class="badge badge-light">'.$num_files.'</span>' ?>,
  1712. <?php echo lng('Folder').': <span class="badge badge-light">'.$num_folders.'</span>' ?>,
  1713. <?php echo lng('MemoryUsed').': <span class="badge badge-light">'.fm_get_filesize(@memory_get_usage(true)).'</span>' ?>,
  1714. <?php echo lng('PartitionSize').': <span class="badge badge-light">'.fm_get_filesize(@disk_free_space($path)) .'</span> free of <span class="badge badge-light">'.fm_get_filesize(@disk_total_space($path)).'</span>'; ?>
  1715. </td>
  1716. </tr>
  1717. </tfoot>
  1718. <?php
  1719. }
  1720. ?>
  1721. </table>
  1722. </div>
  1723.  
  1724. <div class="row">
  1725. <?php if (!FM_READONLY): ?>
  1726. <div class="col-xs-12 col-sm-9">
  1727. <ul class="list-inline footer-action">
  1728. <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>
  1729. <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>
  1730. <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>
  1731. <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?')">
  1732. <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>
  1733. <li class="list-inline-item"><input type="submit" class="hidden" name="zip" id="a-zip" value="zip" onclick="return confirm('Create archive?')">
  1734. <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>
  1735. <li class="list-inline-item"><input type="submit" class="hidden" name="tar" id="a-tar" value="tar" onclick="return confirm('Create archive?')">
  1736. <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>
  1737. <li class="list-inline-item"><input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
  1738. <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>
  1739. </ul>
  1740. </div>
  1741. <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>
  1742. <?php else: ?>
  1743. <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>
  1744. <?php endif; ?>
  1745. </div>
  1746.  
  1747. </form>
  1748.  
  1749. <?php
  1750. fm_show_footer();
  1751.  
  1752. //--- END
  1753.  
  1754. // Functions
  1755.  
  1756. /**
  1757. * Delete file or folder (recursively)
  1758. * @param string $path
  1759. * @return bool
  1760. */
  1761. function fm_rdelete($path)
  1762. {
  1763. if (is_link($path)) {
  1764. return unlink($path);
  1765. } elseif (is_dir($path)) {
  1766. $objects = scandir($path);
  1767. $ok = true;
  1768. if (is_array($objects)) {
  1769. foreach ($objects as $file) {
  1770. if ($file != '.' && $file != '..') {
  1771. if (!fm_rdelete($path . '/' . $file)) {
  1772. $ok = false;
  1773. }
  1774. }
  1775. }
  1776. }
  1777. return ($ok) ? rmdir($path) : false;
  1778. } elseif (is_file($path)) {
  1779. return unlink($path);
  1780. }
  1781. return false;
  1782. }
  1783.  
  1784. /**
  1785. * Recursive chmod
  1786. * @param string $path
  1787. * @param int $filemode
  1788. * @param int $dirmode
  1789. * @return bool
  1790. * @todo Will use in mass chmod
  1791. */
  1792. function fm_rchmod($path, $filemode, $dirmode)
  1793. {
  1794. if (is_dir($path)) {
  1795. if (!chmod($path, $dirmode)) {
  1796. return false;
  1797. }
  1798. $objects = scandir($path);
  1799. if (is_array($objects)) {
  1800. foreach ($objects as $file) {
  1801. if ($file != '.' && $file != '..') {
  1802. if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
  1803. return false;
  1804. }
  1805. }
  1806. }
  1807. }
  1808. return true;
  1809. } elseif (is_link($path)) {
  1810. return true;
  1811. } elseif (is_file($path)) {
  1812. return chmod($path, $filemode);
  1813. }
  1814. return false;
  1815. }
  1816.  
  1817. /**
  1818. * Safely rename
  1819. * @param string $old
  1820. * @param string $new
  1821. * @return bool|null
  1822. */
  1823. function fm_rename($old, $new)
  1824. {
  1825. $allowed = (FM_EXTENSION) ? explode(',', FM_EXTENSION) : false;
  1826.  
  1827. $ext = pathinfo($new, PATHINFO_EXTENSION);
  1828. $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
  1829.  
  1830. if(!$isFileAllowed) return false;
  1831.  
  1832. return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
  1833. }
  1834.  
  1835. /**
  1836. * Copy file or folder (recursively).
  1837. * @param string $path
  1838. * @param string $dest
  1839. * @param bool $upd Update files
  1840. * @param bool $force Create folder with same names instead file
  1841. * @return bool
  1842. */
  1843. function fm_rcopy($path, $dest, $upd = true, $force = true)
  1844. {
  1845. if (is_dir($path)) {
  1846. if (!fm_mkdir($dest, $force)) {
  1847. return false;
  1848. }
  1849. $objects = scandir($path);
  1850. $ok = true;
  1851. if (is_array($objects)) {
  1852. foreach ($objects as $file) {
  1853. if ($file != '.' && $file != '..') {
  1854. if (!fm_rcopy($path . '/' . $file, $dest . '/' . $file)) {
  1855. $ok = false;
  1856. }
  1857. }
  1858. }
  1859. }
  1860. return $ok;
  1861. } elseif (is_file($path)) {
  1862. return fm_copy($path, $dest, $upd);
  1863. }
  1864. return false;
  1865. }
  1866.  
  1867. /**
  1868. * Safely create folder
  1869. * @param string $dir
  1870. * @param bool $force
  1871. * @return bool
  1872. */
  1873. function fm_mkdir($dir, $force)
  1874. {
  1875. if (file_exists($dir)) {
  1876. if (is_dir($dir)) {
  1877. return $dir;
  1878. } elseif (!$force) {
  1879. return false;
  1880. }
  1881. unlink($dir);
  1882. }
  1883. return mkdir($dir, 0777, true);
  1884. }
  1885.  
  1886. /**
  1887. * Safely copy file
  1888. * @param string $f1
  1889. * @param string $f2
  1890. * @param bool $upd
  1891. * @return bool
  1892. */
  1893. function fm_copy($f1, $f2, $upd)
  1894. {
  1895. $time1 = filemtime($f1);
  1896. if (file_exists($f2)) {
  1897. $time2 = filemtime($f2);
  1898. if ($time2 >= $time1 && $upd) {
  1899. return false;
  1900. }
  1901. }
  1902. $ok = copy($f1, $f2);
  1903. if ($ok) {
  1904. touch($f2, $time1);
  1905. }
  1906. return $ok;
  1907. }
  1908.  
  1909. /**
  1910. * Get mime type
  1911. * @param string $file_path
  1912. * @return mixed|string
  1913. */
  1914. function fm_get_mime_type($file_path)
  1915. {
  1916. if (function_exists('finfo_open')) {
  1917. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  1918. $mime = finfo_file($finfo, $file_path);
  1919. finfo_close($finfo);
  1920. return $mime;
  1921. } elseif (function_exists('mime_content_type')) {
  1922. return mime_content_type($file_path);
  1923. } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
  1924. $file = escapeshellarg($file_path);
  1925. $mime = shell_exec('file -bi ' . $file);
  1926. return $mime;
  1927. } else {
  1928. return '--';
  1929. }
  1930. }
  1931.  
  1932. /**
  1933. * HTTP Redirect
  1934. * @param string $url
  1935. * @param int $code
  1936. */
  1937. function fm_redirect($url, $code = 302)
  1938. {
  1939. header('Location: ' . $url, true, $code);
  1940. exit;
  1941. }
  1942.  
  1943. /**
  1944. * Clean path
  1945. * @param string $path
  1946. * @return string
  1947. */
  1948. function fm_clean_path($path)
  1949. {
  1950. $path = trim($path);
  1951. $path = trim($path, '\\/');
  1952. $path = str_replace(array('../', '..\\'), '', $path);
  1953. if ($path == '..') {
  1954. $path = '';
  1955. }
  1956. return str_replace('\\', '/', $path);
  1957. }
  1958.  
  1959. /**
  1960. * Get parent path
  1961. * @param string $path
  1962. * @return bool|string
  1963. */
  1964. function fm_get_parent_path($path)
  1965. {
  1966. $path = fm_clean_path($path);
  1967. if ($path != '') {
  1968. $array = explode('/', $path);
  1969. if (count($array) > 1) {
  1970. $array = array_slice($array, 0, -1);
  1971. return implode('/', $array);
  1972. }
  1973. return '';
  1974. }
  1975. return false;
  1976. }
  1977.  
  1978. /*
  1979. * get language translations from json file
  1980. * @param int $tr
  1981. * @return array
  1982. */
  1983. function fm_get_translations($tr) {
  1984. try {
  1985. $content = @file_get_contents('translation.json');
  1986. if($content !== FALSE) {
  1987. $lng = json_decode($content, TRUE);
  1988. global $lang_list;
  1989. foreach ($lng["language"] as $key => $value)
  1990. {
  1991. $code = $value["code"];
  1992. $lang_list[$code] = $value["name"];
  1993. if ($tr)
  1994. $tr[$code] = $value["translation"];
  1995. }
  1996. return $tr;
  1997. }
  1998.  
  1999. }
  2000. catch (Exception $e) {
  2001. echo $e;
  2002. }
  2003. }
  2004.  
  2005. /**
  2006. * @param $file
  2007. * Recover all file sizes larger than > 2GB.
  2008. * Works on php 32bits and 64bits and supports linux
  2009. * @return int|string
  2010. */
  2011. function fm_get_size($file)
  2012. {
  2013. static $iswin;
  2014. if (!isset($iswin)) {
  2015. $iswin = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
  2016. }
  2017.  
  2018. static $exec_works;
  2019. if (!isset($exec_works)) {
  2020. $exec_works = (function_exists('exec') && !ini_get('safe_mode') && @exec('echo EXEC') == 'EXEC');
  2021. }
  2022.  
  2023. // try a shell command
  2024. if ($exec_works) {
  2025. $cmd = ($iswin) ? "for %F in (\"$file\") do @echo %~zF" : "stat -c%s \"$file\"";
  2026. @exec($cmd, $output);
  2027. if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) {
  2028. return $size;
  2029. }
  2030. }
  2031.  
  2032. // try the Windows COM interface
  2033. if ($iswin && class_exists("COM")) {
  2034. try {
  2035. $fsobj = new COM('Scripting.FileSystemObject');
  2036. $f = $fsobj->GetFile( realpath($file) );
  2037. $size = $f->Size;
  2038. } catch (Exception $e) {
  2039. $size = null;
  2040. }
  2041. if (ctype_digit($size)) {
  2042. return $size;
  2043. }
  2044. }
  2045.  
  2046. // if all else fails
  2047. return filesize($file);
  2048. }
  2049.  
  2050. /**
  2051. * Get nice filesize
  2052. * @param int $size
  2053. * @return string
  2054. */
  2055. function fm_get_filesize($size)
  2056. {
  2057. if ($size < 1000) {
  2058. return sprintf('%s B', $size);
  2059. } elseif (($size / 1024) < 1000) {
  2060. return sprintf('%s KB', round(($size / 1024), 2));
  2061. } elseif (($size / 1024 / 1024) < 1000) {
  2062. return sprintf('%s MB', round(($size / 1024 / 1024), 2));
  2063. } elseif (($size / 1024 / 1024 / 1024) < 1000) {
  2064. return sprintf('%s GB', round(($size / 1024 / 1024 / 1024), 2));
  2065. } else {
  2066. return sprintf('%s TB', round(($size / 1024 / 1024 / 1024 / 1024), 2));
  2067. }
  2068. }
  2069.  
  2070. /**
  2071. * Get info about zip archive
  2072. * @param string $path
  2073. * @return array|bool
  2074. */
  2075. function fm_get_zif_info($path, $ext) {
  2076. if ($ext == 'zip' && function_exists('zip_open')) {
  2077. $arch = zip_open($path);
  2078. if ($arch) {
  2079. $filenames = array();
  2080. while ($zip_entry = zip_read($arch)) {
  2081. $zip_name = zip_entry_name($zip_entry);
  2082. $zip_folder = substr($zip_name, -1) == '/';
  2083. $filenames[] = array(
  2084. 'name' => $zip_name,
  2085. 'filesize' => zip_entry_filesize($zip_entry),
  2086. 'compressed_size' => zip_entry_compressedsize($zip_entry),
  2087. 'folder' => $zip_folder
  2088. //'compression_method' => zip_entry_compressionmethod($zip_entry),
  2089. );
  2090. }
  2091. zip_close($arch);
  2092. return $filenames;
  2093. }
  2094. } elseif($ext == 'tar' && class_exists('PharData')) {
  2095. $archive = new PharData($path);
  2096. $filenames = array();
  2097. foreach(new RecursiveIteratorIterator($archive) as $file) {
  2098. $parent_info = $file->getPathInfo();
  2099. $zip_name = str_replace("phar://".$path, '', $file->getPathName());
  2100. $zip_name = substr($zip_name, ($pos = strpos($zip_name, '/')) !== false ? $pos + 1 : 0);
  2101. $zip_folder = $parent_info->getFileName();
  2102. $zip_info = new SplFileInfo($file);
  2103. $filenames[] = array(
  2104. 'name' => $zip_name,
  2105. 'filesize' => $zip_info->getSize(),
  2106. 'compressed_size' => $file->getCompressedSize(),
  2107. 'folder' => $zip_folder
  2108. );
  2109. }
  2110. return $filenames;
  2111. }
  2112. return false;
  2113. }
  2114.  
  2115. /**
  2116. * Encode html entities
  2117. * @param string $text
  2118. * @return string
  2119. */
  2120. function fm_enc($text)
  2121. {
  2122. return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  2123. }
  2124.  
  2125. /**
  2126. * Save message in session
  2127. * @param string $msg
  2128. * @param string $status
  2129. */
  2130. function fm_set_msg($msg, $status = 'ok')
  2131. {
  2132. $_SESSION[FM_SESSION_ID]['message'] = $msg;
  2133. $_SESSION[FM_SESSION_ID]['status'] = $status;
  2134. }
  2135.  
  2136. /**
  2137. * Check if string is in UTF-8
  2138. * @param string $string
  2139. * @return int
  2140. */
  2141. function fm_is_utf8($string)
  2142. {
  2143. return preg_match('//u', $string);
  2144. }
  2145.  
  2146. /**
  2147. * Convert file name to UTF-8 in Windows
  2148. * @param string $filename
  2149. * @return string
  2150. */
  2151. function fm_convert_win($filename)
  2152. {
  2153. if (FM_IS_WIN && function_exists('iconv')) {
  2154. $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
  2155. }
  2156. return $filename;
  2157. }
  2158.  
  2159. /**
  2160. * @param $obj
  2161. * @return array
  2162. */
  2163. function fm_object_to_array($obj)
  2164. {
  2165. if (!is_object($obj) && !is_array($obj)) {
  2166. return $obj;
  2167. }
  2168. if (is_object($obj)) {
  2169. $obj = get_object_vars($obj);
  2170. }
  2171. return array_map('fm_object_to_array', $obj);
  2172. }
  2173.  
  2174. /**
  2175. * Get CSS classname for file
  2176. * @param string $path
  2177. * @return string
  2178. */
  2179. function fm_get_file_icon_class($path)
  2180. {
  2181. // get extension
  2182. $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
  2183.  
  2184. switch ($ext) {
  2185. case 'ico':
  2186. case 'gif':
  2187. case 'jpg':
  2188. case 'jpeg':
  2189. case 'jpc':
  2190. case 'jp2':
  2191. case 'jpx':
  2192. case 'xbm':
  2193. case 'wbmp':
  2194. case 'png':
  2195. case 'bmp':
  2196. case 'tif':
  2197. case 'tiff':
  2198. case 'svg':
  2199. $img = 'fa fa-picture-o';
  2200. break;
  2201. case 'passwd':
  2202. case 'ftpquota':
  2203. case 'sql':
  2204. case 'js':
  2205. case 'json':
  2206. case 'sh':
  2207. case 'config':
  2208. case 'twig':
  2209. case 'tpl':
  2210. case 'md':
  2211. case 'gitignore':
  2212. case 'c':
  2213. case 'cpp':
  2214. case 'cs':
  2215. case 'py':
  2216. case 'map':
  2217. case 'lock':
  2218. case 'dtd':
  2219. $img = 'fa fa-file-code-o';
  2220. break;
  2221. case 'txt':
  2222. case 'ini':
  2223. case 'conf':
  2224. case 'log':
  2225. case 'htaccess':
  2226. $img = 'fa fa-file-text-o';
  2227. break;
  2228. case 'css':
  2229. case 'less':
  2230. case 'sass':
  2231. case 'scss':
  2232. $img = 'fa fa-css3';
  2233. break;
  2234. case 'zip':
  2235. case 'rar':
  2236. case 'gz':
  2237. case 'tar':
  2238. case '7z':
  2239. $img = 'fa fa-file-archive-o';
  2240. break;
  2241. case 'php':
  2242. case 'php4':
  2243. case 'php5':
  2244. case 'phps':
  2245. case 'phtml':
  2246. $img = 'fa fa-code';
  2247. break;
  2248. case 'htm':
  2249. case 'html':
  2250. case 'shtml':
  2251. case 'xhtml':
  2252. $img = 'fa fa-html5';
  2253. break;
  2254. case 'xml':
  2255. case 'xsl':
  2256. $img = 'fa fa-file-excel-o';
  2257. break;
  2258. case 'wav':
  2259. case 'mp3':
  2260. case 'mp2':
  2261. case 'm4a':
  2262. case 'aac':
  2263. case 'ogg':
  2264. case 'oga':
  2265. case 'wma':
  2266. case 'mka':
  2267. case 'flac':
  2268. case 'ac3':
  2269. case 'tds':
  2270. $img = 'fa fa-music';
  2271. break;
  2272. case 'm3u':
  2273. case 'm3u8':
  2274. case 'pls':
  2275. case 'cue':
  2276. $img = 'fa fa-headphones';
  2277. break;
  2278. case 'avi':
  2279. case 'mpg':
  2280. case 'mpeg':
  2281. case 'mp4':
  2282. case 'm4v':
  2283. case 'flv':
  2284. case 'f4v':
  2285. case 'ogm':
  2286. case 'ogv':
  2287. case 'mov':
  2288. case 'mkv':
  2289. case '3gp':
  2290. case 'asf':
  2291. case 'wmv':
  2292. $img = 'fa fa-file-video-o';
  2293. break;
  2294. case 'eml':
  2295. case 'msg':
  2296. $img = 'fa fa-envelope-o';
  2297. break;
  2298. case 'xls':
  2299. case 'xlsx':
  2300. $img = 'fa fa-file-excel-o';
  2301. break;
  2302. case 'csv':
  2303. $img = 'fa fa-file-text-o';
  2304. break;
  2305. case 'bak':
  2306. $img = 'fa fa-clipboard';
  2307. break;
  2308. case 'doc':
  2309. case 'docx':
  2310. $img = 'fa fa-file-word-o';
  2311. break;
  2312. case 'ppt':
  2313. case 'pptx':
  2314. $img = 'fa fa-file-powerpoint-o';
  2315. break;
  2316. case 'ttf':
  2317. case 'ttc':
  2318. case 'otf':
  2319. case 'woff':
  2320. case 'woff2':
  2321. case 'eot':
  2322. case 'fon':
  2323. $img = 'fa fa-font';
  2324. break;
  2325. case 'pdf':
  2326. $img = 'fa fa-file-pdf-o';
  2327. break;
  2328. case 'psd':
  2329. case 'ai':
  2330. case 'eps':
  2331. case 'fla':
  2332. case 'swf':
  2333. $img = 'fa fa-file-image-o';
  2334. break;
  2335. case 'exe':
  2336. case 'msi':
  2337. $img = 'fa fa-file-o';
  2338. break;
  2339. case 'bat':
  2340. $img = 'fa fa-terminal';
  2341. break;
  2342. default:
  2343. $img = 'fa fa-info-circle';
  2344. }
  2345.  
  2346. return $img;
  2347. }
  2348.  
  2349. /**
  2350. * Get image files extensions
  2351. * @return array
  2352. */
  2353. function fm_get_image_exts()
  2354. {
  2355. return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd');
  2356. }
  2357.  
  2358. /**
  2359. * Get video files extensions
  2360. * @return array
  2361. */
  2362. function fm_get_video_exts()
  2363. {
  2364. return array('webm', 'mp4', 'm4v', 'ogm', 'ogv', 'mov');
  2365. }
  2366.  
  2367. /**
  2368. * Get audio files extensions
  2369. * @return array
  2370. */
  2371. function fm_get_audio_exts()
  2372. {
  2373. return array('wav', 'mp3', 'ogg', 'm4a');
  2374. }
  2375.  
  2376. /**
  2377. * Get text file extensions
  2378. * @return array
  2379. */
  2380. function fm_get_text_exts()
  2381. {
  2382. return array(
  2383. 'txt', 'css', 'ini', 'conf', 'log', 'htaccess', 'passwd', 'ftpquota', 'sql', 'js', 'json', 'sh', 'config',
  2384. 'php', 'php4', 'php5', 'phps', 'phtml', 'htm', 'html', 'shtml', 'xhtml', 'xml', 'xsl', 'm3u', 'm3u8', 'pls', 'cue',
  2385. 'eml', 'msg', 'csv', 'bat', 'twig', 'tpl', 'md', 'gitignore', 'less', 'sass', 'scss', 'c', 'cpp', 'cs', 'py',
  2386. 'map', 'lock', 'dtd', 'svg',
  2387. );
  2388. }
  2389.  
  2390. /**
  2391. * Get mime types of text files
  2392. * @return array
  2393. */
  2394. function fm_get_text_mimes()
  2395. {
  2396. return array(
  2397. 'application/xml',
  2398. 'application/javascript',
  2399. 'application/x-javascript',
  2400. 'image/svg+xml',
  2401. 'message/rfc822',
  2402. );
  2403. }
  2404.  
  2405. /**
  2406. * Get file names of text files w/o extensions
  2407. * @return array
  2408. */
  2409. function fm_get_text_names()
  2410. {
  2411. return array(
  2412. 'license',
  2413. 'readme',
  2414. 'authors',
  2415. 'contributors',
  2416. 'changelog',
  2417. );
  2418. }
  2419.  
  2420. /**
  2421. * Get online docs viewer supported files extensions
  2422. * @return array
  2423. */
  2424. function fm_get_onlineViewer_exts()
  2425. {
  2426. return array('doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx', 'ai', 'psd', 'dxf', 'xps', 'rar');
  2427. }
  2428.  
  2429. /**
  2430. * Class to work with zip files (using ZipArchive)
  2431. */
  2432. class FM_Zipper
  2433. {
  2434. private $zip;
  2435.  
  2436. public function __construct()
  2437. {
  2438. $this->zip = new ZipArchive();
  2439. }
  2440.  
  2441. /**
  2442. * Create archive with name $filename and files $files (RELATIVE PATHS!)
  2443. * @param string $filename
  2444. * @param array|string $files
  2445. * @return bool
  2446. */
  2447. public function create($filename, $files)
  2448. {
  2449. $res = $this->zip->open($filename, ZipArchive::CREATE);
  2450. if ($res !== true) {
  2451. return false;
  2452. }
  2453. if (is_array($files)) {
  2454. foreach ($files as $f) {
  2455. if (!$this->addFileOrDir($f)) {
  2456. $this->zip->close();
  2457. return false;
  2458. }
  2459. }
  2460. $this->zip->close();
  2461. return true;
  2462. } else {
  2463. if ($this->addFileOrDir($files)) {
  2464. $this->zip->close();
  2465. return true;
  2466. }
  2467. return false;
  2468. }
  2469. }
  2470.  
  2471. /**
  2472. * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  2473. * @param string $filename
  2474. * @param string $path
  2475. * @return bool
  2476. */
  2477. public function unzip($filename, $path)
  2478. {
  2479. $res = $this->zip->open($filename);
  2480. if ($res !== true) {
  2481. return false;
  2482. }
  2483. if ($this->zip->extractTo($path)) {
  2484. $this->zip->close();
  2485. return true;
  2486. }
  2487. return false;
  2488. }
  2489.  
  2490. /**
  2491. * Add file/folder to archive
  2492. * @param string $filename
  2493. * @return bool
  2494. */
  2495. private function addFileOrDir($filename)
  2496. {
  2497. if (is_file($filename)) {
  2498. return $this->zip->addFile($filename);
  2499. } elseif (is_dir($filename)) {
  2500. return $this->addDir($filename);
  2501. }
  2502. return false;
  2503. }
  2504.  
  2505. /**
  2506. * Add folder recursively
  2507. * @param string $path
  2508. * @return bool
  2509. */
  2510. private function addDir($path)
  2511. {
  2512. if (!$this->zip->addEmptyDir($path)) {
  2513. return false;
  2514. }
  2515. $objects = scandir($path);
  2516. if (is_array($objects)) {
  2517. foreach ($objects as $file) {
  2518. if ($file != '.' && $file != '..') {
  2519. if (is_dir($path . '/' . $file)) {
  2520. if (!$this->addDir($path . '/' . $file)) {
  2521. return false;
  2522. }
  2523. } elseif (is_file($path . '/' . $file)) {
  2524. if (!$this->zip->addFile($path . '/' . $file)) {
  2525. return false;
  2526. }
  2527. }
  2528. }
  2529. }
  2530. return true;
  2531. }
  2532. return false;
  2533. }
  2534. }
  2535.  
  2536. /**
  2537. * Class to work with Tar files (using PharData)
  2538. */
  2539. class FM_Zipper_Tar
  2540. {
  2541. private $tar;
  2542.  
  2543. public function __construct()
  2544. {
  2545. $this->tar = null;
  2546. }
  2547.  
  2548. /**
  2549. * Create archive with name $filename and files $files (RELATIVE PATHS!)
  2550. * @param string $filename
  2551. * @param array|string $files
  2552. * @return bool
  2553. */
  2554. public function create($filename, $files)
  2555. {
  2556. $this->tar = new PharData($filename);
  2557. if (is_array($files)) {
  2558. foreach ($files as $f) {
  2559. if (!$this->addFileOrDir($f)) {
  2560. return false;
  2561. }
  2562. }
  2563. return true;
  2564. } else {
  2565. if ($this->addFileOrDir($files)) {
  2566. return true;
  2567. }
  2568. return false;
  2569. }
  2570. }
  2571.  
  2572. /**
  2573. * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
  2574. * @param string $filename
  2575. * @param string $path
  2576. * @return bool
  2577. */
  2578. public function unzip($filename, $path)
  2579. {
  2580. $res = $this->tar->open($filename);
  2581. if ($res !== true) {
  2582. return false;
  2583. }
  2584. if ($this->tar->extractTo($path)) {
  2585. return true;
  2586. }
  2587. return false;
  2588. }
  2589.  
  2590. /**
  2591. * Add file/folder to archive
  2592. * @param string $filename
  2593. * @return bool
  2594. */
  2595. private function addFileOrDir($filename)
  2596. {
  2597. if (is_file($filename)) {
  2598. return $this->tar->addFile($filename);
  2599. } elseif (is_dir($filename)) {
  2600. return $this->addDir($filename);
  2601. }
  2602. return false;
  2603. }
  2604.  
  2605. /**
  2606. * Add folder recursively
  2607. * @param string $path
  2608. * @return bool
  2609. */
  2610. private function addDir($path)
  2611. {
  2612. $objects = scandir($path);
  2613. if (is_array($objects)) {
  2614. foreach ($objects as $file) {
  2615. if ($file != '.' && $file != '..') {
  2616. if (is_dir($path . '/' . $file)) {
  2617. if (!$this->addDir($path . '/' . $file)) {
  2618. return false;
  2619. }
  2620. } elseif (is_file($path . '/' . $file)) {
  2621. try {
  2622. $this->tar->addFile($path . '/' . $file);
  2623. } catch (Exception $e) {
  2624. return false;
  2625. }
  2626. }
  2627. }
  2628. }
  2629. return true;
  2630. }
  2631. return false;
  2632. }
  2633. }
  2634.  
  2635.  
  2636.  
  2637. /**
  2638. * Save Configuration
  2639. */
  2640. class FM_Config
  2641. {
  2642. var $data;
  2643.  
  2644. function __construct()
  2645. {
  2646. global $root_path, $root_url, $CONFIG;
  2647. $fm_url = $root_url.$_SERVER["PHP_SELF"];
  2648. $this->data = array(
  2649. 'lang' => 'en',
  2650. 'error_reporting' => true,
  2651. 'show_hidden' => true
  2652. );
  2653. $data = false;
  2654. if (strlen($CONFIG)) {
  2655. $data = fm_object_to_array(json_decode($CONFIG));
  2656. } else {
  2657. $msg = 'Tiny File Manager<br>Error: Cannot load configuration';
  2658. if (substr($fm_url, -1) == '/') {
  2659. $fm_url = rtrim($fm_url, '/');
  2660. $msg .= '<br>';
  2661. $msg .= '<br>Seems like you have a trailing slash on the URL.';
  2662. $msg .= '<br>Try this link: <a href="' . $fm_url . '">' . $fm_url . '</a>';
  2663. }
  2664. die($msg);
  2665. }
  2666. if (is_array($data) && count($data)) $this->data = $data;
  2667. else $this->save();
  2668. }
  2669.  
  2670. function save()
  2671. {
  2672. global $root_path;
  2673. $fm_file = $root_path.$_SERVER["PHP_SELF"];
  2674. $var_name = '$CONFIG';
  2675. $var_value = var_export(json_encode($this->data), true);
  2676. $config_string = "<?php" . chr(13) . chr(10) . "//Default Configuration".chr(13) . chr(10)."$var_name = $var_value;" . chr(13) . chr(10);
  2677. if (file_exists($fm_file)) {
  2678. $lines = file($fm_file);
  2679. if ($fh = @fopen($fm_file, "w")) {
  2680. @fputs($fh, $config_string, strlen($config_string));
  2681. for ($x = 3; $x < count($lines); $x++) {
  2682. @fputs($fh, $lines[$x], strlen($lines[$x]));
  2683. }
  2684. @fclose($fh);
  2685. }
  2686. }
  2687. }
  2688. }
  2689.  
  2690. //--- templates functions
  2691.  
  2692. /**
  2693. * Show nav block
  2694. * @param string $path
  2695. */
  2696. function fm_show_nav_path($path)
  2697. {
  2698. global $lang, $sticky_navbar;
  2699. $isStickyNavBar = $sticky_navbar ? 'fixed-top' : '';
  2700. ?>
  2701. <nav class="navbar navbar-expand-lg navbar-light bg-white mb-4 main-nav <?php echo $isStickyNavBar ?>">
  2702. <a class="navbar-brand" href=""> <?php echo lng('AppTitle') ?> </a>
  2703. <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  2704. <span class="navbar-toggler-icon"></span>
  2705. </button>
  2706. <div class="collapse navbar-collapse" id="navbarSupportedContent">
  2707.  
  2708. <?php
  2709. $path = fm_clean_path($path);
  2710. $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
  2711. $sep = '<i class="bread-crumb"> / </i>';
  2712. if ($path != '') {
  2713. $exploded = explode('/', $path);
  2714. $count = count($exploded);
  2715. $array = array();
  2716. $parent = '';
  2717. for ($i = 0; $i < $count; $i++) {
  2718. $parent = trim($parent . '/' . $exploded[$i], '/');
  2719. $parent_enc = urlencode($parent);
  2720. $array[] = "<a href='?p={$parent_enc}'>" . fm_enc(fm_convert_win($exploded[$i])) . "</a>";
  2721. }
  2722. $root_url .= $sep . implode($sep, $array);
  2723. }
  2724. echo '<div class="col-xs-6 col-sm-5">' . $root_url . '</div>';
  2725. ?>
  2726.  
  2727. <div class="col-xs-6 col-sm-7 text-right">
  2728. <ul class="navbar-nav mr-auto float-right">
  2729. <?php if (!FM_READONLY): ?>
  2730. <li class="nav-item mr-2">
  2731. <div class="input-group input-group-sm mr-1" style="margin-top:4px;">
  2732. <input type="text" class="form-control" placeholder="<?php echo lng('Search') ?>" aria-label="<?php echo lng('Search') ?>" aria-describedby="search-addon2" id="search-addon">
  2733. <div class="input-group-append">
  2734. <span class="input-group-text" id="search-addon2"><i class="fa fa-search"></i></span>
  2735. </div>
  2736. </div>
  2737. </li>
  2738. <li class="nav-item">
  2739. <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>
  2740. </li>
  2741. <li class="nav-item">
  2742. <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>
  2743. </li>
  2744. <?php endif; ?>
  2745. <?php if (FM_USE_AUTH): ?>
  2746. <li class="nav-item avatar dropdown">
  2747. <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>
  2748. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink-5">
  2749. <?php if (!FM_READONLY): ?>
  2750. <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>
  2751. <?php endif ?>
  2752. <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>
  2753. <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>
  2754. </div>
  2755. </li>
  2756. <?php endif; ?>
  2757. </ul>
  2758. </div>
  2759. </div>
  2760. </nav>
  2761. <?php
  2762. }
  2763.  
  2764. /**
  2765. * Show message from session
  2766. */
  2767. function fm_show_message()
  2768. {
  2769. if (isset($_SESSION[FM_SESSION_ID]['message'])) {
  2770. $class = isset($_SESSION[FM_SESSION_ID]['status']) ? $_SESSION[FM_SESSION_ID]['status'] : 'ok';
  2771. echo '<p class="message ' . $class . '">' . $_SESSION[FM_SESSION_ID]['message'] . '</p>';
  2772. unset($_SESSION[FM_SESSION_ID]['message']);
  2773. unset($_SESSION[FM_SESSION_ID]['status']);
  2774. }
  2775. }
  2776.  
  2777. /**
  2778. * Show page header in Login Form
  2779. */
  2780. function fm_show_header_login()
  2781. {
  2782. $sprites_ver = '20160315';
  2783. header("Content-Type: text/html; charset=utf-8");
  2784. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  2785. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2786. header("Pragma: no-cache");
  2787.  
  2788. global $lang;
  2789. ?>
  2790. <!DOCTYPE html>
  2791. <html lang="en">
  2792. <head>
  2793. <meta charset="utf-8">
  2794. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  2795. <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  2796. <meta name="author" content="CCP Programmers">
  2797. <meta name="robots" content="noindex, nofollow">
  2798. <meta name="googlebot" content="noindex">
  2799. <link rel="icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
  2800. <title>H3K | Tiny File Manager</title>
  2801. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  2802. <style>
  2803. body.fm-login-page{background-color:#f7f9fb;font-size:14px}
  2804. .fm-login-page .brand{width:121px;overflow:hidden;margin:0 auto;margin:40px auto;margin-bottom:0;position:relative;z-index:1}
  2805. .fm-login-page .brand img{width:100%}
  2806. .fm-login-page .card-wrapper{width:360px}
  2807. .fm-login-page .card{border-color:transparent;box-shadow:0 4px 8px rgba(0,0,0,.05)}
  2808. .fm-login-page .card-title{margin-bottom:1.5rem;font-size:24px;font-weight:300;letter-spacing:-.5px}
  2809. .fm-login-page .form-control{border-width:2.3px}
  2810. .fm-login-page .form-group label{width:100%}
  2811. .fm-login-page .btn.btn-block{padding:12px 10px}
  2812. .fm-login-page .footer{margin:40px 0;color:#888;text-align:center}
  2813. @media screen and (max-width: 425px) {
  2814. .fm-login-page .card-wrapper{width:90%;margin:0 auto}
  2815. }
  2816. @media screen and (max-width: 320px) {
  2817. .fm-login-page .card.fat{padding:0}
  2818. .fm-login-page .card.fat .card-body{padding:15px}
  2819. }
  2820. .message{padding:4px 7px;border:1px solid #ddd;background-color:#fff}
  2821. .message.ok{border-color:green;color:green}
  2822. .message.error{border-color:red;color:red}
  2823. .message.alert{border-color:orange;color:orange}
  2824. </style>
  2825. </head>
  2826. <body class="fm-login-page">
  2827. <div id="wrapper" class="container-fluid">
  2828.  
  2829. <?php
  2830. }
  2831.  
  2832. /**
  2833. * Show page footer in Login Form
  2834. */
  2835. function fm_show_footer_login()
  2836. {
  2837. ?>
  2838. </div>
  2839. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.min.js"></script>
  2840. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  2841. </body>
  2842. </html>
  2843. <?php
  2844. }
  2845.  
  2846. /**
  2847. * Show Header after login
  2848. */
  2849. function fm_show_header()
  2850. {
  2851. $sprites_ver = '20160315';
  2852. header("Content-Type: text/html; charset=utf-8");
  2853. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
  2854. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2855. header("Pragma: no-cache");
  2856.  
  2857. global $lang, $sticky_navbar;
  2858. $isStickyNavBar = $sticky_navbar ? 'navbar-fixed' : 'navbar-normal';
  2859. ?>
  2860. <!DOCTYPE html>
  2861. <html>
  2862. <head>
  2863. <meta charset="utf-8">
  2864. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  2865. <meta name="description" content="Web based File Manager in PHP, Manage your files efficiently and easily with Tiny File Manager">
  2866. <meta name="author" content="CCP Programmers">
  2867. <meta name="robots" content="noindex, nofollow">
  2868. <meta name="googlebot" content="noindex">
  2869. <link rel="icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
  2870. <title>H3K | Tiny File Manager</title>
  2871. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  2872. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  2873. <?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
  2874. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/<?php echo FM_HIGHLIGHTJS_STYLE ?>.min.css">
  2875. <?php endif; ?>
  2876. <style>
  2877. body {
  2878. font-size: 14px;
  2879. color: #222;
  2880. background: #F7F7F7;
  2881. }
  2882. body.navbar-fixed {
  2883. margin-top: 55px;
  2884. }
  2885. a:hover, a:visited, a:focus {
  2886. text-decoration: none !important;
  2887. }
  2888. * {
  2889. -webkit-border-radius: 0 !important;
  2890. -moz-border-radius: 0 !important;
  2891. border-radius: 0 !important;
  2892. }
  2893. .filename, td, th {
  2894. white-space: nowrap
  2895. }
  2896. .navbar-brand {
  2897. font-weight: bold;
  2898. }
  2899. .nav-item.avatar a {
  2900. cursor: pointer;
  2901. text-transform: capitalize;
  2902. }
  2903. .nav-item.avatar a > i {
  2904. font-size: 15px;
  2905. }
  2906. .nav-item.avatar .dropdown-menu a {
  2907. font-size: 13px;
  2908. }
  2909. #search-addon {
  2910. font-size: 12px;
  2911. border-right-width: 0;
  2912. }
  2913. #search-addon2 {
  2914. background: transparent;
  2915. border-left: 0;
  2916. }
  2917. .bread-crumb {
  2918. color: #cccccc;
  2919. font-style: normal;
  2920. }
  2921. #main-table .filename a {
  2922. color: #222222;
  2923. }
  2924. .table td, .table th {
  2925. vertical-align: middle !important;
  2926. }
  2927. .table .custom-checkbox-td .custom-control.custom-checkbox, .table .custom-checkbox-header .custom-control.custom-checkbox {
  2928. padding: 0;
  2929. min-width: 18px;
  2930. }
  2931. .hidden {
  2932. display: none
  2933. }
  2934. pre.with-hljs {
  2935. padding: 0
  2936. }
  2937. pre.with-hljs code {
  2938. margin: 0;
  2939. border: 0;
  2940. overflow: visible
  2941. }
  2942. code.maxheight, pre.maxheight {
  2943. max-height: 512px
  2944. }
  2945. .fa.fa-caret-right {
  2946. font-size: 1.2em;
  2947. margin: 0 4px;
  2948. vertical-align: middle;
  2949. color: #ececec
  2950. }
  2951. .fa.fa-home {
  2952. font-size: 1.3em;
  2953. vertical-align: bottom
  2954. }
  2955. .path {
  2956. margin-bottom: 10px
  2957. }
  2958. form.dropzone {
  2959. min-height: 200px;
  2960. border: 2px dashed #007bff;
  2961. line-height: 6rem;
  2962. }
  2963. .right {
  2964. text-align: right
  2965. }
  2966. .center, .close, .login-form {
  2967. text-align: center
  2968. }
  2969. .message {
  2970. padding: 4px 7px;
  2971. border: 1px solid #ddd;
  2972. background-color: #fff
  2973. }
  2974. .message.ok {
  2975. border-color: green;
  2976. color: green
  2977. }
  2978. .message.error {
  2979. border-color: red;
  2980. color: red
  2981. }
  2982. .message.alert {
  2983. border-color: orange;
  2984. color: orange
  2985. }
  2986. .preview-img {
  2987. max-width: 100%;
  2988. background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC)
  2989. }
  2990. .inline-actions > a > i {
  2991. font-size: 1em;
  2992. margin-left: 5px;
  2993. background: #3785c1;
  2994. color: #fff;
  2995. padding: 3px;
  2996. border-radius: 3px
  2997. }
  2998. .preview-video {
  2999. position: relative;
  3000. max-width: 100%;
  3001. height: 0;
  3002. padding-bottom: 62.5%;
  3003. margin-bottom: 10px
  3004. }
  3005. .preview-video video {
  3006. position: absolute;
  3007. width: 100%;
  3008. height: 100%;
  3009. left: 0;
  3010. top: 0;
  3011. background: #000
  3012. }
  3013. .compact-table {
  3014. border: 0;
  3015. width: auto
  3016. }
  3017. .compact-table td, .compact-table th {
  3018. width: 100px;
  3019. border: 0;
  3020. text-align: center
  3021. }
  3022. .compact-table tr:hover td {
  3023. background-color: #fff
  3024. }
  3025. .filename {
  3026. max-width: 420px;
  3027. overflow: hidden;
  3028. text-overflow: ellipsis
  3029. }
  3030. .break-word {
  3031. word-wrap: break-word;
  3032. margin-left: 30px
  3033. }
  3034. .break-word.float-left a {
  3035. color: #7d7d7d
  3036. }
  3037. .break-word + .float-right {
  3038. padding-right: 30px;
  3039. position: relative
  3040. }
  3041. .break-word + .float-right > a {
  3042. color: #7d7d7d;
  3043. font-size: 1.2em;
  3044. margin-right: 4px
  3045. }
  3046. #editor {
  3047. position: absolute;
  3048. right: 15px;
  3049. top: 100px;
  3050. bottom: 15px;
  3051. left: 15px
  3052. }
  3053. @media (max-width:481px) {
  3054. #editor {
  3055. top: 150px;
  3056. }
  3057. }
  3058. #normal-editor {
  3059. border-radius: 3px;
  3060. border-width: 2px;
  3061. padding: 10px;
  3062. outline: none;
  3063. }
  3064. .btn-2 {
  3065. border-radius: 0;
  3066. padding: 3px 6px;
  3067. font-size: small;
  3068. }
  3069. li.file:before,li.folder:before{font:normal normal normal 14px/1 FontAwesome;content:"\f016";margin-right:5px}li.folder:before{content:"\f114"}i.fa.fa-folder-o{color:#0157b3}i.fa.fa-picture-o{color:#26b99a}i.fa.fa-file-archive-o{color:#da7d7d}.btn-2 i.fa.fa-file-archive-o{color:inherit}i.fa.fa-css3{color:#f36fa0}i.fa.fa-file-code-o{color:#007bff}i.fa.fa-code{color:#cc4b4c}i.fa.fa-file-text-o{color:#0096e6}i.fa.fa-html5{color:#d75e72}i.fa.fa-file-excel-o{color:#09c55d}i.fa.fa-file-powerpoint-o{color:#f6712e}
  3070. i.go-back {
  3071. font-size: 1.2em;
  3072. color: #007bff;
  3073. }
  3074. .main-nav {
  3075. padding: 0.2rem 1rem;
  3076. 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)
  3077. }
  3078. .dataTables_filter {
  3079. display: none;
  3080. }
  3081. table.dataTable thead .sorting {
  3082. cursor: pointer;
  3083. background-repeat: no-repeat;
  3084. background-position: center right;
  3085. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7XQMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azioNZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4euts6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC');
  3086. }
  3087. table.dataTable thead .sorting_asc {
  3088. cursor: pointer;
  3089. background-repeat: no-repeat;
  3090. background-position: center right;
  3091. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg==');
  3092. }
  3093. table.dataTable thead .sorting_desc {
  3094. cursor: pointer;
  3095. background-repeat: no-repeat;
  3096. background-position: center right;
  3097. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII=');
  3098. }
  3099. table.dataTable thead tr:first-child th.custom-checkbox-header:first-child{
  3100. background-image: none;
  3101. }
  3102. .footer-action li {
  3103. margin-bottom: 10px;
  3104. }
  3105. .app-v-title {
  3106. font-size: 24px;
  3107. font-weight: 300;
  3108. letter-spacing: -.5px;
  3109. text-transform: uppercase;
  3110. }
  3111. hr.custom-hr {
  3112. border-top: 1px dashed #8c8b8b;
  3113. border-bottom: 1px dashed #fff;
  3114. }
  3115. @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; } }
  3116. .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}
  3117. .lds-facebook{display:none;position:relative;width:64px;height:64px}.lds-facebook div,.lds-facebook.show-me{display:inline-block}.lds-facebook div{position:absolute;left:6px;width:13px;background:#007bff;animation:lds-facebook 1.2s cubic-bezier(0,.5,.5,1) infinite}.lds-facebook div:nth-child(1){left:6px;animation-delay:-.24s}.lds-facebook div:nth-child(2){left:26px;animation-delay:-.12s}.lds-facebook div:nth-child(3){left:45px;animation-delay:0}@keyframes lds-facebook{0%{top:6px;height:51px}100%,50%{top:19px;height:26px}}
  3118. </style>
  3119. </head>
  3120. <body class="<?php echo $isStickyNavBar; ?>">
  3121. <div id="wrapper" class="container-fluid">
  3122.  
  3123. <!-- New Item creation -->
  3124. <div class="modal fade" id="createNewItem" tabindex="-1" role="dialog" aria-label="newItemModalLabel" aria-hidden="true">
  3125. <div class="modal-dialog" role="document">
  3126. <div class="modal-content">
  3127. <div class="modal-header">
  3128. <h5 class="modal-title" id="newItemModalLabel"><i class="fa fa-plus-square fa-fw"></i><?php echo lng('CreateNewItem') ?></h5>
  3129. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  3130. <span aria-hidden="true">&times;</span>
  3131. </button>
  3132. </div>
  3133. <div class="modal-body">
  3134. <p><label for="newfile"><?php echo lng('ItemType') ?> </label></p>
  3135.  
  3136. <div class="custom-control custom-radio custom-control-inline">
  3137. <input type="radio" id="customRadioInline1" name="newfile" value="file" class="custom-control-input">
  3138. <label class="custom-control-label" for="customRadioInline1"><?php echo lng('File') ?></label>
  3139. </div>
  3140.  
  3141. <div class="custom-control custom-radio custom-control-inline">
  3142. <input type="radio" id="customRadioInline2" name="newfile" value="folder" class="custom-control-input" checked="">
  3143. <label class="custom-control-label" for="customRadioInline2"><?php echo lng('Folder') ?></label>
  3144. </div>
  3145.  
  3146. <p class="mt-3"><label for="newfilename"><?php echo lng('ItemName') ?> </label></p>
  3147. <input type="text" name="newfilename" id="newfilename" value="" class="form-control">
  3148. </div>
  3149. <div class="modal-footer">
  3150. <button type="button" class="btn btn-outline-primary" data-dismiss="modal"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></button>
  3151. <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>
  3152. </div>
  3153. </div>
  3154. </div>
  3155. </div>
  3156.  
  3157. <!-- Modal -->
  3158. <script type="text/html" id="js-tpl-modal">
  3159. <div class="modal fade" id="js-ModalCenter-<%this.id%>" tabindex="-1" role="dialog" aria-labelledby="ModalCenterTitle" aria-hidden="true">
  3160. <div class="modal-dialog modal-dialog-centered" role="document">
  3161. <div class="modal-content">
  3162. <div class="modal-header">
  3163. <h5 class="modal-title" id="ModalCenterTitle"><%this.title%></h5>
  3164. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  3165. <span aria-hidden="true">&times;</span>
  3166. </button>
  3167. </div>
  3168. <div class="modal-body">
  3169. <%this.content%>
  3170. </div>
  3171. <div class="modal-footer">
  3172. <button type="button" class="btn btn-outline-primary" data-dismiss="modal"><i class="fa fa-times-circle"></i> <?php echo lng('Cancel') ?></button>
  3173. <%if(this.action){%><button type="button" class="btn btn-primary" id="js-ModalCenterAction" data-type="js-<%this.action%>"><%this.action%></button><%}%>
  3174. </div>
  3175. </div>
  3176. </div>
  3177. </div>
  3178. </script>
  3179.  
  3180. <?php
  3181. }
  3182.  
  3183. /**
  3184. * Show page footer
  3185. */
  3186. function fm_show_footer()
  3187. {
  3188. ?>
  3189. </div>
  3190. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  3191. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  3192. <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  3193. <script>
  3194. //TFM Config
  3195. window.curi = "https://tinyfilemanager.github.io/config.json", window.config = null;
  3196. 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; } }); }}
  3197. function template(html,options){
  3198. 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}
  3199. while(match=re.exec(html)){add(html.slice(cursor,match.index))(match[1],!0);cursor=match.index+match[0].length}
  3200. add(html.substr(cursor,html.length-cursor));code+='return r.join("");';return new Function(code.replace(/[\r\t\n]/g,'')).apply(options)
  3201. }
  3202. function newfolder(e) {
  3203. var t = document.getElementById("newfilename").value, n = document.querySelector('input[name="newfile"]:checked').value;
  3204. null !== t && "" !== t && n && (window.location.hash = "#", window.location.search = "p=" + encodeURIComponent(e) + "&new=" + encodeURIComponent(t) + "&type=" + encodeURIComponent(n))
  3205. }
  3206. 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))}
  3207. function change_checkboxes(e, t) { for (var n = e.length - 1; n >= 0; n--) e[n].checked = "boolean" == typeof t ? t : !e[n].checked }
  3208. 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 }
  3209. function select_all() { change_checkboxes(get_checkboxes(), !0) }
  3210. function unselect_all() { change_checkboxes(get_checkboxes(), !1) }
  3211. function invert_all() { change_checkboxes(get_checkboxes()) }
  3212. function checkbox_toggle() { var e = get_checkboxes(); e.push(this), change_checkboxes(e) }
  3213. function backup(e, t) { //Create file backup with .bck
  3214. var n = new XMLHttpRequest,
  3215. a = "path=" + e + "&file=" + t + "&type=backup&ajax=true";
  3216. return n.open("POST", "", !0), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.onreadystatechange = function () {
  3217. 4 == n.readyState && 200 == n.status && alert(n.responseText)
  3218. }, n.send(a), !1
  3219. }
  3220. //Save file
  3221. function edit_save(e, t) {
  3222. var n = "ace" == t ? editor.getSession().getValue() : document.getElementById("normal-editor").value;
  3223. if (n) {
  3224. var a = document.createElement("form");
  3225. a.setAttribute("method", "POST"), a.setAttribute("action", "");
  3226. var o = document.createElement("textarea");
  3227. o.setAttribute("type", "textarea"), o.setAttribute("name", "savedata");
  3228. var c = document.createTextNode(n);
  3229. o.appendChild(c), a.appendChild(o), document.body.appendChild(a), a.submit()
  3230. }
  3231. }
  3232. //Check latest version
  3233. function latest_release_info(v) {
  3234. if(!!window.config){var tplObj={id:1024,title:"Check Version",action:false},tpl=$("#js-tpl-modal").html();
  3235. if(window.config.version!=v){tplObj.content=window.config.newUpdate;}else{tplObj.content=window.config.noUpdate;}
  3236. $('#wrapper').append(template(tpl,tplObj));$("#js-ModalCenter-1024").modal('show');}else{fm_get_config();}
  3237. }
  3238. function show_new_pwd() { $(".js-new-pwd").toggleClass('hidden'); window.open("https://tinyfilemanager.github.io/docs/pwd.html", '_blank'); }
  3239. //Save Settings
  3240. function save_settings($this) {
  3241. let form = $($this);
  3242. $.ajax({
  3243. type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&ajax="+true,
  3244. success: function (data) {if(data) { window.location.reload();}}
  3245. }); return false;
  3246. }
  3247. //Create new password hash
  3248. function new_password_hash($this) {
  3249. let form = $($this), $pwd = $("#js-pwd-result"); $pwd.val('');
  3250. $.ajax({
  3251. type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&ajax="+true,
  3252. success: function (data) { if(data) { $pwd.val(data); } }
  3253. }); return false;
  3254. }
  3255. //Upload files using URL @param {Object}
  3256. function upload_from_url($this) {
  3257. let form = $($this), resultWrapper = $("div#js-url-upload__list");
  3258. $.ajax({
  3259. type: form.attr('method'), url: form.attr('action'), data: form.serialize()+"&ajax="+true,
  3260. beforeSend: function() { form.find("input[name=uploadurl]").attr("disabled","disabled"); form.find("button").hide(); form.find(".lds-facebook").addClass('show-me'); },
  3261. success: function (data) {
  3262. if(data) {
  3263. data = JSON.parse(data);
  3264. if(data.done) {
  3265. resultWrapper.append('<div class="alert alert-success row">Uploaded Successful: '+data.done.name+'</div>'); form.find("input[name=uploadurl]").val('');
  3266. } else if(data['fail']) { resultWrapper.append('<div class="alert alert-danger row">Error: '+data.fail.message+'</div>'); }
  3267. form.find("input[name=uploadurl]").removeAttr("disabled");form.find("button").show();form.find(".lds-facebook").removeClass('show-me');
  3268. }
  3269. },
  3270. error: function(xhr) {
  3271. form.find("input[name=uploadurl]").removeAttr("disabled");form.find("button").show();form.find(".lds-facebook").removeClass('show-me');console.error(xhr);
  3272. }
  3273. }); return false;
  3274. }
  3275. // Dom Ready Event
  3276. $(document).ready( function () {
  3277. //load config
  3278. fm_get_config();
  3279. //dataTable init
  3280. var $table = $('#main-table'),
  3281. tableLng = $table.find('th').length,
  3282. _targets = (tableLng && tableLng == 7 ) ? [0, 4,5,6] : tableLng == 5 ? [0,4] : [3],
  3283. mainTable = $('#main-table').DataTable({"paging": false, "info": false, "columnDefs": [{"targets": _targets, "orderable": false}]
  3284. });
  3285. $('#search-addon').on( 'keyup', function () { //Search using custom input box
  3286. mainTable.search( this.value ).draw();
  3287. });
  3288. //upload nav tabs
  3289. $(".fm-upload-wrapper .card-header-tabs").on("click", 'a', function(e){
  3290. e.preventDefault();let target=$(this).data('target');
  3291. $(".fm-upload-wrapper .card-header-tabs a").removeClass('active');$(this).addClass('active');
  3292. $(".fm-upload-wrapper .card-tabs-container").addClass('hidden');$(target).removeClass('hidden');
  3293. });
  3294. });
  3295. </script>
  3296. <?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
  3297. <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
  3298. <script>hljs.initHighlightingOnLoad();</script>
  3299. <?php endif; ?>
  3300. <?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE): ?>
  3301. <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/ace.js"></script>
  3302. <script>
  3303. var editor = ace.edit("editor");
  3304. editor.getSession().setMode("ace/mode/javascript");
  3305. //editor.setTheme("ace/theme/twilight"); //Dark Theme
  3306. function ace_commend (cmd) { editor.commands.exec(cmd, editor); }
  3307. editor.commands.addCommands([{
  3308. name: 'save', bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
  3309. exec: function(editor) { edit_save(this, 'ace'); }
  3310. }]);
  3311. function renderThemeMode() {
  3312. var $modeEl = $("select#js-ace-mode"), $themeEl = $("select#js-ace-theme"), optionNode = function(type, arr){ var $Option = ""; $.each(arr, function(i, val) { $Option += "<option value='"+type+i+"'>" + val + "</option>"; }); return $Option; };
  3313. if(window.config && window.config.aceMode) { $modeEl.html(optionNode("ace/mode/", window.config.aceMode)); }
  3314. if(window.config && window.config.aceTheme) { var lightTheme = optionNode("ace/theme/", window.config.aceTheme.bright), darkTheme = optionNode("ace/theme/", window.config.aceTheme.dark); $themeEl.html("<optgroup label=\"Bright\">"+lightTheme+"</optgroup><optgroup label=\"Dark\">"+darkTheme+"</optgroup>");}
  3315. }
  3316.  
  3317. $(function(){
  3318. renderThemeMode();
  3319. $(".js-ace-toolbar").on("click", 'button', function(e){
  3320. e.preventDefault();
  3321. let cmdValue = $(this).attr("data-cmd"), editorOption = $(this).attr("data-option");
  3322. if(cmdValue && cmdValue != "none") {
  3323. ace_commend(cmdValue);
  3324. } else if(editorOption) {
  3325. if(editorOption == "fullscreen") {
  3326. (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)
  3327. &&(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());
  3328. } else if(editorOption == "wrap") {
  3329. let wrapStatus = (editor.getSession().getUseWrapMode()) ? false : true;
  3330. editor.getSession().setUseWrapMode(wrapStatus);
  3331. } else if(editorOption == "help") {
  3332. 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');
  3333. }
  3334. }
  3335. });
  3336. $("select#js-ace-mode, select#js-ace-theme").on("change", function(e){
  3337. e.preventDefault();
  3338. let selectedValue = $(this).val(), selectionType = $(this).attr("data-type");
  3339. if(selectedValue && selectionType == "mode") {
  3340. editor.getSession().setMode(selectedValue);
  3341. } else if(selectedValue && selectionType == "theme") {
  3342. editor.setTheme(selectedValue);
  3343. }
  3344. });
  3345. });
  3346. </script>
  3347. <?php endif; ?>
  3348. </body>
  3349. </html>
  3350. <?php
  3351. }
  3352.  
  3353. /**
  3354. * Show image
  3355. * @param string $img
  3356. */
  3357. function fm_show_image($img)
  3358. {
  3359. $modified_time = gmdate('D, d M Y 00:00:00') . ' GMT';
  3360. $expires_time = gmdate('D, d M Y 00:00:00', strtotime('+1 day')) . ' GMT';
  3361.  
  3362. $img = trim($img);
  3363. $images = fm_get_images();
  3364. $image = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42mL4//8/A0CAAQAI/AL+26JNFgAAAABJRU5ErkJggg==';
  3365. if (isset($images[$img])) {
  3366. $image = $images[$img];
  3367. }
  3368. $image = base64_decode($image);
  3369. if (function_exists('mb_strlen')) {
  3370. $size = mb_strlen($image, '8bit');
  3371. } else {
  3372. $size = strlen($image);
  3373. }
  3374.  
  3375. if (function_exists('header_remove')) {
  3376. header_remove('Cache-Control');
  3377. header_remove('Pragma');
  3378. } else {
  3379. header('Cache-Control:');
  3380. header('Pragma:');
  3381. }
  3382.  
  3383. header('Last-Modified: ' . $modified_time, true, 200);
  3384. header('Expires: ' . $expires_time);
  3385. header('Content-Length: ' . $size);
  3386. header('Content-Type: image/png');
  3387. echo $image;
  3388.  
  3389. exit;
  3390. }
  3391.  
  3392.  
  3393. /**
  3394. * Language Translation System
  3395. * @param string $txt
  3396. * @return string
  3397. */
  3398. function lng($txt) {
  3399. global $lang;
  3400.  
  3401. // English Language
  3402. $tr['en']['AppName'] = 'Tiny File Manager'; $tr['en']['AppTitle'] = 'File Manager';
  3403. $tr['en']['Login'] = 'Sign in'; $tr['en']['Username'] = 'Username';
  3404. $tr['en']['Password'] = 'Password'; $tr['en']['Logout'] = 'Sign Out';
  3405. $tr['en']['Move'] = 'Move'; $tr['en']['Copy'] = 'Copy';
  3406. $tr['en']['Save'] = 'Save'; $tr['en']['SelectAll'] = 'Select all';
  3407. $tr['en']['UnSelectAll'] = 'Unselect all'; $tr['en']['File'] = 'File';
  3408. $tr['en']['Back'] = 'Back'; $tr['en']['Size'] = 'Size';
  3409. $tr['en']['Perms'] = 'Perms'; $tr['en']['Modified'] = 'Modified';
  3410. $tr['en']['Owner'] = 'Owner'; $tr['en']['Search'] = 'Search';
  3411. $tr['en']['NewItem'] = 'New Item'; $tr['en']['Folder'] = 'Folder';
  3412. $tr['en']['Delete'] = 'Delete'; $tr['en']['Rename'] = 'Rename';
  3413. $tr['en']['CopyTo'] = 'Copy to'; $tr['en']['DirectLink'] = 'Direct link';
  3414. $tr['en']['UploadingFiles'] = 'Upload Files'; $tr['en']['ChangePermissions'] = 'Change Permissions';
  3415. $tr['en']['Copying'] = 'Copying'; $tr['en']['CreateNewItem'] = 'Create New Item';
  3416. $tr['en']['Name'] = 'Name'; $tr['en']['AdvancedEditor'] = 'Advanced Editor';
  3417. $tr['en']['RememberMe'] = 'Remember Me'; $tr['en']['Actions'] = 'Actions';
  3418. $tr['en']['Upload'] = 'Upload'; $tr['en']['Cancel'] = 'Cancel';
  3419. $tr['en']['InvertSelection']= 'Invert Selection'; $tr['en']['DestinationFolder'] = 'Destination Folder';
  3420. $tr['en']['ItemType'] = 'Item Type'; $tr['en']['ItemName'] = 'Item Name';
  3421. $tr['en']['CreateNow'] = 'Create Now'; $tr['en']['Download'] = 'Download';
  3422. $tr['en']['Open'] = 'Open'; $tr['en']['UnZip'] = 'UnZip';
  3423. $tr['en']['UnZipToFolder'] = 'UnZip to folder'; $tr['en']['Edit'] = 'Edit';
  3424. $tr['en']['NormalEditor'] = 'Normal Editor'; $tr['en']['BackUp'] = 'Back Up';
  3425. $tr['en']['SourceFolder'] = 'Source Folder'; $tr['en']['Files'] = 'Files';
  3426. $tr['en']['Move'] = 'Move'; $tr['en']['Change'] = 'Change';
  3427. $tr['en']['Settings'] = 'Settings'; $tr['en']['Language'] = 'Language';
  3428. $tr['en']['MemoryUsed'] = 'Memory used'; $tr['en']['PartitionSize'] = 'Partition size';
  3429. $tr['en']['ErrorReporting'] = 'Error Reporting'; $tr['en']['ShowHiddenFiles'] = 'Show Hidden Files';
  3430.  
  3431. $i18n = fm_get_translations($tr);
  3432. $tr = $i18n ? $i18n : $tr;
  3433.  
  3434. if (!strlen($lang)) $lang = 'en';
  3435. if (isset($tr[$lang][$txt])) return fm_enc($tr[$lang][$txt]);
  3436. else if (isset($tr['en'][$txt])) return fm_enc($tr['en'][$txt]);
  3437. else return "$txt";
  3438. }
  3439.  
  3440. /**
  3441. * Get base64-encoded images
  3442. * @return array
  3443. */
  3444. function fm_get_images()
  3445. {
  3446. return array(
  3447. 'favicon' => 'Qk04AgAAAAAAADYAAAAoAAAAEAAAABAAAAABABAAAAAAAAICAAASCwAAEgsAAAAAAAAAAAAAIQQhBCEEIQQhBCEEIQQhBCEEIQ
  3448. QhBCEEIQQhBCEEIQQhBCEEIQQhBHNO3n/ef95/vXetNSEEIQQhBCEEIQQhBCEEIQQhBCEEc07ef95/3n/ef95/1lohBCEEIQQhBCEEIQQhBCEEIQ
  3449. RzTt5/3n8hBDFG3n/efyEEIQQhBCEEIQQhBCEEIQQhBHNO3n/efyEEMUbef95/IQQhBCEEIQQhBCEEIQQhBCEErTVzTnNOIQQxRt5/3n8hBCEEIQ
  3450. QhBCEEIQQhBCEEIQQhBCEEIQQhBDFG3n/efyEEIQQhBCEEIQQhBCEEIQQhBCEEIQQxRt5/3n+cc2stIQQhBCEEIQQhBCEEIQQhBCEEIQQIIZxz3n
  3451. /ef5xzay0hBCEEIQQhBCEEIQQhBCEEIQQhBCEEIQQhBDFG3n/efyEEIQQhBCEEIQQhBCEEIQQhBK01c05zTiEEMUbef95/IQQhBCEEIQQhBCEEIQ
  3452. QhBCEEc07ef95/IQQxRt5/3n8hBCEEIQQhBCEEIQQhBCEEIQRzTt5/3n8hBDFG3n/efyEEIQQhBCEEIQQhBCEEIQQhBKUUOWfef95/3n/ef95/IQ
  3453. QhBCEEIQQhBCEEIQQhBCEEIQQhBJRW3n/ef95/3n8hBCEEIQQhBCEEIQQhBCEEIQQhBCEEIQQhBCEEIQQhBCEEIQQhBCEEIQQAAA=='
  3454. );
  3455. }
  3456.  
  3457. ?>
Add Comment
Please, Sign In to add comment