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