|
1 |
| -mod_fortune |
2 |
| -=== |
| 1 | +# mod_fortune |
3 | 2 |
|
4 | 3 |
|
5 |
| -Covering My Behind |
6 |
| --- |
| 4 | +## Covering My Behind |
| 5 | + |
7 | 6 | This is my first foray into writing Apache2 modules, and it is meant as both a learning exercise for me and an entertaining piece of open source software for the world at large. It is by no means optimized for high-availability environments and I make no guarantee that it is free of bugs or security flaws. Use at your own risk!
|
8 | 7 |
|
9 | 8 |
|
10 |
| -What Is `fortune`? |
11 |
| --- |
| 9 | +## What Is `fortune`? |
| 10 | + |
12 | 11 | Anyone that's made heavy use of Linux has probably come across the `fortune` program at some point. It outputs "a random, hopefully interesting, adage" on demand, a sort of digital fortune cookie (hence the name).
|
13 | 12 |
|
14 | 13 |
|
15 |
| -What is `mod_fortune`? |
16 |
| --- |
| 14 | +## What is `mod_fortune`? |
| 15 | + |
17 | 16 | It is a module for the Apache2 webserver that pipes the output of the `fortune` command into an environment variable. This results in each and every request to the webserver having available a different fortune that can be dumped into a header, accessed by a CGI script, or any other number of things.
|
18 | 17 |
|
19 | 18 |
|
20 |
| -Why? |
21 |
| --- |
| 19 | +## Why? |
| 20 | + |
22 | 21 | I wrote this mostly for fun and because it's been a while since I dabbled in the C language.
|
23 | 22 |
|
24 | 23 |
|
25 |
| -How? |
26 |
| --- |
| 24 | +## How? |
| 25 | + |
27 | 26 | There are multiple ways to compile and install an apache module. My preferred method is to use `apxs`:
|
28 |
| - # build shared object file |
29 |
| - apxs -c mod_fortune.c |
30 |
| - # and install it (may require root/sudo) |
31 |
| - apxs -i -a mod_fortune.la |
| 27 | + |
| 28 | +```shell |
| 29 | +# build shared object file |
| 30 | +apxs -c mod_fortune.c |
| 31 | +# and install it (may require root/sudo) |
| 32 | +apxs -i -a mod_fortune.la |
| 33 | +``` |
| 34 | + |
32 | 35 | This should not only move the object file into place, but add a *LoadModule* directive into your apache configuration.
|
33 | 36 |
|
34 | 37 |
|
35 |
| -Licensing |
36 |
| --- |
37 |
| -This software is released as open source under the MIT license: |
38 |
| - http://www.opensource.org/licenses/mit-license.php |
| 38 | +## Licensing |
| 39 | + |
| 40 | +This software is released as open source under [the MIT license](http://www.opensource.org/licenses/mit-license.php) |
| 41 | + |
39 | 42 |
|
| 43 | +## Usage Example |
40 | 44 |
|
41 |
| -Usage Example |
42 |
| --- |
43 | 45 | This is an example configuration that would insert an `X-Fortune` header to every successful request.
|
44 |
| - # if mod_header is enabled... |
45 |
| - <IfModule mod_header.c> |
46 |
| - # load and configure mod_fortune (default path but custom max length) |
47 |
| - LoadModule fortune_module modules/mod_fortune.so |
48 |
| - |
49 |
| - <IfModule mod_fortune.c> |
50 |
| - FortuneMaxLength 1000 |
51 |
| - #FortuneProgram /usr/games/fortune |
52 |
| - </IfModule> |
53 |
| - |
54 |
| - # set X-Fortune header for successful response, if env variable exists |
55 |
| - Header onsuccess set X-Fortune %{FORTUNE_COOKIE}e env=FORTUNE_COOKIE |
56 |
| - </IfModule> |
57 | 46 |
|
| 47 | +```apache |
| 48 | +# if mod_header is enabled... |
| 49 | +<IfModule mod_header.c> |
| 50 | + # load and configure mod_fortune (default path but custom max length) |
| 51 | + LoadModule fortune_module modules/mod_fortune.so |
| 52 | + |
| 53 | + <IfModule mod_fortune.c> |
| 54 | + FortuneMaxLength 1000 |
| 55 | + #FortuneProgram /usr/games/fortune |
| 56 | + </IfModule> |
| 57 | + |
| 58 | + # set X-Fortune header for successful response, if env variable exists |
| 59 | + Header onsuccess set X-Fortune %{FORTUNE_COOKIE}e env=FORTUNE_COOKIE |
| 60 | +</IfModule> |
| 61 | +``` |
0 commit comments