forked from Real-Gecko/Filemin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cgi
62 lines (47 loc) · 1.66 KB
/
index.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl
# File manager written in perl
#$unsafe_index_cgi = 1;
require './filemin-lib.pl';
use lib './lib';
use File::MimeInfo;
use POSIX;
#use File::Basename;
&ReadParse();
get_paths();
unless (opendir ( DIR, $cwd )) {
$path="";
print_errors("$text{'error_opendir'} $cwd $!");
} else {
# &ui_print_header(undef, "Filemin", "");
&ui_print_header(undef, "Filemin", "", "",0 , 0, 0, "<a href='config.cgi?path=$path'>$text{'module_config'}</a>");
##########################################
#---------LET DA BRAINF###ING BEGIN----------
# Push file names with full paths to array, filtering out "." and ".."
@list = map { &simplify_path("$cwd/$_") } grep { $_ ne '.' && $_ ne '..' } readdir(DIR);
closedir(DIR);
# Filter out not allowed entries
if($remote_user_info[0] ne 'root' && $allowed_paths[0] ne '$ROOT') {
# Leave only allowed
for $path(@allowed_paths) {
push @tmp_list, grep {"$path/" =~ /^$_\// || $_ =~ /$path\//} @list;
}
# Remove duplicates
my %hash = map { $_, 1 } @tmp_list;
@list = keys %hash;
}
# Get info about directory entries
@info = map { [ $_, stat($_), mimetype($_), -d $_ ] } @list;
# Filter out folders
@folders = map {$_} grep {$_->[15] == 1 } @info;
# Filter out files
@files = map {$_} grep {$_->[15] != 1 } @info;
# Sort stuff by name
@folders = sort { $a->[0] cmp $b->[0] } @folders;
@files = sort { $a->[0] cmp $b->[0] } @files;
# Recreate list
undef(@list);
push @list, @folders, @files;
#########################################
print_interface();
&ui_print_footer("/", $text{'index'});
}