mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-25 03:19:08 +01:00
LSattr_html_gpg_pub_key & LSformRule_gpg_pub_key: fix setting GnuPG home dir in PHP 7.3
This commit is contained in:
parent
171161ae18
commit
2ccf579125
2 changed files with 16 additions and 8 deletions
|
@ -44,10 +44,14 @@ class LSformElement_gpg_pub_key extends LSformElement {
|
||||||
public function parseValue($value, $details=true) {
|
public function parseValue($value, $details=true) {
|
||||||
if (!$details)
|
if (!$details)
|
||||||
return $value;
|
return $value;
|
||||||
if (function_exists('gnupg_init')) {
|
if (class_exists('gnupg')) {
|
||||||
// @phpstan-ignore-next-line
|
// The home_dir parameter passed to gnupg_init() is not correctly handled in PHP 7.3, also set
|
||||||
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
|
// the GNUPGHOME environment variable.
|
||||||
$info = gnupg_import($res, $value);
|
putenv('GNUPGHOME='.LS_TMP_DIR_PATH);
|
||||||
|
$gpg = new gnupg(["home_dir" => LS_TMP_DIR_PATH]);
|
||||||
|
// Don't warn about (GNUPG_ERROR_SILENT is currently the default but ensure it)
|
||||||
|
$gpg -> seterrormode(GNUPG_ERROR_SILENT);
|
||||||
|
$info = $gpg -> import($value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LSerror :: addErrorCode('LSformElement_gpg_pub_key_01');
|
LSerror :: addErrorCode('LSformElement_gpg_pub_key_01');
|
||||||
|
|
|
@ -37,13 +37,17 @@ class LSformRule_gpg_pub_key extends LSformRule {
|
||||||
* @return boolean true if the value is valide, false if not
|
* @return boolean true if the value is valide, false if not
|
||||||
*/
|
*/
|
||||||
public static function validate($value, $options, &$formElement) {
|
public static function validate($value, $options, &$formElement) {
|
||||||
if (!function_exists('gnupg_init')) {
|
if (!class_exists('gnupg')) {
|
||||||
LSerror :: addErrorCode('LSformRule_gpg_pub_key_01');
|
LSerror :: addErrorCode('LSformRule_gpg_pub_key_01');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// @phpstan-ignore-next-line
|
// The home_dir parameter passed to gnupg_init() is not correctly handled in PHP 7.3, also set
|
||||||
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
|
// the GNUPGHOME environment variable.
|
||||||
$info = gnupg_import($res, $value);
|
putenv('GNUPGHOME='.LS_TMP_DIR_PATH);
|
||||||
|
$gpg = new gnupg(["home_dir" => LS_TMP_DIR_PATH]);
|
||||||
|
// Don't warn about (GNUPG_ERROR_SILENT is currently the default but ensure it)
|
||||||
|
$gpg -> seterrormode(GNUPG_ERROR_SILENT);
|
||||||
|
$info = $gpg -> import($value);
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
return is_array($info) && ($info['imported'] + $info['unchanged']) == 1 && $info['fingerprint'];
|
return is_array($info) && ($info['imported'] + $info['unchanged']) == 1 && $info['fingerprint'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue