-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_u.cgi
executable file
·156 lines (124 loc) · 4.49 KB
/
_u.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/local/bin/perl
#################################################################################
# _U.CGI
#
# Author : Zheileman (zheileman at gmail.com)
# URL : http://github.com/zheileman/potiphoti
#
# Copyright 2003-2011, Zheileman.
#
#
# This file is part of PotiPhoti.
#
# PotiPhoti is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# PotiPhoti is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PotiPhoti; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#################################################################################
use strict;
use CGI;
use GD;
use lib::Thumbnail;
use lib::BASE;
my $big = $BASE::big;
my $img = $BASE::img;
my $xml = $BASE::xml;
my $charset = $BASE::charset;
my $password = $BASE::password;
print "Content-type: text/html\n\n";
my $q = new CGI;
my $step = $q->param('step') || 0;
if (!$step) {
&printForm;
} else {
my $pass = $q->param('pass') || 0;
my $file = $q->param('file') || 0;
my $comment = $q->param('comment') || 0;
if (!$file || !$comment || !$pass) {
&printForm("<p>$BASE::nullparms</p>");
} else {
if ($password eq 'changeme' || $pass ne $password) {
&printForm("<p>$BASE::passerror</p>");
exit;
}
$comment =~ s/<.+?>//g;
my $id = BASE::getFecha();
my $fecha = BASE::getFecha($id);
my $remoteimg = "$img$id.jpg";
my $remoteimg_original = "$big$id.jpg";
my $osizeX = 0;
my $osizeY = 0;
if (!open ARCH, "> $remoteimg_original") {
&printForm("<p>$BASE::outputerror $remoteimg_original ($!)</p>");
} else {
my $ReadBytes;
my $Buffer;
my $Bytes;
binmode(ARCH);
while ($Bytes=read($file,$Buffer,1024)){
print ARCH $Buffer;
}
close ARCH;
# Resize the uploaded image
if (open IN, "< $remoteimg_original") {
my $srcImage = GD::Image->newFromJpeg(*IN);
close IN;
# Create a thumbnail where the biggest side is X
# Save original size for later reference
my $maxthumbsize = $BASE::thumbsize1;
($osizeX, $osizeY) = $srcImage->getBounds();
if ($osizeX > $maxthumbsize || $osizeY > $maxthumbsize) {
my ($thumbb,$x,$y) = Thumbnail::create($srcImage, $maxthumbsize);
# Save the thumbnail
if (open OUT, "> $remoteimg") {
binmode OUT;
print OUT $thumbb->jpeg;
close OUT;
} else {
&printForm("<p>$BASE::outputerror $remoteimg ($!)</p>");
}
} else {
# We do not need to resize image, so a hardlink will be used to
# reference the original image.
link("$remoteimg_original", "$remoteimg") || &printForm("<p>$BASE::outputerror $remoteimg ($!)</p>");
}
}
my $remotexml = "$xml$id.xml";
if (!open XML, "> $remotexml") {
&printForm("<p>$BASE::outputerror $remotexml ($!)</p>");
} else {
print XML "<?xml version=\"1.0\" encoding=\"$charset\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"../transform.xsl\"?>
<Foto>
<Archivo>../$remoteimg</Archivo>
<Original>../$remoteimg_original</Original>
<OriginalSizeX>$osizeX</OriginalSizeX>
<OriginalSizeY>$osizeY</OriginalSizeY>
<ID>$id</ID>
<Fecha>$fecha</Fecha>
<Texto><![CDATA[$comment]]></Texto>
</Foto>
";
close(XML);
&printForm("<p>$BASE::uploadok</p>");
}
}
}
}
sub printForm {
my $html = BASE::joinTemplate("template_u.txt");
my $replace = (!$_[0] ? "<p> </p>" : $_[0]);
$html =~ s/<!--<ERRORES>-->/$replace/;
print $html;
exit(0);
}