require imagick

This commit is contained in:
Roland Gruber 2018-05-12 09:39:29 +02:00
parent ffaa7d5bac
commit 5ec89293b2
5 changed files with 72 additions and 98 deletions

View File

@ -10,7 +10,7 @@ Package: ldap-account-manager
Architecture: all Architecture: all
Depends: php5 (>= 5.4.26) | php (>= 7), php5-ldap | php-ldap, php5-gd | php-gd, Depends: php5 (>= 5.4.26) | php (>= 7), php5-ldap | php-ldap, php5-gd | php-gd,
php5-json | php-json, php5-imagick | php-imagick, php5-curl | php-curl, php5-json | php-json, php5-imagick | php-imagick, php5-curl | php-curl,
php5 | php-zip, php5 | php-xml, php5 | php-zip, php5 | php-xml, php-imagick,
libapache2-mod-php5 | libapache2-mod-php | php5-fpm | php-fpm, libapache2-mod-php5 | libapache2-mod-php | php5-fpm | php-fpm,
apache2 | httpd, fonts-dejavu, debconf (>= 0.2.26) | debconf-2.0, ${misc:Depends} apache2 | httpd, fonts-dejavu, debconf (>= 0.2.26) | debconf-2.0, ${misc:Depends}
Recommends: php-apc | php-opcache Recommends: php-apc | php-opcache

View File

