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