-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpaste.cgi
More file actions
58 lines (53 loc) · 1.85 KB
/
paste.cgi
File metadata and controls
58 lines (53 loc) · 1.85 KB
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
#!/usr/bin/perl
require './filemin-lib.pl';
use lib './lib';
&ReadParse();
get_paths();
print_ajax_header();
if(open(my $fh, "<", &get_paste_buffer_file())) {
my @arr = <$fh>;
close($fh);
my $act = $arr[0];
my $dir = $arr[1];
chomp($act);
chomp($dir);
$dir =~ s/\.\.//g;
$dir = &simplify_path($dir);
my @errors;
if ($cwd eq &simplify_path($base.$dir) & ($act eq "cut" || $in{'overwrite'})) {
push @errors, $text{'error_pasting_nonsence'};
} else {
for(my $i = 2;$i <= scalar(@arr)-1;$i++) {
chomp($arr[$i]);
$arr[$i] =~ s/\.\.//g;
$arr[$i] = &simplify_path($arr[$i]);
my @p = split('/', $arr[$i]);
my $name = pop(@p);
my $suggested_name;
if ($in{'overwrite'}) {
$suggested_name = $name;
} else {
$suggested_name = suggest_filename($cwd, $name);
}
if ($act eq "copy") {
system("cp -r ".quotemeta($base.$arr[$i]).
" ".quotemeta("$cwd/$suggested_name")) == 0 or push @errors, $base.$arr[$i]." $text{'error_copy'} $!";
} elsif ($act eq "cut") {
system("mv ".quotemeta($base.$arr[$i]).
" ".quotemeta("$cwd/$suggested_name")) == 0 or push @errors, $base.$arr[$i]." $text{'error_copy'} $!";
}
}
}
if (scalar(@errors) > 0) {
$result = '';
foreach $error(@errors) {
$result.= "$error\\n";
}
print Mojo::JSON::to_json({'error' => $result});
} else {
my $success_text = ($act eq "copy") ? $text{'copy_complete'} : $text {'move_complete'};
print Mojo::JSON::to_json({'success' => 1, 'text' => $success_text, 'from' => $dir});
}
} else {
print Mojo::JSON::to_json({'error' => "Error .buffer $!"});
}