libravatarserv is a simple libravatar server.
Go to file
Nicholas Guriev a7c89b0e3f
Do not reopen stdout while image resizing
On Linux, some web-servers (Apache in particular) close file with fd = 1 and
offer something else as stdout. Notable difference can be seen with a pipe and
an immediate redirection. Consider:

  $ REQUEST_URI=/avatar/68b329da9893e34099c7d8ad5cb9c940 libravatarserv | cat > /tmp/response1.out
  $ REQUEST_URI=/avatar/68b329da9893e34099c7d8ad5cb9c940 libravatarserv > /tmp/response2.out
  $ diff -s /tmp/response{1,2}.out
  Binary files /tmp/response1.out and /tmp/response2.out differ

Solution.

The output should be identical in both cases. So do not let ImageMagick to open
/dev/stdout by itself, instead write the resulted image to an in-memory buffer
and then to a file associated with the "cout" global object.
2020-10-23 21:13:47 +03:00
doc Fixed enginx example 2018-12-09 20:04:48 +01:00
src Do not reopen stdout while image resizing 2020-10-23 21:13:47 +03:00
.drone.yml Updated the dependency-list to require identiconpp-0.3.4 or above. 2018-12-28 02:25:34 +01:00
.gitignore Initial commit 2018-11-24 11:38:10 +01:00
CMakeLists.txt Bumped version to 0.7.3. 2019-02-28 19:23:45 +01:00
LICENSE Initial commit 2018-11-24 11:38:10 +01:00
README.md Update copyright years. 2019-02-28 19:49:46 +01:00
packages.CMakeLists.txt Added automatic package generation 2018-11-27 06:00:50 +01:00

README.md

libravatarserv is a simple libravatar server. It is intended to be used as a CGI program.

Libravatar is a free service and an open specification for hosting profile images tied to email or OpenID addresses.

Features

  • Avatar delivery based on email addresses
  • Default avatar for unknown addresses
  • MD5 hashes
  • SHA256 hashes
  • Variable image size (s or size)
  • Default fallbacks (d or default): 404, URL, mp/mm, identicon, retro

The API is explained in greater detail at the Libravar wiki.

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
    • Patches welcome
  • forcedefault

Usage

Install nginx and fcgiwrap, copy the example config to the nginx configuration directory and edit it according to your needs. Other webservers and cgi spawners will also work, of course.

Add the following DNS records to your nameserver:

_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

_avatars._tcp.example.com is for HTTP, _avatars-sec._tcp.example.com is for HTTPS.

libravatarserv looks in each of ${XDG_DATA_DIRS} for a directory named libravatarserv. You can force a different directory by setting the environment variable LIBRAVATARSERV_DIR (until 0.3.0 AVATAR_DIR).

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.

If you want to support "Mystery persons" (mp/mm) as default avatars, place a file named mp in the avatar dir. You can use the default libravatar mystery person (SVG), for example.

Test your setup on https://www.libravatar.org/tools/check/.

Example

The avatar directory could look like this:

/usr/share/libravatarserv
├── [ 32K]  default
├── [ 759]  user@example.com
└── [  16]  user+newsletter@example.com -> user@example.com

Configuration

Configuration is done through environment variables.

LIBRAVATARSERV_DIR

The directory containing the avatars.

Default: empty

LIBRAVATARSERV_DEFAULT_FALLBACK

Controls what happens if no fallback was requested. Possible values: Anything that can be supplied with the d or default parameter.

Default: 404

LIBRAVATARSERV_REDIRECT_NOFALLBACK

Set to 1 to redirect to libravatar.org if the user is not found and the requested fallback is not supported.

Default: 0

LIBRAVATARSERV_REDIRECT_NOUSER

Set to 1 to redirect to libravatar.org if the user is not found.

Default: 0

Things to keep in mind

libravatarserv resizes images on the fly and does not cache anything. It also calculates both MD5 and SHA256 hashes for every user on every request. This could seriously strain the ressources of your computer if many users use the service.

Install

Gentoo

Gentoo ebuilds are available via my repository.

Automatically generated packages

Binary packages are generated automatically for each release in the formats:

  • deb
  • rpm
  • tar.gz

They are generated on Debian Stretch 64 bit and signed with my automatic signing key.

Up to and including 0.6.2, the packages were generated on Ubuntu 16.04 64 bit.

From source

Dependencies

On a Debian system, install the packages: build-essential cmake libcrypto++-dev libmagick++-dev libxdg-basedir-dev and identiconpp.

Compile

mkdir build
cd build
cmake ..
make
make install
cmake options
  • -DCMAKE_BUILD_TYPE=Debug for a debug build
  • One of:
    • -DWITH_DEB=YES to generate a deb-package
    • -DWITH_RPM=YES to generate an rpm-package

To generate a binary package, execute make package

Contributing

Contributions are always welcome. You can submit them as pull requests or via email to tastytea@tastytea.de.

Speed

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 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.

Contact

See https://tastytea.de/

Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.