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
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 | php-zip, php5 | php-xml,
php5 | php-zip, php5 | php-xml, php-imagick,
libapache2-mod-php5 | libapache2-mod-php | php5-fpm | php-fpm,
apache2 | httpd, fonts-dejavu, debconf (>= 0.2.26) | debconf-2.0, ${misc:Depends}
Recommends: php-apc | php-opcache

View File

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

View File

@ -1,9 +1,8 @@
<?php
/*
$Id$
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
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')) {
$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
if (! function_exists('getimagesize')) {
$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['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'][1] = array('ERROR', _('Please upload a .jpg/.jpeg 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['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)) {
$name = $_FILES['photoFile']['name'];
$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");
$data = fread($handle, 10000000);
if (!empty($this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['inetOrgPerson_jpegPhoto_maxSize'][0]))) {
@ -1633,7 +1628,6 @@ class inetOrgPerson extends baseModule implements passwordService {
return array($errMsg);
}
fclose($handle);
if (extension_loaded('imagick')) {
// convert to JPG if imagick extension is available
$image = new Imagick();
try {
@ -1654,7 +1648,6 @@ class inetOrgPerson extends baseModule implements passwordService {
$messages[] = $msg;
return $messages;
}
}
$this->attributes['jpegPhoto'][0] = $data;
}
else {
@ -1670,10 +1663,7 @@ class inetOrgPerson extends baseModule implements passwordService {
*/
function display_html_photo() {
$container = new htmlTable();
$label = _('Photo file (JPG format)');
if (extension_loaded('imagick')) {
$label = _('Photo file');
}
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
$buttonContainer = new htmlTable();
$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) {
$container = new htmlResponsiveRow();
$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 height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, array('crop', get_class($this))), 12);
}
$container->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12);
return $container;
}
@ -3225,7 +3213,6 @@ class inetOrgPerson extends baseModule implements passwordService {
$handle = fopen($_FILES['photoFile']['tmp_name'], "r");
$data = fread($handle, 100000000);
fclose($handle);
if (extension_loaded('imagick')) {
try {
$data = inetOrgPerson::resizeAndConvertImage($data, $moduleSettings);
}
@ -3234,7 +3221,6 @@ class inetOrgPerson extends baseModule implements passwordService {
$msg[] = htmlspecialchars($e->getMessage());
$return['messages'][] = $msg;
}
}
if (isset($_POST['removeReplacePhoto']) && ($_POST['removeReplacePhoto'] == 'on')) {
$return['mod']['jpegPhoto'][0] = $data;
}
@ -3352,7 +3338,6 @@ class inetOrgPerson extends baseModule implements passwordService {
* @return array binary image data
*/
private static function resizeAndConvertImage($data, $settings) {
if (extension_loaded('imagick')) {
// convert to JPG if imagick extension is available
$image = new Imagick();
$image->readImageBlob($data);
@ -3365,7 +3350,6 @@ class inetOrgPerson extends baseModule implements passwordService {
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageFormat('jpeg');
$data = $image->getimageblob();
}
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 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 height (px)'), 'inetOrgPerson_jpegPhoto_maxHeight', null, 'crop'), 12);
}
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'inetOrgPerson_jpegPhoto_maxSize'), 12);
$advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false);
$configContainer->add($advancedOptionsAccordion, 12);

View File

@ -2,10 +2,9 @@
use \LAM\TYPES\TypeManager;
use LAM\TYPES\ConfiguredType;
/*
$Id$
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
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() {
$container = new htmlTable();
$label = _('Photo file (JPG format)');
if (extension_loaded('imagick')) {
$label = _('Photo file');
}
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
$buttonContainer = new htmlTable();
$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)) {
$name = $_FILES['photoFile']['name'];
$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");
$data = fread($handle, 10000000);
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]) && (strlen($data) > (1024 * $this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]))) {
@ -1783,7 +1775,6 @@ class windowsUser extends baseModule implements passwordService {
return array($errMsg);
}
fclose($handle);
if (extension_loaded('imagick')) {
// convert to JPG if imagick extension is available
$image = new Imagick();
try {
@ -1804,7 +1795,6 @@ class windowsUser extends baseModule implements passwordService {
$messages[] = $msg;
return $messages;
}
}
$this->attributes['jpegPhoto'][0] = $data;
}
else {
@ -3222,10 +3212,8 @@ class windowsUser extends baseModule implements passwordService {
}
$advancedOptions = new htmlResponsiveRow();
$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 height (px)'), 'windowsUser_jpegPhoto_maxHeight', null, 'crop'), 12);
}
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'windowsUser_jpegPhoto_maxSize'), 12);
$advancedOptionsAccordion = new htmlAccordion('inetOrgPersonAdvancedOptions', array(_('Advanced options') => $advancedOptions), false);
$advancedOptionsAccordion->colspan = 5;