| 1 |
#!/usr/bin/perl |
| 2 |
# Special purpose plugin that takes advantage of ikiwiki being configured |
| 3 |
# as the 404 handler, and *always* displays missingsite.tmpl. |
| 4 |
# |
| 5 |
# One special-purpose site per web server can be configured to use this |
| 6 |
# plugin, and set as apache's default site. This way, attempts to access |
| 7 |
# sites that have been deleted or are not created yet will display a |
| 8 |
# useful error message. |
| 9 |
# |
| 10 |
# Put this in the apache config template for the missingsite (eg, in |
| 11 |
# /etc/ikiwiki-hosting/config/b-missingsite/apache.conf.tmpl): |
| 12 |
# DirectoryIndex index.html ikiwiki.cgi |
| 13 |
package IkiWiki::Plugin::missingsite; |
| 14 |
|
| 15 |
use warnings; |
| 16 |
use strict; |
| 17 |
use IkiWiki 3.00; |
| 18 |
use IkiWiki::Hosting; |
| 19 |
|
| 20 |
sub import { |
| 21 |
hook(type => "cgi", id => 'missingsite', call => \&cgi); |
| 22 |
hook(type => "getsetup", id => 'missingsite', call => \&getsetup); |
| 23 |
hook(type => "genwrapper", id => 'missingsite', call => \&genwrapper); |
| 24 |
} |
| 25 |
|
| 26 |
sub getsetup () { |
| 27 |
return |
| 28 |
plugin => { |
| 29 |
safe => 0, |
| 30 |
rebuild => 0, |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
sub cgi ($) { |
| 35 |
my $cgi=shift; |
| 36 |
|
| 37 |
print STDERR "missing site: $ENV{SERVER_NAME}\n"; |
| 38 |
|
| 39 |
my $template=IkiWiki::Hosting::ikisite_template("missingsite.tmpl"); |
| 40 |
$template->param(SERVER_NAME => $ENV{SERVER_NAME}); |
| 41 |
IkiWiki::cgi_custom_failure( |
| 42 |
$cgi, |
| 43 |
"404 Not Found", |
| 44 |
$template->output, |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub genwrapper () { |
| 49 |
# Pass SERVER_NAME through the wrapper. |
| 50 |
return <<EOF; |
| 51 |
if ((s=getenv("SERVER_NAME"))) |
| 52 |
addenv("SERVER_NAME", s); |
| 53 |
EOF |
| 54 |
} |
| 55 |
|
| 56 |
1; |