From 76935df16105b2c46c1f4bd10f09b620d91b9ca8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 20 Aug 2022 20:43:05 +0200 Subject: [PATCH] move render code to modules --- lam/lib/account.inc | 2 +- lam/lib/modules/inetOrgPerson.inc | 28 ++++++++++++++++++++++++++++ lam/lib/modules/windowsUser.inc | 28 ++++++++++++++++++++++++++++ lam/lib/types/user.inc | 24 ------------------------ 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 164463e04..13464788d 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -1595,7 +1595,7 @@ class moduleCache { * @return int random number */ function getRandomNumber() { - return abs(hexdec(bin2hex(openssl_random_pseudo_bytes(5)))); + return abs(hexdec(bin2hex(openssl_random_pseudo_bytes(6)))); } /** diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index f8c59b956..6d5368656 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -4628,6 +4628,34 @@ class inetOrgPerson extends baseModule implements passwordService,AccountStatusP return $group; }; } + elseif ($attributeName === 'jpegphoto') { + return function(array $entry, string $attribute): ?htmlElement { + if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) { + if (strlen($entry[$attribute][0]) < 100) { + // looks like we have read broken binary data, reread photo + $result = @ldap_read($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*", array($attribute), 0, 0, 0, LDAP_DEREF_NEVER); + if ($result) { + $tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result); + if ($tempEntry) { + $binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute); + $entry[$attribute] = $binData; + } + } + } + $imgNumber = getRandomNumber(); + $jpeg_filename = 'jpg' . $imgNumber . '.jpg'; + $outjpeg = @fopen(dirname(__FILE__) . '/../../tmp/' . $jpeg_filename, "wb"); + fwrite($outjpeg, $entry[$attribute][0]); + fclose ($outjpeg); + $photoFile = '../../tmp/' . $jpeg_filename; + $image = new htmlImage($photoFile); + $image->enableLightbox(); + $image->setCSSClasses(array('thumbnail')); + return $image; + } + return null; + }; + } return null; } diff --git a/lam/lib/modules/windowsUser.inc b/lam/lib/modules/windowsUser.inc index e2e2ad935..ab254cb11 100644 --- a/lam/lib/modules/windowsUser.inc +++ b/lam/lib/modules/windowsUser.inc @@ -4536,6 +4536,34 @@ class windowsUser extends baseModule implements passwordService,AccountStatusPro return $group; }; } + elseif ($attributeName === 'jpegphoto') { + return function(array $entry, string $attribute): ?htmlElement { + if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) { + if (strlen($entry[$attribute][0]) < 100) { + // looks like we have read broken binary data, reread photo + $result = @ldap_read($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*", array($attribute), 0, 0, 0, LDAP_DEREF_NEVER); + if ($result) { + $tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result); + if ($tempEntry) { + $binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute); + $entry[$attribute] = $binData; + } + } + } + $imgNumber = getRandomNumber(); + $jpeg_filename = 'jpg' . $imgNumber . '.jpg'; + $outjpeg = @fopen(dirname(__FILE__) . '/../../tmp/' . $jpeg_filename, "wb"); + fwrite($outjpeg, $entry[$attribute][0]); + fclose ($outjpeg); + $photoFile = '../../tmp/' . $jpeg_filename; + $image = new htmlImage($photoFile); + $image->enableLightbox(); + $image->setCSSClasses(array('thumbnail')); + return $image; + } + return null; + }; + } return null; } diff --git a/lam/lib/types/user.inc b/lam/lib/types/user.inc index 393700366..deb40a1d4 100644 --- a/lam/lib/types/user.inc +++ b/lam/lib/types/user.inc @@ -506,30 +506,6 @@ class lamUserList extends lamList { return parent::getTableCellContent($entry, $attribute); } } - // show user photos - elseif (($attribute == "jpegphoto") && (!empty($entry[$attribute][0]))) { - if (strlen($entry[$attribute][0]) < 100) { - // looks like we have read broken binary data, reread photo - $result = @ldap_read($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*", array($attribute), 0, 0, 0, LDAP_DEREF_NEVER); - if ($result) { - $tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result); - if ($tempEntry) { - $binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute); - $entry[$attribute] = $binData; - } - } - } - $imgNumber = getRandomNumber(); - $jpeg_filename = 'jpg' . $imgNumber . '.jpg'; - $outjpeg = @fopen(dirname(__FILE__) . '/../../tmp/' . $jpeg_filename, "wb"); - fwrite($outjpeg, $entry[$attribute][0]); - fclose ($outjpeg); - $photoFile = '../../tmp/' . $jpeg_filename; - $image = new htmlImage($photoFile); - $image->enableLightbox(); - $image->setCSSClasses(array('thumbnail')); - return $image; - } // account status elseif ($attribute == self::ATTR_ACCOUNT_STATUS) { return $this->getAccountStatus($entry);