Skip to content

Commit

Permalink
Item13483: added compatibility to Foswiki-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Jul 17, 2015
1 parent 16cded5 commit bf3cfcf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/xsendfile
Expand Up @@ -30,7 +30,7 @@ $Foswiki::engine->run();
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2013 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2015 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
13 changes: 11 additions & 2 deletions data/System/XSendFileContrib.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1409330875" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1437154671" format="1.1" version="1"}%
---+!! %TOPIC%
%TOC%

Expand Down Expand Up @@ -94,8 +94,16 @@ location /protected_files {

---++ Configuring Apache2
Apache itself requires an additional simple module that processes an *X-Sendfile* header.
In a classical Foswiki Apache2 installation you have to modify your web server configuration as follows:

<verbatim>
XSendFile on
XSendFilePath /path/to/pub
RewriteRule ^/+pub/+(.*)$ /bin/xsendfile/$1 [L,PT]
</verbatim>

See https://tn123.org/mod_xsendfile/ for more information on how to compile =mod_xsendfile= and how to configure apache.

---++ Installation
%$INSTALL_INSTRUCTIONS%

Expand All @@ -108,11 +116,12 @@ One line description, required for extensions repository catalog.
-->

| Author: | Michael Daum |
| Copyright &copy;: | 2013-2014, Michael Daum http://michaeldaumconsulting.com |
| Copyright &copy;: | 2013-2015, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 17 Jul 2015 | added support for Foswiki-2.0 |
| 29 Aug 2014 | improved decoding and untainting url components |
| 28 May 2014 | fixed file check on wrong location |
| 15 Apr 2014 | untaint attachment filenames |
Expand Down
16 changes: 9 additions & 7 deletions lib/Foswiki/Contrib/XSendFileContrib.pm
@@ -1,6 +1,6 @@
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2013-2014 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2013-2015 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -24,8 +24,8 @@ use Foswiki::Func ();
use Foswiki::Time ();
use File::MMagic ();

our $VERSION = '3.10';
our $RELEASE = '3.10';
our $VERSION = '4.00';
our $RELEASE = '17 Jul 2015';
our $SHORTDESCRIPTION = 'A viewfile replacement to send static files efficiently';
our $mimeTypeInfo;
our $mmagic;
Expand Down Expand Up @@ -146,8 +146,10 @@ sub xsendfile {

my $headerName = $Foswiki::cfg{XSendFileContrib}{Header} || 'X-LIGHTTPD-send-file';

$fileName = Encode::encode_utf8($fileName);
$fileLocation = Encode::encode_utf8($fileLocation);
unless ($Foswiki::UNICODE) {
$fileName = Encode::encode_utf8($fileName);
$fileLocation = Encode::encode_utf8($fileLocation);
}

if ($lastModified eq $ifModifiedSince) {
$response->header(
Expand Down Expand Up @@ -175,7 +177,7 @@ sub checkAccess {
my $web = $topicObject->web;
my $topic = $topicObject->topic;
foreach my $rule (@{$Foswiki::cfg{XSendFileContrib}{AccessRules}}) {
#print STDERR "rule: web=$rule->{web}, topic=$rule->{topic}, file=$rule->{file}, requiredAccess=$rule->{requiredAccess}\n";
#print STDERR "rule: web=".($rule->{web}||'').", topic=".($rule->{topic}||'').", file=".($rule->{file}||'').", requiredAccess=".($rule->{requiredAccess}||'')."\n";
if ((!defined($rule->{web}) || $web =~ /^$rule->{web}$/) &&
(!defined($rule->{topic}) || $topic =~ /^$rule->{topic}$/) &&
(!defined($rule->{file}) || $fileName =~ /^$rule->{file}$/)) {
Expand Down Expand Up @@ -223,7 +225,7 @@ sub sanitizeAttachmentName {

$fileName =~ s{[\\/]+$}{}; # Get rid of trailing slash/backslash (unlikely)
$fileName =~ s!^.*[\\/]!!; # Get rid of leading directory components
$fileName =~ s/[\*?~^\$@%`"'&;|<>\[\]#\x00-\x1f\(\)]//g; # Get rid of a subset of Namefilter
$fileName =~ s/[\*?~^\$@%`"'&;|<>\[\]#\x00-\x1f]//g; # Get rid of a subset of Namefilter

return Foswiki::Sandbox::untaintUnchecked($fileName);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Foswiki/Contrib/XSendFileContrib/Config.spec
Expand Up @@ -8,14 +8,14 @@ $Foswiki::cfg{SwitchBoard}{xsendfile} = ['Foswiki::Contrib::XSendFileContrib', '
# Enable efficient delivery of static files
# using the xsendfile feature available in apache, nginx and lighttpd.
# Use <ul>
# <li>X-Sendfile for Apache2 <li>
# <li>X-LIGHTTPD-send-file for Lighttpd<li>
# <li>X-Accel-Redirect for Nginx<li>
# <li>X-Sendfile for Apache2 </li>
# <li>X-LIGHTTPD-send-file for Lighttpd</li>
# <li>X-Accel-Redirect for Nginx</li>
# </ul>
# Note that you will need to configure your http server accordingly.
$Foswiki::cfg{XSendFileContrib}{Header} = 'none';

# **PATH M**
# **PATH**
# Location that the http server will process internally to send protected files.
# Leave it to {PubDir} for Lighttpd; use the <code>/protected_files</code> location
# as configured for an Nginx.
Expand Down
2 changes: 1 addition & 1 deletion tools/virtualhosts-xsendfile
Expand Up @@ -47,7 +47,7 @@ sub doit {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2013 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2015 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down

0 comments on commit bf3cfcf

Please sign in to comment.