@ -1,4 +1,5 @@
June 2018 6.4 June 2018 6.4
- Imagick PHP extension required
- Passwords can be checked against external service (e.g. https://api.pwnedpasswords.com/range) - Passwords can be checked against external service (e.g. https://api.pwnedpasswords.com/range)
- IMAP: create mailbox via file upload - IMAP: create mailbox via file upload
- PHP 7.2 support - PHP 7.2 support

View File

@ -1,9 +1,8 @@
<?php <?php
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2010 - 2015 Roland Gruber Copyright (C) 2010 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -82,6 +81,10 @@ if (! function_exists('utf8_decode') || !extension_loaded('xml')) {
if (!extension_loaded('libxml')) { if (!extension_loaded('libxml')) {
$criticalErrors[] = array("ERROR", "Your PHP has no Lib XML support!", "Please install the Lib XML extension for PHP."); $criticalErrors[] = array("ERROR", "Your PHP has no Lib XML support!", "Please install the Lib XML extension for PHP.");
} }
// imagick
if (!extension_loaded('imagick')) {
$criticalErrors[] = array("ERROR", "Your PHP has no imagick support.", "Please install the imagick extension for PHP.");
}
// check if PHP has GD support // check if PHP has GD support
if (! function_exists('getimagesize')) { if (! function_exists('getimagesize')) {
$criticalErrors[] = array("ERROR", "Your PHP has no GD support!", "Please install the GD extension for PHP."); $criticalErrors[] = array("ERROR", "Your PHP has no GD support!", "Please install the GD extension for PHP.");

View File

@ -97,7 +97,6 @@ class inetOrgPerson extends baseModule implements passwordService {
$this->messages['uid'][3] = array('ERROR', _('Account %s:') . ' inetOrgPerson_userName', _('User name already exists!')); $this->messages['uid'][3] = array('ERROR', _('Account %s:') . ' inetOrgPerson_userName', _('User name already exists!'));
$this->messages['manager'][0] = array('ERROR', _('Account %s:') . ' inetOrgPerson_manager', _('This is not a valid DN!')); $this->messages['manager'][0] = array('ERROR', _('Account %s:') . ' inetOrgPerson_manager', _('This is not a valid DN!'));
$this->messages['file'][0] = array('ERROR', _('No file selected.')); $this->messages['file'][0] = array('ERROR', _('No file selected.'));
$this->messages['file'][1] = array('ERROR', _('Please upload a .jpg/.jpeg file.'));
$this->messages['file'][2] = array('ERROR', _('Unable to process this file.')); $this->messages['file'][2] = array('ERROR', _('Unable to process this file.'));
$this->messages['file'][3] = array('ERROR', _('File is too large. Maximum allowed size is %s kB.')); $this->messages['file'][3] = array('ERROR', _('File is too large. Maximum allowed size is %s kB.'));
$this->messages['businessCategory'][0] = array('ERROR', _('Business category'), _('Please enter a valid business category!')); $this->messages['businessCategory'][0] = array('ERROR', _('Business category'), _('Please enter a valid business category!'));
@ -1620,10 +1619,6 @@ class inetOrgPerson extends baseModule implements passwordService {
if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) { if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) {
$name = $_FILES['photoFile']['name']; $name = $_FILES['photoFile']['name'];
$extension = strtolower(substr($name, strpos($name, '.') + 1)); $extension = strtolower(substr($name, strpos($name, '.') + 1));
if (!extension_loaded('imagick') && !($extension == 'jpg') && !($extension == 'jpeg')) {
$messages[] = $this->messages['file'][1];
return $messages;
}
$handle = fopen($_FILES['photoFile']['tmp_name'], "r"); $handle = fopen($_FILES['photoFile']['tmp_name'], "r");
$data = fread($handle, 10000000); $data = fread($handle, 10000000);
if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]))) { if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]))) {
@ -1633,27 +1628,25 @@ class inetOrgPerson extends baseModule implements passwordService {
return array($errMsg); return array($errMsg);
} }
fclose($handle); fclose($handle);
if (extension_loaded('imagick')) { // convert to JPG if imagick extension is available
// convert to JPG if imagick extension is available $image = new Imagick();
$image = new Imagick(); try {
try { $image->readImageBlob($data);
$image->readImageBlob($data); // resize if maximum values specified
// resize if maximum values specified if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0])) {
if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0])) { $maxWidth = empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0];
$maxWidth = empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['inetOrgPerson_jpegPhoto_maxWidth'][0]; $maxHeight = empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0];
$maxHeight = empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['inetOrgPerson_jpegPhoto_maxHeight'][0]; $image->thumbnailimage($maxWidth, $maxHeight, true);
$image->thumbnailimage($maxWidth, $maxHeight, true); }
} $image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompression(Imagick::COMPRESSION_JPEG); $image->setImageFormat('jpeg');
$image->setImageFormat('jpeg'); $data = $image->getimageblob();
$data = $image->getimageblob(); }
} catch (Exception $e) {
catch (Exception $e) { $msg = $this->messages['file'][2];
$msg = $this->messages['file'][2]; $msg[] = htmlspecialchars($e->getMessage());
$msg[] = htmlspecialchars($e->getMessage()); $messages[] = $msg;
$messages[] = $msg; return $messages;
return $messages;
}
} }
$this->attributes['jpegPhoto'][0] = $data; $this->attributes['jpegPhoto'][0] = $data;
} }
@ -1670,10 +1663,7 @@ class inetOrgPerson extends baseModule implements passwordService {
*/ */
function display_html_photo() { function display_html_photo() {
$container = new htmlTable(); $container = new htmlTable();
$label = _('Photo file (JPG format)'); $label = _('Photo file');
if (extension_loaded('imagick')) {
$label = _('Photo file');
}
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true); $container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
$buttonContainer = new htmlTable(); $buttonContainer = new htmlTable();
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo'))); $buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo')));
@ -2434,10 +2424,8 @@ class inetOrgPerson extends baseModule implements passwordService {
public function getSelfServiceSettings($profile) { public function getSelfServiceSettings($profile) {
$container = new htmlResponsiveRow(); $container = new htmlResponsiveRow();
$container->add(new htmlSubTitle(_('Photo')), 12); $container->add(new htmlSubTitle(_('Photo')), 12);
if (extension_loaded('imagick')) { $container->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'inetOrgPerson_jpegPhoto_maxWidth', null, array('crop', get_class($this))), 12);
$container->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'inetOrgPerson_jpegPhoto_maxWidth', null, array('crop', get_class($this))), 12); $container->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, array('crop', get_class($this))), 12);
$container->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, array('crop', get_class($this))), 12);
}
$container->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12); $container->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12);
return $container; return $container;
} }
@ -3225,15 +3213,13 @@ class inetOrgPerson extends baseModule implements passwordService {
$handle = fopen($_FILES['photoFile']['tmp_name'], "r"); $handle = fopen($_FILES['photoFile']['tmp_name'], "r");
$data = fread($handle, 100000000); $data = fread($handle, 100000000);
fclose($handle); fclose($handle);
if (extension_loaded('imagick')) { try {
try { $data = inetOrgPerson::resizeAndConvertImage($data, $moduleSettings);
$data = inetOrgPerson::resizeAndConvertImage($data, $moduleSettings); }
} catch (Exception $e) {
catch (Exception $e) { $msg = $this->messages['file'][2];
$msg = $this->messages['file'][2]; $msg[] = htmlspecialchars($e->getMessage());
$msg[] = htmlspecialchars($e->getMessage()); $return['messages'][] = $msg;
$return['messages'][] = $msg;
}
} }
if (isset($_POST['removeReplacePhoto']) && ($_POST['removeReplacePhoto'] == 'on')) { if (isset($_POST['removeReplacePhoto']) && ($_POST['removeReplacePhoto'] == 'on')) {
$return['mod']['jpegPhoto'][0] = $data; $return['mod']['jpegPhoto'][0] = $data;
@ -3352,20 +3338,18 @@ class inetOrgPerson extends baseModule implements passwordService {
* @return array binary image data * @return array binary image data
*/ */
private static function resizeAndConvertImage($data, $settings) { private static function resizeAndConvertImage($data, $settings) {
if (extension_loaded('imagick')) { // convert to JPG if imagick extension is available
// convert to JPG if imagick extension is available $image = new Imagick();
$image = new Imagick(); $image->readImageBlob($data);
$image->readImageBlob($data); // resize if maximum values specified
// resize if maximum values specified if (!empty($settings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($settings['inetOrgPerson_jpegPhoto_maxHeight'][0])) {
if (!empty($settings['inetOrgPerson_jpegPhoto_maxWidth'][0]) || !empty($settings['inetOrgPerson_jpegPhoto_maxHeight'][0])) { $maxWidth = empty($settings['inetOrgPerson_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $settings['inetOrgPerson_jpegPhoto_maxWidth'][0];
$maxWidth = empty($settings['inetOrgPerson_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $settings['inetOrgPerson_jpegPhoto_maxWidth'][0]; $maxHeight = empty($settings['inetOrgPerson_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $settings['inetOrgPerson_jpegPhoto_maxHeight'][0];
$maxHeight = empty($settings['inetOrgPerson_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $settings['inetOrgPerson_jpegPhoto_maxHeight'][0]; $image->thumbnailimage($maxWidth, $maxHeight, true);
$image->thumbnailimage($maxWidth, $maxHeight, true);
}
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageFormat('jpeg');
$data = $image->getimageblob();
} }
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageFormat('jpeg');
$data = $image->getimageblob();
return $data; return $data;
} }
@ -3718,10 +3702,8 @@ class inetOrgPerson extends baseModule implements passwordService {
$advancedOptions->add(new htmlResponsiveInputCheckbox($id, false, $label, null, true), 12, 4); $advancedOptions->add(new htmlResponsiveInputCheckbox($id, false, $label, null, true), 12, 4);
} }
$advancedOptions->add(new htmlSubTitle(_('Photo')), 12); $advancedOptions->add(new htmlSubTitle(_('Photo')), 12);
if (extension_loaded('imagick')) { $advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'inetOrgPerson_jpegPhoto_maxWidth', null, 'crop'), 12);
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'inetOrgPerson_jpegPhoto_maxWidth', null, 'crop'), 12); $advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, 'crop'), 12);
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, 'crop'), 12);
}
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12); $advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12);
$advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false); $advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false);
$configContainer->add($advancedOptionsAccordion, 12); $configContainer->add($advancedOptionsAccordion, 12);

