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