#!/usr/bin/perl -w
# nerxscode
# htmlmaker.pl
# 2001-01-09 20:33:00 nik@nerxs.com
# Makes html of nerxs-textfiles.
$date = `date "+%Y-%m-%d %H:%M:%S %Z"`;
chomp($date);
system("rm /home/nik/nerxs.com/error.html");
# get path from ARGV or die #########
if ($ARGV[0]) {
$path = $ARGV[0];
}
else {
print "Usage: htmlmaker.pl [DIR].\n";
exit;
}
# Prepare error log
open(ERROR, ">> /home/nik/nerxs.com/error.html") or die "errorlog could not be opend";
open (HEADER, "< /home/nik/makenerxs/Config/Templates/header.tpl") or die "could not open header.tpl: $!.";
while () {
foreach ($_) {
print ERROR $_ ;
}
}
print ERROR "
..: .: :.. . error log :.. .. :::: ...
";
close(HEADER);
close(ERROR);
# get all dirs #####################
@dirs = `find $path -type d`;
# get all subdirs and files ########
foreach $dir (@dirs) {
chomp ($dir);
@subs = `find $dir -maxdepth 1 -type d`;
@files = `find $dir -maxdepth 1 -type f -or -type l |grep -v \'\\.cat\$\'`;
# split the path into dirs #########
@splitdir = split("/", $dir);
# make new dirs ####################
# Test if $dir exists, if not create it
if (opendir(DIR, "/home/nik/$dir")) {
print "Verzeichnis /home/nik/$dir vorhanden.\n";
closedir(DIR);
}
else {
print "Verzeichnis /home/nik/$dir erstellen.\n";
system("mkdir /home/nik/$dir");
}
# prepare index.html in this dir
open(HTML, "> /home/nik/$dir/index.html") or die "DATEI /home/nik/nerxs.com/$splitdir[$#splitdir]/index.html: $!.";
open (HEADER, "< /home/nik/makenerxs/Config/Templates/header.tpl") or die "could not open header.tpl: $!.";
while () {
foreach ($_) {
print HTML $_ ;
}
}
close(HEADER);
# Print path and all subdirs to $dir/index.html
print HTML "
.::. .:. ";
$f = 0;
$fullpath = "";
for $i (0 ...$#splitdir) {
if ($i != 0 && $f > 0) {
print HTML "/ home";
$f++;
}
if ($splitdir[$i] ne "nerxs.com") {
$fullpath = $fullpath . "/$splitdir[$i]";
print HTML " / $splitdir[$i] ";
}
}
print HTML ".:. .. ::: :.. .:
";
foreach $sub (@subs) {
chomp ($sub);
if($sub ne $dir) {
@splitpath = split("/", $sub);
print HTML "
";
# Open every file and get its entries
foreach $file (@files) {
chomp ($file);
open(FH, "< $file") or die "could not open $file: $!.";
# print "Opening $file \n";
while() {
foreach ($_) {
($key, $val) = /^(\w+):\s*(.*)$/;
$HoH{$file}{$key} = $val;
}
}
close(FH);
}
# sort all files by the creation time key (CTIME)
foreach $site (reverse sort {$HoH{$a}{CTIME}<=>$HoH{$b}{CTIME} } keys (%HoH)) {
# write entries to $dir/index.html
# if the scriptkiddie bug is fixed change this line
chomp($HoH{$site}{'STATE'});
if (($HoH{$site}{'URL'} =~ "www.scriptkiddie.de") || ($HoH{$site}{'URL'} =~ /https:/)
|| ($HoH{$site}{'URL'} =~ /ftp:/)
|| ($HoH{$site}{'STATE'} eq "200 OK") || ($HoH{$site}{'STATE'} eq "200 Ok")
|| ($HoH{$site}{'STATE'} eq "200 ok") || ($HoH{$site}{'STATE'} =~ "200")) {
print HTML "
.: ..:
";
if ($dir eq "nerxs.com/New") {
print HTML "$HoH{$site}{'CTIME'} ";
}
print HTML "$HoH{$site}{'NAME'} \n";
print HTML " $HoH{$site}{'URL'} \n
";
print HTML "
$HoH{$site}{'DESCR'} \n";
print HTML " Last Modified: $HoH{$site}{'MODIF'} Last Checked: $HoH{$site}{'CHECK'} \n";
print HTML "
\n";
}
# if status not 200 OK put this entry on the error page
else {
if ($dir ne "nerxs.com/New") {
open(ERROR, ">> /home/nik/nerxs.com/error.html") or die "errorlog could not be opend";
print ERROR "
\n";
}
close(ERROR);
}
}
# write footer and close $dir/index.html
open (FOOTER, "< /home/nik/makenerxs/Config/Templates/footer.tpl") or die "could not open footer.tpl: $!.";
while (