-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlist_archive.cgi
39 lines (31 loc) · 985 Bytes
/
list_archive.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
#!/usr/bin/perl
require './filemin-lib.pl';
use lib './lib';
use File::MimeInfo;
use Mojo::JSON;
&ReadParse();
get_paths();
if(!$in{'file'}) {
print Mojo::JSON::to_json({'error' => $text{'provide_correct_parameters'}});
exit;
}
# Remove exploiting "../"
$file = $in{'file'};
$file =~ s/\.\.//g;
$file = &simplify_path($file);
print_ajax_header();
$archive_type = mimetype($cwd.'/'.$file);
my $result;
my $command;
if ($archive_type eq 'application/zip') {
$command = "unzip -l ".quotemeta("$cwd/$file")." 2>&1";
$result = `$command`;
print Mojo::JSON::to_json({'success' => $result});
} elsif (index($archive_type, "tar") != -1 || index($archive_type, "gzip") != -1) {
$command = "tar tvf ".quotemeta("$cwd/$file")." 2>&1";
$result = `$command`;
# $result = system($command);
print Mojo::JSON::to_json({'success' => $result});
} else {
print Mojo::JSON::to_json({'error' => "$archive_type $text{'error_archive_type_not_supported'}"});
}