libravatarserv/README.md

168 lines
5.4 KiB
Markdown
Raw Permalink Normal View History

2018-11-29 13:18:16 +01:00
**libravatarserv** is a simple libravatar server.
2018-11-26 02:25:25 +01:00
It is intended to be used as a
2018-11-24 11:00:07 +01:00
[CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface) program.
2018-11-29 13:18:16 +01:00
[Libravatar](https://www.libravatar.org/) is a free service and an open
specification for hosting profile images tied to email or OpenID addresses.
2018-11-25 06:33:32 +01:00
**The default branch changed from `master` to `main` on 2022-06-11.**
2018-11-25 06:33:32 +01:00
## Features
* Avatar delivery based on email addresses
* Default avatar for unknown addresses
* MD5 hashes
* SHA256 hashes
2018-11-26 04:37:28 +01:00
* Variable image size (`s` or `size`)
2022-06-11 07:42:56 +02:00
* Default fallbacks (`d` or `default`): 404, mp/mm, identicon (=retro), retro
2022-06-26 16:05:26 +02:00
* Requesting file type by appending `.jpg`, `.png`, `.gif` or `.webp` to the
hash
2018-11-26 04:37:28 +01:00
2018-11-26 05:20:46 +01:00
The API is explained in greater detail at the
[Libravar wiki](https://wiki.libravatar.org/api/).
2018-11-25 06:33:32 +01:00
2018-11-27 12:06:34 +01:00
### Not supported
* OpenID
* Because it isn't possible to store filenames with '/' in it on most filesystems.
* The default fallbacks monsterid, wavatar, robohash and pagan
2018-11-27 12:06:34 +01:00
* Patches welcome
2019-02-28 19:23:45 +01:00
* forcedefault
* Fallback URLs for to external sites (due to [CWE-601](https://cwe.mitre.org/data/definitions/601.html))
2022-06-11 07:42:56 +02:00
* We have a server setting (`LIBRAVATARSERV_REDIRECT`) to redirect to
libravatar.org.
2018-11-27 12:06:34 +01:00
2018-11-24 11:00:07 +01:00
## Usage
2018-11-25 06:33:32 +01:00
Install nginx and
[fcgiwrap](https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/),
copy the [example config](https://schlomp.space/tastytea/libravatarserv/src/branch/main/doc/nginx-example.conf)
2020-10-24 12:09:54 +02:00
to the nginx configuration directory and edit it according to your needs. Other
webservers and cgi spawners will also work, of course.
2018-11-25 06:33:32 +01:00
2018-11-25 07:59:17 +01:00
Add the following DNS records to your nameserver:
2020-10-24 12:09:54 +02:00
``` plain
2018-11-25 07:59:17 +01:00
_avatars._tcp.example.com. IN SRV 0 0 80 avatars.example.com
_avatars-sec._tcp.example.com. IN SRV 0 0 443 avatars.example.com
```
2020-10-24 12:09:54 +02:00
2018-11-25 07:59:17 +01:00
`_avatars._tcp.example.com` is for HTTP, `_avatars-sec._tcp.example.com` is for
HTTPS.
2022-06-11 07:42:56 +02:00
libravatarserv looks in the current working directory for images. You can force
2022-06-26 16:05:26 +02:00
a different directory by setting the environment variable
`LIBRAVATARSERV_DIR`. Any file format supported by ImageMagick is supported, but
it should be PNG, JPEG or GIF for compatibility.
2018-11-25 06:33:32 +01:00
2018-12-02 11:24:18 +01:00
The image files are named like your email address, no file extension. The
default behaviour for unknown users is to return a 404 error. You can change
that by setting the environment variable `LIBRAVATARSERV_DEFAULT_FALLBACK` to
any value accepted by `d` or `default`. If you want to force a default image for
unknown email addresses, name it `default`. The default image overrides the
specified fallback in the URL and in the environment variable.
2018-11-25 07:23:20 +01:00
If you want to support "Mystery persons" (mp/mm) as default avatars, place a
2019-02-20 03:21:27 +01:00
file named `mp` in the avatar dir. You can use the
[default libravatar mystery person](https://git.linux-kernel.at/oliver/ivatar/raw/master/ivatar/static/img/mm.png)
2020-10-24 12:09:54 +02:00
([SVG](https://git.linux-kernel.at/oliver/ivatar/raw/master/ivatar/static/img/mm.svg)),
for example.
2020-10-24 12:09:54 +02:00
Test your setup on <https://www.libravatar.org/tools/check/>.
2018-11-25 07:23:20 +01:00
### Example
2018-11-26 02:25:25 +01:00
The avatar directory could look like this:
2020-10-24 12:09:54 +02:00
``` plain
2022-06-11 07:42:56 +02:00
/var/db/libravatarserv
2018-11-25 07:23:20 +01:00
├── [ 32K] default
├── [ 759] user@example.com
└── [ 16] user+newsletter@example.com -> user@example.com
```
2018-11-25 06:33:32 +01:00
### Configuration
Configuration is done through environment variables.
2018-11-27 17:15:47 +01:00
**LIBRAVATARSERV_DIR**
The directory containing the avatars.
2022-06-11 07:42:56 +02:00
Default: current directory
2018-11-27 17:15:47 +01:00
**LIBRAVATARSERV_DEFAULT_FALLBACK**
Controls what happens if no fallback was requested.
2018-11-28 04:02:17 +01:00
Possible values: Anything that can be supplied with the `d` or `default`
parameter.
Default: 404
2022-06-11 07:42:56 +02:00
**LIBRAVATARSERV_REDIRECT**
Set to 1 to redirect to libravatar.org if the user is not found.
2022-06-11 07:42:56 +02:00
Default: 1
### Things to keep in mind
2022-06-11 07:42:56 +02:00
libravatarserv resizes images on the fly and potentially calculates hashes for
every user on every request. This could seriously strain the ressources of your
computer if many users use the service. Make sure to set up caching if you
expect more than occasional traffic.
2018-11-24 11:00:07 +01:00
## Install
2018-11-27 05:46:45 +01:00
### Gentoo
Gentoo ebuilds are available via my
[repository](https://schlomp.space/tastytea/overlay).
### From source
#### Dependencies
2018-11-24 11:00:07 +01:00
2022-06-11 07:42:56 +02:00
* C++ compiler (tested: [gcc](https://gcc.gnu.org/) 8/11,
[clang](https://llvm.org/) 7)
* [cmake](https://cmake.org/) (at least 3.12)
* [crypto++](https://cryptopp.com) (tested: 8.6 / 5.6)
* [imagemagick](https://www.imagemagick.org/) (tested: 7.1 / 6.7)
* [identiconpp](https://schlomp.space/tastytea/identiconpp) (at least: 0.7.1)
2018-11-24 11:00:07 +01:00
2022-06-11 07:52:25 +02:00
On a Debian system, install the packages: `build-essential pkg-config cmake
libcrypto++-dev libmagick++-dev` and
2022-06-11 07:42:56 +02:00
[identiconpp](https://schlomp.space/tastytea/identiconpp) (or use the bundled).
2018-11-27 05:46:45 +01:00
#### Compile
2018-11-24 11:00:07 +01:00
2020-10-24 12:09:54 +02:00
``` shell
2022-06-11 07:42:56 +02:00
cmake -S . -B build
cmake --build build
2018-11-24 11:00:07 +01:00
```
2018-11-27 06:24:43 +01:00
##### cmake options
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
2022-06-11 08:43:56 +02:00
* `-DLIBRAVATAR_BUNDLED_IDENTICONPP=YES` to use the bundled identiconpp
2018-11-27 06:24:43 +01:00
2022-06-11 07:42:56 +02:00
To install, run `sudo cmake --install build`. To create a linux distribution
package, run `cpack -G DEB` or `cpack -G RPM`.
2018-11-27 06:24:43 +01:00
2018-11-24 11:00:07 +01:00
## Contributing
Contributions are always welcome. You can submit them as pull requests or via
email to `tastytea`@`tastytea.de`.
2018-12-03 21:17:13 +01:00
## Speed
2018-12-03 21:38:55 +01:00
Tests on a laptop with an x86_64 2GHz CPU with 2 cores showed that the average
response time is 140ms with 3 avatars in the "database", 180ms with 1003
2018-12-03 21:17:13 +01:00
avatars. The tests were done with a 27KiB image, scaled down from 569px to
512px. It took 3,8s / 5-7s to transfer 50 unique avatars (about 3 KiB each) on
one page.
2022-06-11 07:42:56 +02:00
This test was done on an older version and may not be accurate any more.
2018-11-25 06:33:32 +01:00
## Contact
See https://tastytea.de/