From 49789839fb775b1b23fd9bddcf7d0fee8e1651f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Wed, 26 Jun 2024 17:18:55 +0200 Subject: [PATCH] Photo.php: add no_fallback parameter --- docs/photos.rst | 8 ++++++++ htdocs/photo.php | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/photos.rst b/docs/photos.rst index deea181..df5b5dc 100644 --- a/docs/photos.rst +++ b/docs/photos.rst @@ -10,6 +10,14 @@ Configure which file is used as default photo : $default_photo = "images/240px-PICA.jpg"; +Photo endpoint +-------------- + +A user's photo can be queried on ``/photo.php?dn=[user's DN]``. An additionnal +``no_fallback`` parameter can be passed to avoid falling back to a default +picture and returning 404: ``/photo.php?no_fallback&dn=[user's DN]``. This is +useful to eg. use an application's internal fallback image instead. + LDAP attribute -------------- diff --git a/htdocs/photo.php b/htdocs/photo.php index 4205f4f..c5106f7 100644 --- a/htdocs/photo.php +++ b/htdocs/photo.php @@ -74,8 +74,14 @@ $result = "dnrequired"; } -# Display default photo if any error if ( !$photo ) { + # If `no_fallback` in GET parameters, fail with 404 + if(isset($_GET['no_fallback'])) { + http_response_code(404); + die(); + } + + # Else, display default photo if any error $photo = imagecreatefromjpeg($default_photo); }