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) {
|
||||
if (!$details)
|
||||
return $value;
|
||||
if (function_exists('gnupg_init')) {
|
||||
// @phpstan-ignore-next-line
|
||||
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
|
||||
$info = gnupg_import($res, $value);
|
||||
if (class_exists('gnupg')) {
|
||||
// The home_dir parameter passed to gnupg_init() is not correctly handled in PHP 7.3, also set
|
||||
// the GNUPGHOME environment variable.
|
||||
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 {
|
||||
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
|
||||
*/
|
||||
public static function validate($value, $options, &$formElement) {
|
||||
if (!function_exists('gnupg_init')) {
|
||||
if (!class_exists('gnupg')) {
|
||||
LSerror :: addErrorCode('LSformRule_gpg_pub_key_01');
|
||||
return false;
|
||||
}
|
||||
// @phpstan-ignore-next-line
|
||||
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
|
||||
$info = gnupg_import($res, $value);
|
||||
// The home_dir parameter passed to gnupg_init() is not correctly handled in PHP 7.3, also set
|
||||
// the GNUPGHOME environment variable.
|
||||
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
|
||||
return is_array($info) && ($info['imported'] + $info['unchanged']) == 1 && $info['fingerprint'];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue