]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/http/url_rewriters/LFS/url_lfs_rewrite.pl.in
15 url_lfs_rewrite [--debug] --local-dir=/var/www/ [options]
19 Direct all request to files who are in a local directory to
20 a local web server hosting this directory.
22 This program uses Squid concurrency support.
30 Write debug info to stderr.
34 Directory path under which the scripts searches for files.
38 Scheme to use for the redirected URL.
44 Domain name to use for the redirected URL.
50 URL path to add as prefix for the redirected URL path.
52 If set it must end with a '/'.
54 Default: use the original URL path.
60 * The --local-dir parameter must end with a '/'. Otherwise no
61 file paths will be found.
63 * URL with no filename in the path can match directories on the local
64 filesystem and be wrongly redirected to the local web server.
66 * Any scheme name accepted by the Perl URL library can be used
67 as the --to-scheme parameter. However only schemes supported by
70 * URL containing query-string are not handled well and will not
71 be rewritten even if the base script or file exists on the local
76 url_rewrite_program /path/to/url_lfs_rewrite --local-dir=\var\www\localhost
77 url_rewrite_children 20 startup=1 idle=1 concurrency=25
78 url_rewrite_access deny CONNECT
79 url_rewrite_access deny to_localhost
82 This helper can redirect to any web server but only does so if there is
83 a file matching the URL path segment in the local filesystem. Normal
84 configuration requires a web server running on localhost serving up files
85 from a local disk (eg. \var\www\localhost). Configuration of that web
86 server is not covered here.
90 This program and documentation was written by I<Amos Jeffries <squid3@treenet.co.nz>>
92 Based on prior work in B<rredir.pl> by I<Peter Eisenhauer <pe@pipetronix.de>>.
93 First Version: 26. May 1997
97 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
99 * Squid software is distributed under GPLv2+ license and includes
100 * contributions from numerous individuals and organizations.
101 * Please see the COPYING and CONTRIBUTORS files for details.
103 =head1 REPORTING BUGS
105 Bug reports need to be made in English.
106 See http://wiki.squid-cache.org/SquidFaq/BugReporting for details of what you need to include with your bug report.
108 Report bugs or bug fixes using http://bugs.squid-cache.org/
110 Report serious security bugs to I<Squid Bugs <squid-bugs@squid-cache.org>>
112 Report ideas for new improvements to the I<Squid Developers mailing list <squid-dev@squid-cache.org>>
118 The Squid FAQ wiki http://wiki.squid-cache.org/SquidFaq
120 The Squid Configuration Manual http://www.squid-cache.org/Doc/config/
127 # command line parameters
129 my $access_local_dir = undef;
130 my $redirect_scheme = "http";
131 my $redirect_host = "localhost";
132 my $redirect_path = "";
136 'local-dir=s' => \
$access_local_dir,
137 'to-scheme=s' => \
$redirect_scheme,
138 'to-host=s' => \
$redirect_host,
139 'to-path=s' => \
$redirect_path,
142 # flush after every print
146 # Process lines of the form 'channel-ID URL ip-address/fqdn ident method'
147 # See http://wiki.squid-cache.org/Features/AddonHelpers for details
150 my ($cid, $url, $remainder) = split;
153 my $host = lc($url->host);
155 # do not process hosts with unqualified hostnames
156 if ($host !~ /\./ ) {
157 $status = $cid . " ERR message=\"unqualified hostname\"";
158 print "found unqualified hostname.\n" if $debug;
162 # just the file, without any host or path parts
163 # and just in case: lowercase the file name, so you should make sure
164 # all the files in the local dir are only lowercase !!
165 my $file = lc(basename
($url->path));
167 # look if in local dir, if yes redirect
168 if ( $file && -r
$access_local_dir . $file
169 && $file ne '.' && $file ne '..' ) {
171 $url->scheme($redirect_scheme);
172 $url->host($redirect_host);
173 $url->path($redirect_path . $file);
175 $status = $cid . " OK rewrite-url=\"" . $url . "\"";
176 print "file found: " . $file . "\n" if $debug;
178 $status = $cid . " ERR";
179 print "file not found: " . $file . "\n" if $debug;
183 print $status . "\n";