aboutsummaryrefslogtreecommitdiff
path: root/lib/Apache
diff options
context:
space:
mode:
authorroot <root@rbsd.ankarstrom.se>2021-04-26 12:26:06 +0000
committerroot <root@rbsd.ankarstrom.se>2021-04-26 12:26:06 +0000
commite1c7d5442ca1d3bd67c200d2dbd94bd0e40e72bd (patch)
treefe2b3bb1c7e3612f05311d591f3704deb912fcd4 /lib/Apache
parente455862603e1ae1842b26bc9cbe685e5c4ee2d90 (diff)
downloadApache-Inject-e1c7d5442ca1d3bd67c200d2dbd94bd0e40e72bd.tar.gz
Use single hyphen for NULL value, allow the user to specify it
This lets the user inject a footer without injecting a header.
Diffstat (limited to 'lib/Apache')
-rw-r--r--lib/Apache/Inject.pm76
-rw-r--r--lib/Apache/Inject/Handler.pm14
2 files changed, 58 insertions, 32 deletions
diff --git a/lib/Apache/Inject.pm b/lib/Apache/Inject.pm
index 2c05b14..09bf18a 100644
--- a/lib/Apache/Inject.pm
+++ b/lib/Apache/Inject.pm
@@ -11,35 +11,31 @@ use Apache2::Const qw/OR_LIMIT OR_AUTHCFG TAKE12/;
use Apache2::Log ();
use Apache2::Module ();
-my @directives = (
- { name => 'Inject',
- func => __PACKAGE__.'::Inject',
- req_override => OR_LIMIT|OR_AUTHCFG,
- args_how => TAKE12,
- errmsg => 'Inject HeadFile[!] FootFile[!]' }
-);
+my @directives = ({
+ name => 'Inject',
+ func => __PACKAGE__.'::Inject',
+ req_override => OR_LIMIT|OR_AUTHCFG,
+ args_how => TAKE12,
+ errmsg => 'Inject HeadFile[!] FootFile[!]',
+});
Apache2::Module::add(__PACKAGE__, \@directives);
sub Inject {
my ($self, $parms, @args) = @_;
- for (@args) {
- if ($_ eq ' ') {
- $parms->server->log_error('Inject: Argument cannot be a single space');
- }
- }
-
# Construct directives for passing arguments to handler
my $head = $args[0];
- my $foot = $args[1] || ' '; # single space signifies absence of argument
+ my $foot = $args[1] || '-'; # single hyphen signifies absence of argument
$head =~ s/\\/\\\\/; s/"/\\"/;
$foot =~ s/\\/\\\\/; s/"/\\"/;
# Add relevant directives to current configuration
- $parms->add_config(['SetHandler perl-script',
- 'PerlResponseHandler Apache::Inject::Handler',
- qq{PerlSetVar InjectHead "$head"},
- qq{PerlSetVar InjectFoot "$foot"}]);
+ $parms->add_config([
+ 'SetHandler perl-script',
+ 'PerlResponseHandler Apache::Inject::Handler',
+ qq{PerlSetVar InjectHead "$head"},
+ qq{PerlSetVar InjectFoot "$foot"},
+ ]);
}
1;
@@ -54,11 +50,23 @@ Apache::Inject - Apache directive for injecting HTML headers and footers
LoadModule perl_module libexec/apache24/mod_perl.so
PerlLoadModule Apache::Inject
- DocumentRoot /uar/local/www/apache24/data
+ DocumentRoot /usr/local/www/apache24/data
+
<Directory /usr/local/www/apache24/data>
+ # Inject both header and footer on all pages on the server
Inject head.html foot.html
</Directory>
+ <Location /blog>
+ # Inject only header on pages under /blog
+ Inject head.html
+ </Location>
+
+ <Files index.html>
+ # Inject only footer on pages named index.html
+ Inject - foot.html
+ </Files>
+
=head1 DESCRIPTION
Apache::Inject is a mod_perl module that adds an Apache directive
@@ -129,6 +137,30 @@ an unprivileged user and will be skipped if they are run as root.
This is relevant if you install Apache::Inject via App::Cpan, which
normally runs as root.
+=head1 SYNTAX
+
+The Inject directive takes one or two arguments:
+
+ Inject HEADER_FILE [FOOTER_FILE]
+
+Each argument can consist of one of two things:
+
+=over
+
+=item 1.
+the path to a file relative to the document root, or
+
+=item 2.
+a single hyphen (C<->), signifying the absence of an argument.
+
+=back
+
+Passing a hyphen as the first argument disables the header, and
+passing a hyphen as the second argument disables the footer.
+
+If you leave out the second argument, then it is implicitly equivalent
+to a hyphen.
+
=head1 OPERATION
Behind the scenes, the Inject directive works as an alias for
@@ -160,12 +192,6 @@ Apache handle it as it would if the Inject directive were not used.
=over
-=item Error: Argument cannot be a single space
-
-In the current implementation, the file names given to Inject are
-not allowed to consist solely of a single space, as this is a special
-value signifying the absence of an argument.
-
=item Error: InjectHead/InjectFoot should not begin with slash, as
it is already always relative to document root
diff --git a/lib/Apache/Inject/Handler.pm b/lib/Apache/Inject/Handler.pm
index f9254fd..0e054e7 100644
--- a/lib/Apache/Inject/Handler.pm
+++ b/lib/Apache/Inject/Handler.pm
@@ -12,14 +12,14 @@ use Apache2::RequestUtil ();
my $doc = qr{
\A
(?<head> \s*
- (<!doctype[^>]*>)? \s*
- (<html[^>]*>)? \s*
- ( <head[^>]*>.*?</head> \s*
+ ( <!doctype[^>]*> )? \s*
+ ( <html[^>]*> )? \s*
+ ( <head[^>]*> .*? </head> \s*
| ( <meta[^>]*> \s*
| <link[^>]*> \s*
- | <title[^>]*>.*?</title> \s*
- | <style[^>]*>.*?</style> \s* # n.b.
- | <script[^>]*>.*?</script> \s* # n.b.
+ | <title[^>]*> .*? </title> \s*
+ | <style[^>]*> .*? </style> \s*
+ | <script[^>]*> .*? </script> \s*
| <base[^>]*> \s*
)+
)?
@@ -57,7 +57,7 @@ sub inject {
# Retrieve value implicitly set by Inject directive
return if not (my $val = $r->dir_config($var));
- return if $val eq ' '; # special value signifying absence of argument
+ return if $val eq '-'; # special value signifying absence of argument
# Validate path
if ($val =~ m{^/}) {