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