#!/usr/bin/perl
# File: whats-new.pl -*- Perl -*-
# Created by: Alex (wtwf.com) Fri Jul 21 10:56:39 1995
# Last Modified: Time-stamp: <26 Sep 96 2212 Alex>
# RCS $Id: whats-new,v 2.6 1997/01/03 01:32:27 aknowles Exp $
#!/usr/bin/perl
# original concept by Andrew kennedy adk@tardis.ed.ac.uk
$arkHOME="/ftp/ftproot/www/htdocs/people/ark";
$libdir="$arkHOME/lib/perl/";
require "$libdir/find.pl";
require "$libdir/sys/socket.ph";
require "$libdir/ark-lib.pl";
@months = (
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September','October', 'November', 'December'
);
$do_save_titles =0;
$oldest_file =0;
$commandline =0;
$all_files =0;
$stdout =0;
$outbase ="whatsnew.shtml";
print "File is @ARGV[0]\n";
if(true || $ENV{'QUERY_STRING'} =~ /all/i || $#ARGV>1){
print "Command line all files!\n";
$all_files=1;
$outbase="allfiles.shtml";
}
if( $ENV{'SERVER_NAME'} !~ /.+/ ){
print "Command line mode!\n";
$wwwdir ="$arkHOME/";
$wwwdir ="$arkHOME/" if @ARGV[0] =~ /\S+/;
$outfile =$outbase;
$titlesfile ="$arkHOME/.titles";
$ignorefile ="$arkHOME/.ignore";
$commandline=1;
} else {
$wwwdir ="$arkHOME";
$outfile ="$wwwdir/etc/$outbase";
$titlesfile ="$wwwdir/.titles";
$ignorefile ="$wwwdir/.ignore";
}
$searchdir=$wwwdir;
print "Searching in $wwwdir\n";
if($ENV{'QUERY_STRING'} =~ /dir=(\S+)/i){
$searchdir="$wwwdir/$1";
$stdout=1;
$outbase="$1";
}
# $oldest_file=(stat($ignorefile))[9];
print "Reading Ignore file\n" if( $commandline );
&get_ignore( $ignorefile );
print "Ignre file is $ignore\n";
print "Getting quick ref titles\n" if( $commandline );
&get_titles( $titlesfile );
&error("Directory does not exist") unless (-x $wwwdir);
print "Searching\n" if( $commandline );
&find($searchdir);
print "Done Searching\n" if( $commandline );
# only do something if the newest file is younger than the outfile.html file
if( true || $stdout || (-r $outfile && ((stat($outfile))[9] < $oldest_file)) || !-r $outfile){
print "Creating output $outfile\n" if( $commandline );
if( $stdout ){
&ARKprint_header();
} else {
&error("Couldn't write to file!") unless open(FILE,">$outfile");
select(FILE);
}
if( $all_files ){
@files = sort @found;
$lt="UL";
$title="All My HTML Pages";
} else {
@files = sort {$rtime{$b} <=> $rtime{$a}} @found;
$title="Last Modified Pages";
$lt="OL";
}
$title="$title Under $outbase" if $stdout;
print &ARKtitle($title);
print "\n<$lt>\n"; # lt is the list type
$curr_indent=0;
$last_prefix="";
foreach (@files) {
$file=$_;
$title=$titlea{$file};
if( $all_files ){
if( $file =~ /(\S+)\/([^\/]+|\.\/)$/ ){
$prefix=$1;
} else {
$prefix="";
}
if( $prefix ne $last_prefix ){
$indent=&indent_level( $file );
if( $indent < $curr_indent ){
while( $curr_indent != $indent ){
print "$lt>\n";
$curr_indent--;
}
} else {
if( $indent > $curr_indent ){
while( $curr_indent != $indent ){
print "<$lt>\n";
$curr_indent++;
}
}
}
$last_prefix=$prefix;
}
}
($sec,$min,$hour,$mday,$mon,$year) = gmtime($rtime{$file});
$file = "/~ark/$file" if( $commandline != 1 );
if( $title =~ /\S+/ ){
if( $all_files ){
# the end list stuff - it's a bit hacky, but it does what I want!
print "$lt>" if $file =~ /\.\/$/;
print "
$pages pages in total
\n"; } $user=$ENV{'REMOTE_IDENT'}; $user='someone' if $user !~ /\S+/; $machine=$ENV{'REMOTE_ADDR'}; $mach=&ARKip_to_addr($machine); if( $stdout ){ &ARKprint_created(); &ARKprint_back(); } &ARKprint_sig(); &ARKprint_end(); select(STDOUT); } else { print "Nothing to do!\n" if $commandline == 1 ; } sub indent_level { local( $str ) = @_; $indent=0; while( $str =~ /^[^\/\.]+\// ){ $str=~ s/^[^\/]+\///; $indent++; } return $indent; } # works out if we really want a file sub wanted { local($file_time); # ignore directories, symbolic links and non .html files return if (-d || -l || !-r || !/\.s?html$/ ); $basename = $name; # get rid of the full path gumf! $basename =~ s/$wwwdir\///; # get rid of index.html's turn them into ./ $basename =~ s/index\.s?html$/\.\//; # add this file if it is not in the ignore list if( $basename !~ /$ignore/ ){ push(@found, ($basename)); $ftime=(stat($name))[9]; $oldest_file=$ftime if $ftime > $oldest_file; $rtime{$basename}=$ftime; # get the title for this file if( $time{$basename} =~ /\S+/ && ($rtime{$basename} == $time{$basename}) ){ # quick lookup $title=$titlea{$basename}; } else { $title=&ARKgettitle( $name ); if( $title =~ /\S+/ ){ $time{$basename}=$ftime; $titlea{$basename}=$title; $do_save_titles=1; } else { # $titlea{$basename}="File: $basename"; print "Can't find title of: $basename\n"; pop(@found); # exit(10); } } } else { print "Ignored $basename!!!!!!!!!!!!!!!!!!!!!\n"; } } # reads in the file of html files to ignore sub get_ignore { local($file)=@_; local(@ignores)=(); if( -r $file && open(IFILE,"<$file")){ while(There was an error in my what's new script sorry!
\n"; print "$str\n"; print "I may be working on it try it again some other time\n"; &ARKprint_sig(); &ARKprint_end(); } exit 0; } # redirect it to the right place! if( $commandline ){ print "Done\n"; } else { if( !$stdout ){ $outfile =~ s/^$wwwdir/\/~ark/; print "Location: http://www.tardis.ed.ac.uk$outfile\n\n"; } } if( $do_save_titles != 0 ){ &save_titles( $titlesfile ); }