Skip to content

Commit fc7bbb3

Browse files
authored
Added CI workflow and fixed README markdown
1 parent fe25836 commit fc7bbb3

File tree

2 files changed

+91
-35
lines changed

2 files changed

+91
-35
lines changed

.github/workflows/ci.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build and test apache module
2+
3+
on:
4+
# Triggers on push/pull only for the "master" branch
5+
push:
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ "master" ]
9+
10+
# Allows running workflow manually
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install packages we'll need for building
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get -y install build-essential libtool \
22+
apache2 apache2-dev apache2-utils \
23+
libapr1-dev libaprutil1-dev \
24+
curl fortune
25+
# git clone https://github.com/EvanK/apache2-mod-fortune.git ~/a2mf && cd ~/a2mf && apxs -c mod_fortune.c && apxs -i -a mod_fortune.la
26+
- name: Build and install module
27+
run: |
28+
apxs -c mod_fortune.c
29+
sudo apxs -i -a mod_fortune.la
30+
- name: Ensure module combiled to shared object
31+
run: ls -1 /usr/lib/apache2/modules/mod_fortune.so
32+
- name: Ensure module installed and enabled
33+
run: ls -1 /etc/apache2/mods-enabled/fortune.load
34+
# ^^ need to figure correct so and conf paths here and below
35+
- name: Add to apache config
36+
run: |
37+
cat << EOF | sudo tee -a /etc/apache2/apache2.conf
38+
<IfModule headers_module>
39+
<IfModule fortune_module>
40+
FortuneMaxLength 1000
41+
</IfModule>
42+
Header onsuccess set X-Fortune %{FORTUNE_COOKIE}e env=FORTUNE_COOKIE
43+
</IfModule>
44+
EOF
45+
- name: Enable headers module as we'll need it
46+
run: sudo a2enmod headers
47+
- name: Gracefully (re)start apache
48+
run: sudo apachectl graceful
49+
# run: kill -s USR1 $(cat /usr/local/apache2/logs/httpd.pid)
50+
# ^^ hopefully can use systemctl or something to do this
51+
- name: Test for fortune header
52+
run: curl -sI http://localhost/ | grep X-Fortune

README.md

+39-35
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
1-
mod_fortune
2-
===
1+
# mod_fortune
32

43

5-
Covering My Behind
6-
--
4+
## Covering My Behind
5+
76
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!
87

98

10-
What Is `fortune`?
11-
--
9+
## What Is `fortune`?
10+
1211
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).
1312

1413

15-
What is `mod_fortune`?
16-
--
14+
## What is `mod_fortune`?
15+
1716
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.
1817

1918

20-
Why?
21-
--
19+
## Why?
20+
2221
I wrote this mostly for fun and because it's been a while since I dabbled in the C language.
2322

2423

25-
How?
26-
--
24+
## How?
25+
2726
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+
3235
This should not only move the object file into place, but add a *LoadModule* directive into your apache configuration.
3336

3437

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+
3942

43+
## Usage Example
4044

41-
Usage Example
42-
--
4345
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>
5746

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

Comments
 (0)