#!/usr/bin/perl
$directory = '/home/ftp/www/html/library';
$baseurl = '/library';
$index = 'index.html';
$out = "/home/ftp/www/html/library.html";
$bg0="#00008B";
#$bg1="#00688b";
$bg1="#262626";
open(OUT,">$out");
print OUT <AltBlue's HQ: Documentation Area
!Get yourself a headache!
HTML
$lineindex=0;
&copacel($directory);
print OUT <
$lineindex titles proccesed.
HTML
exit 0;
sub print_line {
local ($url,$title) = @_;
$lineindex += 1;
print OUT<<" HTML";
- $title
HTML
}
sub copacel {
local($dir) = shift;
local($path);
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
return undef;
}
# daca gasim $index ne oprim
if (-e "$dir/$index") {
closedir(DIR);
open(F,"$dir/$index");
my $file;
foreach(){
$file .= $_;
}
close(F);
$file =~ s/\n//g;
if($file =~ /(.*?)<\/title>/i) {
$title = $1;
} else {
$title = "UNKNOWN";
}
if($title =~ /^\s+$/ || !$title) {
$title = "UNKNOWN";
} else {
$title =~ s/^\s+//g; $title =~ s/\s+$//g;
}
$dir =~ s/^$directory/$baseurl/;
print_line($dir,$title);
return 1;
}
# daca nu gasim $index, inseamna k 3' sa coboram prin directoare
local $kk = $dir;
$kk =~ s/.*\///g;
print OUT "
- $kk :
\n";
local $idx = 0;
foreach (sort readdir(DIR)) {
next if $_ eq '.' || $_ eq '..';
$path = "$dir/$_";
if (-d $path) {
&copacel($path);
$idx += 1;
}
}
unless($idx) {
print_line($dir,'NO INDEX');
}
print OUT "
\n";
closedir(DIR);
}