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