N
Nitin Thakur
Hi,
I have written a script, which lists text files from a directory on a
web page on our intranet site. I want to add search functionality to
this page so that users can grep a regular expression and it lists
those files. Is there any simple cgi/perl script available or can
somebody give me some pointers as to how to make one.
A speedy response would be appreciated.
Cheers
Nitin
Here is the code for the listing the files
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#!/usr/bin/perl -w
#Set Dir path.
$dir = "/reports/";
use CGI qw/:all/;
$query = new CGI;
@months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
chdir $dir;
#Open dir and start listing and take time.
opendir (DIR, "$dir") || die "Can not Reports: $!";
foreach (readdir DIR) {
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime) = stat $_;
next if !$dev;
next if /^\./;
$dates{$_} = $mtime;
$rdev = " ";
$gid = " ";
$ino = " ";
$size = " ";
$uid = " ";
$mode = " ";
$atime = " ";
$ctime = " ";
$nlink = " ";
}
closedir DIR || die "Can not close Dir: $!";
print $query->header;
print $query->title('Reports');
print <<EOF;
<H2> Previously Sent Mails: </H2>
EOF
print "<TABLE>\n";
foreach (sort { $dates{$b} <=> $dates{$a}} keys %dates) {
print "<TR><TD>\n";
print "<b>";
{
$href="$dir$_";
$href=~s%//%/%g;
print (qq%<A HREF="/reports/$_">$_/</A>%);
}
print "</b>";
$date = (localtime($dates{$_}))[3] . " " .
$months[(localtime($dates{$_}))[4]] . " " .
(localtime($dates{$_}))[5]. " " .
(localtime($dates{$_}))[2] . ":" .
sprintf("%02d", (localtime($dates{$_}))[1]);
print "<TD>";
print qq% [$date]%;
print "<BR>\n";
print "</TR>\n";
}
print "</TABLE>\n";
print $query->end_html;
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I have written a script, which lists text files from a directory on a
web page on our intranet site. I want to add search functionality to
this page so that users can grep a regular expression and it lists
those files. Is there any simple cgi/perl script available or can
somebody give me some pointers as to how to make one.
A speedy response would be appreciated.
Cheers
Nitin
Here is the code for the listing the files
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#!/usr/bin/perl -w
#Set Dir path.
$dir = "/reports/";
use CGI qw/:all/;
$query = new CGI;
@months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
chdir $dir;
#Open dir and start listing and take time.
opendir (DIR, "$dir") || die "Can not Reports: $!";
foreach (readdir DIR) {
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime) = stat $_;
next if !$dev;
next if /^\./;
$dates{$_} = $mtime;
$rdev = " ";
$gid = " ";
$ino = " ";
$size = " ";
$uid = " ";
$mode = " ";
$atime = " ";
$ctime = " ";
$nlink = " ";
}
closedir DIR || die "Can not close Dir: $!";
print $query->header;
print $query->title('Reports');
print <<EOF;
<H2> Previously Sent Mails: </H2>
EOF
print "<TABLE>\n";
foreach (sort { $dates{$b} <=> $dates{$a}} keys %dates) {
print "<TR><TD>\n";
print "<b>";
{
$href="$dir$_";
$href=~s%//%/%g;
print (qq%<A HREF="/reports/$_">$_/</A>%);
}
print "</b>";
$date = (localtime($dates{$_}))[3] . " " .
$months[(localtime($dates{$_}))[4]] . " " .
(localtime($dates{$_}))[5]. " " .
(localtime($dates{$_}))[2] . ":" .
sprintf("%02d", (localtime($dates{$_}))[1]);
print "<TD>";
print qq% [$date]%;
print "<BR>\n";
print "</TR>\n";
}
print "</TABLE>\n";
print $query->end_html;
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=