# HG changeset patch # User Heiko Schlittermann # Date 1451916265 -3600 # Node ID 0bbcd830cecdf43048bb8b37f9584be01f97c993 # Parent b0f2dfaa34ac3608a392d47b8f6a73fd518fac62# Parent 33ff1832a0962ac08606e0ab3d4b8e4cd9963aa7 [merge] diff -r 33ff1832a096 -r 0bbcd830cecd bin/once --- a/bin/once Mon Jan 04 14:53:19 2016 +0100 +++ b/bin/once Mon Jan 04 15:04:25 2016 +0100 @@ -68,6 +68,7 @@ my $rxFILE = qr/[a-z\d]{6}-[a-z\d]+-[dme]/i; # date-filehash-removalmode my %TT_CONFIG = ( +# PROCESS => 'version.tt', INCLUDE_PATH => [ (map { catfile($Bin, $_) } qw(templates templates.default) ), #(map { catfile(dist_dir($DIST), $_) } qw(var templates.override templates)), @@ -150,7 +151,11 @@ # sanitize the filename my $filename = do { - $file =~ tr /\\/\//; + # FIXME: should we allow backslashes in filenames? It's totally legal for *nix, + # but may confuse win* users, for now we play safe and convert \ to _ + # OTOH, then we should convert other problematic chars too. + $file =~ tr /\\/\//; # convert \ to / + $file =~ s/.*\///; # poor man's basename $file =~ /(.*)/; $1; }; @@ -212,7 +217,7 @@ } $file{name} = $file; - $file{link} = "$ENV{PATH_INFO}/$dir$file"; + $file{link} = deslash "$ENV{PATH_INFO}/$dir$file"; $file{size} = humanize -s $_; $file{uploaded} = (stat _)[9]; $file{removal}{type} = $d; @@ -222,9 +227,9 @@ } } - $tt->process('inventory.html', \%tt) or die sprintf "template: %s\nINCLUDE_PATH:\n%s\n", - $tt->error(), - join "\n", @{$TT_CONFIG{INCLUDE_PATH}}; + $tt->process('inventory.html', \%tt) or + die sprintf "template: %s\nINCLUDE_PATH:\n%s\n", $tt->error(), + join "\n", map { "'$_'" } @{$TT_CONFIG{INCLUDE_PATH}}; return 0; } @@ -336,8 +341,12 @@ my $file = deslash realpath catfile $VAR, $+{path}; my $base = $+{base}; - unless (-f $file) { - print header('text/plain', '404 Not found'), 'Not found'; + if (not -f $file) { + my $tt = Template->new(\%TT_CONFIG) + or die $Template::ERROR; + my %tt = ( file => { name => $base }); + + $tt->process('not-found.html', \%tt) or die $tt->error(); exit 0; } diff -r 33ff1832a096 -r 0bbcd830cecd configs/apache.conf --- a/configs/apache.conf Mon Jan 04 14:53:19 2016 +0100 +++ b/configs/apache.conf Mon Jan 04 15:04:25 2016 +0100 @@ -10,26 +10,26 @@ # This directory needs to be r/w by the web server user # (wwwrun, www-data, who ever), but it must not be # accessible via HTTP(s) - + Require all denied Action once-handler /once-handler/once.cgi virtual ScriptAlias /once-handler/ $lib/ - Alias $location/public $lib/public + Alias $location/static $lib/static # Order of location blocks matters! # We handle requests to our script, with the exception (see below) - # for …/public/… requests. These should be answered from a simple + # for …/static/… requests. These should be answered from a simple # static directory for style sheets and similiar SetHandler once-handler - + SetHandler none - + Require all granted Allow from all diff -r 33ff1832a096 -r 0bbcd830cecd lib/version.PL --- a/lib/version.PL Mon Jan 04 14:53:19 2016 +0100 +++ b/lib/version.PL Mon Jan 04 15:04:25 2016 +0100 @@ -1,14 +1,16 @@ #! /usr/bin/perl my $outfile = shift; +my $now = localtime; chomp(my $version = `hg log -r . --template '{latesttag}-{latesttagdistance}-{node|short}\n'`); -my $now = localtime; -open(my $output, '>', $_ = $outfile) or die "Can't open $_: $!\n"; +if (defined $outfile) { + open(STDOUT, '>', $_ = $outfile) or die "Can't open $_: $!\n"; +} -print {$output} <<_; +print <<_; [%# autogenerated at $now by $0 %] [% vcs.version = "$version"; %] _ -utime 0, 0 => $outfile; +utime 0, 0 => $outfile diff -r 33ff1832a096 -r 0bbcd830cecd templates/README --- a/templates/README Mon Jan 04 14:53:19 2016 +0100 +++ b/templates/README Mon Jan 04 15:04:25 2016 +0100 @@ -1,2 +1,5 @@ Do not overwrite the files here. If you want to modify something, -put your versions to ../template.override/ +put your versions to "templates" in your lib directory. + + /usr/local/lib/once/templates/ for your modifications + /usr/local/lib/once/templates.default for default templates diff -r 33ff1832a096 -r 0bbcd830cecd templates/not-found.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/not-found.html Mon Jan 04 15:04:25 2016 +0100 @@ -0,0 +1,4 @@ +[% WRAPPER once.tt %] +

Sorry

+Das File [% file.name %] existiert (nicht) mehr. +[% END %] diff -r 33ff1832a096 -r 0bbcd830cecd templates/once.tt --- a/templates/once.tt Mon Jan 04 14:53:19 2016 +0100 +++ b/templates/once.tt Mon Jan 04 15:04:25 2016 +0100 @@ -3,7 +3,6 @@ [%- USE date; - PROCESS version.tt; -%] Once @@ -11,10 +10,12 @@ - + + [% content %] +
[% vcs.version %] | Scripting: Matthias Förste, Heiko Schlittermann