Skip to content

Commit 08a1287

Browse files
authored
Merge pull request #1254 from pi-hole/low_level_lua
Add webserver documentation
2 parents 69fb881 + 1e5ca0f commit 08a1287

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/ftldns/webserver.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
### FTL's Embedded Webserver and Lua Server Pages
2+
3+
FTL comes with the embedded webserver [CivetWeb](https://github.com/civetweb/civetweb) supporting Lua server pages (LSP). This means you can write dynamic web content directly using Lua scripts, similar to how PHP is used in traditional web development. Lua offers several advantages over PHP in the embedded context:
4+
5+
- **Lightweight and Fast:** Lua has a very small memory footprint and is designed for high performance, making it ideal for our purposes.
6+
- **Easy Integration:** Lua is easy to embed and extend, allowing seamless integration with FTL. We can easily bundle any Lua libraries we need, and they can be used directly in the webserver. No extra tools or external dependencies are required.
7+
- **Simplicity:** Lua's syntax is straightforward and easy to learn, reducing the complexity of writing and maintaining server-side scripts.
8+
- **Security:** Running Lua scripts within the FTL webserver provides a controlled environment, minimizing potential security risks compared to running a full PHP interpreter.
9+
10+
---
11+
12+
You can use the webserver to serve static files, dynamic content, or even custom HTTP responses (see the following examples). The webserver is configured through `pihole.toml` and can be accessed at `https://pi.hole/admin/`. Serving files outside of the webserver's home directory (`admin/`) is disabled by default for security reasons. It can be enabled by setting `webserver.serve_all` to `true`.
13+
14+
### Example 1: Custom HTTP status code
15+
16+
Create a file like
17+
18+
``` plain
19+
HTTP/1.1 204 No Content
20+
Connection: close
21+
Cache-Control: max-age=0, must-revalidate
22+
23+
```
24+
25+
Two important things here: You need to save it using "MS-DOS formatting" (`\r\n` line endings) and there needs to be a single trailing line.
26+
27+
### Example 2: Regular page but manual headers
28+
29+
You could also use it for "regular" pages, e.g.,
30+
31+
``` plain
32+
HTTP/1.0 200 OK
33+
Content-Type: text/html
34+
35+
<html><body>
36+
<p><?= 1+1 ?></p>
37+
</body></html>
38+
```
39+
40+
which will print an empty page with "2" on it.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ nav:
142142
- 'Blocking mode': ftldns/blockingmode.md
143143
- 'Privacy levels': ftldns/privacylevels.md
144144
- 'dnsmasq warnings': ftldns/dnsmasq_warn.md
145+
- 'Webserver': ftldns/webserver.md
145146
- 'Advanced':
146147
- 'Install from source': ftldns/compile.md
147148
- 'Signals': 'ftldns/signals.md'
@@ -246,7 +247,6 @@ plugins:
246247
- redirects:
247248
redirect_maps:
248249
'ftldns/database.md': database/index.md
249-
'ftldns/regex/index.md': ftldns/regex/overview.md
250250
'main/presentations.md': index.md
251251
'main/prerequesites.md': main/prerequisites.md
252252
'guides/unbound.md': guides/dns/unbound.md

0 commit comments

Comments
 (0)