View File

@ -2,10 +2,9 @@
use \LAM\TYPES\TypeManager; use \LAM\TYPES\TypeManager;
use LAM\TYPES\ConfiguredType; use LAM\TYPES\ConfiguredType;
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2017 Roland Gruber Copyright (C) 2013 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -1747,10 +1746,7 @@ class windowsUser extends baseModule implements passwordService {
*/ */
function display_html_photo() { function display_html_photo() {
$container = new htmlTable(); $container = new htmlTable();
$label = _('Photo file (JPG format)'); $label = _('Photo file');
if (extension_loaded('imagick')) {
$label = _('Photo file');
}
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true); $container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
$buttonContainer = new htmlTable(); $buttonContainer = new htmlTable();
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo'))); $buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo')));
@ -1770,10 +1766,6 @@ class windowsUser extends baseModule implements passwordService {
if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) { if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) {
$name = $_FILES['photoFile']['name']; $name = $_FILES['photoFile']['name'];
$extension = strtolower(substr($name, strpos($name, '.') + 1)); $extension = strtolower(substr($name, strpos($name, '.') + 1));
if (!extension_loaded('imagick') && !($extension == 'jpg') && !($extension == 'jpeg')) {
$messages[] = $this->messages['file'][1];
return $messages;
}
$handle = fopen($_FILES['photoFile']['tmp_name'], "r"); $handle = fopen($_FILES['photoFile']['tmp_name'], "r");
$data = fread($handle, 10000000); $data = fread($handle, 10000000);
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]))) { if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]))) {
@ -1783,27 +1775,25 @@ class windowsUser extends baseModule implements passwordService {
return array($errMsg); return array($errMsg);
} }
fclose($handle); fclose($handle);
if (extension_loaded('imagick')) { // convert to JPG if imagick extension is available
// convert to JPG if imagick extension is available $image = new Imagick();
$image = new Imagick(); try {
try { $image->readImageBlob($data);
$image->readImageBlob($data); // resize if maximum values specified
// resize if maximum values specified if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0])) {
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0])) { $maxWidth = empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0];
$maxWidth = empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]; $maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0];
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]; $image->thumbnailimage($maxWidth, $maxHeight, true);
$image->thumbnailimage($maxWidth, $maxHeight, true); }
} $image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompression(Imagick::COMPRESSION_JPEG); $image->setImageFormat('jpeg');
$image->setImageFormat('jpeg'); $data = $image->getimageblob();
$data = $image->getimageblob(); }
} catch (Exception $e) {
catch (Exception $e) { $msg = $this->messages['file'][2];
$msg = $this->messages['file'][2]; $msg[] = htmlspecialchars($e->getMessage());
$msg[] = htmlspecialchars($e->getMessage()); $messages[] = $msg;
$messages[] = $msg; return $messages;
return $messages;
}
} }
$this->attributes['jpegPhoto'][0] = $data; $this->attributes['jpegPhoto'][0] = $data;
} }
@ -3222,10 +3212,8 @@ class windowsUser extends baseModule implements passwordService {
} }
$advancedOptions = new htmlResponsiveRow(); $advancedOptions = new htmlResponsiveRow();
$advancedOptions->add(new htmlSubTitle(_('Photo')), 12); $advancedOptions->add(new htmlSubTitle(_('Photo')), 12);
if (extension_loaded('imagick')) { $advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'windowsUser_jpegPhoto_maxWidth', null, 'crop'), 12);
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'windowsUser_jpegPhoto_maxWidth', null, 'crop'), 12); $advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'windowsUser_jpegPhoto_maxHeight', null, 'crop'), 12);
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'windowsUser_jpegPhoto_maxHeight', null, 'crop'), 12);
}
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'windowsUser_jpegPhoto_maxSize'), 12); $advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'windowsUser_jpegPhoto_maxSize'), 12);
$advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false); $advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false);
$advancedOptionsAccordion->colspan = 5; $advancedOptionsAccordion->colspan = 5;