-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.pl
executable file
·93 lines (77 loc) · 2.68 KB
/
upload.pl
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;
$CGI::POST_MAX = 1024 * 5000;
my $safe_filename_characters = "a-zA-Z0-9_.-";
my $upload_dir = "/var/www/uploads";
my $query = new CGI;
if ($query->param('action') eq 'Copy from History'){
print $query->header();
my $oldfile1 = "$upload_dir/" . $query->param('old_res_id') . '_front.png';
my $oldfile2 = "$upload_dir/" . $query->param('old_res_id') . '_back.png';
my $newfile1 = "$upload_dir/" . $query->param('res_id') . '_front.png';
my $newfile2 = "$upload_dir/" . $query->param('res_id') . '_back.png';
system "cp $oldfile1 $newfile1";
system "cp $oldfile2 $newfile2";
print "<h1>CNIC copied from history successfully.</h1>";
exit;
}
my $filename = $query->param("cnicfront");
my $filename2 = $query->param("cnicback");
my $munshi9_url = $query->param("munshi9_url");
if ( !$filename ){
print $query->header ( );
print "There was a problem uploading your cnicfront (try a smaller file).";
exit;
}
if ( !$filename2 ){
print $query->header ( );
print "There was a problem uploading your cnicback (try a smaller file).";
exit;
}
my ( $name, $path, $extension ) = fileparse ( $filename, '..*' );
$filename = $query->param("res_id") . '_front.png';
$filename2 = $query->param("res_id") . '_back.png';
if ( $filename =~ /^([$safe_filename_characters]+)$/ ){
$filename = $1;
unlink "$upload_dir/$filename";
} else {
die "Filename contains invalid characters";
}
if ( $filename2 =~ /^([$safe_filename_characters]+)$/ ){
$filename2 = $1;
unlink "$upload_dir/$filename2";
} else {
die "Filename contains invalid characters";
}
my $upload_filehandle = $query->upload("cnicfront");
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
binmode UPLOADFILE;
while ( <$upload_filehandle> ){ print UPLOADFILE; }
close UPLOADFILE;
$upload_filehandle = $query->upload("cnicback");
open ( UPLOADFILE, ">$upload_dir/$filename2" ) or die "$!";
binmode UPLOADFILE;
while ( <$upload_filehandle> ){ print UPLOADFILE; }
close UPLOADFILE;
print $query->header ( );
print <<END_HTML;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thanks!</title>
<style type="text/css">
img {border: none;}
</style>
</head>
<body>
<p>Thanks for uploading your cnicfront!</p>
<p>Your cnicfront:</p>
<p><img src="http://$munshi9_url/uploads/$filename" alt="CNIC Front" width="200" height="100" /></p>
<p><img src="http://$munshi9_url/uploads/$filename2" alt="CNIC Back" width="200" height="100" /></p>
</body>
</html>
END_HTML