Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add CGI script for randomly serving a file

mod_random simply did not work, always returned a 404
  • Loading branch information...
commit 18407b3d1c4763c32fb2bf92f90a109c848fa42e 1 parent ab0620f
@moritz moritz authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 source/
23 source/
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -T
+use strict;
+use warnings;
+print "Content-Type: text/html; charset=UTF-8\r\n\r\n";
+my $dir = '/var/www/';
+opendir my $DIR, $dir
+ or die "Cannot open dir '$dir': $!";
+my @files = grep !/^\./, readdir $DIR;
+closedir $DIR;
+my $fn = @files[rand @files];
+open my $file, '<:raw', "$dir$fn"
+ or die "Cannot open '$dir$fn' for reading: $!";
+binmode $fn;
+print while <$fn>;
+close $file;
+# vim: ft=perl
Please sign in to comment.
Something went wrong with that request. Please try again.