#!/usr/bin/perl -w use strict; my $deposit_dir = "/home/public/dog-slow.org/blog"; my $time=time(); my $pid=$$; my $randnum=int(rand 65535)+1; my $file=".$time.$pid.$randnum.txt"; my @files; my $action; $ENV{"TZ"}="EST5EDT"; open (LOG, ">>$deposit_dir/.log"); open (FILE, ">$deposit_dir/$file") or die ("cant write to $deposit_dir/$file $!"); my $header=1; # if header == 1, we are in the header ; header == 0, body while (<>) { print LOG; # log everything, trust noone! if (/^Subject:(.*)/ and $header==1) { $action = $1 || "undef"; } $header=0 if /^$/; # skip header next unless $header==0; # skip header print FILE; } close (FILE); chmod 0644, "$deposit_dir/$file"; if ($action =~ /delete(.*)/) { my $filenum = $1; chomp $filenum; exit 1 unless $filenum =~ /^\.[\.0-9]+.txt$/; # stop any nefarious dir tree traversing and other shenanigans rename ("$deposit_dir/$filenum", "$deposit_dir/.a$filenum") if -f "$deposit_dir/$filenum"; unlink ("$deposit_dir/$file"); } build_daily(); exit 0; sub build_daily { # read dir opendir (DIR, "$deposit_dir") or die ("cant read dir $deposit_dir $!"); @files = grep /^\.[0-9].*\.txt$/, readdir DIR; closedir (DIR); @files = sort {$b cmp $a } (@files); # show only the last 10 days # @files = $files[0..9]; # oop, didn't work. # write index.html open (INDEX, ">$deposit_dir/.$file.index.html") or die ("Can't write temp index.html $!"); # header print INDEX ("\n\n\n\n\n"); open (MENU, "/home/public/dog-slow.org/.menu") or die; while () { print INDEX ; } close MENU; print INDEX ("

Blog

\n"); # contents foreach my $file (@files) { # get date my $date = localtime (substr($file,1,10)); # write line print INDEX ("

$date

\n"); print INDEX ("\n"); open (FILE, "$deposit_dir/$file") or die ("cant read file $file $!"); while () { print INDEX ("

") if /^$/; print INDEX; } close (FILE); } # footer print INDEX ("\n\n\n"); close (INDEX); # move tempfile into place rename ("$deposit_dir/.$file.index.html", "$deposit_dir/index.html") or die ("Cant move temp index.html to index.html $!"); chmod (0644, "$deposit_dir/index.html") or die ("Cant chmod index.html $!"); }