summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorArno Töll <arno@debian.org>2012-11-21 23:03:46 +0100
committerArno Töll <arno@debian.org>2012-11-21 23:03:46 +0100
commit0f22664a8c9f92c8b7d5dd05772bacf7caecbd52 (patch)
treec85da4e4968e5ec69d6d154fa032672f45cb3e13 /doc
parent9fa7c3d770fb8688555b661940e04c3bf6b6d8aa (diff)
downloadlighttpd-0f22664a8c9f92c8b7d5dd05772bacf7caecbd52.tar.gz
Imported Upstream version 1.4.15upstream/1.4.15
Diffstat (limited to 'doc')
-rw-r--r--doc/Makefile.am8
-rw-r--r--doc/Makefile.in113
-rw-r--r--doc/extforward.txt96
-rw-r--r--doc/magnet.txt429
4 files changed, 591 insertions, 55 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am
index eeaae74..6be113b 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -6,6 +6,7 @@ authentication.txt \
cgi.txt \
compress.txt \
configuration.txt \
+extforward.txt \
fastcgi-state.txt \
fastcgi.txt \
features.txt \
@@ -35,13 +36,15 @@ trigger_b4_dl.txt \
webdav.txt \
expire.txt \
dirlisting.txt \
-evhost.txt
+evhost.txt \
+magnet.txt
HTMLDOCS=accesslog.html \
authentication.html \
cgi.html \
compress.html \
configuration.html \
+ extforward.html \
fastcgi-state.html \
fastcgi.html \
features.html \
@@ -71,7 +74,8 @@ HTMLDOCS=accesslog.html \
webdav.html \
expire.html \
dirlisting.html \
- evhost.html
+ evhost.html \
+ magnet.html
EXTRA_DIST=lighttpd.conf lighttpd.user \
rc.lighttpd rc.lighttpd.redhat sysconfig.lighttpd \
diff --git a/doc/Makefile.in b/doc/Makefile.in
index 4391fa2..aa2761d 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -1,8 +1,8 @@
-# Makefile.in generated by automake 1.9.5 from Makefile.am.
+# Makefile.in generated by automake 1.10 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005 Free Software Foundation, Inc.
+# 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -13,15 +13,11 @@
# PARTICULAR PURPOSE.
@SET_MAKE@
-srcdir = @srcdir@
-top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
-top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
@@ -54,8 +50,6 @@ NROFF = nroff
MANS = $(dist_man1_MANS)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
-AMDEP_FALSE = @AMDEP_FALSE@
-AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
ATTR_LIB = @ATTR_LIB@
@@ -67,12 +61,8 @@ BZ_LIB = @BZ_LIB@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
-CHECK_WITH_FASTCGI_FALSE = @CHECK_WITH_FASTCGI_FALSE@
-CHECK_WITH_FASTCGI_TRUE = @CHECK_WITH_FASTCGI_TRUE@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CROSS_COMPILING_FALSE = @CROSS_COMPILING_FALSE@
-CROSS_COMPILING_TRUE = @CROSS_COMPILING_TRUE@
CRYPT_LIB = @CRYPT_LIB@
CXX = @CXX@
CXXCPP = @CXXCPP@
@@ -93,6 +83,8 @@ FAM_CFLAGS = @FAM_CFLAGS@
FAM_LIBS = @FAM_LIBS@
FFLAGS = @FFLAGS@
GDBM_LIB = @GDBM_LIB@
+GREP = @GREP@
+INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
@@ -108,15 +100,12 @@ LTLIBOBJS = @LTLIBOBJS@
LUA_CFLAGS = @LUA_CFLAGS@
LUA_LIBS = @LUA_LIBS@
MAINT = @MAINT@
-MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
-MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
MEMCACHE_LIB = @MEMCACHE_LIB@
+MKDIR_P = @MKDIR_P@
MYSQL_CONFIG = @MYSQL_CONFIG@
MYSQL_INCLUDE = @MYSQL_INCLUDE@
MYSQL_LIBS = @MYSQL_LIBS@
-NO_RDYNAMIC_FALSE = @NO_RDYNAMIC_FALSE@
-NO_RDYNAMIC_TRUE = @NO_RDYNAMIC_TRUE@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
@@ -137,21 +126,18 @@ SQLITE_LIBS = @SQLITE_LIBS@
SSL_LIB = @SSL_LIB@
STRIP = @STRIP@
U = @U@
+UUID_LIBS = @UUID_LIBS@
VERSION = @VERSION@
XML_CFLAGS = @XML_CFLAGS@
XML_LIBS = @XML_LIBS@
Z_LIB = @Z_LIB@
-ac_ct_AR = @ac_ct_AR@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
-ac_ct_RANLIB = @ac_ct_RANLIB@
-ac_ct_STRIP = @ac_ct_STRIP@
-ac_pt_PKG_CONFIG = @ac_pt_PKG_CONFIG@
-am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
-am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
-am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
-am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
@@ -163,38 +149,50 @@ build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
+builddir = @builddir@
datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
+htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
+localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
+psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
dist_man1_MANS = lighttpd.1 spawn-fcgi.1
DOCS = accesslog.txt \
authentication.txt \
cgi.txt \
compress.txt \
configuration.txt \
+extforward.txt \
fastcgi-state.txt \
fastcgi.txt \
features.txt \
@@ -224,13 +222,15 @@ trigger_b4_dl.txt \
webdav.txt \
expire.txt \
dirlisting.txt \
-evhost.txt
+evhost.txt \
+magnet.txt
HTMLDOCS = accesslog.html \
authentication.html \
cgi.html \
compress.html \
configuration.html \
+ extforward.html \
fastcgi-state.html \
fastcgi.html \
features.html \
@@ -260,7 +260,8 @@ HTMLDOCS = accesslog.html \
webdav.html \
expire.html \
dirlisting.html \
- evhost.html
+ evhost.html \
+ magnet.html
EXTRA_DIST = lighttpd.conf lighttpd.user \
rc.lighttpd rc.lighttpd.redhat sysconfig.lighttpd \
@@ -309,13 +310,9 @@ mostlyclean-libtool:
clean-libtool:
-rm -rf .libs _libs
-
-distclean-libtool:
- -rm -f libtool
-uninstall-info-am:
install-man1: $(man1_MANS) $(man_MANS)
@$(NORMAL_INSTALL)
- test -z "$(man1dir)" || $(mkdir_p) "$(DESTDIR)$(man1dir)"
+ test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)"
@list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \
l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \
for i in $$l2; do \
@@ -366,22 +363,21 @@ CTAGS:
distdir: $(DISTFILES)
- @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
- topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
- list='$(DISTFILES)'; for file in $$list; do \
- case $$file in \
- $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
- $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
- esac; \
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
- dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
- if test "$$dir" != "$$file" && test "$$dir" != "."; then \
- dir="/$$dir"; \
- $(mkdir_p) "$(distdir)$$dir"; \
- else \
- dir=''; \
- fi; \
if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
@@ -397,7 +393,7 @@ check: check-am
all-am: Makefile $(MANS)
installdirs:
for dir in "$(DESTDIR)$(man1dir)"; do \
- test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
@@ -429,7 +425,7 @@ clean-am: clean-generic clean-libtool clean-local mostlyclean-am
distclean: distclean-am
-rm -f Makefile
-distclean-am: clean-am distclean-generic distclean-libtool
+distclean-am: clean-am distclean-generic
dvi: dvi-am
@@ -441,12 +437,20 @@ info-am:
install-data-am: install-man
+install-dvi: install-dvi-am
+
install-exec-am:
+install-html: install-html-am
+
install-info: install-info-am
install-man: install-man1
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
installcheck-am:
maintainer-clean: maintainer-clean-am
@@ -465,20 +469,23 @@ ps: ps-am
ps-am:
-uninstall-am: uninstall-info-am uninstall-man
+uninstall-am: uninstall-man
uninstall-man: uninstall-man1
+.MAKE: install-am install-strip
+
.PHONY: all all-am check check-am clean clean-generic clean-libtool \
clean-local distclean distclean-generic distclean-libtool \
distdir dvi dvi-am html html-am info info-am install \
- install-am install-data install-data-am install-exec \
- install-exec-am install-info install-info-am install-man \
- install-man1 install-strip installcheck installcheck-am \
+ install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-man1 install-pdf install-pdf-am install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
- ps ps-am uninstall uninstall-am uninstall-info-am \
- uninstall-man uninstall-man1
+ ps ps-am uninstall uninstall-am uninstall-man uninstall-man1
%.html: %.txt
diff --git a/doc/extforward.txt b/doc/extforward.txt
new file mode 100644
index 0000000..af4f2a8
--- /dev/null
+++ b/doc/extforward.txt
@@ -0,0 +1,96 @@
+==============
+mod_extforward
+==============
+
+.. contents::
+
+Overview
+========
+
+Comman Kang <comman.kang at gmail.com> sent me: ::
+
+ Hello jan.
+
+ I've made something rough but similar to mod_extract_forwarded for
+ Apache. This module will extract the client's "real" ip from
+ X-Forwarded-For header which is added by squid or other proxies. It might be
+ useful for servers behind reverse proxy servers.
+
+ However, this module is causing segfault with mod_ssl or
+ $HTTP{''socket"} directive, crashing in config_check_cond while patching
+ connection , I do not understand architecture of the lighttpd well, does it
+ need to call patch_connection in either handle_request_done and
+ connection_reset ?
+
+Lionel Elie Mamane <lionel@mamane.lu> improved the patch: ::
+
+ I've taken lighttpd-1.4.10-mod_extforward.c from the wiki and I've
+ extended it. Here is the result.
+
+ Major changes:
+
+ - IPv6 support
+
+ - Fixed at least one segfault with SERVER['socket']
+
+ - Arrange things so that a url.access-deny under scope of a
+ HTTP['remoteip'] condition works well :)
+
+ I've commented the code in some places, mostly where I wasn't sure
+ what was going on, or I didn't see what the original author meant to
+ do.
+
+Options
+=======
+
+extforward.forwarder
+ Sets trust level of proxy IP's.
+
+ Default: empty
+
+ Example: ::
+
+ extforward.forwarder = ("10.0.0.232" => "trust")
+
+ will translate ip addresses coming from 10.0.0.232 to real ip addresses extracted from X-Forwarded-For: HTTP request header.
+
+Note
+=======
+
+The effect of this module is variable on $HTTP["remotip"] directives and other module's remote ip dependent actions.
+Things done by modules before we change the remoteip or after we reset it will match on the proxy's IP.
+Things done in between these two moments will match on the real client's IP.
+The moment things are done by a module depends on in which hook it does things and within the same hook
+on whether they are before/after us in the module loading order
+(order in the server.modules directive in the config file).
+
+Tested behaviours:
+
+ mod_access: Will match on the real client.
+
+ mod_accesslog:
+ In order to see the "real" ip address in access log ,
+ you'll have to load mod_extforward after mod_accesslog.
+ like this: ::
+
+ server.modules = (
+ .....
+ mod_accesslog,
+ mod_extforward
+ )
+
+Samples
+=======
+
+Trust proxy 10.0.0.232 and 10.0.0.232 ::
+
+ extforward.forwarder = (
+ "10.0.0.232" => "trust",
+ "10.0.0.233" => "trust",
+ )
+
+Trust all proxies (NOT RECOMMENDED!) ::
+
+ extforward.forwarder = ( "all" => "trust")
+
+Note that "all" has precedence over specific entries, so "all except" setups will not work.
diff --git a/doc/magnet.txt b/doc/magnet.txt
new file mode 100644
index 0000000..9d7697a
--- /dev/null
+++ b/doc/magnet.txt
@@ -0,0 +1,429 @@
+{{{
+#!rst
+==============
+a power-magnet
+==============
+
+------------------
+Module: mod_magnet
+------------------
+
+
+
+.. contents:: Table of Contents
+
+Requirements
+============
+
+:Version: lighttpd 1.4.12 or higher
+:Packages: lua >= 5.1
+
+Overview
+========
+
+mod_magnet is a module to control the request handling in lighty.
+
+.. note::
+
+ Keep in mind that the magnet is executed in the core of lighty. EVERY long-running operation is blocking
+ ALL connections in the server. You are warned. For time-consuming or blocking scripts use mod_fastcgi and friends.
+
+For performance reasons mod_magnet caches the compiled script. For each script-run the script itself is checked for
+freshness and recompile if neccesary.
+
+
+Installation
+============
+
+mod_magnet needs a lighty which is compiled with the lua-support ( --with-lua). Lua 5.1 or higher are required by
+the module. Use "--with-lua=lua5.1" to install on Debian and friends. ::
+
+ server.modules = ( ..., "mod_magnet", ... )
+
+Options
+=======
+
+mod_magnet can attract a request in several stages in the request-handling.
+
+* either at the same level as mod_rewrite, before any parsing of the URL is done
+* or at a later stage, when the doc-root is known and the physical-path is already setup
+
+It depends on the purpose of the script which stage you want to intercept. Usually you want to use
+the 2nd stage where the physical-path which relates to your request is known. At this level you
+can run checks against lighty.env["physical.path"].
+
+::
+
+ magnet.attract-raw-url-to = ( ... )
+ magnet.attract-physical-path-to = ( ... )
+
+You can define multiple scripts when separated by a semicolon. The scripts are executed in the specified
+order. If one of them a returning a status-code, the following scripts will not be executed.
+
+Tables
+======
+
+Most of the interaction between between mod_magnet and lighty is done through tables. Tables in lua are hashes (Perl), dictionaries (Java), arrays (PHP), ...
+
+Request-Environment
+-------------------
+
+Lighttpd has its internal variables which are exported as read/write to the magnet.
+
+If "http://example.org/search.php?q=lighty" is requested this results in a request like ::
+
+ GET /search.php?q=lighty HTTP/1.1
+ Host: example.org
+
+When you are using ``attract-raw-url-to`` you can access the following variables:
+
+* parts of the request-line
+
+ * lighty.env["request.uri"] = "/search.php?q=lighty"
+
+* HTTP request-headers
+
+ * lighty.request["Host"] = "example.org"
+
+Later in the request-handling, the URL is splitted, cleaned up and turned into a physical path name:
+
+* parts of the URI
+
+ * lighty.env["uri.path"] = "/search.php"
+ * lighty.env["uri.path-raw"] = "/search.php"
+ * lighty.env["uri.scheme"] = "http"
+ * lighty.env["uri.authority"] = "example.org"
+ * lighty.env["uri.query"] = "q=lighty"
+
+* filenames, pathnames
+
+ * lighty.env["physical.path"] = "/my-docroot/search.php"
+ * lighty.env["physical.rel-path"] = "/search.php"
+ * lighty.env["physical.doc-root"] = "/my-docroot"
+
+All of them are readable, not all of the are writable (or don't have an effect if you write to them).
+
+As a start, you might want to use those variables for writing: ::
+
+ -- 1. simple rewriting is done via the request.uri
+ lighty.env["request.uri"] = ...
+ return lighty.RESTART_REQUEST
+
+ -- 2. changing the physical-path
+ lighty.env["physical.path"] = ...
+
+ -- 3. changing the query-string
+ lighty.env["uri.query"] = ...
+
+Response Headers
+----------------
+
+If you want to set a response header for your request, you can add a field to the lighty.header[] table: ::
+
+ lighty.header["Content-Type"] = "text/html"
+
+Sending Content
+===============
+
+You can generate your own content and send it out to the clients. ::
+
+ lighty.content = { "<pre>", { filename = "/etc/passwd" }, "</pre>" }
+ lighty.header["Content-Type"] = "text/html"
+
+ return 200
+
+The lighty.content[] table is executed when the script is finished. The elements of the array are processed left to right and the elements can either be a string or a table. Strings are included AS IS into the output of the request.
+
+* Strings
+
+ * are included as is
+
+* Tables
+
+ * filename = "<absolute-path>" is required
+ * offset = <number> [default: 0]
+ * length = <number> [default: size of the file - offset]
+
+Internally lighty will use the sendfile() call to send out the static files at full speed.
+
+Status Codes
+============
+
+You might have seen it already in other examples: In case you are handling the request completly in the magnet you
+can return your own status-codes. Examples are: Redirected, Input Validation, ... ::
+
+ if (lighty.env["uri.scheme"] == "http") then
+ lighty.header["Location"] = "https://" .. lighty.env["uri.authority"] .. lighty.env["request.uri"]
+ return 302
+ end
+
+You every number above and equal to 100 is taken as final status code and finishes the request. No other modules are
+executed after this return.
+
+A special return-code is lighty.RESTART_REQUEST (currently equal to 99) which is usually used in combination with
+changing the request.uri in a rewrite. It restarts the splitting of the request-uri again.
+
+If you return nothing (or nil) the request-handling just continues.
+
+Debugging
+=========
+
+To easy debugging we overloaded the print()-function in lua and redirect the output of print() to the error-log. ::
+
+ print("Host: " .. lighty.request["Host"])
+ print("Request-URI: " .. lighty.env["request.uri"])
+
+
+Examples
+========
+
+Sending text-files as HTML
+--------------------------
+
+This is a bit simplistic, but it illustrates the idea: Take a text-file and cover it in a <pre> tag.
+
+Config-file ::
+
+ magnet.attract-physical-path-to = server.docroot + "/readme.lua"
+
+readme.lua ::
+
+ lighty.content = { "<pre>", { filename = "/README" }, "</pre>" }
+ lighty.header["Content-Type"] = "text/html"
+
+ return 200
+
+Maintainance pages
+------------------
+
+Your side might be on maintainance from time to time. Instead of shutting down the server confusing all
+users, you can just send a maintainance page.
+
+Config-file ::
+
+ magnet.attract-physical-path-to = server.docroot + "/maintainance.lua"
+
+maintainance.lua ::
+
+ require "lfs"
+
+ if (nil == lfs.attributes(lighty.env["physical.doc-root"] .. "/maintainance.html")) then
+ lighty.content = ( lighty.env["physical.doc-root"] .. "/maintainance.html" )
+
+ lighty.header["Content-Type"] = "text/html"
+
+ return 200
+ end
+
+mod_flv_streaming
+-----------------
+
+Config-file ::
+
+ magnet.attract-physical-path-to = server.docroot + "/flv-streaming.lua"
+
+flv-streaming.lua::
+
+ if (lighty.env["uri.query"]) then
+ -- split the query-string
+ get = {}
+ for k, v in string.gmatch(lighty.env["uri.query"], "(%w+)=(%w+)") do
+ get[k] = v
+ end
+
+ if (get["start"]) then
+ -- missing: check if start is numeric and positive
+
+ -- send te FLV header + a seek into the file
+ lighty.content = { "FLV\x1\x1\0\0\0\x9\0\0\0\x9",
+ { filename = lighty.env["physical.path"], offset = get["start"] } }
+ lighty.header["Content-Type"] = "video/x-flv"
+
+ return 200
+ end
+ end
+
+
+selecting a random file from a directory
+----------------------------------------
+
+Say, you want to send a random file (ad-content) from a directory.
+
+To simplify the code and to improve the performance we define:
+
+* all images have the same format (e.g. image/png)
+* all images use increasing numbers starting from 1
+* a special index-file names the highest number
+
+Config ::
+
+ server.modules += ( "mod_magnet" )
+ magnet.attract-physical-path-to = "random.lua"
+
+random.lua ::
+
+ dir = lighty.env["physical.path"]
+
+ f = assert(io.open(dir .. "/index", "r"))
+ maxndx = f:read("*all")
+ f:close()
+
+ ndx = math.random(maxndx)
+
+ lighty.content = { { filename = dir .. "/" .. ndx }}
+ lighty.header["Content-Type"] = "image/png"
+
+ return 200
+
+denying illegal character sequences in the URL
+----------------------------------------------
+
+Instead of implementing mod_security, you might just want to apply filters on the content
+and deny special sequences that look like SQL injection.
+
+A common injection is using UNION to extend a query with another SELECT query.
+
+::
+
+ if (string.find(lighty.env["request.uri"], "UNION%s")) then
+ return 400
+ end
+
+Traffic Quotas
+--------------
+
+If you only allow your virtual hosts a certain amount for traffic each month and want to
+disable them if the traffic is reached, perhaps this helps: ::
+
+ host_blacklist = { ["www.example.org"] = 0 }
+
+ if (host_blacklist[lighty.request["Host"]]) then
+ return 404
+ end
+
+Just add the hosts you want to blacklist into the blacklist table in the shown way.
+
+Complex rewrites
+----------------
+
+If you want to implement caching on your document-root and only want to regenerate
+content if the requested file doesn't exist, you can attract the physical.path: ::
+
+ magnet.attract-physical-path-to = ( server.document-root + "/rewrite.lua" )
+
+rewrite.lua ::
+
+ require "lfs"
+
+ attr = lfs.attributes(lighty.env["physical.path"])
+
+ if (not attr) then
+ -- we couldn't stat() the file for some reason
+ -- let the backend generate it
+
+ lighty.env["uri.path"] = "/dispatch.fcgi"
+ lighty.env["physical.rel-path"] = lighty.env["uri.path"]
+ lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
+ fi
+
+luafilesystem
++++++++++++++
+
+We are requiring the lua-module 'lfs' (http://www.keplerproject.org/luafilesystem/).
+
+I had to compile lfs myself for lua-5.1 which required a minor patch as compat-5.1 is not needed::
+
+ $ wget http://luaforge.net/frs/download.php/1487/luafilesystem-1.2.tar.gz
+ $ wget http://www.lighttpd.net/download/luafilesystem-1.2-lua51.diff
+ $ gzip -cd luafilesystem-1.2.tar.gz | tar xf -
+ $ cd luafilesystem-1.2
+ $ patch -ls -p1 < ../luafilesystem-1.2-lua51.diff
+ $ make install
+
+It will install lfs.so into /usr/lib/lua/5.1/ which is where lua expects the extensions on my system.
+
+SuSE and Gentoo are known to have their own lfs packages and don't require a compile.
+
+Usertracking
+------------
+
+... or how to store data globally in the script-context:
+
+Each script has its own script-context. When the script is started it only contains the lua-functions
+and the special lighty.* name-space. If you want to save data between script runs, you can use the global-script
+context:
+
+::
+
+ if (nil == _G["usertrack"]) then
+ _G["usertrack"] = {}
+ end
+ if (nil == _G["usertrack"][lighty.request["Cookie"]]) then
+ _G["usertrack"][lighty.request["Cookie"]]
+ else
+ _G["usertrack"][lighty.request["Cookie"]] = _G["usertrack"][lighty.request["Cookie"]] + 1
+ end
+
+ print _G["usertrack"][lighty.request["Cookie"]]
+
+The global-context is per script. If you update the script without restarting the server, the context will still be maintained.
+
+Counters
+--------
+
+mod_status support a global statistics page and mod_magnet allows to add and update values in the status page:
+
+Config ::
+
+ status.statistics-url = "/server-counters"
+ magnet.attract-raw-url-to = server.docroot + "/counter.lua"
+
+counter.lua ::
+
+ lighty.status["core.connections"] = lighty.status["core.connections"] + 1
+
+Result::
+
+ core.connections: 7
+ fastcgi.backend.php-foo.0.connected: 0
+ fastcgi.backend.php-foo.0.died: 0
+ fastcgi.backend.php-foo.0.disabled: 0
+ fastcgi.backend.php-foo.0.load: 0
+ fastcgi.backend.php-foo.0.overloaded: 0
+ fastcgi.backend.php-foo.1.connected: 0
+ fastcgi.backend.php-foo.1.died: 0
+ fastcgi.backend.php-foo.1.disabled: 0
+ fastcgi.backend.php-foo.1.load: 0
+ fastcgi.backend.php-foo.1.overloaded: 0
+ fastcgi.backend.php-foo.load: 0
+
+Porting mod_cml scripts
+-----------------------
+
+mod_cml got replaced by mod_magnet.
+
+A CACHE_HIT in mod_cml::
+
+ output_include = { "file1", "file2" }
+
+ return CACHE_HIT
+
+becomes::
+
+ content = { { filename = "/path/to/file1" }, { filename = "/path/to/file2"} }
+
+ return 200
+
+while a CACHE_MISS like (CML) ::
+
+ trigger_handler = "/index.php"
+
+ return CACHE_MISS
+
+becomes (magnet) ::
+
+ lighty.env["request.uri"] = "/index.php"
+
+ return lighty.RESTART_REQUEST
+
+}}} \ No newline at end of file