This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cgi
executable file
·358 lines (291 loc) · 10.6 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#! /usr/bin/perl
###################################################################################
# Dan Cardamore <[email protected]>
# Copyright 2000 all rights reserved
# This software is released under the GNU GPL license
###################################################################################
# $rcs = ' $Id: index.cgi,v 1.8 2002/07/24 04:40:32 dan Exp $ ' ;
###################################################################################
use strict;
use CGI qw(param);
use POSIX ":sys_wait_h";
use File::stat;
use Date::Manip;
use vars qw/$dbname $dbhost $dbuser $dbpass $icon_url $header $footer $background $site_logo $site_url/;
###################################################################################
################## User Configuration Data #############################
###################################################################################
# this is the url of the directory where you have your icons
$icon_url = 'http://hld.ca/icons';
$site_logo = 'http://hld.ca/images/hld.gif';
$site_url = 'http://www.hld.ca';
# this is the path to header.shtml
$header = '/home/httpd/html/template/header.shtml';
# this is the path to footer.shtml
$footer = '/home/httpd/html/template/footer.shtml';
# this is the background color for the top row of the table
$background = '#bebebe';
##################################################################################
############### END OF CONFIGURATION DATA ################################
##################################################################################
sub redirect {
my $file = param('file');
my $pwd = `pwd`;
chomp $pwd;
my $dbfile = relpath("$pwd" ."/$file");
my ($hits) = 0;
print "Location: $file\n\n";
}
sub handleThisDir {
my $pwd = `pwd`;
my ($name, $date, $size, $random, $thumbed);
chomp $pwd;
&printDirs($pwd);
&printFiles($pwd);
return;
}
sub printDirs {
my ($pwd) = @_;
# start by printing the table header
print "<font size=\"+1\">\n";
print "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"4\" valign=\"top\">\n";
print "<tr valign=\"bottom\">\n";
print "<td bgcolor=$background><b>Name</b></td>\n";
print "<td bgcolor=$background><b>Size</b></td>\n";
print "<td bgcolor=$background><b>Type</b></td>\n";
print "</tr>\n\n";
my @allfiles = get_files();
foreach my $temp_file (@allfiles) {
if ($temp_file eq ".") { next; }
my $dbfile = relpath("$pwd" ."/$temp_file");
if (-d $temp_file) { #If it is a directory
print "<tr valign=\"bottom\">\n";
my $link = "index.cgi?file=$temp_file";
if (-e "$dbfile/index.cgi") {
$link = "$temp_file";
}
if ($temp_file eq '..') {
print "<td><img src=\"$icon_url/folder.gif\"> \n";
print "<font size=\"-1\"><a href=\"$link\">".
"<b>$temp_file</b></a></font></td>\n";
print "<td><font size=\"-1\">N/A</font></td>\n";
print "<td><font size=\"-1\">Directory</font></td>\n";
}
else {
print "<td><img src=\"$icon_url/folder.gif\"> \n";
print "<font size=\"-1\"><a href=\"$link\">" .
"<b>$temp_file</b></a></font></td>\n";
print "<td><font size=\"-1\">N/A</font></td>\n";
print "<td><font size=\"-1\">Directory</font></td>\n";
}
print "</tr>\n\n";
}
}
}
sub printFiles {
my ($pwd) = @_;
my @allfiles = get_files();
foreach my $temp_file (@allfiles) {
if ($temp_file eq ".") { next; }
my $dbfile = relpath("$pwd" ."/$temp_file");
if (-f $temp_file and ($temp_file ne "index.cgi") and ($temp_file ne ".welcome.html") and
($temp_file ne ".htaccess")) {
my @fnameExt = split(/\./,$temp_file);
my $ext = $fnameExt[$#fnameExt];
my $icon = "generic.gif";
my $typedesc = $ext;
if ($ext =~ /htm/i || $ext =~ /html/i) { $icon = "portal.gif"; $typedesc = "HTML Document"}
if ($ext =~ /txt/i) { $icon = "a.gif"; $typedesc = "Text File"}
if ($ext =~ /(pl|cgi|py|sh|php)/i || $ext =~ /cgi/i) { $icon = "script.gif"; $typedesc = "Script Application" }
if ($ext =~ /(mov|mpeg|mpg|avi|asf)/i) { $icon = "small/movie.gif"; $typedesc = "Movie Video"}
if ($ext =~ /(tar|gz|zip|arj|rar)/i) { $icon = "compressed.gif"; $typedesc = "Compressed File"}
if ($ext =~ /pdf/i) { $icon = "pdf.gif"; $typedesc = "Adobe PDF"}
if ($ext =~ /(dvi|tex|ps|doc)/i) { $icon = "dvi.gif"; $typedesc = "Document"}
if ($ext =~ /(wav|mp3|wave|ogg|au)/i) { $icon = "sound1.gif"; $typedesc = "Audio File"}
if ($ext =~ /(jpg|gif|jpeg|tiff|bmp|png)/i) { $icon = "image2.gif"; $typedesc = "Graphic Image"}
print "<tr valign=\"bottom\">\n";
my $sref = stat($temp_file);
my $size = $sref->size / 1024;
my $old_temp_file = $temp_file;
$temp_file =~ s/ /%20/g;
print "<td><img src=\"$icon_url/$icon\"> <font size=\"-1\">" .
"<a href=\"index.cgi?file=$temp_file\"><b>$old_temp_file</b></a></font></td>\n";
print "<td><font size=\"-1\">$size kB</font></td>\n";
print "<td><font size=\"-1\">$typedesc</font></td>\n";
print "</tr>\n\n";
}
}
print "</table><br><br>\n";
return;
}
sub get_files {
opendir (DIR, '.');
my @allfiles = readdir(DIR);
closedir (DIR);
@allfiles = sort @allfiles;
return @allfiles;
}
sub print_header {
print "Content-type: text/html\n\n";
open (FILE, "<$header");
flock (FILE, 2);
my @header = <FILE>;
flock (FILE, 8);
close (FILE);
print @header;
print "\n\n";
print "<p align=\"right\"><a href=$site_url><img src=$site_logo border=0></a></p>\n\n";
}
sub print_footer {
open (FILE, "<$footer");
flock (FILE, 2);
my @footer = <FILE>;
flock (FILE, 8);
close (FILE);
print @footer;
}
sub print_welcome {
if (-e ".welcome.html"){
print `cat .welcome.html`;
}
}
sub relpath($) {
my $file = shift;
my $newfile = "";
$file =~ s/\n//g; # remove new lines
my @peices = split /\//, $file;
for (my $i = 0; $i <= $#peices; $i++) {
if ($peices[$i + 1] eq "..") {
last;
}
if ($peices[$i] ne ".") {
$newfile .= "/$peices[$i]";
}
}
$newfile =~ s/\/\//\//g;
return $newfile;
}
# displays on pic and has next, prev, and back buttons
sub displayPic() {
my $picNum = param('picNum');
open (FILE, "<photo.dat") or die print "Error opening photo.dat";
flock (FILE, 2);
my @file = <FILE>;
flock (FILE, 8);
close (FILE);
chomp @file;
my ($albumName, $albumDesc) = split /~:~/, $file[0];
my ($bgcolor, $fontcolor) = ($file[2], $file[3]);
my ($picName, $picDesc) = split /~:~/, $file[$picNum + 4];
my $prev = $picNum - 1;
my $next = $picNum + 1;
print "<html><head><title>Album: $albumName Picture: $picName</title>";
print "</head><body bgcolor=$bgcolor>\n";
print "<center>\n";
print "<a href=palbum.pl?option=displayPic\&picNum=$prev>Previous</a> ";
print "<a href=palbum.pl>Index</a> ";
print "<a href=palbum.pl?option=displayPic\&picNum=$next>Next</a><br><br>";
print "<img src=$picName border=0 alt=$picName><br>\n";
print "<font color=$fontcolor>$picDesc</font><br><br>";
print "<a href=palbum.pl?option=displayPic\&picNum=$prev>Previous</a> ";
print "<a href=palbum.pl>Index</a> ";
print "<a href=palbum.pl?option=displayPic\&picNum=$next>Next</a><br><br>";
print "</center></body></html>\n";
}
sub generateIndex() {
if ( -e "photo.dat" ) { die print "Error: photo.dat exists"; }
opendir (DIR, ".");
my @allpics = readdir(DIR);
closedir(DIR);
chomp @allpics;
@allpics = sort @allpics;
my @pics;
foreach my $pic (@allpics) {
unless ( -f "$pic") { next; } # only look at files
if ( $pic eq "photo.dat" ) { next; } # ignore photo.dat
if ( $pic eq "index.cgi" ) { next; } # ignore photo.dat
if ( $pic eq "palbum.pl" ) { next; } # ignore photo.dat
if ( $pic =~ /PAsmall/ ) { next; } # ignore thumbnails.
push @pics, $pic;
}
my $albumName = param('albumName');
my $albumDesc = param('albumDesc');
my $bgcolor = param('bgcolor');
my $fontcolor = param('fontcolor');
my $picNum = param('picNum');
$picNum = 10 unless (defined $picNum);
$bgcolor = "white" unless (defined $bgcolor);
$fontcolor = "blue" unless (defined $fontcolor);
my $date = ParseDate("today");
open (FILE, ">photo.dat") or die print "Cannot open photo.dat for writing";
flock (FILE, 2);
print FILE "$albumName~:~$albumDesc~:~$date\n";
print FILE "$picNum\n$bgcolor\n$fontcolor\n";
foreach my $pic (@pics) {
my $picDesc = param($pic);
if (not defined $picDesc or $picDesc eq "") {
$picDesc = "No Description";
}
print FILE "$pic~:~$picDesc\n";
}
flock (FILE, 8);
close (FILE);
}
sub generateIndexForm() {
if ( -e "photo.dat" ) { die print "Error: photo.dat exists"; }
opendir (DIR, ".");
my @allpics = readdir(DIR);
closedir(DIR);
chomp @allpics;
@allpics = sort @allpics;
my @pics;
foreach my $pic (@allpics) {
unless ( -f "$pic") { next; } # only look at files
if ( $pic eq "photo.dat" ) { next; } # ignore photo.dat
if ( $pic eq "index.cgi" ) { next; } # ignore photo.dat
if ( $pic eq "palbum.pl" ) { next; } # ignore photo.dat
if ( $pic =~ /PAsmall/ ) { next; } # ignore thumbnails.
`convert -geometry 80x80 $pic PAsmall$pic`;
push @pics, $pic;
}
print "<html><head><title>Generate Album</title></head>";
print "<body bgcolor=white><center>\n";
print "<font color=blue><b>Note: The thumbnails have already been created.";
print " You now need to customize your photo album</b></font><br>\n";
print "<form action=palbum.pl method=post>";
print "<input type=hidden name=option value=generateIndex>";
# Global album properties
print "<table width=100% border=1 cellpadding=0>\n";
print "<tr><td colspan=2 align=center>Album Properties</td></tr>\n";
print "<tr><td>Album Name</td><td><input type=text name=albumName></td></tr>\n";
print "<tr><td>Album Description</td><td><input type=text " .
"name=albumDesc></td></tr>\n";
print "<tr><td>Background Color</td><td><input type=text name=bgcolor></td></tr>";
print "<tr><td>Font Color</td><td><input type=text name=fontcolor></td></tr>";
print "<tr><td>Pics per page</td><td><input type=text name=picNum></td></tr>";
print "</table>";
print "<hr>\n";
# each picture properties
print "<table border=1 width=100% cellspacing=0>\n";
print "<tr><td><b>Thumbnail</b></td><td>Description</td></tr>\n";
foreach my $pic (@pics) {
print "<tr><td><img src=PAsmall$pic alt=$pic><br>$pic</td>";
print "<td><input type=text name=\"$pic\"></td></tr>\n";
}
print "</table>\n";
print "<input type=submit value=OK>\n";
print "</form>\n";
print "</center></body></html>\n";
}
if (defined param('file')) {
&redirect;
}
else {
my $pwd = `pwd`;
chomp $pwd;
my $dbfile = relpath("$pwd");
&print_header;
&print_welcome;
&handleThisDir;
&print_footer;
}