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